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

154 行
4.5 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 menu = this.get_dropdown_menu("File");
  25. var p = this.frm.perm[0];
  26. var docstatus = cint(this.frm.doc.docstatus);
  27. // New
  28. if(p[CREATE]) {
  29. this.appframe.add_dropdown_button("File", "New " + 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", "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", "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", "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", "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", "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", "Delete", function() {
  61. me.frm.savetrash();}, 'icon-remove-sign');
  62. }
  63. },
  64. make_view_menu: function() {
  65. var me = this;
  66. var menu = this.get_dropdown_menu("View");
  67. // Edit
  68. if(this.frm.meta.read_only_onload && !this.frm.doc.__islocal) {
  69. this.appframe.add_dropdown_button("View", 'Print View', function() {
  70. me.frm.last_view_is_edit[me.frm.docname] = 0;
  71. me.frm.refresh(); }, 'icon-print');
  72. }
  73. if(this.frm.meta.read_only_onload && !this.frm.doc.__islocal) {
  74. this.appframe.add_dropdown_button("View", 'Edit', function() {
  75. me.frm.last_view_is_edit[me.frm.docname] = 1;
  76. me.frm.refresh(); }, 'icon-edit');
  77. }
  78. // Linked With
  79. if(!me.frm.doc.__islocal && !me.frm.meta.issingle) {
  80. this.appframe.add_dropdown_button("View", 'Linked With', function() {
  81. if(!me.frm.linked_with) {
  82. me.frm.linked_with = new wn.ui.form.LinkedWith({
  83. frm: me.frm
  84. });
  85. }
  86. me.frm.linked_with.show();
  87. }, "icon-link")
  88. }
  89. },
  90. set_title_button: function() {
  91. var me = this;
  92. this.appframe.$w.find(".title-button-area").empty();
  93. var docstatus = cint(this.frm.doc.docstatus);
  94. var p = this.frm.perm[0];
  95. if(!wn.model.get("Workflow", {document_type: me.frm.doctype}).length) {
  96. if(docstatus==0 && p[SUBMIT] && (!me.frm.doc.__islocal)) {
  97. this.appframe.add_title_button('Submit', function() {
  98. me.frm.savesubmit(this);}, 'icon-lock');
  99. }
  100. else if(docstatus==0) {
  101. this.appframe.add_title_button('Save', function() {
  102. me.frm.save('Save', null, this);}, 'icon-save');
  103. }
  104. else if(docstatus==1 && p[CANCEL]) {
  105. this.appframe.add_title_button('Cancel', function() {
  106. me.frm.savecancel(this) }, 'icon-remove');
  107. }
  108. else if(docstatus==2 && p[AMEND]) {
  109. this.appframe.add_title_button('Amend', function() {
  110. me.frm.amend_doc() }, 'icon-pencil');
  111. }
  112. }
  113. },
  114. add_update_button_on_dirty: function() {
  115. var me = this;
  116. $(this.frm.wrapper).on("dirty", function() {
  117. me.show_title_as_dirty();
  118. // show update button if unsaved
  119. var docstatus = cint(me.frm.doc.docstatus);
  120. if(me.frm.doc.__unsaved && docstatus==1 && me.frm.perm[0][SUBMIT]) {
  121. me.appframe.add_dropdown_button("File", "Update", function() {
  122. me.frm.save('Update', null, me);
  123. }, '').html(wn._('Update'))
  124. }
  125. })
  126. },
  127. show_title_as_dirty: function() {
  128. if(this.frm.doc.__unsaved) {
  129. this.appframe.get_title_area().addClass("text-warning");
  130. } else {
  131. this.appframe.get_title_area().removeClass("text-warning");
  132. }
  133. },
  134. make_actions_menu: function() {
  135. if(this.actions_setup) return;
  136. var menu = this.get_dropdown_menu("Actions");
  137. this.actions_setup = true;
  138. },
  139. refresh: function() {
  140. this.make();
  141. }
  142. })