From 7d514372c0f899707cfaff66addf06103c527edd Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 24 Sep 2012 18:30:21 +0200 Subject: [PATCH 1/4] [IMP] added field_changed mechanism bzr revid: nicolas.vanhoren@openerp.com-20120924163021-ktfmi27q48o9moa8 --- addons/web/static/src/js/view_form.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index dff9df11140..f62b186f662 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -16,6 +16,14 @@ instance.web.form = {}; * Events: * - view_content_has_changed : when the values of the fields have changed. When * this event is triggered all fields should reprocess their modifiers. + * - field_changed: : when the value of a field change, an event is triggered + * named "field_changed:" with replaced by the name of the field. + * This event is not related to the on_change mechanism of OpenERP and is always called + * when the value of a field is setted or changed. This event is only triggered when the + * value of the field is syntactically valid, but it can be triggered when the value + * is sematically invalid (ie, when a required field is false). It is possible that an event + * about a precise field is never triggered even if that field exists in the view, in that + * case the value of the field is assumed to be false. */ instance.web.form.FieldManagerMixin = { /** @@ -26,6 +34,11 @@ instance.web.form.FieldManagerMixin = { * Returns true when the view is in create mode. */ is_create_mode: function() {}, + /** + * Returns the current value of a field present in the view. See the get_value() method + * method in FieldInterface for further information. + */ + get_field_value: function(field_name) {}, }; instance.web.views.add('form', 'instance.web.FormView'); @@ -1056,6 +1069,9 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM this.translatable_fields.push(field); } field.on('changed_value', this, function() { + if (field.is_syntax_valid()) { + this.trigger('field_changed:' + name); + } if (field._inhibit_on_change_flag) { return; } @@ -1073,6 +1089,9 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM is_create_mode: function() { return this.get("actual_mode") === "create"; }, + get_field_value: function(field_name) { + return this.fields[field_name].get_value(); + }, }); /** @@ -1843,7 +1862,8 @@ instance.web.form.WidgetButton = instance.web.form.FormWidget.extend({ * - force_readonly: boolean, When it is true, the field should always appear * in read only mode, no matter what the value of the "readonly" property can be. * Events: - * - changed_value: triggered to inform the view to check on_changes + * - changed_value: triggered when the value of the field has changed. This can be due + * to a user interaction or a call to set_value(). * */ instance.web.form.FieldInterface = { @@ -3378,7 +3398,7 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({ }, this)); }, is_syntax_valid: function() { - if (!this.viewmanager.views[this.viewmanager.active_view]) + if (! this.viewmanager || ! this.viewmanager.views[this.viewmanager.active_view]) return true; var view = this.viewmanager.views[this.viewmanager.active_view].controller; switch (this.viewmanager.active_view) { From 5cb418da8e4f8494f57c7135f61db47cf98988f1 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 25 Sep 2012 14:01:49 +0200 Subject: [PATCH 2/4] [IMP] web: in instance.web.Login.start(), login automatically only when params db, login and password are all present bzr revid: rco@openerp.com-20120925120149-w5nojo2175eiximz --- addons/web/static/src/js/chrome.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 9fdfb50307f..b4ba5404a49 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -532,7 +532,9 @@ instance.web.Login = instance.web.Widget.extend({ }); var d; if (self.params.db) { - d = self.do_login(self.params.db, self.params.login, self.params.password); + if (self.params.login && self.params.password) { + d = self.do_login(self.params.db, self.params.login, self.params.password); + } } else { d = self.rpc("/web/database/get_list", {}).done(self.on_db_loaded).fail(self.on_db_failed); } From 8a7ccd3c760496e35460e514231467c41b92dde8 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 25 Sep 2012 16:15:58 +0200 Subject: [PATCH 3/4] [ADD] Add 'window' in QWeb reserved words bzr revid: fme@openerp.com-20120925141558-zlj6f328oya3z5oy --- addons/web/static/lib/qweb/qweb2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web/static/lib/qweb/qweb2.js b/addons/web/static/lib/qweb/qweb2.js index c9b065ee69f..71a9628eff2 100644 --- a/addons/web/static/lib/qweb/qweb2.js +++ b/addons/web/static/lib/qweb/qweb2.js @@ -4,7 +4,7 @@ // TODO: t-set + t-value + children node == scoped variable ? var QWeb2 = { expressions_cache: {}, - RESERVED_WORDS: 'true,false,NaN,null,undefined,debugger,console,in,instanceof,new,function,return,this,typeof,eval,void,Math,RegExp,Array,Object,Date'.split(','), + RESERVED_WORDS: 'true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,this,typeof,eval,void,Math,RegExp,Array,Object,Date'.split(','), ACTIONS_PRECEDENCE: 'foreach,if,call,set,esc,escf,raw,rawf,js,debug,log'.split(','), WORD_REPLACEMENT: { 'and': '&&', From 42ee1b52b1d83d99a1fdff6dc0bea777afbaf6cb Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 25 Sep 2012 18:01:06 +0200 Subject: [PATCH 4/4] [IMP] web_linkedin: ported to new form view API bzr revid: nicolas.vanhoren@openerp.com-20120925160106-8fl1fxqrbxgl8lbk --- addons/web_linkedin/static/src/js/linkedin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web_linkedin/static/src/js/linkedin.js b/addons/web_linkedin/static/src/js/linkedin.js index 3cdfbfff410..863e51e913f 100644 --- a/addons/web_linkedin/static/src/js/linkedin.js +++ b/addons/web_linkedin/static/src/js/linkedin.js @@ -88,7 +88,7 @@ openerp.web_linkedin = function(instance) { selected_entity: function(entity) { var self = this; this.create_on_change(entity).then(function(to_change) { - self.view.on_processed_onchange({value:to_change}); + self.view.set_values(to_change); }); }, create_on_change: function(entity) {