Rushabh Mehta | aaf86ba | 2012-02-28 17:40:13 +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 | |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 17 | wn.provide('erpnext.todo'); |
| 18 | |
| 19 | erpnext.todo.refresh = function() { |
| 20 | wn.call({ |
| 21 | method: 'utilities.page.todo.todo.get', |
| 22 | callback: function(r,rt) { |
Anand Doshi | 64ddb9f | 2012-06-12 19:24:12 +0530 | [diff] [blame] | 23 | $('#todo-list div.todo-content').empty(); |
| 24 | $('#assigned-todo-list div.todo-content').empty(); |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 25 | if(r.message) { |
| 26 | for(var i in r.message) { |
| 27 | new erpnext.todo.ToDoItem(r.message[i]); |
| 28 | } |
| 29 | } else { |
| 30 | $('#todo-list').html('<div class="help-box">Nothing to do :)</div>'); |
| 31 | } |
| 32 | } |
| 33 | }); |
| 34 | |
| 35 | $('#add-todo').click(function() { |
| 36 | erpnext.todo.make_dialog({ |
| 37 | date:get_today(), priority:'Medium', checked:0, description:''}); |
| 38 | }) |
| 39 | } |
| 40 | |
| 41 | erpnext.todo.ToDoItem = Class.extend({ |
| 42 | init: function(todo) { |
| 43 | label_map = { |
| 44 | 'High': 'label-important', |
| 45 | 'Medium': 'label-info', |
| 46 | 'Low':'' |
| 47 | } |
| 48 | todo.labelclass = label_map[todo.priority]; |
Anand Doshi | 29ed95b | 2012-03-21 18:02:17 +0530 | [diff] [blame] | 49 | todo.userdate = dateutil.str_to_user(todo.date) || ''; |
Anand Doshi | 64ddb9f | 2012-06-12 19:24:12 +0530 | [diff] [blame] | 50 | |
| 51 | todo.fullname = ''; |
Anand Doshi | 06fcfdf | 2012-03-22 11:01:38 +0530 | [diff] [blame] | 52 | if(todo.assigned_by) { |
Anand Doshi | 3c3f996 | 2012-06-13 12:01:41 +0530 | [diff] [blame] | 53 | todo.fullname = repl("[By %(fullname)s] ", { |
Anand Doshi | 06fcfdf | 2012-03-22 11:01:38 +0530 | [diff] [blame] | 54 | fullname: wn.boot.user_info[todo.assigned_by].fullname |
Anand Doshi | 64ddb9f | 2012-06-12 19:24:12 +0530 | [diff] [blame] | 55 | }); |
| 56 | } |
| 57 | |
| 58 | var parent_list = "#todo-list"; |
| 59 | if(todo.owner !== user) { |
| 60 | parent_list = "#assigned-todo-list"; |
Anand Doshi | 3c3f996 | 2012-06-13 12:01:41 +0530 | [diff] [blame] | 61 | todo.fullname = repl("[To %(fullname)s] ", { |
Anand Doshi | 64ddb9f | 2012-06-12 19:24:12 +0530 | [diff] [blame] | 62 | fullname: wn.boot.user_info[todo.owner].fullname |
| 63 | }); |
| 64 | } |
| 65 | parent_list += " div.todo-content"; |
| 66 | |
Anand Doshi | 0b8ac7f | 2012-02-29 18:33:39 +0530 | [diff] [blame] | 67 | if(todo.reference_name && todo.reference_type) { |
| 68 | todo.link = repl('<a href="#!Form/%(reference_type)s/%(reference_name)s">\ |
Anand Doshi | 29ed95b | 2012-03-21 18:02:17 +0530 | [diff] [blame] | 69 | %(reference_type)s: %(reference_name)s</a>', todo); |
Anand Doshi | 0b8ac7f | 2012-02-29 18:33:39 +0530 | [diff] [blame] | 70 | } else if(todo.reference_type) { |
| 71 | todo.link = repl('<a href="#!List/%(reference_type)s">\ |
| 72 | %(reference_type)s</a>', todo); |
| 73 | } else { |
| 74 | todo.link = ''; |
| 75 | } |
Anand Doshi | 130dfae | 2012-04-03 12:18:35 +0530 | [diff] [blame] | 76 | if(!todo.description) todo.description = ''; |
Anand Doshi | 64ddb9f | 2012-06-12 19:24:12 +0530 | [diff] [blame] | 77 | |
| 78 | todo.desc = todo.description.replace(/\n/g, "<br>"); |
| 79 | |
| 80 | $(parent_list).append(repl('\ |
| 81 | <div class="todoitem">\ |
| 82 | <span class="label %(labelclass)s">%(priority)s</span>\ |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 83 | <span class="description">\ |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 84 | <span class="help" style="margin-right: 7px">%(userdate)s</span>\ |
Anand Doshi | 64ddb9f | 2012-06-12 19:24:12 +0530 | [diff] [blame] | 85 | %(fullname)s%(desc)s\ |
| 86 | <span class="ref_link"><br>\ |
Anand Doshi | 0b8ac7f | 2012-02-29 18:33:39 +0530 | [diff] [blame] | 87 | %(link)s</span>\ |
Anand Doshi | 64ddb9f | 2012-06-12 19:24:12 +0530 | [diff] [blame] | 88 | </span>\ |
| 89 | <span class="close-span"><a href="#" class="close">×</a></span>\ |
| 90 | </div>\ |
| 91 | <div class="todo-separator"></div>', todo)); |
| 92 | $todo = $(parent_list + ' div.todoitem:last'); |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 93 | |
| 94 | if(todo.checked) { |
| 95 | $todo.find('.description').css('text-decoration', 'line-through'); |
| 96 | } |
| 97 | |
Anand Doshi | 0b8ac7f | 2012-02-29 18:33:39 +0530 | [diff] [blame] | 98 | if(!todo.reference_type) |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 99 | $todo.find('.ref_link').toggle(false); |
| 100 | |
| 101 | $todo.find('.description') |
| 102 | .data('todo', todo) |
| 103 | .click(function() { |
| 104 | erpnext.todo.make_dialog($(this).data('todo')); |
| 105 | return false; |
| 106 | }); |
| 107 | |
| 108 | $todo.find('.close') |
| 109 | .data('name', todo.name) |
| 110 | .click(function() { |
| 111 | $(this).parent().css('opacity', 0.5); |
| 112 | wn.call({ |
| 113 | method:'utilities.page.todo.todo.delete', |
| 114 | args: {name: $(this).data('name')}, |
| 115 | callback: function() { |
| 116 | erpnext.todo.refresh(); |
| 117 | } |
| 118 | }); |
| 119 | return false; |
| 120 | }) |
| 121 | } |
| 122 | }); |
| 123 | |
| 124 | erpnext.todo.make_dialog = function(det) { |
| 125 | if(!erpnext.todo.dialog) { |
| 126 | var dialog = new wn.widgets.Dialog(); |
| 127 | dialog.make({ |
| 128 | width: 480, |
| 129 | title: 'To Do', |
| 130 | fields: [ |
| 131 | {fieldtype:'Date', fieldname:'date', label:'Event Date', reqd:1}, |
| 132 | {fieldtype:'Text', fieldname:'description', label:'Description', reqd:1}, |
| 133 | {fieldtype:'Check', fieldname:'checked', label:'Completed'}, |
| 134 | {fieldtype:'Select', fieldname:'priority', label:'Priority', reqd:1, 'options':['Medium','High','Low'].join('\n')}, |
| 135 | {fieldtype:'Button', fieldname:'save', label:'Save'} |
| 136 | ] |
| 137 | }); |
| 138 | |
| 139 | dialog.fields_dict.save.input.onclick = function() { |
| 140 | erpnext.todo.save(this); |
| 141 | } |
| 142 | erpnext.todo.dialog = dialog; |
| 143 | } |
| 144 | |
| 145 | if(det) { |
| 146 | erpnext.todo.dialog.set_values({ |
| 147 | date: det.date, |
| 148 | priority: det.priority, |
| 149 | description: det.description, |
| 150 | checked: det.checked |
| 151 | }); |
| 152 | erpnext.todo.dialog.det = det; |
| 153 | } |
| 154 | erpnext.todo.dialog.show(); |
| 155 | |
| 156 | } |
| 157 | |
| 158 | erpnext.todo.save = function(btn) { |
| 159 | var d = erpnext.todo.dialog; |
| 160 | var det = d.get_values(); |
| 161 | |
| 162 | if(!det) { |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | det.name = d.det.name || ''; |
| 167 | wn.call({ |
| 168 | method:'utilities.page.todo.todo.edit', |
| 169 | args: det, |
| 170 | btn: btn, |
| 171 | callback: function() { |
| 172 | erpnext.todo.dialog.hide(); |
| 173 | erpnext.todo.refresh(); |
| 174 | } |
| 175 | }); |
| 176 | } |
| 177 | |
Rushabh Mehta | fdea966 | 2012-02-27 18:03:54 +0530 | [diff] [blame] | 178 | wn.pages.todo.onload = function() { |
Rushabh Mehta | 2886b95 | 2012-02-24 11:26:31 +0530 | [diff] [blame] | 179 | // load todos |
| 180 | erpnext.todo.refresh(); |
Anand Doshi | 0b8ac7f | 2012-02-29 18:33:39 +0530 | [diff] [blame] | 181 | } |