diff --git a/src/screen.js b/src/screen.js index 9c0f21775e..ddfd0b33ea 100644 --- a/src/screen.js +++ b/src/screen.js @@ -776,6 +776,7 @@ } else { this.tab.attachment_count(0); } + this.tab.record_message(); } }, display: function() { diff --git a/src/tab.js b/src/tab.js index 0bb0347acd..02398a8bab 100644 --- a/src/tab.js +++ b/src/tab.js @@ -16,6 +16,9 @@ }); this.title = jQuery('
').appendTo(this.el); + + this.el.append(this.info_bar.el); + this.create_toolbar().appendTo(this.el); }, set_menu: function(menu) { @@ -221,6 +224,7 @@ this.menu_def[10][2] = null; } + this.info_bar = new Sao.Window.InfoBar(); this.create_tabcontent(); var access = Sao.common.MODELACCESS.get(model_name); @@ -429,8 +433,9 @@ return; } this.modified_save().done(function() { - this.screen.new_(); - // TODO message + this.screen.new_().then(function() { + this.info_bar.message(); + }.bind(this)); // TODO activate_save }.bind(this)); }, @@ -438,8 +443,15 @@ if (!Sao.common.MODELACCESS.get(this.screen.model_name).write) { return jQuery.when(); } - // TODO message - return this.screen.save_current(); + return this.screen.save_current().then( + function() { + this.info_bar.message( + Sao.i18n.gettext('Record saved.'), 'info'); + }.bind(this), + function() { + this.info_bar.message( + Sao.i18n.gettext('Invalid form.'), 'danger'); + }.bind(this)); }, switch_: function() { this.modified_save().done(function() { @@ -458,8 +470,9 @@ this.screen.screen_container.search_entry.val()); // TODO set current_record } - return this.screen.display(); - // TODO message + return this.screen.display().then(function() { + this.info_bar.message(); + }.bind(this)); // TODO activate_save }.bind(this)); }.bind(this); @@ -474,8 +487,12 @@ return; } this.modified_save().done(function() { - this.screen.copy(); - // TODO message + this.screen.copy().then(function() { + this.info_bar.message( + Sao.i18n.gettext( + 'Working now on the duplicated record(s).'), + 'info'); + }.bind(this)); }.bind(this)); }, delete_: function() { @@ -489,21 +506,30 @@ msg = Sao.i18n.gettext('Are you sure to remove those records?'); } Sao.common.sur.run(msg).done(function() { - this.screen.remove(true, false, true).done(function() { - // TODO message - }); + this.screen.remove(true, false, true).then( + function() { + this.info_bar.message( + Sao.i18n.gettext('Records removed.'), + 'info'); + }.bind(this), function() { + this.info_bar.message( + Sao.i18n.gettext('Records not removed.'), + 'danger'); + }.bind(this)); }.bind(this)); }, previous: function() { this.modified_save().done(function() { this.screen.display_previous(); - // TODO message and activate_save + this.info_bar.message(); + // TODO activate_save }.bind(this)); }, next: function() { this.modified_save().done(function() { this.screen.display_next(); - // TODO message and activate_save + this.info_bar.message(); + // TODO activate_save }.bind(this)); }, search: function() { @@ -517,7 +543,9 @@ logs: function() { var record = this.screen.current_record; if ((!record) || (record.id < 0)) { - // TODO message + this.info_bar.message( + Sao.i18n.gettext('You have to select one record.'), + 'info'); return; } var fields = [ @@ -640,6 +668,9 @@ this.buttons.attach.prop('disabled', record_id < 0 || record_id === null); }, + record_message: function() { + this.info_bar.message(); + }, action: function() { this.buttons.action.click(); }, diff --git a/src/window.js b/src/window.js index 981196cf7b..6dea50f833 100644 --- a/src/window.js +++ b/src/window.js @@ -5,6 +5,36 @@ Sao.Window = {}; + Sao.Window.InfoBar = Sao.class_(Object, { + init: function() { + this.text = jQuery(''); + this.el = jQuery('', { + 'class': 'alert', + 'role': 'alert' + }).append(jQuery('', { + 'type': 'button', + 'class': 'close', + 'aria-label': Sao.i18n.gettext('Close') + }).append(jQuery('', { + 'aria-hidden': true + }).append('×').click(function() { + this.el.hide(); + }.bind(this)))).append(this.text); + this.el.hide(); + }, + message: function(message, type) { + if (message) { + this.el.removeClass( + 'alert-success alert-info alert-warning alert-danger'); + this.el.addClass('alert-' + (type || 'info')); + this.text.text(message); + this.el.show(); + } else { + this.el.hide(); + } + } + }); + Sao.Window.Form = Sao.class_(Object, { init: function(screen, callback, kwargs) { kwargs = kwargs || {}; @@ -16,6 +46,7 @@ this.save_current = kwargs.save_current; this.prev_view = screen.current_view; this.screen.screen_container.alternate_view = true; + this.info_bar = new Sao.Window.InfoBar(); var view_type = kwargs.view_type || 'form'; var form_prm = jQuery.when(); @@ -38,6 +69,8 @@ var dialog = new Sao.Dialog('', '', 'lg'); this.el = dialog.modal; + dialog.body.append(this.info_bar.el); + var readonly = (this.screen.attributes.readonly || this.screen.group.get_readonly()); @@ -249,8 +282,11 @@ jQuery.when.apply(jQuery, validate_prms).then( closing_prm.resolve, closing_prm.reject); } else if (!validate) { + this.info_bar.message( + Sao.i18n.gettext('Invalid form.'), 'danger'); closing_prm.reject(); } else { + this.info_bar.message(); closing_prm.resolve(); } diff --git a/src/wizard.js b/src/wizard.js index 94980cc47a..99a5800f10 100644 --- a/src/wizard.js +++ b/src/wizard.js @@ -24,6 +24,7 @@ this.session = Sao.Session.current_session; this.__processing = false; this.__waiting_response = false; + this.info_bar = new Sao.Window.InfoBar(); }, run: function(attributes) { this.action = attributes.action; @@ -116,8 +117,11 @@ return this.screen.current_record.validate().then(function(validate) { if ((!validate) && state != this.end_state) { this.screen.display(); + this.info_bar.message( + Sao.i18n.gettext('Invalid form.'), 'danger'); return; } + this.info_bar.message(); this.state = state; this.process(); }.bind(this)); @@ -206,7 +210,7 @@ this.dialog = dialog.modal; this.content = dialog.content; this.footer = dialog.footer; - dialog.body.append(this.widget); + dialog.body.append(this.info_bar.el).append(this.widget); }, clean: function() { Sao.Wizard.Dialog._super.clean.call(this);