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.
 
 
 
 
 
 

172 rader
5.2 KiB

  1. wn.provide("wn.ui.form");
  2. wn.ui.form.Toolbar = Class.extend({
  3. init: function(opts) {
  4. $.extend(this, opts);
  5. this.make();
  6. this.add_update_button_on_dirty();
  7. },
  8. make: function() {
  9. if(this.frm.meta.hide_toolbar) {
  10. this.frm.save_disabled = true;
  11. return;
  12. }
  13. this.appframe.clear_buttons();
  14. this.make_file_menu();
  15. this.make_view_menu();
  16. this.set_title_button();
  17. this.show_title_as_dirty();
  18. },
  19. get_dropdown_menu: function(label) {
  20. return this.appframe.add_dropdown(label);
  21. },
  22. make_file_menu: function() {
  23. var me = this;
  24. var p = this.frm.perm[0];
  25. var docstatus = cint(this.frm.doc.docstatus);
  26. // New
  27. if(p[CREATE]) {
  28. this.appframe.add_dropdown_button("File", wn._("New") + " "
  29. + wn._(me.frm.doctype), function() {
  30. new_doc(me.frm.doctype);}, 'icon-plus');
  31. }
  32. // Save
  33. if(docstatus==0 && p[WRITE] && !this.read_only) {
  34. this.appframe.add_dropdown_button("File", wn._("Save"), function() {
  35. me.frm.save('Save', null, this);}, 'icon-save');
  36. }
  37. // Print
  38. if(!(me.frm.doc.__islocal || me.frm.meta.allow_print)) {
  39. this.appframe.add_dropdown_button("File", wn._("Print..."), function() {
  40. me.frm.print_doc();}, 'icon-print');
  41. }
  42. // email
  43. if(!(me.frm.doc.__islocal || me.frm.meta.allow_email)) {
  44. this.appframe.add_dropdown_button("File", wn._("Email..."), function() {
  45. me.frm.email_doc();}, 'icon-envelope');
  46. }
  47. // copy
  48. if(in_list(profile.can_create, me.frm.doctype) && !me.frm.meta.allow_copy) {
  49. this.appframe.add_dropdown_button("File", wn._("Make Copy"), function() {
  50. me.frm.copy_doc();}, 'icon-file');
  51. }
  52. // rename
  53. if(me.frm.meta.allow_rename && me.frm.perm[0][WRITE]) {
  54. this.appframe.add_dropdown_button("File", wn._("Rename..."), function() {
  55. me.frm.rename_doc();}, 'icon-retweet');
  56. }
  57. // delete
  58. if((cint(me.frm.doc.docstatus) != 1) && !me.frm.doc.__islocal
  59. && wn.model.can_delete(me.frm.doctype)) {
  60. this.appframe.add_dropdown_button("File", wn._("Delete"), function() {
  61. me.frm.savetrash();}, 'icon-remove-sign');
  62. }
  63. },
  64. make_view_menu: function() {
  65. var me = this;
  66. // Edit
  67. if(this.frm.meta.read_only_onload && !this.frm.doc.__islocal) {
  68. this.appframe.add_dropdown_button("View", wn._('Print View'), function() {
  69. me.frm.last_view_is_edit[me.frm.docname] = 0;
  70. me.frm.refresh(); }, 'icon-print');
  71. }
  72. if(this.frm.meta.read_only_onload && !this.frm.doc.__islocal) {
  73. this.appframe.add_dropdown_button("View", wn._('Edit'), function() {
  74. me.frm.last_view_is_edit[me.frm.docname] = 1;
  75. me.frm.refresh(); }, 'icon-edit');
  76. }
  77. // Linked With
  78. if(!me.frm.doc.__islocal && !me.frm.meta.issingle) {
  79. this.appframe.add_dropdown_button("View", wn._('Linked With'), function() {
  80. if(!me.frm.linked_with) {
  81. me.frm.linked_with = new wn.ui.form.LinkedWith({
  82. frm: me.frm
  83. });
  84. }
  85. me.frm.linked_with.show();
  86. }, "icon-link")
  87. }
  88. if(!this.frm.meta.issingle) {
  89. this.appframe.add_menu_divider("View");
  90. this.appframe.add_dropdown_button("View",
  91. wn._(this.frm.doctype) + ' ' + wn._('List'), function() {
  92. wn.set_route("List", me.frm.doctype);
  93. }, 'icon-list');
  94. this.appframe.add_dropdown_button("View",
  95. wn._(this.frm.doctype) + ' ' + wn._('Report View'), function() {
  96. wn.set_route("Report2", me.frm.doctype);
  97. }, 'icon-table');
  98. }
  99. },
  100. set_title_button: function() {
  101. var me = this;
  102. this.appframe.$w.find(".title-button-area").empty();
  103. var docstatus = cint(this.frm.doc.docstatus);
  104. var p = this.frm.perm[0];
  105. var has_workflow = wn.model.get("Workflow", {document_type: me.frm.doctype}).length;
  106. if(has_workflow && this.frm.doc.__islocal) {
  107. this.make_save_button();
  108. } else if(!has_workflow) {
  109. if(docstatus==0 && p[SUBMIT] && (!me.frm.doc.__islocal)) {
  110. this.appframe.add_button('Submit', function() {
  111. me.frm.savesubmit(this);}, 'icon-lock', true).addClass("btn-primary");
  112. }
  113. else if(docstatus==0) {
  114. this.make_save_button();
  115. }
  116. else if(docstatus==1 && p[CANCEL]) {
  117. this.appframe.add_dropdown_button("File", 'Cancel', function() {
  118. me.frm.savecancel(this) }, 'icon-remove');
  119. }
  120. else if(docstatus==2 && p[AMEND]) {
  121. this.appframe.add_button('Amend', function() {
  122. me.frm.amend_doc() }, 'icon-pencil', true);
  123. }
  124. }
  125. },
  126. make_save_button: function() {
  127. var me = this;
  128. this.appframe.add_button('Save', function() {
  129. me.frm.save('Save', null, this);}, 'icon-save', true).addClass("btn-primary");
  130. },
  131. add_update_button_on_dirty: function() {
  132. var me = this;
  133. $(this.frm.wrapper).on("dirty", function() {
  134. me.show_title_as_dirty();
  135. // show update button if unsaved
  136. var docstatus = cint(me.frm.doc.docstatus);
  137. if(docstatus==1 && me.frm.perm[0][SUBMIT]
  138. && !me.appframe.$w.find(".action-update").length) {
  139. me.appframe.add_button("Update", function() {
  140. me.frm.save('Update', null, me);
  141. }, 'icon-save', true).addClass("btn-primary action-update");
  142. }
  143. })
  144. },
  145. show_title_as_dirty: function() {
  146. this.appframe.get_title_area()
  147. .toggleClass("text-warning", this.frm.doc.__unsaved);
  148. },
  149. make_actions_menu: function() {
  150. if(this.actions_setup) return;
  151. var menu = this.get_dropdown_menu("Actions");
  152. this.actions_setup = true;
  153. },
  154. refresh: function() {
  155. this.make();
  156. }
  157. })