您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

121 行
3.3 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. wn.provide('wn.ui');
  23. wn.ui.Dialog = wn.ui.FieldGroup.extend({
  24. init: function(opts) {
  25. this.display = false;
  26. if(!opts.width) opts.width = 480;
  27. $.extend(this, opts);
  28. this.make();
  29. // init fields
  30. if(this.fields) {
  31. this.parent = this.body
  32. this._super({});
  33. }
  34. },
  35. make: function() {
  36. if(!$('#dialog-container').length) {
  37. $('<div id="dialog-container">').appendTo('body');
  38. }
  39. this.wrapper = $('<div class="dialog_wrapper">')
  40. .appendTo('#dialog-container').get(0);
  41. if(this.width)
  42. this.wrapper.style.width = this.width + 'px';
  43. this.make_head();
  44. this.body = $a(this.wrapper, 'div', 'dialog_body');
  45. },
  46. make_head: function() {
  47. var me = this;
  48. this.appframe = new wn.ui.AppFrame(this.wrapper);
  49. this.appframe.set_document_title = false;
  50. this.appframe.$titlebar.find('.close').unbind('click').click(function() {
  51. if(me.oncancel)me.oncancel(); me.hide();
  52. });
  53. this.set_title(this.title);
  54. },
  55. set_title: function(t) {
  56. this.appframe.$titlebar.find('.appframe-title').html(t || '');
  57. },
  58. set_postion: function() {
  59. this.zindex = 1;
  60. if(cur_dialog) {
  61. this.zindex = cur_dialog.zindex + 1;
  62. }
  63. // place it at the center
  64. $(this.wrapper).css({
  65. left: (($(window).width() - cint(this.wrapper.style.width))/2) + 'px',
  66. top: ($(window).scrollTop() + 60) + 'px',
  67. "z-index": this.zindex
  68. })
  69. },
  70. show: function() {
  71. // already live, do nothing
  72. if(this.display) return;
  73. // set position
  74. this.set_postion()
  75. // show it
  76. $ds(this.wrapper);
  77. // hide background
  78. wn.dom.freeze();
  79. this.display = true;
  80. cur_dialog = this;
  81. // call onshow
  82. if(this.onshow)this.onshow();
  83. // focus on first input
  84. $(this.wrapper).find(':input:first').focus();
  85. },
  86. hide: function() {
  87. // call onhide
  88. if(this.onhide) this.onhide();
  89. // hide
  90. wn.dom.unfreeze();
  91. $dh(this.wrapper);
  92. // flags
  93. this.display = false;
  94. cur_dialog = null;
  95. },
  96. no_cancel: function() {
  97. this.appframe.$titlebar.find('.close').toggle(false);
  98. }
  99. });
  100. // close open dialogs on ESC
  101. $(document).bind('keydown', function(e) {
  102. if(cur_dialog && !cur_dialog.no_cancel_flag && e.which==27) {
  103. cur_dialog.hide();
  104. }
  105. });