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.
 
 
 
 
 
 

810 lines
20 KiB

  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. /* Form page structure
  4. + this.parent (either FormContainer or Dialog)
  5. + this.wrapper
  6. + this.toolbar
  7. + this.form_wrapper
  8. + this.head
  9. + this.body
  10. + this.layout
  11. + this.sidebar
  12. + this.footer
  13. */
  14. wn.provide('_f');
  15. wn.provide('wn.ui.form');
  16. wn.ui.form.Controller = Class.extend({
  17. init: function(opts) {
  18. $.extend(this, opts);
  19. this.setup && this.setup();
  20. }
  21. });
  22. _f.frms = {};
  23. _f.Frm = function(doctype, parent, in_form) {
  24. this.docname = '';
  25. this.doctype = doctype;
  26. this.display = 0;
  27. this.refresh_if_stale_for = 120;
  28. var me = this;
  29. this.opendocs = {};
  30. this.sections = [];
  31. this.grids = [];
  32. this.cscript = new wn.ui.form.Controller({frm:this});
  33. this.pformat = {};
  34. this.fetch_dict = {};
  35. this.parent = parent;
  36. this.tinymce_id_list = [];
  37. this.setup_meta(doctype);
  38. // show in form instead of in dialog, when called using url (router.js)
  39. this.in_form = in_form ? true : false;
  40. // notify on rename
  41. var me = this;
  42. $(document).on('rename', function(event, dt, old_name, new_name) {
  43. if(dt==me.doctype)
  44. me.rename_notify(dt, old_name, new_name)
  45. });
  46. }
  47. _f.Frm.prototype.check_doctype_conflict = function(docname) {
  48. var me = this;
  49. if(this.doctype=='DocType' && docname=='DocType') {
  50. msgprint('Allowing DocType, DocType. Be careful!')
  51. } else if(this.doctype=='DocType') {
  52. if (wn.views.formview[docname] || wn.pages['List/'+docname]) {
  53. msgprint("Cannot open DocType when its instance is open")
  54. throw 'doctype open conflict'
  55. }
  56. } else {
  57. if (wn.views.formview.DocType && wn.views.formview.DocType.frm.opendocs[this.doctype]) {
  58. msgprint("Cannot open instance when its DocType is open")
  59. throw 'doctype open conflict'
  60. }
  61. }
  62. }
  63. _f.Frm.prototype.setup = function() {
  64. var me = this;
  65. this.fields = [];
  66. this.fields_dict = {};
  67. this.state_fieldname = wn.workflow.get_state_fieldname(this.doctype);
  68. // wrapper
  69. this.wrapper = this.parent;
  70. wn.ui.make_app_page({
  71. parent: this.wrapper,
  72. single_column: true
  73. });
  74. this.appframe = this.wrapper.appframe;
  75. this.layout_main = $(this.wrapper)
  76. .find(".layout-main")
  77. .css({"padding-bottom": "0px"})
  78. .get(0);
  79. this.toolbar = new wn.ui.form.Toolbar({
  80. frm: this,
  81. appframe: this.appframe
  82. });
  83. this.frm_head = this.toolbar;
  84. // print layout
  85. this.setup_print_layout();
  86. // 2 column layout
  87. this.setup_std_layout();
  88. // client script must be called after "setup" - there are no fields_dict attached to the frm otherwise
  89. this.script_manager = new wn.ui.form.ScriptManager({
  90. frm: this
  91. });
  92. this.script_manager.setup();
  93. this.watch_model_updates();
  94. this.footer = new wn.ui.form.Footer({
  95. frm: this,
  96. parent: $(this.wrapper).find(".appframe-footer")
  97. })
  98. this.setup_done = true;
  99. }
  100. _f.Frm.prototype.setup_print_layout = function() {
  101. this.print_wrapper = $('<div>\
  102. <div class="print-toolbar row" style="background-color: #eee; \
  103. padding-top: 5px; padding-bottom: 5px; margin-top: -15px; \
  104. margin-bottom: 15px; padding-left: 15px; position:relative;">\
  105. <i class="text-muted icon-print" style="position: absolute; top: 13px; left: 10px; "></i>\
  106. <div class="col-xs-3">\
  107. <select class="print-preview-select form-control"></select></div>\
  108. <div class="col-xs-3" style="padding-top: 7px;">\
  109. <input type="checkbox" class="print-letterhead" checked/> Letterhead</div>\
  110. <div class="col-xs-6 text-right" style="padding-top: 7px;">\
  111. <a style="margin-right: 7px;" class="print-print">Print</a>\
  112. <a class="close">×</a>\
  113. </div>\
  114. </div>\
  115. <div class="print-preview">\
  116. </div>\
  117. </div>')
  118. .appendTo(this.layout_main)
  119. .toggle(false);
  120. var me = this;
  121. this.print_wrapper.find(".close").click(function() {
  122. me.hide_print();
  123. });
  124. this.print_formats = wn.meta.get_print_formats(this.meta.name);
  125. this.print_letterhead = this.print_wrapper
  126. .find(".print-letterhead")
  127. .on("change", function() { me.print_sel.trigger("change"); });
  128. this.print_sel = this.print_wrapper
  129. .find(".print-preview-select")
  130. .on("change", function() {
  131. _p.build(me.print_sel.val(), function(html) {
  132. me.print_wrapper.find(".print-preview").html(html);
  133. }, !me.print_letterhead.is(":checked"), true, true);
  134. })
  135. this.print_wrapper.find(".print-print").click(function() {
  136. _p.build(
  137. me.print_sel.val(), // fmtname
  138. _p.go, // onload
  139. !me.print_letterhead.is(":checked") // no_letterhead
  140. );
  141. })
  142. }
  143. _f.Frm.prototype.print_doc = function() {
  144. if(this.print_wrapper.is(":visible")) {
  145. this.hide_print();
  146. return;
  147. }
  148. if(!wn.model.can_print(this.doc.doctype, cur_frm)) {
  149. msgprint(wn._("You are not allowed to Print this document."));
  150. return;
  151. }
  152. if(this.doc.docstatus==2) {
  153. msgprint(wn._("Cannot Print Cancelled Documents."));
  154. return;
  155. }
  156. this.print_wrapper.toggle(true);
  157. this.print_sel
  158. .empty().add_options(this.print_formats)
  159. .trigger("change");
  160. this.form_wrapper.toggle(false);
  161. }
  162. _f.Frm.prototype.hide_print = function() {
  163. if(this.setup_done) {
  164. this.print_wrapper.toggle(false);
  165. this.form_wrapper.toggle(true);
  166. }
  167. }
  168. _f.Frm.prototype.watch_model_updates = function() {
  169. // watch model updates
  170. var me = this;
  171. // on main doc
  172. wn.model.on(me.doctype, "*", function(fieldname, value, doc) {
  173. // set input
  174. if(doc.name===me.docname) {
  175. me.dirty();
  176. me.fields_dict[fieldname]
  177. && me.fields_dict[fieldname].refresh(fieldname);
  178. me.refresh_dependency();
  179. me.script_manager.trigger(fieldname, doc.doctype, doc.name);
  180. }
  181. })
  182. // on table fields
  183. $.each(wn.model.get("DocField", {fieldtype:"Table", parent: me.doctype}), function(i, df) {
  184. wn.model.on(df.options, "*", function(fieldname, value, doc) {
  185. if(doc.parent===me.docname && doc.parentfield===df.fieldname) {
  186. me.dirty();
  187. me.fields_dict[df.fieldname].grid.set_value(fieldname, value, doc);
  188. me.script_manager.trigger(fieldname, doc.doctype, doc.name);
  189. }
  190. })
  191. })
  192. }
  193. _f.Frm.prototype.onhide = function() {
  194. if(_f.cur_grid_cell) _f.cur_grid_cell.grid.cell_deselect();
  195. }
  196. _f.Frm.prototype.setup_std_layout = function() {
  197. this.form_wrapper = $('<div></div>').appendTo(this.layout_main);
  198. this.body_header = $("<div>").appendTo(this.form_wrapper);
  199. this.body = $("<div>").appendTo(this.form_wrapper);
  200. // only tray
  201. this.meta.section_style='Simple'; // always simple!
  202. // layout
  203. this.layout = new wn.ui.form.Layout({
  204. parent: this.body,
  205. doctype: this.doctype,
  206. frm: this,
  207. });
  208. this.layout.make();
  209. this.fields_dict = this.layout.fields_dict;
  210. this.fields = this.layout.fields_list;
  211. this.dashboard = new wn.ui.form.Dashboard({
  212. frm: this,
  213. });
  214. // state
  215. this.states = new wn.ui.form.States({
  216. frm: this
  217. });
  218. }
  219. // email the form
  220. _f.Frm.prototype.email_doc = function(message) {
  221. new wn.views.CommunicationComposer({
  222. doc: this.doc,
  223. subject: wn._(this.meta.name) + ': ' + this.docname,
  224. recipients: this.doc.email || this.doc.email_id || this.doc.contact_email,
  225. attach_document_print: true,
  226. message: message,
  227. real_name: this.doc.real_name || this.doc.contact_display || this.doc.contact_name
  228. });
  229. }
  230. // rename the form
  231. _f.Frm.prototype.rename_doc = function() {
  232. wn.model.rename_doc(this.doctype, this.docname);
  233. }
  234. // notify this form of renamed records
  235. _f.Frm.prototype.rename_notify = function(dt, old, name) {
  236. // from form
  237. if(this.meta.istable)
  238. return;
  239. if(this.docname == old)
  240. this.docname = name;
  241. else
  242. return;
  243. // cleanup
  244. if(this && this.opendocs[old]) {
  245. // delete docfield copy
  246. wn.meta.docfield_copy[dt][name] = wn.meta.docfield_copy[dt][old];
  247. delete wn.meta.docfield_copy[dt][old];
  248. }
  249. delete this.opendocs[old];
  250. this.opendocs[name] = true;
  251. if(this.meta.in_dialog || !this.in_form) {
  252. return;
  253. }
  254. wn.re_route[window.location.hash] = '#Form/' + encodeURIComponent(this.doctype) + '/' + encodeURIComponent(name);
  255. wn.set_route('Form', this.doctype, name);
  256. }
  257. // SETUP
  258. _f.Frm.prototype.setup_meta = function(doctype) {
  259. this.meta = wn.model.get_doc('DocType',this.doctype);
  260. this.perm = wn.perm.get_perm(this.doctype); // for create
  261. if(this.meta.istable) { this.meta.in_dialog = 1 }
  262. }
  263. _f.Frm.prototype.defocus_rest = function() {
  264. // deselect others
  265. if(_f.cur_grid_cell) _f.cur_grid_cell.grid.cell_deselect();
  266. }
  267. _f.Frm.prototype.refresh_header = function() {
  268. // set title
  269. // main title
  270. if(!this.meta.in_dialog || this.in_form) {
  271. set_title(this.meta.issingle ? this.doctype : this.docname);
  272. }
  273. if(wn.ui.toolbar.recent)
  274. wn.ui.toolbar.recent.add(this.doctype, this.docname, 1);
  275. // show / hide buttons
  276. if(this.frm_head) {
  277. this.frm_head.refresh();
  278. }
  279. }
  280. _f.Frm.prototype.check_doc_perm = function() {
  281. // get perm
  282. var dt = this.parent_doctype?this.parent_doctype : this.doctype;
  283. var dn = this.parent_docname?this.parent_docname : this.docname;
  284. this.perm = wn.perm.get_perm(dt, dn);
  285. if(!this.perm[0].read) {
  286. return 0;
  287. }
  288. return 1
  289. }
  290. _f.Frm.prototype.refresh = function(docname) {
  291. // record switch
  292. if(docname) {
  293. if(this.docname != docname && (!this.meta.in_dialog || this.in_form) &&
  294. !this.meta.istable) {
  295. scroll(0, 0);
  296. this.hide_print();
  297. }
  298. this.docname = docname;
  299. }
  300. cur_frm = this;
  301. if(this.docname) { // document to show
  302. // check permissions
  303. if(!this.check_doc_perm()) return;
  304. // read only (workflow)
  305. this.read_only = wn.workflow.is_read_only(this.doctype, this.docname);
  306. // set the doc
  307. this.doc = wn.model.get_doc(this.doctype, this.docname);
  308. // check if doctype is already open
  309. if (!this.opendocs[this.docname]) {
  310. this.check_doctype_conflict(this.docname);
  311. } else {
  312. if(this.doc && (!this.doc.__unsaved) && this.doc.__last_sync_on &&
  313. (new Date() - this.doc.__last_sync_on) > (this.refresh_if_stale_for * 1000)) {
  314. this.reload_doc();
  315. return;
  316. }
  317. }
  318. // do setup
  319. if(!this.setup_done) this.setup();
  320. // load the record for the first time, if not loaded (call 'onload')
  321. cur_frm.cscript.is_onload = false;
  322. if(!this.opendocs[this.docname]) {
  323. cur_frm.cscript.is_onload = true;
  324. this.setnewdoc();
  325. } else {
  326. this.render_form();
  327. }
  328. }
  329. }
  330. _f.Frm.prototype.render_form = function() {
  331. if(!this.meta.istable) {
  332. // header
  333. this.refresh_header();
  334. // call trigger
  335. this.script_manager.trigger("refresh");
  336. // trigger global trigger
  337. // to use this
  338. $(document).trigger('form_refresh');
  339. // fields
  340. this.refresh_fields();
  341. // call onload post render for callbacks to be fired
  342. if(this.cscript.is_onload) {
  343. this.script_manager.trigger("onload_post_render");
  344. }
  345. // focus on first input
  346. if(this.doc.docstatus==0) {
  347. var first = this.form_wrapper.find('.form-layout-row :input:first');
  348. if(!in_list(["Date", "Datetime"], first.attr("data-fieldtype"))) {
  349. first.focus();
  350. }
  351. }
  352. } else {
  353. this.refresh_header();
  354. }
  355. $(cur_frm.wrapper).trigger('render_complete');
  356. }
  357. _f.Frm.prototype.refresh_field = function(fname) {
  358. cur_frm.fields_dict[fname] && cur_frm.fields_dict[fname].refresh
  359. && cur_frm.fields_dict[fname].refresh();
  360. }
  361. _f.Frm.prototype.refresh_fields = function() {
  362. this.layout.refresh(this.doc);
  363. this.layout.primary_button = $(this.wrapper).find(".btn-primary");
  364. // cleanup activities after refresh
  365. this.cleanup_refresh(this);
  366. // dependent fields
  367. this.refresh_dependency();
  368. }
  369. _f.Frm.prototype.cleanup_refresh = function() {
  370. var me = this;
  371. if(me.fields_dict['amended_from']) {
  372. if (me.doc.amended_from) {
  373. unhide_field('amended_from');
  374. if (me.fields_dict['amendment_date']) unhide_field('amendment_date');
  375. } else {
  376. hide_field('amended_from');
  377. if (me.fields_dict['amendment_date']) hide_field('amendment_date');
  378. }
  379. }
  380. if(me.fields_dict['trash_reason']) {
  381. if(me.doc.trash_reason && me.doc.docstatus == 2) {
  382. unhide_field('trash_reason');
  383. } else {
  384. hide_field('trash_reason');
  385. }
  386. }
  387. if(me.meta.autoname && me.meta.autoname.substr(0,6)=='field:' && !me.doc.__islocal) {
  388. var fn = me.meta.autoname.substr(6);
  389. cur_frm.toggle_display(fn, false);
  390. }
  391. if(me.meta.autoname=="naming_series:" && !me.doc.__islocal) {
  392. cur_frm.toggle_display("naming_series", false);
  393. }
  394. }
  395. // Resolve "depends_on" and show / hide accordingly
  396. _f.Frm.prototype.refresh_dependency = function() {
  397. var me = this;
  398. var doc = locals[this.doctype][this.docname];
  399. // build dependants' dictionary
  400. var has_dep = false;
  401. for(fkey in me.fields) {
  402. var f = me.fields[fkey];
  403. f.dependencies_clear = true;
  404. if(f.df.depends_on) {
  405. has_dep = true;
  406. }
  407. }
  408. if(!has_dep)return;
  409. // show / hide based on values
  410. for(var i=me.fields.length-1;i>=0;i--) {
  411. var f = me.fields[i];
  412. f.guardian_has_value = true;
  413. if(f.df.depends_on) {
  414. // evaluate guardian
  415. var v = doc[f.df.depends_on];
  416. if(f.df.depends_on.substr(0,5)=='eval:') {
  417. f.guardian_has_value = eval(f.df.depends_on.substr(5));
  418. } else if(f.df.depends_on.substr(0,3)=='fn:') {
  419. f.guardian_has_value = me.script_manager.trigger(f.df.depends_on.substr(3), me.doctype, me.docname);
  420. } else {
  421. if(!v) {
  422. f.guardian_has_value = false;
  423. }
  424. }
  425. // show / hide
  426. if(f.guardian_has_value) {
  427. if(f.df.hidden_due_to_dependency) {
  428. f.df.hidden_due_to_dependency = false;
  429. f.refresh();
  430. }
  431. } else {
  432. if(!f.df.hidden_due_to_dependency) {
  433. f.df.hidden_due_to_dependency = true;
  434. f.refresh();
  435. }
  436. }
  437. }
  438. }
  439. this.layout.refresh_section_count();
  440. }
  441. _f.Frm.prototype.setnewdoc = function() {
  442. // moved this call to refresh function
  443. // this.check_doctype_conflict(docname);
  444. var me = this;
  445. this.script_manager.trigger("before_load", this.doctype, this.docname, function() {
  446. me.script_manager.trigger("onload");
  447. me.opendocs[me.docname] = true;
  448. me.render_form();
  449. })
  450. }
  451. _f.Frm.prototype.runscript = function(scriptname, callingfield, onrefresh) {
  452. var me = this;
  453. if(this.docname) {
  454. // make doc list
  455. var doclist = wn.model.compress(make_doclist(this.doctype, this.docname));
  456. // send to run
  457. if(callingfield)
  458. $(callingfield.input).set_working();
  459. return $c('runserverobj', {'docs':doclist, 'method':scriptname },
  460. function(r, rtxt) {
  461. // run refresh
  462. if(onrefresh)
  463. onrefresh(r,rtxt);
  464. // fields
  465. me.refresh_fields();
  466. // enable button
  467. if(callingfield)
  468. $(callingfield.input).done_working();
  469. }
  470. );
  471. }
  472. }
  473. _f.Frm.prototype.copy_doc = function(onload, from_amend) {
  474. if(!this.perm[0].create) {
  475. msgprint('You are not allowed to create '+this.meta.name);
  476. return;
  477. }
  478. var dn = this.docname;
  479. // copy parent
  480. var newdoc = wn.model.copy_doc(this.doctype, dn, from_amend);
  481. // copy chidren
  482. var dl = make_doclist(this.doctype, dn);
  483. // table fields dict - for no_copy check
  484. var tf_dict = {};
  485. for(var d in dl) {
  486. d1 = dl[d];
  487. // get tabel field
  488. if(d1.parentfield && !tf_dict[d1.parentfield]) {
  489. tf_dict[d1.parentfield] = wn.meta.get_docfield(d1.parenttype, d1.parentfield);
  490. }
  491. if(d1.parent==dn && cint(tf_dict[d1.parentfield].no_copy)!=1) {
  492. var ch = wn.model.copy_doc(d1.doctype, d1.name, from_amend);
  493. ch.parent = newdoc.name;
  494. ch.docstatus = 0;
  495. ch.owner = user;
  496. ch.creation = '';
  497. ch.modified_by = user;
  498. ch.modified = '';
  499. }
  500. }
  501. newdoc.__islocal = 1;
  502. newdoc.docstatus = 0;
  503. newdoc.owner = user;
  504. newdoc.creation = '';
  505. newdoc.modified_by = user;
  506. newdoc.modified = '';
  507. if(onload)onload(newdoc);
  508. loaddoc(newdoc.doctype, newdoc.name);
  509. }
  510. _f.Frm.prototype.reload_doc = function() {
  511. this.check_doctype_conflict(this.docname);
  512. var me = this;
  513. var onsave = function(r, rtxt) {
  514. me.refresh();
  515. }
  516. if(!me.doc.__islocal) {
  517. wn.model.remove_from_locals(me.doctype, me.docname);
  518. wn.model.with_doc(me.doctype, me.docname, function() {
  519. me.refresh();
  520. })
  521. }
  522. }
  523. var validated;
  524. _f.Frm.prototype.save = function(save_action, callback, btn, on_error) {
  525. $(document.activeElement).blur();
  526. // let any pending js process finish
  527. var me = this;
  528. setTimeout(function() { me._save(save_action, callback, btn, on_error) }, 100);
  529. }
  530. _f.Frm.prototype._save = function(save_action, callback, btn, on_error) {
  531. var me = this;
  532. if((!this.meta.in_dialog || this.in_form) && !this.meta.istable)
  533. scroll(0, 0);
  534. // validate
  535. if(save_action!="Cancel") {
  536. validated = true;
  537. this.script_manager.trigger("validate");
  538. if(!validated) {
  539. if(on_error)
  540. on_error();
  541. return;
  542. }
  543. }
  544. var doclist = new wn.model.DocList(this.doctype, this.docname);
  545. doclist.save(save_action || "Save", function(r) {
  546. if(!r.exc) {
  547. me.refresh();
  548. } else {
  549. if(on_error)
  550. on_error();
  551. }
  552. callback && callback(r);
  553. if(wn._from_link) {
  554. if(me.doctype===wn._from_link.df.options) {
  555. wn._from_link.parse_validate_and_set_in_model(me.docname);
  556. wn.set_route("Form", wn._from_link.frm.doctype, wn._from_link.frm.docname);
  557. setTimeout(function() { scroll(0, wn._from_link_scrollY); }, 100);
  558. }
  559. wn._from_link = null;
  560. }
  561. }, btn);
  562. }
  563. _f.Frm.prototype.savesubmit = function(btn, on_error) {
  564. var me = this;
  565. wn.confirm("Permanently Submit "+this.docname+"?", function() {
  566. validated = true;
  567. me.script_manager.trigger("before_submit");
  568. if(!validated) {
  569. if(on_error)
  570. on_error();
  571. return;
  572. }
  573. me.save('Submit', function(r) {
  574. if(!r.exc) {
  575. me.script_manager.trigger("on_submit");
  576. }
  577. }, btn, on_error);
  578. });
  579. }
  580. _f.Frm.prototype.savecancel = function(btn, on_error) {
  581. var me = this;
  582. wn.confirm("Permanently Cancel "+this.docname+"?", function() {
  583. validated = true;
  584. me.script_manager.trigger("before_cancel");
  585. if(!validated) {
  586. if(on_error)
  587. on_error();
  588. return;
  589. }
  590. var doclist = new wn.model.DocList(me.doctype, me.docname);
  591. doclist.cancel(function(r) {
  592. if(!r.exc) {
  593. me.refresh();
  594. me.script_manager.trigger("after_cancel");
  595. }
  596. }, btn, on_error);
  597. });
  598. }
  599. // delete the record
  600. _f.Frm.prototype.savetrash = function() {
  601. wn.model.delete_doc(this.doctype, this.docname, function(r) {
  602. window.history.back();
  603. })
  604. }
  605. _f.Frm.prototype.amend_doc = function() {
  606. if(!this.fields_dict['amended_from']) {
  607. alert('"amended_from" field must be present to do an amendment.');
  608. return;
  609. }
  610. var me = this;
  611. var fn = function(newdoc) {
  612. newdoc.amended_from = me.docname;
  613. if(me.fields_dict && me.fields_dict['amendment_date'])
  614. newdoc.amendment_date = dateutil.obj_to_str(new Date());
  615. }
  616. this.copy_doc(fn, 1);
  617. }
  618. _f.Frm.prototype.disable_save = function() {
  619. // IMPORTANT: this function should be called in refresh event
  620. this.save_disabled = true;
  621. this.appframe.set_title_right("", null);
  622. }
  623. _f.Frm.prototype.save_or_update = function() {
  624. if(this.save_disabled) return;
  625. if(this.doc.docstatus===0) {
  626. this.save();
  627. } else if(this.doc.docstatus===1 && this.doc.__unsaved) {
  628. this.save("Update");
  629. }
  630. }
  631. _f.get_value = function(dt, dn, fn) {
  632. if(locals[dt] && locals[dt][dn])
  633. return locals[dt][dn][fn];
  634. }
  635. _f.Frm.prototype.dirty = function() {
  636. this.doc.__unsaved = 1;
  637. $(this.wrapper).trigger('dirty')
  638. }
  639. _f.Frm.prototype.get_docinfo = function() {
  640. return wn.model.docinfo[this.doctype][this.docname];
  641. }
  642. _f.Frm.prototype.get_perm = function(permlevel, access_type) {
  643. return this.perm[permlevel] ? this.perm[permlevel][access_type] : null;
  644. }
  645. _f.Frm.prototype.set_intro = function(txt) {
  646. wn.utils.set_intro(this, this.body, txt);
  647. }
  648. _f.Frm.prototype.set_footnote = function(txt) {
  649. wn.utils.set_footnote(this, this.body, txt);
  650. }
  651. _f.Frm.prototype.add_custom_button = function(label, fn, icon) {
  652. return this.appframe.add_primary_action(label, fn, icon || "icon-arrow-right");
  653. }
  654. _f.Frm.prototype.clear_custom_buttons = function() {
  655. this.toolbar.refresh()
  656. }
  657. _f.Frm.prototype.add_fetch = function(link_field, src_field, tar_field) {
  658. if(!this.fetch_dict[link_field]) {
  659. this.fetch_dict[link_field] = {'columns':[], 'fields':[]}
  660. }
  661. this.fetch_dict[link_field].columns.push(src_field);
  662. this.fetch_dict[link_field].fields.push(tar_field);
  663. }
  664. _f.Frm.prototype.set_print_heading = function(txt) {
  665. this.pformat[cur_frm.docname] = txt;
  666. }