diff --git a/src/tab.js b/src/tab.js index 69f6c58f96..9f279be999 100644 --- a/src/tab.js +++ b/src/tab.js @@ -96,7 +96,7 @@ var tab = tabs.find('#nav-' + this.id); var content = tabs.find('#' + this.id); tabs.find('a[href="#' + this.id + '"]').tab('show'); - return this.modified_save().then(function() { + return this._close_allowed().then(function() { var next = tab.next(); if (!next.length) { next = tab.prev(); @@ -108,6 +108,9 @@ next.find('a').tab('show'); } }.bind(this)); + }, + _close_allowed: function() { + return jQuery.when(); } }); @@ -157,6 +160,10 @@ } else { tab = new Sao.Tab.Board(attributes); } + Sao.Tab.add(tab); + }; + + Sao.Tab.add = function(tab) { var tabs = jQuery('#tabs'); var tab_link = jQuery('', { 'aria-controls': tab.id, @@ -355,6 +362,9 @@ }); return toolbar; }, + _close_allowed: function() { + return this.modified_save(); + }, modified_save: function() { this.screen.save_tree_state(); this.screen.current_view.set_value(); @@ -599,4 +609,37 @@ this.buttons.print.click(); } }); + + Sao.Tab.Wizard = Sao.class_(Sao.Tab, { + class_: 'tab-wizard', + init: function(wizard) { + Sao.Tab.Wizard._super.init.call(this); + this.wizard = wizard; + this.name = wizard.name; + wizard.tab = this; + this.create_tabcontent(); + this.title.html(this.name); + this.el.append(wizard.form); + }, + create_toolbar: function() { + return jQuery(''); + }, + _close_allowed: function() { + var wizard = this.wizard; + var prm = jQuery.when(); + if ((wizard.state !== wizard.end_state) && + (wizard.end_state in wizard.states)) { + prm = wizard.response(wizard.end_state); + } + var dfd = jQuery.Deferred(); + prm.always(function() { + if (wizard.state === wizard.end_state) { + dfd.resolve(); + } else { + dfd.reject(); + } + }); + return dfd.promise(); + } + }); }()); diff --git a/src/wizard.js b/src/wizard.js index cecd64c835..9ceeb69794 100644 --- a/src/wizard.js +++ b/src/wizard.js @@ -113,7 +113,7 @@ response: function(state) { this.__waiting_response = false; this.screen.current_view.set_value(); - this.screen.current_record.validate().then(function(validate) { + return this.screen.current_record.validate().then(function(validate) { if ((!validate) && state != this.end_state) { this.screen.display(); return; @@ -155,13 +155,46 @@ var win; if (attributes.window) { win = new Sao.Wizard.Form(attributes.name); + var tab = new Sao.Tab.Wizard(win); + Sao.Tab.add(tab); } else { win = new Sao.Wizard.Dialog(attributes.name); } win.run(attributes); }; - // TODO Wizard.Form + Sao.Wizard.Form = Sao.class_(Sao.Wizard, { + init: function(name) { + Sao.Wizard.Form._super.init.call(this); + this.tab = null; // Filled by Sao.Tab.Wizard + this.name = name; + + this.form = jQuery('
', { + 'class': 'wizard-form', + }).append(this.widget); + this.footer = jQuery('
', { + 'class': 'modal-footer' + }).appendTo(this.form); + }, + clean: function() { + Sao.Wizard.Form._super.clean.call(this); + this.footer.children().remove(); + }, + _get_button: function(definition) { + var button = Sao.Wizard.Form._super._get_button.call(this, + definition); + this.footer.append(button.el); + button.el.click(function() { + this.response(definition.state); + }.bind(this)); + return button; + }, + end: function() { + return Sao.Wizard.Form._super.end.call(this).always(function() { + return this.tab.close(); + }.bind(this)); + } + }); Sao.Wizard.Dialog = Sao.class_(Sao.Wizard, { // TODO nomodal init: function(name) {