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.
 
 
 
 
 
 

796 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.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(this.docname);
  329. }
  330. // view_is_edit
  331. if(this.doc.__islocal)
  332. this.last_view_is_edit[this.docname] = 1; // new is view_is_edit
  333. this.view_is_edit = this.last_view_is_edit[this.docname];
  334. if(this.view_is_edit || (!this.view_is_edit && this.meta.istable)) {
  335. if(this.print_wrapper) {
  336. $dh(this.print_wrapper);
  337. $ds(this.form_wrapper);
  338. }
  339. // header
  340. this.refresh_header();
  341. // call trigger
  342. this.script_manager.trigger("refresh");
  343. // trigger global trigger
  344. // to use this
  345. $(document).trigger('form_refresh');
  346. // fields
  347. this.refresh_fields();
  348. // call onload post render for callbacks to be fired
  349. if(this.cscript.is_onload) {
  350. this.script_manager.trigger("onload_post_render");
  351. }
  352. // focus on first input
  353. if(this.doc.docstatus==0) {
  354. var first = $(this.form_wrapper).find('.form-layout-row :input:first');
  355. if(!in_list(["Date", "Datetime"], first.attr("data-fieldtype"))) {
  356. first.focus();
  357. }
  358. }
  359. } else {
  360. this.refresh_header();
  361. if(this.print_wrapper) {
  362. this.refresh_print_layout();
  363. }
  364. }
  365. $(cur_frm.wrapper).trigger('render_complete');
  366. }
  367. }
  368. _f.Frm.prototype.refresh_field = function(fname) {
  369. cur_frm.fields_dict[fname] && cur_frm.fields_dict[fname].refresh
  370. && cur_frm.fields_dict[fname].refresh();
  371. }
  372. _f.Frm.prototype.refresh_fields = function() {
  373. this.layout.refresh();
  374. // cleanup activities after refresh
  375. this.cleanup_refresh(this);
  376. // dependent fields
  377. this.refresh_dependency();
  378. }
  379. _f.Frm.prototype.cleanup_refresh = function() {
  380. var me = this;
  381. if(me.fields_dict['amended_from']) {
  382. if (me.doc.amended_from) {
  383. unhide_field('amended_from');
  384. if (me.fields_dict['amendment_date']) unhide_field('amendment_date');
  385. } else {
  386. hide_field('amended_from');
  387. if (me.fields_dict['amendment_date']) hide_field('amendment_date');
  388. }
  389. }
  390. if(me.fields_dict['trash_reason']) {
  391. if(me.doc.trash_reason && me.doc.docstatus == 2) {
  392. unhide_field('trash_reason');
  393. } else {
  394. hide_field('trash_reason');
  395. }
  396. }
  397. if(me.meta.autoname && me.meta.autoname.substr(0,6)=='field:' && !me.doc.__islocal) {
  398. var fn = me.meta.autoname.substr(6);
  399. cur_frm.toggle_display(fn, false);
  400. }
  401. if(me.meta.autoname=="naming_series:" && !me.doc.__islocal) {
  402. cur_frm.toggle_display("naming_series", false);
  403. }
  404. }
  405. // Resolve "depends_on" and show / hide accordingly
  406. _f.Frm.prototype.refresh_dependency = function() {
  407. var me = this;
  408. var doc = locals[this.doctype][this.docname];
  409. // build dependants' dictionary
  410. var has_dep = false;
  411. for(fkey in me.fields) {
  412. var f = me.fields[fkey];
  413. f.dependencies_clear = true;
  414. if(f.df.depends_on) {
  415. has_dep = true;
  416. }
  417. }
  418. if(!has_dep)return;
  419. // show / hide based on values
  420. for(var i=me.fields.length-1;i>=0;i--) {
  421. var f = me.fields[i];
  422. f.guardian_has_value = true;
  423. if(f.df.depends_on) {
  424. // evaluate guardian
  425. var v = doc[f.df.depends_on];
  426. if(f.df.depends_on.substr(0,5)=='eval:') {
  427. f.guardian_has_value = eval(f.df.depends_on.substr(5));
  428. } else if(f.df.depends_on.substr(0,3)=='fn:') {
  429. f.guardian_has_value = me.script_manager.trigger(f.df.depends_on.substr(3), me.doctype, me.docname);
  430. } else {
  431. if(!v) {
  432. f.guardian_has_value = false;
  433. }
  434. }
  435. // show / hide
  436. if(f.guardian_has_value) {
  437. if(f.df.hidden != 0) {
  438. f.df.hidden = 0;
  439. f.refresh();
  440. }
  441. } else {
  442. if(f.df.hidden != 1) {
  443. f.df.hidden = 1;
  444. f.refresh();
  445. }
  446. }
  447. }
  448. }
  449. this.layout.refresh_section_count();
  450. }
  451. _f.Frm.prototype.setnewdoc = function(docname) {
  452. // moved this call to refresh function
  453. // this.check_doctype_conflict(docname);
  454. // if loaded
  455. if(this.opendocs[docname]) { // already exists
  456. this.docname=docname;
  457. return;
  458. }
  459. this.docname = docname;
  460. var me = this;
  461. var viewname = this.meta.issingle ? this.doctype : docname;
  462. // Client Script
  463. this.script_manager.trigger("onload");
  464. this.last_view_is_edit[docname] = 1;
  465. //if(cint(this.meta.read_only_onload)) this.last_view_is_edit[docname] = 0;
  466. this.opendocs[docname] = true;
  467. }
  468. _f.Frm.prototype.edit_doc = function() {
  469. // set fields
  470. this.last_view_is_edit[this.docname] = true;
  471. this.refresh();
  472. }
  473. _f.Frm.prototype.runscript = function(scriptname, callingfield, onrefresh) {
  474. var me = this;
  475. if(this.docname) {
  476. // make doc list
  477. var doclist = wn.model.compress(make_doclist(this.doctype, this.docname));
  478. // send to run
  479. if(callingfield)
  480. $(callingfield.input).set_working();
  481. return $c('runserverobj', {'docs':doclist, 'method':scriptname },
  482. function(r, rtxt) {
  483. // run refresh
  484. if(onrefresh)
  485. onrefresh(r,rtxt);
  486. // fields
  487. me.refresh_fields();
  488. // enable button
  489. if(callingfield)
  490. $(callingfield.input).done_working();
  491. }
  492. );
  493. }
  494. }
  495. _f.Frm.prototype.copy_doc = function(onload, from_amend) {
  496. if(!this.perm[0][CREATE]) {
  497. msgprint('You are not allowed to create '+this.meta.name);
  498. return;
  499. }
  500. var dn = this.docname;
  501. // copy parent
  502. var newdoc = wn.model.copy_doc(this.doctype, dn, from_amend);
  503. // copy chidren
  504. var dl = make_doclist(this.doctype, dn);
  505. // table fields dict - for no_copy check
  506. var tf_dict = {};
  507. for(var d in dl) {
  508. d1 = dl[d];
  509. // get tabel field
  510. if(d1.parentfield && !tf_dict[d1.parentfield]) {
  511. tf_dict[d1.parentfield] = wn.meta.get_docfield(d1.parenttype, d1.parentfield);
  512. }
  513. if(d1.parent==dn && cint(tf_dict[d1.parentfield].no_copy)!=1) {
  514. var ch = wn.model.copy_doc(d1.doctype, d1.name, from_amend);
  515. ch.parent = newdoc.name;
  516. ch.docstatus = 0;
  517. ch.owner = user;
  518. ch.creation = '';
  519. ch.modified_by = user;
  520. ch.modified = '';
  521. }
  522. }
  523. newdoc.__islocal = 1;
  524. newdoc.docstatus = 0;
  525. newdoc.owner = user;
  526. newdoc.creation = '';
  527. newdoc.modified_by = user;
  528. newdoc.modified = '';
  529. if(onload)onload(newdoc);
  530. loaddoc(newdoc.doctype, newdoc.name);
  531. }
  532. _f.Frm.prototype.reload_doc = function() {
  533. this.check_doctype_conflict(this.docname);
  534. var me = this;
  535. var onsave = function(r, rtxt) {
  536. me.refresh();
  537. }
  538. if(!me.doc.__islocal) {
  539. wn.model.remove_from_locals(me.doctype, me.docname);
  540. wn.model.with_doc(me.doctype, me.docname, function() {
  541. me.refresh();
  542. })
  543. }
  544. }
  545. var validated;
  546. _f.Frm.prototype.save = function(save_action, callback, btn, on_error) {
  547. $(document.activeElement).blur();
  548. var me = this;
  549. if((!this.meta.in_dialog || this.in_form) && !this.meta.istable)
  550. scroll(0, 0);
  551. // validate
  552. if(save_action!="Cancel") {
  553. validated = true;
  554. this.script_manager.trigger("validate");
  555. if(!validated) {
  556. if(on_error)
  557. on_error();
  558. return;
  559. }
  560. }
  561. var doclist = new wn.model.DocList(this.doctype, this.docname);
  562. doclist.save(save_action || "Save", function(r) {
  563. if(!r.exc) {
  564. me.refresh();
  565. } else {
  566. if(on_error)
  567. on_error();
  568. }
  569. callback && callback(r);
  570. }, btn);
  571. }
  572. _f.Frm.prototype.savesubmit = function(btn, on_error) {
  573. var me = this;
  574. wn.confirm("Permanently Submit "+this.docname+"?", function() {
  575. me.save('Submit', function(r) {
  576. if(!r.exc) {
  577. me.script_manager.trigger("on_submit");
  578. }
  579. }, btn, on_error);
  580. });
  581. }
  582. _f.Frm.prototype.savecancel = function(btn, on_error) {
  583. var me = this;
  584. wn.confirm("Permanently Cancel "+this.docname+"?", function() {
  585. validated = true;
  586. me.script_manager.trigger("before_cancel");
  587. if(!validated) {
  588. if(on_error)
  589. on_error();
  590. return;
  591. }
  592. var doclist = new wn.model.DocList(me.doctype, me.docname);
  593. doclist.cancel(function(r) {
  594. if(!r.exc) {
  595. me.refresh();
  596. me.script_manager.trigger("after_cancel");
  597. }
  598. }, btn, on_error);
  599. });
  600. }
  601. // delete the record
  602. _f.Frm.prototype.savetrash = function() {
  603. wn.model.delete_doc(this.doctype, this.docname, function(r) {
  604. window.history.back();
  605. })
  606. }
  607. _f.Frm.prototype.amend_doc = function() {
  608. if(!this.fields_dict['amended_from']) {
  609. alert('"amended_from" field must be present to do an amendment.');
  610. return;
  611. }
  612. var me = this;
  613. var fn = function(newdoc) {
  614. newdoc.amended_from = me.docname;
  615. if(me.fields_dict && me.fields_dict['amendment_date'])
  616. newdoc.amendment_date = dateutil.obj_to_str(new Date());
  617. }
  618. this.copy_doc(fn, 1);
  619. }
  620. _f.Frm.prototype.disable_save = function() {
  621. // IMPORTANT: this function should be called in refresh event
  622. cur_frm.save_disabled = true;
  623. cur_frm.footer.hide_save();
  624. if(cur_frm.appframe.buttons.Save)
  625. cur_frm.appframe.buttons.Save.remove();
  626. delete cur_frm.appframe.buttons.Save
  627. }
  628. _f.Frm.prototype.save_or_update = function() {
  629. if(this.save_disabled) return;
  630. if(this.doc.docstatus===0) {
  631. this.save();
  632. } else if(this.doc.docstatus===1 && this.doc.__unsaved) {
  633. this.frm_head.appframe.buttons['Update'].click();
  634. }
  635. }
  636. _f.get_value = function(dt, dn, fn) {
  637. if(locals[dt] && locals[dt][dn])
  638. return locals[dt][dn][fn];
  639. }
  640. _f.Frm.prototype.dirty = function() {
  641. this.doc.__unsaved = 1;
  642. $(this.wrapper).trigger('dirty')
  643. }
  644. _f.Frm.prototype.get_docinfo = function() {
  645. return wn.model.docinfo[this.doctype][this.docname];
  646. }
  647. _f.Frm.prototype.get_perm = function(permlevel, access_type) {
  648. return this.perm[permlevel] ? this.perm[permlevel][access_type] : null;
  649. }