From affb4f0589ad7a3d57dcbf191b9c15debb47530a Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 5 Aug 2013 14:39:16 +0200 Subject: Ported model to the framework bzr revid: nicolas.vanhoren@openerp.com-20130805123916-s62upxq3jwqjygt0 --- addons/web/static/src/js/data.js | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 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 b63d44a408d..f333f6a3e4b 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -253,19 +253,11 @@ instance.web.QueryGroup = instance.web.Class.extend({ } }); -instance.web.Model = instance.web.Class.extend({ - /** - * @constructs instance.web.Model - * @extends instance.web.Class - * - * @param {String} model_name name of the OpenERP model this object is bound to - * @param {Object} [context] - * @param {Array} [domain] - */ - init: function (model_name, context, domain) { - this.name = model_name; - this._context = context || {}; - this._domain = domain || []; +instance.web.Model.include({ + session: function() { + if (! this._session) + return instance.session; + return this._super(); }, /** * @deprecated does not allow to specify kwargs, directly use call() instead @@ -294,13 +286,7 @@ instance.web.Model = instance.web.Class.extend({ args = []; } instance.web.pyeval.ensure_evaluated(args, kwargs); - var debug = instance.session.debug ? '/'+this.name+':'+method : ''; - return instance.session.rpc('/web/dataset/call_kw' + debug, { - model: this.name, - method: method, - args: args, - kwargs: kwargs - }, options); + return this._super(method, args, kwargs, options); }, /** * Fetches a Query instance bound to this model, for searching -- cgit v1.2.3 From 226b142ac6d421f7dc5f1bab204f5cde24f1505a Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 5 Aug 2013 15:04:58 +0200 Subject: Simplified a little the Query class by removing a reference to a controller and using call_kw instead bzr revid: nicolas.vanhoren@openerp.com-20130805130458-21w806v9wc456oq4 --- addons/web/static/src/js/data.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 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 f333f6a3e4b..986c58270ca 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -58,19 +58,18 @@ instance.web.Query = instance.web.Class.extend({ }, _execute: function () { var self = this; - return instance.session.rpc('/web/dataset/search_read', { - model: this._model.name, - fields: this._fields || false, + return this._model.call('search_read', { domain: instance.web.pyeval.eval('domains', [this._model.domain(this._filter)]), - context: instance.web.pyeval.eval('contexts', - [this._model.context(this._context)]), + fields: this._fields || false, offset: this._offset, limit: this._limit, - sort: instance.web.serialize_sort(this._order_by) + order: instance.web.serialize_sort(this._order_by), + context: instance.web.pyeval.eval('contexts', + [this._model.context(this._context)]), }).then(function (results) { self._count = results.length; - return results.records; + return results; }, null); }, /** -- cgit v1.2.3 From 76ef945c96c8cb3bbd823965a00232b451ed8a1a Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 5 Aug 2013 15:40:59 +0200 Subject: Corrected some stuff in openerp.web.Model bzr revid: nicolas.vanhoren@openerp.com-20130805134059-3ayw6b0tqqberkaw --- addons/web/static/src/js/data.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 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 986c58270ca..d501b1263b1 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -253,6 +253,36 @@ instance.web.QueryGroup = instance.web.Class.extend({ }); instance.web.Model.include({ + /** + new openerp.web.Model([session,] model_name[, context[, domain]]) + + @constructs instance.web.Model + @extends instance.web.Class + + @param {openerp.web.Session} [session] The session object used to communicate with + the server. + @param {String} model_name name of the OpenERP model this object is bound to + @param {Object} [context] + @param {Array} [domain] + */ + init: function() { + var session, model_name, context, domain; + var args = _.toArray(arguments); + args.reverse(); + session = args.pop(); + if (session && ! (session instanceof openerp.web.Session)) { + model_name = session; + session = null; + } else { + model_name = args.pop(); + } + context = args.length > 0 ? args.pop() : null; + domain = args.length > 0 ? args.pop() : null; + + this._super(session, model_name, context, domain); + this._context = context || {}; + this._domain = domain || []; + }, session: function() { if (! this._session) return instance.session; @@ -303,7 +333,7 @@ instance.web.Model.include({ * @param {String} signal signal to trigger on the workflow */ exec_workflow: function (id, signal) { - return instance.session.rpc('/web/dataset/exec_workflow', { + return this.session().rpc('/web/dataset/exec_workflow', { model: this.name, id: id, signal: signal @@ -340,7 +370,7 @@ instance.web.Model.include({ */ call_button: function (method, args) { instance.web.pyeval.ensure_evaluated(args, {}); - return instance.session.rpc('/web/dataset/call_button', { + return this.session().rpc('/web/dataset/call_button', { model: this.name, method: method, // Should not be necessary anymore. Integrate remote in this? -- cgit v1.2.3