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.
 
 
 
 
 
 

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