blob: 29c0beff361d1bd9eca5d046f0d412ad78596b62 [file] [log] [blame]
Rushabh Mehta2fa2f712012-09-24 19:13:42 +05301// ERPNext - web based ERP (http://erpnext.com)
2// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17// gantt chart for project tasks
18
19wn.require('lib/js/lib/jQuery.Gantt/css/style.css');
20wn.require('lib/js/lib/jQuery.Gantt/js/jquery.fn.gantt.min.js');
21
22erpnext.show_task_gantt = function(parent, project) {
23
Rushabh Mehta3009c462012-10-03 11:56:38 +053024 $(parent).css('min-height', '300px').html('<div class="alert">Loading...</div>')
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053025
26 var get_source = function(r) {
27 var source = [];
28 // projects
29 $.each(r.message, function(i,v) {
30 source.push({
31 name: v.project,
32 desc: v.subject,
33 values: [{
34 label: v.subject,
35 desc: v.description || v.subject,
36 from: '/Date("'+v.exp_start_date+'")/',
37 to: '/Date("'+v.exp_end_date+'")/',
38 customClass: {
39 'Open':'ganttRed',
40 'Pending Review':'ganttOrange',
41 'Working':'',
42 'Completed':'ganttGreen',
43 'Cancelled':'ganttGray'
44 }[v.status],
45 dataObj: v
46 }]
47 })
48 });
49 return source
50 }
51 wn.call({
52 method: 'projects.page.projects.projects.get_tasks',
53 args: {
54 project: project || ''
55 },
56 callback: function(r) {
57 $(parent).empty();
58 if(!r.message.length) {
Rushabh Mehta3009c462012-10-03 11:56:38 +053059 $(parent).html('<div class="alert">No Tasks Yet.</div>');
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053060 } else {
61 var gantt_area = $('<div class="gantt">').appendTo(parent);
62 gantt_area.gantt({
63 source: get_source(r),
64 navigate: project ? "button" : "scroll",
65 scale: "weeks",
66 minScale: "weeks",
67 maxScale: "months",
68 onItemClick: function(data) {
69 wn.set_route('Form', 'Task', data.name);
70 },
71 onAddClick: function(dt, rowId) {
72 newdoc('Task');
73 }
74 });
75 }
76
77 $('<button class="btn"><i class="icon icon-plus"></i>\
78 Create a new Task</button>').click(function() {
79 wn.model.with_doctype('Task', function() {
80 var new_name = LocalDB.create('Task');
81 if(project)
82 locals.Task[new_name].project = project;
83 wn.set_route('Form', 'Task', new_name);
84 });
85 }).appendTo(parent);
86 }
87 })
88}