Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

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