From 5e417f203aa36255eaf7836fb4b4dbb5ec7f813b Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 10 Oct 2011 11:44:38 +0200 Subject: [imp] improved popup for m2o to support usage of buttons while creating a row bzr revid: nicolas.vanhoren@openerp.com-20111010094438-33drycp4l7o1vnzt --- addons/web/static/src/js/data.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'addons/web/static/src/js/data.js') diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index fcf6a65dcf5..dc0e21cf796 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -721,26 +721,42 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({ openerp.web.BufferedDataSet.virtual_id_regex = /^one2many_v_id_.*$/; openerp.web.ReadOnlyDataSetSearch = openerp.web.DataSetSearch.extend({ + init: function() { + this._super.apply(this, arguments); + this.create_function = null; + this.write_function = null; + }, 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); - setTimeout(function () {to_return.resolve({"result": undefined});}, 0); - return to_return.promise(); + if (this.create_function) { + return this.create_function(data, callback, error_callback); + } else { + console.warn("trying to create a record using read only dataset"); + var to_return = $.Deferred().then(callback); + setTimeout(function () {to_return.resolve({"result": undefined});}, 0); + return to_return.promise(); + } }, on_create: function(data) {}, write: function (id, data, options, callback) { this.on_write(id, data); - var to_return = $.Deferred().then(callback); - setTimeout(function () {to_return.resolve({"result": true});}, 0); - return to_return.promise(); + if (this.write_function) { + return this.write_function(id, data, options, callback); + } else { + console.warn("trying to write a record using read only dataset"); + var to_return = $.Deferred().then(callback); + setTimeout(function () {to_return.resolve({"result": true});}, 0); + return to_return.promise(); + } }, on_write: function(id, data) {}, unlink: function(ids, callback, error_callback) { this.on_unlink(ids); + console.warn("trying to unlink a record using read only dataset"); var to_return = $.Deferred().then(callback); setTimeout(function () {to_return.resolve({"result": true});}, 0); return to_return.promise(); -- cgit v1.2.3 From 33b4285d17235ced31a8190fa08c050843ca32c0 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 10 Oct 2011 14:40:44 +0200 Subject: [imp] improved conceptually the preceding fix regarding o2m bzr revid: nicolas.vanhoren@openerp.com-20111010124044-8c02gdeddceq78du --- addons/web/static/src/js/data.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src/js/data.js') diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index dc0e21cf796..0410372f631 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -720,11 +720,19 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({ }); openerp.web.BufferedDataSet.virtual_id_regex = /^one2many_v_id_.*$/; -openerp.web.ReadOnlyDataSetSearch = openerp.web.DataSetSearch.extend({ +openerp.web.ProxyDataSet = openerp.web.DataSetSearch.extend({ init: function() { this._super.apply(this, arguments); this.create_function = null; this.write_function = null; + this.read_function = null; + }, + read_ids: function () { + if (this.read_function) { + return this.read_function.apply(null, arguments); + } else { + this._super.apply(this, arguments); + } }, default_get: function(fields, callback) { return this._super(fields, callback).then(this.on_default_get); @@ -735,7 +743,7 @@ openerp.web.ReadOnlyDataSetSearch = openerp.web.DataSetSearch.extend({ if (this.create_function) { return this.create_function(data, callback, error_callback); } else { - console.warn("trying to create a record using read only dataset"); + console.warn("trying to create a record using default proxy dataset behavior"); var to_return = $.Deferred().then(callback); setTimeout(function () {to_return.resolve({"result": undefined});}, 0); return to_return.promise(); @@ -747,7 +755,7 @@ openerp.web.ReadOnlyDataSetSearch = openerp.web.DataSetSearch.extend({ if (this.write_function) { return this.write_function(id, data, options, callback); } else { - console.warn("trying to write a record using read only dataset"); + console.warn("trying to write a record using default proxy dataset behavior"); var to_return = $.Deferred().then(callback); setTimeout(function () {to_return.resolve({"result": true});}, 0); return to_return.promise(); @@ -756,7 +764,7 @@ openerp.web.ReadOnlyDataSetSearch = openerp.web.DataSetSearch.extend({ on_write: function(id, data) {}, unlink: function(ids, callback, error_callback) { this.on_unlink(ids); - console.warn("trying to unlink a record using read only dataset"); + console.warn("trying to unlink a record using default proxy dataset behavior"); var to_return = $.Deferred().then(callback); setTimeout(function () {to_return.resolve({"result": true});}, 0); return to_return.promise(); -- cgit v1.2.3 From fa9df495ef2f372ed3a57425ca52e8bfbe6ca27f Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 10 Oct 2011 14:45:16 +0200 Subject: [fix] forgot some things bzr revid: nicolas.vanhoren@openerp.com-20111010124516-5vtzop9sbr5z78r0 --- addons/web/static/src/js/data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/data.js') diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index 0410372f631..f72c1b50fcd 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -731,7 +731,7 @@ openerp.web.ProxyDataSet = openerp.web.DataSetSearch.extend({ if (this.read_function) { return this.read_function.apply(null, arguments); } else { - this._super.apply(this, arguments); + return this._super.apply(this, arguments); } }, default_get: function(fields, callback) { -- cgit v1.2.3 From 9857cb60fa71bb09f646b2d48df9ae2c1fc04939 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 10 Oct 2011 16:18:04 +0200 Subject: [imp] removed asynchronous operations in buffered dataset, "l'amour du risque, papapalapapapa" bzr revid: nicolas.vanhoren@openerp.com-20111010141804-zc6t2sr60twz6r4s --- addons/web/static/src/js/data.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src/js/data.js') diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index f72c1b50fcd..459fe2be3af 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -617,7 +617,7 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({ this.cache.push(cached); this.on_change(); var prom = $.Deferred().then(callback); - setTimeout(function() {prom.resolve({result: cached.id});}, 0); + prom.resolve({result: cached.id}); return prom.promise(); }, write: function (id, data, options, callback) { @@ -695,7 +695,7 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({ throw "Record not correctly loaded"; } } - setTimeout(function () {completion.resolve(records);}, 0); + completion.resolve(records); }; if(to_get.length > 0) { var rpc_promise = this._super(to_get, fields, function(records) { -- cgit v1.2.3 From 5cdf82dd0aeeb5ef8ec5b8887adf565a9c2f88fa Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 10 Oct 2011 17:00:12 +0200 Subject: [fix] problem in idea view bzr revid: nicolas.vanhoren@openerp.com-20111010150012-pty14q4z54zdtgvu --- addons/web/static/src/js/data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/data.js') diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index 459fe2be3af..76e430dc34a 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -613,7 +613,7 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({ create: function(data, callback, error_callback) { var cached = {id:_.uniqueId(this.virtual_id_prefix), values: data, defaults: this.last_default_get}; - this.to_create.push(cached); + this.to_create.push(_.extend(_.clone(cached), {values: _.clone(cached.values)})); this.cache.push(cached); this.on_change(); var prom = $.Deferred().then(callback); -- cgit v1.2.3 From b819542c8f574750a3fe3b8c563eee20d38846bf Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 11 Oct 2011 17:35:35 +0200 Subject: [fix] problem with form view, does not prevent multiple creates/saves bzr revid: nicolas.vanhoren@openerp.com-20111011153535-ojo8qqpzlg3ap9fy --- addons/web/static/src/js/data.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'addons/web/static/src/js/data.js') diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index 76e430dc34a..ea0824fb1df 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -639,6 +639,10 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({ self.to_write.push(record); } var cached = _.detect(this.cache, function(x) {return x.id === id;}); + if (!cached) { + cached = {id: id, values: {}}; + this.cache.push(cached); + } $.extend(cached.values, record.values); if (dirty) this.on_change(); -- cgit v1.2.3