You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

todo.js 6.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. wn.provide('erpnext.todo');
  17. erpnext.todo.refresh = function() {
  18. wn.call({
  19. method: 'core.page.todo.todo.get',
  20. callback: function(r,rt) {
  21. var todo_list = $('#todo-list div.todo-content');
  22. var assigned_todo_list = $('#assigned-todo-list div.todo-content');
  23. todo_list.empty();
  24. assigned_todo_list.empty();
  25. var nothing_to_do = function() {
  26. $('#todo-list div.todo-content')
  27. .html('<div class="alert">Nothing to do :)</div>');
  28. }
  29. if(r.message) {
  30. for(var i in r.message) {
  31. new erpnext.todo.ToDoItem(r.message[i]);
  32. }
  33. if (!todo_list.html()) { nothing_to_do(); }
  34. } else {
  35. nothing_to_do();
  36. }
  37. }
  38. });
  39. }
  40. erpnext.todo.ToDoItem = Class.extend({
  41. init: function(todo) {
  42. label_map = {
  43. 'High': 'label-danger',
  44. 'Medium': 'label-info',
  45. 'Low':''
  46. }
  47. todo.labelclass = label_map[todo.priority];
  48. todo.userdate = dateutil.str_to_user(todo.date) || '';
  49. todo.fullname = '';
  50. if(todo.assigned_by) {
  51. var assigned_by = wn.boot.user_info[todo.assigned_by]
  52. todo.fullname = repl("[By %(fullname)s] ".bold(), {
  53. fullname: (assigned_by ? assigned_by.fullname : todo.assigned_by),
  54. });
  55. }
  56. var parent_list = "#todo-list";
  57. if(todo.owner !== user) {
  58. var owner = wn.boot.user_info[todo.owner];
  59. todo.fullname = repl("[To %(fullname)s] ".bold(), {
  60. fullname: (owner ? owner.fullname : todo.owner),
  61. });
  62. }
  63. parent_list += " div.todo-content";
  64. if(todo.reference_name && todo.reference_type) {
  65. todo.link = repl('<a href="#!Form/%(reference_type)s/%(reference_name)s">\
  66. %(reference_type)s: %(reference_name)s</a>', todo);
  67. } else if(todo.reference_type) {
  68. todo.link = repl('<br><a href="#!List/%(reference_type)s">\
  69. %(reference_type)s</a>', todo);
  70. } else {
  71. todo.link = '';
  72. }
  73. if(!todo.description) todo.description = '';
  74. todo.description_display = todo.description.replace(/\n\n/g, "<br>").trim();
  75. $(parent_list).append(repl('\
  76. <div class="todoitem">\
  77. <div class="label %(labelclass)s">%(priority)s</div>\
  78. <div class="popup-on-click"><a href="#">[edit]</a></div>\
  79. <div class="todo-date-fullname">\
  80. <div class="todo-date">%(userdate)s</div>\
  81. %(fullname)s:\
  82. </div>\
  83. <div class="description">%(description_display)s\
  84. <span class="ref_link">%(link)s</span>\
  85. </div>\
  86. <div class="close-span"><a href="#" class="close">&times;</a></div>\
  87. </div>\
  88. <div class="todo-separator"></div>', todo));
  89. $todo = $(parent_list + ' div.todoitem:last');
  90. if(todo.checked) {
  91. $todo.find('.description').css('text-decoration', 'line-through');
  92. }
  93. if(!todo.reference_type)
  94. $todo.find('.ref_link').toggle(false);
  95. $todo.find('.popup-on-click')
  96. .data('todo', todo)
  97. .click(function() {
  98. erpnext.todo.make_dialog($(this).data('todo'));
  99. return false;
  100. });
  101. $todo.find('.close')
  102. .data('name', todo.name)
  103. .click(function() {
  104. $(this).parent().css('opacity', 0.5);
  105. wn.call({
  106. method:'core.page.todo.todo.delete',
  107. args: {name: $(this).data('name')},
  108. callback: function() {
  109. erpnext.todo.refresh();
  110. }
  111. });
  112. return false;
  113. })
  114. }
  115. });
  116. erpnext.todo.make_dialog = function(det) {
  117. if(!erpnext.todo.dialog) {
  118. var dialog = new wn.ui.Dialog({
  119. width: 480,
  120. title: 'To Do',
  121. fields: [
  122. {fieldtype:'Text', fieldname:'description', label:'Description',
  123. reqd:1},
  124. {fieldtype:'Date', fieldname:'date', label:'Event Date', reqd:1},
  125. {fieldtype:'Check', fieldname:'checked', label:'Completed'},
  126. {fieldtype:'Select', fieldname:'priority', label:'Priority', reqd:1, 'options':['Medium','High','Low'].join('\n')},
  127. {fieldtype:'Button', fieldname:'save', label:'Save (Ctrl+S)'}
  128. ]
  129. });
  130. dialog.fields_dict.save.input.onclick = function() {
  131. erpnext.todo.save(this);
  132. }
  133. erpnext.todo.dialog = dialog;
  134. }
  135. if(det) {
  136. erpnext.todo.dialog.set_values({
  137. date: det.date,
  138. priority: det.priority,
  139. description: det.description,
  140. checked: det.checked
  141. });
  142. erpnext.todo.dialog.det = det;
  143. }
  144. erpnext.todo.dialog.show();
  145. }
  146. erpnext.todo.save = function(btn) {
  147. var d = erpnext.todo.dialog;
  148. var det = d.get_values();
  149. if(!det) {
  150. return;
  151. }
  152. det.name = d.det.name || '';
  153. wn.call({
  154. method:'core.page.todo.todo.edit',
  155. args: det,
  156. btn: btn,
  157. callback: function() {
  158. erpnext.todo.dialog.hide();
  159. erpnext.todo.refresh();
  160. }
  161. });
  162. }
  163. wn.pages.todo.onload = function(wrapper) {
  164. // create app frame
  165. wn.ui.make_app_page({
  166. parent: wrapper,
  167. single_column: true,
  168. title: "To Do"
  169. });
  170. $(wrapper)
  171. .css({"background-color": "#FFFDC9", "min-height": "300px"})
  172. .find(".layout-main").html('<div id="todo-list">\
  173. <div class="todo-content"></div>\
  174. </div>');
  175. wrapper.appframe.add_module_icon("To Do");
  176. wrapper.appframe.add_button('Refresh', erpnext.todo.refresh, 'icon-refresh');
  177. wrapper.appframe.add_button('Add', function() {
  178. erpnext.todo.make_dialog({
  179. date:get_today(), priority:'Medium', checked:0, description:''});
  180. }, 'icon-plus');
  181. wrapper.appframe.add_ripped_paper_effect(wrapper);
  182. // show report button for System Manager
  183. if(wn.boot.profile.roles.indexOf("System Manager") !== -1) {
  184. wrapper.appframe.add_button("Report", function() { wn.set_route("query-report", "todo"); },
  185. "icon-table");
  186. }
  187. // load todos
  188. erpnext.todo.refresh();
  189. // save on click
  190. wrapper.save_action = function() {
  191. if(erpnext.todo.dialog && erpnext.todo.dialog.display) {
  192. erpnext.todo.dialog.fields_dict.save.input.click();
  193. }
  194. };
  195. }