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.
 
 
 
 
 
 

165 lines
5.0 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. if(!wn.model.get("Workflow", {document_type: me.frm.doctype}).length) {
  106. if(docstatus==0 && p[SUBMIT] && (!me.frm.doc.__islocal)) {
  107. this.appframe.add_button('Submit', function() {
  108. me.frm.savesubmit(this);}, 'icon-lock', true).addClass("btn-primary");
  109. }
  110. else if(docstatus==0) {
  111. this.appframe.add_button('Save', function() {
  112. me.frm.save('Save', null, this);}, 'icon-save', true).addClass("btn-primary");
  113. }
  114. else if(docstatus==1 && p[CANCEL]) {
  115. this.appframe.add_dropdown_button("File", 'Cancel', function() {
  116. me.frm.savecancel(this) }, 'icon-remove');
  117. }
  118. else if(docstatus==2 && p[AMEND]) {
  119. this.appframe.add_button('Amend', function() {
  120. me.frm.amend_doc() }, 'icon-pencil', true);
  121. }
  122. }
  123. },
  124. add_update_button_on_dirty: function() {
  125. var me = this;
  126. $(this.frm.wrapper).on("dirty", function() {
  127. me.show_title_as_dirty();
  128. // show update button if unsaved
  129. var docstatus = cint(me.frm.doc.docstatus);
  130. if(docstatus==1 && me.frm.perm[0][SUBMIT]
  131. && !me.appframe.$w.find(".action-update").length) {
  132. me.appframe.add_button("Update", function() {
  133. me.frm.save('Update', null, me);
  134. }, 'icon-save', true).addClass("btn-primary action-update");
  135. }
  136. })
  137. },
  138. show_title_as_dirty: function() {
  139. this.appframe.get_title_area()
  140. .toggleClass("text-warning", this.frm.doc.__unsaved);
  141. },
  142. make_actions_menu: function() {
  143. if(this.actions_setup) return;
  144. var menu = this.get_dropdown_menu("Actions");
  145. this.actions_setup = true;
  146. },
  147. refresh: function() {
  148. this.make();
  149. }
  150. })