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.
 
 
 
 
 
 

801 line
19 KiB

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