Browse Source

[IMP/Fix]Improved group by functionality. (#941)

* Fixed the issue of expand shrink buttons showing on discuss menu.
* Added debounce event when buttons are clicked.
* Fixed the issue of buttons are added in FavoriteMenu.
* Restructured the code to fix other various issue like only display group by expand buttons if group by button is visible. NOTE: Earlier code was not honoring disable_groupby by flag in searchview
pull/950/head
Meet Dholakiya 7 years ago
committed by Pedro M. Baeza
parent
commit
442f5b7d61
  1. 1
      web_group_expand/README.rst
  2. 2
      web_group_expand/__manifest__.py
  3. 86
      web_group_expand/static/src/js/web_group_expand.js
  4. 76
      web_group_expand/static/src/js/web_group_expand_menu.js
  5. 12
      web_group_expand/static/src/xml/web_group_expand.xml
  6. 1
      web_group_expand/templates/assets.xml

1
web_group_expand/README.rst

@ -44,6 +44,7 @@ Contributors
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> * Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Jay Vora (SerpentCS) for their alternative implementation * Jay Vora (SerpentCS) for their alternative implementation
* Aldo Soares <soares_aldo@hotmail.com> * Aldo Soares <soares_aldo@hotmail.com>
* Meet Dholakia <meetcomputer009@gmail.com>
Maintainer Maintainer
---------- ----------

2
web_group_expand/__manifest__.py

@ -3,7 +3,7 @@
'summary': """ 'summary': """
Enables expanding/reset all groups in list view Enables expanding/reset all groups in list view
""", """,
"version": "11.0.1.0.0",
"version": "11.0.1.0.1",
"category": "Web", "category": "Web",
"author": "OpenERP SA, " "author": "OpenERP SA, "
"AvanzOSC, " "AvanzOSC, "

86
web_group_expand/static/src/js/web_group_expand.js

@ -1,75 +1,43 @@
odoo.define('web_groupby_expand.web_groupby_expand', function (require) {
odoo.define('web_group_expand.web_group_expand', function (require) {
"use strict"; "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;
SearchView.include({
init: function (parent, dataset, fvg, options) {
this._super.apply(this, arguments);
this.groupby_expand_menu = undefined;
}, },
_process_search_data: function () {
start: function () {
var res = this._super.apply(this, arguments); 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)
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));
} }
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;
})
}, },
})
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;
}, },
}); });
}); });

76
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),
});
});

12
web_group_expand/static/src/xml/web_group_expand.xml

@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<template xml:space="preserve"> <template xml:space="preserve">
<t t-extend="SearchView.FavoriteMenu">
<t t-jquery=".o_favorites_menu" t-operation="after">
<div class="toggle_buttons">
<button id="oe_group_by_expand" class="fa fa-expand btn btn-icon"/>
<button id="oe_group_by_reset" class="fa fa-compress btn btn-icon"/>
<div t-name="SearchView.GroupByExpandMenu" class="btn-group">
<button class="btn btn-sm fa fa-expand btn btn-icon o_group_by_expand"
title="Expand"/>
<button class="btn btn-sm fa fa-compress btn btn-icon o_group_by_shrink"
title="Shrink"/>
</div> </div>
</t>
</t>
</template> </template>

1
web_group_expand/templates/assets.xml

@ -4,6 +4,7 @@
<xpath expr="." position="inside"> <xpath expr="." position="inside">
<link rel="stylesheet" href="/web_group_expand/static/src/css/web_group_expand.css"/> <link rel="stylesheet" href="/web_group_expand/static/src/css/web_group_expand.css"/>
<script type="text/javascript" src="/web_group_expand/static/src/js/web_group_expand.js"></script> <script type="text/javascript" src="/web_group_expand/static/src/js/web_group_expand.js"></script>
<script type="text/javascript" src="/web_group_expand/static/src/js/web_group_expand_menu.js"></script>
</xpath> </xpath>
</template> </template>
</odoo> </odoo>
Loading…
Cancel
Save