diff options
| author | niv-openerp <nicolas.vanhoren@openerp.com> | 2013-08-05 14:39:16 +0200 |
|---|---|---|
| committer | niv-openerp <nicolas.vanhoren@openerp.com> | 2013-08-05 14:39:16 +0200 |
| commit | affb4f0589ad7a3d57dcbf191b9c15debb47530a (patch) | |
| tree | b325f56243725bb4dfff542001c7b8c694798ac8 /addons/web/static/src/js/openerpframework.js | |
| parent | 14fccd0a4eb248145cdd42101407a77541f3c972 (diff) | |
Ported model to the framework
bzr revid: nicolas.vanhoren@openerp.com-20130805123916-s62upxq3jwqjygt0
Diffstat (limited to 'addons/web/static/src/js/openerpframework.js')
| -rw-r--r-- | addons/web/static/src/js/openerpframework.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/addons/web/static/src/js/openerpframework.js b/addons/web/static/src/js/openerpframework.js index c80ee9ffcdb..d3dd5f786a0 100644 --- a/addons/web/static/src/js/openerpframework.js +++ b/addons/web/static/src/js/openerpframework.js @@ -1050,6 +1050,69 @@ openerp.web.Session = openerp.web.Class.extend(openerp.web.PropertiesMixin, { } }); +openerp.web.Model = openerp.web.Class.extend({ + /** + 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 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.name = model_name; + this._context = context || {}; + this._domain = domain || []; + this._session = session; + }, + session: function() { + if (! this._session) + throw new Error("Not implemented"); + return this._session; + }, + /** + * Call a method (over RPC) on the bound OpenERP model. + * + * @param {String} method name of the method to call + * @param {Array} [args] positional arguments + * @param {Object} [kwargs] keyword arguments + * @param {Object} [options] additional options for the rpc() method + * @returns {jQuery.Deferred<>} call result + */ + call: function (method, args, kwargs, options) { + args = args || []; + kwargs = kwargs || {}; + if (!_.isArray(args)) { + // call(method, kwargs) + kwargs = args; + args = []; + } + return this.session().rpc('/web/dataset/call_kw', { + model: this.name, + method: method, + args: args, + kwargs: kwargs + }, options); + }, +}); + openerp.web.get_cookie = function(c_name) { if (document.cookie.length > 0) { var c_start = document.cookie.indexOf(c_name + "="); |
