diff --git a/build.json b/build.json index c9435a9cc0..170eac93cf 100644 --- a/build.json +++ b/build.json @@ -136,6 +136,7 @@ "lib/js/wn/ui/appframe.js", "lib/js/wn/ui/dialog.js", "lib/js/wn/ui/button.js", + "lib/js/wn/ui/search.js", "lib/js/legacy/widgets/dialog.js", "lib/js/legacy/widgets/layout.js", "lib/js/legacy/widgets/tabbedpage.js", diff --git a/js/legacy/widgets/form/fields.js b/js/legacy/widgets/form/fields.js index 67a761fbae..042db1dcc9 100644 --- a/js/legacy/widgets/form/fields.js +++ b/js/legacy/widgets/form/fields.js @@ -404,7 +404,7 @@ DataField.prototype.make_input = function() { this.input.name = this.df.fieldname; $(this.input).change(function() { - me.set_value($(this).val()); + me.set_value(me.get_value && me.get_value() || $(this.input).val()); }); this.set_value = function(val) { @@ -694,7 +694,6 @@ LinkField.prototype.setup_buttons = function() { } LinkField.prototype.set_input_value = function(val) { - var me = this; var from_selector = false; if(selector && selector.display) from_selector = true; @@ -725,7 +724,7 @@ LinkField.prototype.set_input_value = function(val) { _f.cur_grid_cell.grid.cell_deselect(); // run trigger if value is cleared - if(!val) { + if(locals[me.doctype][me.docname][me.df.fieldname] && !val) { me.run_trigger(); return; } diff --git a/js/legacy/widgets/form/grid.js b/js/legacy/widgets/form/grid.js index 6760fb8ca3..fac3a7d35b 100644 --- a/js/legacy/widgets/form/grid.js +++ b/js/legacy/widgets/form/grid.js @@ -364,14 +364,14 @@ _f.Grid.prototype.remove_template = function(cell) { if(!hc.template)return; if(!hc.template.activated)return; - if(hc.template.df.fieldtype=='Date') { + /*if(hc.template.df.fieldtype=='Date') { // for calendar popup. the value will come after this _f.grid_date_cell = cell; setTimeout('_f.grid_refresh_date()', 100); } else { var input = hc.template.txt || hc.template.input; _f.grid_refresh_field(hc.template, input) - } + }*/ if(hc.template && hc.template.wrapper.parentNode) cell.div.removeChild(hc.template.wrapper); diff --git a/js/wn/tmp.js b/js/wn/tmp.js index 139143480c..a668d7d4a1 100644 --- a/js/wn/tmp.js +++ b/js/wn/tmp.js @@ -104,4 +104,15 @@ render_grid: function() { show: function(label) { return this.change_to(label); } +}); + +//// + +me.set_get_query(); +new wn.ui.Search({ + query: me.get_query ? me.get_query() : null, + doctype:me.df.options, + callback: function(val) { + me.set_input_value(val) + } }); \ No newline at end of file diff --git a/js/wn/ui/toolbar.min.js b/js/wn/ui/toolbar.min.js index 82f9a2adeb..a6990b5d4d 100644 --- a/js/wn/ui/toolbar.min.js +++ b/js/wn/ui/toolbar.min.js @@ -12,7 +12,7 @@ wn.ui.toolbar.NewDialog=wn.ui.toolbar.SelectorDialog.extend({init:function(){thi /* * lib/js/wn/ui/toolbar/search.js */ -wn.ui.toolbar.Search=wn.ui.toolbar.SelectorDialog.extend({init:function(){this._super({title:"Search",execute:function(val){selector.set_search(val);selector.show();},});this.set_values(wn.boot.profile.can_search.join(',').split(','));makeselector();}}); +wn.ui.toolbar.Search=wn.ui.toolbar.SelectorDialog.extend({init:function(){this._super({title:"Search",execute:function(val){new wn.ui.Search({doctype:val});},});this.set_values(wn.boot.profile.can_search.join(',').split(','));makeselector();}}); /* * lib/js/wn/ui/toolbar/report.js */ diff --git a/js/wn/ui/toolbar/search.js b/js/wn/ui/toolbar/search.js index 130f0454e3..477ef175bc 100644 --- a/js/wn/ui/toolbar/search.js +++ b/js/wn/ui/toolbar/search.js @@ -27,8 +27,7 @@ wn.ui.toolbar.Search = wn.ui.toolbar.SelectorDialog.extend({ this._super({ title: "Search", execute: function(val) { - selector.set_search(val); - selector.show(); + new wn.ui.Search({doctype:val}); }, }); diff --git a/py/webnotes/widgets/doclistview.py b/py/webnotes/widgets/doclistview.py index ba4bb836cd..b4da6620bf 100644 --- a/py/webnotes/widgets/doclistview.py +++ b/py/webnotes/widgets/doclistview.py @@ -39,6 +39,9 @@ def get(arg=None): data = webnotes.form_dict global tables + if 'query' in data: + return run_custom_query(data) + filters = json.loads(data['filters']) fields = json.loads(data['fields']) tables = get_tables() @@ -61,6 +64,13 @@ def get(arg=None): order by %(order_by)s %(limit)s""" % data return webnotes.conn.sql(query, as_dict=1) +def run_custom_query(data): + """run custom query""" + query = data['query'] + if '%(key)s' in query: + query = query.replace('%(key)s', 'name') + return webnotes.conn.sql(query, as_dict=1, debug=1) + def load_doctypes(): """load all doctypes and roles""" global doctypes, roles @@ -133,13 +143,17 @@ def build_filter_conditions(data, filters, conditions): def build_match_conditions(data, conditions): """add match conditions if applicable""" match_conditions = [] + match = True for d in doctypes[data['doctype']]: - if d.doctype == 'DocPerm' and d.match: - if d.role in roles: # role applicable - for v in webnotes.user.defaults.get(d.match, ['**No Match**']): - match_conditions.append('`tab%s`.%s="%s"' % (data['doctype'], d.match,v)) + if d.doctype == 'DocPerm': + if d.role in roles: + if d.match: # role applicable + for v in webnotes.user.defaults.get(d.match, ['**No Match**']): + match_conditions.append('`tab%s`.%s="%s"' % (data['doctype'], d.match,v)) + else: + match = False - if match_conditions: + if match_conditions and match: conditions.append('('+ ' or '.join(match_conditions) +')') def get_tables():