2011-03-30 14:35:56 +00:00
|
|
|
openerp.base.list = function (openerp) {
|
2011-05-16 10:59:50 +00:00
|
|
|
'use strict';
|
2011-03-31 15:25:31 +00:00
|
|
|
openerp.base.views.add('list', 'openerp.base.ListView');
|
2011-05-11 14:49:10 +00:00
|
|
|
openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListView# */ {
|
2011-04-07 12:12:22 +00:00
|
|
|
defaults: {
|
|
|
|
// records can be selected one by one
|
2011-04-07 13:27:26 +00:00
|
|
|
'selectable': true,
|
2011-04-07 15:13:19 +00:00
|
|
|
// list rows can be deleted
|
|
|
|
'deletable': true,
|
2011-04-07 13:27:26 +00:00
|
|
|
// whether the column headers should be displayed
|
2011-04-12 13:02:29 +00:00
|
|
|
'header': true,
|
|
|
|
// display addition button, with that label
|
2011-04-21 12:06:08 +00:00
|
|
|
'addable': "New",
|
|
|
|
// 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
|
2011-04-07 12:12:22 +00:00
|
|
|
},
|
|
|
|
/**
|
2011-04-21 11:59:24 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2011-04-07 12:12:22 +00:00
|
|
|
* @constructs
|
|
|
|
* @param view_manager
|
|
|
|
* @param session An OpenERP session object
|
|
|
|
* @param element_id the id of the DOM elements this view should link itself to
|
|
|
|
* @param {openerp.base.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)
|
2011-04-07 13:27:26 +00:00
|
|
|
* @param {Boolean} [options.header=true] should the list's header be displayed
|
2011-04-07 15:13:19 +00:00
|
|
|
* @param {Boolean} [options.deletable=true] are the list rows deletable
|
2011-04-12 13:02:29 +00:00
|
|
|
* @param {null|String} [options.addable="New"] should the new-record button be displayed, and what should its label be. Use ``null`` to hide the button.
|
2011-04-21 12:06:08 +00:00
|
|
|
* @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
|
2011-05-04 09:23:51 +00:00
|
|
|
*
|
|
|
|
* @borrows openerp.base.ActionExecutor#execute_action as #execute_action
|
2011-04-07 12:12:22 +00:00
|
|
|
*/
|
|
|
|
init: function(view_manager, session, element_id, dataset, view_id, options) {
|
2011-05-06 12:28:37 +00:00
|
|
|
var self = this;
|
2011-03-30 14:00:48 +00:00
|
|
|
this._super(session, element_id);
|
2011-05-24 11:30:13 +00:00
|
|
|
this.view_manager = view_manager || new openerp.base.NullViewManager();
|
2011-03-30 14:00:48 +00:00
|
|
|
this.dataset = dataset;
|
|
|
|
this.model = dataset.model;
|
|
|
|
this.view_id = view_id;
|
|
|
|
|
2011-04-06 13:58:37 +00:00
|
|
|
this.columns = [];
|
2011-03-30 14:00:48 +00:00
|
|
|
|
2011-04-07 12:12:22 +00:00
|
|
|
this.options = _.extend({}, this.defaults, options || {});
|
2011-05-24 11:30:13 +00:00
|
|
|
this.flags = this.view_manager.action.flags;
|
2011-05-06 12:28:37 +00:00
|
|
|
|
2011-05-18 09:06:30 +00:00
|
|
|
this.groups = new openerp.base.ListView.Groups(this, {
|
2011-05-10 11:07:23 +00:00
|
|
|
options: this.options,
|
|
|
|
columns: this.columns
|
|
|
|
});
|
2011-05-17 14:03:58 +00:00
|
|
|
$(this.groups).bind({
|
2011-05-25 09:28:13 +00:00
|
|
|
'selected': function (e, ids, records) {
|
|
|
|
self.do_select(ids, records);
|
2011-05-06 14:07:15 +00:00
|
|
|
},
|
|
|
|
'deleted': function (e, ids) {
|
|
|
|
self.do_delete(ids);
|
2011-05-09 08:10:22 +00:00
|
|
|
},
|
2011-05-19 11:13:09 +00:00
|
|
|
'action': function (e, action_name, id, callback) {
|
2011-05-09 08:10:22 +00:00
|
|
|
var action = _.detect(self.columns, function (field) {
|
|
|
|
return field.name === action_name;
|
|
|
|
});
|
|
|
|
if (!action) { return; }
|
|
|
|
self.execute_action(
|
|
|
|
action, self.dataset, self.session.action_manager,
|
2011-05-19 11:13:09 +00:00
|
|
|
id, function () {
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
2011-05-09 08:22:12 +00:00
|
|
|
},
|
2011-05-20 14:20:41 +00:00
|
|
|
'row_link': function (e, index, id, dataset) {
|
|
|
|
_.extend(self.dataset, {
|
|
|
|
domain: dataset.domain,
|
|
|
|
context: dataset.context
|
|
|
|
}).read_slice([], null, null, function () {
|
|
|
|
self.select_record(index);
|
|
|
|
});
|
2011-05-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-03-30 14:00:48 +00:00
|
|
|
},
|
2011-04-21 11:59:24 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2011-03-30 14:00:48 +00:00
|
|
|
start: function() {
|
2011-04-12 09:22:22 +00:00
|
|
|
this.$element.addClass('oe-listview');
|
2011-04-21 11:59:24 +00:00
|
|
|
return this.rpc("/base/listview/load", {
|
|
|
|
model: this.model,
|
|
|
|
view_id: this.view_id,
|
2011-05-24 11:30:13 +00:00
|
|
|
toolbar: !!this.flags.sidebar
|
2011-04-21 11:59:24 +00:00
|
|
|
}, this.on_loaded);
|
2011-03-30 14:00:48 +00:00
|
|
|
},
|
2011-04-21 11:59:24 +00:00
|
|
|
/**
|
|
|
|
* Called after loading the list view's description, sets up such things
|
|
|
|
* as the view table's columns, renders the table itself and hooks up the
|
|
|
|
* various table-level and row-level DOM events (action buttons, deletion
|
|
|
|
* buttons, selection of records, [New] button, selection of a given
|
|
|
|
* record, ...)
|
|
|
|
*
|
|
|
|
* Sets up the following:
|
|
|
|
*
|
|
|
|
* * Processes arch and fields to generate a complete field descriptor for each field
|
|
|
|
* * Create the table itself and allocate visible columns
|
|
|
|
* * Hook in the top-level (header) [New|Add] and [Delete] button
|
|
|
|
* * Sets up showing/hiding the top-level [Delete] button based on records being selected or not
|
|
|
|
* * Sets up event handlers for action buttons and per-row deletion button
|
|
|
|
* * Hooks global callback for clicking on a row
|
|
|
|
* * Sets up its sidebar, if any
|
|
|
|
*
|
|
|
|
* @param {Object} data wrapped fields_view_get result
|
|
|
|
* @param {Object} data.fields_view fields_view_get result (processed)
|
|
|
|
* @param {Object} data.fields_view.fields mapping of fields for the current model
|
|
|
|
* @param {Object} data.fields_view.arch current list view descriptor
|
2011-05-17 14:03:58 +00:00
|
|
|
* @param {Array} columns columns to move to the front (and make visible)
|
2011-04-21 11:59:24 +00:00
|
|
|
*/
|
2011-05-17 14:03:58 +00:00
|
|
|
on_loaded: function(data, columns) {
|
2011-04-12 14:55:16 +00:00
|
|
|
var self = this;
|
2011-03-30 14:00:48 +00:00
|
|
|
this.fields_view = data.fields_view;
|
|
|
|
//this.log(this.fields_view);
|
|
|
|
this.name = "" + this.fields_view.arch.attrs.string;
|
|
|
|
|
2011-05-17 14:03:58 +00:00
|
|
|
this.setup_columns(this.fields_view.fields, columns);
|
2011-05-04 14:47:53 +00:00
|
|
|
|
|
|
|
if (!this.fields_view.sorted) { this.fields_view.sorted = {}; }
|
2011-05-06 12:28:37 +00:00
|
|
|
|
2011-04-06 13:58:37 +00:00
|
|
|
this.$element.html(QWeb.render("ListView", this));
|
2011-04-07 15:35:27 +00:00
|
|
|
|
|
|
|
// Head hook
|
2011-04-12 13:02:29 +00:00
|
|
|
this.$element.find('#oe-list-add').click(this.do_add_record);
|
2011-04-12 12:24:02 +00:00
|
|
|
this.$element.find('#oe-list-delete')
|
|
|
|
.hide()
|
|
|
|
.click(this.do_delete_selected);
|
2011-05-04 14:05:35 +00:00
|
|
|
this.$element.find('thead').delegate('th[data-id]', 'click', function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
self.dataset.sort($(this).data('id'));
|
|
|
|
|
2011-05-04 14:47:53 +00:00
|
|
|
// TODO: should only reload content (and set the right column to a sorted display state)
|
2011-05-04 14:05:35 +00:00
|
|
|
self.do_reload();
|
|
|
|
});
|
2011-04-07 15:35:27 +00:00
|
|
|
|
2011-05-24 11:30:13 +00:00
|
|
|
this.view_manager.sidebar.set_toolbar(data.fields_view.toolbar);
|
2011-03-30 14:00:48 +00:00
|
|
|
},
|
2011-04-07 12:12:22 +00:00
|
|
|
/**
|
2011-05-17 14:07:26 +00:00
|
|
|
* Sets up the listview's columns: merges view and fields data, move
|
|
|
|
* grouped-by columns to the front of the columns list and make them all
|
|
|
|
* visible.
|
2011-04-07 12:12:22 +00:00
|
|
|
*
|
2011-05-17 14:07:26 +00:00
|
|
|
* @param {Object} fields fields_view_get's fields section
|
|
|
|
* @param {Array} groupby_columns columns the ListView is grouped by
|
2011-04-07 12:12:22 +00:00
|
|
|
*/
|
2011-05-17 14:03:58 +00:00
|
|
|
setup_columns: function (fields, groupby_columns) {
|
|
|
|
var domain_computer = openerp.base.form.compute_domain;
|
2011-04-12 14:08:29 +00:00
|
|
|
|
2011-05-17 14:07:26 +00:00
|
|
|
var noop = function () { return {}; };
|
2011-05-17 14:03:58 +00:00
|
|
|
var field_to_column = function (field) {
|
|
|
|
var name = field.attrs.name;
|
|
|
|
var column = _.extend({id: name, tag: field.tag},
|
|
|
|
field.attrs, fields[name]);
|
|
|
|
// attrs computer
|
|
|
|
if (column.attrs) {
|
|
|
|
var attrs = eval('(' + column.attrs + ')');
|
|
|
|
column.attrs_for = function (fields) {
|
|
|
|
var result = {};
|
|
|
|
for (var attr in attrs) {
|
|
|
|
result[attr] = domain_computer(attrs[attr], fields);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
} else {
|
2011-05-17 14:07:26 +00:00
|
|
|
column.attrs_for = noop;
|
2011-05-17 14:03:58 +00:00
|
|
|
}
|
|
|
|
return column;
|
|
|
|
};
|
2011-04-13 07:45:39 +00:00
|
|
|
|
2011-05-17 14:03:58 +00:00
|
|
|
this.columns.splice(0, this.columns.length);
|
|
|
|
this.columns.push.apply(
|
|
|
|
this.columns,
|
|
|
|
_(this.fields_view.arch.children).map(field_to_column));
|
2011-05-24 13:27:29 +00:00
|
|
|
if (groupby_columns) {
|
2011-05-24 06:52:05 +00:00
|
|
|
this.columns.unshift({
|
|
|
|
id: '_group', tag: '', string: "Group", meta: true,
|
|
|
|
attrs_for: function () { return {}; }
|
|
|
|
}, {
|
|
|
|
id: '_count', tag: '', string: '#', meta: true,
|
|
|
|
attrs_for: function () { return {}; }
|
|
|
|
});
|
|
|
|
}
|
2011-04-07 12:12:22 +00:00
|
|
|
|
2011-05-17 14:03:58 +00:00
|
|
|
this.visible_columns = _.filter(this.columns, function (column) {
|
|
|
|
return column.invisible !== '1';
|
|
|
|
});
|
2011-05-25 13:04:14 +00:00
|
|
|
|
|
|
|
this.aggregate_columns = _(this.columns).chain()
|
|
|
|
.filter(function (column) {
|
|
|
|
return column['sum'] || column['avg'];})
|
|
|
|
.map(function (column) {
|
|
|
|
var func = column['sum'] ? 'sum' : 'avg';
|
|
|
|
return {
|
|
|
|
field: column.id,
|
|
|
|
type: column.type,
|
|
|
|
'function': func,
|
|
|
|
label: column[func]
|
|
|
|
};
|
|
|
|
}).value();
|
2011-03-31 14:44:22 +00:00
|
|
|
},
|
2011-04-12 13:02:29 +00:00
|
|
|
/**
|
2011-04-21 11:59:24 +00:00
|
|
|
* Used to handle a click on a table row, if no other handler caught the
|
|
|
|
* event.
|
|
|
|
*
|
|
|
|
* The default implementation asks the list view's view manager to switch
|
|
|
|
* to a different view (by calling
|
|
|
|
* :js:func:`~openerp.base.ViewManager.on_mode_switch`), using the
|
|
|
|
* provided record index (within the current list view's dataset).
|
2011-04-12 13:02:29 +00:00
|
|
|
*
|
|
|
|
* If the index is null, ``switch_to_record`` asks for the creation of a
|
|
|
|
* new record.
|
|
|
|
*
|
|
|
|
* @param {Number|null} index the record index (in the current dataset) to switch to
|
2011-04-21 11:59:24 +00:00
|
|
|
* @param {String} [view="form"] the view type to switch to
|
2011-04-12 13:02:29 +00:00
|
|
|
*/
|
2011-05-12 09:57:11 +00:00
|
|
|
select_record:function (index, view) {
|
2011-04-12 13:02:29 +00:00
|
|
|
view = view || 'form';
|
|
|
|
this.dataset.index = index;
|
|
|
|
_.delay(_.bind(function () {
|
2011-04-22 15:54:52 +00:00
|
|
|
if(this.view_manager) {
|
|
|
|
this.view_manager.on_mode_switch(view);
|
|
|
|
}
|
2011-04-12 13:02:29 +00:00
|
|
|
}, this));
|
|
|
|
},
|
2011-04-04 15:34:26 +00:00
|
|
|
do_show: function () {
|
|
|
|
this.$element.show();
|
2011-04-12 14:08:29 +00:00
|
|
|
if (this.hidden) {
|
2011-05-20 14:20:41 +00:00
|
|
|
this.$element.find('table').append(
|
|
|
|
this.groups.apoptosis().render());
|
2011-04-12 14:08:29 +00:00
|
|
|
this.hidden = false;
|
|
|
|
}
|
2011-05-24 11:30:13 +00:00
|
|
|
this.view_manager.sidebar.refresh(true);
|
2011-04-04 15:34:26 +00:00
|
|
|
},
|
|
|
|
do_hide: function () {
|
|
|
|
this.$element.hide();
|
2011-04-12 14:08:29 +00:00
|
|
|
this.hidden = true;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Reloads the search view based on the current settings (dataset & al)
|
2011-05-17 14:03:58 +00:00
|
|
|
*
|
|
|
|
* @param {Array} [primary_columns] columns to bring to the front of the
|
|
|
|
* sequence
|
2011-04-12 14:08:29 +00:00
|
|
|
*/
|
2011-05-17 14:03:58 +00:00
|
|
|
do_reload: function (primary_columns) {
|
2011-05-24 09:11:25 +00:00
|
|
|
// TODO: should just fields_view_get I think
|
2011-05-17 14:03:58 +00:00
|
|
|
var self = this;
|
2011-04-13 11:45:06 +00:00
|
|
|
this.dataset.offset = 0;
|
|
|
|
this.dataset.limit = false;
|
2011-04-12 14:08:29 +00:00
|
|
|
return this.rpc('/base/listview/fill', {
|
|
|
|
'model': this.dataset.model,
|
|
|
|
'id': this.view_id,
|
|
|
|
'context': this.dataset.context,
|
2011-05-04 14:05:35 +00:00
|
|
|
'domain': this.dataset.domain,
|
|
|
|
'sort': this.dataset.sort && this.dataset.sort()
|
2011-05-17 14:03:58 +00:00
|
|
|
}, function (result) {
|
|
|
|
if (result.view) {
|
|
|
|
self.on_loaded({fields_view: result.view}, primary_columns);
|
|
|
|
}
|
|
|
|
});
|
2011-04-04 15:34:26 +00:00
|
|
|
},
|
2011-04-21 11:59:24 +00:00
|
|
|
/**
|
|
|
|
* Event handler for a search, asks for the computation/folding of domains
|
|
|
|
* and contexts (and group-by), then reloads the view's content.
|
|
|
|
*
|
|
|
|
* @param {Array} domains a sequence of literal and non-literal domains
|
|
|
|
* @param {Array} contexts a sequence of literal and non-literal contexts
|
|
|
|
* @param {Array} groupbys a sequence of literal and non-literal group-by contexts
|
|
|
|
* @returns {$.Deferred} fold request evaluation promise
|
|
|
|
*/
|
2011-03-31 14:44:22 +00:00
|
|
|
do_search: function (domains, contexts, groupbys) {
|
|
|
|
var self = this;
|
2011-04-12 14:08:29 +00:00
|
|
|
return this.rpc('/base/session/eval_domain_and_context', {
|
2011-03-31 14:44:22 +00:00
|
|
|
domains: domains,
|
|
|
|
contexts: contexts,
|
|
|
|
group_by_seq: groupbys
|
|
|
|
}, function (results) {
|
2011-04-04 15:06:19 +00:00
|
|
|
self.dataset.context = results.context;
|
|
|
|
self.dataset.domain = results.domain;
|
2011-05-17 14:03:58 +00:00
|
|
|
self.groups.datagroup = new openerp.base.DataGroup(
|
|
|
|
self.session, self.dataset.model,
|
|
|
|
results.domain, results.context,
|
|
|
|
results.group_by);
|
2011-05-24 13:27:29 +00:00
|
|
|
|
|
|
|
if (_.isEmpty(results.group_by) && !results.context['group_by_no_leaf']) {
|
|
|
|
results.group_by = null;
|
2011-05-10 08:34:20 +00:00
|
|
|
}
|
2011-05-17 16:09:48 +00:00
|
|
|
self.do_reload(results.group_by).then(function () {
|
2011-05-25 14:04:56 +00:00
|
|
|
self.$element.find('table').append(
|
|
|
|
self.groups.render(function () {
|
|
|
|
self.compute_aggregates();}));});
|
2011-03-31 14:44:22 +00:00
|
|
|
});
|
2011-04-05 10:38:35 +00:00
|
|
|
},
|
2011-04-07 15:13:19 +00:00
|
|
|
/**
|
|
|
|
* Handles the signal to delete a line from the DOM
|
|
|
|
*
|
2011-05-06 14:07:15 +00:00
|
|
|
* @param {Array} ids the id of the object to delete
|
2011-04-07 15:13:19 +00:00
|
|
|
*/
|
2011-05-06 14:07:15 +00:00
|
|
|
do_delete: function (ids) {
|
|
|
|
if (!ids.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var self = this;
|
|
|
|
return $.when(this.dataset.unlink(ids)).then(function () {
|
2011-05-09 06:32:27 +00:00
|
|
|
_(self.rows).chain()
|
|
|
|
.map(function (row, index) {
|
|
|
|
return {
|
|
|
|
index: index,
|
|
|
|
id: row.data.id.value
|
|
|
|
};})
|
|
|
|
.filter(function (record) {
|
|
|
|
return _.contains(ids, record.id);
|
|
|
|
})
|
|
|
|
.sort(function (a, b) {
|
|
|
|
// sort in reverse index order, so we delete from the end
|
|
|
|
// and don't blow up the following indexes (leading to
|
|
|
|
// removing the wrong records from the visible list)
|
|
|
|
return b.index - a.index;
|
|
|
|
})
|
|
|
|
.each(function (record) {
|
|
|
|
self.rows.splice(record.index, 1);
|
|
|
|
});
|
|
|
|
// TODO only refresh modified rows
|
2011-05-06 14:07:15 +00:00
|
|
|
});
|
2011-04-07 15:13:19 +00:00
|
|
|
},
|
2011-05-25 09:28:13 +00:00
|
|
|
/**
|
|
|
|
* Handles the signal indicating that a new record has been selected
|
|
|
|
*
|
|
|
|
* @param {Array} ids selected record ids
|
|
|
|
* @param {Array} records selected record values
|
|
|
|
*/
|
|
|
|
do_select: function (ids, records) {
|
|
|
|
this.$element.find('#oe-list-delete')
|
|
|
|
.toggle(!!ids.length);
|
2011-05-25 13:04:14 +00:00
|
|
|
|
|
|
|
if (!records.length) {
|
|
|
|
this.compute_aggregates();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.compute_aggregates(records);
|
2011-05-25 09:28:13 +00:00
|
|
|
},
|
2011-04-12 13:02:29 +00:00
|
|
|
/**
|
|
|
|
* Handles signal for the addition of a new record (can be a creation,
|
|
|
|
* can be the addition from a remote source, ...)
|
|
|
|
*
|
|
|
|
* The default implementation is to switch to a new record on the form view
|
|
|
|
*/
|
|
|
|
do_add_record: function () {
|
2011-04-12 13:21:20 +00:00
|
|
|
this.notification.notify('Add', "New record");
|
2011-05-12 09:57:11 +00:00
|
|
|
this.select_record(null);
|
2011-04-12 13:02:29 +00:00
|
|
|
},
|
2011-04-07 15:35:27 +00:00
|
|
|
/**
|
|
|
|
* Handles deletion of all selected lines
|
|
|
|
*/
|
|
|
|
do_delete_selected: function () {
|
2011-05-25 09:28:13 +00:00
|
|
|
this.do_delete(this.groups.get_selection().ids);
|
2011-05-25 13:04:14 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Computes the aggregates for the current list view, either on the
|
|
|
|
* records provided or on the records of the internal
|
|
|
|
* :js:class:`~openerp.base.ListView.Group`, by calling
|
|
|
|
* :js:func:`~openerp.base.ListView.group.get_records`.
|
|
|
|
*
|
|
|
|
* Then displays the aggregates in the table through
|
|
|
|
* :js:method:`~openerp.base.ListView.display_aggregates`.
|
|
|
|
*
|
|
|
|
* @param {Array} [records]
|
|
|
|
*/
|
|
|
|
compute_aggregates: function (records) {
|
|
|
|
if (_.isEmpty(this.aggregate_columns)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_.isEmpty(records)) {
|
|
|
|
records = this.groups.get_records();
|
|
|
|
}
|
|
|
|
|
|
|
|
var aggregator = this.build_aggregator(this.aggregate_columns);
|
|
|
|
this.display_aggregates(
|
|
|
|
_(records).reduce(aggregator, aggregator).value());
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Creates a stateful callable aggregator object, which can be reduced over
|
|
|
|
* a collection of records in order to build the aggregations described
|
|
|
|
* by the parameter
|
|
|
|
*
|
|
|
|
* @param {Array} aggregation_descriptors
|
|
|
|
*/
|
|
|
|
build_aggregator: function (aggregation_descriptors) {
|
|
|
|
var values = {};
|
|
|
|
var descriptors = {};
|
|
|
|
_(aggregation_descriptors).each(function (descriptor) {
|
|
|
|
values[descriptor.field] = [];
|
|
|
|
descriptors[descriptor.field] = descriptor;
|
|
|
|
});
|
|
|
|
|
|
|
|
var aggregator = function (_i, record) {
|
|
|
|
_(values).each(function (collection, key) {
|
|
|
|
collection.push(record[key]);
|
|
|
|
});
|
|
|
|
|
|
|
|
return aggregator;
|
|
|
|
};
|
|
|
|
aggregator.value = function () {
|
|
|
|
var result = {};
|
|
|
|
|
|
|
|
_(values).each(function (collection, key) {
|
|
|
|
var value;
|
|
|
|
switch(descriptors[key]['function']) {
|
|
|
|
case 'avg':
|
|
|
|
value = (_(collection).chain()
|
|
|
|
.filter(function (item) {
|
|
|
|
return !_.isUndefined(item); })
|
|
|
|
.reduce(function (total, item) {
|
|
|
|
return total + item; }, 0).value()
|
|
|
|
/ collection.length);
|
|
|
|
break;
|
|
|
|
case 'sum':
|
|
|
|
value = (_(collection).chain()
|
|
|
|
.filter(function (item) {
|
|
|
|
return !_.isUndefined(item); })
|
|
|
|
.reduce(function (total, item) {
|
|
|
|
return total + item; }, 0).value());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
result[key] = value;
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
return aggregator;
|
|
|
|
},
|
|
|
|
display_aggregates: function (aggregation) {
|
|
|
|
var $footer = this.$element.find('.oe-list-footer');
|
|
|
|
$footer.text(
|
|
|
|
_(this.aggregate_columns).map(function (column) {
|
|
|
|
return _.sprintf(
|
|
|
|
"%s: %.2f", column.label, aggregation[column.field]);
|
|
|
|
}).join(' '));
|
2011-05-06 12:28:37 +00:00
|
|
|
}
|
|
|
|
// TODO: implement reorder (drag and drop rows)
|
|
|
|
});
|
2011-05-11 14:49:10 +00:00
|
|
|
openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List# */{
|
2011-05-09 06:54:57 +00:00
|
|
|
/**
|
|
|
|
* List display for the ListView, handles basic DOM events and transforms
|
|
|
|
* them in the relevant higher-level events, to which the list view (or
|
|
|
|
* other consumers) can subscribe.
|
|
|
|
*
|
|
|
|
* Events on this object are registered via jQuery.
|
|
|
|
*
|
|
|
|
* Available events:
|
|
|
|
*
|
|
|
|
* `selected`
|
|
|
|
* Triggered when a row is selected (using check boxes), provides an
|
|
|
|
* array of ids of all the selected records.
|
|
|
|
* `deleted`
|
|
|
|
* Triggered when deletion buttons are hit, provide an array of ids of
|
|
|
|
* all the records being marked for suppression.
|
2011-05-09 08:10:22 +00:00
|
|
|
* `action`
|
|
|
|
* Triggered when an action button is clicked, provides two parameters:
|
|
|
|
*
|
|
|
|
* * The name of the action to execute (as a string)
|
|
|
|
* * The id of the record to execute the action on
|
2011-05-09 08:22:12 +00:00
|
|
|
* `row_link`
|
|
|
|
* Triggered when a row of the table is clicked, provides the index (in
|
|
|
|
* the rows array) and id of the selected record to the handle function.
|
2011-05-09 06:54:57 +00:00
|
|
|
*
|
|
|
|
* @constructs
|
|
|
|
* @param {Object} opts display options, identical to those of :js:class:`openerp.base.ListView`
|
|
|
|
*/
|
2011-05-06 12:28:37 +00:00
|
|
|
init: function (opts) {
|
|
|
|
var self = this;
|
|
|
|
// columns, rows, options
|
|
|
|
|
|
|
|
this.options = opts.options;
|
|
|
|
this.columns = opts.columns;
|
2011-05-20 14:20:41 +00:00
|
|
|
this.dataset = opts.dataset;
|
2011-05-06 12:28:37 +00:00
|
|
|
this.rows = opts.rows;
|
|
|
|
|
|
|
|
this.$_element = $('<tbody class="ui-widget-content">')
|
|
|
|
.appendTo(document.body)
|
|
|
|
.delegate('th.oe-record-selector', 'click', function (e) {
|
2011-05-06 14:07:15 +00:00
|
|
|
e.stopPropagation();
|
2011-05-25 09:28:13 +00:00
|
|
|
var selection = self.get_selection();
|
|
|
|
$(self).trigger('selected', [selection.ids, selection.records]);
|
2011-05-06 14:07:15 +00:00
|
|
|
})
|
|
|
|
.delegate('td.oe-record-delete button', 'click', function (e) {
|
|
|
|
e.stopPropagation();
|
2011-05-09 08:10:22 +00:00
|
|
|
var $row = $(e.target).closest('tr');
|
|
|
|
$(self).trigger('deleted', [[self.row_id($row)]]);
|
|
|
|
})
|
|
|
|
.delegate('td.oe-field-cell button', 'click', function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
var $target = $(e.currentTarget),
|
|
|
|
field = $target.closest('td').data('field'),
|
|
|
|
record_id = self.row_id($target.closest('tr'));
|
|
|
|
|
|
|
|
$(self).trigger('action', [field, record_id]);
|
2011-05-09 08:22:12 +00:00
|
|
|
})
|
|
|
|
.delegate('tr', 'click', function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
$(self).trigger(
|
|
|
|
'row_link',
|
|
|
|
[self.row_position(e.currentTarget),
|
2011-05-20 14:20:41 +00:00
|
|
|
self.row_id(e.currentTarget),
|
|
|
|
self.dataset]);
|
2011-05-06 12:28:37 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
render: function () {
|
2011-05-17 16:09:48 +00:00
|
|
|
if (this.$current) {
|
|
|
|
this.$current.remove();
|
|
|
|
}
|
|
|
|
this.$current = this.$_element.clone(true);
|
2011-05-06 12:28:37 +00:00
|
|
|
this.$current.empty().append($(QWeb.render('ListView.rows', this)));
|
2011-04-07 15:35:27 +00:00
|
|
|
},
|
2011-04-07 12:46:39 +00:00
|
|
|
/**
|
|
|
|
* Gets the ids of all currently selected records, if any
|
2011-05-25 09:28:13 +00:00
|
|
|
* @returns {Object} object with the keys ``ids`` and ``records``, holding respectively the ids of all selected records and the records themselves.
|
2011-04-07 12:46:39 +00:00
|
|
|
*/
|
|
|
|
get_selection: function () {
|
|
|
|
if (!this.options.selectable) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
var rows = this.rows;
|
2011-05-25 09:28:13 +00:00
|
|
|
var result = {ids: [], records: []};
|
|
|
|
this.$current.find('th.oe-record-selector input:checked')
|
|
|
|
.closest('tr').each(function () {
|
|
|
|
var record = {};
|
|
|
|
_(rows[$(this).prevAll().length].data).each(function (obj, key) {
|
|
|
|
record[key] = obj.value;
|
|
|
|
});
|
|
|
|
result.ids.push(record.id);
|
|
|
|
result.records.push(record);
|
|
|
|
});
|
|
|
|
return result;
|
2011-05-06 14:07:15 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Returns the index of the row in the list of rows.
|
|
|
|
*
|
|
|
|
* @param {Object} row the selected row
|
|
|
|
* @returns {Number} the position of the row in this.rows
|
|
|
|
*/
|
|
|
|
row_position: function (row) {
|
|
|
|
return $(row).prevAll().length;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Returns the identifier of the object displayed in the provided table
|
|
|
|
* row
|
|
|
|
*
|
|
|
|
* @param {Object} row the selected table row
|
|
|
|
* @returns {Number|String} the identifier of the row's object
|
|
|
|
*/
|
|
|
|
row_id: function (row) {
|
|
|
|
return this.rows[this.row_position(row)].data.id.value;
|
2011-05-19 09:22:22 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Death signal, cleans up list
|
|
|
|
*/
|
|
|
|
apoptosis: function () {
|
2011-05-20 13:30:45 +00:00
|
|
|
if (!this.$current) { return; }
|
2011-05-19 09:22:22 +00:00
|
|
|
this.$current.remove();
|
|
|
|
this.$current = null;
|
2011-05-25 13:04:14 +00:00
|
|
|
},
|
|
|
|
get_records: function () {
|
|
|
|
return _(this.rows).map(function (row) {
|
|
|
|
var record = {};
|
|
|
|
_(row.data).each(function (obj, key) {
|
|
|
|
record[key] = obj.value;
|
|
|
|
});
|
|
|
|
return record;
|
|
|
|
});
|
2011-03-30 14:00:48 +00:00
|
|
|
}
|
2011-05-06 12:28:37 +00:00
|
|
|
// drag and drop
|
|
|
|
// editable?
|
2011-03-30 14:00:48 +00:00
|
|
|
});
|
2011-05-11 14:49:10 +00:00
|
|
|
openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Groups# */{
|
2011-05-10 11:07:23 +00:00
|
|
|
/**
|
|
|
|
* Grouped display for the ListView. Handles basic DOM events and interacts
|
|
|
|
* with the :js:class:`~openerp.base.DataGroup` bound to it.
|
|
|
|
*
|
|
|
|
* Provides events similar to those of
|
|
|
|
* :js:class:`~openerp.base.ListView.List`
|
|
|
|
*/
|
2011-05-18 09:06:30 +00:00
|
|
|
init: function (view, opts) {
|
|
|
|
this.view = view;
|
2011-05-10 11:07:23 +00:00
|
|
|
this.options = opts.options;
|
|
|
|
this.columns = opts.columns;
|
|
|
|
this.datagroup = {};
|
2011-05-18 14:35:17 +00:00
|
|
|
|
2011-05-19 09:22:22 +00:00
|
|
|
this.sections = [];
|
|
|
|
this.children = {};
|
2011-05-10 11:07:23 +00:00
|
|
|
},
|
2011-05-17 16:09:48 +00:00
|
|
|
pad: function ($row) {
|
|
|
|
if (this.options.selectable) {
|
|
|
|
$row.append('<td>');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
make_fragment: function () {
|
2011-05-19 09:22:22 +00:00
|
|
|
return document.createDocumentFragment();
|
2011-05-17 16:09:48 +00:00
|
|
|
},
|
2011-05-19 09:22:22 +00:00
|
|
|
/**
|
|
|
|
* Returns a DOM node after which a new tbody can be inserted, so that it
|
|
|
|
* follows the provided row.
|
|
|
|
*
|
|
|
|
* Necessary to insert the result of a new group or list view within an
|
|
|
|
* existing groups render, without losing track of the groups's own
|
|
|
|
* elements
|
|
|
|
*
|
|
|
|
* @param {HTMLTableRowElement} row the row after which the caller wants to insert a body
|
|
|
|
* @returns {HTMLTableSectionElement} element after which a tbody can be inserted
|
|
|
|
*/
|
|
|
|
point_insertion: function (row) {
|
|
|
|
var $row = $(row);
|
|
|
|
var red_letter_tbody = $row.closest('tbody')[0];
|
2011-05-18 13:00:09 +00:00
|
|
|
|
2011-05-19 09:22:22 +00:00
|
|
|
var $next_siblings = $row.nextAll();
|
|
|
|
if ($next_siblings.length) {
|
|
|
|
var $root_kanal = $('<tbody>').insertAfter(red_letter_tbody);
|
2011-05-18 13:00:09 +00:00
|
|
|
|
2011-05-19 09:22:22 +00:00
|
|
|
$root_kanal.append($next_siblings);
|
|
|
|
this.elements.splice(
|
|
|
|
_.indexOf(this.elements, red_letter_tbody),
|
|
|
|
0,
|
|
|
|
$root_kanal[0]);
|
|
|
|
}
|
|
|
|
return red_letter_tbody;
|
|
|
|
},
|
|
|
|
open_group: function (e, group) {
|
|
|
|
var row = e.currentTarget;
|
|
|
|
|
|
|
|
if (this.children[group.value]) {
|
|
|
|
this.children[group.value].apoptosis();
|
|
|
|
delete this.children[group.value];
|
|
|
|
}
|
|
|
|
var prospekt = this.children[group.value] = new openerp.base.ListView.Groups(this.view, {
|
|
|
|
options: this.options,
|
|
|
|
columns: this.columns
|
2011-05-18 13:00:09 +00:00
|
|
|
});
|
2011-05-19 11:13:09 +00:00
|
|
|
this.bind_child_events(prospekt);
|
2011-05-19 09:22:22 +00:00
|
|
|
prospekt.datagroup = group;
|
|
|
|
prospekt.render().insertAfter(
|
|
|
|
this.point_insertion(row));
|
2011-05-20 13:08:54 +00:00
|
|
|
$(row).find('span.ui-icon')
|
|
|
|
.removeClass('ui-icon-triangle-1-e')
|
|
|
|
.addClass('ui-icon-triangle-1-s');
|
2011-05-18 13:00:09 +00:00
|
|
|
},
|
2011-05-24 06:52:05 +00:00
|
|
|
/**
|
|
|
|
* Prefixes ``$node`` with floated spaces in order to indent it relative
|
|
|
|
* to its own left margin/baseline
|
|
|
|
*
|
|
|
|
* @param {jQuery} $node jQuery object to indent
|
|
|
|
* @param {Number} level current nesting level, >= 1
|
|
|
|
* @returns {jQuery} the indentation node created
|
|
|
|
*/
|
|
|
|
indent: function ($node, level) {
|
|
|
|
return $('<span>')
|
|
|
|
.css({'float': 'left', 'white-space': 'pre'})
|
|
|
|
.text(new Array(level).join(' '))
|
|
|
|
.prependTo($node);
|
|
|
|
},
|
2011-05-17 16:09:48 +00:00
|
|
|
render_groups: function (datagroups) {
|
|
|
|
var self = this;
|
|
|
|
var placeholder = this.make_fragment();
|
|
|
|
_(datagroups).each(function (group) {
|
2011-05-24 09:11:25 +00:00
|
|
|
var $row = $('<tr>');
|
2011-05-24 10:26:54 +00:00
|
|
|
if (group.openable) {
|
2011-05-24 09:11:25 +00:00
|
|
|
$row.click(function (e) {
|
|
|
|
if (!$row.data('open')) {
|
|
|
|
$row.data('open', true);
|
|
|
|
self.open_group(e, group);
|
|
|
|
} else {
|
|
|
|
$row.removeData('open')
|
|
|
|
.find('span.ui-icon')
|
|
|
|
.removeClass('ui-icon-triangle-1-s')
|
|
|
|
.addClass('ui-icon-triangle-1-e');
|
|
|
|
_(self.children).each(function (child) {child.apoptosis();});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-05-17 16:09:48 +00:00
|
|
|
placeholder.appendChild($row[0]);
|
|
|
|
|
2011-05-24 11:57:55 +00:00
|
|
|
|
2011-05-24 13:27:29 +00:00
|
|
|
var $group_column = $('<th>').appendTo($row);
|
|
|
|
if (group.grouped_on) {
|
|
|
|
// Don't fill this if group_by_no_leaf but no group_by
|
2011-05-24 11:57:55 +00:00
|
|
|
$group_column
|
2011-05-24 13:27:29 +00:00
|
|
|
.text((group.value instanceof Array ? group.value[1] : group.value));
|
|
|
|
if (group.openable) {
|
|
|
|
// Make openable if not terminal group & group_by_no_leaf
|
|
|
|
$group_column
|
2011-05-24 14:00:55 +00:00
|
|
|
.prepend('<span class="ui-icon ui-icon-triangle-1-e" style="float: left;">');
|
2011-05-24 13:27:29 +00:00
|
|
|
}
|
2011-05-24 11:57:55 +00:00
|
|
|
}
|
|
|
|
self.indent($group_column, group.level);
|
|
|
|
// count column
|
|
|
|
$('<td>').text(group.length).appendTo($row);
|
|
|
|
|
|
|
|
self.pad($row);
|
2011-05-20 13:00:38 +00:00
|
|
|
_(self.columns).chain()
|
2011-05-17 16:09:48 +00:00
|
|
|
.filter(function (column) {return !column.invisible;})
|
2011-05-20 13:00:38 +00:00
|
|
|
.each(function (column) {
|
2011-05-24 11:57:55 +00:00
|
|
|
if (column.meta) {
|
|
|
|
// do not do anything
|
2011-05-20 13:00:38 +00:00
|
|
|
} else if (column.id in group.aggregates) {
|
|
|
|
var value = group.aggregates[column.id];
|
|
|
|
var format;
|
|
|
|
if (column.type === 'integer') {
|
|
|
|
format = "%.0f";
|
|
|
|
} else if (column.type === 'float') {
|
|
|
|
format = "%.2f";
|
|
|
|
}
|
|
|
|
$('<td>')
|
|
|
|
.text(_.sprintf(format, value))
|
|
|
|
.appendTo($row);
|
|
|
|
} else {
|
|
|
|
$row.append('<td>');
|
|
|
|
}
|
2011-05-10 11:07:23 +00:00
|
|
|
});
|
|
|
|
});
|
2011-05-17 16:09:48 +00:00
|
|
|
return placeholder;
|
|
|
|
},
|
2011-05-19 09:22:22 +00:00
|
|
|
bind_child_events: function (child) {
|
2011-05-18 14:35:17 +00:00
|
|
|
var $this = $(this),
|
|
|
|
self = this;
|
2011-05-19 09:22:22 +00:00
|
|
|
$(child).bind('selected', function (e) {
|
2011-05-18 14:35:17 +00:00
|
|
|
// can have selections spanning multiple links
|
2011-05-25 09:28:13 +00:00
|
|
|
var selection = self.get_selection();
|
|
|
|
$this.trigger(e, [selection.ids, selection.records]);
|
2011-05-19 11:13:09 +00:00
|
|
|
}).bind('action', function (e, name, id, callback) {
|
|
|
|
if (!callback) {
|
|
|
|
callback = function () {
|
|
|
|
var $prev = child.$current.prev();
|
|
|
|
if (!$prev.is('tbody')) {
|
|
|
|
// ungrouped
|
|
|
|
$(self.elements[0]).replaceWith(self.render());
|
|
|
|
} else {
|
|
|
|
// ghetto reload child (and its siblings)
|
|
|
|
$prev.children().last().click();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
$this.trigger(e, [name, id, callback]);
|
|
|
|
}).bind('deleted row_link', function (e) {
|
2011-05-18 13:00:09 +00:00
|
|
|
// additional positional parameters are provided to trigger as an
|
|
|
|
// Array, following the event type or event object, but are
|
|
|
|
// provided to the .bind event handler as *args.
|
|
|
|
// Convert our *args back into an Array in order to trigger them
|
|
|
|
// on the group itself, so it can ultimately be forwarded wherever
|
|
|
|
// it's supposed to go.
|
|
|
|
var args = Array.prototype.slice.call(arguments, 1);
|
2011-05-18 14:35:17 +00:00
|
|
|
$this.trigger.call($this, e, args);
|
2011-05-18 13:00:09 +00:00
|
|
|
});
|
2011-05-18 14:35:17 +00:00
|
|
|
},
|
|
|
|
render_dataset: function (dataset) {
|
|
|
|
var rows = [],
|
|
|
|
list = new openerp.base.ListView.List({
|
|
|
|
options: this.options,
|
|
|
|
columns: this.columns,
|
2011-05-20 14:20:41 +00:00
|
|
|
dataset: dataset,
|
2011-05-18 14:35:17 +00:00
|
|
|
rows: rows
|
2011-05-10 11:07:23 +00:00
|
|
|
});
|
2011-05-19 09:22:22 +00:00
|
|
|
this.bind_child_events(list);
|
2011-05-18 09:06:30 +00:00
|
|
|
|
|
|
|
var d = new $.Deferred();
|
|
|
|
this.view.rpc('/base/listview/fill', {
|
|
|
|
model: dataset.model,
|
|
|
|
id: this.view.view_id,
|
|
|
|
context: dataset.context,
|
|
|
|
domain: dataset.domain,
|
|
|
|
sort: dataset.sort && dataset.sort()
|
|
|
|
}, function (result) {
|
|
|
|
rows.splice(0, rows.length);
|
|
|
|
rows.push.apply(rows, result.records);
|
|
|
|
list.render();
|
|
|
|
d.resolve(list);
|
2011-05-10 11:07:23 +00:00
|
|
|
});
|
2011-05-18 09:06:30 +00:00
|
|
|
return d.promise();
|
2011-05-10 11:07:23 +00:00
|
|
|
},
|
2011-05-25 14:04:56 +00:00
|
|
|
render: function (post_render) {
|
2011-05-17 16:09:48 +00:00
|
|
|
var self = this;
|
2011-05-19 09:22:22 +00:00
|
|
|
var $element = $('<tbody>');
|
|
|
|
this.elements = [$element[0]];
|
2011-05-17 16:09:48 +00:00
|
|
|
this.datagroup.list(function (groups) {
|
2011-05-19 09:22:22 +00:00
|
|
|
$element[0].appendChild(
|
2011-05-17 16:09:48 +00:00
|
|
|
self.render_groups(groups));
|
2011-05-25 14:04:56 +00:00
|
|
|
if (post_render) { post_render(); }
|
2011-05-18 09:06:30 +00:00
|
|
|
}, function (dataset) {
|
|
|
|
self.render_dataset(dataset).then(function (list) {
|
2011-05-19 11:13:09 +00:00
|
|
|
self.children[null] = list;
|
2011-05-19 09:22:22 +00:00
|
|
|
self.elements =
|
|
|
|
[list.$current.replaceAll($element)[0]];
|
2011-05-25 14:04:56 +00:00
|
|
|
if (post_render) { post_render(); }
|
2011-05-18 09:06:30 +00:00
|
|
|
});
|
|
|
|
});
|
2011-05-19 09:22:22 +00:00
|
|
|
return $element;
|
2011-05-18 14:35:17 +00:00
|
|
|
},
|
|
|
|
/**
|
2011-05-25 09:28:13 +00:00
|
|
|
* Returns the ids of all selected records for this group, and the records
|
|
|
|
* themselves
|
2011-05-18 14:35:17 +00:00
|
|
|
*/
|
|
|
|
get_selection: function () {
|
2011-05-25 09:28:13 +00:00
|
|
|
var ids = [], records = [];
|
|
|
|
|
|
|
|
_(this.children)
|
|
|
|
.each(function (child) {
|
|
|
|
var selection = child.get_selection();
|
|
|
|
ids.push.apply(ids, selection.ids);
|
|
|
|
records.push.apply(records, selection.records);
|
|
|
|
});
|
|
|
|
|
|
|
|
return {ids: ids, records: records};
|
2011-05-19 09:22:22 +00:00
|
|
|
},
|
|
|
|
apoptosis: function () {
|
|
|
|
_(this.children).each(function (child) {
|
|
|
|
child.apoptosis();
|
|
|
|
});
|
2011-05-20 13:30:45 +00:00
|
|
|
$(this.elements).remove();
|
2011-05-20 14:20:41 +00:00
|
|
|
return this;
|
2011-05-25 13:04:14 +00:00
|
|
|
},
|
|
|
|
get_records: function () {
|
|
|
|
return _(this.children).chain()
|
|
|
|
.map(function (child) {
|
|
|
|
return child.get_records();
|
|
|
|
}).flatten().value();
|
2011-05-10 11:07:23 +00:00
|
|
|
}
|
|
|
|
});
|
2011-03-30 14:00:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|