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 1.3 KiB

13 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. opts:
  3. - title
  4. - execute
  5. */
  6. wn.provide('wn.ui.toolbar');
  7. wn.ui.toolbar.SelectorDialog = Class.extend({
  8. init: function(opts) {
  9. this.opts = opts;
  10. try{
  11. this.make_dialog();
  12. } catch(e) {
  13. console.log(e);
  14. }
  15. this.bind_events();
  16. },
  17. make_dialog: function() {
  18. this.dialog = new wn.widgets.Dialog({
  19. title: this.opts.title,
  20. width: 300,
  21. fields: [
  22. {fieldtype:'Select', fieldname:'doctype', options:'Select...', label:'Select Type'},
  23. {fieldtype:'Button', label:'Go', fieldname:'go'}
  24. ]
  25. });
  26. },
  27. bind_events: function() {
  28. var me = this;
  29. // on go
  30. $(this.dialog.fields_dict.go.input).click(function() {
  31. if(!me.dialog.display) return;
  32. me.dialog.hide();
  33. me.opts.execute(me.dialog.fields_dict.doctype.get_value());
  34. });
  35. // on change
  36. $(this.dialog.fields_dict.doctype.input).change(function() {
  37. me.dialog.fields_dict.go.input.click();
  38. }).keypress(function(ev) {
  39. if(ev.which==13) {
  40. me.dialog.fields_dict.go.input.click();
  41. }
  42. });
  43. },
  44. show: function() {
  45. this.dialog.show();
  46. this.dialog.fields_dict.doctype.input.focus();
  47. return false;
  48. },
  49. set_values: function(lst) {
  50. // convert to labels
  51. for(var i=0;i<lst.length;i++)
  52. lst[i]=get_doctype_label(lst[i]);
  53. // set values
  54. var sel = this.dialog.fields_dict.doctype.input;
  55. $(sel).empty();
  56. add_sel_options(sel, lst.sort());
  57. }
  58. })