Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

133 righe
3.9 KiB

  1. // Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. //
  3. // MIT License (MIT)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a
  6. // copy of this software and associated documentation files (the "Software"),
  7. // to deal in the Software without restriction, including without limitation
  8. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. // and/or sell copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. // FrmDialog - twin of FrmContainer
  23. // =======================================================================
  24. _f.frm_dialog = null;
  25. _f.calling_doc_stack = [];
  26. _f.temp_access = {};
  27. _f.FrmDialog = function() {
  28. var me = this;
  29. this.last_displayed = null;
  30. var d = new Dialog(640, null, 'Edit Row');
  31. this.body = $a(d.body, 'div', 'dialog_frm');
  32. d.done_btn_area = $a(d.body, 'div', '', {margin:'8px'});
  33. // done button
  34. me.on_complete = function() {
  35. if(me.table_form) {
  36. // table form, just hide the dialog (saving will be done with the parent)
  37. me.dialog.hide();
  38. } else {
  39. // form in dialog, so save it
  40. var callback = function(r) {
  41. var dn = cur_frm.docname;
  42. if(!r.exc) {
  43. // check if there is another dialog open?
  44. me.dialog.hide();
  45. }
  46. // callback
  47. if(me.on_save_callback)
  48. me.on_save_callback(dn);
  49. }
  50. cur_frm.save('Save', callback);
  51. }
  52. }
  53. // set title onshow
  54. // -------------------------------------------
  55. d.onshow = function() {
  56. // set the dialog title
  57. d.done_btn_area.innerHTML = '';
  58. d.done_btn = $btn(d.done_btn_area, 'Save', null, null, 'green');
  59. d.done_btn.onclick = function() { me.on_complete() };
  60. if(me.table_form) {
  61. d.set_title("Editing Row #" + (_f.cur_grid_ridx+1));
  62. d.done_btn.innerHTML = 'Done Editing';
  63. } else {
  64. d.set_title(cur_frm.doctype==cur_frm.doctype ? (cur_frm.doctype) : (cur_frm.doctype + ': ' + cur_frm.docname));
  65. d.done_btn.innerHTML = 'Save';
  66. }
  67. }
  68. // on hide, refresh grid or call onsave
  69. // -------------------------------------------
  70. d.onhide = function() {
  71. // if called from grid, refresh the row
  72. if(_f.cur_grid) {
  73. _f.cur_grid.refresh_row(_f.cur_grid_ridx, me.dn);
  74. }
  75. // set the new global cur_frm (if applicable)
  76. if(wn.container.page.frm) {
  77. cur_frm = wn.container.page.frm;
  78. }
  79. // call onhide
  80. if(me.cur_frm.cscript.hide_dialog) {
  81. me.cur_frm.cscript.hide_dialog();
  82. }
  83. // hide the form
  84. //console.log(me.cur_frm.wrapper);
  85. $(me.cur_frm.page_layout.wrapper).toggle(false);
  86. }
  87. this.dialog = d;
  88. }
  89. // called from table edit
  90. _f.edit_record = function(dt, dn) {
  91. if(!_f.frm_dialog) {
  92. _f.frm_dialog = new _f.FrmDialog();
  93. }
  94. var d = _f.frm_dialog;
  95. wn.model.with_doctype(dt, function() {
  96. wn.model.with_doc(dt, dn, function(dn) {
  97. // load
  98. if(!_f.frms[dt]) {
  99. _f.frms[dt] = new _f.Frm(dt, d.body);
  100. }
  101. var f = _f.frms[dt];
  102. if(f.meta.istable) {
  103. f.parent_doctype = cur_frm.doctype;
  104. f.parent_docname = cur_frm.docname;
  105. }
  106. d.cur_frm = f;
  107. d.dn = dn;
  108. d.table_form = f.meta.istable;
  109. // show the form
  110. f.refresh(dn);
  111. $(f.page_layout.wrapper).removeClass('layout-wrapper')
  112. .removeClass('layout-wrapper-background').toggle(true);
  113. d.dialog.show();
  114. })
  115. })
  116. }