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) 2015, Frappe 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. frappe.provide('_f');
  15. frappe.provide('frappe.ui.form');
  16. frappe.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 frappe.ui.form.Controller({frm:this});
  33. this.events = {};
  34. this.pformat = {};
  35. this.fetch_dict = {};
  36. this.parent = parent;
  37. this.tinymce_id_list = [];
  38. this.setup_meta(doctype);
  39. // show in form instead of in dialog, when called using url (router.js)
  40. this.in_form = in_form ? true : false;
  41. // notify on rename
  42. var me = this;
  43. $(document).on('rename', function(event, dt, old_name, new_name) {
  44. if(dt==me.doctype)
  45. me.rename_notify(dt, old_name, new_name)
  46. });
  47. }
  48. _f.Frm.prototype.check_doctype_conflict = function(docname) {
  49. var me = this;
  50. if(this.doctype=='DocType' && docname=='DocType') {
  51. msgprint(__('Allowing DocType, DocType. Be careful!'))
  52. } else if(this.doctype=='DocType') {
  53. if (frappe.views.formview[docname] || frappe.pages['List/'+docname]) {
  54. msgprint(__("Cannot open {0} when its instance is open", ['DocType']))
  55. throw 'doctype open conflict'
  56. }
  57. } else {
  58. if (frappe.views.formview.DocType && frappe.views.formview.DocType.frm.opendocs[this.doctype]) {
  59. msgprint(__("Cannot open instance when its {0} is open", ['DocType']))
  60. throw 'doctype open conflict'
  61. }
  62. }
  63. }
  64. _f.Frm.prototype.setup = function() {
  65. var me = this;
  66. this.fields = [];
  67. this.fields_dict = {};
  68. this.state_fieldname = frappe.workflow.get_state_fieldname(this.doctype);
  69. // wrapper
  70. this.wrapper = this.parent;
  71. frappe.ui.make_app_page({
  72. parent: this.wrapper,
  73. single_column: this.meta.hide_toolbar
  74. });
  75. this.page = this.wrapper.page;
  76. this.layout_main = this.page.main.get(0);
  77. this.toolbar = new frappe.ui.form.Toolbar({
  78. frm: this,
  79. page: this.page
  80. });
  81. // print layout
  82. this.setup_print_layout();
  83. // 2 column layout
  84. this.setup_std_layout();
  85. // client script must be called after "setup" - there are no fields_dict attached to the frm otherwise
  86. this.script_manager = new frappe.ui.form.ScriptManager({
  87. frm: this
  88. });
  89. this.script_manager.setup();
  90. this.watch_model_updates();
  91. if(!this.meta.hide_toolbar) {
  92. this.footer = new frappe.ui.form.Footer({
  93. frm: this,
  94. parent: $('<div>').appendTo(this.page.main.parent())
  95. })
  96. }
  97. this.setup_drag_drop();
  98. this.setup_done = true;
  99. }
  100. _f.Frm.prototype.setup_drag_drop = function() {
  101. var me = this;
  102. $(this.wrapper).on('dragenter dragover', false)
  103. .on('drop', function (e) {
  104. var dataTransfer = e.originalEvent.dataTransfer;
  105. if (!(dataTransfer && dataTransfer.files && dataTransfer.files.length > 0)) {
  106. return;
  107. }
  108. e.stopPropagation();
  109. e.preventDefault();
  110. if(me.doc.__islocal) {
  111. msgprint(__("Please save before attaching."));
  112. throw "attach error";
  113. }
  114. if(me.attachments.max_reached()) {
  115. msgprint(__("Maximum Attachment Limit for this record reached."));
  116. throw "attach error";
  117. }
  118. frappe.upload.upload_file(dataTransfer.files[0], me.attachments.get_args(), {
  119. callback: function(attachment, r) {
  120. me.attachments.attachment_uploaded(attachment, r);
  121. }
  122. });
  123. });
  124. }
  125. _f.Frm.prototype.setup_print_layout = function() {
  126. this.print_preview = new frappe.ui.form.PrintPreview({
  127. frm: this
  128. })
  129. }
  130. _f.Frm.prototype.print_doc = function() {
  131. if(this.print_preview.wrapper.is(":visible")) {
  132. this.hide_print();
  133. return;
  134. }
  135. if(!frappe.model.can_print(this.doc.doctype, cur_frm)) {
  136. msgprint(__("You are not allowed to print this document"));
  137. return;
  138. }
  139. if(this.doc.docstatus==2) {
  140. msgprint(__("Cannot print cancelled documents"));
  141. return;
  142. }
  143. this.print_preview.refresh_print_options().trigger("change");
  144. this.page.set_view("print");
  145. }
  146. _f.Frm.prototype.hide_print = function() {
  147. if(this.setup_done && this.page.current_view_name==="print") {
  148. this.page.set_view(this.page.previous_view_name==="print" ?
  149. "main" : (this.page.previous_view_name || "main"));
  150. }
  151. }
  152. _f.Frm.prototype.watch_model_updates = function() {
  153. // watch model updates
  154. var me = this;
  155. // on main doc
  156. frappe.model.on(me.doctype, "*", function(fieldname, value, doc) {
  157. // set input
  158. if(doc.name===me.docname) {
  159. me.dirty();
  160. me.fields_dict[fieldname]
  161. && me.fields_dict[fieldname].refresh(fieldname);
  162. me.layout.refresh_dependency();
  163. me.script_manager.trigger(fieldname, doc.doctype, doc.name);
  164. }
  165. })
  166. // on table fields
  167. var table_fields = frappe.get_children("DocType", me.doctype, "fields", {fieldtype:"Table"});
  168. // using $.each to preserve df via closure
  169. $.each(table_fields, function(i, df) {
  170. frappe.model.on(df.options, "*", function(fieldname, value, doc) {
  171. if(doc.parent===me.docname && doc.parentfield===df.fieldname) {
  172. me.dirty();
  173. me.fields_dict[df.fieldname].grid.set_value(fieldname, value, doc);
  174. me.script_manager.trigger(fieldname, doc.doctype, doc.name);
  175. }
  176. });
  177. });
  178. }
  179. _f.Frm.prototype.setup_std_layout = function() {
  180. this.form_wrapper = $('<div></div>').appendTo(this.layout_main);
  181. this.body = $('<div></div>').appendTo(this.form_wrapper);
  182. // only tray
  183. this.meta.section_style='Simple'; // always simple!
  184. // layout
  185. this.layout = new frappe.ui.form.Layout({
  186. parent: this.body,
  187. doctype: this.doctype,
  188. frm: this,
  189. });
  190. this.layout.make();
  191. this.fields_dict = this.layout.fields_dict;
  192. this.fields = this.layout.fields_list;
  193. this.dashboard = new frappe.ui.form.Dashboard({
  194. frm: this,
  195. });
  196. // state
  197. this.states = new frappe.ui.form.States({
  198. frm: this
  199. });
  200. }
  201. // email the form
  202. _f.Frm.prototype.email_doc = function(message) {
  203. new frappe.views.CommunicationComposer({
  204. doc: this.doc,
  205. frm: this,
  206. subject: __(this.meta.name) + ': ' + this.docname,
  207. recipients: this.doc.email || this.doc.email_id || this.doc.contact_email,
  208. attach_document_print: true,
  209. message: message,
  210. real_name: this.doc.real_name || this.doc.contact_display || this.doc.contact_name
  211. });
  212. }
  213. // rename the form
  214. _f.Frm.prototype.rename_doc = function() {
  215. frappe.model.rename_doc(this.doctype, this.docname);
  216. }
  217. _f.Frm.prototype.share_doc = function() {
  218. this.shared.show();
  219. }
  220. // notify this form of renamed records
  221. _f.Frm.prototype.rename_notify = function(dt, old, name) {
  222. // from form
  223. if(this.meta.istable)
  224. return;
  225. if(this.docname == old)
  226. this.docname = name;
  227. else
  228. return;
  229. // cleanup
  230. if(this && this.opendocs[old]) {
  231. // delete docfield copy
  232. frappe.meta.docfield_copy[dt][name] = frappe.meta.docfield_copy[dt][old];
  233. delete frappe.meta.docfield_copy[dt][old];
  234. }
  235. delete this.opendocs[old];
  236. this.opendocs[name] = true;
  237. if(this.meta.in_dialog || !this.in_form) {
  238. return;
  239. }
  240. frappe.re_route[window.location.hash] = '#Form/' + encodeURIComponent(this.doctype) + '/' + encodeURIComponent(name);
  241. frappe.set_route('Form', this.doctype, name);
  242. }
  243. // SETUP
  244. _f.Frm.prototype.setup_meta = function(doctype) {
  245. this.meta = frappe.get_doc('DocType',this.doctype);
  246. this.perm = frappe.perm.get_perm(this.doctype); // for create
  247. if(this.meta.istable) { this.meta.in_dialog = 1 }
  248. }
  249. _f.Frm.prototype.refresh_header = function() {
  250. // set title
  251. // main title
  252. if(!this.meta.in_dialog || this.in_form) {
  253. frappe.utils.set_title(this.meta.issingle ? this.doctype : this.docname);
  254. }
  255. if(frappe.ui.toolbar.recent)
  256. frappe.ui.toolbar.recent.add(this.doctype, this.docname, 1);
  257. // show / hide buttons
  258. if(this.toolbar) {
  259. this.toolbar.refresh();
  260. }
  261. this.clear_custom_buttons();
  262. this.show_web_link();
  263. }
  264. _f.Frm.prototype.show_web_link = function() {
  265. var doc = this.doc, me = this;
  266. if(!doc.__islocal && doc.__onload && doc.__onload.is_website_generator) {
  267. me.web_link && me.web_link.remove();
  268. if(doc.__onload.published) {
  269. me.web_link = me.sidebar.add_user_action("See on Website",
  270. function() {}).attr("href", "/" + doc.__onload.website_route).attr("target", "_blank");
  271. }
  272. }
  273. }
  274. _f.Frm.prototype.check_doc_perm = function() {
  275. // get perm
  276. var dt = this.parent_doctype?this.parent_doctype : this.doctype;
  277. this.perm = frappe.perm.get_perm(dt, this.doc);
  278. if(!this.perm[0].read) {
  279. return 0;
  280. }
  281. return 1
  282. }
  283. _f.Frm.prototype.refresh = function(docname) {
  284. // record switch
  285. if(docname) {
  286. if(this.docname != docname && (!this.meta.in_dialog || this.in_form) &&
  287. !this.meta.istable) {
  288. scroll(0, 0);
  289. this.hide_print();
  290. }
  291. frappe.ui.form.close_grid_form();
  292. this.docname = docname;
  293. }
  294. cur_frm = this;
  295. if(this.docname) { // document to show
  296. // set the doc
  297. this.doc = frappe.get_doc(this.doctype, this.docname);
  298. // check permissions
  299. if(!this.check_doc_perm()) {
  300. frappe.show_not_permitted(__(this.doctype) + " " + __(this.docname));
  301. return;
  302. }
  303. // read only (workflow)
  304. this.read_only = frappe.workflow.is_read_only(this.doctype, this.docname);
  305. // check if doctype is already open
  306. if (!this.opendocs[this.docname]) {
  307. this.check_doctype_conflict(this.docname);
  308. } else {
  309. if(this.doc && (!this.doc.__unsaved) && this.doc.__last_sync_on &&
  310. (new Date() - this.doc.__last_sync_on) > (this.refresh_if_stale_for * 1000)) {
  311. this.reload_doc();
  312. return;
  313. }
  314. }
  315. // do setup
  316. if(!this.setup_done) this.setup();
  317. // load the record for the first time, if not loaded (call 'onload')
  318. cur_frm.cscript.is_onload = false;
  319. if(!this.opendocs[this.docname]) {
  320. cur_frm.cscript.is_onload = true;
  321. this.setnewdoc();
  322. } else {
  323. this.render_form();
  324. }
  325. // if print format is shown, refresh the format
  326. if(this.print_preview.wrapper.is(":visible")) {
  327. this.print_preview.preview();
  328. }
  329. }
  330. }
  331. _f.Frm.prototype.render_form = function() {
  332. if(!this.meta.istable) {
  333. this.layout.doc = this.doc;
  334. this.layout.attach_doc_and_docfields()
  335. this.sidebar = new frappe.ui.form.Sidebar({
  336. frm: this,
  337. page: this.page
  338. });
  339. // header must be refreshed before client methods
  340. // because add_custom_button
  341. this.refresh_header();
  342. // call trigger
  343. this.script_manager.trigger("refresh");
  344. // trigger global trigger
  345. // to use this
  346. $(document).trigger('form_refresh');
  347. // fields
  348. this.refresh_fields();
  349. // call onload post render for callbacks to be fired
  350. if(this.cscript.is_onload) {
  351. this.script_manager.trigger("onload_post_render");
  352. }
  353. // focus on first input
  354. if(this.doc.docstatus==0) {
  355. var first = this.form_wrapper.find('.form-layout-row :input:first');
  356. if(!in_list(["Date", "Datetime"], first.attr("data-fieldtype"))) {
  357. first.focus();
  358. }
  359. }
  360. } else {
  361. this.refresh_header();
  362. }
  363. $(cur_frm.wrapper).trigger('render_complete');
  364. }
  365. _f.Frm.prototype.refresh_field = function(fname) {
  366. cur_frm.fields_dict[fname] && cur_frm.fields_dict[fname].refresh
  367. && cur_frm.fields_dict[fname].refresh();
  368. }
  369. _f.Frm.prototype.refresh_fields = function() {
  370. this.layout.refresh(this.doc);
  371. this.layout.primary_button = $(this.wrapper).find(".btn-primary");
  372. // cleanup activities after refresh
  373. this.cleanup_refresh(this);
  374. }
  375. _f.Frm.prototype.cleanup_refresh = function() {
  376. var me = this;
  377. if(me.fields_dict['amended_from']) {
  378. if (me.doc.amended_from) {
  379. unhide_field('amended_from');
  380. if (me.fields_dict['amendment_date']) unhide_field('amendment_date');
  381. } else {
  382. hide_field('amended_from');
  383. if (me.fields_dict['amendment_date']) hide_field('amendment_date');
  384. }
  385. }
  386. if(me.fields_dict['trash_reason']) {
  387. if(me.doc.trash_reason && me.doc.docstatus == 2) {
  388. unhide_field('trash_reason');
  389. } else {
  390. hide_field('trash_reason');
  391. }
  392. }
  393. if(me.meta.autoname && me.meta.autoname.substr(0,6)=='field:' && !me.doc.__islocal) {
  394. var fn = me.meta.autoname.substr(6);
  395. cur_frm.toggle_display(fn, false);
  396. }
  397. if(me.meta.autoname=="naming_series:" && !me.doc.__islocal) {
  398. cur_frm.toggle_display("naming_series", false);
  399. }
  400. }
  401. _f.Frm.prototype.setnewdoc = function() {
  402. // moved this call to refresh function
  403. // this.check_doctype_conflict(docname);
  404. var me = this;
  405. // hide any open grid
  406. this.script_manager.trigger("before_load", this.doctype, this.docname, function() {
  407. me.script_manager.trigger("onload");
  408. me.opendocs[me.docname] = true;
  409. me.render_form();
  410. if(frappe.route_options) {
  411. $.each(frappe.route_options, function(fieldname, value) {
  412. try {
  413. me.set_value(fieldname, value);
  414. } catch (e) {
  415. // pass - see error log
  416. }
  417. });
  418. frappe.route_options = null;
  419. }
  420. frappe.breadcrumbs.add(me.meta.module, me.doctype)
  421. })
  422. }
  423. _f.Frm.prototype.runscript = function(scriptname, callingfield, onrefresh) {
  424. var me = this;
  425. if(this.docname) {
  426. // send to run
  427. if(callingfield)
  428. $(callingfield.input).set_working();
  429. frappe.call({
  430. method: "runserverobj",
  431. args: {'docs':this.doc, 'method':scriptname },
  432. btn: callingfield.$input,
  433. callback: function(r) {
  434. if(!r.exc) {
  435. if(onrefresh) {
  436. onrefresh(r);
  437. }
  438. me.refresh_fields();
  439. }
  440. }
  441. });
  442. }
  443. }
  444. _f.Frm.prototype.copy_doc = function(onload, from_amend) {
  445. this.validate_form_action("Create");
  446. var newdoc = frappe.model.copy_doc(this.doc, from_amend);
  447. newdoc.idx = null;
  448. if(onload)onload(newdoc);
  449. loaddoc(newdoc.doctype, newdoc.name);
  450. }
  451. _f.Frm.prototype.reload_doc = function() {
  452. this.check_doctype_conflict(this.docname);
  453. var me = this;
  454. var onsave = function(r, rtxt) {
  455. me.refresh();
  456. }
  457. if(!me.doc.__islocal) {
  458. frappe.model.remove_from_locals(me.doctype, me.docname);
  459. frappe.model.with_doc(me.doctype, me.docname, function() {
  460. me.refresh();
  461. })
  462. }
  463. }
  464. var validated;
  465. _f.Frm.prototype.save = function(save_action, callback, btn, on_error) {
  466. btn && $(btn).prop("disabled", true);
  467. $(document.activeElement).blur();
  468. frappe.ui.form.close_grid_form();
  469. // let any pending js process finish
  470. var me = this;
  471. setTimeout(function() { me._save(save_action, callback, btn, on_error) }, 100);
  472. }
  473. _f.Frm.prototype._save = function(save_action, callback, btn, on_error) {
  474. var me = this;
  475. if(!save_action) save_action = "Save";
  476. this.validate_form_action(save_action);
  477. if((!this.meta.in_dialog || this.in_form) && !this.meta.istable)
  478. scroll(0, 0);
  479. var after_save = function(r) {
  480. if(!r.exc) {
  481. me.script_manager.trigger("after_save");
  482. me.refresh();
  483. } else {
  484. if(on_error)
  485. on_error();
  486. }
  487. callback && callback(r);
  488. if(frappe._from_link) {
  489. if(me.doctype===frappe._from_link.df.options) {
  490. frappe._from_link.parse_validate_and_set_in_model(me.docname);
  491. frappe.set_route("Form", frappe._from_link.frm.doctype, frappe._from_link.frm.docname);
  492. setTimeout(function() { scroll(0, frappe._from_link_scrollY); }, 100);
  493. }
  494. frappe._from_link = null;
  495. }
  496. }
  497. if(save_action != "Update") {
  498. // validate
  499. validated = true;
  500. $.when(this.script_manager.trigger("validate"), this.script_manager.trigger("before_save"))
  501. .done(function() {
  502. // done is called after all ajaxes in validate & before_save are completed :)
  503. if(!validated) {
  504. if(on_error)
  505. on_error();
  506. return;
  507. }
  508. frappe.ui.form.save(me, save_action, after_save, btn);
  509. });
  510. } else {
  511. frappe.ui.form.save(me, save_action, after_save, btn);
  512. }
  513. }
  514. _f.Frm.prototype.savesubmit = function(btn, callback, on_error) {
  515. var me = this;
  516. this.validate_form_action("Submit");
  517. frappe.confirm(__("Permanently Submit {0}?", [this.docname]), function() {
  518. validated = true;
  519. me.script_manager.trigger("before_submit").done(function() {
  520. if(!validated) {
  521. if(on_error)
  522. on_error();
  523. return;
  524. }
  525. me.save('Submit', function(r) {
  526. if(!r.exc) {
  527. callback && callback();
  528. me.script_manager.trigger("on_submit");
  529. }
  530. }, btn, on_error);
  531. });
  532. }, on_error);
  533. };
  534. _f.Frm.prototype.savecancel = function(btn, callback, on_error) {
  535. var me = this;
  536. this.validate_form_action('Cancel');
  537. frappe.confirm(__("Permanently Cancel {0}?", [this.docname]), function() {
  538. validated = true;
  539. me.script_manager.trigger("before_cancel").done(function() {
  540. if(!validated) {
  541. if(on_error)
  542. on_error();
  543. return;
  544. }
  545. var after_cancel = function(r) {
  546. if(!r.exc) {
  547. me.refresh();
  548. callback && callback();
  549. me.script_manager.trigger("after_cancel");
  550. } else {
  551. on_error();
  552. }
  553. }
  554. frappe.ui.form.save(me, "cancel", after_cancel, btn);
  555. });
  556. }, on_error);
  557. }
  558. // delete the record
  559. _f.Frm.prototype.savetrash = function() {
  560. this.validate_form_action("Delete");
  561. frappe.model.delete_doc(this.doctype, this.docname, function(r) {
  562. window.history.back();
  563. })
  564. }
  565. _f.Frm.prototype.amend_doc = function() {
  566. if(!this.fields_dict['amended_from']) {
  567. alert('"amended_from" field must be present to do an amendment.');
  568. return;
  569. }
  570. this.validate_form_action("Amend");
  571. var me = this;
  572. var fn = function(newdoc) {
  573. newdoc.amended_from = me.docname;
  574. if(me.fields_dict && me.fields_dict['amendment_date'])
  575. newdoc.amendment_date = dateutil.obj_to_str(new Date());
  576. }
  577. this.copy_doc(fn, 1);
  578. }
  579. _f.Frm.prototype.disable_save = function() {
  580. // IMPORTANT: this function should be called in refresh event
  581. this.save_disabled = true;
  582. this.page.clear_primary_action();
  583. }
  584. _f.Frm.prototype.enable_save = function() {
  585. this.save_disabled = false;
  586. this.toolbar.set_primary_action();
  587. }
  588. _f.Frm.prototype.save_or_update = function() {
  589. if(this.save_disabled) return;
  590. if(this.doc.docstatus===0) {
  591. this.save();
  592. } else if(this.doc.docstatus===1 && this.doc.__unsaved) {
  593. this.save("Update");
  594. }
  595. }
  596. _f.get_value = function(dt, dn, fn) {
  597. if(locals[dt] && locals[dt][dn])
  598. return locals[dt][dn][fn];
  599. }
  600. _f.Frm.prototype.dirty = function() {
  601. this.doc.__unsaved = 1;
  602. $(this.wrapper).trigger('dirty');
  603. }
  604. _f.Frm.prototype.get_docinfo = function() {
  605. return frappe.model.docinfo[this.doctype][this.docname];
  606. }
  607. _f.Frm.prototype.reload_docinfo = function(callback) {
  608. var me = this;
  609. frappe.call({
  610. method: "frappe.desk.form.load.get_docinfo",
  611. args: {
  612. doctype: me.doctype,
  613. name: me.doc.name
  614. },
  615. callback: function(r) {
  616. // docinfo will be synced
  617. if(callback) callback(r.docinfo);
  618. me.comments.refresh();
  619. me.assign_to.refresh();
  620. me.attachments.refresh();
  621. }
  622. })
  623. }
  624. _f.Frm.prototype.get_perm = function(permlevel, access_type) {
  625. return this.perm[permlevel] ? this.perm[permlevel][access_type] : null;
  626. }
  627. _f.Frm.prototype.set_intro = function(txt, append) {
  628. frappe.utils.set_intro(this, this.body, txt, append);
  629. }
  630. _f.Frm.prototype.set_footnote = function(txt) {
  631. frappe.utils.set_footnote(this, this.body, txt);
  632. }
  633. _f.Frm.prototype.add_custom_button = function(label, fn, icon, toolbar_or_class) {
  634. this.page.add_inner_button(label, fn);
  635. }
  636. _f.Frm.prototype.clear_custom_buttons = function() {
  637. this.page.inner_toolbar.empty().addClass("hide");
  638. this.page.clear_user_actions();
  639. }
  640. _f.Frm.prototype.add_fetch = function(link_field, src_field, tar_field) {
  641. if(!this.fetch_dict[link_field]) {
  642. this.fetch_dict[link_field] = {'columns':[], 'fields':[]}
  643. }
  644. this.fetch_dict[link_field].columns.push(src_field);
  645. this.fetch_dict[link_field].fields.push(tar_field);
  646. }
  647. _f.Frm.prototype.set_print_heading = function(txt) {
  648. this.pformat[cur_frm.docname] = txt;
  649. }
  650. _f.Frm.prototype.action_perm_type_map = {
  651. "Create": "create",
  652. "Save": "write",
  653. "Submit": "submit",
  654. "Update": "submit",
  655. "Cancel": "cancel",
  656. "Amend": "amend",
  657. "Delete": "delete"
  658. };
  659. _f.Frm.prototype.validate_form_action = function(action) {
  660. var perm_to_check = this.action_perm_type_map[action];
  661. if (!this.perm[0][perm_to_check]) {
  662. frappe.throw (__("No permission to '{0}' {1}", [__(action), __(this.doc.doctype)]));
  663. }
  664. };
  665. _f.Frm.prototype.get_handlers = function(fieldname, doctype, docname) {
  666. return this.script_manager.get_handlers(fieldname, doctype || this.doctype, docname || this.docname)
  667. }