diff options
| author | Antony Lesuisse <al@openerp.com> | 2011-04-06 23:10:37 +0200 |
|---|---|---|
| committer | Antony Lesuisse <al@openerp.com> | 2011-04-06 23:10:37 +0200 |
| commit | a65ac8c709815cf9d6bb1250dcfaa84ee7eea182 (patch) | |
| tree | 6fac3b82f729f86a2e1aacdd0777ec4c3b1e5cac /addons/base/static/src/js/data.js | |
| parent | ebcc06bb5add67e407fb728d978b3e045237b8c2 (diff) | |
dataset split, crashmanager
bzr revid: al@openerp.com-20110406211037-uzn3n0uravuy900q
Diffstat (limited to 'addons/base/static/src/js/data.js')
| -rw-r--r-- | addons/base/static/src/js/data.js | 126 |
1 files changed, 73 insertions, 53 deletions
diff --git a/addons/base/static/src/js/data.js b/addons/base/static/src/js/data.js index 059b24af232..6c82d79e00f 100644 --- a/addons/base/static/src/js/data.js +++ b/addons/base/static/src/js/data.js @@ -29,72 +29,30 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base. init: function(session, model) { this._super(session); this.model = model; - - this.ids = []; - this.offset + this.context = {}; this.index = 0; this.count = 0; - - this.sort = []; - this.domain = []; - this.context = {}; }, start: function() { }, - previous: function () { this.index -= 1; if (this.index < 0) { - this.index = this.ids.length - 1; + this.index = this.count - 1; } return this; }, next: function () { this.index += 1; - if (this.index >= this.ids.length) { + if (this.index >= this.count) { this.index = 0; } return this; }, - - default_get: function() { - }, - create: function() { - }, /** - * Fetch all the records selected by this DataSet, based on its domain - * and context. - * - * Fires the on_ids event. - * - * TODO: return deferred - * - * @param {Number} [offset=0] The index from which selected records should be returned - * @param {Number} [limit=null] The maximum number of records to return - * @returns itself + * Read records. */ - // Rename into read() ? - fetch: function (fields, offset, limit, callback) { - var self = this; - offset = offset || 0; - this.rpc('/base/dataset/find', { - model: this.model, - fields: fields, - domain: this.domain, - context: this.context, - sort: this.sort, - offset: offset, - limit: limit - }, function (records) { - self.offset = offset; - self.count = records.length; // TODO: get real count - for (var i=0; i < records.length; i++ ) { - self.ids.push(records[i].id); - } - callback(records); - }); - }, - fetch_ids: function (ids, fields, callback) { + read_ids: function (ids, fields, callback) { var self = this; this.rpc('/base/dataset/get', { model: this.model, @@ -102,16 +60,32 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base. fields: fields }, callback); }, - fetch_index: function (fields, callback) { + /** + * Read a slice of the records represented by this DataSet, based on its + * domain and context. + * + * @param {Number} [offset=0] The index from which selected records should be returned + * @param {Number} [limit=null] The maximum number of records to return + */ + read_slice: function (fields, offset, limit, callback) { + }, + /** + * Read the indexed record. + */ + read_index: function (fields, callback) { if (_.isEmpty(this.ids)) { callback([]); } else { fields = fields || false; - this.fetch_ids([this.ids[this.index]], fields, function(records) { + this.read_ids([this.ids[this.index]], fields, function(records) { callback(records[0]); }); } }, + default_get: function() { + }, + create: function() { + }, write: function (id, data, callback) { this.rpc('/base/dataset/save', { model: this.model, @@ -120,6 +94,8 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base. context: this.context }, callback); }, + unlink: function() { + }, call: function (method, ids, args, callback) { ids = ids || []; args = args || []; @@ -130,14 +106,58 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base. args: args }, callback); }, - unlink: function() { - } }); -openerp.base.DataSetSearch = openerp.base.DataSet.extend( /** @lends openerp.base.DataSet# */{ +openerp.base.DataSetStatic = openerp.base.DataSet.extend({ + init: function(session, model, ids) { + this._super(session, model); + // all local records + this.ids = ids; + this.count = ids.length; + }, + read_slice: function (fields, offset, limit, callback) { + this.read_ids(this.ids.slice(offset, offset + limit)); + }, }); -openerp.base.DataSetRelational = openerp.base.DataSet.extend( /** @lends openerp.base.DataSet# */{ +openerp.base.DataSetSearch = openerp.base.DataSet.extend({ + init: function(session, model) { + this._super(session, model); + this.domain = []; + this.sort = []; + this.offset = 0; + // subset records[offset:offset+limit] + // is it necessary ? + this.ids = []; + }, + read_slice: function (fields, offset, limit, callback) { + var self = this; + offset = offset || 0; + // cached search, not sure it's a good idea + if(this.offset <= offset) { + var start = offset - this.offset; + if(this.ids.length - start >= limit) { + // TODO: check if this could work do only read if possible + // return read_ids(ids.slice(start,start+limit),fields,callback) + } + } + this.rpc('/base/dataset/search_read', { + model: this.model, + fields: fields, + domain: this.domain, + context: this.context, + sort: this.sort, + offset: offset, + limit: limit + }, function (records) { + self.offset = offset; + self.count = records.length; // TODO: get real count + for (var i=0; i < records.length; i++ ) { + self.ids.push(records[i].id); + } + callback(records); + }); + }, }); }; |
