Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. this.appframe.add_module_icon(this.frm.meta.module);
  8. this.appframe.set_views_for(this.frm.meta.name, "form");
  9. },
  10. make: function() {
  11. this.appframe.clear_buttons();
  12. this.set_title();
  13. if(!this.frm.view_is_edit) {
  14. // print view
  15. this.show_print_toolbar();
  16. }
  17. this.show_title_as_dirty();
  18. if(this.frm.meta.hide_toolbar) {
  19. this.frm.save_disabled = true;
  20. return;
  21. }
  22. this.make_file_menu();
  23. this.show_infobar();
  24. },
  25. refresh: function() {
  26. this.make();
  27. },
  28. set_title: function() {
  29. var title = this.frm.docname;
  30. if(title.length > 30) {
  31. title = title.substr(0,30) + "...";
  32. }
  33. this.appframe.set_title(title, wn._(this.frm.docname));
  34. this.appframe.set_sub_title(wn._(this.frm.doctype));
  35. },
  36. show_infobar: function() {
  37. /* docs:
  38. Render info bar that shows timestamp, # of comments, # of attachments etc.
  39. only if saved doc. (doc.__islocal is falsy)
  40. */
  41. var me = this;
  42. this.appframe.clear_infobar();
  43. if(this.frm.doc.__islocal)
  44. return;
  45. this.appframe.add_infobar(
  46. wn.user.full_name(this.frm.doc.modified_by) + " / " + comment_when(this.frm.doc.modified), function() {
  47. msgprint("Created By: " + wn.user.full_name(me.frm.doc.owner) + "<br>" +
  48. "Created On: " + dateutil.str_to_user(me.frm.doc.creation) + "<br>" +
  49. "Last Modified By: " + wn.user.full_name(me.frm.doc.modified_by) + "<br>" +
  50. "Last Modifed On: " + dateutil.str_to_user(me.frm.doc.modified), "History");
  51. })
  52. this.make_infobar_docinfo_links();
  53. this.make_infobar_side_icons();
  54. },
  55. make_infobar_docinfo_links: function() {
  56. var me = this,
  57. docinfo = wn.model.docinfo[this.frm.doctype][this.frm.docname],
  58. comments = docinfo.comments.length,
  59. attachments = keys(docinfo.attachments).length,
  60. assignments = docinfo.assignments.length;
  61. var $li1 = this.appframe.add_infobar(
  62. (comments ? '<i class="icon-comments" style="font-size: 120%; color: orange"></i> ' : '')
  63. + comments + " "
  64. + (comments===1 ? wn._("Comment") : wn._("Comments")),
  65. function() {
  66. $('html, body').animate({
  67. scrollTop: $(me.frm.wrapper).find(".form-comments").offset().top
  68. }, 2000);
  69. });
  70. comments > 0 && $li1.addClass("bold");
  71. var $li2 = this.appframe.add_infobar(attachments + " " + (attachments===1 ?
  72. wn._("Attachment") : wn._("Attachments")),
  73. function() {
  74. $('html, body').animate({
  75. scrollTop: $(me.frm.wrapper).find(".form-attachments").offset().top
  76. }, 2000);
  77. });
  78. attachments > 0 && $li2.addClass("bold");
  79. var $li3 = this.appframe.add_infobar(assignments + " " + (assignments===1 ?
  80. wn._("Assignment") : wn._("Assignments")),
  81. function() {
  82. $('html, body').animate({
  83. scrollTop: $(me.frm.wrapper).find(".form-assignments").offset().top
  84. }, 2000);
  85. })
  86. assignments > 0 && $li3.addClass("bold");
  87. },
  88. make_infobar_side_icons: function() {
  89. var me = this;
  90. this.appframe.$w.find(".form-icon").remove();
  91. if(!this.frm.meta.issingle) {
  92. $('<i class="icon-arrow-right pull-right form-icon" title="Next Record"></i>')
  93. .click(function() {
  94. me.go_prev_next(false);
  95. })
  96. .appendTo(this.appframe.$w.find(".info-bar"));
  97. $('<i class="icon-arrow-left pull-right form-icon" title="Previous Record"></i>')
  98. .click(function() {
  99. me.go_prev_next(true);
  100. })
  101. .appendTo(this.appframe.$w.find(".info-bar"));
  102. }
  103. if(!me.frm.meta.allow_print) {
  104. $('<i class="icon-print pull-right form-icon" title="Print"></i>')
  105. .click(function() {
  106. me.frm.print_doc();
  107. })
  108. .appendTo(this.appframe.$w.find(".info-bar"));
  109. }
  110. if(!me.frm.meta.allow_email) {
  111. $('<i class="icon-envelope pull-right form-icon" title="Email"></i>')
  112. .click(function() {
  113. me.frm.email_doc();
  114. })
  115. .appendTo(this.appframe.$w.find(".info-bar"));
  116. }
  117. },
  118. show_print_toolbar: function() {
  119. var me = this;
  120. this.appframe.add_button("Edit", function() {
  121. me.frm.edit_doc();
  122. return false;
  123. }, 'icon-pencil')
  124. this.frm.$print_view_select =
  125. this.appframe.add_select("Print Format", this.frm.print_formats)
  126. .val(this.frm.print_formats[0])
  127. .change(function() {
  128. me.frm.refresh_print_layout();
  129. });
  130. },
  131. get_dropdown_menu: function(label) {
  132. return this.appframe.add_dropdown(label);
  133. },
  134. set_docstatus_label: function() {
  135. var status_bar_parent = this.frm.appframe.$w.find(".status-bar").empty();
  136. if(this.frm.meta.is_submittable && !this.frm.doc.__islocal) {
  137. var status_bar = $("<h4>")
  138. .css({"margin": "0px", "margin-top": "-15px"})
  139. .appendTo(status_bar_parent);
  140. switch(this.frm.doc.docstatus) {
  141. case 0:
  142. $('<span class="label"><i class="icon-unlock"> To Submit</span>')
  143. .appendTo(status_bar);
  144. break;
  145. case 1:
  146. $('<span class="label label-success"><i class="icon-lock"> Submitted</span>')
  147. .appendTo(status_bar);
  148. break;
  149. case 2:
  150. $('<span class="label label-danger"><i class="icon-remove"> Cancelled</span>')
  151. .appendTo(status_bar);
  152. break;
  153. }
  154. }
  155. },
  156. make_file_menu: function() {
  157. var me = this;
  158. var p = this.frm.perm[0];
  159. var docstatus = cint(this.frm.doc.docstatus);
  160. // New
  161. if(p[CREATE]) {
  162. this.appframe.add_dropdown_button("File", wn._("New") + " "
  163. + wn._(me.frm.doctype), function() {
  164. new_doc(me.frm.doctype);}, 'icon-plus');
  165. }
  166. // Save
  167. if(docstatus==0 && p[WRITE] && !this.read_only) {
  168. this.appframe.add_dropdown_button("File", wn._("Save"), function() {
  169. me.frm.save('Save', null, this);}, 'icon-save');
  170. }
  171. // Print
  172. if(!(me.frm.doc.__islocal || me.frm.meta.allow_print)) {
  173. this.appframe.add_dropdown_button("File", wn._("Print..."), function() {
  174. me.frm.print_doc();}, 'icon-print');
  175. }
  176. // email
  177. if(!(me.frm.doc.__islocal || me.frm.meta.allow_email)) {
  178. this.appframe.add_dropdown_button("File", wn._("Email..."), function() {
  179. me.frm.email_doc();}, 'icon-envelope');
  180. }
  181. // Linked With
  182. if(!me.frm.doc.__islocal && !me.frm.meta.issingle) {
  183. this.appframe.add_dropdown_button("File", wn._('Linked With'), function() {
  184. if(!me.frm.linked_with) {
  185. me.frm.linked_with = new wn.ui.form.LinkedWith({
  186. frm: me.frm
  187. });
  188. }
  189. me.frm.linked_with.show();
  190. }, "icon-link")
  191. }
  192. // copy
  193. if(in_list(profile.can_create, me.frm.doctype) && !me.frm.meta.allow_copy) {
  194. this.appframe.add_dropdown_button("File", wn._("Copy"), function() {
  195. me.frm.copy_doc();}, 'icon-file');
  196. }
  197. // rename
  198. if(me.frm.meta.allow_rename && me.frm.perm[0][WRITE]) {
  199. this.appframe.add_dropdown_button("File", wn._("Rename..."), function() {
  200. me.frm.rename_doc();}, 'icon-retweet');
  201. }
  202. // delete
  203. if((cint(me.frm.doc.docstatus) != 1) && !me.frm.doc.__islocal
  204. && wn.model.can_delete(me.frm.doctype)) {
  205. this.appframe.add_dropdown_button("File", wn._("Delete"), function() {
  206. me.frm.savetrash();}, 'icon-remove-sign');
  207. }
  208. },
  209. set_title_button: function() {
  210. var me = this;
  211. var docstatus = cint(this.frm.doc.docstatus);
  212. var p = this.frm.perm[0];
  213. var has_workflow = wn.model.get("Workflow", {document_type: me.frm.doctype}).length;
  214. // remove existing title buttons
  215. this.appframe.toolbar.find(".btn-title").remove();
  216. // Print Preview
  217. if(this.frm.meta.read_only_onload && !this.frm.doc.__islocal && this.frm.view_is_edit) {
  218. this.appframe.add_button(wn._('Preview'), function() {
  219. me.frm.last_view_is_edit[me.frm.docname] = 0;
  220. me.frm.refresh(); }, 'icon-print');
  221. }
  222. if(has_workflow && (this.frm.doc.__islocal || this.frm.doc.__unsaved)) {
  223. this.make_save_button();
  224. } else if(!has_workflow) {
  225. if(docstatus==0 && p[SUBMIT] && (!me.frm.doc.__islocal)
  226. && (!me.frm.doc.__unsaved)) {
  227. this.appframe.add_button('Submit', function() {
  228. me.frm.savesubmit(this);}, 'icon-lock', true)
  229. .removeClass("btn-default")
  230. .addClass("btn-primary");
  231. }
  232. else if(docstatus==0) {
  233. this.make_save_button();
  234. }
  235. else if(docstatus==1 && p[CANCEL]) {
  236. this.appframe.add_button('Cancel', function() {
  237. me.frm.savecancel(this) }, 'icon-remove');
  238. }
  239. else if(docstatus==2 && p[AMEND]) {
  240. this.appframe.add_button('Amend', function() {
  241. me.frm.amend_doc() }, 'icon-pencil', true);
  242. }
  243. }
  244. },
  245. make_save_button: function() {
  246. if(this.frm.save_disabled)
  247. return;
  248. var me = this;
  249. this.appframe.add_button('Save', function() {
  250. me.frm.save('Save', null, this);}, 'icon-save', true)
  251. .removeClass("btn-default")
  252. .addClass("btn-primary");
  253. },
  254. add_update_button_on_dirty: function() {
  255. var me = this;
  256. $(this.frm.wrapper).on("dirty", function() {
  257. me.show_title_as_dirty();
  258. // show update button if unsaved
  259. var docstatus = cint(me.frm.doc.docstatus);
  260. if(docstatus==1 && me.frm.perm[0][SUBMIT]
  261. && !me.appframe.$w.find(".action-update").length) {
  262. me.appframe.add_button("Update", function() {
  263. me.frm.save('Update', null, me);
  264. }, 'icon-save', true)
  265. .removeClass("btn-default")
  266. .addClass("btn-primary action-update");
  267. }
  268. })
  269. },
  270. show_title_as_dirty: function() {
  271. if(this.frm.save_disabled)
  272. return;
  273. this.appframe.get_title_area()
  274. .toggleClass("text-warning", this.frm.doc.__unsaved ? true : false);
  275. this.set_title_button();
  276. this.set_docstatus_label();
  277. },
  278. make_actions_menu: function() {
  279. if(this.actions_setup) return;
  280. var menu = this.get_dropdown_menu("Actions");
  281. this.actions_setup = true;
  282. },
  283. go_prev_next: function(prev) {
  284. var me = this;
  285. wn.call({
  286. method: "webnotes.widgets.form.utils.get_next",
  287. args: {
  288. doctype: me.frm.doctype,
  289. name: me.frm.docname,
  290. prev: prev ? 1 : 0
  291. },
  292. callback: function(r) {
  293. if(r.message)
  294. wn.set_route("Form", me.frm.doctype, r.message);
  295. }
  296. });
  297. },
  298. })