@@ -78,10 +78,15 @@ wn.utils = { | |||
me.footnote_area = null; | |||
} | |||
}, | |||
}; | |||
var unique = function(a) { | |||
return a.filter(function(item,i,a){ | |||
return i==a.indexOf(item); | |||
}); | |||
} | |||
get_args_dict_from_url: function(txt) { | |||
var args = {}; | |||
$.each(decodeURIComponent(txt).split("&"), function(i, arg) { | |||
arg = arg.split("="); | |||
args[arg[0]] = arg[1] | |||
}); | |||
return args; | |||
}, | |||
get_url_from_dict: function(args) { | |||
return encodeURIComponent($.map(args, function(val, key) { return key+"="+val; }).join("&") || ""); | |||
} | |||
}; |
@@ -90,7 +90,7 @@ wn.ui.FilterList = Class.extend({ | |||
get_filter: function(fieldname) { | |||
for(var i in this.filters) { | |||
if(this.filters[i].field.df.fieldname==fieldname) | |||
if(this.filters[i].field && this.filters[i].field.df.fieldname==fieldname) | |||
return this.filters[i]; | |||
} | |||
} | |||
@@ -139,12 +139,19 @@ wn.ui.Filter = Class.extend({ | |||
this.$w.find('a.close').bind('click', function() { | |||
me.$w.css('display','none'); | |||
var value = me.field.get_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); | |||
} | |||
if(value) { | |||
// remove from route | |||
var in_route = me.remove_from_route(fieldname); | |||
if(value && !in_route) { | |||
me.flist.listobj.run(); | |||
} | |||
me.flist.update_filters(); | |||
@@ -173,6 +180,20 @@ wn.ui.Filter = Class.extend({ | |||
}, | |||
remove_from_route: function(fieldname) { | |||
var route = wn.get_route(); | |||
if(route[2]) { | |||
var args = wn.utils.get_args_dict_from_url(route[2]); | |||
if(in_list(keys(args), fieldname)) { | |||
delete args[fieldname]; | |||
route[2] = wn.utils.get_url_from_dict(args); | |||
wn.set_route(route[0], route[1], route[2]); | |||
return true; | |||
} | |||
} | |||
return false; | |||
}, | |||
set_values: function(tablename, fieldname, condition, value) { | |||
// presents given (could be via tags!) | |||
this.set_field(tablename, fieldname); | |||
@@ -5,13 +5,13 @@ wn.provide('wn.views.doclistview'); | |||
wn.provide('wn.doclistviews'); | |||
wn.views.doclistview.show = function(doctype) { | |||
var page_name = wn.get_route_str(); | |||
var route = wn.get_route(); | |||
var page_name = "List/" + route[1]; | |||
if(wn.pages[page_name]) { | |||
wn.container.change_to(wn.pages[page_name]); | |||
if(wn.container.page.doclistview) | |||
wn.container.page.doclistview.run(); | |||
} else { | |||
var route = wn.get_route(); | |||
if(route[1]) { | |||
wn.model.with_doctype(route[1], function(r) { | |||
if(r && r['403']) { | |||
@@ -35,7 +35,7 @@ wn.views.DocListView = wn.ui.Listing.extend({ | |||
make_page: function() { | |||
var me = this; | |||
var page_name = wn.get_route_str(); | |||
var page_name = "List/" + this.doctype; | |||
var page = wn.container.add_page(page_name); | |||
wn.container.change_to(page_name); | |||
page.doclistview = this; | |||
@@ -145,6 +145,18 @@ wn.views.DocListView = wn.ui.Listing.extend({ | |||
if((auto_run !== false) && (auto_run !== 0)) this.run(); | |||
}, | |||
run: function() { | |||
// set filter from route | |||
var route = wn.get_route(); | |||
var me = this; | |||
if(route[2]) { | |||
$.each(wn.utils.get_args_dict_from_url(route[2]), function(key, val) { | |||
me.set_filter(key, val); | |||
}) | |||
} | |||
this._super(); | |||
}, | |||
make_no_result: function() { | |||
var new_button = wn.boot.profile.can_create.indexOf(this.doctype)!=-1 | |||
? ('<hr><p><button class="btn btn-info" \ | |||
@@ -327,7 +339,7 @@ wn.views.DocListView = wn.ui.Listing.extend({ | |||
set_filter: function(fieldname, label) { | |||
var filter = this.filter_list.get_filter(fieldname); | |||
if(filter) { | |||
var v = filter.field.get_value(); | |||
var v = cstr(filter.field.get_value()); | |||
if(v.indexOf(label)!=-1) { | |||
// already set | |||
return false; | |||
@@ -2,6 +2,8 @@ | |||
// MIT Licensed. See license.txt | |||
wn.provide("wn.views.moduleview"); | |||
wn.provide("wn.model.open_count_conditions") | |||
wn.views.moduleview.make = function(wrapper, module) { | |||
var doctypes = []; | |||
@@ -21,6 +23,19 @@ wn.views.moduleview.make = function(wrapper, module) { | |||
<div class='span5 side-section'></div>\ | |||
</div>") | |||
$(wrapper).on("click", ".badge-important", function() { | |||
var doctype = $(this).parent().attr("data-doctype"); | |||
var condition = wn.model.open_count_conditions[doctype]; | |||
if(condition) { | |||
wn.set_route("List", doctype, wn.utils.get_url_from_dict(condition)); | |||
} | |||
}); | |||
$(wrapper).on("click", ".badge-count", function() { | |||
var doctype = $(this).attr("data-doctype-count"); | |||
wn.set_route("List", doctype); | |||
}); | |||
var add_section = function(section) { | |||
var table = $(repl("<table class='table table-bordered'>\ | |||
<thead><tr>\ | |||
@@ -131,16 +146,19 @@ wn.views.moduleview.make = function(wrapper, module) { | |||
$.each(r.message.item_count, function(doctype, count) { | |||
$(wrapper).find("[data-doctype-count='"+doctype+"']") | |||
.html(count) | |||
.addClass("badge"); | |||
.addClass("badge badge-count") | |||
.css({cursor:"pointer"}); | |||
}) | |||
} | |||
// counts | |||
if(r.message.open_count) { | |||
$.extend(wn.model.open_count_conditions, r.message.conditions); | |||
$.each(r.message.open_count, function(doctype, count) { | |||
$(wrapper).find("[data-doctype='"+doctype+"']") | |||
.append(" <span class='badge badge-important pull-right'>" | |||
+ count + "</span>") | |||
.append(" <span class='badge badge-important pull-right'\ | |||
style='cursor:pointer'>" + count + "</span>"); | |||
}) | |||
} | |||
} | |||
@@ -7,11 +7,13 @@ import webnotes, json | |||
@webnotes.whitelist() | |||
def get_data(module, doctypes='[]'): | |||
doctypes = json.loads(doctypes) | |||
open_count, conditions = get_open_count(doctypes) | |||
return { | |||
"search_criteria": get_sc_list(module), | |||
"reports": get_report_list(module), | |||
"item_count": get_count(doctypes), | |||
"open_count": get_open_count(doctypes) | |||
"open_count": open_count, | |||
"conditions": conditions | |||
} | |||
def get_count(doctypes): | |||
@@ -32,19 +34,21 @@ def get_doctype_count_from_table(doctype): | |||
def get_open_count(doctypes): | |||
count = {} | |||
conditions = {} | |||
try: | |||
from startup.open_count import queries | |||
for d in doctypes: | |||
if d in queries: | |||
query = queries[d] | |||
if query=="docstatus": | |||
query = "select count(*) from `tab%s` where docstatus=0" % d | |||
count[d] = webnotes.conn.sql(query)[0][0] or "" | |||
condition = queries[d] | |||
key = condition.keys()[0] | |||
query = "select count(*) from `tab%s` where `%s`=%s" % (d, key, '%s') | |||
count[d] = webnotes.conn.sql(query, condition[key])[0][0] or "" | |||
conditions[d] = condition | |||
except ImportError, e: | |||
pass | |||
return count | |||
return count, conditions | |||
def get_doctype_count(doctype): | |||
count = webnotes.conn.get_global("item_count:" + doctype) | |||