diff --git a/addons/edi/static/src/js/edi.js b/addons/edi/static/src/js/edi.js index 352177156e1..d62a4c3b780 100644 --- a/addons/edi/static/src/js/edi.js +++ b/addons/edi/static/src/js/edi.js @@ -114,30 +114,49 @@ openerp.edi.edi_view = function (db, token) { } openerp.edi.EdiImport = openerp.web.Widget.extend({ - init: function(parent,url) { - this._super(); - this.url = url; - var params = {}; + template: "EdiImport", - this.template = "EdiImport"; - this.session = openerp.connection; - this.login = new openerp.web.Login(this); - this.header = new openerp.web.Header(this); + init: function(parent, url) { + this._super(parent); + this.url = url; }, start: function() { - // TODO fix by explicitly asking login if needed - //this.session.on_session_invalid.add_last(this.do_ask_login); - this.header.appendTo($("#oe_header")); - this.login.appendTo($('#oe_login')); + if (!this.session.session_is_valid()) { + this.show_login(); + this.session.on_session_valid.add({ + callback: this.proxy('show_import'), + unique: true, + }); + } else { + this.show_import(); + } + }, + + show_import: function() { + this.destroy_content(); this.do_import(); }, + + show_login: function() { + this.destroy_content(); + this.login = new openerp.web.Login(this); + this.login.appendTo(this.$element); + }, + + destroy_content: function() { + _.each(_.clone(this.widget_children), function(el) { + el.stop(); + }); + this.$element.children().remove(); + }, + do_import: function() { this.rpc('/edi/import_edi_url', {url: this.url}, this.on_imported, this.on_imported_error); }, on_imported: function(response) { if ('action' in response) { this.rpc("/web/session/save_session_action", {the_action: response.action}, function(key) { - window.location = "/web/webclient/home?debug=1&s_action="+encodeURIComponent(key); + window.location = "/web/webclient/home#sa="+encodeURIComponent(key); }); } else { @@ -147,7 +166,7 @@ openerp.edi.EdiImport = openerp.web.Widget.extend({ buttons: { Ok: function() { $(this).dialog("close"); - window.location = "/web/webclient/home"; + window.location = "/"; } } }).html('The document has been successfully imported!');