diff --git a/web_group_expand/README.rst b/web_group_expand/README.rst index 278696a4..c81aad52 100644 --- a/web_group_expand/README.rst +++ b/web_group_expand/README.rst @@ -44,6 +44,7 @@ Contributors * Pedro M. Baeza * Jay Vora (SerpentCS) for their alternative implementation * Aldo Soares +* Meet Dholakia Maintainer ---------- diff --git a/web_group_expand/__manifest__.py b/web_group_expand/__manifest__.py index c680789f..085a93b7 100644 --- a/web_group_expand/__manifest__.py +++ b/web_group_expand/__manifest__.py @@ -3,7 +3,7 @@ 'summary': """ Enables expanding/reset all groups in list view """, - "version": "11.0.1.0.0", + "version": "11.0.1.0.1", "category": "Web", "author": "OpenERP SA, " "AvanzOSC, " diff --git a/web_group_expand/static/src/js/web_group_expand.js b/web_group_expand/static/src/js/web_group_expand.js index ddb98032..e222a0bd 100644 --- a/web_group_expand/static/src/js/web_group_expand.js +++ b/web_group_expand/static/src/js/web_group_expand.js @@ -1,75 +1,43 @@ -odoo.define('web_groupby_expand.web_groupby_expand', function (require) { -"use strict"; +odoo.define('web_group_expand.web_group_expand', function (require) { + "use strict"; -var ViewManager = require('web.ViewManager'); + var ViewManager = require('web.ViewManager'); + var SearchView = require('web.SearchView'); + var GroupByExpandMenu = require('web_group_expand.GroupByExpandMenu'); -ViewManager.include({ - render_view_control_elements: function (){ - var res = this._super.apply(this, arguments); - if (this.searchview_elements) { - var searchview = this.searchview_elements.$searchview_buttons - var expand_button = searchview.find('#oe_group_by_expand'); - var reset_button = searchview.find('#oe_group_by_reset'); - expand_button.on('click', this.proxy('expand_records')); - reset_button.on('click', this.proxy('reset_records')); - this.do_toggle_visibility(false) - } - return res; - }, - - _process_search_data: function () { - var res = this._super.apply(this, arguments); - if (this.active_view && this.active_view.type == 'list' && this.searchview_elements) { - var searchview = this.searchview_elements.$searchview_buttons - var has_groups = res.groupBy.length > 0 - this.do_toggle_visibility(has_groups) - } - return res; - }, - - get_search_groups: function (groups) { - var current_search_group = {}; - for (var group in groups) { - if (groups[group].count > 0 && groups[group].data.length > 0) { - current_search_group[groups[group].id] = groups[group].data; - } - } - return current_search_group; - }, + SearchView.include({ + init: function (parent, dataset, fvg, options) { + this._super.apply(this, arguments); + this.groupby_expand_menu = undefined; + }, + start: function () { + var res = this._super.apply(this, arguments); + var self = this; + return res.done(function(){ + var group_by_menu_defs = []; + if (self.$buttons) { + if (!self.options.disable_groupby && self.groupby_menu) { + self.groupby_expand_menu = new GroupByExpandMenu(self, self.groupbys); + group_by_menu_defs.push(self.groupby_expand_menu.appendTo(self.$buttons)); + } + } + }) + }, + }) - do_toggle_visibility: function (show) { - var searchview = this.searchview_elements.$searchview_buttons - var buttons = searchview.find('.toggle_buttons'); - if (show) { - buttons.show() - } - else { - buttons.hide() - } - }, + ViewManager.include({ - toggle_group_records: function (op, controller) { - var current_search_group = this.get_search_groups(controller.model.localData); - if (current_search_group) { - for (var group in current_search_group) { - for (var gp in current_search_group[group]) { - var cur_group = controller.model.localData[current_search_group[group][gp]] - if ((op && !cur_group.isOpen) || (!op && cur_group.isOpen)) { - controller.trigger_up('toggle_group', { group: cur_group }) - } + _process_search_data: function () { + var res = this._super.apply(this, arguments); + if (this.active_view && this.active_view.type == 'list' && this.searchview) { + if(this.searchview.groupby_expand_menu){ + var has_groups = res.groupBy.length > 0 + this.searchview.groupby_expand_menu.do_toggle_visibility(has_groups) } + }else{ + this.searchview.groupby_expand_menu.do_toggle_visibility(false) } - } - }, - - reset_records: function () { - var controller = this.active_view.controller; - this.toggle_group_records(false, controller) - }, - - expand_records: function () { - var controller = this.active_view.controller; - this.toggle_group_records(true, controller) - }, -}); + return res; + }, + }); }); diff --git a/web_group_expand/static/src/js/web_group_expand_menu.js b/web_group_expand/static/src/js/web_group_expand_menu.js new file mode 100644 index 00000000..ccdcd1cb --- /dev/null +++ b/web_group_expand/static/src/js/web_group_expand_menu.js @@ -0,0 +1,76 @@ +odoo.define('web_group_expand.GroupByExpandMenu', function (require) { + "use strict"; + + var core = require('web.core'); + var Widget = require('web.Widget'); + + var QWeb = core.qweb; + + return Widget.extend({ + template: 'SearchView.GroupByExpandMenu', + events: { + 'click .o_group_by_expand': function (event) { + event.preventDefault(); + this.expand_records(); + }, + 'click .o_group_by_shrink': function (event) { + event.preventDefault(); + this.reset_records(); + }, + }, + init: function (parent, groups) { + var self = this; + this._super(parent); + this.searchview = parent; + }, + start: function () { + this._super() + var self = this; + this.do_toggle_visibility(false) + }, + do_toggle_visibility: function (show) { + var self = this; + var $expand_button = this.$('.o_group_by_expand'); + var $shrink_button = this.$('.o_group_by_shrink'); + if (show) { + $expand_button.show() + $shrink_button.show() + } + else { + $expand_button.hide() + $shrink_button.hide() + } + }, + get_search_groups: function (groups) { + var current_search_group = {}; + for (var group in groups) { + if (groups[group].count > 0 && groups[group].data.length > 0) { + current_search_group[groups[group].id] = groups[group].data; + } + } + return current_search_group; + }, + toggle_group_records: function (op, controller) { + var current_search_group = this.get_search_groups(controller.model.localData); + if (current_search_group) { + for (var group in current_search_group) { + for (var gp in current_search_group[group]) { + var cur_group = controller.model.localData[current_search_group[group][gp]] + if ((op && !cur_group.isOpen) || (!op && cur_group.isOpen)) { + controller.trigger_up('toggle_group', { group: cur_group }) + } + } + } + } + }, + expand_records: _.debounce(function () { + var controller = this.searchview.getParent().active_view.controller; + this.toggle_group_records(true, controller) + }, 200, true), + reset_records: _.debounce(function () { + var controller = this.searchview.getParent().active_view.controller; + this.toggle_group_records(false, controller) + }, 200, true), + }); + +}); diff --git a/web_group_expand/static/src/xml/web_group_expand.xml b/web_group_expand/static/src/xml/web_group_expand.xml index 614900a5..9afec5cd 100644 --- a/web_group_expand/static/src/xml/web_group_expand.xml +++ b/web_group_expand/static/src/xml/web_group_expand.xml @@ -1,11 +1,9 @@ \ No newline at end of file diff --git a/web_group_expand/templates/assets.xml b/web_group_expand/templates/assets.xml index 4fcaee58..ec62493c 100644 --- a/web_group_expand/templates/assets.xml +++ b/web_group_expand/templates/assets.xml @@ -4,6 +4,7 @@ +