@@ -136,6 +136,7 @@ | |||||
"lib/js/wn/ui/appframe.js", | "lib/js/wn/ui/appframe.js", | ||||
"lib/js/wn/ui/dialog.js", | "lib/js/wn/ui/dialog.js", | ||||
"lib/js/wn/ui/button.js", | "lib/js/wn/ui/button.js", | ||||
"lib/js/wn/ui/search.js", | |||||
"lib/js/legacy/widgets/dialog.js", | "lib/js/legacy/widgets/dialog.js", | ||||
"lib/js/legacy/widgets/layout.js", | "lib/js/legacy/widgets/layout.js", | ||||
"lib/js/legacy/widgets/tabbedpage.js", | "lib/js/legacy/widgets/tabbedpage.js", | ||||
@@ -404,7 +404,7 @@ DataField.prototype.make_input = function() { | |||||
this.input.name = this.df.fieldname; | this.input.name = this.df.fieldname; | ||||
$(this.input).change(function() { | $(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) { | this.set_value = function(val) { | ||||
@@ -694,7 +694,6 @@ LinkField.prototype.setup_buttons = function() { | |||||
} | } | ||||
LinkField.prototype.set_input_value = function(val) { | LinkField.prototype.set_input_value = function(val) { | ||||
var me = this; | var me = this; | ||||
var from_selector = false; | var from_selector = false; | ||||
if(selector && selector.display) from_selector = true; | 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(); | _f.cur_grid_cell.grid.cell_deselect(); | ||||
// run trigger if value is cleared | // run trigger if value is cleared | ||||
if(!val) { | |||||
if(locals[me.doctype][me.docname][me.df.fieldname] && !val) { | |||||
me.run_trigger(); | me.run_trigger(); | ||||
return; | return; | ||||
} | } | ||||
@@ -364,14 +364,14 @@ _f.Grid.prototype.remove_template = function(cell) { | |||||
if(!hc.template)return; | if(!hc.template)return; | ||||
if(!hc.template.activated)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 | // for calendar popup. the value will come after this | ||||
_f.grid_date_cell = cell; | _f.grid_date_cell = cell; | ||||
setTimeout('_f.grid_refresh_date()', 100); | setTimeout('_f.grid_refresh_date()', 100); | ||||
} else { | } else { | ||||
var input = hc.template.txt || hc.template.input; | var input = hc.template.txt || hc.template.input; | ||||
_f.grid_refresh_field(hc.template, input) | _f.grid_refresh_field(hc.template, input) | ||||
} | |||||
}*/ | |||||
if(hc.template && hc.template.wrapper.parentNode) | if(hc.template && hc.template.wrapper.parentNode) | ||||
cell.div.removeChild(hc.template.wrapper); | cell.div.removeChild(hc.template.wrapper); | ||||
@@ -104,4 +104,15 @@ render_grid: function() { | |||||
show: function(label) { | show: function(label) { | ||||
return this.change_to(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) | |||||
} | |||||
}); | }); |
@@ -12,7 +12,7 @@ wn.ui.toolbar.NewDialog=wn.ui.toolbar.SelectorDialog.extend({init:function(){thi | |||||
/* | /* | ||||
* lib/js/wn/ui/toolbar/search.js | * 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 | * lib/js/wn/ui/toolbar/report.js | ||||
*/ | */ | ||||
@@ -27,8 +27,7 @@ wn.ui.toolbar.Search = wn.ui.toolbar.SelectorDialog.extend({ | |||||
this._super({ | this._super({ | ||||
title: "Search", | title: "Search", | ||||
execute: function(val) { | execute: function(val) { | ||||
selector.set_search(val); | |||||
selector.show(); | |||||
new wn.ui.Search({doctype:val}); | |||||
}, | }, | ||||
}); | }); | ||||
@@ -39,6 +39,9 @@ def get(arg=None): | |||||
data = webnotes.form_dict | data = webnotes.form_dict | ||||
global tables | global tables | ||||
if 'query' in data: | |||||
return run_custom_query(data) | |||||
filters = json.loads(data['filters']) | filters = json.loads(data['filters']) | ||||
fields = json.loads(data['fields']) | fields = json.loads(data['fields']) | ||||
tables = get_tables() | tables = get_tables() | ||||
@@ -61,6 +64,13 @@ def get(arg=None): | |||||
order by %(order_by)s %(limit)s""" % data | order by %(order_by)s %(limit)s""" % data | ||||
return webnotes.conn.sql(query, as_dict=1) | 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(): | def load_doctypes(): | ||||
"""load all doctypes and roles""" | """load all doctypes and roles""" | ||||
global doctypes, roles | global doctypes, roles | ||||
@@ -133,13 +143,17 @@ def build_filter_conditions(data, filters, conditions): | |||||
def build_match_conditions(data, conditions): | def build_match_conditions(data, conditions): | ||||
"""add match conditions if applicable""" | """add match conditions if applicable""" | ||||
match_conditions = [] | match_conditions = [] | ||||
match = True | |||||
for d in doctypes[data['doctype']]: | 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) +')') | conditions.append('('+ ' or '.join(match_conditions) +')') | ||||
def get_tables(): | def get_tables(): | ||||