Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

14 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // opts { width, height, title, fields (like docfields) }
  2. wn.widgets.FieldGroup = function() {
  3. this.make_fields = function(body, fl) {
  4. $y(this.body, {padding:'11px'});
  5. this.fields_dict = {}; // reset
  6. for(var i=0; i<fl.length; i++) {
  7. var df = fl[i];
  8. var div = $a(body, 'div', '', {margin:'6px 0px'})
  9. f = make_field(df, null, div, null);
  10. f.not_in_form = 1;
  11. this.fields_dict[df.fieldname] = f
  12. f.refresh();
  13. }
  14. }
  15. /* get values */
  16. this.get_values = function() {
  17. var ret = {};
  18. var errors = [];
  19. for(var key in this.fields_dict) {
  20. var f = this.fields_dict[key];
  21. var v = f.get_value ? f.get_value() : null;
  22. if(f.df.reqd && !v)
  23. errors.push(f.df.label + ' is mandatory');
  24. if(v) ret[f.df.fieldname] = v;
  25. }
  26. if(errors.length) {
  27. msgprint('<b>Please check the following Errors</b>\n' + errors.join('\n'));
  28. return null;
  29. }
  30. return ret;
  31. }
  32. /* set field value */
  33. this.set_value = function(key, val){
  34. var f = this.fields_dict[key];
  35. if(f) {
  36. f.set_input(val);
  37. f.refresh_mandatory();
  38. }
  39. }
  40. /* set values from a dict */
  41. this.set_values = function(dict) {
  42. for(var key in dict) {
  43. if(this.fields_dict[key]) {
  44. this.set_value(key, dict[key]);
  45. }
  46. }
  47. }
  48. }
  49. wn.widgets.Dialog = function(opts) {
  50. this.opts = opts;
  51. this.display = false;
  52. this.make = function(opts) {
  53. if(opts) this.opts = opts;
  54. this.wrapper = $a(popup_cont, 'div', 'dialog_wrapper');
  55. if(this.opts.width)
  56. this.wrapper.style.width = this.opts.width + 'px';
  57. this.make_head();
  58. this.body = $a(this.wrapper, 'div', 'dialog_body');
  59. if(this.opts.fields)
  60. this.make_fields(this.body, this.opts.fields);
  61. }
  62. this.make_head = function() {
  63. var me = this;
  64. this.head = $a(this.wrapper, 'div', 'dialog_head');
  65. var t = make_table(this.head,1,2,'100%',['100%','16px'],{padding:'2px'});
  66. $y($td(t,0,0),{paddingLeft:'16px',fontWeight:'bold',fontSize:'14px',textAlign:'center'});
  67. $y($td(t,0,1),{textAlign:'right'});
  68. var img = $a($td(t,0,01),'img','',{cursor:'pointer'});
  69. img.src='images/icons/close.gif';
  70. this.title_text = $td(t,0,0);
  71. this.set_title(this.opts.title);
  72. img.onclick = function() { if(me.oncancel)me.oncancel(); me.hide(); }
  73. this.cancel_img = img;
  74. }
  75. this.set_title = function(t) {
  76. this.title_text.innerHTML = t ? t : '';
  77. }
  78. this.set_postion = function() {
  79. // place it at the center
  80. var d = get_screen_dims();
  81. this.wrapper.style.left = ((d.w - cint(this.wrapper.style.width))/2) + 'px';
  82. this.wrapper.style.top = (get_scroll_top() + 60) + 'px';
  83. // place it on top
  84. top_index++;
  85. $y(this.wrapper,{zIndex:top_index});
  86. }
  87. /** show the dialog */
  88. this.show = function() {
  89. // already live, do nothing
  90. if(this.display) return;
  91. // set position
  92. this.set_postion()
  93. // show it
  94. $ds(this.wrapper);
  95. // hide background
  96. freeze();
  97. this.display = true;
  98. cur_dialog = this;
  99. // call onshow
  100. if(this.onshow)this.onshow();
  101. }
  102. this.hide = function() {
  103. // call onhide
  104. if(this.onhide) this.onhide();
  105. // hide
  106. unfreeze();
  107. $dh(this.wrapper);
  108. // clear open autosuggests
  109. if(cur_autosug) cur_autosug.clearSuggestions();
  110. // flags
  111. this.display = false;
  112. cur_dialog = null;
  113. }
  114. this.no_cancel = function() {
  115. $dh(this.cancel_img);
  116. }
  117. if(opts) this.make();
  118. }
  119. wn.widgets.Dialog.prototype = new wn.widgets.FieldGroup();
  120. // Close dialog on Escape
  121. keypress_observers.push(new function() {
  122. this.notify_keypress = function(e, kc) {
  123. if(cur_dialog && kc==27 && !cur_dialog.no_cancel_flag)
  124. cur_dialog.hide();
  125. }
  126. });