25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

64 lines
1.5 KiB

  1. // search widget
  2. // options: doctype, callback, query (if applicable)
  3. wn.ui.Search = Class.extend({
  4. init: function(opts) {
  5. $.extend(this, opts);
  6. var me = this;
  7. wn.model.with_doctype(this.doctype, function(r) {
  8. me.make();
  9. me.dialog.show();
  10. me.list.$w.find('.list-filters input[type="text"]').focus();
  11. });
  12. },
  13. make: function() {
  14. var me = this;
  15. this.dialog = new wn.ui.Dialog({
  16. title: this.doctype + ' Search',
  17. width: 500
  18. });
  19. this.list = new wn.ui.Listing({
  20. parent: $(this.dialog.body),
  21. appframe: this.dialog.appframe,
  22. new_doctype: this.doctype,
  23. doctype: this.doctype,
  24. method: 'webnotes.widgets.doclistview.get',
  25. show_filters: true,
  26. style: 'compact',
  27. get_args: function() {
  28. if(me.query) {
  29. me.page_length = 50; // there has to be a better way :(
  30. return {
  31. query: me.query
  32. }
  33. } else {
  34. return {
  35. doctype: me.doctype,
  36. fields: [ '`tab' + me.doctype + '`.name'],
  37. filters: me.list.filter_list.get_filters(),
  38. docstatus: ['0','1']
  39. }
  40. }
  41. },
  42. render_row: function(parent, data) {
  43. $ln = $('<a href="#" data-name="'+data.name+'">'
  44. + data.name +'</a>')
  45. .appendTo(parent)
  46. .click(function() {
  47. var val = $(this).attr('data-name');
  48. me.dialog.hide();
  49. if(me.callback)
  50. me.callback(val);
  51. else
  52. wn.set_route('Form', me.doctype, val);
  53. return false;
  54. });
  55. if(this.data.length==1) {
  56. $ln.click();
  57. }
  58. }
  59. });
  60. this.list.filter_list.add_filter(this.doctype, 'name', 'like');
  61. this.list.run();
  62. }
  63. })