(function() { var instance = openerp; openerp.web.list = {}; var _t = instance.web._t, _lt = instance.web._lt; var QWeb = instance.web.qweb; instance.web.views.add('list', 'instance.web.ListView'); instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListView# */ { _template: 'ListView', display_name: _lt('List'), defaults: { // records can be selected one by one 'selectable': true, // list rows can be deleted 'deletable': false, // 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, 'action_buttons': true, //whether the editable property of the view has to be disabled 'disable_editable_mode': false, }, view_type: 'tree', events: { 'click thead th.oe_sortable[data-id]': 'sort_by_column' }, /** * 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 instance.web.ListView * @extends instance.web.View * * @param parent parent object * @param {instance.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.fonts = null; this.columns = []; this.records = new Collection(); this.set_groups(new (this.options.GroupsType)(this)); if (this.dataset instanceof instance.web.DataSetStatic) { this.groups.datagroup = new StaticDataGroup(this.dataset); } else { this.groups.datagroup = new 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; this.grouped = false; }, view_loading: function(r) { return this.load_list(r); }, set_default_options: function (options) { this._super(options); _.defaults(this.options, { GroupsType: instance.web.ListView.Groups, ListType: instance.web.ListView.List }); }, /** * 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.getParent().action || {}).limit || 80); } return this._limit; }, /** * Set a custom Group construct as the root of the List View. * * @param {instance.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, deselected) { self.do_select(ids, records, deselected); }, '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_list`` * class on its root element and to perform an RPC load call. * * @returns {$.Deferred} loading promise */ start: function() { this.$el.addClass('oe_list'); return this._super(); }, /** * Returns the style for the provided record in the current view (from the * ``@colors`` and ``@fonts`` attributes) * * @param {Record} record record for the current row * @returns {String} CSS style declaration */ style_for: function (record) { var len, style= ''; var context = _.extend({}, record.attributes, { uid: this.session.uid, current_date: new Date().toString('yyyy-MM-dd') // TODO: time, datetime, relativedelta }); var i; var pair; var expression; if (this.fonts) { for(i=0, len=this.fonts.length; i max_page) { self.page = 0; } self.reload_content(); }).find('.oe_list_pager_state') .click(function (e) { e.stopPropagation(); var $this = $(this); var $select = $('', row_data[this.id].value ? 'checked="checked"' : ''); } }); instance.web.list.Binary = instance.web.list.Column.extend({ /** * Return a link to the binary data as a file * * @private */ _format: function (row_data, options) { var text = _t("Download"); var value = row_data[this.id].value; var download_url; if (value && value.substr(0, 10).indexOf(' ') == -1) { download_url = "data:application/octet-stream;base64," + value; } else { download_url = instance.session.url('/web/binary/saveas', {model: options.model, field: this.id, id: options.id}); if (this.filename) { download_url += '&filename_field=' + this.filename; } } if (this.filename && row_data[this.filename]) { text = _.str.sprintf(_t("Download \"%s\""), instance.web.format_value( row_data[this.filename].value, {type: 'char'})); } return _.template('<%-text%> (<%-size%>)', { text: text, href: download_url, size: instance.web.binary_to_binsize(value), }); } }); instance.web.list.Char = instance.web.list.Column.extend({ replacement: '*', /** * If password field, only display replacement characters (if value is * non-empty) */ _format: function (row_data, options) { var value = row_data[this.id].value; if (value && this.password === 'True') { return value.replace(/[\s\S]/g, _.escape(this.replacement)); } return this._super(row_data, options); } }); instance.web.list.ProgressBar = instance.web.list.Column.extend({ /** * Return a formatted progress bar display * * @private */ _format: function (row_data, options) { return _.template( '<%-value%>%', { value: _.str.sprintf("%.0f", row_data[this.id].value || 0) }); } }); instance.web.list.Handle = instance.web.list.Column.extend({ init: function () { this._super.apply(this, arguments); // Handle overrides the field to not be form-editable. this.modifiers.readonly = true; }, /** * Return styling hooks for a drag handle * * @private */ _format: function (row_data, options) { return '
'; } }); instance.web.list.Many2OneButton = instance.web.list.Column.extend({ _format: function (row_data, options) { this.has_value = !!row_data[this.id].value; this.icon = this.has_value ? 'gtk-yes' : 'gtk-no'; this.string = this.has_value ? _t('View') : _t('Create'); return QWeb.render('Many2OneButton.cell', { 'widget': this, 'prefix': instance.session.prefix, }); }, }); instance.web.list.Many2Many = instance.web.list.Column.extend({ _format: function (row_data, options) { if (!_.isEmpty(row_data[this.id].value)) { // If value, use __display version for printing row_data[this.id] = row_data[this.id + '__display']; } return this._super(row_data, options); } }); instance.web.list.Reference = instance.web.list.Column.extend({ _format: function (row_data, options) { if (!_.isEmpty(row_data[this.id].value)) { // If value, use __display version for printing if (!!row_data[this.id + '__display']) { row_data[this.id] = row_data[this.id + '__display']; } else { row_data[this.id] = {'value': ''}; } } return this._super(row_data, options); } }); })(); // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: