You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

110 lines
2.4 KiB

  1. wn.provide("wn.views.calendar");
  2. wn.views.GanttFactory = wn.views.Factory.extend({
  3. make: function(route) {
  4. var me = this;
  5. wn.model.with_doctype(route[1], function() {
  6. var options = {
  7. doctype: route[1],
  8. page: me.make_page()
  9. };
  10. $.extend(options, wn.views.calendar[route[1]] || {});
  11. new wn.views.Gantt(options);
  12. });
  13. }
  14. });
  15. wn.views.Gantt = Class.extend({
  16. init: function(opts) {
  17. $.extend(this, opts);
  18. wn.require('lib/js/lib/jQuery.Gantt/css/style.css');
  19. wn.require('lib/js/lib/jQuery.Gantt/js/jquery.fn.gantt.js');
  20. this.make_page();
  21. this.make_chart();
  22. },
  23. make_page: function() {
  24. var module = locals.DocType[this.doctype].module;
  25. this.page.appframe.set_title(wn._("Gantt Chart") + " - " + wn._(this.doctype));
  26. this.page.appframe.add_module_icon(module)
  27. this.page.appframe.set_views_for(this.doctype, "gantt");
  28. },
  29. make_chart: function() {
  30. var parent = $(this.page)
  31. .find(".layout-main")
  32. .empty()
  33. .css('min-height', '300px')
  34. .html('<div class="alert">Loading...</div>');
  35. var me = this;
  36. wn.call({
  37. method: this.get_events_method,
  38. type: "GET",
  39. args: {
  40. doctype: this.doctype,
  41. start: "2013-01-01",
  42. end: "2014-01-01"
  43. },
  44. callback: function(r) {
  45. $(parent).empty();
  46. if(!r.message.length) {
  47. $(parent).html('<div class="alert">No Tasks Yet.</div>');
  48. } else {
  49. var gantt_area = $('<div class="gantt">').appendTo(parent);
  50. gantt_area.gantt({
  51. source: me.get_source(r),
  52. navigate: "scroll",
  53. scale: "weeks",
  54. minScale: "day",
  55. maxScale: "months",
  56. onItemClick: function(data) {
  57. wn.set_route('Form', me.doctype, data.name);
  58. },
  59. onAddClick: function(dt, rowId) {
  60. newdoc(me.doctype);
  61. }
  62. });
  63. }
  64. }
  65. })
  66. },
  67. get_source: function(r) {
  68. var source = [],
  69. me = this;
  70. // projects
  71. $.each(r.message, function(i,v) {
  72. // standardize values
  73. $.each(me.field_map, function(target, source) {
  74. v[target] = v[source];
  75. });
  76. if(v.start && v.end) {
  77. source.push({
  78. name: v.project || " ",
  79. desc: v.subject,
  80. values: [{
  81. name: v.title,
  82. desc: v.status,
  83. from: '/Date("'+v.start+'")/',
  84. to: '/Date("'+v.end+'")/',
  85. customClass: {
  86. 'danger':'ganttRed',
  87. 'warning':'ganttOrange',
  88. 'info':'ganttBlue',
  89. 'success':'ganttGreen',
  90. '':'ganttGray'
  91. }[me.style_map[v.status]],
  92. dataObj: v
  93. }]
  94. })
  95. }
  96. });
  97. return source
  98. }
  99. });