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 4.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. // assign to is lined to todo
  4. // refresh - load todos
  5. // create - new todo
  6. // delete to do
  7. wn.provide("wn.ui.form");
  8. wn.ui.form.AssignTo = Class.extend({
  9. init: function(opts) {
  10. $.extend(this, opts);
  11. var me = this;
  12. this.wrapper = $('<div>\
  13. <div class="alert-list" style="margin-bottom: 7px;"></div>\
  14. </div>').appendTo(this.parent);
  15. this.$list = this.wrapper.find(".alert-list");
  16. this.parent.find(".btn").click(function() {
  17. me.add();
  18. });
  19. this.refresh();
  20. },
  21. refresh: function() {
  22. if(this.frm.doc.__islocal) {
  23. this.parent.toggle(false);
  24. return;
  25. }
  26. this.parent.toggle(true);
  27. this.render(this.frm.get_docinfo().assignments);
  28. },
  29. render: function(d) {
  30. var me = this;
  31. this.frm.get_docinfo().assignments = d;
  32. this.$list.empty();
  33. if(this.dialog) {
  34. this.dialog.hide();
  35. }
  36. if(d && d.length) {
  37. for(var i=0; i<d.length; i++) {
  38. var info = wn.user_info(d[i]);
  39. info.owner = d[i];
  40. info.avatar = wn.avatar(d[i]);
  41. $(repl('<div class="alert alert-success" style="margin-bottom: 7px;">\
  42. %(avatar)s %(fullname)s \
  43. <a class="close" href="#" style="top: 1px;"\
  44. data-owner="%(owner)s">&times;</a></div>', info))
  45. .appendTo(this.$list);
  46. this.$list.find(".avatar").css("margin-top", "-7px")
  47. this.$list.find('.avatar img').centerImage();
  48. }
  49. // set remove
  50. this.$list.find('a.close').click(function() {
  51. wn.call({
  52. method:'webnotes.widgets.form.assign_to.remove',
  53. args: {
  54. doctype: me.frm.doctype,
  55. name: me.frm.docname,
  56. assign_to: $(this).attr('data-owner')
  57. },
  58. callback:function(r,rt) {
  59. me.render(r.message);
  60. me.frm.toolbar.show_infobar();
  61. }
  62. });
  63. return false;
  64. });
  65. } else {
  66. $('<p class="text-muted">' + wn._("No one") + '</p>').appendTo(this.$list);
  67. }
  68. },
  69. add: function() {
  70. var me = this;
  71. if(!me.dialog) {
  72. me.dialog = new wn.ui.Dialog({
  73. title: wn._('Add to To Do'),
  74. width: 350,
  75. fields: [
  76. {fieldtype:'Link', fieldname:'assign_to', options:'Profile',
  77. label:wn._("Assign To"),
  78. description:wn._("Add to To Do List of"), reqd:true},
  79. {fieldtype:'Data', fieldname:'description', label:wn._("Comment")},
  80. {fieldtype:'Date', fieldname:'date', label: wn._("Complete By")},
  81. {fieldtype:'Select', fieldname:'priority', label: wn._("Priority"),
  82. options:'Low\nMedium\nHigh', 'default':'Medium'},
  83. {fieldtype:'Check', fieldname:'notify',
  84. label:wn._("Notify By Email"), "default":1},
  85. {fieldtype:'Check', fieldname:'restrict',
  86. label:wn._("Add This To User's Restrictions")
  87. + ' <a class="assign-user-properties"><i class="icon-share"></i></a>'},
  88. {fieldtype:'Button', label:wn._("Add"), fieldname:'add_btn'}
  89. ]
  90. });
  91. me.dialog.fields_dict.restrict.$wrapper
  92. .find(".assign-user-properties")
  93. .on("click", function() {
  94. wn.route_options = {
  95. property: me.frm.doctype,
  96. user: me.dialog.get_value("assign_to")
  97. };
  98. wn.set_route("user-properties");
  99. });
  100. me.dialog.fields_dict.add_btn.input.onclick = function() {
  101. var assign_to = me.dialog.fields_dict.assign_to.get_value();
  102. var args = me.dialog.get_values();
  103. if(assign_to) {
  104. return wn.call({
  105. method:'webnotes.widgets.form.assign_to.add',
  106. args: $.extend(args, {
  107. doctype: me.frm.doctype,
  108. name: me.frm.docname,
  109. assign_to: assign_to
  110. }),
  111. callback: function(r,rt) {
  112. if(!r.exc) {
  113. me.render(r.message);
  114. me.frm.toolbar.show_infobar();
  115. }
  116. },
  117. btn: this
  118. });
  119. }
  120. }
  121. me.dialog.fields_dict.assign_to.get_query = "webnotes.core.doctype.profile.profile.profile_query";
  122. }
  123. me.dialog.clear();
  124. (function toggle_restrict() {
  125. var can_restrict = wn.model.can_restrict(me.frm.doctype, me.frm);
  126. me.dialog.fields_dict.restrict.$wrapper.toggle(can_restrict);
  127. me.dialog.get_input("restrict").prop("checked", can_restrict);
  128. })();
  129. me.dialog.show();
  130. }
  131. });