選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

226 行
6.8 KiB

  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. wn.provide("wn.ui.form");
  4. wn.ui.form.Toolbar = Class.extend({
  5. init: function(opts) {
  6. $.extend(this, opts);
  7. this.make();
  8. this.add_update_button_on_dirty();
  9. this.appframe.add_module_icon(this.frm.meta.module, this.frm.doctype);
  10. this.appframe.set_views_for(this.frm.meta.name, "form");
  11. },
  12. make: function() {
  13. this.appframe.set_title_right(); // clear
  14. this.set_title();
  15. this.show_title_as_dirty();
  16. if(this.frm.meta.hide_toolbar) {
  17. this.frm.save_disabled = true;
  18. this.appframe.iconbar.hide();
  19. } else {
  20. this.appframe.iconbar.clear(1)
  21. this.make_file_menu();
  22. this.make_cancel_amend_button();
  23. this.show_infobar();
  24. if(this.frm.doc.__islocal) {
  25. this.appframe.iconbar.hide(2);
  26. this.appframe.iconbar.hide(3);
  27. } else {
  28. this.appframe.iconbar.show(2);
  29. this.appframe.iconbar.show(3);
  30. }
  31. }
  32. },
  33. refresh: function() {
  34. this.make();
  35. },
  36. set_title: function() {
  37. var title = wn._(this.frm.docname);
  38. var me = this;
  39. this.appframe.set_title(title + this.get_lock_status(), wn._(this.frm.docname),
  40. this.frm.doc.modified_by);
  41. if(this.frm.meta.issingle) {
  42. this.appframe.set_title_left('<i class="icon-angle-left"></i> ' + wn._(this.frm.meta.module),
  43. function() { wn.set_route(wn.modules[me.frm.meta.module].link); });
  44. } else {
  45. this.appframe.set_title_left('<i class="icon-angle-left"></i> ' + wn._(this.frm.doctype),
  46. function() { wn.set_route("List", me.frm.doctype); });
  47. }
  48. },
  49. show_infobar: function() {
  50. /* docs:
  51. Render info bar that shows timestamp, # of comments, # of attachments etc.
  52. only if saved doc. (doc.__islocal is falsy)
  53. */
  54. if(this.infobar)
  55. this.infobar.refresh();
  56. else
  57. this.infobar = new wn.ui.form.InfoBar({appframe:this.appframe, frm:this.frm});
  58. },
  59. get_dropdown_menu: function(label) {
  60. return this.appframe.add_dropdown(label);
  61. },
  62. get_lock_status: function() {
  63. if(this.frm.meta.is_submittable && !this.frm.doc.__islocal) {
  64. switch(this.frm.doc.docstatus) {
  65. case 0:
  66. return ' <i class="icon-unlock text-muted" title="Not Submitted">';
  67. case 1:
  68. return ' <i class="icon-lock text-primary" title="Submitted">';
  69. case 2:
  70. return ' <i class="icon-remove text-danger" title="Cancelled">';
  71. }
  72. } else {
  73. return "";
  74. }
  75. },
  76. make_file_menu: function() {
  77. var me = this;
  78. var p = this.frm.perm[0];
  79. var docstatus = cint(this.frm.doc.docstatus);
  80. $(".custom-menu").remove();
  81. // New
  82. if(p[CREATE]) {
  83. this.appframe.add_dropdown_button("File", wn._("New") + " "
  84. + wn._(me.frm.doctype), function() {
  85. new_doc(me.frm.doctype);}, 'icon-plus');
  86. }
  87. // Save
  88. if(docstatus==0 && p[WRITE] && !this.read_only) {
  89. this.appframe.add_dropdown_button("File", wn._("Save"), function() {
  90. me.frm.save('Save', null, this);}, 'icon-save');
  91. }
  92. // Submit
  93. if(docstatus==0 && !this.frm.doc.__unsaved && p[SUBMIT] && !this.read_only) {
  94. this.appframe.add_dropdown_button("File", wn._("Submit"), function() {
  95. me.frm.savesubmit(this);}, 'icon-lock');
  96. }
  97. // Cancel
  98. if(docstatus==1 && p[CANCEL] && !this.read_only) {
  99. this.appframe.add_dropdown_button("File", wn._("Cancel"), function() {
  100. me.frm.savecancel(this);}, 'icon-remove');
  101. }
  102. // Amend
  103. if(docstatus==2 && p[AMEND] && !this.read_only) {
  104. this.appframe.add_dropdown_button("File", wn._("Amend"), function() {
  105. me.frm.amend_doc();}, 'icon-pencil');
  106. this.appframe.set_title_right("Amend", function() { me.frm.amend_doc(); });
  107. }
  108. // Print
  109. if(!(me.frm.doc.__islocal || me.frm.meta.allow_print)) {
  110. this.appframe.add_dropdown_button("File", wn._("Print..."), function() {
  111. me.frm.print_doc();}, 'icon-print');
  112. }
  113. // email
  114. if(!(me.frm.doc.__islocal || me.frm.meta.allow_email)) {
  115. this.appframe.add_dropdown_button("File", wn._("Email..."), function() {
  116. me.frm.email_doc();}, 'icon-envelope');
  117. }
  118. // Linked With
  119. if(!me.frm.doc.__islocal && !me.frm.meta.issingle) {
  120. this.appframe.add_dropdown_button("File", wn._('Linked With'), function() {
  121. me.show_linked_with();
  122. }, "icon-link")
  123. }
  124. // copy
  125. if(in_list(profile.can_create, me.frm.doctype) && !me.frm.meta.allow_copy) {
  126. this.appframe.add_dropdown_button("File", wn._("Copy"), function() {
  127. me.frm.copy_doc();}, 'icon-file');
  128. }
  129. // rename
  130. if(me.frm.meta.allow_rename && me.frm.perm[0].write) {
  131. this.appframe.add_dropdown_button("File", wn._("Rename..."), function() {
  132. me.frm.rename_doc();}, 'icon-retweet');
  133. }
  134. // delete
  135. if((cint(me.frm.doc.docstatus) != 1) && !me.frm.doc.__islocal
  136. && wn.model.can_delete(me.frm.doctype)) {
  137. this.appframe.add_dropdown_button("File", wn._("Delete"), function() {
  138. me.frm.savetrash();}, 'icon-remove-sign');
  139. }
  140. },
  141. show_linked_with: function() {
  142. if(!this.frm.linked_with) {
  143. this.frm.linked_with = new wn.ui.form.LinkedWith({
  144. frm: this.frm
  145. });
  146. }
  147. this.frm.linked_with.show();
  148. },
  149. set_title_button: function() {
  150. var me = this;
  151. var docstatus = cint(this.frm.doc.docstatus);
  152. var p = this.frm.perm[0];
  153. var has_workflow = wn.model.get("Workflow", {document_type: me.frm.doctype}).length;
  154. if(has_workflow && (this.frm.doc.__islocal || this.frm.doc.__unsaved)) {
  155. this.make_save_button();
  156. } else if(!has_workflow) {
  157. if(docstatus==0 && p[SUBMIT] && (!me.frm.doc.__islocal)
  158. && (!me.frm.doc.__unsaved)) {
  159. this.appframe.set_title_right("Submit", function() { me.frm.savesubmit(this); } );
  160. }
  161. else if(docstatus==0) {
  162. this.make_save_button();
  163. }
  164. }
  165. },
  166. make_cancel_amend_button: function() {
  167. var me = this;
  168. var docstatus = cint(this.frm.doc.docstatus);
  169. var p = this.frm.perm[0];
  170. var has_workflow = wn.model.get("Workflow", {document_type: me.frm.doctype}).length;
  171. if(has_workflow) {
  172. return;
  173. } else if(docstatus==1 && p[CANCEL]) {
  174. this.appframe.add_button('Cancel', function() {
  175. me.frm.savecancel(this) }, 'icon-remove');
  176. } else if(docstatus==2 && p[AMEND]) {
  177. this.appframe.add_button('Amend', function() {
  178. me.frm.amend_doc() }, 'icon-pencil', true);
  179. }
  180. },
  181. make_save_button: function() {
  182. if(this.frm.save_disabled)
  183. return;
  184. var me = this;
  185. this.appframe.set_title_right("Save", function() { me.frm.save('Save', null, this); } );
  186. },
  187. add_update_button_on_dirty: function() {
  188. var me = this;
  189. $(this.frm.wrapper).on("dirty", function() {
  190. me.show_title_as_dirty();
  191. // show update button if unsaved
  192. var docstatus = cint(me.frm.doc.docstatus);
  193. if(docstatus==1 && me.frm.perm[0].submit) {
  194. this.appframe.set_title_right("Update", function() { me.frm.save('Update', null, this); } );
  195. }
  196. })
  197. },
  198. show_title_as_dirty: function() {
  199. if(this.frm.save_disabled)
  200. return;
  201. this.appframe.get_title_area()
  202. .toggleClass("text-warning", this.frm.doc.__unsaved ? true : false);
  203. this.set_title();
  204. this.set_title_button();
  205. }
  206. })