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.

преди 11 години
преди 13 години
преди 11 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 13 години
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. wn.provide('wn.ui');
  4. var cur_dialog;
  5. wn.ui.open_dialogs = [];
  6. wn.ui.Dialog = wn.ui.FieldGroup.extend({
  7. _intro:' usage:\n\
  8. \n\
  9. var dialog = new wn.ui.Dialog({\n\
  10. title: "Dialog Title",\n\
  11. fields: [\n\
  12. {fieldname:"field1", fieldtype:"Data", reqd:1, label: "Test 1"},\n\
  13. {fieldname:"field2", fieldtype:"Link", reqd:1, label: "Test 1", options:"Some DocType"},\n\
  14. {fieldname:"mybutton", fieldtype:"Button", reqd:1, label: "Submit"},\n\
  15. ]\n\
  16. })\n\
  17. dialog.get_input("mybutton").click(function() { /* do something; */ dialog.hide(); });\n\
  18. dialog.show()',
  19. init: function(opts) {
  20. this.display = false;
  21. this.is_dialog = true;
  22. if(!opts.width) opts.width = 480;
  23. $.extend(this, opts);
  24. this._super();
  25. this.make();
  26. },
  27. make: function() {
  28. this.$wrapper = wn.get_modal("", "");
  29. this.wrapper = this.$wrapper.find('.modal-dialog').get(0);
  30. this.make_head();
  31. this.body = this.$wrapper.find(".modal-body").get(0);
  32. // make fields (if any)
  33. this._super();
  34. var me = this;
  35. this.$wrapper
  36. .on("hide.bs.modal", function() {
  37. me.display = false;
  38. if(wn.ui.open_dialogs[wn.ui.open_dialogs.length-1]===me) {
  39. wn.ui.open_dialogs.pop();
  40. if(wn.ui.open_dialogs.length)
  41. cur_dialog = wn.ui.open_dialogs[wn.ui.open_dialogs.length-1];
  42. else
  43. cur_dialog = null;
  44. }
  45. me.onhide && me.onhide();
  46. })
  47. .on("shown.bs.modal", function() {
  48. // focus on first input
  49. me.display = true;
  50. cur_dialog = me;
  51. wn.ui.open_dialogs.push(me);
  52. var first = me.$wrapper.find(':input:first');
  53. if(first.length && first.attr("data-fieldtype")!="Date") {
  54. try {
  55. first.get(0).focus();
  56. } catch(e) {
  57. console.log("Dialog: unable to focus on first input: " + e);
  58. }
  59. }
  60. me.onshow && me.onshow();
  61. })
  62. },
  63. make_head: function() {
  64. var me = this;
  65. //this.appframe = new wn.ui.AppFrame(this.wrapper);
  66. //this.appframe.set_document_title = false;
  67. this.set_title(this.title);
  68. },
  69. set_title: function(t) {
  70. this.$wrapper.find(".modal-title").html(t);
  71. },
  72. show: function() {
  73. // show it
  74. this.$wrapper.modal("show");
  75. },
  76. hide: function(from_event) {
  77. this.$wrapper.modal("hide");
  78. },
  79. no_cancel: function() {
  80. this.$wrapper.find('.close').toggle(false);
  81. }
  82. });
  83. // close open dialogs on ESC
  84. $(document).bind('keydown', function(e) {
  85. if(cur_dialog && !cur_dialog.no_cancel_flag && e.which==27) {
  86. cur_dialog.hide();
  87. }
  88. });