From 79a8b39369e3ee8636c493ba8784fdf5becb9110 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 20 Feb 2012 12:57:04 +0100 Subject: [FIX] avoid adding session_id and token fields in form if they are already there, reuse existing fields instead lp bug: https://launchpad.net/bugs/936704 fixed bzr revid: xmo@openerp.com-20120220115704-zxo024voy3dxa7qe --- addons/web/static/src/js/core.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index c4e37a8a3b1..106d2b86dc9 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -884,9 +884,12 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. _(_.extend({}, options.data || {}, {session_id: this.session_id, token: token})) .each(function (value, key) { - $('') - .val(value) - .appendTo($form_data); + var $input = $form.find('[name=' + key +']'); + if (!$input.length) { + $input = $('') + .appendTo($form_data); + } + $input.val(value) }); $form -- cgit v1.2.3 From a6f6b7fd9dd636bde823b39edc309f69eb994d6d Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 21 Feb 2012 16:22:12 +0100 Subject: [imp] added setParent bzr revid: nicolas.vanhoren@openerp.com-20120221152212-yr6iaa2znq37mcsz --- addons/web/static/src/js/core.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 086f7f3b56a..647a8713dff 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -1006,6 +1006,9 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W this.$element = $(document.createElement(this.tag_name)); + this.setParent(parent); + }, + setParent: function(parent) { this.widget_parent = parent; this.widget_children = []; if(parent && parent.widget_children) { -- cgit v1.2.3 From 8384876ef08ae3e8af97a9531da7f79a8359d607 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 21 Feb 2012 16:30:23 +0100 Subject: [imp] renamed widget_parent to getParent() bzr revid: nicolas.vanhoren@openerp.com-20120221153023-cqs66neaddtuf7km --- addons/web/static/src/js/core.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 647a8713dff..dca4ad47d0e 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -1017,6 +1017,9 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W // useful to know if the widget was destroyed and should not be used anymore this.widget_is_stopped = false; }, + getParent: function() { + return this.widget_parent; + }, /** * Renders the current widget and appends it to the given jQuery object or Widget. * -- cgit v1.2.3 From cdd8489e4ca4c790cc4772ec1a6edbee4fe8136f Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 21 Feb 2012 16:44:58 +0100 Subject: [imp] further refactoring of parents bzr revid: nicolas.vanhoren@openerp.com-20120221154458-imbqiywuj91mds9c --- addons/web/static/src/js/core.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index dca4ad47d0e..ca4d5f00781 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -974,6 +974,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. * That will kill the widget in a clean way and erase its content from the dom. */ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.Widget# */{ + __parented_mixin: true, /** * The name of the QWeb template that will be used for rendering. Must be * redefined in subclasses or the default render() method can not be used. @@ -1009,16 +1010,23 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W this.setParent(parent); }, setParent: function(parent) { - this.widget_parent = parent; - this.widget_children = []; - if(parent && parent.widget_children) { + if(this.getParent()) { + if (this.getParent().__parented_mixin) { + this.getParent().widget_children = _.without(this.getParent().widget_children, this); + } + this.__parented_parent = undefined; + } + this.__parented_parent = parent; + if(parent && parent.__parented_mixin) { + if (!parent.widget_children) + parent.widget_children = []; parent.widget_children.push(this); } // useful to know if the widget was destroyed and should not be used anymore this.widget_is_stopped = false; }, getParent: function() { - return this.widget_parent; + return this.__parented_parent; }, /** * Renders the current widget and appends it to the given jQuery object or Widget. @@ -1120,10 +1128,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W if(this.$element != null) { this.$element.remove(); } - if (this.widget_parent && this.widget_parent.widget_children) { - this.widget_parent.widget_children = _.without(this.widget_parent.widget_children, this); - } - this.widget_parent = null; + this.setParent(undefined); this.widget_is_stopped = true; }, /** @@ -1132,20 +1137,20 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W * If that's not the case this method will simply return `false`. */ do_action: function(action, on_finished) { - if (this.widget_parent) { - return this.widget_parent.do_action(action, on_finished); + if (this.getParent()) { + return this.getParent().do_action(action, on_finished); } return false; }, do_notify: function() { - if (this.widget_parent) { - return this.widget_parent.do_notify.apply(this,arguments); + if (this.getParent()) { + return this.getParent().do_notify.apply(this,arguments); } return false; }, do_warn: function() { - if (this.widget_parent) { - return this.widget_parent.do_warn.apply(this,arguments); + if (this.getParent()) { + return this.getParent().do_warn.apply(this,arguments); } return false; }, -- cgit v1.2.3 From be66f62357f7cf0658a7c04b8cc41c15e38c55c8 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 21 Feb 2012 16:51:34 +0100 Subject: [imp] changed children bzr revid: nicolas.vanhoren@openerp.com-20120221155134-lej2ren1troagr72 --- addons/web/static/src/js/core.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index ca4d5f00781..d31d27b8fa4 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -1012,15 +1012,15 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W setParent: function(parent) { if(this.getParent()) { if (this.getParent().__parented_mixin) { - this.getParent().widget_children = _.without(this.getParent().widget_children, this); + this.getParent().__parented_children = _.without(this.getParent().getChildren(), this); } this.__parented_parent = undefined; } this.__parented_parent = parent; if(parent && parent.__parented_mixin) { - if (!parent.widget_children) - parent.widget_children = []; - parent.widget_children.push(this); + if (!parent.getChildren()) + parent.__parented_children = []; + parent.getChildren().push(this); } // useful to know if the widget was destroyed and should not be used anymore this.widget_is_stopped = false; @@ -1028,6 +1028,9 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W getParent: function() { return this.__parented_parent; }, + getChildren: function() { + return this.__parented_children || []; + }, /** * Renders the current widget and appends it to the given jQuery object or Widget. * @@ -1122,7 +1125,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W * Destroys the current widget, also destroys all its children before destroying itself. */ stop: function() { - _.each(_.clone(this.widget_children), function(el) { + _.each(_.clone(this.getChildren()), function(el) { el.stop(); }); if(this.$element != null) { -- cgit v1.2.3 From 7fcfcbaddbea0da9c17eed388ef5d7af21b9e100 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 21 Feb 2012 16:55:16 +0100 Subject: [imp] changed is_stopped bzr revid: nicolas.vanhoren@openerp.com-20120221155516-7eczor9bobky9dxq --- addons/web/static/src/js/core.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index d31d27b8fa4..9e9e01428ba 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -1022,8 +1022,6 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W parent.__parented_children = []; parent.getChildren().push(this); } - // useful to know if the widget was destroyed and should not be used anymore - this.widget_is_stopped = false; }, getParent: function() { return this.__parented_parent; @@ -1031,6 +1029,9 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W getChildren: function() { return this.__parented_children || []; }, + isStopped: function() { + return this.__parented_stopped; + }, /** * Renders the current widget and appends it to the given jQuery object or Widget. * @@ -1132,7 +1133,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W this.$element.remove(); } this.setParent(undefined); - this.widget_is_stopped = true; + this.__parented_stopped = true; }, /** * Informs the action manager to do an action. This supposes that @@ -1162,10 +1163,10 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W var def = $.Deferred().then(success, error); var self = this; openerp.connection.rpc(url, data). then(function() { - if (!self.widget_is_stopped) + if (!self.isStopped()) def.resolve.apply(def, arguments); }, function() { - if (!self.widget_is_stopped) + if (!self.isStopped()) def.reject.apply(def, arguments); }); return def.promise(); -- cgit v1.2.3 From 4ee34acbbec49b6de11b1ef0843b4e6605d60227 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 21 Feb 2012 16:58:06 +0100 Subject: [imp] cosmetic changes bzr revid: nicolas.vanhoren@openerp.com-20120221155806-e6efydx5k7qtppdn --- addons/web/static/src/js/core.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 9e9e01428ba..992c7fef83c 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -1029,9 +1029,22 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W getChildren: function() { return this.__parented_children || []; }, - isStopped: function() { + isDestroyed: function() { return this.__parented_stopped; }, + /** + * Destroys the current widget, also destroys all its children before destroying itself. + */ + stop: function() { + _.each(_.clone(this.getChildren()), function(el) { + el.stop(); + }); + if(this.$element != null) { + this.$element.remove(); + } + this.setParent(undefined); + this.__parented_stopped = true; + }, /** * Renders the current widget and appends it to the given jQuery object or Widget. * @@ -1122,19 +1135,6 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W start: function() { return $.Deferred().done().promise(); }, - /** - * Destroys the current widget, also destroys all its children before destroying itself. - */ - stop: function() { - _.each(_.clone(this.getChildren()), function(el) { - el.stop(); - }); - if(this.$element != null) { - this.$element.remove(); - } - this.setParent(undefined); - this.__parented_stopped = true; - }, /** * Informs the action manager to do an action. This supposes that * the action manager can be found amongst the ancestors of the current widget. @@ -1163,10 +1163,10 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W var def = $.Deferred().then(success, error); var self = this; openerp.connection.rpc(url, data). then(function() { - if (!self.isStopped()) + if (!self.isDestroyed()) def.resolve.apply(def, arguments); }, function() { - if (!self.isStopped()) + if (!self.isDestroyed()) def.reject.apply(def, arguments); }); return def.promise(); -- cgit v1.2.3 From 75d39c7f6a2565419c28bac4397678a6d60c5544 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 21 Feb 2012 17:29:12 +0100 Subject: [imp] renammed stop() bzr revid: nicolas.vanhoren@openerp.com-20120221162912-zheko30qoh84hcoq --- addons/web/static/src/js/core.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 992c7fef83c..63e0e2010c5 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -969,7 +969,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. * * And of course, when you don't need that widget anymore, just do: * - * my_widget.stop(); + * my_widget.destroy(); * * That will kill the widget in a clean way and erase its content from the dom. */ @@ -994,7 +994,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W * @extends openerp.web.CallbackEnabled * * @param {openerp.web.Widget} parent Binds the current instance to the given Widget instance. - * When that widget is destroyed by calling stop(), the current instance will be + * When that widget is destroyed by calling destroy(), the current instance will be * destroyed too. Can be null. * @param {String} element_id Deprecated. Sets the element_id. Only useful when you want * to bind the current Widget to an already existing part of the DOM, which is not compatible @@ -1035,9 +1035,9 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W /** * Destroys the current widget, also destroys all its children before destroying itself. */ - stop: function() { + destroy: function() { _.each(_.clone(this.getChildren()), function(el) { - el.stop(); + el.destroy(); }); if(this.$element != null) { this.$element.remove(); -- cgit v1.2.3 From a7386b589a99197453f1a5311fbf1d388efee3b0 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 21 Feb 2012 17:35:47 +0100 Subject: [imp] extracted parenting into a mixin bzr revid: nicolas.vanhoren@openerp.com-20120221163547-i1ii1frqj9b6ddtp --- addons/web/static/src/js/core.js | 63 +++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 27 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 63e0e2010c5..a02c6767ca3 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -925,6 +925,40 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. } }); +openerp.web.ParentedMixin = { + __parented_mixin: true, + setParent: function(parent) { + if(this.getParent()) { + if (this.getParent().__parented_mixin) { + this.getParent().__parented_children = _.without(this.getParent().getChildren(), this); + } + this.__parented_parent = undefined; + } + this.__parented_parent = parent; + if(parent && parent.__parented_mixin) { + if (!parent.getChildren()) + parent.__parented_children = []; + parent.getChildren().push(this); + } + }, + getParent: function() { + return this.__parented_parent; + }, + getChildren: function() { + return this.__parented_children ? _.clone(this.__parented_children) : []; + }, + isDestroyed: function() { + return this.__parented_stopped; + }, + destroy: function() { + _.each(this.getChildren(), function(el) { + el.destroy(); + }); + this.setParent(undefined); + this.__parented_stopped = true; + }, +}; + /** * Base class for all visual components. Provides a lot of functionalities helpful * for the management of a part of the DOM. @@ -973,8 +1007,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. * * That will kill the widget in a clean way and erase its content from the dom. */ -openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.Widget# */{ - __parented_mixin: true, +openerp.web.Widget = openerp.web.CallbackEnabled.extend(openerp.web.ParentedMixin).extend(/** @lends openerp.web.Widget# */{ /** * The name of the QWeb template that will be used for rendering. Must be * redefined in subclasses or the default render() method can not be used. @@ -1009,29 +1042,6 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W this.setParent(parent); }, - setParent: function(parent) { - if(this.getParent()) { - if (this.getParent().__parented_mixin) { - this.getParent().__parented_children = _.without(this.getParent().getChildren(), this); - } - this.__parented_parent = undefined; - } - this.__parented_parent = parent; - if(parent && parent.__parented_mixin) { - if (!parent.getChildren()) - parent.__parented_children = []; - parent.getChildren().push(this); - } - }, - getParent: function() { - return this.__parented_parent; - }, - getChildren: function() { - return this.__parented_children || []; - }, - isDestroyed: function() { - return this.__parented_stopped; - }, /** * Destroys the current widget, also destroys all its children before destroying itself. */ @@ -1042,8 +1052,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W if(this.$element != null) { this.$element.remove(); } - this.setParent(undefined); - this.__parented_stopped = true; + this._super(); }, /** * Renders the current widget and appends it to the given jQuery object or Widget. -- cgit v1.2.3 From bd4723f66d0e5a68ab48214837fbca98d2d37ca2 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 22 Feb 2012 11:22:34 +0100 Subject: [fix] some details bzr revid: nicolas.vanhoren@openerp.com-20120222102234-k9jjclhmgpalf3qs --- addons/web/static/src/js/core.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index a02c6767ca3..fd0abcb0eb4 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -936,9 +936,9 @@ openerp.web.ParentedMixin = { } this.__parented_parent = parent; if(parent && parent.__parented_mixin) { - if (!parent.getChildren()) + if (!parent.__parented_children) parent.__parented_children = []; - parent.getChildren().push(this); + parent.__parented_children.push(this); } }, getParent: function() { @@ -948,14 +948,14 @@ openerp.web.ParentedMixin = { return this.__parented_children ? _.clone(this.__parented_children) : []; }, isDestroyed: function() { - return this.__parented_stopped; + return this.__parented_destroyed; }, destroy: function() { _.each(this.getChildren(), function(el) { el.destroy(); }); this.setParent(undefined); - this.__parented_stopped = true; + this.__parented_destroyed = true; }, }; @@ -1046,7 +1046,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(openerp.web.ParentedMixi * Destroys the current widget, also destroys all its children before destroying itself. */ destroy: function() { - _.each(_.clone(this.getChildren()), function(el) { + _.each(this.getChildren(), function(el) { el.destroy(); }); if(this.$element != null) { -- cgit v1.2.3 From 3baa0d76081f0d5e2d6ebc10296a8efaf656cfbc Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 22 Feb 2012 17:13:24 +0100 Subject: [FIX] Widget: correctly check if rendered template is empty bzr revid: fme@openerp.com-20120222161324-fut6gawp70qff0ev --- addons/web/static/src/js/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 086f7f3b56a..b394570b72d 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -1086,7 +1086,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W var rendered = null; if (this.template) rendered = openerp.web.qweb.render(this.template, {widget: this}); - if (rendered) { + if (_.str.trim(rendered)) { var elem = $(rendered); this.$element.replaceWith(elem); this.$element = elem; -- cgit v1.2.3 From fa510462f4c49d434cd2ed4145eb8c3c99dae0e6 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 23 Feb 2012 17:10:41 +0100 Subject: [imp] switched to nivjs bzr revid: nicolas.vanhoren@openerp.com-20120223161041-mymbna11fsp3bo9m --- addons/web/static/src/js/core.js | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index fd0abcb0eb4..69ec98e7350 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -925,40 +925,6 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. } }); -openerp.web.ParentedMixin = { - __parented_mixin: true, - setParent: function(parent) { - if(this.getParent()) { - if (this.getParent().__parented_mixin) { - this.getParent().__parented_children = _.without(this.getParent().getChildren(), this); - } - this.__parented_parent = undefined; - } - this.__parented_parent = parent; - if(parent && parent.__parented_mixin) { - if (!parent.__parented_children) - parent.__parented_children = []; - parent.__parented_children.push(this); - } - }, - getParent: function() { - return this.__parented_parent; - }, - getChildren: function() { - return this.__parented_children ? _.clone(this.__parented_children) : []; - }, - isDestroyed: function() { - return this.__parented_destroyed; - }, - destroy: function() { - _.each(this.getChildren(), function(el) { - el.destroy(); - }); - this.setParent(undefined); - this.__parented_destroyed = true; - }, -}; - /** * Base class for all visual components. Provides a lot of functionalities helpful * for the management of a part of the DOM. @@ -1007,7 +973,7 @@ openerp.web.ParentedMixin = { * * That will kill the widget in a clean way and erase its content from the dom. */ -openerp.web.Widget = openerp.web.CallbackEnabled.extend(openerp.web.ParentedMixin).extend(/** @lends openerp.web.Widget# */{ +openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).extend(/** @lends openerp.web.Widget# */{ /** * The name of the QWeb template that will be used for rendering. Must be * redefined in subclasses or the default render() method can not be used. -- cgit v1.2.3 From a2b98743785dc4290e5b5adfac5892c2e0707fda Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 24 Feb 2012 14:26:39 +0100 Subject: [imp] adapted widget to new lib bzr revid: nicolas.vanhoren@openerp.com-20120224132639-um1aitu3bymnk7wo --- addons/web/static/src/js/core.js | 108 +++------------------------------------ 1 file changed, 7 insertions(+), 101 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 69ec98e7350..9a564c653bb 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -362,7 +362,7 @@ openerp.web.Registry = openerp.web.Class.extend( /** @lends openerp.web.Registry } }); -openerp.web.CallbackEnabled = openerp.web.Class.extend(/** @lends openerp.web.CallbackEnabled# */{ +openerp.web.CallbackEnabledMixin = { /** * @constructs openerp.web.CallbackEnabled * @extends openerp.web.Class @@ -404,7 +404,9 @@ openerp.web.CallbackEnabled = openerp.web.Class.extend(/** @lends openerp.web.Ca return self[method_name].apply(self, arguments); } } -}); +}; + +openerp.web.CallbackEnabled = openerp.web.Class.extend(_.extend({}, openerp.web.CallbackEnabledMixin)); openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.web.Connection# */{ /** @@ -973,7 +975,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. * * That will kill the widget in a clean way and erase its content from the dom. */ -openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).extend(/** @lends openerp.web.Widget# */{ +openerp.web.Widget = niv.Widget.extend(_.extend({}, openerp.web.CallbackEnabledMixin, { /** * The name of the QWeb template that will be used for rendering. Must be * redefined in subclasses or the default render() method can not be used. @@ -981,11 +983,6 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).exten * @type string */ template: null, - /** - * Tag name when creating a default $element. - * @type string - */ - tag_name: 'div', /** * Constructs the widget and sets its parent if a parent is given. * @@ -1001,88 +998,10 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).exten * for new components this argument should not be provided any more. */ init: function(parent) { + openerp.web.CallbackEnabledMixin.init.call(this); this._super(); this.session = openerp.connection; - - this.$element = $(document.createElement(this.tag_name)); - - this.setParent(parent); - }, - /** - * Destroys the current widget, also destroys all its children before destroying itself. - */ - destroy: function() { - _.each(this.getChildren(), function(el) { - el.destroy(); - }); - if(this.$element != null) { - this.$element.remove(); - } - this._super(); - }, - /** - * Renders the current widget and appends it to the given jQuery object or Widget. - * - * @param target A jQuery object or a Widget instance. - */ - appendTo: function(target) { - var self = this; - return this._render_and_insert(function(t) { - self.$element.appendTo(t); - }, target); - }, - /** - * Renders the current widget and prepends it to the given jQuery object or Widget. - * - * @param target A jQuery object or a Widget instance. - */ - prependTo: function(target) { - var self = this; - return this._render_and_insert(function(t) { - self.$element.prependTo(t); - }, target); }, - /** - * Renders the current widget and inserts it after to the given jQuery object or Widget. - * - * @param target A jQuery object or a Widget instance. - */ - insertAfter: function(target) { - var self = this; - return this._render_and_insert(function(t) { - self.$element.insertAfter(t); - }, target); - }, - /** - * Renders the current widget and inserts it before to the given jQuery object or Widget. - * - * @param target A jQuery object or a Widget instance. - */ - insertBefore: function(target) { - var self = this; - return this._render_and_insert(function(t) { - self.$element.insertBefore(t); - }, target); - }, - /** - * Renders the current widget and replaces the given jQuery object. - * - * @param target A jQuery object or a Widget instance. - */ - replace: function(target) { - return this._render_and_insert(_.bind(function(t) { - this.$element.replaceAll(t); - }, this), target); - }, - _render_and_insert: function(insertion, target) { - this.render_element(); - if (target instanceof openerp.web.Widget) - target = target.$element; - insertion(target); - this.on_inserted(this.$element, this); - return this.start(); - }, - on_inserted: function(element, widget) {}, /** * Renders the element. The default implementation renders the widget using QWeb, * `this.template` must be defined. The context given to QWeb contains the "widget" @@ -1098,18 +1017,6 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).exten this.$element = elem; } }, - /** - * Method called after rendering. Mostly used to bind actions, perform asynchronous - * calls, etc... - * - * By convention, the method should return a promise to inform the caller when - * this widget has been initialized. - * - * @returns {jQuery.Deferred} - */ - start: function() { - return $.Deferred().done().promise(); - }, /** * Informs the action manager to do an action. This supposes that * the action manager can be found amongst the ancestors of the current widget. @@ -1133,7 +1040,6 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).exten } return false; }, - rpc: function(url, data, success, error) { var def = $.Deferred().then(success, error); var self = this; @@ -1146,7 +1052,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).exten }); return def.promise(); } -}); +})); /** * @deprecated use :class:`openerp.web.Widget` -- cgit v1.2.3 From b6f93c8fa600b227ed6266e11c91fc7cecde36fa Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 24 Feb 2012 14:58:59 +0100 Subject: [fix] some bugs providing the web client to work bzr revid: nicolas.vanhoren@openerp.com-20120224135859-w937wgm51328dbk1 --- addons/web/static/src/js/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 9a564c653bb..7b88279cf16 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -999,7 +999,7 @@ openerp.web.Widget = niv.Widget.extend(_.extend({}, openerp.web.CallbackEnabledM */ init: function(parent) { openerp.web.CallbackEnabledMixin.init.call(this); - this._super(); + this._super(parent); this.session = openerp.connection; }, /** -- cgit v1.2.3 From 4ff154c30856f5ed80589015bf0552a3852f0a9f Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 24 Feb 2012 15:51:04 +0100 Subject: [imp] switched openerp's class to lib's class bzr revid: nicolas.vanhoren@openerp.com-20120224145104-iues3wzd4inwywpd --- addons/web/static/src/js/core.js | 104 +-------------------------------------- 1 file changed, 1 insertion(+), 103 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 7b88279cf16..93b9a237bf0 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -10,110 +10,8 @@ if (!console.debug) { } openerp.web.core = function(openerp) { -/** - * John Resig Class with factory improvement - */ -(function() { - var initializing = false, - fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; - // The web Class implementation (does nothing) - /** - * Extended version of John Resig's Class pattern - * - * @class - */ - openerp.web.Class = function(){}; - - /** - * Subclass an existing class - * - * @param {Object} prop class-level properties (class attributes and instance methods) to set on the new class - */ - openerp.web.Class.extend = function(prop) { - var _super = this.prototype; - - // Instantiate a web class (but only create the instance, - // don't run the init constructor) - initializing = true; - var prototype = new this(); - initializing = false; - - // Copy the properties over onto the new prototype - for (var name in prop) { - // Check if we're overwriting an existing function - prototype[name] = typeof prop[name] == "function" && - typeof _super[name] == "function" && - fnTest.test(prop[name]) ? - (function(name, fn) { - return function() { - var tmp = this._super; - - // Add a new ._super() method that is the same - // method but on the super-class - this._super = _super[name]; - - // The method only need to be bound temporarily, so - // we remove it when we're done executing - var ret = fn.apply(this, arguments); - this._super = tmp; - return ret; - }; - })(name, prop[name]) : - prop[name]; - } - - // The dummy class constructor - function Class() { - // All construction is actually done in the init method - if (!initializing && this.init) { - var ret = this.init.apply(this, arguments); - if (ret) { return ret; } - } - return this; - } - Class.include = function (properties) { - for (var name in properties) { - if (typeof properties[name] !== 'function' - || !fnTest.test(properties[name])) { - prototype[name] = properties[name]; - } else if (typeof prototype[name] === 'function' - && prototype.hasOwnProperty(name)) { - prototype[name] = (function (name, fn, previous) { - return function () { - var tmp = this._super; - this._super = previous; - var ret = fn.apply(this, arguments); - this._super = tmp; - return ret; - } - })(name, properties[name], prototype[name]); - } else if (typeof _super[name] === 'function') { - prototype[name] = (function (name, fn) { - return function () { - var tmp = this._super; - this._super = _super[name]; - var ret = fn.apply(this, arguments); - this._super = tmp; - return ret; - } - })(name, properties[name]); - } - } - }; - - // Populate our constructed prototype object - Class.prototype = prototype; - - // Enforce the constructor to be what we expect - Class.constructor = Class; - - // And make this class extendable - Class.extend = arguments.callee; - - return Class; - }; -})(); +openerp.web.Class = niv.Class; openerp.web.callback = function(obj, method) { var callback = function() { -- cgit v1.2.3 From 7969c1f08003382aa9c3102b79ad2b68da6c3301 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 24 Feb 2012 15:54:33 +0100 Subject: [fix] renammed bind to session_bind bzr revid: nicolas.vanhoren@openerp.com-20120224145433-c5bunu2fuciqj2uc --- addons/web/static/src/js/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 93b9a237bf0..da100c19241 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -322,7 +322,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. this.name = openerp._session_id; this.qweb_mutex = new $.Mutex(); }, - bind: function(origin) { + bind_session: function(origin) { var window_origin = location.protocol+"//"+location.host, self=this; this.origin = origin ? _.str.rtrim(origin,'/') : window_origin; this.prefix = this.origin; -- cgit v1.2.3 From 739f719ad6f26c007deb6b48134734588538bcbe Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 27 Feb 2012 08:37:21 +0100 Subject: [UP] py.parse 0.2 to py.js 0.4 ~ should probably go through a testing phase (checking its result against that of eval_domain_and_context) for a while, but apart from that it's supposed to work. 'stdlib' stuff (datetime.date.today, datetime.timedelta, time.localtime, time.time, time.strftime) still need to be written. Isn't there also a dateutil.relativedeleta somewhere? Anyway that needs to be done and the various evaluation contexts need to be defined, but the valuator itself should mostly work. bzr revid: xmo@openerp.com-20120227073721-nkgeiqacbzch8xev --- addons/web/static/src/js/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index f02efc07173..7c2a3876e42 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -1237,7 +1237,7 @@ openerp.web.TranslationDataBase = openerp.web.Class.extend(/** @lends openerp.we if (translation_bundle.lang_parameters) { this.parameters = translation_bundle.lang_parameters; this.parameters.grouping = py.eval( - this.parameters.grouping).toJSON(); + this.parameters.grouping); } }, add_module_translation: function(mod) { -- cgit v1.2.3 From f23a5914cab7ea8039f2b42bc5f279152ed5e31a Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 27 Feb 2012 10:34:13 +0100 Subject: [imp] cleaned initialization of mixins bzr revid: nicolas.vanhoren@openerp.com-20120227093413-8qp1vo90500h9lrw --- addons/web/static/src/js/core.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index da100c19241..e4d426ac4a0 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -261,10 +261,6 @@ openerp.web.Registry = openerp.web.Class.extend( /** @lends openerp.web.Registry }); openerp.web.CallbackEnabledMixin = { - /** - * @constructs openerp.web.CallbackEnabled - * @extends openerp.web.Class - */ init: function() { // Transform on_* method into openerp.web.callbacks for (var name in this) { @@ -304,7 +300,12 @@ openerp.web.CallbackEnabledMixin = { } }; -openerp.web.CallbackEnabled = openerp.web.Class.extend(_.extend({}, openerp.web.CallbackEnabledMixin)); +openerp.web.CallbackEnabled = openerp.web.Class.extend(_.extend({}, niv.GetterSetterMixin, openerp.web.CallbackEnabledMixin, { + init: function() { + niv.GetterSetterMixin.init.call(this); + openerp.web.CallbackEnabledMixin.init.call(this); + } +})); openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.web.Connection# */{ /** -- cgit v1.2.3 From 080c9ed7fd7e782a3d2ae41747f0a80204ce2d5e Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 27 Feb 2012 11:37:15 +0100 Subject: [imp] renammed niv to nova bzr revid: nicolas.vanhoren@openerp.com-20120227103715-ez6m5bth0spbuupk --- addons/web/static/src/js/core.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index e4d426ac4a0..bdc8059ff63 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -11,7 +11,7 @@ if (!console.debug) { openerp.web.core = function(openerp) { -openerp.web.Class = niv.Class; +openerp.web.Class = nova.Class; openerp.web.callback = function(obj, method) { var callback = function() { @@ -300,9 +300,9 @@ openerp.web.CallbackEnabledMixin = { } }; -openerp.web.CallbackEnabled = openerp.web.Class.extend(_.extend({}, niv.GetterSetterMixin, openerp.web.CallbackEnabledMixin, { +openerp.web.CallbackEnabled = openerp.web.Class.extend(_.extend({}, nova.GetterSetterMixin, openerp.web.CallbackEnabledMixin, { init: function() { - niv.GetterSetterMixin.init.call(this); + nova.GetterSetterMixin.init.call(this); openerp.web.CallbackEnabledMixin.init.call(this); } })); @@ -874,7 +874,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. * * That will kill the widget in a clean way and erase its content from the dom. */ -openerp.web.Widget = niv.Widget.extend(_.extend({}, openerp.web.CallbackEnabledMixin, { +openerp.web.Widget = nova.Widget.extend(_.extend({}, openerp.web.CallbackEnabledMixin, { /** * The name of the QWeb template that will be used for rendering. Must be * redefined in subclasses or the default render() method can not be used. @@ -897,8 +897,8 @@ openerp.web.Widget = niv.Widget.extend(_.extend({}, openerp.web.CallbackEnabledM * for new components this argument should not be provided any more. */ init: function(parent) { - openerp.web.CallbackEnabledMixin.init.call(this); this._super(parent); + openerp.web.CallbackEnabledMixin.init.call(this); this.session = openerp.connection; }, /** -- cgit v1.2.3 From aca64bb558ebe2b617620eb62678107dccce971a Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 27 Feb 2012 13:49:58 +0100 Subject: [imp] removed useless function bzr revid: nicolas.vanhoren@openerp.com-20120227124958-ehlps91290hrwo9o --- addons/web/static/src/js/core.js | 25 ------------------------- 1 file changed, 25 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index bdc8059ff63..6ff8f86dcc3 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -72,31 +72,6 @@ openerp.web.callback = function(obj, method) { }); }; -/** - * Generates an inherited class that replaces all the methods by null methods (methods - * that does nothing and always return undefined). - * - * @param {Class} claz - * @param {Object} add Additional functions to override. - * @return {Class} - */ -openerp.web.generate_null_object_class = function(claz, add) { - var newer = {}; - var copy_proto = function(prototype) { - for (var name in prototype) { - if(typeof prototype[name] == "function") { - newer[name] = function() {}; - } - } - if (prototype.prototype) - copy_proto(prototype.prototype); - }; - copy_proto(claz.prototype); - newer.init = openerp.web.Widget.prototype.init; - var tmpclass = claz.extend(newer); - return tmpclass.extend(add || {}); -}; - /** * web error for lookup failure * -- cgit v1.2.3 From 2da29835334266a278e030411d1a3539fc7d11e2 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 29 Feb 2012 12:04:28 +0100 Subject: [imp] renammed tag_name bzr revid: nicolas.vanhoren@openerp.com-20120229110428-es0fof2fxxa5qzd5 --- addons/web/static/src/js/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 93e2b06c1f6..bbfac551c5d 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -937,7 +937,7 @@ openerp.web.OldWidget = openerp.web.Widget.extend({ this.element_id = element_id; this.element_id = this.element_id || _.uniqueId('widget-'); var tmp = document.getElementById(this.element_id); - this.$element = tmp ? $(tmp) : $(document.createElement(this.tag_name)); + this.$element = tmp ? $(tmp) : $(document.createElement(this.tagName)); }, render_element: function() { var rendered = this.render(); -- cgit v1.2.3 From 7eb12aee74633e4f240b0373eae476788c14ecba Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 29 Feb 2012 12:07:44 +0100 Subject: [imp] renammed render_element bzr revid: nicolas.vanhoren@openerp.com-20120229110744-0m55gqlme6s225jv --- addons/web/static/src/js/core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index bbfac551c5d..fe2ca1beb4f 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -881,7 +881,7 @@ openerp.web.Widget = nova.Widget.extend(_.extend({}, openerp.web.CallbackEnabled * `this.template` must be defined. The context given to QWeb contains the "widget" * key that references `this`. */ - render_element: function() { + renderElement: function() { var rendered = null; if (this.template) rendered = openerp.web.qweb.render(this.template, {widget: this}); @@ -939,7 +939,7 @@ openerp.web.OldWidget = openerp.web.Widget.extend({ var tmp = document.getElementById(this.element_id); this.$element = tmp ? $(tmp) : $(document.createElement(this.tagName)); }, - render_element: function() { + renderElement: function() { var rendered = this.render(); if (rendered) { var elem = $(rendered); -- cgit v1.2.3 From 7e5feece185205a187d57539d97d5b0279cf4c68 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 1 Mar 2012 14:00:08 +0100 Subject: [ADD] eval tests for eval_domain_and_context bzr revid: xmo@openerp.com-20120301130008-dijd6r49js1227by --- addons/web/static/src/js/core.js | 105 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index fe2ca1beb4f..679b193e121 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -321,6 +321,108 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. this.active_id = null; return this.session_init(); }, + test_eval: function (source, expected) { + try { + var ctx = this.test_eval_contexts(source.contexts); + if (!_.isEqual(ctx, expected.context)) { + console.group('Local context does not match remote'); + console.warn('source', source.contexts); + console.warn('local', ctx); + console.warn('remote', expected.context); + console.groupEnd(); + } + } catch (e) { + console.error( + 'Failed to evaluate contexts', source.contexts, ':', e); + } + + try { + var dom = this.test_eval_domains(source.domains); + if (!_.isEqual(dom, expected.domain)) { + console.group('Local domain does not match remote'); + console.warn('source', source.domains); + console.warn('local', dom); + console.warn('remote', expected.domain); + console.groupEnd(); + } + } catch (e) { + console.error( + 'Failed to evaluate domains', source.domains, ':', e); + } + + try { + var groups = this.test_eval_groupby(source.group_by_seq); + if (!_.isEqual(groups, expected.group_by)) { + console.group('Local groupby does not match remote'); + console.warn('source', source.group_by_seq); + console.warn('local', groups); + console.warn('remote', expected.group_by); + console.groupEnd(); + } + } catch (e) {} + }, + test_eval_contexts: function (contexts) { + var result_context = _.extend({}, this.user_context), + self = this; + _(contexts).each(function (ctx) { + switch(ctx.__ref) { + case 'context': + _.extend(py.eval(ctx.__debug)); + break; + case 'compound_context': + _.extend(self.test_eval_contexts(ctx.__contexts)); + break; + default: + _.extend(result_context, ctx); + } + }); + return result_context; + }, + test_eval_domains: function (domains) { + var result_domain = [], self = this; + _(domains).each(function (dom) { + switch(dom.__ref) { + case 'domain': + result_domain.push.apply( + result_domain, py.eval(dom.__debug)); + break; + case 'compound_domain': + result_domain.push.apply( + result_domain, self.test_eval_contexts(dom.__contexts)); + break; + default: + result_domain.push.apply( + result_domain, dom); + } + }); + return result_domain; + }, + test_eval_groupby: function (contexts) { + var result_group = [], self = this; + _(contexts).each(function (ctx) { + var group; + switch(ctx.__ref) { + case 'context': + group = py.eval(ctx.__debug).group_by; + break; + case 'compound_context': + group = self.test_eval_contexts(ctx.__contexts).group_by; + break; + default: + group = ctx.group_by + } + if (!group) { return; } + if (typeof group === 'string') { + result_group.push(group); + } else if (group instanceof Array) { + result_group.push.apply(result_group, group); + } else { + throw new Error('Got invalid groupby {{' + + JSON.stringify(group) + '}}'); + } + }); + return result_group; + }, /** * Executes an RPC call, registering the provided callbacks. * @@ -358,6 +460,9 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. function (response, textStatus, jqXHR) { self.on_rpc_response(); if (!response.error) { + if (url.url === '/web/session/eval_domain_and_context') { + self.test_eval(params, response.result); + } deferred.resolve(response["result"], textStatus, jqXHR); } else if (response.error.data.type === "session_invalid") { self.uid = false; -- cgit v1.2.3 From 12358af73bc0df054881258d690c91536e92b368 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 1 Mar 2012 14:59:00 +0100 Subject: [IMP] add basic evaluation context to asserter (for domains, so time and datetime are available). Doesn't really work because kwargs not supported by py.js (see bug #3), so Sales > Reporting > Opportunities analysis does not work Also current implementation of datetime and time.strftime very incomplete bzr revid: xmo@openerp.com-20120301135900-w4aucd5boi9yzmod --- addons/web/static/src/js/core.js | 50 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 679b193e121..ca53bce9c59 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -321,6 +321,47 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. this.active_id = null; return this.session_init(); }, + test_eval_get_context: function () { + var datetime = new py.object(); + var date = datetime.date = new py.type(function date(y, m, d) { + this._year = y; + this._month = m; + this._day = d; + }, py.object, { + strftime: function (format) { + var f = format.toJSON(), self = this; + return new py.str(f.replace(/%([A-Za-z])/g, function (m, c) { + switch (c) { + case 'Y': return self._year; + case 'm': return _.str.sprintf('%02d', self._month); + case 'd': return _.str.sprintf('%02d', self._day); + } + throw new Error('ValueError: No known conversion for ' + m); + })); + } + }); + date.__getattribute__ = function (name) { + if (name === 'today') { + return date.today; + } + throw new Error("AttributeError: object 'date' has no attribute '" + name +"'"); + }; + date.today = new py.def(function () { + var d = new Date(); + return new date(d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate()); + }); + + var time = new py.object(); + time.strftime = new py.def(function (format) { + return date.today.__call__().strftime(format); + }); + + return { + uid: new py.float(this.uid), + datetime: datetime, + time: time + }; + }, test_eval: function (source, expected) { try { var ctx = this.test_eval_contexts(source.contexts); @@ -337,7 +378,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. } try { - var dom = this.test_eval_domains(source.domains); + var dom = this.test_eval_domains(source.domains, this.test_eval_get_context()); if (!_.isEqual(dom, expected.domain)) { console.group('Local domain does not match remote'); console.warn('source', source.domains); @@ -378,17 +419,18 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. }); return result_context; }, - test_eval_domains: function (domains) { + test_eval_domains: function (domains, eval_context) { var result_domain = [], self = this; _(domains).each(function (dom) { switch(dom.__ref) { case 'domain': result_domain.push.apply( - result_domain, py.eval(dom.__debug)); + result_domain, py.eval(dom.__debug, eval_context)); break; case 'compound_domain': result_domain.push.apply( - result_domain, self.test_eval_contexts(dom.__contexts)); + result_domain, self.test_eval_domains( + dom.__domains, eval_context)); break; default: result_domain.push.apply( -- cgit v1.2.3 From f8a93bc2848eba516213142f4f730a1feda5a39e Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 5 Mar 2012 09:55:32 +0100 Subject: [FIX] update py.js for operators &al, implement basic crummy version of relativedelta bzr revid: xmo@openerp.com-20120305085532-0vcz6j0m985gjuz1 --- addons/web/static/src/js/core.js | 128 +++++++++++++++++++++++++++++++++++---- 1 file changed, 117 insertions(+), 11 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index ca53bce9c59..ead33822926 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -322,19 +322,34 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. return this.session_init(); }, test_eval_get_context: function () { + var asJS = function (arg) { + if (arg instanceof py.object) { + return arg.toJSON(); + } + return arg; + }; + var datetime = new py.object(); + datetime.datetime = new py.type(function datetime() { + throw new Error('datetime.datetime not implemented'); + }); var date = datetime.date = new py.type(function date(y, m, d) { - this._year = y; - this._month = m; - this._day = d; + if (y instanceof Array) { + d = y[2]; + m = y[1]; + y = y[0]; + } + this.year = asJS(y); + this.month = asJS(m); + this.day = asJS(d); }, py.object, { - strftime: function (format) { - var f = format.toJSON(), self = this; + strftime: function (args) { + var f = asJS(args[0]), self = this; return new py.str(f.replace(/%([A-Za-z])/g, function (m, c) { switch (c) { - case 'Y': return self._year; - case 'm': return _.str.sprintf('%02d', self._month); - case 'd': return _.str.sprintf('%02d', self._day); + case 'Y': return self.year; + case 'm': return _.str.sprintf('%02d', self.month); + case 'd': return _.str.sprintf('%02d', self.day); } throw new Error('ValueError: No known conversion for ' + m); })); @@ -350,16 +365,107 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. var d = new Date(); return new date(d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate()); }); + datetime.time = new py.type(function time() { + throw new Error('datetime.time not implemented'); + }); var time = new py.object(); - time.strftime = new py.def(function (format) { - return date.today.__call__().strftime(format); + time.strftime = new py.def(function (args) { + return date.today.__call__().strftime(args); + }); + + var relativedelta = new py.type(function relativedelta(args, kwargs) { + if (!_.isEmpty(args)) { + throw new Error('Extraction of relative deltas from existing datetimes not supported'); + } + this.ops = kwargs; + }, py.object, { + __add__: function (other) { + if (!(other instanceof datetime.date)) { + return py.NotImplemented; + } + // TODO: test this whole mess + var year = asJS(this.ops.year) || asJS(other.year); + if (asJS(this.ops.years)) { + year += asJS(this.ops.years); + } + + var month = asJS(this.ops.month) || asJS(other.month); + if (asJS(this.ops.months)) { + month += asJS(this.ops.months); + // FIXME: no divmod in JS? + while (month < 1) { + year -= 1; + month += 12; + } + while (month > 12) { + year += 1; + month -= 12; + } + } + + var lastMonthDay = new Date(year, month, 0).getDate(); + var day = asJS(this.ops.day) || asJS(other.day); + if (day > lastMonthDay) { day = lastMonthDay; } + var days_offset = ((asJS(this.ops.weeks) || 0) * 7) + (asJS(this.ops.days) || 0); + if (days_offset) { + day = new Date(year, month-1, day + days_offset).getDate(); + } + // TODO: leapdays? + // TODO: hours, minutes, seconds? Not used in XML domains + // TODO: weekday? + return new datetime.date(year, month, day); + }, + __radd__: function (other) { + return this.__add__(other); + }, + + __sub__: function (other) { + if (!(other instanceof datetime.date)) { + return py.NotImplemented; + } + // TODO: test this whole mess + var year = asJS(this.ops.year) || asJS(other.year); + if (asJS(this.ops.years)) { + year -= asJS(this.ops.years); + } + + var month = asJS(this.ops.month) || asJS(other.month); + if (asJS(this.ops.months)) { + month -= asJS(this.ops.months); + // FIXME: no divmod in JS? + while (month < 1) { + year -= 1; + month += 12; + } + while (month > 12) { + year += 1; + month -= 12; + } + } + + var lastMonthDay = new Date(year, month, 0).getDate(); + var day = asJS(this.ops.day) || asJS(other.day); + if (day > lastMonthDay) { day = lastMonthDay; } + var days_offset = ((asJS(this.ops.weeks) || 0) * 7) + (asJS(this.ops.days) || 0); + if (days_offset) { + day = new Date(year, month-1, day - days_offset).getDate(); + } + // TODO: leapdays? + // TODO: hours, minutes, seconds? Not used in XML domains + // TODO: weekday? + return new datetime.date(year, month, day); + }, + __rsub__: function (other) { + return this.__sub__(other); + } }); return { uid: new py.float(this.uid), datetime: datetime, - time: time + time: time, + relativedelta: relativedelta }; }, test_eval: function (source, expected) { -- cgit v1.2.3 From 98341230a78fe9798b55d3a4173b17a00d8d9a0f Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 7 Mar 2012 08:46:41 +0100 Subject: [FIX] context evaluation: accumulation of literal and compound context data into evaluated context bzr revid: xmo@openerp.com-20120307074641-pm5wl9t3cb4l9s64 --- addons/web/static/src/js/core.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 6e44394c8a2..6f9773a676e 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -514,10 +514,11 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. _(contexts).each(function (ctx) { switch(ctx.__ref) { case 'context': - _.extend(py.eval(ctx.__debug)); + _.extend(result_context, py.eval(ctx.__debug)); break; case 'compound_context': - _.extend(self.test_eval_contexts(ctx.__contexts)); + _.extend( + result_context, self.test_eval_contexts(ctx.__contexts)); break; default: _.extend(result_context, ctx); -- cgit v1.2.3 From 80ebf90a7c411342cc280cb2824f117fad15bb55 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 7 Mar 2012 10:57:32 +0100 Subject: [IMP] debug messages of test evaluator bzr revid: xmo@openerp.com-20120307095732-ckfuowa43i7dkapg --- addons/web/static/src/js/core.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 6f9773a676e..f464bded13b 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -468,45 +468,57 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. relativedelta: relativedelta }; }, + /** + * FIXME: Huge testing hack, especially the evaluation context, rewrite + test for real before switching + */ test_eval: function (source, expected) { try { var ctx = this.test_eval_contexts(source.contexts); if (!_.isEqual(ctx, expected.context)) { - console.group('Local context does not match remote'); + console.group('Local context does not match remote, nothing is broken but please report to R&D (xmo)'); console.warn('source', source.contexts); console.warn('local', ctx); console.warn('remote', expected.context); console.groupEnd(); } } catch (e) { - console.error( - 'Failed to evaluate contexts', source.contexts, ':', e); + console.group('Failed to evaluate contexts, nothing is broken but please report to R&D (xmo)'); + console.error(e); + console.log('source', source.contexts); + console.groupEnd(); } try { var dom = this.test_eval_domains(source.domains, this.test_eval_get_context()); if (!_.isEqual(dom, expected.domain)) { - console.group('Local domain does not match remote'); + console.group('Local domain does not match remote, nothing is broken but please report to R&D (xmo)'); console.warn('source', source.domains); console.warn('local', dom); console.warn('remote', expected.domain); console.groupEnd(); } } catch (e) { - console.error( - 'Failed to evaluate domains', source.domains, ':', e); + console.group('Failed to evaluate domains, nothing is broken but please report to R&D (xmo)'); + console.error(e); + console.log('source', source.domains); + console.groupEnd(); } try { var groups = this.test_eval_groupby(source.group_by_seq); if (!_.isEqual(groups, expected.group_by)) { - console.group('Local groupby does not match remote'); + console.group('Local groupby does not match remote, nothing is broken but please report to R&D (xmo)'); console.warn('source', source.group_by_seq); console.warn('local', groups); console.warn('remote', expected.group_by); console.groupEnd(); } - } catch (e) {} + } catch (e) { + console.group('Failed to evaluate groupby, nothing is broken but please report to R&D (xmo)'); + console.error(e); + console.log('source', source.group_by_seq); + console.groupEnd(); + } }, test_eval_contexts: function (contexts) { var result_context = _.extend({}, this.user_context), -- cgit v1.2.3 From 66e1ce8606643eb0490584356f2d7b60cfffd3e6 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 8 Mar 2012 11:21:51 +0100 Subject: [FIX] Missing date.js CultureInfo's am/pm descriptor causes wrong dates to be sent to server without user's knowledge lp bug: https://launchpad.net/bugs/938497 fixed bzr revid: fme@openerp.com-20120308102151-eyr71rzk345f6xji --- addons/web/static/src/js/core.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 106d2b86dc9..49840e5aba8 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -744,6 +744,14 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. var file_list = ["/web/static/lib/datejs/globalization/" + lang.replace("_", "-") + ".js"]; return self.rpc('/web/webclient/jslist', {mods: to_load}).pipe(function(files) { return self.do_load_js(file_list.concat(files)); + }).then(function () { + if (!Date.CultureInfo.pmDesignator) { + // If no am/pm designator is specified but the openerp + // datetime format uses %i, date.js won't be able to + // correctly format a date. See bug#938497. + Date.CultureInfo.amDesignator = 'AM'; + Date.CultureInfo.pmDesignator = 'PM'; + } }); })) } -- cgit v1.2.3 From 89061adc7d8b6af9632cda42ea96dbabad050807 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 13 Mar 2012 16:37:07 +0100 Subject: [imp] possible problem with debug & qweb bzr revid: nicolas.vanhoren@openerp.com-20120313153707-zi6kdlbxz72dit7l --- addons/web/static/src/js/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index f464bded13b..a962d205c1c 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -1300,7 +1300,7 @@ openerp.web._lt = function (s) { return {toString: function () { return openerp.web._t(s); }} }; openerp.web.qweb = new QWeb2.Engine(); -openerp.web.qweb.debug = (window.location.search.indexOf('?debug') !== -1); +openerp.web.qweb.debug = ($.deparam($.param.querystring()).debug != undefined); openerp.web.qweb.default_dict = { '_' : _, '_t' : openerp.web._t -- cgit v1.2.3 From 4e7796cfeea94e3225fed1c9b99f4f25afe6cd6a Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 13 Mar 2012 17:37:19 +0100 Subject: [imp] added some stuff to manage interfaces bzr revid: nicolas.vanhoren@openerp.com-20120313163719-ez4n7ca4qxus0m9t --- addons/web/static/src/js/core.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'addons/web/static/src/js/core.js') diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index a962d205c1c..650939c843c 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -1335,6 +1335,23 @@ openerp.web.qweb.preprocess_node = function() { } }; +/** + * A small utility function to check if a class implements correctly an interface, assuming that + * interface is simply specified using a dictionary containing methods and attributes with the + * correct type. It only performs the check when in debug mode and the only effect of an invalid + * check is messages in the console. + */ +openerp.web.check_interface = function(_class, _interface) { + if (! openerp.web.check_interface.debug) + return; + for (var member in _interface) { + if ( (typeof _class.prototype[member] != typeof _interface[member]) ) { + console.error("class failed to implement interface member '" + member + "'"); + } + } +} +openerp.web.check_interface.debug = ($.deparam($.param.querystring()).debug != undefined); + /** Jquery extentions */ $.Mutex = (function() { function Mutex() { -- cgit v1.2.3