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