summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/data.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/data.js')
-rw-r--r--addons/web/static/src/js/data.js43
1 files changed, 26 insertions, 17 deletions
diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js
index e5d323c8a96..fcf6a65dcf5 100644
--- a/addons/web/static/src/js/data.js
+++ b/addons/web/static/src/js/data.js
@@ -233,6 +233,7 @@ openerp.web.StaticDataGroup = openerp.web.GrouplessDataGroup.extend( /** @lends
});
openerp.web.DataSet = openerp.web.Widget.extend( /** @lends openerp.web.DataSet# */{
+ identifier_prefix: "dataset",
/**
* DateaManagement interface between views and the collection of selected
* OpenERP records (represents the view's state?)
@@ -242,16 +243,12 @@ openerp.web.DataSet = openerp.web.Widget.extend( /** @lends openerp.web.DataSet
*
* @param {String} model the OpenERP model this dataset will manage
*/
- init: function(source_controller, model, context) {
- // we don't want the dataset to be a child of anything!
- this._super(null);
- this.session = source_controller ? source_controller.session : undefined;
+ init: function(parent, model, context) {
+ this._super(parent);
this.model = model;
this.context = context || {};
this.index = null;
},
- start: function() {
- },
previous: function () {
this.index -= 1;
if (this.index < 0) {
@@ -549,13 +546,11 @@ openerp.web.DataSetSearch = openerp.web.DataSet.extend(/** @lends openerp.web.D
sort: this.sort(),
offset: offset,
limit: options.limit || false
- }, function (result) {
+ }).pipe(function (result) {
self.ids = result.ids;
self.offset = offset;
- if (callback) {
- callback(result.records);
- }
- });
+ return result.records;
+ }).then(callback);
},
get_domain: function (other_domain) {
if (other_domain) {
@@ -603,20 +598,27 @@ openerp.web.DataSetSearch = openerp.web.DataSet.extend(/** @lends openerp.web.D
});
openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({
virtual_id_prefix: "one2many_v_id_",
- virtual_id_regex: /one2many_v_id_.*/,
debug_mode: true,
init: function() {
this._super.apply(this, arguments);
this.reset_ids([]);
+ this.last_default_get = {};
+ },
+ default_get: function(fields, callback) {
+ return this._super(fields).then(this.on_default_get).then(callback);
+ },
+ on_default_get: function(res) {
+ this.last_default_get = res;
},
create: function(data, callback, error_callback) {
- var cached = {id:_.uniqueId(this.virtual_id_prefix), values: data};
+ var cached = {id:_.uniqueId(this.virtual_id_prefix), values: data,
+ defaults: this.last_default_get};
this.to_create.push(cached);
this.cache.push(cached);
this.on_change();
- var to_return = $.Deferred().then(callback);
- to_return.resolve({result: cached.id});
- return to_return.promise();
+ var prom = $.Deferred().then(callback);
+ setTimeout(function() {prom.resolve({result: cached.id});}, 0);
+ return prom.promise();
},
write: function (id, data, options, callback) {
var self = this;
@@ -676,7 +678,8 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({
var cached = _.detect(self.cache, function(x) {return x.id === id;});
var created = _.detect(self.to_create, function(x) {return x.id === id;});
if (created) {
- _.each(fields, function(x) {if (cached.values[x] === undefined) cached.values[x] = false;});
+ _.each(fields, function(x) {if (cached.values[x] === undefined)
+ cached.values[x] = created.defaults[x] || false;});
} else {
if (!cached || !_.all(fields, function(x) {return cached.values[x] !== undefined}))
to_get.push(id);
@@ -715,7 +718,13 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({
return completion.promise();
}
});
+openerp.web.BufferedDataSet.virtual_id_regex = /^one2many_v_id_.*$/;
+
openerp.web.ReadOnlyDataSetSearch = openerp.web.DataSetSearch.extend({
+ default_get: function(fields, callback) {
+ return this._super(fields, callback).then(this.on_default_get);
+ },
+ on_default_get: function(result) {},
create: function(data, callback, error_callback) {
this.on_create(data);
var to_return = $.Deferred().then(callback);