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.
 
 
 
 
 
 

126 rader
3.3 KiB

  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.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:'Button', label:wn._("Add"), fieldname:'add_btn'}
  86. ]
  87. });
  88. me.dialog.fields_dict.add_btn.input.onclick = function() {
  89. var assign_to = me.dialog.fields_dict.assign_to.get_value();
  90. var args = me.dialog.get_values();
  91. if(assign_to) {
  92. return wn.call({
  93. method:'webnotes.widgets.form.assign_to.add',
  94. args: $.extend(args, {
  95. doctype: me.frm.doctype,
  96. name: me.frm.docname,
  97. assign_to: assign_to,
  98. }),
  99. callback: function(r,rt) {
  100. if(!r.exc) {
  101. me.render(r.message);
  102. me.frm.toolbar.show_infobar();
  103. }
  104. },
  105. btn: this
  106. });
  107. }
  108. }
  109. me.dialog.fields_dict.assign_to.get_query = "core.doctype.profile.profile.profile_query";
  110. }
  111. me.dialog.clear();
  112. me.dialog.show();
  113. }
  114. });