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.
 
 
 
 
 
 

111 lines
3.7 KiB

  1. // Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. //
  3. // MIT License (MIT)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a
  6. // copy of this software and associated documentation files (the "Software"),
  7. // to deal in the Software without restriction, including without limitation
  8. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. // and/or sell copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. // assign to is lined to todo
  23. // refresh - load todos
  24. // create - new todo
  25. // delete to do
  26. wn.widgets.form.sidebar.AssignTo = Class.extend({
  27. init: function(parent, sidebar, doctype, docname) {
  28. var me = this;
  29. this.doctype = doctype;
  30. this.name = docname;
  31. this.wrapper = $a(parent, 'div', 'sidebar-comment-wrapper');
  32. this.body = $a(this.wrapper, 'div');
  33. this.add_btn = $btn($a(this.wrapper, 'div', 'sidebar-comment-message'), 'Assign',
  34. function() {
  35. me.add();
  36. })
  37. this.refresh();
  38. },
  39. refresh: function() {
  40. var me = this;
  41. $c('webnotes.widgets.form.assign_to.get', {
  42. doctype: me.doctype,
  43. name: me.name
  44. }, function(r,rt) {
  45. me.render(r.message)
  46. })
  47. },
  48. render: function(d) {
  49. var me = this;
  50. $(this.body).empty();
  51. if(this.dialog) {
  52. this.dialog.hide();
  53. }
  54. for(var i=0; i<d.length; i++) {
  55. $(this.body).append(repl('<div>%(owner)s \
  56. <a class="close" href="#" data-owner="%(owner)s">&#215</a></div>', d[i]))
  57. }
  58. // set remove
  59. $(this.body).find('a.close').click(function() {
  60. $c('webnotes.widgets.form.assign_to.remove', {
  61. doctype: me.doctype,
  62. name: me.name,
  63. assign_to: $(this).attr('data-owner')
  64. }, function(r,rt) {me.render(r.message);});
  65. return false;
  66. });
  67. },
  68. add: function() {
  69. var me = this;
  70. if(!me.dialog) {
  71. me.dialog = new wn.ui.Dialog({
  72. title: 'Add to To Do',
  73. width: 350,
  74. fields: [
  75. {fieldtype:'Link', fieldname:'assign_to', options:'Profile',
  76. label:'Assign To',
  77. description:'Add to To Do List of', reqd:true},
  78. {fieldtype:'Data', fieldname:'description', label:'Comment'},
  79. {fieldtype:'Date', fieldname:'date', label:'Complete By'},
  80. {fieldtype:'Select', fieldname:'priority', label:'Priority',
  81. options:'Low\nMedium\nHigh', 'default':'Medium'},
  82. {fieldtype:'Check', fieldname:'notify', label:'Notify By Email'},
  83. {fieldtype:'Button', label:'Add', fieldname:'add_btn'}
  84. ]
  85. });
  86. me.dialog.fields_dict.add_btn.input.onclick = function() {
  87. var assign_to = me.dialog.fields_dict.assign_to.get_value();
  88. if(assign_to) {
  89. $c('webnotes.widgets.form.assign_to.add', {
  90. doctype: me.doctype,
  91. name: me.name,
  92. assign_to: assign_to,
  93. description: me.dialog.fields_dict.description.get_value(),
  94. priority: me.dialog.fields_dict.priority.get_value(),
  95. date: me.dialog.fields_dict.date.get_value(),
  96. notify: me.dialog.fields_dict.notify.get_value()
  97. }, function(r,rt) {me.render(r.message);});
  98. }
  99. }
  100. }
  101. me.dialog.clear();
  102. me.dialog.show();
  103. }
  104. });