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.

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