Set report filter label while loading
This commit is contained in:
parent
ed1c5b2ea6
commit
5b29d145b3
1 changed files with 53 additions and 53 deletions
|
|
@ -18,7 +18,7 @@ frappe.ui.FilterList = Class.extend({
|
|||
me.listobj.run();
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
show_filters: function() {
|
||||
this.$w.find('.show_filters').toggle();
|
||||
if(!this.filters.length)
|
||||
|
|
@ -29,7 +29,7 @@ frappe.ui.FilterList = Class.extend({
|
|||
this.filters = [];
|
||||
this.$w.find('.filter_area').empty();
|
||||
},
|
||||
|
||||
|
||||
add_filter: function(tablename, fieldname, condition, value) {
|
||||
this.push_new_filter(tablename, fieldname, condition, value);
|
||||
// list must be expanded
|
||||
|
|
@ -37,7 +37,7 @@ frappe.ui.FilterList = Class.extend({
|
|||
this.$w.find('.show_filters').toggle(true);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
push_new_filter: function(tablename, fieldname, condition, value) {
|
||||
this.filters.push(new frappe.ui.Filter({
|
||||
flist: this,
|
||||
|
|
@ -47,7 +47,7 @@ frappe.ui.FilterList = Class.extend({
|
|||
value: value
|
||||
}));
|
||||
},
|
||||
|
||||
|
||||
get_filters: function() {
|
||||
// get filter values as dict
|
||||
var values = [];
|
||||
|
|
@ -57,7 +57,7 @@ frappe.ui.FilterList = Class.extend({
|
|||
})
|
||||
return values;
|
||||
},
|
||||
|
||||
|
||||
// remove hidden filters
|
||||
update_filters: function() {
|
||||
var fl = [];
|
||||
|
|
@ -66,7 +66,7 @@ frappe.ui.FilterList = Class.extend({
|
|||
})
|
||||
this.filters = fl;
|
||||
},
|
||||
|
||||
|
||||
get_filter: function(fieldname) {
|
||||
for(var i in this.filters) {
|
||||
if(this.filters[i].field && this.filters[i].field.df.fieldname==fieldname)
|
||||
|
|
@ -109,29 +109,30 @@ frappe.ui.Filter = Class.extend({
|
|||
make_select: function() {
|
||||
var me = this;
|
||||
this.fieldselect = new frappe.ui.FieldSelect({
|
||||
parent: this.$w.find('.fieldname_select_area'),
|
||||
doctype: this.doctype,
|
||||
filter_fields: this.filter_fields,
|
||||
parent: this.$w.find('.fieldname_select_area'),
|
||||
doctype: this.doctype,
|
||||
filter_fields: this.filter_fields,
|
||||
select: function(doctype, fieldname) {
|
||||
me.set_field(doctype, fieldname);
|
||||
}
|
||||
});
|
||||
this.fieldselect.set_value(this.doctype, this.fieldname);
|
||||
},
|
||||
set_events: function() {
|
||||
var me = this;
|
||||
|
||||
this.$w.find('a.close').bind('click', function() {
|
||||
|
||||
this.$w.find('a.close').bind('click', function() {
|
||||
me.$w.css('display','none');
|
||||
var value = me.field.get_parsed_value();
|
||||
var fieldname = me.field.df.fieldname;
|
||||
me.field = null;
|
||||
|
||||
|
||||
// hide filter section
|
||||
if(!me.flist.get_filters().length) {
|
||||
me.flist.$w.find('.set_filters').toggle(true);
|
||||
me.flist.$w.find('.show_filters').toggle(false);
|
||||
}
|
||||
|
||||
|
||||
me.flist.update_filters();
|
||||
me.flist.listobj.dirty = true;
|
||||
me.flist.listobj.run();
|
||||
|
|
@ -144,33 +145,33 @@ frappe.ui.Filter = Class.extend({
|
|||
me.set_field(me.field.df.parent, me.field.df.fieldname, 'Data');
|
||||
if(!me.field.desc_area)
|
||||
me.field.desc_area = $a(me.field.wrapper, 'span', 'help', null,
|
||||
'values separated by comma');
|
||||
'values separated by comma');
|
||||
} else {
|
||||
me.set_field(me.field.df.parent, me.field.df.fieldname, null,
|
||||
me.$w.find('.condition').val());
|
||||
me.set_field(me.field.df.parent, me.field.df.fieldname, null,
|
||||
me.$w.find('.condition').val());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// set the field
|
||||
if(me.fieldname) {
|
||||
// presents given (could be via tags!)
|
||||
this.set_values(me.tablename, me.fieldname, me.condition, me.value);
|
||||
} else {
|
||||
me.set_field(me.doctype, 'name');
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
set_values: function(tablename, fieldname, condition, value) {
|
||||
// presents given (could be via tags!)
|
||||
this.set_field(tablename, fieldname);
|
||||
if(condition) this.$w.find('.condition').val(condition).change();
|
||||
if(value!=null) this.field.set_input(value);
|
||||
},
|
||||
|
||||
|
||||
set_field: function(doctype, fieldname, fieldtype, condition) {
|
||||
var me = this;
|
||||
|
||||
|
||||
// set in fieldname (again)
|
||||
var cur = me.field ? {
|
||||
fieldname: me.field.df.fieldname,
|
||||
|
|
@ -185,13 +186,12 @@ frappe.ui.Filter = Class.extend({
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
var df = copy_dict(me.fieldselect.fields_by_name[doctype][fieldname]);
|
||||
this.set_fieldtype(df, fieldtype);
|
||||
|
||||
// called when condition is changed,
|
||||
|
||||
// called when condition is changed,
|
||||
// don't change if all is well
|
||||
if(me.field && cur.fieldname == fieldname && df.fieldtype == cur.fieldtype &&
|
||||
if(me.field && cur.fieldname == fieldname && df.fieldtype == cur.fieldtype &&
|
||||
df.parent == cur.parent) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -199,13 +199,13 @@ frappe.ui.Filter = Class.extend({
|
|||
// clear field area and make field
|
||||
me.fieldselect.selected_doctype = doctype;
|
||||
me.fieldselect.selected_fieldname = fieldname;
|
||||
|
||||
|
||||
// save old text
|
||||
var old_text = null;
|
||||
if(me.field) {
|
||||
old_text = me.field.get_parsed_value();
|
||||
}
|
||||
|
||||
|
||||
var field_area = me.$w.find('.filter_field').empty().get(0);
|
||||
var f = frappe.ui.form.make_control({
|
||||
df: df,
|
||||
|
|
@ -213,13 +213,13 @@ frappe.ui.Filter = Class.extend({
|
|||
only_input: true,
|
||||
})
|
||||
f.refresh();
|
||||
|
||||
|
||||
me.field = f;
|
||||
if(old_text)
|
||||
if(old_text && me.field.df.fieldtype===cur.fieldtype)
|
||||
me.field.set_input(old_text);
|
||||
|
||||
|
||||
if(!condition) this.set_default_condition(df, fieldtype);
|
||||
|
||||
|
||||
// run on enter
|
||||
$(me.field.wrapper).find(':input').keydown(function(ev) {
|
||||
if(ev.which==13) {
|
||||
|
|
@ -227,33 +227,33 @@ frappe.ui.Filter = Class.extend({
|
|||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
set_fieldtype: function(df, fieldtype) {
|
||||
// reset
|
||||
if(df.original_type)
|
||||
df.fieldtype = df.original_type;
|
||||
else
|
||||
df.original_type = df.fieldtype;
|
||||
|
||||
|
||||
df.description = ''; df.reqd = 0;
|
||||
|
||||
|
||||
// given
|
||||
if(fieldtype) {
|
||||
df.fieldtype = fieldtype;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// scrub
|
||||
if(df.fieldtype=='Check') {
|
||||
df.fieldtype='Select';
|
||||
df.options='No\nYes';
|
||||
} else if(['Text','Small Text','Text Editor','Code','Tags','Comments'].indexOf(df.fieldtype)!=-1) {
|
||||
df.fieldtype = 'Data';
|
||||
df.fieldtype = 'Data';
|
||||
} else if(df.fieldtype=='Link' && this.$w.find('.condition').val()!="=") {
|
||||
df.fieldtype = 'Data';
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
set_default_condition: function(df, fieldtype) {
|
||||
if(!fieldtype) {
|
||||
// set as "like" for data fields
|
||||
|
|
@ -261,27 +261,27 @@ frappe.ui.Filter = Class.extend({
|
|||
this.$w.find('.condition').val('like');
|
||||
} else {
|
||||
this.$w.find('.condition').val('=');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
get_value: function() {
|
||||
var me = this;
|
||||
var val = me.field.get_parsed_value();
|
||||
var cond = me.$w.find('.condition').val();
|
||||
|
||||
|
||||
if(me.field.df.original_type == 'Check') {
|
||||
val = (val=='Yes' ? 1 :0);
|
||||
}
|
||||
|
||||
|
||||
if(cond=='like') {
|
||||
// add % only if not there at the end
|
||||
if ((val.length === 0) || (val.lastIndexOf("%") !== (val.length - 1))) {
|
||||
val = (val || "") + '%';
|
||||
}
|
||||
} else if(val === '%') val = null;
|
||||
|
||||
return [me.fieldselect.selected_doctype,
|
||||
|
||||
return [me.fieldselect.selected_doctype,
|
||||
me.field.df.fieldname, me.$w.find('.condition').val(), val];
|
||||
}
|
||||
|
||||
|
|
@ -311,10 +311,10 @@ frappe.ui.FieldSelect = Class.extend({
|
|||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if(this.filter_fields) {
|
||||
for(var i in this.filter_fields)
|
||||
this.add_field_option(this.filter_fields[i])
|
||||
this.add_field_option(this.filter_fields[i])
|
||||
} else {
|
||||
this.build_options();
|
||||
}
|
||||
|
|
@ -340,14 +340,14 @@ frappe.ui.FieldSelect = Class.extend({
|
|||
var me = this;
|
||||
this.clear();
|
||||
if(!doctype) return;
|
||||
|
||||
|
||||
// old style
|
||||
if(doctype.indexOf(".")!==-1) {
|
||||
parts = doctype.split(".");
|
||||
doctype = parts[0];
|
||||
fieldname = parts[1];
|
||||
}
|
||||
|
||||
|
||||
$.each(this.options, function(i, v) {
|
||||
if(v.doctype===doctype && v.fieldname===fieldname) {
|
||||
me.selected_doctype = doctype;
|
||||
|
|
@ -365,7 +365,7 @@ frappe.ui.FieldSelect = Class.extend({
|
|||
if(d.fieldname=="name") opts.options = me.doctype;
|
||||
return $.extend(copy_dict(d), opts);
|
||||
});
|
||||
|
||||
|
||||
// add parenttype column
|
||||
var doctype_obj = locals['DocType'][me.doctype];
|
||||
if(doctype_obj && cint(doctype_obj.istable)) {
|
||||
|
|
@ -376,7 +376,7 @@ frappe.ui.FieldSelect = Class.extend({
|
|||
parent: me.doctype,
|
||||
}]);
|
||||
}
|
||||
|
||||
|
||||
// blank
|
||||
if(this.with_blank) {
|
||||
this.options.push({
|
||||
|
|
@ -414,7 +414,7 @@ frappe.ui.FieldSelect = Class.extend({
|
|||
var label = df.label + ' (' + df.parent + ')';
|
||||
var table = df.parent;
|
||||
}
|
||||
if(frappe.model.no_value_type.indexOf(df.fieldtype)==-1 &&
|
||||
if(frappe.model.no_value_type.indexOf(df.fieldtype)==-1 &&
|
||||
!(me.fields_by_name[df.parent] && me.fields_by_name[df.parent][df.fieldname])) {
|
||||
this.options.push({
|
||||
label: __(label),
|
||||
|
|
@ -423,7 +423,7 @@ frappe.ui.FieldSelect = Class.extend({
|
|||
doctype: df.parent
|
||||
})
|
||||
if(!me.fields_by_name[df.parent]) me.fields_by_name[df.parent] = {};
|
||||
me.fields_by_name[df.parent][df.fieldname] = df;
|
||||
me.fields_by_name[df.parent][df.fieldname] = df;
|
||||
}
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue