Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

dialog.js 4.2 KiB

13 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. //
  23. // Dialog - old style dialog - deprecated
  24. //
  25. var cur_dialog;
  26. var top_index=91;
  27. function Dialog(w, h, title, content) {
  28. this.make({width:w, title:title});
  29. if(content)this.make_body(content);
  30. this.onshow = '';
  31. this.oncancel = '';
  32. this.no_cancel_flag = 0; // allow to cancel
  33. this.display = false;
  34. this.first_button = false;
  35. }
  36. Dialog.prototype = new wn.widgets.Dialog()
  37. Dialog.prototype.make_body = function(content) {
  38. this.rows = {}; this.widgets = {};
  39. for(var i in content) this.make_row(content[i]);
  40. }
  41. Dialog.prototype.clear_inputs = function(d) {
  42. for(var wid in this.widgets) {
  43. var w = this.widgets[wid];
  44. var tn = w.tagName ? w.tagName.toLowerCase() : '';
  45. if(tn=='input' || tn=='textarea') {
  46. w.value = '';
  47. } else if(tn=='select') {
  48. sel_val(w.options[0].value);
  49. } else if(w.txt) {
  50. w.txt.value = '';
  51. } else if(w.input) {
  52. w.input.value = '';
  53. }
  54. }
  55. }
  56. Dialog.prototype.make_row = function(d) {
  57. var me = this;
  58. this.rows[d[1]] = $a(this.body, 'div', 'dialog_row');
  59. var row = this.rows[d[1]];
  60. if(d[0]!='HTML') {
  61. var t = make_table(row,1,2,'100%',['30%','70%']);
  62. row.tab = t;
  63. var c1 = $td(t,0,0);
  64. var c2 = $td(t,0,1);
  65. if(d[0]!='Check' && d[0]!='Button')
  66. $(c1).text(d[1]);
  67. }
  68. if(d[0]=='HTML') {
  69. if(d[2])row.innerHTML = d[2];
  70. this.widgets[d[1]]=row;
  71. }
  72. else if(d[0]=='Check') {
  73. var i = $a_input(c2, 'checkbox','',{width:'20px'});
  74. c1.innerHTML = d[1];
  75. this.widgets[d[1]] = i;
  76. }
  77. else if(d[0]=='Data') {
  78. c1.innerHTML = d[1];
  79. c2.style.overflow = 'auto';
  80. this.widgets[d[1]] = $a_input(c2, 'text');
  81. if(d[2])$a(c2, 'div', 'field_description').innerHTML = d[2];
  82. }
  83. else if(d[0]=='Link') {
  84. c1.innerHTML = d[1];
  85. var f = make_field({fieldtype:'Link', 'label':d[1], 'options':d[2]}, '', c2, this, 0, 1);
  86. f.not_in_form = 1;
  87. f.dialog = this;
  88. f.refresh();
  89. this.widgets[d[1]] = f.input;
  90. }
  91. else if(d[0]=='Date') {
  92. c1.innerHTML = d[1];
  93. var f = make_field({fieldtype:'Date', 'label':d[1], 'options':d[2]}, '', c2, this, 0, 1);
  94. f.not_in_form = 1;
  95. f.refresh();
  96. f.dialog = this;
  97. this.widgets[d[1]] = f.input;
  98. }
  99. else if(d[0]=='Password') {
  100. c1.innerHTML = d[1];
  101. c2.style.overflow = 'auto';
  102. this.widgets[d[1]] = $a_input(c2, 'password');
  103. if(d[3])$a(c2, 'div', 'field_description').innerHTML = d[3];
  104. }
  105. else if(d[0]=='Select') {
  106. c1.innerHTML = d[1];
  107. this.widgets[d[1]] = $a(c2, 'select', '', {width:'160px'})
  108. if(d[2])$a(c2, 'div', 'field_description').innerHTML = d[2];
  109. if(d[3])add_sel_options(this.widgets[d[1]], d[3], d[3][0]);
  110. }
  111. else if(d[0]=='Text') {
  112. c1.innerHTML = d[1];
  113. c2.style.overflow = 'auto';
  114. this.widgets[d[1]] = $a(c2, 'textarea');
  115. if(d[2])$a(c2, 'div', 'field_description').innerHTML = d[2];
  116. }
  117. else if(d[0]=='Button') {
  118. c2.style.height = '32px';
  119. var b = $btn(c2, d[1], function(btn) {
  120. if(btn._onclick) btn._onclick(me) }, null, null, 1);
  121. b.dialog = me;
  122. if(!this.first_button) {
  123. $(b).addClass('btn-primary');
  124. this.first_button = true;
  125. }
  126. if(d[2]) {
  127. b._onclick = d[2];
  128. }
  129. this.widgets[d[1]] = b;
  130. }
  131. }