選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

69 行
1.6 KiB

  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. /*
  4. opts:
  5. - title
  6. - execute
  7. */
  8. wn.provide('wn.ui.toolbar');
  9. wn.ui.toolbar.SelectorDialog = Class.extend({
  10. init: function(opts) {
  11. this.opts = opts;
  12. this.make_dialog();
  13. this.bind_events();
  14. },
  15. make_dialog: function() {
  16. this.dialog = new wn.ui.Dialog({
  17. title: this.opts.title,
  18. width: 300,
  19. fields: [
  20. {fieldtype:'Select', fieldname:'doctype', options:'Select...', label:wn._('Select Type')},
  21. {fieldtype:'Button', label:'Go', fieldname:'go'}
  22. ]
  23. });
  24. if(this.opts.help) {
  25. $("<div class='help'>"+this.opts.help+"</div>").appendTo(this.dialog.body);
  26. }
  27. },
  28. bind_events: function() {
  29. var me = this;
  30. // on go
  31. $(this.dialog.fields_dict.go.input).click(function() {
  32. if(!me.dialog.display) return;
  33. me.dialog.hide();
  34. me.opts.execute(me.dialog.fields_dict.doctype.get_value());
  35. });
  36. // on change
  37. $(this.dialog.fields_dict.doctype.input).change(function() {
  38. me.dialog.fields_dict.go.input.click();
  39. }).keypress(function(ev) {
  40. if(ev.which==13) {
  41. me.dialog.fields_dict.go.input.click();
  42. }
  43. });
  44. },
  45. show: function() {
  46. this.dialog.show();
  47. this.dialog.fields_dict.doctype.input.focus();
  48. return false;
  49. },
  50. set_values: function(lst) {
  51. // convert to labels
  52. for(var i=0;i<lst.length;i++)
  53. lst[i]={label:wn._(lst[i]), value:lst[i]};
  54. // set values
  55. var sel = this.dialog.fields_dict.doctype.input;
  56. $(sel).empty().add_options(lst.sort(function(a, b) {
  57. return (a.label > b.label ? 1 : -1) }));
  58. }
  59. })