From db1145258465d47ceba71c7a0b6ea2e34d2e726a Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 4 Aug 2014 11:27:25 +0530 Subject: [PATCH] made filter editable --- frappe/core/doctype/todo/todo_list.js | 5 +- frappe/public/css/desk.css | 2 +- frappe/public/js/frappe/ui/filters.js | 82 +++++++++++++++++---------- frappe/public/js/frappe/ui/listing.js | 3 +- 4 files changed, 58 insertions(+), 34 deletions(-) diff --git a/frappe/core/doctype/todo/todo_list.js b/frappe/core/doctype/todo/todo_list.js index 9527192493..d9a75b3e33 100644 --- a/frappe/core/doctype/todo/todo_list.js +++ b/frappe/core/doctype/todo/todo_list.js @@ -1,11 +1,12 @@ frappe.listview_settings['ToDo'] = { onload: function(me) { frappe.route_options = { - "status": "Open", - "owner": user + "owner": user, + "status": "Open" }; }, fields: ["status", "priority", "due_date", "assigned_to"], + filters: [["status","=","Open"]], set_title_left: function() { frappe.set_route(); }, diff --git a/frappe/public/css/desk.css b/frappe/public/css/desk.css index b44943df8f..d70f42a655 100644 --- a/frappe/public/css/desk.css +++ b/frappe/public/css/desk.css @@ -75,7 +75,7 @@ div#freeze { border-bottom: 1px solid #c7c7c7; } -.set-filters .btn { +.set-filters .btn-group { margin-bottom: 10px; margin-right: 10px; } diff --git a/frappe/public/js/frappe/ui/filters.js b/frappe/public/js/frappe/ui/filters.js index afcf66b153..047778c1c4 100644 --- a/frappe/public/js/frappe/ui/filters.js +++ b/frappe/public/js/frappe/ui/filters.js @@ -98,10 +98,10 @@ frappe.ui.Filter = Class.extend({ \ \
\ -
\ - \ +
\ + \ \ - ×\ + ×\
\
').appendTo(this.flist.$w.find('.filter_area')); }, @@ -159,7 +159,7 @@ frappe.ui.Filter = Class.extend({ remove: function() { this.$w.remove(); - this.$btn && this.$btn.remove(); + this.$btn_group && this.$btn_group.remove(); var value = this.field.get_parsed_value(); var fieldname = this.field.df.fieldname; this.field = null; @@ -286,57 +286,79 @@ frappe.ui.Filter = Class.extend({ }, get_value: function() { - if(this.frozen_value) { - return this.frozen_value; - } + return [this.fieldselect.selected_doctype, + this.field.df.fieldname, this.get_condition(), this.get_selected_value()]; + }, - var me = this; - var val = me.field.get_parsed_value(); - var cond = me.$w.find('.condition').val(); + get_selected_value: function() { + var val = this.field.get_parsed_value(); - if(me.field.df.original_type == 'Check') { + if(this.field.df.original_type == 'Check') { val = (val=='Yes' ? 1 :0); } - if(cond=='like') { + if(this.get_condition()==='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, - me.field.df.fieldname, me.$w.find('.condition').val(), val]; + return val; + }, + + get_condition: function() { + return this.$w.find('.condition').val(); }, freeze: function() { - if(this.frozen_value) + if(this.$btn_group) { + // already made, just hide the condition setter + this.set_filter_button_text(); + this.$w.toggle(false); return; + } var me = this; - this.frozen_value = this.get_value(); - var value = __(this.frozen_value[3]); + var value = __(this.get_selected_value()); if(this.field.df.fieldname==="docstatus") { value = {0:"Draft", 1:"Submitted", 2:"Cancelled"}[value]; } // add a button for new filter if missing - this.$btn = $(repl('', { - label: __(this.field.df.label), - condition: this.frozen_value[2], - value: value, - })) - .attr("title", __("Remove Filter")) - .insertBefore(this.flist.$w.find(".set-filters .new-filter")) - .on("click", function() { - me.remove(); - }); - this.$w.remove(); + this.$btn_group = $('
\ + \ +
') + .insertBefore(this.flist.$w.find(".set-filters .new-filter")); + + this.set_filter_button_text(); + + this.$btn_group.find(".remove-filter").on("click", function() { + me.remove(); + }); + + this.$btn_group.find(".toggle-filter").on("click", function() { + me.$w.toggle(); + }) + this.$w.toggle(false); }, + set_filter_button_text: function() { + this.$btn_group.find(".toggle-filter") + .html(repl(' %(label)s %(condition)s "%(value)s"', { + label: __(this.field.df.label), + condition: this.get_condition(), + value: this.get_selected_value(), + })); + } + }); //