Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

dialog.js 3.4 KiB

il y a 13 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. var cur_dialog;
  24. wn.ui.open_dialogs = [];
  25. wn.ui.Dialog = wn.ui.FieldGroup.extend({
  26. init: function(opts) {
  27. this.display = false;
  28. if(!opts.width) opts.width = 480;
  29. $.extend(this, opts);
  30. this.make();
  31. },
  32. make: function() {
  33. this.$wrapper = $('<div class="modal" style="overflow: auto;">\
  34. <div class="modal-dialog">\
  35. <div class="modal-content">\
  36. <div class="modal-header">\
  37. <a type="button" class="close" \
  38. data-dismiss="modal" aria-hidden="true">&times;</a>\
  39. <h4 class="modal-title"></h4>\
  40. </div>\
  41. <div class="modal-body">\
  42. </div>\
  43. </div>\
  44. </div>\
  45. </div>')
  46. .appendTo(document.body);
  47. this.wrapper = this.$wrapper.find('.modal-dialog').get(0);
  48. this.make_head();
  49. this.body = this.$wrapper.find(".modal-body").get(0);
  50. // make fields (if any)
  51. this._super();
  52. var me = this;
  53. this.$wrapper
  54. .on("hide.bs.modal", function() {
  55. me.display = false;
  56. if(wn.ui.open_dialogs[wn.ui.open_dialogs.length-1]===me) {
  57. wn.ui.open_dialogs.pop();
  58. if(wn.ui.open_dialogs.length)
  59. cur_dialog = wn.ui.open_dialogs[wn.ui.open_dialogs.length-1];
  60. else
  61. cur_dialog = null;
  62. }
  63. me.onhide && me.onhide();
  64. })
  65. .on("shown.bs.modal", function() {
  66. // focus on first input
  67. me.display = true;
  68. cur_dialog = me;
  69. wn.ui.open_dialogs.push(me);
  70. var first = me.$wrapper.find(':input:first');
  71. if(first.length && first.attr("data-fieldtype")!="Date") {
  72. try {
  73. first.get(0).focus();
  74. } catch(e) {
  75. console.log("Dialog: unable to focus on first input: " + e);
  76. }
  77. }
  78. me.onshow && me.onshow();
  79. })
  80. },
  81. make_head: function() {
  82. var me = this;
  83. //this.appframe = new wn.ui.AppFrame(this.wrapper);
  84. //this.appframe.set_document_title = false;
  85. this.set_title(this.title);
  86. },
  87. set_title: function(t) {
  88. this.$wrapper.find(".modal-title").html(t);
  89. },
  90. show: function() {
  91. // show it
  92. this.$wrapper.modal("show");
  93. },
  94. hide: function(from_event) {
  95. this.$wrapper.modal("hide");
  96. },
  97. no_cancel: function() {
  98. this.appframe.$titlebar.find('.close').toggle(false);
  99. }
  100. });
  101. // close open dialogs on ESC
  102. $(document).bind('keydown', function(e) {
  103. if(cur_dialog && !cur_dialog.no_cancel_flag && e.which==27) {
  104. cur_dialog.hide();
  105. }
  106. });