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