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.
 
 
 
 
 
 

151 lines
4.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.provide("wn.ui.form");
  27. wn.ui.form.AssignTo = Class.extend({
  28. init: function(opts) {
  29. $.extend(this, opts);
  30. var me = this;
  31. this.wrapper = $('<div>\
  32. <div class="alert-list" style="margin-bottom: 7px;"></div>\
  33. </div>').appendTo(this.parent);
  34. this.$list = this.wrapper.find(".alert-list");
  35. this.parent.find(".btn").click(function() {
  36. me.add();
  37. });
  38. this.refresh();
  39. },
  40. refresh: function() {
  41. if(this.frm.doc.__islocal) {
  42. this.parent.toggle(false);
  43. return;
  44. }
  45. this.parent.toggle(true);
  46. this.render(this.frm.get_docinfo().assignments);
  47. },
  48. render: function(d) {
  49. var me = this;
  50. this.frm.get_docinfo().assignments = d;
  51. this.$list.empty();
  52. if(this.dialog) {
  53. this.dialog.hide();
  54. }
  55. for(var i=0; i<d.length; i++) {
  56. var info = wn.user_info(d[i]);
  57. info.owner = d[i];
  58. info.avatar = wn.avatar(d[i]);
  59. $(repl('<div class="alert alert-success" style="margin-bottom: 7px;">\
  60. %(avatar)s %(fullname)s \
  61. <a class="close" href="#" style="top: 1px;"\
  62. data-owner="%(owner)s">&times;</a></div>', info))
  63. .appendTo(this.$list);
  64. this.$list.find(".avatar").css("margin-top", "-7px")
  65. this.$list.find('.avatar img').centerImage();
  66. }
  67. // set remove
  68. this.$list.find('a.close').click(function() {
  69. wn.call({
  70. method:'webnotes.widgets.form.assign_to.remove',
  71. args: {
  72. doctype: me.frm.doctype,
  73. name: me.frm.docname,
  74. assign_to: $(this).attr('data-owner')
  75. },
  76. callback:function(r,rt) {
  77. me.render(r.message);
  78. me.frm.toolbar.show_infobar();
  79. }
  80. });
  81. return false;
  82. });
  83. },
  84. add: function() {
  85. var me = this;
  86. if(!me.dialog) {
  87. me.dialog = new wn.ui.Dialog({
  88. title: wn._('Add to To Do'),
  89. width: 350,
  90. fields: [
  91. {fieldtype:'Link', fieldname:'assign_to', options:'Profile',
  92. label:wn._("Assign To"),
  93. description:wn._("Add to To Do List of"), reqd:true},
  94. {fieldtype:'Data', fieldname:'description', label:wn._("Comment")},
  95. {fieldtype:'Date', fieldname:'date', label: wn._("Complete By")},
  96. {fieldtype:'Select', fieldname:'priority', label: wn._("Priority"),
  97. options:'Low\nMedium\nHigh', 'default':'Medium'},
  98. {fieldtype:'Check', fieldname:'notify',
  99. label: wn._("Notify By Email"), "default": 1},
  100. {fieldtype:'Button', label:wn._("Add"), fieldname:'add_btn'}
  101. ]
  102. });
  103. me.dialog.fields_dict.add_btn.input.onclick = function() {
  104. var assign_to = me.dialog.fields_dict.assign_to.get_value();
  105. var args = me.dialog.get_values();
  106. if(assign_to) {
  107. wn.call({
  108. method:'webnotes.widgets.form.assign_to.add',
  109. args: $.extend(args, {
  110. doctype: me.frm.doctype,
  111. name: me.frm.docname,
  112. assign_to: assign_to,
  113. }),
  114. callback: function(r,rt) {
  115. if(!r.exc) {
  116. me.render(r.message);
  117. me.frm.toolbar.show_infobar();
  118. }
  119. },
  120. btn: this
  121. });
  122. }
  123. }
  124. me.dialog.fields_dict.assign_to.get_query = function() {
  125. return "select name, concat_ws(' ', first_name, middle_name, last_name) \
  126. from `tabProfile` where ifnull(enabled, 0)=1 and docstatus < 2 and \
  127. name not in ('Administrator', 'Guest') and (%(key)s like \"%s\" or \
  128. concat_ws(' ', first_name, middle_name, last_name) like \"%%%s\") \
  129. order by \
  130. case when name like \"%s%%\" then 0 else 1 end, \
  131. case when concat_ws(' ', first_name, middle_name, last_name) \
  132. like \"%s%%\" then 0 else 1 end, \
  133. name asc limit 50";
  134. };
  135. }
  136. me.dialog.clear();
  137. me.dialog.show();
  138. }
  139. });