blob: 066ad34a0a33f9a6cf59e2a5465b4bed87defe93 [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) {
Rushabh Mehta601199d2012-11-16 11:46:43 +053030 if(v.exp_start_date && v.exp_end_date) {
31 source.push({
32 name: v.project,
33 desc: v.subject,
34 values: [{
35 label: v.subject,
36 desc: v.description || v.subject,
37 from: '/Date("'+v.exp_start_date+'")/',
38 to: '/Date("'+v.exp_end_date+'")/',
39 customClass: {
40 'Open':'ganttRed',
41 'Pending Review':'ganttOrange',
42 'Working':'',
43 'Completed':'ganttGreen',
44 'Cancelled':'ganttGray'
45 }[v.status],
46 dataObj: v
47 }]
48 })
49 }
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053050 });
51 return source
52 }
53 wn.call({
54 method: 'projects.page.projects.projects.get_tasks',
55 args: {
56 project: project || ''
57 },
58 callback: function(r) {
59 $(parent).empty();
60 if(!r.message.length) {
Rushabh Mehta3009c462012-10-03 11:56:38 +053061 $(parent).html('<div class="alert">No Tasks Yet.</div>');
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053062 } else {
63 var gantt_area = $('<div class="gantt">').appendTo(parent);
64 gantt_area.gantt({
65 source: get_source(r),
66 navigate: project ? "button" : "scroll",
67 scale: "weeks",
Rushabh Mehta601199d2012-11-16 11:46:43 +053068 minScale: "day",
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053069 maxScale: "months",
70 onItemClick: function(data) {
71 wn.set_route('Form', 'Task', data.name);
72 },
73 onAddClick: function(dt, rowId) {
74 newdoc('Task');
75 }
76 });
77 }
78
79 $('<button class="btn"><i class="icon icon-plus"></i>\
80 Create a new Task</button>').click(function() {
81 wn.model.with_doctype('Task', function() {
82 var new_name = LocalDB.create('Task');
83 if(project)
84 locals.Task[new_name].project = project;
85 wn.set_route('Form', 'Task', new_name);
86 });
87 }).appendTo(parent);
88 }
89 })
90}