From 37206e0078419dfec5c02f20d23677920acaed8a Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 5 Apr 2011 19:35:12 +0200 Subject: [PATCH] [ADD] Changed notification. Added notification on form invalid. bzr revid: fme@openerp.com-20110405173512-82k1uonpvrdflz4a --- addons/base/static/src/css/base.css | 3 +++ addons/base/static/src/js/chrome.js | 12 +++++++--- addons/base/static/src/js/form.js | 36 +++++++++++++++++++---------- addons/base/static/src/xml/base.xml | 6 +++++ 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/addons/base/static/src/css/base.css b/addons/base/static/src/css/base.css index 075150f6ca6..f3b83e66ae0 100644 --- a/addons/base/static/src/css/base.css +++ b/addons/base/static/src/css/base.css @@ -54,6 +54,9 @@ body.openerp { z-index: 1001; display: none; } +.openerp .oe_notification * { + color: white; +} /* Login */ .openerp .login { diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js index 439d34e4ad2..fd28a92a30a 100644 --- a/addons/base/static/src/js/chrome.js +++ b/addons/base/static/src/js/chrome.js @@ -503,8 +503,14 @@ openerp.base.Notification = openerp.base.Controller.extend({ speed: 500 }); }, - add: function(title, text) { - this.$element.notify("create", { + default: function(title, text) { + this.$element.notify('create', { + title: title, + text: text + }); + }, + alert: function(title, text) { + this.$element.notify('create', 'oe_notification_alert', { title: title, text: text }); @@ -690,7 +696,7 @@ openerp.base.WebClient = openerp.base.Controller.extend({ this.header.start(); this.login.start(); this.menu.start(); - this.notification.add("OpenERP Client", "The openerp client has been initialized."); + this.notification.default("OpenERP Client", "The openerp client has been initialized."); }, on_logged: function() { this.action = new openerp.base.ActionManager(this.session, "oe_app"); diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index 9c2c7004c1e..1b6fcb15328 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -145,14 +145,21 @@ openerp.base.FormView = openerp.base.Controller.extend( /** @lends openerp.base switch_editable: function() { }, on_invalid: function() { - console.info("Form invalid"); + var msg = ""; + this.notification.alert("The following fields are invalid :", msg); }, on_saved: function(r) { if (!r.result) { this.log("Record was not saved"); } else { // Check response for exceptions, display error - this.notification.add("Record saved", "The record #" + this.datarecord.id + " has been saved."); + this.notification.default("Record saved", "The record #" + this.datarecord.id + " has been saved."); } }, do_search: function (domains, contexts, groupbys) { @@ -413,7 +420,6 @@ openerp.base.form.Field = openerp.base.form.Widget.extend({ this.$element.toggleClass('invalid', this.invalid); }, on_ui_change: function() { - this.view.on_form_changed(this); this.touched = true; } }); @@ -437,9 +443,10 @@ openerp.base.form.FieldChar = openerp.base.form.Field.extend({ this.$element.find('input').attr('disabled', this.readonly); }, on_ui_change: function() { + this._super.apply(this, arguments); this.value = this.$element.find('input').val(); this.invalid = this.required && this.value == ""; - this._super.apply(this, arguments); + this.view.on_form_changed(this); } }); @@ -456,9 +463,10 @@ openerp.base.form.FieldFloat = openerp.base.form.FieldChar.extend({ this.$element.find('input').val(value); }, on_ui_change: function() { - this.value = parseFloat(this.$element.find('input').val()); // TODO: do it well - this.invalid = this.required && this.value == ""; this._super.apply(this, arguments); + this.value = this.$element.find('input').val().replace(/,/g, '.'); + this.invalid = (this.required && this.value == "") || !this.value.match(/^\d(\.\d)?$/) ; + this.view.on_form_changed(this); } }); @@ -479,9 +487,10 @@ openerp.base.form.FieldDate = openerp.base.form.FieldChar.extend({ this.$element.find('input').val(show_value); }, on_ui_change: function() { + this._super.apply(this, arguments); this.value = this.$element.find('input').val(); this.invalid = this.required && this.value == ""; - this._super.apply(this, arguments); + this.view.on_form_changed(this); } }); @@ -503,9 +512,10 @@ openerp.base.form.FieldDatetime = openerp.base.form.FieldChar.extend({ this.$element.find('input').val(show_value); }, on_ui_change: function() { + this._super.apply(this, arguments); this.value = this.$element.find('input').val(); this.invalid = this.required && this.value == ""; - this._super.apply(this, arguments); + this.view.on_form_changed(this); } }); @@ -528,9 +538,10 @@ openerp.base.form.FieldText = openerp.base.form.Field.extend({ this.$element.find('textarea').attr('disabled', this.readonly); }, on_ui_change: function() { + this._super.apply(this, arguments); this.value = this.$element.find('textarea').val(); this.invalid = this.required && this.value == ""; - this._super.apply(this, arguments); + this.view.on_form_changed(this); } }); @@ -557,9 +568,10 @@ openerp.base.form.FieldBoolean = openerp.base.form.Field.extend({ this.$element.find('textarea').attr('disabled', this.readonly); }, on_ui_change: function() { + this._super.apply(this, arguments); this.value = this.$element.find('input').is(':checked'); this.invalid = this.required && !this.value; - this._super.apply(this, arguments); + this.view.on_form_changed(this); } }); @@ -589,9 +601,10 @@ openerp.base.form.FieldSelection = openerp.base.form.Field.extend({ this.$element.find('select').attr('disabled', this.readonly); }, on_ui_change: function() { + this._super.apply(this, arguments); this.value = this.$element.find('select').val(); this.invalid = this.required && this.value == ""; - this._super.apply(this, arguments); + this.view.on_form_changed(this); } }); @@ -646,7 +659,6 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({ this.$element.toggleClass('required', this.required); }, on_ui_change: function() { - this.view.on_form_changed(this); } }); diff --git a/addons/base/static/src/xml/base.xml b/addons/base/static/src/xml/base.xml index b26c481327a..47913f8cb55 100644 --- a/addons/base/static/src/xml/base.xml +++ b/addons/base/static/src/xml/base.xml @@ -10,6 +10,12 @@

#{title}

#{text}

+
+ x + +

#{title}

+

#{text}

+