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

87 行
2.5 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. /*
  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. this.make_dialog();
  32. this.bind_events();
  33. },
  34. make_dialog: function() {
  35. this.dialog = new wn.ui.Dialog({
  36. title: this.opts.title,
  37. width: 300,
  38. fields: [
  39. {fieldtype:'Select', fieldname:'doctype', options:'Select...', label:wn._('Select Type')},
  40. {fieldtype:'Button', label:'Go', fieldname:'go'}
  41. ]
  42. });
  43. if(this.opts.help) {
  44. $("<div class='help'>"+this.opts.help+"</div>").appendTo(this.dialog.body);
  45. }
  46. },
  47. bind_events: function() {
  48. var me = this;
  49. // on go
  50. $(this.dialog.fields_dict.go.input).click(function() {
  51. if(!me.dialog.display) return;
  52. me.dialog.hide();
  53. me.opts.execute(me.dialog.fields_dict.doctype.get_value());
  54. });
  55. // on change
  56. $(this.dialog.fields_dict.doctype.input).change(function() {
  57. me.dialog.fields_dict.go.input.click();
  58. }).keypress(function(ev) {
  59. if(ev.which==13) {
  60. me.dialog.fields_dict.go.input.click();
  61. }
  62. });
  63. },
  64. show: function() {
  65. this.dialog.show();
  66. this.dialog.fields_dict.doctype.input.focus();
  67. return false;
  68. },
  69. set_values: function(lst) {
  70. // convert to labels
  71. for(var i=0;i<lst.length;i++)
  72. lst[i]=wn._(lst[i]);
  73. // set values
  74. var sel = this.dialog.fields_dict.doctype.input;
  75. $(sel).empty().add_options(lst.sort());
  76. }
  77. })