2012-10-16 12:29:13 +00:00
|
|
|
openerp.edi = function(instance) {
|
|
|
|
var _t = instance.web._t;
|
2014-01-13 15:24:10 +00:00
|
|
|
instance.edi = {};
|
|
|
|
|
2011-10-18 14:06:27 +00:00
|
|
|
|
2012-10-16 12:29:13 +00:00
|
|
|
instance.edi.EdiImport = instance.web.Widget.extend({
|
2011-12-27 19:54:00 +00:00
|
|
|
|
2011-10-18 14:06:27 +00:00
|
|
|
init: function(parent,url) {
|
|
|
|
this._super();
|
|
|
|
this.url = url;
|
|
|
|
},
|
|
|
|
start: function() {
|
2012-01-13 11:21:21 +00:00
|
|
|
if (!this.session.session_is_valid()) {
|
2014-01-13 15:24:10 +00:00
|
|
|
instance.redirect('/web/login?redir=' + encodeURIComponent(window.location));
|
2012-01-13 11:21:21 +00:00
|
|
|
} else {
|
|
|
|
this.show_import();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
show_import: function() {
|
|
|
|
this.destroy_content();
|
2011-12-27 19:54:00 +00:00
|
|
|
this.do_import();
|
2011-10-18 21:11:39 +00:00
|
|
|
},
|
2012-01-13 11:21:21 +00:00
|
|
|
|
|
|
|
destroy_content: function() {
|
2012-02-21 16:45:36 +00:00
|
|
|
_.each(_.clone(this.getChildren()), function(el) {
|
|
|
|
el.destroy();
|
2012-01-13 11:21:21 +00:00
|
|
|
});
|
2012-08-24 18:27:43 +00:00
|
|
|
this.$el.children().remove();
|
2012-01-13 11:21:21 +00:00
|
|
|
},
|
|
|
|
|
2011-10-18 21:11:39 +00:00
|
|
|
do_import: function() {
|
2012-10-31 10:31:48 +00:00
|
|
|
this.rpc('/edi/import_edi_url', {url: this.url}).done(this.on_imported).fail(this.on_imported_error);
|
2011-10-18 21:11:39 +00:00
|
|
|
},
|
2011-10-24 22:40:55 +00:00
|
|
|
on_imported: function(response) {
|
2011-11-05 00:44:38 +00:00
|
|
|
if ('action' in response) {
|
2012-10-31 10:31:48 +00:00
|
|
|
this.rpc("/web/session/save_session_action", {the_action: response.action}).done(function(key) {
|
2012-08-08 12:02:14 +00:00
|
|
|
window.location = "/#sa="+encodeURIComponent(key);
|
2011-11-05 00:44:38 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
2014-06-02 14:41:58 +00:00
|
|
|
new instance.web.Dialog(this,{
|
|
|
|
title: 'Import Successful!',
|
|
|
|
buttons: {
|
|
|
|
Ok: function() {
|
|
|
|
this.parents('.modal').modal('hide');
|
|
|
|
window.location = "/";
|
|
|
|
}
|
2011-11-05 00:44:38 +00:00
|
|
|
}
|
2014-06-02 14:41:58 +00:00
|
|
|
},$('<div>').html(_t('The document has been successfully imported!'))).open();
|
2011-11-05 00:44:38 +00:00
|
|
|
}
|
2011-10-20 14:45:58 +00:00
|
|
|
},
|
|
|
|
on_imported_error: function(response){
|
2011-10-24 22:40:55 +00:00
|
|
|
var self = this;
|
2012-10-16 12:29:13 +00:00
|
|
|
var msg = _t("Sorry, the document could not be imported.");
|
2013-01-30 15:42:29 +00:00
|
|
|
if (response.data.message) {
|
|
|
|
msg += "\n " + _t("Reason:") + response.data.message;
|
2011-11-05 00:44:38 +00:00
|
|
|
}
|
|
|
|
var params = {error: response, message: msg};
|
2014-06-02 14:41:58 +00:00
|
|
|
new instance.web.Dialog(this,{
|
|
|
|
title: _t("Document Import Notification"),
|
|
|
|
buttons: {
|
|
|
|
Ok: function() { this.parents('.modal').modal('hide');}
|
|
|
|
}
|
|
|
|
},$(instance.web.qweb.render("CrashManager.warning", params))).open();
|
2011-10-20 14:45:58 +00:00
|
|
|
}
|
2011-10-18 14:06:27 +00:00
|
|
|
});
|
|
|
|
|
2012-10-16 12:29:13 +00:00
|
|
|
instance.edi.edi_import = function (url) {
|
2012-11-09 13:36:23 +00:00
|
|
|
instance.session.session_bind().done(function () {
|
2012-10-16 12:29:13 +00:00
|
|
|
new instance.edi.EdiImport(null,url).appendTo($("body").addClass('openerp'));
|
2011-12-27 19:54:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-01-13 14:56:47 +00:00
|
|
|
};
|
2011-10-18 14:06:27 +00:00
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|