Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 1 | // 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 | |
| 19 | wn.require('lib/js/lib/jQuery.Gantt/css/style.css'); |
| 20 | wn.require('lib/js/lib/jQuery.Gantt/js/jquery.fn.gantt.min.js'); |
| 21 | |
| 22 | erpnext.show_task_gantt = function(parent, project) { |
| 23 | |
Rushabh Mehta | 3009c46 | 2012-10-03 11:56:38 +0530 | [diff] [blame] | 24 | $(parent).css('min-height', '300px').html('<div class="alert">Loading...</div>') |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 25 | |
| 26 | var get_source = function(r) { |
| 27 | var source = []; |
| 28 | // projects |
| 29 | $.each(r.message, function(i,v) { |
Rushabh Mehta | 601199d | 2012-11-16 11:46:43 +0530 | [diff] [blame] | 30 | 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 Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 50 | }); |
| 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 Mehta | 3009c46 | 2012-10-03 11:56:38 +0530 | [diff] [blame] | 61 | $(parent).html('<div class="alert">No Tasks Yet.</div>'); |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 62 | } 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 Mehta | 601199d | 2012-11-16 11:46:43 +0530 | [diff] [blame] | 68 | minScale: "day", |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 69 | 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() { |
Rushabh Mehta | 291449b | 2012-12-13 12:53:21 +0530 | [diff] [blame] | 82 | var new_name = wn.model.make_new_doc_and_get_name('Task'); |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 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 | } |