From 80657b1c29ec9dea947426fccc1ffc7b20a6d97a Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 24 Oct 2011 11:07:27 +0200 Subject: [IMP] support for jsonp bzr revid: chs@openerp.com-20111024090727-f8w5wv08ugxnrpt8 --- addons/web/static/src/js/core.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 4ed33341ea6..1b6a6302f72 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -346,12 +346,12 @@ openerp.web.Session = openerp.web.CallbackEnabled.extend( /** @lends openerp.web * @param {String} [server] JSON-RPC endpoint hostname * @param {String} [port] JSON-RPC endpoint port */ - init: function(server, port) { + init: function(server) { this._super(); - this.server = (server == undefined) ? location.hostname : server; - this.port = (port == undefined) ? location.port : port; - this.rpc_mode = (server == location.hostname) ? "ajax" : "jsonp"; - this.debug = (window.location.search.indexOf('?debug') !== -1); + var hostname = _('%s//%s').sprintf(location.protocol, location.host); + this.server = (server == undefined) ? hostname : server; + this.rpc_mode = (this.server == hostname) ? "oe-json" : "oe-jsonp"; + this.debug = ($.deparam($.param.querystring()).debug != undefined); this.session_id = false; this.uid = false; this.user_context= {}; @@ -390,13 +390,9 @@ openerp.web.Session = openerp.web.CallbackEnabled.extend( /** @lends openerp.web // Call using the rpc_mode var deferred = $.Deferred(); - this.rpc_ajax(url, { - jsonrpc: "2.0", - method: "call", - params: params, - id: _.uniqueId('browser-client-') - }).then(function () {deferred.resolve.apply(deferred, arguments);}, - function(error) {deferred.reject(error, $.Event());}); + this.rpc_ajax(url, params) + .then(function () {deferred.resolve.apply(deferred, arguments);}, + function(error) {deferred.reject(error, $.Event());}); return deferred.fail(function() { deferred.fail(function(error, event) { if (!event.isDefaultPrevented()) { @@ -422,10 +418,11 @@ openerp.web.Session = openerp.web.CallbackEnabled.extend( /** @lends openerp.web var ajax = _.extend({ type: "POST", url: url, - dataType: 'json', + dataType: this.rpc_mode, contentType: 'application/json', - data: JSON.stringify(payload), - processData: false + data: payload, + processData: false, + openerp: _.extend({}, this), // need a plainObject }, url); var deferred = $.Deferred(); $.ajax(ajax).done(function(response, textStatus, jqXHR) { @@ -440,7 +437,7 @@ openerp.web.Session = openerp.web.CallbackEnabled.extend( /** @lends openerp.web } self.uid = false; self.on_session_invalid(function() { - self.rpc(url, payload.params, + self.rpc(url, payload, function() { deferred.resolve.apply(deferred, arguments); }, -- cgit v1.2.3 From 66a99fd118a5309f801d48c2cbc75ac08cc76805 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 25 Oct 2011 11:50:16 +0200 Subject: [FIX] web: add missing file bzr revid: chs@openerp.com-20111025095016-4ebswa44be2h4cmd --- addons/web/static/src/js/jq_ajax.js | 192 ++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 addons/web/static/src/js/jq_ajax.js (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/jq_ajax.js b/addons/web/static/src/js/jq_ajax.js new file mode 100644 index 00000000000..cf90016ba4c --- /dev/null +++ b/addons/web/static/src/js/jq_ajax.js @@ -0,0 +1,192 @@ + + $.ajaxSetup({ + converters: { + "json oe-jsonp": true, + "json oe-json": true, + } + }); + + + // common preconditions checks + $.ajaxPrefilter("oe-json oe-jsonp", function(options, originalOptions, jqXHR) { + console.log('use', options.dataType); + if (!$.isPlainObject(options.openerp)) { + console.error(options.openerp); + $.error('"openerp" option is required.'); + } + + if (_(options.openerp.server).endsWith('/')) { + options.openerp.server = options.openerp.server.substr(0, options.openerp.server.length-1); + } + + if (!$.isPlainObject(options.data)) { + $.error('data must not be serialized'); + } + options.processData = false; + }); + + + + $.ajaxPrefilter("oe-json", function(options, originalOptions, jqXHR) { + options.data = JSON.stringify({ + jsonrpc: '2.0', + method: 'call', + params: options.data, + id: _.uniqueId('browser-client-') + }); + + return 'json'; + }); + + + $.ajaxPrefilter("oe-jsonp", function(options, originalOptions, jqXHR) { + + var data = null; + if (options.data) { + data = $.param({r:JSON.stringify(options.data)}); + } + + + var max_url_length = options.max_url_length || 1000, + absolute_url, full_url; + + var r_has_protocol = /^https?:\/\//, + r_absolute_internal = /^\/[^\/]/; // starts with / (but not //) + + + if (r_has_protocol.test(options.url)) { + if (!_(options.url).startsWith(options.openerp.server + '/')) { + $.error('can only contact openerp.server'); + } + absolute_url = options.url; + } else if (r_absolute_internal.test(options.url)) { + absolute_url = options.openerp.server + options.url; + } else { // relative url + var parts = document.location.pathname.split('/'); + parts.pop(); + parts.push(options.url); + absolute_url = options.openerp.server + parts.join('/'); + } + + + /// now, made the same url changes that jQuery will do... + var rquery = /\?/, + rts = /([?&])_=[^&]*/; + + full_url = absolute_url; + if (data) { + full_url += (rquery.test(full_url) ? "&" : "?") + data; + } + + // Add anti-cache in url if needed + if (!options.cache) { + var ts = $.now(), + // try replacing _= if it is there + ret = full_url.replace(rts, "$1_=" + ts); + + // if nothing was replaced, add timestamp to the end + full_url = ret + ((ret === full_url) ? (rquery.test(full_url) ? "&" : "?") + "_=" + ts : ""); + } + + console.log('absolute_url', absolute_url); + console.log('full_url', full_url); + + options.url = absolute_url; + + if (full_url.length < max_url_length) { + options.type = "GET"; + options.data = data; + return "jsonp"; // classic jsonp query... + } + }); + + + $.ajaxTransport("oe-jsonp", function(options, originalOptions, jqXHR) { + + console.log('real oe-jsonp', options); + var $iframe = null; + var $form = $('
') + .attr('method', 'POST') + .attr('enctype', "multipart/form-data") + .attr('action', options.openerp.server + "/web/jsonp/post") + .hide() + .appendTo($('body')) + ; + + console.log($form); + + function cleanUp() { + if ($iframe) { + $iframe.unbind("load").attr("src", "javascript:false;").remove(); + } + $form.remove(); + } + + return { + + send: function(headers, completeCallback) { + + var ifid = _.uniqueId('oe_jsonp_iframe_'); + var request_id = _.uniqueId('browser-client-'); + var oe_callback = _.uniqueId('oe_callback_'); + + window[oe_callback] = function(result) { + completeCallback(200, 'success', {json: result}); + }; + + + $iframe = $(_("").sprintf(ifid, ifid)); + + + // the first bind is fired up when the iframe is added to the DOM + $iframe.bind('load', function() { + //console.log('bind1', this); + // the second bind is fired up when the result of the form submission is received + $iframe.unbind('load').bind('load', function() { + //console.log('bind2', this); + + // we cannot access the content of remote iframe. + // but we don't care, we try to get the result in any cases + + $.ajax({ + type: "GET", + url: options.url, + dataType: 'jsonp', + jsonp: false, // do not append callback=? argument on query string + jsonpCallback: oe_callback, + data: { + sid: options.openerp.session_id, + rid: request_id, + }, + }).always(function() { + cleanUp(); + }); + + }); + + + // now that the iframe can receive data, we fill and submit the form + var params = JSON.stringify(options.data); + + $form + .append($('').attr('value', options.openerp.session_id)) + .append($('').attr('value', request_id)) + .append($('').attr('value', params)) + .append($('').attr('value', oe_callback)) + .submit() + ; + + }); + + $form.attr('target', ifid) // set the iframe as target of the form + .after($iframe); // append the iframe to the DOM (will trigger the first load) + + }, + abort: function() { + cleanUp(); + }, + }; + + }); + + -- cgit v1.2.3 From 1b7125432843d0db93628b04e56065e77d7d14ee Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 26 Oct 2011 15:27:14 +0200 Subject: [FIX] jsonp: force crossdomain request bzr revid: chs@openerp.com-20111026132714-6uko5u7f35y2yaj4 --- addons/web/static/src/js/jq_ajax.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/jq_ajax.js b/addons/web/static/src/js/jq_ajax.js index cf90016ba4c..8d347c398d7 100644 --- a/addons/web/static/src/js/jq_ajax.js +++ b/addons/web/static/src/js/jq_ajax.js @@ -41,6 +41,8 @@ $.ajaxPrefilter("oe-jsonp", function(options, originalOptions, jqXHR) { + options.crossDomain = true; + var data = null; if (options.data) { data = $.param({r:JSON.stringify(options.data)}); -- cgit v1.2.3 From 10bbbad52f76a7fc40eaf6de94bf9b3d14f8ff02 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 9 Nov 2011 09:14:59 +0100 Subject: [FIX] base.xml: use full absolute url for all images bzr revid: chs@openerp.com-20111109081459-b031iutztocpxo9w --- addons/web/static/src/xml/base.xml | 72 +++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 1fc98ba34ee..01da70335b6 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -264,7 +264,7 @@
- +
@@ -304,7 +304,7 @@ @@ -813,7 +813,7 @@ @@ -826,12 +826,12 @@ t-attf-class="field_#{widget.type}" t-attf-style="width: #{widget.field.translate ? '99' : '100'}%" > - +
-
- + Full featured
@@ -313,7 +313,7 @@
- + Open Source
@@ -322,7 +322,7 @@
- + User Friendly
@@ -350,13 +350,13 @@
  • - +
  • - +
  • - +
@@ -694,7 +694,7 @@ @@ -779,7 +779,7 @@ t-attf-class="field_#{widget.type}" t-attf-style="width: #{widget.field.translate ? '99' : '100'}%" /> - +
- @@ -938,14 +938,14 @@
@@ -973,7 +973,7 @@ @@ -982,13 +982,13 @@ @@ -996,7 +996,7 @@ - + Uploading ... @@ -1007,7 +1007,7 @@ @@ -1057,7 +1057,7 @@ t-att-title="attrs.help" t-att-class="classes.join(' ')" t-att-autofocus="attrs.default_focus === '1' ? 'autofocus' : undefined"> - +
@@ -1204,7 +1204,7 @@ - +

@@ -1292,7 +1292,7 @@

+ t-att-src='widget.session.server + "/web/static/src/img/collapse.gif"' width="16" height="16" border="0"/> @@ -1305,22 +1305,22 @@
+ id="side-add" t-att-src='widget.session.server + "/web/static/src/img/icons/gtk-add.png"' style="cursor: pointer;"/> - + + id="side-edit" t-att-src='widget.session.server + "/web/static/src/img/icons/gtk-edit.png"' style="cursor: pointer;"/> + id="side-up" t-att-src='widget.session.server + "/web/static/src/img/icons/gtk-go-up.png"' style="cursor: pointer;"/> + id="side-down" t-att-src='widget.session.server + "/web/static/src/img/icons/gtk-go-down.png"' style="cursor: pointer;"/>
@@ -1402,7 +1402,7 @@ - + @@ -1518,7 +1518,7 @@ - + -- cgit v1.2.3 From bccc64ac7c2a6671a15f74d13465c27b8f13e9d8 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 9 Nov 2011 09:16:26 +0100 Subject: [FIX] use absolute url when getting css/js/qweb files + use a static proxy for getting qweb files bzr revid: chs@openerp.com-20111109081626-l868h7w8glinbxdl --- addons/web/static/src/js/core.js | 49 +++++++++++++++++++++++++++++++++---- addons/web/static/src/js/jq_ajax.js | 21 ++++------------ 2 files changed, 49 insertions(+), 21 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 951e6e2b01f..fac18f18734 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -349,7 +349,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. init: function(server) { this._super(); var hostname = _('%s//%s').sprintf(location.protocol, location.host); - this.server = (server == undefined) ? hostname : server; + this.server = _.rtrim((server == undefined) ? hostname : server, '/'); this.rpc_mode = (this.server == hostname) ? "oe-json" : "oe-jsonp"; this.debug = ($.deparam($.param.querystring()).debug != undefined); this.session_id = false; @@ -370,6 +370,29 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. start: function() { this.session_restore(); }, + + get_absolute_url: function(path) { + var r_has_protocol = /^https?:\/\//, + r_absolute_internal = /^\/[^\/]/; // starts with / (but not //) + + + if (r_has_protocol.test(path)) { + if (!_(path).startsWith(this.server + '/')) { + $.error('can only contact openerp.server'); + } + absolute_url = path; + } else if (r_absolute_internal.test(path)) { + absolute_url = this.server + path; + } else { // relative url + // XXX is it correct to mix document.location and this.server ?? + var parts = document.location.pathname.split('/'); + parts.pop(); + parts.push(path); + absolute_url = this.server + parts.join('/'); + } + return absolute_url + }, + /** * Executes an RPC call, registering the provided callbacks. * @@ -574,11 +597,11 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. self.user_context.lang.replace("_", "-") + ".js" ]; + self.rpc('/web/webclient/qweblist', {"mods": modules}, self.do_load_qweb); self.rpc('/web/webclient/csslist', {"mods": modules}, self.do_load_css); self.rpc('/web/webclient/jslist', {"mods": modules}, function(files) { self.do_load_js(file_list.concat(files)); }); - self.rpc('/web/webclient/qweblist', {"mods": modules}, self.do_load_qweb); openerp._modules_loaded = true; }); }); @@ -587,7 +610,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. var self = this; _.each(files, function (file) { $('head').append($('', { - 'href': file, + 'href': self.get_absolute_url(file), 'rel': 'stylesheet', 'type': 'text/css' })); @@ -599,7 +622,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. var file = files.shift(); var tag = document.createElement('script'); tag.type = 'text/javascript'; - tag.src = file; + tag.src = self.get_absolute_url(file); tag.onload = tag.onreadystatechange = function() { if ( (tag.readyState && tag.readyState != "loaded" && tag.readyState != "complete") || tag.onload_done ) return; @@ -615,7 +638,23 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. do_load_qweb: function(files) { var self = this; _.each(files, function(file) { - openerp.web.qweb.add_template(file); + self.rpc({ + //url: self.get_absolute_url(file), + url: '/web/jsonp/static_proxy', + async: false, + //dataType: 'text', + + }, + { + path: file, + }, + function(xml) { + //function(result) { + // console.log('do_load_qweb', result); + // var xml = result.result; + //}).then(function(xml) { + openerp.web.qweb.add_template(_(xml).trim()); + }); }); }, on_modules_loaded: function() { diff --git a/addons/web/static/src/js/jq_ajax.js b/addons/web/static/src/js/jq_ajax.js index 8d347c398d7..19c3bb31295 100644 --- a/addons/web/static/src/js/jq_ajax.js +++ b/addons/web/static/src/js/jq_ajax.js @@ -9,16 +9,11 @@ // common preconditions checks $.ajaxPrefilter("oe-json oe-jsonp", function(options, originalOptions, jqXHR) { - console.log('use', options.dataType); if (!$.isPlainObject(options.openerp)) { console.error(options.openerp); $.error('"openerp" option is required.'); } - if (_(options.openerp.server).endsWith('/')) { - options.openerp.server = options.openerp.server.substr(0, options.openerp.server.length-1); - } - if (!$.isPlainObject(options.data)) { $.error('data must not be serialized'); } @@ -49,9 +44,10 @@ } + var max_url_length = options.max_url_length || 1000, absolute_url, full_url; - + /* var r_has_protocol = /^https?:\/\//, r_absolute_internal = /^\/[^\/]/; // starts with / (but not //) @@ -69,7 +65,9 @@ parts.push(options.url); absolute_url = options.openerp.server + parts.join('/'); } - + // */ + + var absolute_url = options.openerp.get_absolute_url(options.url); /// now, made the same url changes that jQuery will do... var rquery = /\?/, @@ -89,9 +87,6 @@ // if nothing was replaced, add timestamp to the end full_url = ret + ((ret === full_url) ? (rquery.test(full_url) ? "&" : "?") + "_=" + ts : ""); } - - console.log('absolute_url', absolute_url); - console.log('full_url', full_url); options.url = absolute_url; @@ -105,7 +100,6 @@ $.ajaxTransport("oe-jsonp", function(options, originalOptions, jqXHR) { - console.log('real oe-jsonp', options); var $iframe = null; var $form = $('
') .attr('method', 'POST') @@ -115,8 +109,6 @@ .appendTo($('body')) ; - console.log($form); - function cleanUp() { if ($iframe) { $iframe.unbind("load").attr("src", "javascript:false;").remove(); @@ -142,11 +134,8 @@ // the first bind is fired up when the iframe is added to the DOM $iframe.bind('load', function() { - //console.log('bind1', this); // the second bind is fired up when the result of the form submission is received $iframe.unbind('load').bind('load', function() { - //console.log('bind2', this); - // we cannot access the content of remote iframe. // but we don't care, we try to get the result in any cases -- cgit v1.2.3 From fafa6b2d910735bd7d193a2471ec4797552456c2 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 15 Nov 2011 17:10:16 +0100 Subject: [FIX] jq_ajax: addapt code to new version of underscore.string [IMP] jq_ajax: only show transport iframe in debug mode bzr revid: chs@openerp.com-20111115161016-q1p2ne4zp1geui92 --- addons/web/static/src/js/jq_ajax.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/jq_ajax.js b/addons/web/static/src/js/jq_ajax.js index 19c3bb31295..611ab1e1e22 100644 --- a/addons/web/static/src/js/jq_ajax.js +++ b/addons/web/static/src/js/jq_ajax.js @@ -129,7 +129,8 @@ }; - $iframe = $(_("").sprintf(ifid, ifid)); + var display = options.openerp.debug ? 'block' : 'none'; + $iframe = $(_.str.sprintf("", ifid, ifid, display)); // the first bind is fired up when the iframe is added to the DOM -- cgit v1.2.3 From 7e9d606238ed1fa00d2bf8b852987889566c49e0 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 15 Nov 2011 18:04:08 +0100 Subject: [IMP] Connection: new method to bind to a server. Must be called before login [IMP] loading of qweb/css/js files are now sequencial bzr revid: chs@openerp.com-20111115170408-u1i805s1854igyja --- addons/web/static/src/js/chrome.js | 36 ++++++---- addons/web/static/src/js/core.js | 134 +++++++++++++++++++++++-------------- 2 files changed, 107 insertions(+), 63 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 2b838ee3743..31ea05b572b 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -977,12 +977,6 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie this._super(null, element_id); openerp.webclient = this; - var params = {}; - if(jQuery.param != undefined && jQuery.deparam(jQuery.param.querystring()).kitten != undefined) { - this.$element.addClass("kitten-mode-activated"); - } - this.$element.html(QWeb.render("Interface", params)); - this.notification = new openerp.web.Notification(this); this.loading = new openerp.web.Loading(this); this.crashmanager = new openerp.web.CrashManager(); @@ -997,8 +991,6 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie this.session.on_session_invalid.add_last(this.header.do_update); this.session.on_session_valid.add_last(this.on_logged); - this.menu = new openerp.web.Menu(this, "oe_menu", "oe_secondary_menu"); - this.menu.on_action.add(this.on_menu_action); this.url_internal_hashchange = false; this.url_external_hashchange = false; @@ -1007,12 +999,28 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie }, start: function() { this._super.apply(this, arguments); - this.notification.prependTo(this.$element); - this.loading.appendTo($('#oe_loading')); - this.header.appendTo($("#oe_header")); - this.session.start(); - this.login.appendTo($('#oe_login')); - this.menu.start(); + var self = this; + openerp.connection.bind(function() { + + var params = {}; + if(jQuery.param != undefined && jQuery.deparam(jQuery.param.querystring()).kitten != undefined) { + self.$element.addClass("kitten-mode-activated"); + } + self.$element.html(QWeb.render("Interface", params)); + openerp.connection.session_restore(); + + + // TODO nivification of menu Widget !!! + self.menu = new openerp.web.Menu(self, "oe_menu", "oe_secondary_menu"); + self.menu.on_action.add(self.on_menu_action); + + + self.notification.prependTo(self.$element); + self.loading.appendTo($('#oe_loading')); + self.header.appendTo($("#oe_header")); + self.login.appendTo($('#oe_login')); + self.menu.start(); + }); }, do_reload: function() { this.session.session_restore(); diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 7cd81d2a7c1..590438c09dc 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -346,29 +346,43 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. * @param {String} [server] JSON-RPC endpoint hostname * @param {String} [port] JSON-RPC endpoint port */ - init: function(server) { + init: function() { + + // FIXME need to be a real singleton. + // create more than one Connection on the same instance will not works + this._super(); - var hostname = _('%s//%s').sprintf(location.protocol, location.host); - this.server = _.rtrim((server == undefined) ? hostname : server, '/'); - this.rpc_mode = (this.server == hostname) ? "oe-json" : "oe-jsonp"; + this.server = null; this.debug = ($.deparam($.param.querystring()).debug != undefined); + // TODO: session should have an optional name indicating that they'll + // be saved to (and revived from) cookies + this.name = 'session'; + }, + + bind: function(server, continuation) { + + if(_.isFunction(server)) { + continuation = server; + server = null; + } + + if (this.server) { + throw new Error("Connection already bind to " + this.server); + } + var hostname = _.str.sprintf('%s//%s', location.protocol, location.host); + this.server = _.str.rtrim((!server) ? hostname : server, '/'); + this.rpc_mode = (this.server == hostname) ? "oe-json" : "oe-jsonp"; this.session_id = false; this.uid = false; this.user_context= {}; this.db = false; + this.module_loading = $.Deferred(); this.module_list = []; this.module_loaded = {"web": true}; this.context = {}; this.shortcuts = []; this.active_id = null; - // TODO: session should have an optional name indicating that they'll - // be saved to (and revived from) cookies - this.name = 'session'; - this.do_load_qweb(['/web/webclient/qweb']); - }, - - start: function() { - this.session_restore(); + this.do_load_qweb(['/web/webclient/qweb'], continuation); }, get_absolute_url: function(path) { @@ -377,7 +391,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. if (r_has_protocol.test(path)) { - if (!_(path).startsWith(this.server + '/')) { + if (!_.str.startsWith(path, this.server + '/')) { $.error('can only contact openerp.server'); } absolute_url = path; @@ -426,6 +440,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. }); }).then(success_callback, error_callback).promise(); }, + /** * Raw JSON-RPC call * @@ -491,9 +506,8 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. /** * The session is validated either by login or by restoration of a previous session */ - on_session_valid: function() { - if(!openerp._modules_loaded) - this.load_modules(); + on_session_valid: function(continuation) { + this.load_modules(continuation); }, on_session_invalid: function(contination) { }, @@ -509,15 +523,17 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. self.user_context = result.context; self.db = result.db; self.session_save(); - self.on_session_valid(); + + self.on_session_valid(success_callback); return true; - }).then(success_callback); + //}).done(success_callback); + }); }, login: function() { this.session_login.apply(this, arguments); }, /** * Reloads uid and session_id from local storage, if they exist */ - session_restore: function () { + session_restore: function (continuation) { var self = this; this.session_id = this.get_cookie('session_id'); return this.rpc("/web/session/get_session_info", {}).then(function(result) { @@ -525,11 +541,11 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. self.user_context = result.context; self.db = result.db; if (self.uid) - self.on_session_valid(); + self.on_session_valid(continuation); else - self.on_session_invalid(); + self.on_session_invalid(continuation); }, function() { - self.on_session_invalid(); + self.on_session_invalid(continuation); }); }, /** @@ -583,9 +599,17 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. }, /** * Load additional web addons of that instance and init them + * FIXME do all actions in sync... */ - load_modules: function() { + load_modules: function(continuation) { var self = this; + + this.module_loading.done(continuation); + //if (this.module_loading.state() !== "pending") { + if (this.module_loading.isResolved() || this.module_loading.isRejected()) { + return; + } + this.rpc('/web/session/modules', {}, function(result) { self.module_list = result; var lang = self.user_context.lang; @@ -597,16 +621,36 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. self.user_context.lang.replace("_", "-") + ".js" ]; - self.rpc('/web/webclient/qweblist', {"mods": modules}, self.do_load_qweb); - self.rpc('/web/webclient/csslist', {"mods": modules}, self.do_load_css); - self.rpc('/web/webclient/jslist', {"mods": modules}, function(files) { + /* + self.rpc('/web/webclient/qweblist', {mods: modules}, self.do_load_qweb); + self.rpc('/web/webclient/csslist', {mods: modules}, self.do_load_css); + self.rpc('/web/webclient/jslist', {mods: modules}, function(files) { self.do_load_js(file_list.concat(files)); }); openerp._modules_loaded = true; + // */ + + self.rpc('/web/webclient/qweblist', {mods: modules}, function(files) { + self.do_load_qweb(files, function() { + // once qweb files are loaded... + self.rpc('/web/webclient/csslist', {mods: modules}, function(files) { + self.do_load_css(files, function() { + // once css files are loaded + self.rpc('/web/webclient/jslist', {mods: modules}, function(files) { + self.do_load_js(file_list.concat(files), function() { + self.on_modules_loaded(); + self.module_loading.resolve(); + }); + }); + }); + }); + }); + }); + }); }); }, - do_load_css: function (files) { + do_load_css: function (files, callback) { var self = this; _.each(files, function (file) { $('head').append($('', { @@ -615,8 +659,9 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. 'type': 'text/css' })); }); + if (callback) { callback(); } }, - do_load_js: function(files) { + do_load_js: function(files, callback) { var self = this; if(files.length != 0) { var file = files.shift(); @@ -627,35 +672,26 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. if ( (tag.readyState && tag.readyState != "loaded" && tag.readyState != "complete") || tag.onload_done ) return; tag.onload_done = true; - self.do_load_js(files); + self.do_load_js(files, callback); }; var head = document.head || document.getElementsByTagName('head')[0]; head.appendChild(tag); } else { - this.on_modules_loaded(); + if (callback) { callback(); } } }, - do_load_qweb: function(files) { + do_load_qweb: function(files, callback) { var self = this; - _.each(files, function(file) { - self.rpc({ - //url: self.get_absolute_url(file), - url: '/web/jsonp/static_proxy', - async: false, - //dataType: 'text', - - }, - { - path: file, - }, - function(xml) { - //function(result) { - // console.log('do_load_qweb', result); - // var xml = result.result; - //}).then(function(xml) { - openerp.web.qweb.add_template(_(xml).trim()); + + if (files.length != 0) { + var file = files.shift(); + self.rpc('/web/jsonp/static_proxy', {path: file}, function(xml) { + openerp.web.qweb.add_template(_.str.trim(xml)); + self.do_load_qweb(files, callback); }); - }); + } else { + if (callback) { callback(); } + } }, on_modules_loaded: function() { for(var j=0; j Date: Thu, 17 Nov 2011 13:48:19 +0100 Subject: [FIX] typo bzr revid: chs@openerp.com-20111117124819-qmxoit9i2ryo8szo --- addons/web/static/src/js/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 590438c09dc..8d7bed56b5b 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -367,7 +367,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. } if (this.server) { - throw new Error("Connection already bind to " + this.server); + throw new Error("Connection already bound to " + this.server); } var hostname = _.str.sprintf('%s//%s', location.protocol, location.host); this.server = _.str.rtrim((!server) ? hostname : server, '/'); -- cgit v1.2.3 From 4e85f0762cc69af8efdb88ec857329ac955afe0b Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Thu, 17 Nov 2011 13:49:26 +0100 Subject: [IMP] Connection: add utility method that bind() then login() bzr revid: chs@openerp.com-20111117124926-y3z3osoq76va0kjy --- addons/web/static/src/js/core.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 8d7bed56b5b..113b83f57dc 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -385,6 +385,13 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. this.do_load_qweb(['/web/webclient/qweb'], continuation); }, + connect: function(server, db, login, password, continuation) { + var self = this; + this.bind(server, function() { + self.login(db, login, password, continuation); + }); + }, + get_absolute_url: function(path) { var r_has_protocol = /^https?:\/\//, r_absolute_internal = /^\/[^\/]/; // starts with / (but not //) -- cgit v1.2.3 From c5bcea713d360a71ca1d94d385d6e5110d1ff142 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 22 Nov 2011 13:20:16 +0100 Subject: [FIX] set correct session name bzr revid: chs@openerp.com-20111122122016-ykckmih2q7dfb4yb --- addons/web/static/src/js/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index e3f85a92503..0c3eaff56ed 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -360,7 +360,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. this.debug = ($.deparam($.param.querystring()).debug != undefined); // TODO: session should have an optional name indicating that they'll // be saved to (and revived from) cookies - this.name = 'session'; + this.name = openerp._session_id; }, bind: function(server, continuation) { -- cgit v1.2.3 From f7893968428df6cb518db4615e96b1d0e627d294 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 22 Nov 2011 13:20:46 +0100 Subject: [IMP] correct var name bzr revid: chs@openerp.com-20111122122046-kl6f4o4ej1mdcd1o --- addons/web/static/src/js/core.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 0c3eaff56ed..19607bc11a2 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -398,7 +398,8 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. }, get_absolute_url: function(path) { - var r_has_protocol = /^https?:\/\//, + var absolute_url, + r_has_protocol = /^https?:\/\//, r_absolute_internal = /^\/[^\/]/; // starts with / (but not //) @@ -416,7 +417,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. parts.push(path); absolute_url = this.server + parts.join('/'); } - return absolute_url + return absolute_url; }, /** @@ -488,7 +489,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. return; } self.uid = false; - self.on_session_invalid(function() { + self.on_session_invalid(function() { // retry self.rpc(url, payload, function() { deferred.resolve.apply(deferred, arguments); @@ -521,7 +522,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. on_session_valid: function(continuation) { this.load_modules(continuation); }, - on_session_invalid: function(contination) { + on_session_invalid: function(continuation) { }, session_is_valid: function() { return this.uid; -- cgit v1.2.3 From 64d223d4271a431457992a399e5cb65795ac4c11 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 22 Nov 2011 13:22:50 +0100 Subject: [ADD] EmbedClient widget for ease the use of embed code bzr revid: chs@openerp.com-20111122122250-v0cys6fdv42222l0 --- addons/web/static/src/js/boot.js | 2 +- addons/web/static/src/js/embed.js | 49 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 addons/web/static/src/js/embed.js (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/boot.js b/addons/web/static/src/js/boot.js index 58dcd922ea9..7440ae42dbc 100644 --- a/addons/web/static/src/js/boot.js +++ b/addons/web/static/src/js/boot.js @@ -59,7 +59,7 @@ openerp.web = function(instance) { openerp.web.formats(instance); openerp.web.chrome(instance); openerp.web.data(instance); - var files = ["views","search","list","form","list_editable","web_mobile","view_tree","data_export","data_import","view_editor"]; + var files = ["views","search","list","form","list_editable","web_mobile","view_tree","data_export","data_import","view_editor", 'embed']; for(var i=0; i Date: Wed, 23 Nov 2011 10:20:55 +0100 Subject: [FIX] generate absolute urls for images bzr revid: chs@openerp.com-20111123092055-iqwm3uy1sxw4iq5o --- addons/web/static/src/js/formats.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/formats.js b/addons/web/static/src/js/formats.js index 3151b34636b..18b679bed3c 100644 --- a/addons/web/static/src/js/formats.js +++ b/addons/web/static/src/js/formats.js @@ -253,7 +253,7 @@ openerp.web.format_cell = function (row_data, column, value_if_empty, process_mo if (column.tag === 'button') { return [ '' ].join('') -- cgit v1.2.3 From 12296a03e496cde652a4c75f90153e5f7ff3c8f9 Mon Sep 17 00:00:00 2001 From: vishmita Date: Tue, 6 Dec 2011 16:11:28 +0530 Subject: [FIX]Readonly char fields should be grey. lp bug: https://launchpad.net/bugs/899076 fixed bzr revid: vja@vja-desktop-20111206104128-1xrurdtr6qyoybq4 --- addons/web/static/src/css/base.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 00e8e1f5e55..c4beab3badc 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -1151,7 +1151,9 @@ label.error { .openerp .oe_forms select{ padding-top: 2px; } - +.openerp .oe_forms input[disabled] { + background: #EBEBE4; +} .openerp .oe_forms textarea { resize:vertical; } -- cgit v1.2.3 From 06d0b51915760cd38ebe0660f1dca484aa3fc558 Mon Sep 17 00:00:00 2001 From: vishmita Date: Thu, 8 Dec 2011 12:18:18 +0530 Subject: [FIX]Improve code. lp bug: https://launchpad.net/bugs/899076 fixed bzr revid: vja@vja-desktop-20111208064818-08kpnp7b1y3ybwjp --- addons/web/static/src/css/base.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index c4beab3badc..de11e2d182a 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -1151,8 +1151,8 @@ label.error { .openerp .oe_forms select{ padding-top: 2px; } -.openerp .oe_forms input[disabled] { - background: #EBEBE4; +.openerp .oe_forms input[disabled],.openerp .oe_forms select[disabled], .openerp .oe_forms textarea[disabled]{ + background: #EBEBE4 !important; } .openerp .oe_forms textarea { resize:vertical; -- cgit v1.2.3 From f09915b5e4776db26eda5a014c82c78581c2fe5e Mon Sep 17 00:00:00 2001 From: vishmita Date: Mon, 12 Dec 2011 16:52:19 +0530 Subject: [FIX]fixed change color of readonly fields. bzr revid: vja@vja-desktop-20111212112219-1bx7xocogk6ji236 --- addons/web/static/src/css/base.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index de11e2d182a..f0bdc872176 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -1152,7 +1152,7 @@ label.error { padding-top: 2px; } .openerp .oe_forms input[disabled],.openerp .oe_forms select[disabled], .openerp .oe_forms textarea[disabled]{ - background: #EBEBE4 !important; + background: #E0E0E0; } .openerp .oe_forms textarea { resize:vertical; -- cgit v1.2.3 From 7099b809e70224b84ac7842ed30897e887298408 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 13 Dec 2011 17:11:44 +0100 Subject: [FIX] o2m uses weird class sets bzr revid: xmo@openerp.com-20111213161144-lwwr261r3ghs8wk4 --- addons/web/static/src/css/base.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 00e8e1f5e55..0fa3a44a4cd 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -1108,7 +1108,8 @@ label.error { white-space: normal; } -.openerp .oe_form_field_one2many .oe-actions h3.oe_view_title { +.openerp .oe_form_field_one2many .oe-actions h3.oe_view_title, +.openerp .oe_form_field_one2many_list .oe-actions h3.oe_view_title{ display: inline; margin: 0 0.5em 0 0; } -- cgit v1.2.3 From 2a492cf3add2ef41dcd911feb4cb2c1af9049491 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 13 Dec 2011 17:27:30 +0100 Subject: [FIX] chs stupidity bzr revid: chs@openerp.com-20111213162730-w1p543ctjzpuf7f7 --- addons/web/static/src/xml/base.xml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index f42d173a5bc..0a245fe0f38 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -928,12 +928,7 @@ t-att-id="widget.element_id" t-attf-class="field_#{widget.type}" style="width: 100%" -<<<<<<< TREE - > - -======= - > ->>>>>>> MERGE-SOURCE + >
@@ -941,12 +936,7 @@ - >>>>>> MERGE-SOURCE + />
-- cgit v1.2.3 From ddd1ea5d5d8b1ce383bf2340a23bd47f25cf8f4b Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 13 Dec 2011 17:34:46 +0100 Subject: [IMP] allow modification of options of action of EmbedClient bzr revid: chs@openerp.com-20111213163446-h6sy1yti92mcgg1f --- addons/web/static/src/js/embed.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/embed.js b/addons/web/static/src/js/embed.js index ce6ad8b60f9..1c261060da8 100644 --- a/addons/web/static/src/js/embed.js +++ b/addons/web/static/src/js/embed.js @@ -20,9 +20,10 @@ openerp.web.embed = function(session) { session.web.EmbedClient = session.web.Widget.extend({ template: 'EmptyComponent', - init: function(action_id) { + init: function(action_id, options) { this._super(); this.action_id = action_id; + this.options = options || {}; this.am = new session.web.ActionManager(); }, @@ -39,7 +40,7 @@ openerp.web.embed = function(session) { action_buttons : false, sidebar : false //pager : false - }, action.flags || {}); + }, self.options, action.flags || {}); self.am.do_action(action); }); -- cgit v1.2.3 From 228aed18bb62b35c26f3deee9a1041f472463e50 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 14 Dec 2011 10:51:23 +0100 Subject: [IMP] Remove bottom pager from o2m bzr revid: fme@openerp.com-20111214095123-1dwn1yld44pndzpz --- addons/web/static/src/xml/base.xml | 3 +++ 1 file changed, 3 insertions(+) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 1894d351e40..a2cc9e1725f 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -619,6 +619,9 @@ this.removeAttr('t-if'); + + + this.removeAttr('t-if'); var $title = $(document.createElement('h3')).addClass('oe_view_title'); -- cgit v1.2.3 From 139f4f85a0fd34b945584ab603f589a46196bb59 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 14 Dec 2011 11:13:44 +0100 Subject: [IMP] Merge Advanced Filter button in select box and float it right bzr revid: fme@openerp.com-20111214101344-7jcltxvjd34no3q6 --- addons/web/static/src/css/base.css | 6 ++---- addons/web/static/src/js/search.js | 5 ++++- addons/web/static/src/xml/base.xml | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 0fa3a44a4cd..4badc4d4690 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -717,11 +717,9 @@ label.error { .openerp .oe_search-view-buttons { padding: 10px 0 10px 0; } -.openerp .oe_search-view-custom-filter-btn span { - background: url(/web/static/src/img/icons/gtk-add.png) repeat-y; - padding-left: 18px; +.openerp .oe_search-view-filters-management { + float: right; } - .openerp .searchview_extended_add_proposition span { font-size: 0.9em; background: url(/web/static/src/img/icons/gtk-add.png) repeat-y; diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index d1e4b161b39..9b485b457cd 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -155,6 +155,7 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search var ext = new openerp.web.search.ExtendedSearch(this, this.model); lines.push([ext]); this.inputs.push(ext); + this.extended_search = ext; var render = QWeb.render("SearchView", { 'view': data.fields_view['arch'], @@ -163,7 +164,6 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search }); this.$element.html(render); - this.$element.find(".oe_search-view-custom-filter-btn").click(ext.on_activate); var f = this.$element.find('form'); this.$element.find('form') @@ -199,6 +199,9 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search var select = this.$element.find(".oe_search-view-filters-management"); var val = select.val(); switch(val) { + case 'advanced_filter': + this.extended_search.on_activate(); + break; case 'add_to_dashboard': this.on_add_to_dashboard(); break; diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index a2cc9e1725f..09472e38657 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1151,7 +1151,6 @@
-
@@ -1165,6 +1164,7 @@
+ -- cgit v1.2.3 From b1f0142a21fac3bb2df3adacb48eb13633883c81 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 14 Dec 2011 11:43:01 +0100 Subject: [IMP] Hide secondary menu on home page client action bzr revid: fme@openerp.com-20111214104301-v1nxqqglhubpkdqc --- addons/web/static/src/js/chrome.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 4910d794876..8c8c3b5f7d6 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -916,6 +916,8 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ if (!(this.folded && manual)) { this.do_show_secondary($sub_menu, $main_menu); + } else { + this.do_show_secondary(); } if ($main_menu != $clicked_menu) { @@ -941,8 +943,15 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ } return false; }, + do_hide_secondary: function() { + this.$secondary_menu.hide(); + }, do_show_secondary: function($sub_menu, $main_menu) { var self = this; + this.$secondary_menu.show(); + if (!arguments.length) { + return; + } if (this.folded) { var css = $main_menu.position(), fold_width = this.$secondary_menu.width() + 2, -- cgit v1.2.3 From 6da5e9245e5f680866e4bf64c92e653127dfbb55 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 14 Dec 2011 13:56:58 +0100 Subject: [IMP] Rename EmbedClient to EmbeddedClient and move it to chrome.js. [IMP] move the currentScript function to root namespace bzr revid: chs@openerp.com-20111214125658-huw4955d7zo2y37g --- addons/web/static/src/js/boot.js | 2 +- addons/web/static/src/js/chrome.js | 42 ++++++++++++++++++++++++++++++++ addons/web/static/src/js/embed.js | 50 -------------------------------------- 3 files changed, 43 insertions(+), 51 deletions(-) delete mode 100644 addons/web/static/src/js/embed.js (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/boot.js b/addons/web/static/src/js/boot.js index 14f50adb473..c2aea24276b 100644 --- a/addons/web/static/src/js/boot.js +++ b/addons/web/static/src/js/boot.js @@ -59,7 +59,7 @@ openerp.web = function(instance) { openerp.web.formats(instance); openerp.web.chrome(instance); openerp.web.data(instance); - var files = ["views","search","list","form", "page","list_editable","web_mobile","view_tree","data_export","data_import","view_editor","embed"]; + var files = ["views","search","list","form", "page","list_editable","web_mobile","view_tree","data_export","data_import","view_editor"]; for(var i=0; i Date: Wed, 14 Dec 2011 14:23:06 +0100 Subject: [FIX] Make Field boolean readonly inherit of form's view boolean Field bzr revid: fme@openerp.com-20111214132306-xtem0i3waxrucc4a --- addons/web/static/src/js/view_form.js | 28 ++++++++++++---------------- addons/web/static/src/js/view_page.js | 7 ++++--- 2 files changed, 16 insertions(+), 19 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index fef32df4a90..5908dc67dc6 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -619,8 +619,8 @@ openerp.web.form.SidebarAttachments = openerp.web.Widget.extend({ var $e = $(e.target); if ($e.val() != '') { this.$element.find('form.oe-binary-form').submit(); - $e.parent().find('input[type=file]').attr('disabled', 'true'); - $e.parent().find('button').attr('disabled', 'true').find('img, span').toggle(); + $e.parent().find('input[type=file]').prop('disabled', true); + $e.parent().find('button').prop('disabled', true).find('img, span').toggle(); } }, on_attachment_delete: function(e) { @@ -1094,13 +1094,9 @@ openerp.web.form.WidgetButton = openerp.web.form.Widget.extend({ this.check_disable(); }, check_disable: function() { - if (this.readonly || this.force_disabled || !this.view.is_interactible_record()) { - this.$element.find("button").attr("disabled", "disabled"); - this.$element.find("button").css("color", "grey"); - } else { - this.$element.find("button").removeAttr("disabled"); - this.$element.find("button").css("color", ""); - } + var disabled = (this.readonly || this.force_disabled || !this.view.is_interactible_record()); + this.$element.find('button').prop('disabled', disabled); + this.$element.find("button").css('color', disabled ? 'grey' : ''); } }); @@ -1268,7 +1264,7 @@ openerp.web.form.FieldChar = openerp.web.form.Field.extend({ }, update_dom: function() { this._super.apply(this, arguments); - this.$element.find('input').attr('disabled', this.readonly); + this.$element.find('input').prop('disabled', this.readonly); }, set_value_from_ui: function() { this.value = openerp.web.parse_value(this.$element.find('input').val(), this); @@ -1392,7 +1388,7 @@ openerp.web.DateTimeWidget = openerp.web.Widget.extend({ }, set_readonly: function(readonly) { this.readonly = readonly; - this.$input.attr('disabled', this.readonly); + this.$input.prop('disabled', this.readonly); this.$element.find('img.oe_datepicker_trigger').toggleClass('oe_input_icon_disabled', readonly); }, is_valid: function(required) { @@ -1479,7 +1475,7 @@ openerp.web.form.FieldText = openerp.web.form.Field.extend({ }, update_dom: function() { this._super.apply(this, arguments); - this.$element.find('textarea').attr('disabled', this.readonly); + this.$element.find('textarea').prop('disabled', this.readonly); }, set_value_from_ui: function() { this.value = openerp.web.parse_value(this.$element.find('textarea').val(), this); @@ -1516,7 +1512,7 @@ openerp.web.form.FieldBoolean = openerp.web.form.Field.extend({ }, update_dom: function() { this._super.apply(this, arguments); - this.$element.find('input').attr('disabled', this.readonly); + this.$element.find('input').prop('disabled', this.readonly); }, focus: function() { this.$element.find('input').focus(); @@ -1599,7 +1595,7 @@ openerp.web.form.FieldSelection = openerp.web.form.Field.extend({ }, update_dom: function() { this._super.apply(this, arguments); - this.$element.find('select').attr('disabled', this.readonly); + this.$element.find('select').prop('disabled', this.readonly); }, validate: function() { var value = this.values[this.$element.find('select')[0].selectedIndex]; @@ -1948,7 +1944,7 @@ openerp.web.form.FieldMany2One = openerp.web.form.Field.extend({ }, update_dom: function() { this._super.apply(this, arguments); - this.$input.attr('disabled', this.readonly); + this.$input.prop('disabled', this.readonly); } }); @@ -2905,7 +2901,7 @@ openerp.web.form.FieldBinaryFile = openerp.web.form.FieldBinary.extend({ update_dom: function() { this._super.apply(this, arguments); this.$element.find('.oe-binary-file-set, .oe-binary-file-clear').toggle(!this.readonly); - this.$element.find('input[type=text]').attr('disabled', this.readonly); + this.$element.find('input[type=text]').prop('disabled', this.readonly); }, set_value: function(value) { this._super.apply(this, arguments); diff --git a/addons/web/static/src/js/view_page.js b/addons/web/static/src/js/view_page.js index abcfb5131dd..40ca1176c79 100644 --- a/addons/web/static/src/js/view_page.js +++ b/addons/web/static/src/js/view_page.js @@ -102,9 +102,10 @@ openerp.web.page = function (openerp) { this._super(s[2]); } }); - openerp.web.page.FieldBooleanReadonly = openerp.web.page.FieldCharReadonly.extend({ - set_value: function (value) { - this._super(value ? '\u2611' : '\u2610'); + openerp.web.page.FieldBooleanReadonly = openerp.web.form.FieldBoolean.extend({ + update_dom: function() { + this._super.apply(this, arguments); + this.$element.find('input').prop('disabled', true); } }); openerp.web.page.FieldSelectionReadonly = openerp.web.page.FieldReadonly.extend({ -- cgit v1.2.3 From 0b314b259610290d3a2cc1fe9f8a1a24848c4139 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 14 Dec 2011 14:45:12 +0100 Subject: [IMP] add session.server as a global variable for qweb temlates bzr revid: chs@openerp.com-20111214134512-byuq129f02t3fk4s --- addons/web/static/src/js/core.js | 1 + addons/web/static/src/xml/base.xml | 60 +++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 30 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 7123fe2934b..e1591f46235 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -375,6 +375,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. } var hostname = _.str.sprintf('%s//%s', location.protocol, location.host); this.server = _.str.rtrim((!server) ? hostname : server, '/'); + openerp.web.qweb.default_dict['_s'] = this.server this.rpc_mode = (this.server == hostname) ? "oe-json" : "oe-jsonp"; this.session_id = false; this.uid = false; diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 0a245fe0f38..1894d351e40 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -266,7 +266,7 @@
- +
@@ -306,7 +306,7 @@ @@ -916,7 +916,7 @@ @@ -928,7 +928,7 @@ t-att-id="widget.element_id" t-attf-class="field_#{widget.type}" style="width: 100%" - > + >
@@ -936,7 +936,7 @@
@@ -956,9 +956,9 @@ - + - + @@ -1009,7 +1009,7 @@
- + Full featured
@@ -315,7 +315,7 @@
- + Open Source
@@ -324,7 +324,7 @@
- + User Friendly
@@ -352,13 +352,13 @@
  • - +
  • - +
  • - +
@@ -712,7 +712,7 @@ @@ -883,7 +883,7 @@ t-att-id="widget.element_id" t-attf-class="field_#{widget.type} #{_(['integer', 'float', 'float_time']).contains(widget.type) ? 'oe-number' : ''}" style="width: 100%" - /> + />
- @@ -1039,14 +1039,14 @@
@@ -1074,7 +1074,7 @@ @@ -1083,13 +1083,13 @@ @@ -1097,7 +1097,7 @@ - + Uploading ... @@ -1106,7 +1106,7 @@ @@ -1199,7 +1199,7 @@ t-att-title="attrs.help" t-att-class="classes.join(' ')" t-att-autofocus="attrs.default_focus === '1' ? 'autofocus' : undefined"> - +
@@ -1346,7 +1346,7 @@ - + @@ -1689,7 +1689,7 @@ -- cgit v1.2.3 From 05af07ad0ed9023cab93d2d33877a6f99f858c05 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 14 Dec 2011 15:17:29 +0100 Subject: [IMP] o2m: do not display viewmanager header when only one view defined bzr revid: fme@openerp.com-20111214141729-arebojkvaxajozlm --- addons/web/static/src/xml/base.xml | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 09472e38657..fe5598ff6e9 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -483,6 +483,10 @@ + + + this.attr('t-if', 'views.length != 1'); + -- cgit v1.2.3 From e579d0fd712b40810be2c6d2951784d5d0b529de Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 14 Dec 2011 15:43:17 +0100 Subject: [FIX] don't display add/remove buttons in group_by_no_leaf views bzr revid: xmo@openerp.com-20111214144317-hfctv9rebwp5kvkp --- addons/web/static/src/js/view_list.js | 2 ++ addons/web/static/src/xml/base.xml | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 059bc020682..bf423434ecc 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -79,6 +79,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView# self.compute_aggregates(); }); + this.no_leaf = false; }, /** * Retrieves the view's number of records per page (|| section) @@ -473,6 +474,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView# if (_.isEmpty(group_by) && !context['group_by_no_leaf']) { group_by = null; } + this.no_leaf = !!context['group_by_no_leaf']; this.reload_view(!!group_by, context).then( $.proxy(this, 'reload_content')); diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index fe5598ff6e9..a880293403d 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -573,7 +573,7 @@

@@ -1573,7 +1573,7 @@

- +
- +
-
+ -- cgit v1.2.3 From 12014ea02c818f0d51facf91197b7e5efad9ab30 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 14 Dec 2011 16:29:03 +0100 Subject: [IMP] Move flags to ViewManager level so it can be passed to its constructor bzr revid: fme@openerp.com-20111214152903-wpkbw0s45xkdpr2a --- addons/web/static/src/js/views.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 0ad49f69f7b..fcc8a4cc06c 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -200,7 +200,7 @@ session.web.ViewManager = session.web.Widget.extend(/** @lends session.web.View * @param dataset * @param views */ - init: function(parent, dataset, views) { + init: function(parent, dataset, views, flags) { this._super(parent); this.model = dataset ? dataset.model : undefined; this.dataset = dataset; @@ -208,7 +208,7 @@ session.web.ViewManager = session.web.Widget.extend(/** @lends session.web.View this.active_view = null; this.views_src = _.map(views, function(x) {return x instanceof Array? {view_id: x[0], view_type: x[1]} : x;}); this.views = {}; - this.flags = this.flags || {}; + this.flags = flags || {}; this.registry = session.web.views; this.views_history = []; }, @@ -415,19 +415,10 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner // dataset initialization will take the session from ``this``, so if we // do not have it yet (and we don't, because we've not called our own // ``_super()``) rpc requests will blow up. - this._super(parent, null, action.views); - this.session = parent.session; - this.action = action; - var dataset = new session.web.DataSetSearch(this, action.res_model, action.context, action.domain); - if (action.res_id) { - dataset.ids.push(action.res_id); - dataset.index = 0; - } - this.dataset = dataset; - this.flags = this.action.flags || {}; + var flags = action.flags || {}; if (action.res_model == 'board.board' && action.view_mode === 'form') { // Special case for Dashboards - _.extend(this.flags, { + _.extend(flags, { views_switcher : false, display_title : false, search_view : false, @@ -436,6 +427,15 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner action_buttons : false }); } + this._super(parent, null, action.views, flags); + this.session = parent.session; + this.action = action; + var dataset = new session.web.DataSetSearch(this, action.res_model, action.context, action.domain); + if (action.res_id) { + dataset.ids.push(action.res_id); + dataset.index = 0; + } + this.dataset = dataset; // setup storage for session-wise menu hiding if (this.session.hidden_menutips) { -- cgit v1.2.3 From 6c2d28cadb56e66df913811d0e396beea37b5697 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 14 Dec 2011 16:54:41 +0100 Subject: [IMP] o2m: do not display action buttons in views used by one2many bzr revid: fme@openerp.com-20111214155441-gnb0yqjxyq0uklfa --- addons/web/static/src/js/view_form.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 5908dc67dc6..0ac70e64a67 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2055,7 +2055,9 @@ openerp.web.form.FieldOne2Many = openerp.web.form.Field.extend({ }); this.views = views; - this.viewmanager = new openerp.web.ViewManager(this, this.dataset, views); + this.viewmanager = new openerp.web.ViewManager(this, this.dataset, views, { + action_buttons : false + }); this.viewmanager.template = 'One2Many.viewmanager'; this.viewmanager.registry = openerp.web.views.clone({ list: 'openerp.web.form.One2ManyListView', @@ -2083,7 +2085,6 @@ openerp.web.form.FieldOne2Many = openerp.web.form.Field.extend({ controller.on_pager_action.add_first(function() { self.save_any_view(); }); - controller.$element.find(".oe_form_button_save").hide(); } else if (view_type == "graph") { self.reload_current_view() } -- cgit v1.2.3 From b53ee6fe2074fbbd7dc6932554631a5b3fbec185 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 14 Dec 2011 17:09:58 +0100 Subject: [WIP] better url management, only views are allowed to call this.do_push_state bzr revid: chs@openerp.com-20111214160958-xrtdubgh6jqn3mq3 --- addons/web/static/src/js/chrome.js | 10 +++----- addons/web/static/src/js/view_form.js | 3 +++ addons/web/static/src/js/views.js | 43 ++++++++++++++++++----------------- 3 files changed, 28 insertions(+), 28 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 8c8c3b5f7d6..4b41d3adc54 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1061,7 +1061,6 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie if(this.action_manager) this.action_manager.stop(); this.action_manager = new openerp.web.ActionManager(this); - this.action_manager.do_push_state.add(this.do_push_state); this.action_manager.appendTo($("#oe_app")); if (openerp._modules_loaded) { // TODO: find better option than this @@ -1076,7 +1075,7 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie }, on_logged_out: function() { $(window).unbind('hashchange', this.on_hashchange); - this.do_push_state({},true); + this.do_push_state({}); if(this.action_manager) this.action_manager.stop(); this.action_manager = null; @@ -1098,11 +1097,8 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie } this._current_state = state; }, - do_push_state: function(state, overwrite) { - if (!overwrite) { - var hash = $.deparam.fragment(true); - state = _.extend({}, hash, state); - } + do_push_state: function(state) { + console.log('dopushstate', state); var url = '#' + $.param(state); this._current_state = _.clone(state); $.bbq.pushState(url); diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 0ac70e64a67..b961b0089e3 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -175,6 +175,9 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView# if (self.default_focus_field && !self.embedded_view) { self.default_focus_field.focus(); } + if (record.id) { + self.do_push_state({id:record.id}); + } }); }, on_form_changed: function() { diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index fcc8a4cc06c..af0f0f47aba 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -20,6 +20,7 @@ session.web.ActionManager = session.web.Widget.extend({ identifier_prefix: "actionmanager", init: function(parent) { this._super(parent); + this.action = null; this.inner_viewmanager = null; this.dialog = null; this.dialog_viewmanager = null; @@ -47,7 +48,15 @@ session.web.ActionManager = session.web.Widget.extend({ } }, - do_push_state: function(state, overwrite) { + do_push_state: function(state) { + if (this.wiget_parent && this.widget_parent.do_push_state) { + if (this.action.id) { + state = _.extend({}, state || {}, { + action_id: this.action.id, + }); + } + this.widget_parent.do_push_state(state); + } }, do_load_state: function(state) { @@ -95,6 +104,7 @@ session.web.ActionManager = session.web.Widget.extend({ console.error("Action manager can't handle action of type " + action.type, action); return; } + this.action = action; return this[type](action, on_close); }, null_action: function() { @@ -128,10 +138,6 @@ session.web.ActionManager = session.web.Widget.extend({ this.content_stop(); this.inner_action = action; this.inner_viewmanager = new session.web.ViewManagerAction(this, action); - this.inner_viewmanager.do_push_state.add(function(state,overwrite) { - state['action_id'] = action.id; - self.do_push_state(state,true); - }); this.inner_viewmanager.appendTo(this.$element); } }, @@ -154,10 +160,6 @@ session.web.ActionManager = session.web.Widget.extend({ this.content_stop(); var ClientWidget = session.web.client_actions.get_object(action.tag); (this.client_widget = new ClientWidget(this, action.params)).appendTo(this); - - var client_action = {tag: action.tag}; - if (action.params) _.extend(client_action, {params: action.params}); - this.do_push_state({client_action: client_action}, true); }, ir_actions_report_xml: function(action, on_closed) { var self = this; @@ -466,12 +468,6 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner var main_view_loaded = this._super(); - _.each(_.keys(this.views), function(view_type) { - $.when(self.views[view_type].deferred).done(function(view_type) { - self.views[view_type].controller.do_push_state.add(self.do_push_state); - }); - }); - var manager_ready = $.when(searchview_loaded, main_view_loaded); this.$element.find('.oe_debug_view').change(this.on_debug_changed); @@ -584,12 +580,16 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner } else { $search_prefix.remove(); } - - self.do_push_state({view_type: self.active_view}); }); }, - do_push_state: function(state, overwrite) { + do_push_state: function(state) { + if (this.wiget_parent && this.widget_parent.do_push_state) { + state = _.extend({}, state || {}, { + view_type: this.active_view + }); + this.widget_parent.do_push_state(state); + } }, do_load_state: function(state) { @@ -1146,11 +1146,12 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{ return $.Deferred().resolve({}).promise(); }, - do_push_state: function(state, overwrite) { + do_push_state: function(state) { + if (this.wiget_parent && this.widget_parent.do_push_state) { + this.widget_parent.do_push_state(state); + } }, - do_load_state: function(state) { - } }); session.web.json_node_to_xml = function(node, human_readable, indent) { -- cgit v1.2.3 From f6b2fc59e98fe31ebf6ee352a180b026a44d0d53 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 14 Dec 2011 18:03:56 +0100 Subject: [imp] now closes dialogs when using client actions bzr revid: nicolas.vanhoren@openerp.com-20111214170356-sljdibj73yy0maeu --- addons/web/static/src/js/chrome.js | 2 +- addons/web/static/src/js/data.js | 2 +- addons/web/static/src/js/views.js | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 8c8c3b5f7d6..41f1ac532c6 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -663,7 +663,7 @@ openerp.web.Header = openerp.web.Widget.extend(/** @lends openerp.web.Header# * self.$content.remove(); if (!self.session.uid) return; - var func = new openerp.web.Model(self.session, "res.users").get_func("read"); + var func = new openerp.web.Model("res.users").get_func("read"); return func(self.session.uid, ["name", "company_id"]).pipe(function(res) { self.$content = $(QWeb.render("Header-content", {widget: self, user: res})); self.$content.appendTo(self.$element); diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index 26147b4d4e0..aec701e6e67 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -811,7 +811,7 @@ openerp.web.ProxyDataSet = openerp.web.DataSetSearch.extend({ }); openerp.web.Model = openerp.web.CallbackEnabled.extend({ - init: function(_, model_name) { + init: function(model_name) { this._super(); this.model_name = model_name; }, diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index fcc8a4cc06c..116d7da3aef 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -152,6 +152,7 @@ session.web.ActionManager = session.web.Widget.extend({ }, ir_actions_client: function (action) { this.content_stop(); + this.dialog_stop(); var ClientWidget = session.web.client_actions.get_object(action.tag); (this.client_widget = new ClientWidget(this, action.params)).appendTo(this); -- cgit v1.2.3 From 1db085976809c6fd9276c80724712967ed2dc99e Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Wed, 14 Dec 2011 18:18:11 +0100 Subject: [IMP] factorise View.do_show do_hide bzr revid: al@openerp.com-20111214171811-6l9jqafkr8k9grut --- addons/web/static/src/js/view_form.js | 4 ++-- addons/web/static/src/js/view_list.js | 4 ++-- addons/web/static/src/js/views.js | 15 ++++++++++----- 3 files changed, 14 insertions(+), 9 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 0ac70e64a67..79732296816 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -125,14 +125,14 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView# } else { promise = this.dataset.read_index(_.keys(this.fields_view.fields)).pipe(this.on_record_loaded); } - this.$element.show(); + this._super(); if (this.sidebar) { this.sidebar.$element.show(); } return promise; }, do_hide: function () { - this.$element.hide(); + this._super(); if (this.sidebar) { this.sidebar.$element.hide(); } diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index bf423434ecc..ad253586591 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -402,13 +402,13 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView# }, this)); }, do_show: function () { - this.$element.show(); + this._super(); if (this.sidebar) { this.sidebar.$element.show(); } }, do_hide: function () { - this.$element.hide(); + this._super(); if (this.sidebar) { this.sidebar.$element.hide(); } diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 116d7da3aef..30b3cff6c96 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -1065,19 +1065,26 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{ this.embedded_view = embedded_view; this.options.sidebar = false; }, + do_show: function () { + this.$element.show(); + }, + do_hide: function () { + this.$element.hide(); + }, /** * Switches to a specific view type * * @param {String} view view type to switch to */ - do_switch_view: function(view) { }, + do_switch_view: function(view) { + }, /** * Cancels the switch to the current view, switches to the previous one */ - do_prev_view: function () { }, + do_prev_view: function () { + }, do_search: function(view) { }, - set_common_sidebar_sections: function(sidebar) { sidebar.add_default_sections(); }, @@ -1146,10 +1153,8 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{ sidebar_context: function () { return $.Deferred().resolve({}).promise(); }, - do_push_state: function(state, overwrite) { }, - do_load_state: function(state) { } }); -- cgit v1.2.3 From cb4dbede99065b6e0bfa10163ce51579d77ec2e3 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Wed, 14 Dec 2011 19:04:42 +0100 Subject: [FIX] working urls bzr revid: al@openerp.com-20111214180442-gd1j369la1kss2wj --- addons/web/static/src/js/chrome.js | 1 - addons/web/static/src/js/view_form.js | 2 +- addons/web/static/src/js/views.js | 39 +++++++++++++++-------------------- 3 files changed, 18 insertions(+), 24 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index e4bbf5f2503..0d0454c08e4 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1098,7 +1098,6 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie this._current_state = state; }, do_push_state: function(state) { - console.log('dopushstate', state); var url = '#' + $.param(state); this._current_state = _.clone(state); $.bbq.pushState(url); diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 502778d0f28..eb5a310e154 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -125,7 +125,7 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView# } else { promise = this.dataset.read_index(_.keys(this.fields_view.fields)).pipe(this.on_record_loaded); } - this._super(); + this.$element.show(); if (this.sidebar) { this.sidebar.$element.show(); } diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index e29d7761196..f97a09dee94 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -20,7 +20,7 @@ session.web.ActionManager = session.web.Widget.extend({ identifier_prefix: "actionmanager", init: function(parent) { this._super(parent); - this.action = null; + this.inner_action = null; this.inner_viewmanager = null; this.dialog = null; this.dialog_viewmanager = null; @@ -47,18 +47,14 @@ session.web.ActionManager = session.web.Widget.extend({ this.client_widget = null; } }, - do_push_state: function(state) { - if (this.wiget_parent && this.widget_parent.do_push_state) { - if (this.action.id) { - state = _.extend({}, state || {}, { - action_id: this.action.id, - }); + if (this.widget_parent && this.widget_parent.do_push_state) { + if (this.inner_action && this.inner_action.id) { + state['action_id'] = this.inner_action.id; } this.widget_parent.do_push_state(state); } }, - do_load_state: function(state) { if (state.action_id) { this.null_action(); @@ -78,7 +74,6 @@ session.web.ActionManager = session.web.Widget.extend({ this.inner_viewmanager.do_load_state(state); } }, - do_action: function(action, on_close) { if (_.isNumber(action)) { var self = this; @@ -104,7 +99,6 @@ session.web.ActionManager = session.web.Widget.extend({ console.error("Action manager can't handle action of type " + action.type, action); return; } - this.action = action; return this[type](action, on_close); }, null_action: function() { @@ -317,8 +311,6 @@ session.web.ViewManager = session.web.Widget.extend(/** @lends session.web.View }); return view_promise; }, - - /** * Returns to the view preceding the caller view in this manager's * navigation history (the navigation history is appended to via @@ -394,7 +386,8 @@ session.web.ViewManager = session.web.Widget.extend(/** @lends session.web.View /** * Called by children view after executing an action */ - on_action_executed: function () {}, + on_action_executed: function () { + }, display_title: function () { var view = this.views[this.active_view]; if (view) { @@ -583,23 +576,18 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner } }); }, - do_push_state: function(state) { - if (this.wiget_parent && this.widget_parent.do_push_state) { - state = _.extend({}, state || {}, { - view_type: this.active_view - }); + if (this.widget_parent && this.widget_parent.do_push_state) { + state["view_type"] = this.active_view; this.widget_parent.do_push_state(state); } }, - do_load_state: function(state) { var self = this; $.when(this.on_mode_switch(state.view_type, true)).done(function() { self.views[self.active_view].controller.do_load_state(state); }); }, - shortcut_check : function(view) { var self = this; var grandparent = this.widget_parent && this.widget_parent.widget_parent; @@ -1067,10 +1055,18 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{ }, do_show: function () { this.$element.show(); + this.do_push_state({}); }, do_hide: function () { this.$element.hide(); }, + do_push_state: function(state) { + if (this.widget_parent && this.widget_parent.do_push_state) { + this.widget_parent.do_push_state(state); + } + }, + do_load_state: function(state) { + }, /** * Switches to a specific view type * @@ -1152,8 +1148,7 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{ }, sidebar_context: function () { return $.Deferred().resolve({}).promise(); - }, - }, + } }); session.web.json_node_to_xml = function(node, human_readable, indent) { -- cgit v1.2.3 From 028f9cc9842f07c9b33337332051b7e2b31f9d22 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 15 Dec 2011 11:06:52 +0100 Subject: [FIX] translatability of addition button label in listview * Original label is evaluated very early (before translation database is loaded), defer its execution * Replacement 'add' label in m2m list views wasn't marked for translation * Also mark a few strings in form view lp bug: https://launchpad.net/bugs/903963 fixed bzr revid: xmo@openerp.com-20111215100652-ibgqod7ikwiz85ic --- addons/web/static/src/js/view_form.js | 8 ++++---- addons/web/static/src/js/view_list.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 502778d0f28..83f6768f292 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -140,7 +140,7 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView# on_record_loaded: function(record) { var self = this, set_values = []; if (!record) { - throw("Form: No record received"); + throw new Error("Form: No record received"); } this.datarecord = record; @@ -629,7 +629,7 @@ openerp.web.form.SidebarAttachments = openerp.web.Widget.extend({ on_attachment_delete: function(e) { var self = this, $e = $(e.currentTarget); var name = _.str.trim($e.parent().find('a.oe-sidebar-attachments-link').text()); - if (confirm("Do you really want to delete the attachment " + name + " ?")) { + if (confirm(_.sprintf(_t("Do you really want to delete the attachment %s?"), name))) { this.rpc('/web/dataset/unlink', { model: 'ir.attachment', ids: [parseInt($e.attr('data-id'))] @@ -1051,7 +1051,7 @@ openerp.web.form.WidgetButton = openerp.web.form.Widget.extend({ if (self.node.attrs.confirm) { var def = $.Deferred(); var dialog = $('
' + self.node.attrs.confirm + '
').dialog({ - title: 'Confirm', + title: _t('Confirm'), modal: true, buttons: { Ok: function() { @@ -2374,7 +2374,7 @@ openerp.web.form.FieldMany2Many = openerp.web.form.Field.extend({ load_view: function() { var self = this; this.list_view = new openerp.web.form.Many2ManyListView(this, this.dataset, false, { - 'addable': self.is_readonly() ? null : 'Add', + 'addable': self.is_readonly() ? null : _t("Add"), 'deletable': self.is_readonly() ? false : true, 'selectable': self.multi_selection }); diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index ad253586591..36dc71cc485 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -12,7 +12,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView# // whether the column headers should be displayed 'header': true, // display addition button, with that label - 'addable': _t("Create"), + 'addable': {toString: function () { return _t("Create"); }}, // whether the list view can be sorted, note that once a view has been // sorted it can not be reordered anymore 'sortable': true, -- cgit v1.2.3 From 187216f8bdd055bc2dd3cdfa79245c8a2fbd754e Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 15 Dec 2011 11:40:31 +0100 Subject: [IMP] mark a bunch of dialog stuff as exportable (mostly buttons, but also dialog titles) bzr revid: xmo@openerp.com-20111215104031-zy56xwtb7cjwzcbj --- addons/web/static/src/js/chrome.js | 68 ++++++-------- addons/web/static/src/js/data_export.js | 17 ++-- addons/web/static/src/js/data_import.js | 2 +- addons/web/static/src/js/view_editor.js | 155 +++++++++++++++----------------- addons/web/static/src/js/view_form.js | 30 +++---- addons/web/static/src/js/views.js | 2 +- 6 files changed, 124 insertions(+), 150 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 0d0454c08e4..22b8ff88c37 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -2,7 +2,8 @@ * OpenERP Web chrome *---------------------------------------------------------*/ openerp.web.chrome = function(openerp) { -var QWeb = openerp.web.qweb; +var QWeb = openerp.web.qweb, + _t = openerp.web._t; openerp.web.Notification = openerp.web.Widget.extend(/** @lends openerp.web.Notification# */{ template: 'Notification', @@ -157,11 +158,9 @@ openerp.web.CrashManager = openerp.web.CallbackEnabled.extend({ on_managed_error: function(error) { $('
' + QWeb.render('DialogWarning', {error: error}) + '
').dialog({ title: "OpenERP " + _.str.capitalize(error.type), - buttons: { - Ok: function() { - $(this).dialog("close"); - } - } + buttons: [ + {text: _t("Ok"), click: function() { $(this).dialog("close"); }} + ] }); }, on_traceback: function(error) { @@ -172,11 +171,9 @@ openerp.web.CrashManager = openerp.web.CallbackEnabled.extend({ height: '90%', min_width: '800px', min_height: '600px', - buttons: { - Ok: function() { - $(this).dialog("close"); - } - } + buttons: [ + {text: _t("Ok"), click: function() { $(this).dialog("close"); }} + ] }).start(); dialog.$element.html(QWeb.render('DialogTraceback', {error: error})); } @@ -368,11 +365,9 @@ openerp.web.Database = openerp.web.Widget.extend(/** @lends openerp.web.Database return $('
').dialog({ modal: true, title: error.title, - buttons: { - Ok: function() { - $(this).dialog("close"); - } - } + buttons: [ + {text: _t("Ok"), click: function() { $(this).dialog("close"); }} + ] }).html(error.error); }, do_create: function() { @@ -680,7 +675,7 @@ openerp.web.Header = openerp.web.Widget.extend(/** @lends openerp.web.Header# * self.rpc("/web/webclient/version_info", {}).then(function(res) { var $help = $(QWeb.render("About-Page", {version_info: res})); $help.dialog({autoOpen: true, - modal: true, width: 960, title: "About"}); + modal: true, width: 960, title: _t("About")}); }); }, shortcut_load :function(){ @@ -760,25 +755,22 @@ openerp.web.Header = openerp.web.Widget.extend(/** @lends openerp.web.Header# * }); this.dialog = new openerp.web.Dialog(this,{ modal: true, - title: 'Preferences', + title: _t("Preferences"), width: 600, height: 500, - buttons: { - "Change password": function(){ - self.change_password(); - }, - Cancel: function(){ - $(this).dialog('destroy'); - }, - Save: function(){ - var inner_viewmanager = action_manager.inner_viewmanager; - inner_viewmanager.views[inner_viewmanager.active_view].controller.do_save() - .then(function() { - self.dialog.stop(); - window.location.reload(); - }); + buttons: [ + {text: _t("Change password"), click: function(){ self.change_password(); }}, + {text: _t("Cancel"), click: function(){ $(this).dialog('destroy'); }}, + {text: _t("Save"), click: function(){ + var inner_viewmanager = action_manager.inner_viewmanager; + inner_viewmanager.views[inner_viewmanager.active_view].controller.do_save() + .then(function() { + self.dialog.stop(); + window.location.reload(); + }); + } } - } + ] }); this.dialog.start().open(); action_manager.appendTo(this.dialog); @@ -789,7 +781,7 @@ openerp.web.Header = openerp.web.Widget.extend(/** @lends openerp.web.Header# * var self = this; this.dialog = new openerp.web.Dialog(this,{ modal : true, - title : 'Change Password', + title: _t("Change Password"), width : 'auto', height : 'auto' }); @@ -814,11 +806,9 @@ openerp.web.Header = openerp.web.Widget.extend(/** @lends openerp.web.Header# * return $('
').dialog({ modal: true, title: error.title, - buttons: { - Ok: function() { - $(this).dialog("close"); - } - } + buttons: [ + {text: _("Ok"), click: function() { $(this).dialog("close"); }} + ] }).html(error.error); }, on_logout: function() { diff --git a/addons/web/static/src/js/data_export.js b/addons/web/static/src/js/data_export.js index ea142606b5b..8a2d2c8594b 100644 --- a/addons/web/static/src/js/data_export.js +++ b/addons/web/static/src/js/data_export.js @@ -1,8 +1,9 @@ openerp.web.data_export = function(openerp) { -var QWeb = openerp.web.qweb; +var QWeb = openerp.web.qweb, + _t = openerp.web._t; openerp.web.DataExport = openerp.web.Dialog.extend({ template: 'ExportTreeView', - dialog_title: 'Export Data', + dialog_title: {toString: function () { return _t("Export Data"); }}, init: function(parent, dataset) { this._super(parent); this.records = {}; @@ -18,14 +19,10 @@ openerp.web.DataExport = openerp.web.Dialog.extend({ width: '55%', height: 'auto', position: 'top', - buttons : { - "Close" : function() { - self.close(); - }, - "Export To File" : function() { - self.on_click_export_data(); - } - }, + buttons : [ + {text: _t("Close"), click: function() { self.close(); }}, + {text: _t("Export To File"), click: function() { self.on_click_export_data(); }} + ], close: function(event, ui){ self.close();} }); self.$element.removeClass('ui-dialog-content ui-widget-content'); diff --git a/addons/web/static/src/js/data_import.js b/addons/web/static/src/js/data_import.js index cd699c0481d..7f4af7b35bb 100644 --- a/addons/web/static/src/js/data_import.js +++ b/addons/web/static/src/js/data_import.js @@ -31,7 +31,7 @@ function jsonp(form, attributes, callback) { openerp.web.DataImport = openerp.web.Dialog.extend({ template: 'ImportDataView', - dialog_title: "Import Data", + dialog_title: {toString: function () { return _t("Import Data"); }}, init: function(parent, dataset){ var self = this; this._super(parent, {}); diff --git a/addons/web/static/src/js/view_editor.js b/addons/web/static/src/js/view_editor.js index 352856c2b6c..f925a6416eb 100644 --- a/addons/web/static/src/js/view_editor.js +++ b/addons/web/static/src/js/view_editor.js @@ -35,28 +35,19 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ pager: false, radio: true, select_view_id: self.parent.fields_view.view_id - }, + } }; this.view_edit_dialog = new openerp.web.Dialog(this, { modal: true, - title: 'ViewEditor', + title: _t("ViewEditor"), width: 750, height: 500, - buttons: { - "Create": function(){ - self.on_create_view(); - }, - "Edit": function(){ - self.xml_element_id = 0; - self.get_arch(); - }, - "Remove": function(){ - self.do_delete_view(); - }, - "Close": function(){ - self.view_edit_dialog.close(); - } - }, + buttons: [ + {text: _t("Create"), click: function() { self.on_create_view(); }}, + {text: _t("Edit"), click: function() { self.xml_element_id = 0; self.get_arch(); }}, + {text: _t("Remove"), click: function() { self.do_delete_view(); }}, + {text: _t("Close"), click: function() { self.view_edit_dialog.close(); }} + ] }).start().open(); this.main_view_id = this.parent.fields_view.view_id; this.action_manager = new openerp.web.ActionManager(this); @@ -77,36 +68,34 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ var self = this; this.create_view_dialog = new openerp.web.Dialog(this, { modal: true, - title: _.str.sprintf("Create a view (%s)", self.model), + title: _.str.sprintf(_t("Create a view (%s)"), self.model), width: 500, height: 400, - buttons: { - "Save": function(){ - var view_values = {}; - var warn = false; - _.each(self.create_view_widget, function(widget) { - if (widget.is_invalid) { - warn = true; - return false; - }; - if (widget.dirty && !widget.is_invalid) { - view_values[widget.name] = widget.get_value(); - } - }); - if (warn) { - self.on_valid_create_view(self.create_view_widget); - } else { - $.when(self.do_save_view(view_values)).then(function() { - self.create_view_dialog.close(); - var controller = self.action_manager.inner_viewmanager.views[self.action_manager.inner_viewmanager.active_view].controller; - controller.reload_content(); - }); + buttons: [ + {text: _t("Save"), click: function () { + var view_values = {}; + var warn = false; + _.each(self.create_view_widget, function(widget) { + if (widget.is_invalid) { + warn = true; + return false; } - }, - "Cancel": function(){ - self.create_view_dialog.close(); + if (widget.dirty && !widget.is_invalid) { + view_values[widget.name] = widget.get_value(); + } + }); + if (warn) { + self.on_valid_create_view(self.create_view_widget); + } else { + $.when(self.do_save_view(view_values)).then(function() { + self.create_view_dialog.close(); + var controller = self.action_manager.inner_viewmanager.views[self.action_manager.inner_viewmanager.active_view].controller; + controller.reload_content(); + }); } - } + }}, + {text: _t("Cancel"), click: function () { self.create_view_dialog.close(); }} + ] }); this.create_view_dialog.start().open(); var view_widget = [{'name': 'view_name', 'string':'View Name', 'type': 'char', 'required': true, 'value' : this.model + '.custom_' + Math.round(Math.random() * 1000)}, @@ -375,11 +364,11 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ this.one_object = one_object; this.edit_xml_dialog = new openerp.web.Dialog(this, { modal: true, - title: _.str.sprintf("View Editor %d - %s", self.main_view_id, self.model), + title: _.str.sprintf(_t("View Editor %d - %s"), self.main_view_id, self.model), width: 750, height: 500, - buttons: { - "Preview": function() { + buttons: [ + {text: _t("Preview"), click: function() { var action = { context: self.session.user_context, res_model: self.model, @@ -389,16 +378,16 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ flags: { sidebar: false, views_switcher: false, - action_buttons: false, - }, + action_buttons: false + } }; var action_manager = new openerp.web.ActionManager(self); action_manager.do_action(action); - }, - "Close": function(){ + }}, + {text: _t("Close"), click: function(){ self.edit_xml_dialog.close(); - } - } + }} + ] }).start().open(); var no_property_att = []; _.each(_PROPERTIES, function(val, key) { @@ -764,17 +753,17 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ var self = this; this.edit_node_dialog = new openerp.web.Dialog(this,{ modal: true, - title: 'Properties', + title: _t("Properties"), width: 500, height: 400, - buttons: { - "Update": function(){ + buttons: [ + {text: _t("Update"), click: function () { var warn = false, update_values = []; _.each(self.edit_widget, function(widget) { if (widget.is_invalid) { warn = true; return false; - }; + } if (widget.dirty && !widget.is_invalid) { update_values.push([widget.name, widget.get_value()]); } @@ -785,11 +774,9 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ self.do_save_update_arch("update_node", update_values); self.edit_node_dialog.close(); } - }, - "Cancel": function(){ - self.edit_node_dialog.close(); - } - } + }}, + {text: _t("Cancel"), click: function () { self.edit_node_dialog.close(); }} + ] }); this.edit_node_dialog.start().open(); var _PROPERTIES_ATTRIBUTES = { @@ -893,32 +880,32 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ this.add_widget = []; this.add_node_dialog = new openerp.web.Dialog(this,{ modal: true, - title: 'Properties', + title: _t("Properties"), width: 450, height: 190, - buttons: { - "Update": function(){ - var check_add_node = true, values = {}; - _.each(self.add_widget, function(widget) { - values[widget.name] = widget.get_value() || false; - }); - (values.position == "Inside")? - check_add_node =(_.include(_CHILDREN[properties[0]],values.node_type))?true:false: - check_add_node =(_.include(_CHILDREN[properties[1]],values.node_type))?true:false; - if(values.node_type == "field" && check_add_node ) - {check_add_node = (values.field_value != " ")?true:false; - } - if(check_add_node){ - var tag = (values.node_type == "field")? - _.str.sprintf("<%s name='%s'> ",values.node_type,values.field_value,values.node_type): - _.str.sprintf("<%s> ",values.node_type,values.node_type); - self.do_save_update_arch("add_node", [tag, values.position]); - }else{alert("Can't Update View");} - }, - "Cancel": function(){ - self.add_node_dialog.close(); + buttons: [ + {text: _t("Update"), click: function() { + var check_add_node = true, values = {}; + _.each(self.add_widget, function(widget) { + values[widget.name] = widget.get_value() || false; + }); + (values.position == "Inside")? + check_add_node =(_.include(_CHILDREN[properties[0]],values.node_type))?true:false: + check_add_node =(_.include(_CHILDREN[properties[1]],values.node_type))?true:false; + if(values.node_type == "field" && check_add_node ) + {check_add_node = (values.field_value != " ")?true:false; } - } + if(check_add_node){ + var tag = (values.node_type == "field")? + _.str.sprintf("<%s name='%s'> ",values.node_type,values.field_value,values.node_type): + _.str.sprintf("<%s> ",values.node_type,values.node_type); + self.do_save_update_arch("add_node", [tag, values.position]); + } else { + alert("Can't Update View"); + } + }}, + {text: _t("Cancel"), click: function() { self.add_node_dialog.close(); }} + ] }).start().open(); this.add_node_dialog.$element.append('
'); var table_selector = self.add_node_dialog.$element.find('table[id=rec_table] tbody'); diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 83f6768f292..7be1cfec741 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -337,11 +337,9 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView# if (!_.isEmpty(result.warning)) { $(QWeb.render("DialogWarning", result.warning)).dialog({ modal: true, - buttons: { - Ok: function() { - $(this).dialog("close"); - } - } + buttons: [ + {text: _t("Ok"), click: function() { $(this).dialog("close"); }} + ] }); } if (result.domain) { @@ -1053,18 +1051,20 @@ openerp.web.form.WidgetButton = openerp.web.form.Widget.extend({ var dialog = $('
' + self.node.attrs.confirm + '
').dialog({ title: _t('Confirm'), modal: true, - buttons: { - Ok: function() { - self.on_confirmed().then(function() { - def.resolve(); - }); - $(this).dialog("close"); + buttons: [ + {text: _t("Ok"), click: function() { + self.on_confirmed().then(function() { + def.resolve(); + }); + $(this).dialog("close"); + } }, - Cancel: function() { - def.resolve(); - $(this).dialog("close"); + {text: _t("Cancel"), click: function() { + def.resolve(); + $(this).dialog("close"); + } } - } + ] }); return def.promise(); } else { diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index ba5ef2772e7..94972fcde31 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -840,7 +840,7 @@ session.web.Sidebar = session.web.Widget.extend({ }); session.web.TranslateDialog = session.web.Dialog.extend({ - dialog_title: _t("Translations"), + dialog_title: {toString: function () { return _t("Translations"); }}, init: function(view) { // TODO fme: should add the language to fields_view_get because between the fields view get // and the moment the user opens the translation dialog, the user language could have been changed -- cgit v1.2.3 From 31e65bdddf56510db08116029113d5966cd6a51f Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Thu, 15 Dec 2011 13:07:32 +0100 Subject: partial rework to merge trunk bzr revid: al@openerp.com-20111215120732-is7pab5e5rsfqpj0 --- addons/web/static/src/js/core.js | 96 +++++++++------------------------------- 1 file changed, 22 insertions(+), 74 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index e1591f46235..1f5e29a311a 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -362,7 +362,6 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. // be saved to (and revived from) cookies this.name = openerp._session_id; }, - bind: function(server, continuation) { if(_.isFunction(server)) { @@ -390,37 +389,12 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. this.active_id = null; this.do_load_qweb(['/web/webclient/qweb'], continuation); }, - connect: function(server, db, login, password, continuation) { var self = this; this.bind(server, function() { self.login(db, login, password, continuation); }); }, - - get_absolute_url: function(path) { - var absolute_url, - r_has_protocol = /^https?:\/\//, - r_absolute_internal = /^\/[^\/]/; // starts with / (but not //) - - - if (r_has_protocol.test(path)) { - if (!_.str.startsWith(path, this.server + '/')) { - $.error('can only contact openerp.server'); - } - absolute_url = path; - } else if (r_absolute_internal.test(path)) { - absolute_url = this.server + path; - } else { // relative url - // XXX is it correct to mix document.location and this.server ?? - var parts = document.location.pathname.split('/'); - parts.pop(); - parts.push(path); - absolute_url = this.server + parts.join('/'); - } - return absolute_url; - }, - /** * Executes an RPC call, registering the provided callbacks. * @@ -454,7 +428,6 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. }); }).then(success_callback, error_callback).promise(); }, - /** * Raw JSON-RPC call * @@ -521,7 +494,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. * The session is validated either by login or by restoration of a previous session */ on_session_valid: function(continuation) { - this.load_modules(continuation); + this.load_modules().then(function() { continuation() } ); }, on_session_invalid: function(continuation) { }, @@ -547,7 +520,9 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. //}).done(success_callback); }); }, - login: function() { this.session_authenticate.apply(this, arguments); }, + login: function() { + this.session_authenticate.apply(this, arguments); + }, /** * Reloads uid and session_id from local storage, if they exist */ @@ -628,17 +603,12 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. }, /** * Load additional web addons of that instance and init them - * FIXME do all actions in sync... */ - load_modules: function(continuation) { + load_modules: function() { var self = this; - - this.module_loading.done(continuation); - //if (this.module_loading.state() !== "pending") { - if (this.module_loading.isResolved() || this.module_loading.isRejected()) { - return; + if(openerp._modules_loaded) { + return $.when(); } - this.rpc('/web/session/modules', {}, function(result) { self.module_list = result; var lang = self.user_context.lang; @@ -649,37 +619,17 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. var file_list = ["/web/static/lib/datejs/globalization/" + self.user_context.lang.replace("_", "-") + ".js" ]; - - /* - self.rpc('/web/webclient/qweblist', {mods: modules}, self.do_load_qweb); - self.rpc('/web/webclient/csslist', {mods: modules}, self.do_load_css); - self.rpc('/web/webclient/jslist', {mods: modules}, function(files) { - self.do_load_js(file_list.concat(files)); - }); - openerp._modules_loaded = true; - // */ - - self.rpc('/web/webclient/qweblist', {mods: modules}, function(files) { - self.do_load_qweb(files, function() { - // once qweb files are loaded... - self.rpc('/web/webclient/csslist', {mods: modules}, function(files) { - self.do_load_css(files, function() { - // once css files are loaded - self.rpc('/web/webclient/jslist', {mods: modules}, function(files) { - self.do_load_js(file_list.concat(files), function() { - self.on_modules_loaded(); - self.module_loading.resolve(); - }); - }); - }); - }); - }); - }); - + return $.when( + self.rpc('/web/webclient/qweblist', {mods: modules}, self.do_load_qweb), + self.rpc('/web/webclient/csslist', {mods: modules}, self.do_load_css), + self.rpc('/web/webclient/jslist', {mods: modules}, function(files) { + self.do_load_js(file_list.concat(files)); + }) + ); }); }); }, - do_load_css: function (files, callback) { + do_load_css: function (files) { var self = this; _.each(files, function (file) { $('head').append($('', { @@ -688,9 +638,8 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. 'type': 'text/css' })); }); - if (callback) { callback(); } }, - do_load_js: function(files, callback) { + do_load_js: function(files) { var self = this; if(files.length != 0) { var file = files.shift(); @@ -706,21 +655,18 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. var head = document.head || document.getElementsByTagName('head')[0]; head.appendChild(tag); } else { - if (callback) { callback(); } + self.on_modules_loaded(); } }, - do_load_qweb: function(files, callback) { + do_load_qweb: function(files) { var self = this; - if (files.length != 0) { var file = files.shift(); - self.rpc('/web/jsonp/static_proxy', {path: file}, function(xml) { + self.rpc('/web/proxy/load', {path: file}, function(xml) { openerp.web.qweb.add_template(_.str.trim(xml)); self.do_load_qweb(files, callback); }); - } else { - if (callback) { callback(); } - } + } }, on_modules_loaded: function() { for(var j=0; j Date: Thu, 15 Dec 2011 14:33:05 +0100 Subject: move jq_ajax.js bzr revid: al@openerp.com-20111215133305-c7jgyqdes33drllk --- addons/web/static/src/js/chrome.js | 3 - addons/web/static/src/js/core.js | 181 ++++++++++++++++++++++++++++++++++++- 2 files changed, 177 insertions(+), 7 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 22b8ff88c37..b03c5965bf7 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1014,7 +1014,6 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie this._super.apply(this, arguments); var self = this; openerp.connection.bind(function() { - var params = {}; if(jQuery.param != undefined && jQuery.deparam(jQuery.param.querystring()).kitten != undefined) { self.$element.addClass("kitten-mode-activated"); @@ -1022,8 +1021,6 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie self.$element.html(QWeb.render("Interface", params)); openerp.connection.session_restore(); - - // TODO nivification of menu Widget !!! self.menu = new openerp.web.Menu(self, "oe_menu", "oe_secondary_menu"); self.menu.on_action.add(self.on_menu_action); diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 1f5e29a311a..96e38b4e4d0 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -342,6 +342,183 @@ openerp.web.CallbackEnabled = openerp.web.Class.extend(/** @lends openerp.web.Ca } }); +$.ajaxSetup({ + converters: { + "json oe-jsonp": true, + "json oe-json": true, + } +}); + +// common preconditions checks +$.ajaxPrefilter("oe-json oe-jsonp", function(options, originalOptions, jqXHR) { + if (!$.isPlainObject(options.openerp)) { + console.error(options.openerp); + $.error('"openerp" option is required.'); + } + + if (!$.isPlainObject(options.data)) { + $.error('data must not be serialized'); + } + options.processData = false; +}); + +$.ajaxPrefilter("oe-json", function(options, originalOptions, jqXHR) { + options.data = JSON.stringify({ + jsonrpc: '2.0', + method: 'call', + params: options.data, + id: _.uniqueId('browser-client-') + }); + + return 'json'; +}); + +$.ajaxPrefilter("oe-jsonp", function(options, originalOptions, jqXHR) { + + options.crossDomain = true; + + var data = null; + if (options.data) { + data = $.param({r:JSON.stringify(options.data)}); + } + + + + var max_url_length = options.max_url_length || 1000, + absolute_url, full_url; + /* + var r_has_protocol = /^https?:\/\//, + r_absolute_internal = /^\/[^\/]/; // starts with / (but not //) + + + if (r_has_protocol.test(options.url)) { + if (!_(options.url).startsWith(options.openerp.server + '/')) { + $.error('can only contact openerp.server'); + } + absolute_url = options.url; + } else if (r_absolute_internal.test(options.url)) { + absolute_url = options.openerp.server + options.url; + } else { // relative url + var parts = document.location.pathname.split('/'); + parts.pop(); + parts.push(options.url); + absolute_url = options.openerp.server + parts.join('/'); + } + // */ + + var absolute_url = options.openerp.get_absolute_url(options.url); + + /// now, made the same url changes that jQuery will do... + var rquery = /\?/, + rts = /([?&])_=[^&]*/; + + full_url = absolute_url; + if (data) { + full_url += (rquery.test(full_url) ? "&" : "?") + data; + } + + // Add anti-cache in url if needed + if (!options.cache) { + var ts = $.now(), + // try replacing _= if it is there + ret = full_url.replace(rts, "$1_=" + ts); + + // if nothing was replaced, add timestamp to the end + full_url = ret + ((ret === full_url) ? (rquery.test(full_url) ? "&" : "?") + "_=" + ts : ""); + } + + options.url = absolute_url; + + if (full_url.length < max_url_length) { + options.type = "GET"; + options.data = data; + return "jsonp"; // classic jsonp query... + } +}); + +$.ajaxTransport("oe-jsonp", function(options, originalOptions, jqXHR) { + + var $iframe = null; + var $form = $('
') + .attr('method', 'POST') + .attr('enctype', "multipart/form-data") + .attr('action', options.openerp.server + "/web/jsonp/post") + .hide() + .appendTo($('body')) + ; + + function cleanUp() { + if ($iframe) { + $iframe.unbind("load").attr("src", "javascript:false;").remove(); + } + $form.remove(); + } + + return { + + send: function(headers, completeCallback) { + + var ifid = _.uniqueId('oe_jsonp_iframe_'); + var request_id = _.uniqueId('browser-client-'); + var oe_callback = _.uniqueId('oe_callback_'); + + window[oe_callback] = function(result) { + completeCallback(200, 'success', {json: result}); + }; + + + var display = options.openerp.debug ? 'block' : 'none'; + $iframe = $(_.str.sprintf("", ifid, ifid, display)); + + + // the first bind is fired up when the iframe is added to the DOM + $iframe.bind('load', function() { + // the second bind is fired up when the result of the form submission is received + $iframe.unbind('load').bind('load', function() { + // we cannot access the content of remote iframe. + // but we don't care, we try to get the result in any cases + + $.ajax({ + type: "GET", + url: options.url, + dataType: 'jsonp', + jsonp: false, // do not append callback=? argument on query string + jsonpCallback: oe_callback, + data: { + sid: options.openerp.session_id, + rid: request_id, + }, + }).always(function() { + cleanUp(); + }); + + }); + + + // now that the iframe can receive data, we fill and submit the form + var params = JSON.stringify(options.data); + + $form + .append($('').attr('value', options.openerp.session_id)) + .append($('').attr('value', request_id)) + .append($('').attr('value', params)) + .append($('').attr('value', oe_callback)) + .submit() + ; + + }); + + $form.attr('target', ifid) // set the iframe as target of the form + .after($iframe); // append the iframe to the DOM (will trigger the first load) + + }, + abort: function() { + cleanUp(); + }, + }; + +}); + openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.web.Connection# */{ /** * @constructs openerp.web.Connection @@ -351,10 +528,6 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. * @param {String} [port] JSON-RPC endpoint port */ init: function() { - - // FIXME need to be a real singleton. - // create more than one Connection on the same instance will not works - this._super(); this.server = null; this.debug = ($.deparam($.param.querystring()).debug != undefined); -- cgit v1.2.3 From 4206e4d2627be8ca252fdfce2f90654ff9db0055 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Thu, 15 Dec 2011 19:32:59 +0100 Subject: connection jsonp wip bzr revid: al@openerp.com-20111215183259-vam7tsjlkqhjam69 --- addons/web/static/src/js/chrome.js | 3 +- addons/web/static/src/js/core.js | 356 +++++++++++------------------------- addons/web/static/src/js/formats.js | 2 +- addons/web/static/src/js/jq_ajax.js | 184 ------------------- 4 files changed, 107 insertions(+), 438 deletions(-) delete mode 100644 addons/web/static/src/js/jq_ajax.js (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index b03c5965bf7..eb9328a6bd1 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1013,7 +1013,7 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie start: function() { this._super.apply(this, arguments); var self = this; - openerp.connection.bind(function() { + openerp.connection.bind("",function() { var params = {}; if(jQuery.param != undefined && jQuery.deparam(jQuery.param.querystring()).kitten != undefined) { self.$element.addClass("kitten-mode-activated"); @@ -1103,7 +1103,6 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie }, }); - openerp.currentScript = function() { var currentScript = document.currentScript; if (!currentScript) { diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 96e38b4e4d0..55bce373330 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -342,183 +342,6 @@ openerp.web.CallbackEnabled = openerp.web.Class.extend(/** @lends openerp.web.Ca } }); -$.ajaxSetup({ - converters: { - "json oe-jsonp": true, - "json oe-json": true, - } -}); - -// common preconditions checks -$.ajaxPrefilter("oe-json oe-jsonp", function(options, originalOptions, jqXHR) { - if (!$.isPlainObject(options.openerp)) { - console.error(options.openerp); - $.error('"openerp" option is required.'); - } - - if (!$.isPlainObject(options.data)) { - $.error('data must not be serialized'); - } - options.processData = false; -}); - -$.ajaxPrefilter("oe-json", function(options, originalOptions, jqXHR) { - options.data = JSON.stringify({ - jsonrpc: '2.0', - method: 'call', - params: options.data, - id: _.uniqueId('browser-client-') - }); - - return 'json'; -}); - -$.ajaxPrefilter("oe-jsonp", function(options, originalOptions, jqXHR) { - - options.crossDomain = true; - - var data = null; - if (options.data) { - data = $.param({r:JSON.stringify(options.data)}); - } - - - - var max_url_length = options.max_url_length || 1000, - absolute_url, full_url; - /* - var r_has_protocol = /^https?:\/\//, - r_absolute_internal = /^\/[^\/]/; // starts with / (but not //) - - - if (r_has_protocol.test(options.url)) { - if (!_(options.url).startsWith(options.openerp.server + '/')) { - $.error('can only contact openerp.server'); - } - absolute_url = options.url; - } else if (r_absolute_internal.test(options.url)) { - absolute_url = options.openerp.server + options.url; - } else { // relative url - var parts = document.location.pathname.split('/'); - parts.pop(); - parts.push(options.url); - absolute_url = options.openerp.server + parts.join('/'); - } - // */ - - var absolute_url = options.openerp.get_absolute_url(options.url); - - /// now, made the same url changes that jQuery will do... - var rquery = /\?/, - rts = /([?&])_=[^&]*/; - - full_url = absolute_url; - if (data) { - full_url += (rquery.test(full_url) ? "&" : "?") + data; - } - - // Add anti-cache in url if needed - if (!options.cache) { - var ts = $.now(), - // try replacing _= if it is there - ret = full_url.replace(rts, "$1_=" + ts); - - // if nothing was replaced, add timestamp to the end - full_url = ret + ((ret === full_url) ? (rquery.test(full_url) ? "&" : "?") + "_=" + ts : ""); - } - - options.url = absolute_url; - - if (full_url.length < max_url_length) { - options.type = "GET"; - options.data = data; - return "jsonp"; // classic jsonp query... - } -}); - -$.ajaxTransport("oe-jsonp", function(options, originalOptions, jqXHR) { - - var $iframe = null; - var $form = $('') - .attr('method', 'POST') - .attr('enctype', "multipart/form-data") - .attr('action', options.openerp.server + "/web/jsonp/post") - .hide() - .appendTo($('body')) - ; - - function cleanUp() { - if ($iframe) { - $iframe.unbind("load").attr("src", "javascript:false;").remove(); - } - $form.remove(); - } - - return { - - send: function(headers, completeCallback) { - - var ifid = _.uniqueId('oe_jsonp_iframe_'); - var request_id = _.uniqueId('browser-client-'); - var oe_callback = _.uniqueId('oe_callback_'); - - window[oe_callback] = function(result) { - completeCallback(200, 'success', {json: result}); - }; - - - var display = options.openerp.debug ? 'block' : 'none'; - $iframe = $(_.str.sprintf("", ifid, ifid, display)); - - - // the first bind is fired up when the iframe is added to the DOM - $iframe.bind('load', function() { - // the second bind is fired up when the result of the form submission is received - $iframe.unbind('load').bind('load', function() { - // we cannot access the content of remote iframe. - // but we don't care, we try to get the result in any cases - - $.ajax({ - type: "GET", - url: options.url, - dataType: 'jsonp', - jsonp: false, // do not append callback=? argument on query string - jsonpCallback: oe_callback, - data: { - sid: options.openerp.session_id, - rid: request_id, - }, - }).always(function() { - cleanUp(); - }); - - }); - - - // now that the iframe can receive data, we fill and submit the form - var params = JSON.stringify(options.data); - - $form - .append($('').attr('value', options.openerp.session_id)) - .append($('').attr('value', request_id)) - .append($('').attr('value', params)) - .append($('').attr('value', oe_callback)) - .submit() - ; - - }); - - $form.attr('target', ifid) // set the iframe as target of the form - .after($iframe); // append the iframe to the DOM (will trigger the first load) - - }, - abort: function() { - cleanUp(); - }, - }; - -}); - openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.web.Connection# */{ /** * @constructs openerp.web.Connection @@ -529,26 +352,17 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. */ init: function() { this._super(); - this.server = null; - this.debug = ($.deparam($.param.querystring()).debug != undefined); // TODO: session should have an optional name indicating that they'll // be saved to (and revived from) cookies this.name = openerp._session_id; }, - bind: function(server, continuation) { - - if(_.isFunction(server)) { - continuation = server; - server = null; - } - - if (this.server) { - throw new Error("Connection already bound to " + this.server); - } - var hostname = _.str.sprintf('%s//%s', location.protocol, location.host); - this.server = _.str.rtrim((!server) ? hostname : server, '/'); - openerp.web.qweb.default_dict['_s'] = this.server - this.rpc_mode = (this.server == hostname) ? "oe-json" : "oe-jsonp"; + bind: function(host, protocol) { + this.host = (host == undefined) ? location.host : host; + this.protocol = (protocol == undefined) ? location.protocol : protocol; + this.prefix = this.protocol + '//' + this.host; + openerp.web.qweb.default_dict['_s'] = this.prefix + this.rpc_mode = (host == location.host) ? "json" : "jsonp"; + this.debug = (window.location.search.indexOf('?debug') !== -1); this.session_id = false; this.uid = false; this.username = false; @@ -562,12 +376,6 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. this.active_id = null; this.do_load_qweb(['/web/webclient/qweb'], continuation); }, - connect: function(server, db, login, password, continuation) { - var self = this; - this.bind(server, function() { - self.login(db, login, password, continuation); - }); - }, /** * Executes an RPC call, registering the provided callbacks. * @@ -583,79 +391,130 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. */ rpc: function(url, params, success_callback, error_callback) { var self = this; + // url can be an $.ajax option object + if (_.isString(url)) { + url = { url: url }; + } // Construct a JSON-RPC2 request, method is currently unused params.session_id = this.session_id; if (this.debug) params.debug = 1; - + var payload = { + jsonrpc: '2.0', + method: 'call', + params: params, + id: _.uniqueId('oe-') + }; // Call using the rpc_mode var deferred = $.Deferred(); - this.rpc_ajax(url, params) - .then(function () {deferred.resolve.apply(deferred, arguments);}, - function(error) {deferred.reject(error, $.Event());}); - return deferred.fail(function() { + this.on_rpc_request(); + this.rpc_json(url, payload).then( + function (response, textStatus, jqXHR) { + self.on_rpc_response(); + if (!response.error) { + deferred.resolve(response["result"], textStatus, jqXHR); + } else if (response.error.data.type === "session_invalid") { + self.uid = false; + self.on_session_invalid(function() { + self.rpc(url, payload.params, + function() { deferred.resolve.apply(deferred, arguments); }, + function() { deferred.reject.apply(deferred, arguments); }); + }); + } else { + deferred.reject(response.error, $.Event()); + } + }, + function(jqXHR, textStatus, errorThrown) { + self.on_rpc_response(); + var error = { + code: -32098, + message: "XmlHttpRequestError " + errorThrown, + data: {type: "xhr"+textStatus, debug: jqXHR.responseText, objects: [jqXHR, errorThrown] } + }; + deferred.reject(error, $.Event()); + }); + // Allow deferred user to disable on_rpc_error in fail + deferred.fail(function() { deferred.fail(function(error, event) { if (!event.isDefaultPrevented()) { self.on_rpc_error(error, event); } }); }).then(success_callback, error_callback).promise(); + return deferred; }, /** * Raw JSON-RPC call * * @returns {jQuery.Deferred} ajax-webd deferred object */ - rpc_ajax: function(url, payload) { + rpc_json: function(url, payload) { var self = this; - this.on_rpc_request(); - // url can be an $.ajax option object - if (_.isString(url)) { - url = { - url: url - } - } var ajax = _.extend({ type: "POST", - url: url, - dataType: this.rpc_mode, + dataType: 'json', contentType: 'application/json', - data: payload, + data: JSON.stringify(payload), processData: false, - openerp: _.extend({}, this), // need a plainObject }, url); - var deferred = $.Deferred(); - $.ajax(ajax).done(function(response, textStatus, jqXHR) { - self.on_rpc_response(); - if (!response.error) { - deferred.resolve(response["result"], textStatus, jqXHR); - return; - } - if (response.error.data.type !== "session_invalid") { - deferred.reject(response.error); - return; + return $.ajax(ajax); + }, + rpc_jsonp: function(url, payload) { + var self = this; + var ajax = _.extend({ + type: "GET", + dataType: 'jsonp', + jsonp: 'jsonp', + cache: false, + data: { + session_id: this.session_id, + id: payload.id, } - self.uid = false; - self.on_session_invalid(function() { // retry - self.rpc(url, payload, - function() { - deferred.resolve.apply(deferred, arguments); - }, - function(error, event) { - event.preventDefault(); - deferred.reject.apply(deferred, arguments); - }); - }); - }).fail(function(jqXHR, textStatus, errorThrown) { - self.on_rpc_response(); - var error = { - code: -32098, - message: "XmlHttpRequestError " + errorThrown, - data: {type: "xhr"+textStatus, debug: jqXHR.responseText, objects: [jqXHR, errorThrown] } + }, url); + var payload_str = JSON.stringify(payload); + var payload_url = $.param({r:payload_str}); + if(playload_url.length < 2000) { + // Direct json request + ajax.data.r = payload_str; + return $.ajax(ajax); + } else { + // Indirect json request + var ifid = _.uniqueId('oe_rpc_iframe_'); + var display = options.openerp.debug ? 'block' : 'none'; + var $iframe = $(_.str.sprintf("", ifid, ifid, display)); + var $form = $('') + .attr('method', 'POST') + .attr('target', ifid) + .attr('enctype', "multipart/form-data") + .attr('action', ajax.url) + .append($('').attr('value', payload_str)) + .hide() + .appendTo($('body')); + var cleanUp = function() { + if ($iframe) { + $iframe.unbind("load").attr("src", "javascript:false;").remove(); + } + $form.remove(); }; - deferred.reject(error); - }); - return deferred.promise(); + var deferred = $.Deferred(); + // the first bind is fired up when the iframe is added to the DOM + $iframe.bind('load', function() { + // the second bind is fired up when the result of the form submission is received + $iframe.unbind('load').bind('load', function() { + $.ajax(ajax).always(function() { + cleanUp(); + }).then( + function() { deferred.resolve.apply(deferred, arguments); }, + function() { deferred.reject.apply(deferred, arguments); } + ); + }); + // now that the iframe can receive data, we fill and submit the form + $form.submit(); + }); + // append the iframe to the DOM (will trigger the first load) + $form.after($iframe); + return deffered; + } }, on_rpc_request: function() { }, @@ -687,15 +546,10 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. username: result.login }); self.session_save(); - self.on_session_valid(success_callback); return true; - //}).done(success_callback); }); }, - login: function() { - this.session_authenticate.apply(this, arguments); - }, /** * Reloads uid and session_id from local storage, if they exist */ diff --git a/addons/web/static/src/js/formats.js b/addons/web/static/src/js/formats.js index 13cceaeba8d..264cc836e2d 100644 --- a/addons/web/static/src/js/formats.js +++ b/addons/web/static/src/js/formats.js @@ -254,7 +254,7 @@ openerp.web.format_cell = function (row_data, column, value_if_empty, process_mo if (column.tag === 'button') { return [ '' ].join('') diff --git a/addons/web/static/src/js/jq_ajax.js b/addons/web/static/src/js/jq_ajax.js deleted file mode 100644 index 611ab1e1e22..00000000000 --- a/addons/web/static/src/js/jq_ajax.js +++ /dev/null @@ -1,184 +0,0 @@ - - $.ajaxSetup({ - converters: { - "json oe-jsonp": true, - "json oe-json": true, - } - }); - - - // common preconditions checks - $.ajaxPrefilter("oe-json oe-jsonp", function(options, originalOptions, jqXHR) { - if (!$.isPlainObject(options.openerp)) { - console.error(options.openerp); - $.error('"openerp" option is required.'); - } - - if (!$.isPlainObject(options.data)) { - $.error('data must not be serialized'); - } - options.processData = false; - }); - - - - $.ajaxPrefilter("oe-json", function(options, originalOptions, jqXHR) { - options.data = JSON.stringify({ - jsonrpc: '2.0', - method: 'call', - params: options.data, - id: _.uniqueId('browser-client-') - }); - - return 'json'; - }); - - - $.ajaxPrefilter("oe-jsonp", function(options, originalOptions, jqXHR) { - - options.crossDomain = true; - - var data = null; - if (options.data) { - data = $.param({r:JSON.stringify(options.data)}); - } - - - - var max_url_length = options.max_url_length || 1000, - absolute_url, full_url; - /* - var r_has_protocol = /^https?:\/\//, - r_absolute_internal = /^\/[^\/]/; // starts with / (but not //) - - - if (r_has_protocol.test(options.url)) { - if (!_(options.url).startsWith(options.openerp.server + '/')) { - $.error('can only contact openerp.server'); - } - absolute_url = options.url; - } else if (r_absolute_internal.test(options.url)) { - absolute_url = options.openerp.server + options.url; - } else { // relative url - var parts = document.location.pathname.split('/'); - parts.pop(); - parts.push(options.url); - absolute_url = options.openerp.server + parts.join('/'); - } - // */ - - var absolute_url = options.openerp.get_absolute_url(options.url); - - /// now, made the same url changes that jQuery will do... - var rquery = /\?/, - rts = /([?&])_=[^&]*/; - - full_url = absolute_url; - if (data) { - full_url += (rquery.test(full_url) ? "&" : "?") + data; - } - - // Add anti-cache in url if needed - if (!options.cache) { - var ts = $.now(), - // try replacing _= if it is there - ret = full_url.replace(rts, "$1_=" + ts); - - // if nothing was replaced, add timestamp to the end - full_url = ret + ((ret === full_url) ? (rquery.test(full_url) ? "&" : "?") + "_=" + ts : ""); - } - - options.url = absolute_url; - - if (full_url.length < max_url_length) { - options.type = "GET"; - options.data = data; - return "jsonp"; // classic jsonp query... - } - }); - - - $.ajaxTransport("oe-jsonp", function(options, originalOptions, jqXHR) { - - var $iframe = null; - var $form = $('') - .attr('method', 'POST') - .attr('enctype', "multipart/form-data") - .attr('action', options.openerp.server + "/web/jsonp/post") - .hide() - .appendTo($('body')) - ; - - function cleanUp() { - if ($iframe) { - $iframe.unbind("load").attr("src", "javascript:false;").remove(); - } - $form.remove(); - } - - return { - - send: function(headers, completeCallback) { - - var ifid = _.uniqueId('oe_jsonp_iframe_'); - var request_id = _.uniqueId('browser-client-'); - var oe_callback = _.uniqueId('oe_callback_'); - - window[oe_callback] = function(result) { - completeCallback(200, 'success', {json: result}); - }; - - - var display = options.openerp.debug ? 'block' : 'none'; - $iframe = $(_.str.sprintf("", ifid, ifid, display)); - - - // the first bind is fired up when the iframe is added to the DOM - $iframe.bind('load', function() { - // the second bind is fired up when the result of the form submission is received - $iframe.unbind('load').bind('load', function() { - // we cannot access the content of remote iframe. - // but we don't care, we try to get the result in any cases - - $.ajax({ - type: "GET", - url: options.url, - dataType: 'jsonp', - jsonp: false, // do not append callback=? argument on query string - jsonpCallback: oe_callback, - data: { - sid: options.openerp.session_id, - rid: request_id, - }, - }).always(function() { - cleanUp(); - }); - - }); - - - // now that the iframe can receive data, we fill and submit the form - var params = JSON.stringify(options.data); - - $form - .append($('').attr('value', options.openerp.session_id)) - .append($('').attr('value', request_id)) - .append($('').attr('value', params)) - .append($('').attr('value', oe_callback)) - .submit() - ; - - }); - - $form.attr('target', ifid) // set the iframe as target of the form - .after($iframe); // append the iframe to the DOM (will trigger the first load) - - }, - abort: function() { - cleanUp(); - }, - }; - - }); - - -- cgit v1.2.3 From 8721df9d549e72b7154ae34dff53aa4b82718b85 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Fri, 16 Dec 2011 01:44:02 +0100 Subject: [IMP] massive connection deferrization, json works again bzr revid: al@openerp.com-20111216004402-q6v26822swarra7r --- addons/web/static/src/js/chrome.js | 44 +++++--------- addons/web/static/src/js/core.js | 120 +++++++++++++++++-------------------- 2 files changed, 69 insertions(+), 95 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 70beb7ecc34..cbf475af44e 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1004,20 +1004,12 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie this.header.on_logout.add(this.login.on_logout); this.header.on_action.add(this.on_menu_action); - this.session.on_session_invalid.add(this.login.do_ask_login); - this.session.on_session_valid.add_last(this.header.do_update); - this.session.on_session_invalid.add_last(this.header.do_update); - this.session.on_session_valid.add_last(this.on_logged); - this.session.on_session_invalid.add_last(this.on_logged_out); - - this._current_state = null; - }, start: function() { this._super.apply(this, arguments); var self = this; - openerp.connection.bind("",function() { + this.session.bind().then(function() { var params = {}; if (jQuery.param != undefined && jQuery.deparam(jQuery.param.querystring()).kitten != undefined) { this.$element.addClass("kitten-mode-activated"); @@ -1026,17 +1018,25 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie }); } self.$element.html(QWeb.render("Interface", params)); - openerp.connection.session_restore(); - self.menu = new openerp.web.Menu(self, "oe_menu", "oe_secondary_menu"); self.menu.on_action.add(self.on_menu_action); - self.notification.prependTo(self.$element); self.loading.appendTo($('#oe_loading')); self.header.appendTo($("#oe_header")); self.login.appendTo($('#oe_login')); self.menu.start(); + self.login.on_login_invalid(); + }); + this.session.ready.then(function() { + self.login.on_login_valid(); + self.header.do_update(); + self.menu.do_reload(); + if(self.action_manager) + self.action_manager.stop(); + self.action_manager = new openerp.web.ActionManager(this); + self.action_manager.appendTo($("#oe_app")); + self.bind_hashchange(); }); }, do_reload: function() { @@ -1050,24 +1050,8 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie var n = this.notification; n.warn.apply(n, arguments); }, - on_logged: function() { - this.menu.do_reload(); - if(this.action_manager) - this.action_manager.stop(); - this.action_manager = new openerp.web.ActionManager(this); - this.action_manager.appendTo($("#oe_app")); - - if (openerp._modules_loaded) { // TODO: find better option than this - this.bind_hashchange(); - } else { - this.session.on_modules_loaded.add({ // XXX what about a $.Deferred ? - callback: $.proxy(this, 'bind_hashchange'), - unique: true, - position: 'last' - }) - } - }, - on_logged_out: function() { + on_loggued_out: function() { + this.header.do_update(); $(window).unbind('hashchange', this.on_hashchange); this.do_push_state({}); if(this.action_manager) diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 55bce373330..f28d0adfc03 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -352,11 +352,11 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. */ init: function() { this._super(); - // TODO: session should have an optional name indicating that they'll - // be saved to (and revived from) cookies + // TODO: session store in cookie should be optional this.name = openerp._session_id; }, bind: function(host, protocol) { + var self = this; this.host = (host == undefined) ? location.host : host; this.protocol = (protocol == undefined) ? location.protocol : protocol; this.prefix = this.protocol + '//' + this.host; @@ -368,13 +368,13 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. this.username = false; this.user_context= {}; this.db = false; - this.module_loading = $.Deferred(); this.module_list = []; this.module_loaded = {"web": true}; this.context = {}; this.shortcuts = []; this.active_id = null; - this.do_load_qweb(['/web/webclient/qweb'], continuation); + this.ready = $.Deferred(); + return this.session_restore(); }, /** * Executes an RPC call, registering the provided callbacks. @@ -523,73 +523,51 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. on_rpc_error: function(error) { }, /** - * The session is validated either by login or by restoration of a previous session + * Init a session, reloads from cookie, if it exists */ - on_session_valid: function(continuation) { - this.load_modules().then(function() { continuation() } ); - }, - on_session_invalid: function(continuation) { - }, - session_is_valid: function() { - return this.uid; - }, - session_authenticate: function(db, login, password, success_callback) { + session_restore: function () { var self = this; - var base_location = document.location.protocol + '//' + document.location.host; - var params = { db: db, login: login, password: password, base_location: base_location }; - return this.rpc("/web/session/authenticate", params, function(result) { + // TODO: session store in cookie should be optional + this.session_id = this.get_cookie('session_id'); + return this.rpc("/web/session/get_session_info", {}).pipe(function(result) { + // If immediately follows a login (triggered by trying to restore + // an invalid session or no session at all), refresh session data + // (should not change, but just in case...) _.extend(self, { - session_id: result.session_id, - uid: result.uid, - user_context: result.context, db: result.db, - username: result.login + username: result.login, + uid: result.uid, + user_context: result.context }); - self.session_save(); - self.on_session_valid(success_callback); - return true; + var deferred = self.do_load_qweb(['/web/webclient/qweb']); + if(self.uid) { + return deferred.then(self.load_modules()); + } + return deferred; }); }, /** - * Reloads uid and session_id from local storage, if they exist + * The session is validated either by login or by restoration of a previous session */ - session_restore: function (continuation) { + session_authenticate: function(db, login, password) { var self = this; - this.session_id = this.get_cookie('session_id'); - return this.rpc("/web/session/get_session_info", {}).then(function(result) { - // If immediately follows a login (triggered by trying to restore - // an invalid session or no session at all), refresh session data - // (should not change, but just in case...) but should not call - // on_session_valid again as it triggers reloading the menu - var already_logged = self.uid; + var base_location = document.location.protocol + '//' + document.location.host; + var params = { db: db, login: login, password: password, base_location: base_location }; + return this.rpc("/web/session/authenticate", params).pipe(function(result) { _.extend(self, { - uid: result.uid, - user_context: result.context, + session_id: result.session_id, db: result.db, - username: result.login + username: result.login, + uid: result.uid, + user_context: result.context }); - if (!already_logged) { - if (self.uid) { - self.on_session_valid(continuation); - } else { - self.on_session_invalid(continuation); - } - } - }, function() { - self.on_session_invalid(continuation); + // TODO: session store in cookie should be optional + self.set_cookie('session_id', this.session_id); + return self.load_modules(); }); }, - /** - * Saves the session id and uid locally - */ - session_save: function () { - this.set_cookie('session_id', this.session_id); - }, - logout: function() { + session_logout: function() { this.set_cookie('session_id', ''); - this.reload_client(); - }, - reload_client: function() { window.location.reload(); }, /** @@ -640,19 +618,21 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. self.module_list = result; var lang = self.user_context.lang; var params = { mods: ["web"].concat(result), lang: lang}; - self.rpc('/web/webclient/translations',params).then(function(transs) { + self.rpc('/web/webclient/translations',params).pipe(function(transs) { openerp.web._t.database.set_bundle(transs); var modules = self.module_list.join(','); var file_list = ["/web/static/lib/datejs/globalization/" + self.user_context.lang.replace("_", "-") + ".js" ]; return $.when( - self.rpc('/web/webclient/qweblist', {mods: modules}, self.do_load_qweb), self.rpc('/web/webclient/csslist', {mods: modules}, self.do_load_css), - self.rpc('/web/webclient/jslist', {mods: modules}, function(files) { + self.rpc('/web/webclient/qweblist', {mods: modules}).pipe(self.do_load_qweb), + self.rpc('/web/webclient/jslist', {mods: modules}).pipe(function(files) { self.do_load_js(file_list.concat(files)); }) - ); + ).then(function() { + self.ready.resolve(); + }); }); }); }, @@ -660,7 +640,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. var self = this; _.each(files, function (file) { $('head').append($('', { - 'href': self.get_absolute_url(file), + 'href': self.get_url(file), 'rel': 'stylesheet', 'type': 'text/css' })); @@ -668,32 +648,39 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. }, do_load_js: function(files) { var self = this; + var d = $.Deferred(); if(files.length != 0) { var file = files.shift(); var tag = document.createElement('script'); tag.type = 'text/javascript'; - tag.src = self.get_absolute_url(file); + tag.src = self.get_url(file); tag.onload = tag.onreadystatechange = function() { if ( (tag.readyState && tag.readyState != "loaded" && tag.readyState != "complete") || tag.onload_done ) return; tag.onload_done = true; - self.do_load_js(files, callback); + self.do_load_js(files).then(function () { + d.resolve(); + }); }; var head = document.head || document.getElementsByTagName('head')[0]; head.appendChild(tag); } else { self.on_modules_loaded(); + d.resolve(); } + return d; }, do_load_qweb: function(files) { var self = this; if (files.length != 0) { var file = files.shift(); - self.rpc('/web/proxy/load', {path: file}, function(xml) { + return self.rpc('/web/proxy/load', {path: file}).pipe(function(xml) { openerp.web.qweb.add_template(_.str.trim(xml)); - self.do_load_qweb(files, callback); + return self.do_load_qweb(files); }); - } + } else { + return $.when(); + } }, on_modules_loaded: function() { for(var j=0; j Date: Fri, 16 Dec 2011 01:48:23 +0100 Subject: [IMP] minor changes bzr revid: al@openerp.com-20111216004823-s3lh80nymv2xu6fs --- addons/web/static/src/js/chrome.js | 2 +- addons/web/static/src/js/core.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index cbf475af44e..90c51571d3d 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1040,7 +1040,7 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie }); }, do_reload: function() { - return $.when(this.session.session_restore(),this.menu.do_reload()); + return $.when(this.session.session_init(),this.menu.do_reload()); }, do_notify: function() { var n = this.notification; diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index f28d0adfc03..695a833da81 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -374,7 +374,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. this.shortcuts = []; this.active_id = null; this.ready = $.Deferred(); - return this.session_restore(); + return this.session_init(); }, /** * Executes an RPC call, registering the provided callbacks. @@ -415,6 +415,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. deferred.resolve(response["result"], textStatus, jqXHR); } else if (response.error.data.type === "session_invalid") { self.uid = false; + // TODO deprecate or use a deferred on login.do_ask_login() self.on_session_invalid(function() { self.rpc(url, payload.params, function() { deferred.resolve.apply(deferred, arguments); }, @@ -525,7 +526,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. /** * Init a session, reloads from cookie, if it exists */ - session_restore: function () { + session_init: function () { var self = this; // TODO: session store in cookie should be optional this.session_id = this.get_cookie('session_id'); -- cgit v1.2.3 From d315489256557498de4e3c641a7cc28e6550d575 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Fri, 16 Dec 2011 02:25:42 +0100 Subject: [FIX] session cookie and logout bzr revid: al@openerp.com-20111216012542-svbiuf64x017wll5 --- addons/web/static/src/js/chrome.js | 9 ++++----- addons/web/static/src/js/core.js | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 90c51571d3d..50fb8018918 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -629,9 +629,6 @@ openerp.web.Login = openerp.web.Widget.extend(/** @lends openerp.web.Login# */{ callback: continuation || function() {} }); }, - on_logout: function() { - this.session.logout(); - } }); openerp.web.Header = openerp.web.Widget.extend(/** @lends openerp.web.Header# */{ @@ -1001,7 +998,7 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie this.header = new openerp.web.Header(this); this.login = new openerp.web.Login(this); - this.header.on_logout.add(this.login.on_logout); + this.header.on_logout.add(this.on_logout); this.header.on_action.add(this.on_menu_action); this._current_state = null; @@ -1050,7 +1047,9 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie var n = this.notification; n.warn.apply(n, arguments); }, - on_loggued_out: function() { + on_logout: function() { + this.session.session_logout(); + this.login.on_login_invalid(); this.header.do_update(); $(window).unbind('hashchange', this.on_hashchange); this.do_push_state({}); diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 695a833da81..a46f7d5cac8 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -563,7 +563,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. user_context: result.context }); // TODO: session store in cookie should be optional - self.set_cookie('session_id', this.session_id); + self.set_cookie('session_id', self.session_id); return self.load_modules(); }); }, -- cgit v1.2.3 From 770a738b9b0e773506c38af0a14e91476ae14e1b Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Fri, 16 Dec 2011 02:30:51 +0100 Subject: [FIX] more deferred bzr revid: al@openerp.com-20111216013051-x45j314u7d4zvfoq --- addons/web/static/src/js/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index a46f7d5cac8..7efd673f124 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -629,7 +629,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. self.rpc('/web/webclient/csslist', {mods: modules}, self.do_load_css), self.rpc('/web/webclient/qweblist', {mods: modules}).pipe(self.do_load_qweb), self.rpc('/web/webclient/jslist', {mods: modules}).pipe(function(files) { - self.do_load_js(file_list.concat(files)); + return self.do_load_js(file_list.concat(files)); }) ).then(function() { self.ready.resolve(); -- cgit v1.2.3 From 28715cfaab85970c3bbabf49bc12a5dfa2efc200 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Fri, 16 Dec 2011 02:49:45 +0100 Subject: [FIX] jsonp fixes currently untested bzr revid: al@openerp.com-20111216014945-mhq4eee2hy9mip27 --- addons/web/static/src/js/core.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 7efd673f124..3d66c4f4ccf 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -361,7 +361,8 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. this.protocol = (protocol == undefined) ? location.protocol : protocol; this.prefix = this.protocol + '//' + this.host; openerp.web.qweb.default_dict['_s'] = this.prefix - this.rpc_mode = (host == location.host) ? "json" : "jsonp"; + this.rpc_mode = (this.host == location.host) ? "json" : "jsonp"; + this.rpc_function = (this.host == location.host) ? this.rpc_json : this.rpc_jsonp; this.debug = (window.location.search.indexOf('?debug') !== -1); this.session_id = false; this.uid = false; @@ -403,12 +404,11 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. jsonrpc: '2.0', method: 'call', params: params, - id: _.uniqueId('oe-') + id: _.uniqueId('r') }; - // Call using the rpc_mode var deferred = $.Deferred(); this.on_rpc_request(); - this.rpc_json(url, payload).then( + this.rpc_function(url, payload).then( function (response, textStatus, jqXHR) { self.on_rpc_response(); if (!response.error) { @@ -462,32 +462,35 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. }, rpc_jsonp: function(url, payload) { var self = this; + // extracted from payload to set on the url + var data = { + session_id: this.session_id, + id: payload.id, + }; + url.url = this.get_url(url.url); var ajax = _.extend({ type: "GET", dataType: 'jsonp', jsonp: 'jsonp', cache: false, - data: { - session_id: this.session_id, - id: payload.id, - } + data: data }, url); var payload_str = JSON.stringify(payload); var payload_url = $.param({r:payload_str}); if(playload_url.length < 2000) { - // Direct json request + // Direct jsonp request ajax.data.r = payload_str; return $.ajax(ajax); } else { - // Indirect json request - var ifid = _.uniqueId('oe_rpc_iframe_'); + // Indirect jsonp request + var ifid = _.uniqueId('oe_rpc_iframe'); var display = options.openerp.debug ? 'block' : 'none'; var $iframe = $(_.str.sprintf("", ifid, ifid, display)); var $form = $('') .attr('method', 'POST') .attr('target', ifid) .attr('enctype', "multipart/form-data") - .attr('action', ajax.url) + .attr('action', ajax.url + '?' + $.param(data)) .append($('').attr('value', payload_str)) .hide() .appendTo($('body')); @@ -514,7 +517,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. }); // append the iframe to the DOM (will trigger the first load) $form.after($iframe); - return deffered; + return deferred; } }, on_rpc_request: function() { @@ -696,6 +699,9 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. } } }, + get_url: function (file) { + return this.prefix + file; + }, /** * Cooperative file download implementation, for ajaxy APIs. * @@ -716,9 +722,6 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. * @param {Function} [options.error] callback in case of request error, provided with the error body * @param {Function} [options.complete] called after both ``success`` and ``error` callbacks have executed */ - get_url: function (file) { - return this.prefix + file; - }, get_file: function (options) { // need to detect when the file is done downloading (not used // yet, but we'll need it to fix the UI e.g. with a throbber -- cgit v1.2.3