This commit is contained in:
ivan deng
2017-07-25 12:41:57 +08:00
commit 1d0c6d6bb8
13 changed files with 261 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
.o_main_content .o_list_buttons {
position:relative;
}

View File

@@ -0,0 +1,97 @@
odoo.define('app_dynamic_list.shcolumns', function (require) {
"use strict";
var core = require('web.core');
var ListView = require('web.ListView');
var QWeb = core.qweb;
ListView.include({
reload: function () {
this.setup_columns(this.fields_view.fields, this.grouped);
this.$el.html(QWeb.render(this._template, this));
return this.reload_content();
},
render_buttons: function($node) {
var self = this;
this._super($node);
this.$buttons.find('.oe_select_columns').click(this.proxy('my_setup_columns'));
this.$buttons.find('.oe_dropdown_btn').click(this.proxy('hide_show_columns'));
this.$buttons.find('.dropdown-menu').click(this.proxy('stop_event'));
},
my_setup_columns: function (fields, grouped) {
$("#showcb").toggle();
var getcb = document.getElementById('showcb');
this.visible_columns = _.filter(this.columns, function (column) {
var firstcheck = document.getElementById(column.id);
if(firstcheck == null)
{
var li= document.createElement("li");
var description = document.createTextNode(column.string);
var checkbox = document.createElement("input");
checkbox.id = column.id;
checkbox.type = "checkbox";
checkbox.name = "cb";
if(column.invisible !== '1')
{
checkbox.checked = true;
}
li.appendChild(checkbox);
li.appendChild(description);
getcb.appendChild(li);
}
else
{
if(column.invisible !== '1')
{
firstcheck.checked = true;
}
else
{
firstcheck.checked = false;
}
}
});
},
stop_event : function(e)
{
e.stopPropagation();
},
hide_show_columns : function()
{
$("#showcb").hide();
this.setup_columns(this.fields_view.fields, this.grouped);
this.$el.html(QWeb.render(this._template, this));
return this.reload_content();
},
setup_columns: function (fields, grouped) {
this._super(fields, grouped);
this.visible_columns = _.filter(this.columns, function (column) {
var cbid = document.getElementById(column.id);
if(cbid !== null)
{
var cbid = cbid.checked;
if(cbid !== false)
{
column.invisible = '2';
}
else
{
column.invisible = '1';
}
}
return column.invisible !== '1';
});
this.aggregate_columns = _(this.visible_columns).invoke('to_aggregate');
},
});
$(document).click(function(){
$("#showcb").hide();
});
});

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<templates t-name="selectcolumns">
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_button_add" t-operation="after">
<button name="select_columns" id="select_columns"
class="oe_select_columns btn btn-default btn-sm dropdown-toggle dropdown-toggle"
data-toggle="dropdown">
Set Columns
<span class="caret"></span>
</button>
<ul id="showcb" class="dropdown-menu" style="max-height:320px; overflow:auto;padding: 3px 10px;right:0px;left:auto;">
<li>
<button name="apply" id="apply" class="oe_dropdown_btn btn btn-primary btn-block">
Apply
</button>
</li>
</ul>
</t>
</t>
</templates>