No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

search.js 2.3 KiB

hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 13 años
hace 12 años
hace 13 años
hace 12 años
hace 13 años
hace 12 años
hace 13 años
hace 12 años
hace 13 años
hace 13 años
hace 13 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. // search widget
  4. // options: doctype, callback, query (if applicable)
  5. wn.ui.Search = Class.extend({
  6. init: function(opts) {
  7. $.extend(this, opts);
  8. var me = this;
  9. wn.model.with_doctype(this.doctype, function(r) {
  10. me.make();
  11. me.dialog.show();
  12. me.list.$w.find('.list-filters input[type="text"]').focus();
  13. });
  14. },
  15. make: function() {
  16. var me = this;
  17. this.dialog = new wn.ui.Dialog({
  18. title: this.doctype + ' Search',
  19. width: 500
  20. });
  21. var parent = $('<div class="row"><div class="col-md-12"></div></div>')
  22. .appendTo(this.dialog.body)
  23. .find(".col-md-12")
  24. this.list = new wn.ui.Listing({
  25. parent: parent,
  26. appframe: this.dialog.appframe,
  27. new_doctype: this.doctype,
  28. doctype: this.doctype,
  29. type: "GET",
  30. method: 'webnotes.widgets.reportview.get',
  31. show_filters: true,
  32. style: 'compact',
  33. get_args: function() {
  34. if(me.query) {
  35. me.page_length = 50; // there has to be a better way :(
  36. return {
  37. query: me.query
  38. }
  39. } else {
  40. return {
  41. doctype: me.doctype,
  42. fields: me.get_fields(),
  43. filters: me.list.filter_list.get_filters(),
  44. docstatus: ['0','1']
  45. }
  46. }
  47. },
  48. render_row: function(parent, data) {
  49. $ln = $('<a href="#" data-name="'+data.name+'">'
  50. + data.name +'</a>')
  51. .appendTo(parent)
  52. .click(function() {
  53. var val = $(this).attr('data-name');
  54. me.dialog.hide();
  55. if(me.callback)
  56. me.callback(val);
  57. else
  58. wn.set_route('Form', me.doctype, val);
  59. return false;
  60. });
  61. // other values
  62. $.each(data, function(key, value) {
  63. if(key!=="name") {
  64. $("<span>")
  65. .html(value)
  66. .css({"margin-left": "15px", "display": "block"})
  67. .appendTo(parent);
  68. }
  69. })
  70. if(this.data.length==1) {
  71. $ln.click();
  72. }
  73. }
  74. });
  75. this.list.filter_list.add_filter(this.doctype, 'name', 'like');
  76. this.list.run();
  77. },
  78. get_fields: function() {
  79. var me = this;
  80. var fields = [ '`tab' + me.doctype + '`.name'];
  81. $.each((wn.model.get("DocType", me.doctype)[0].search_fields || "").split(","),
  82. function(i, field) {
  83. if(strip(field)) {
  84. fields.push('`tab' + me.doctype + '`.' + strip(field));
  85. }
  86. }
  87. )
  88. return fields;
  89. }
  90. })