odoo.define('web_pivot.PivotView', function (require) {
"use strict";
/*---------------------------------------------------------
 * Odoo Pivot Table view (Extended)
 *---------------------------------------------------------*/

var core = require('web.core');
var PivotView = require('web.PivotView');
var _lt = core._lt;
var _t = core._t;
var QWeb = core.qweb;

    PivotView.include({
        start: function () {
            this.$el.toggleClass('o_enable_linking', this.enable_linking);
            var self = this;
            var remove = [];
            if(self.fields_view.arch.attrs.hasOwnProperty('remove') ){
                        remove = eval(self.fields_view.arch.attrs.remove)
            }
            remove.map(function (r) {
                if(r in self.groupable_fields){
                    delete self.groupable_fields[r]
                }
            });
            var context = {
                fields: _.chain(this.groupable_fields).pairs().sortBy(function(f) {
                    return f[1].string;
                }).value(),
            };
            this.$field_selection = this.$('.o_field_selection');

            this.$field_selection.html(QWeb.render('PivotView.FieldSelection', context));
            core.bus.on('click', this, function () {
                this.$field_selection.find('ul').first().hide();
            });
            return this._super();
        }
    });
});
