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.

assign_to.js 5.1 KiB

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