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.

selector_dialog.js 2.6 KiB

12 years ago
13 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. /*
  23. opts:
  24. - title
  25. - execute
  26. */
  27. wn.provide('wn.ui.toolbar');
  28. wn.ui.toolbar.SelectorDialog = Class.extend({
  29. init: function(opts) {
  30. this.opts = opts;
  31. try{
  32. this.make_dialog();
  33. } catch(e) {
  34. console.log(e);
  35. }
  36. this.bind_events();
  37. },
  38. make_dialog: function() {
  39. this.dialog = new wn.widgets.Dialog({
  40. title: this.opts.title,
  41. width: 300,
  42. fields: [
  43. {fieldtype:'Select', fieldname:'doctype', options:'Select...', label:'Select Type'},
  44. {fieldtype:'Button', label:'Go', fieldname:'go'}
  45. ]
  46. });
  47. if(this.opts.help) {
  48. $("<div class='help'>"+this.opts.help+"</div>").appendTo(this.dialog.body);
  49. }
  50. },
  51. bind_events: function() {
  52. var me = this;
  53. // on go
  54. $(this.dialog.fields_dict.go.input).click(function() {
  55. if(!me.dialog.display) return;
  56. me.dialog.hide();
  57. me.opts.execute(me.dialog.fields_dict.doctype.get_value());
  58. });
  59. // on change
  60. $(this.dialog.fields_dict.doctype.input).change(function() {
  61. me.dialog.fields_dict.go.input.click();
  62. }).keypress(function(ev) {
  63. if(ev.which==13) {
  64. me.dialog.fields_dict.go.input.click();
  65. }
  66. });
  67. },
  68. show: function() {
  69. this.dialog.show();
  70. this.dialog.fields_dict.doctype.input.focus();
  71. return false;
  72. },
  73. set_values: function(lst) {
  74. // convert to labels
  75. for(var i=0;i<lst.length;i++)
  76. lst[i]=get_doctype_label(lst[i]);
  77. // set values
  78. var sel = this.dialog.fields_dict.doctype.input;
  79. $(sel).empty();
  80. add_sel_options(sel, lst.sort());
  81. }
  82. })