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