Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

118 rader
4.0 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 = $("<button class='btn btn-small'>\
  34. <i class='icon-plus'></i></button>")
  35. .click(function() { me.add(); }).appendTo(this.wrapper).get(0);
  36. this.refresh();
  37. },
  38. refresh: function() {
  39. var me = this;
  40. $c('webnotes.widgets.form.assign_to.get', {
  41. doctype: me.doctype,
  42. name: me.name
  43. }, function(r,rt) {
  44. me.render(r.message)
  45. })
  46. },
  47. render: function(d) {
  48. var me = this;
  49. $(this.body).empty();
  50. if(this.dialog) {
  51. this.dialog.hide();
  52. }
  53. for(var i=0; i<d.length; i++) {
  54. $(this.body).append(repl('<div>%(owner)s \
  55. <a class="close" href="#" data-owner="%(owner)s">&#215</a></div>', d[i]))
  56. }
  57. // set remove
  58. $(this.body).find('a.close').click(function() {
  59. $c('webnotes.widgets.form.assign_to.remove', {
  60. doctype: me.doctype,
  61. name: me.name,
  62. assign_to: $(this).attr('data-owner')
  63. }, function(r,rt) {me.render(r.message);});
  64. return false;
  65. });
  66. },
  67. add: function() {
  68. var me = this;
  69. if(!me.dialog) {
  70. me.dialog = new wn.ui.Dialog({
  71. title: 'Add to To Do',
  72. width: 350,
  73. fields: [
  74. {fieldtype:'Link', fieldname:'assign_to', options:'Profile',
  75. label:'Assign To',
  76. description:'Add to To Do List of', reqd:true},
  77. {fieldtype:'Data', fieldname:'description', label:'Comment'},
  78. {fieldtype:'Date', fieldname:'date', label:'Complete By'},
  79. {fieldtype:'Select', fieldname:'priority', label:'Priority',
  80. options:'Low\nMedium\nHigh', 'default':'Medium'},
  81. {fieldtype:'Check', fieldname:'notify', label:'Notify By Email'},
  82. {fieldtype:'Button', label:'Add', fieldname:'add_btn'}
  83. ]
  84. });
  85. me.dialog.fields_dict.add_btn.input.onclick = function() {
  86. var assign_to = me.dialog.fields_dict.assign_to.get_value();
  87. if(assign_to) {
  88. $c('webnotes.widgets.form.assign_to.add', {
  89. doctype: me.doctype,
  90. name: me.name,
  91. assign_to: assign_to,
  92. description: me.dialog.fields_dict.description.get_value(),
  93. priority: me.dialog.fields_dict.priority.get_value(),
  94. date: me.dialog.fields_dict.date.get_value(),
  95. notify: me.dialog.fields_dict.notify.get_value()
  96. }, function(r,rt) {me.render(r.message);});
  97. }
  98. };
  99. me.dialog.fields_dict.assign_to.get_query = function() {
  100. return "select name, concat_ws(' ', first_name, middle_name, last_name) \
  101. from `tabProfile` where ifnull(enabled, 0)=1 and docstatus < 2 and \
  102. (%(key)s like \"%s\" or \
  103. concat_ws(' ', first_name, middle_name, last_name) like \"%%%s\") \
  104. limit 50";
  105. };
  106. }
  107. me.dialog.clear();
  108. me.dialog.show();
  109. }
  110. });