openerp.web.list = function (openerp) { var _t = openerp.web._t, _lt = openerp.web._lt; var QWeb = openerp.web.qweb; openerp.web.views.add('list', 'openerp.web.ListView'); openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView# */ { _template: 'ListView', display_name: _lt('List'), defaults: { // records can be selected one by one 'selectable': true, // list rows can be deleted 'deletable': true, // whether the column headers should be displayed 'header': true, // display addition button, with that label 'addable': _lt("Create"), // whether the list view can be sorted, note that once a view has been // sorted it can not be reordered anymore 'sortable': true, // whether the view rows can be reordered (via vertical drag & drop) 'reorderable': true, // display an edit icon linking to form view 'isClarkGable': true }, /** * Core class for list-type displays. * * As a view, needs a number of view-related parameters to be correctly * instantiated, provides options and overridable methods for behavioral * customization. * * See constructor parameters and method documentations for information on * the default behaviors and possible options for the list view. * * @constructs openerp.web.ListView * @extends openerp.web.View * * @param parent parent object * @param {openerp.web.DataSet} dataset the dataset the view should work with * @param {String} view_id the listview's identifier, if any * @param {Object} options A set of options used to configure the view * @param {Boolean} [options.selectable=true] determines whether view rows are selectable (e.g. via a checkbox) * @param {Boolean} [options.header=true] should the list's header be displayed * @param {Boolean} [options.deletable=true] are the list rows deletable * @param {void|String} [options.addable="New"] should the new-record button be displayed, and what should its label be. Use ``null`` to hide the button. * @param {Boolean} [options.sortable=true] is it possible to sort the table by clicking on column headers * @param {Boolean} [options.reorderable=true] is it possible to reorder list rows */ init: function(parent, dataset, view_id, options) { var self = this; this._super(parent); this.set_default_options(_.extend({}, this.defaults, options || {})); this.dataset = dataset; this.model = dataset.model; this.view_id = view_id; this.previous_colspan = null; this.colors = null; this.columns = []; this.records = new Collection(); this.set_groups(new openerp.web.ListView.Groups(this)); if (this.dataset instanceof openerp.web.DataSetStatic) { this.groups.datagroup = new openerp.web.StaticDataGroup(this.dataset); } else { this.groups.datagroup = new openerp.web.DataGroup( this, this.model, dataset.get_domain(), dataset.get_context(), {}); this.groups.datagroup.sort = this.dataset._sort; } this.page = 0; this.records.bind('change', function (event, record, key) { if (!_(self.aggregate_columns).chain() .pluck('name').contains(key).value()) { return; } self.compute_aggregates(); }); this.no_leaf = false; }, /** * Retrieves the view's number of records per page (|| section) * * options > defaults > parent.action.limit > indefinite * * @returns {Number|null} */ limit: function () { if (this._limit === undefined) { this._limit = (this.options.limit || this.defaults.limit || (this.widget_parent.action || {}).limit || null); } return this._limit; }, /** * Set a custom Group construct as the root of the List View. * * @param {openerp.web.ListView.Groups} groups */ set_groups: function (groups) { var self = this; if (this.groups) { $(this.groups).unbind("selected deleted action row_link"); delete this.groups; } this.groups = groups; $(this.groups).bind({ 'selected': function (e, ids, records) { self.do_select(ids, records); }, 'deleted': function (e, ids) { self.do_delete(ids); }, 'action': function (e, action_name, id, callback) { self.do_button_action(action_name, id, callback); }, 'row_link': function (e, id, dataset, view) { self.do_activate_record(dataset.index, id, dataset, view); } }); }, /** * View startup method, the default behavior is to set the ``oe-listview`` * class on its root element and to perform an RPC load call. * * @returns {$.Deferred} loading promise */ start: function() { this._super(); this.$element.addClass('oe-listview'); return this.reload_view(null, null, true); }, /** * Returns the color for the provided record in the current view (from the * ``@colors`` attribute) * * @param {Record} record record for the current row * @returns {String} CSS color declaration */ color_for: function (record) { if (!this.colors) { return ''; } var context = _.extend({}, record.attributes, { uid: this.session.uid, current_date: new Date().toString('yyyy-MM-dd') // TODO: time, datetime, relativedelta }); for(var i=0, len=this.colors.length; i') .siblings('.oe-sortable').find('span').remove(); } self.reload_content(); }); this.$element.find('.oe-list-pager') .delegate('button', 'click', function () { var $this = $(this); switch ($this.data('pager-action')) { case 'first': self.page = 0; break; case 'last': self.page = Math.floor( self.dataset.ids.length / self.limit()); break; case 'next': self.page += 1; break; case 'previous': self.page -= 1; break; } self.reload_content(); }).find('.oe-pager-state') .click(function (e) { e.stopPropagation(); var $this = $(this); var $select = $('