duplicate filters entry resolved

This commit is contained in:
Zlash65 2017-09-13 13:51:58 +05:30
parent da0a4ea7fd
commit d7a41cc74a

View file

@ -133,7 +133,9 @@ frappe.ui.FilterList = Class.extend({
for(var i in this.filters) {
if(this.filters[i].field) {
var f = this.filters[i].get_value();
if(f[0]==doctype && f[1]==fieldname && f[2]==condition && f[3]==value) {
var val = this.get_correct_value(this.filters[i].field, f[3]);
if(f[0]==doctype && f[1]==fieldname && f[2]==condition && val==value) {
flag = true;
} else if($.isArray(value) && frappe.utils.arrays_equal(value, f[3])) {
flag = true;
@ -174,6 +176,19 @@ frappe.ui.FilterList = Class.extend({
if(this.filters[i].field && this.filters[i].field.df.fieldname==fieldname)
return this.filters[i];
}
},
get_correct_value: function(field, val){
var value = val;
if(field.df.fieldname==="docstatus") {
value = {0:"Draft", 1:"Submitted", 2:"Cancelled"}[value] || value;
} else if(field.df.original_type==="Check") {
value = {0:"No", 1:"Yes"}[cint(value)];
}
value = frappe.format(value, field.df, {only_value: 1});
return value;
}
});
@ -214,6 +229,7 @@ frappe.ui.Filter = Class.extend({
this.wrapper.find(".set-filter-and-run").on("click", function() {
me.wrapper.removeClass("is-new-filter");
me.flist.base_list.run();
me.apply();
});
// add help for "in" codition
@ -244,6 +260,14 @@ frappe.ui.Filter = Class.extend({
}
},
apply: function() {
var f = this.get_value();
this.flist.filters.pop();
var val = this.flist.get_correct_value(this.field, f[3]);
this.flist.push_new_filter(f[0], f[1], f[2], val);
this.wrapper.remove();
},
remove: function(dont_run) {
this.wrapper.remove();
this.$btn_group && this.$btn_group.remove();
@ -467,14 +491,7 @@ frappe.ui.Filter = Class.extend({
set_filter_button_text: function() {
var value = this.get_selected_value();
if(this.field.df.fieldname==="docstatus") {
value = {0:"Draft", 1:"Submitted", 2:"Cancelled"}[value] || value;
} else if(this.field.df.original_type==="Check") {
value = {0:"No", 1:"Yes"}[cint(value)];
}
value = frappe.format(value, this.field.df, {only_value: 1});
value = this.flist.get_correct_value(this.field, value);
// for translations
// __("like"), __("not like"), __("in")