From afb1382575c2904fb40217c8cba7fee2d3de0d17 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Fri, 15 Nov 2013 17:32:47 +0100 Subject: [PATCH] [ADD] forgot to add utility.js file to addon web_graph bzr revid: ged@openerp.com-20131115163247-9tv5t7w9ygcmcnnm --- addons/web_graph/static/src/js/utility.js | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 addons/web_graph/static/src/js/utility.js diff --git a/addons/web_graph/static/src/js/utility.js b/addons/web_graph/static/src/js/utility.js new file mode 100644 index 00000000000..9f4ab2bb6a3 --- /dev/null +++ b/addons/web_graph/static/src/js/utility.js @@ -0,0 +1,38 @@ + +function removeFromArray(array, element) { + var index = array.indexOf(element); + if (index > -1) { + array.splice(index, 1); + } +} + +/** + * Query the server and return a deferred which will return the data + * with all the groupbys applied (this is done for now, but the goal + * is to modify read_group in order to allow eager and lazy groupbys + */ +function query_groups (model, fields, domain, groupbys) { + return model.query(fields) + .filter(domain) + .group_by(groupbys) + .then(function (results) { + var non_empty_results = _.filter(results, function (group) { + return group.attributes.length > 0; + }); + if (groupbys.length <= 1) { + return non_empty_results; + } else { + var get_subgroups = $.when.apply(null, _.map(non_empty_results, function (result) { + var new_domain = result.model._domain; + var new_groupings = groupbys.slice(1); + return query_groups(model, fields,new_domain, new_groupings).then(function (subgroups) { + result.subgroups_data = subgroups; + }); + })); + return get_subgroups.then(function () { + return non_empty_results; + }); + } + }); +} +