diff --git a/addons/point_of_sale/static/src/js/chrome.js b/addons/point_of_sale/static/src/js/chrome.js index f7bf1f78010..02d1123bcc3 100644 --- a/addons/point_of_sale/static/src/js/chrome.js +++ b/addons/point_of_sale/static/src/js/chrome.js @@ -278,13 +278,19 @@ var DebugWidget = PosBaseWidget.extend({ }); this.$('.button.export_unpaid_orders').click(function(){ - self.gui.download_file(self.pos.export_unpaid_orders(), - "unpaid_orders_" + (new Date()).toUTCString().replace(/\ /g,'_') + '.json'); + self.gui.prepare_download_link( + self.pos.export_unpaid_orders(), + _t("unpaid orders") + ' ' + moment().format('YYYY-MM-DD-HH-mm-ss') + '.json', + ".export_unpaid_orders", ".download_unpaid_orders" + ); }); this.$('.button.export_paid_orders').click(function() { - self.gui.download_file(self.pos.export_paid_orders(), - "paid_orders_" + (new Date()).toUTCString().replace(/\ /g,'_') + '.json'); + self.gui.prepare_download_link( + self.pos.export_paid_orders(), + _t("paid orders") + ' ' + moment().format('YYYY-MM-DD-HH-mm-ss') + '.json', + ".export_paid_orders", ".download_paid_orders" + ); }); this.$('.button.import_orders input').on('change', function(event) { diff --git a/addons/point_of_sale/static/src/js/gui.js b/addons/point_of_sale/static/src/js/gui.js index 0fca3607f81..bfd24130cc6 100644 --- a/addons/point_of_sale/static/src/js/gui.js +++ b/addons/point_of_sale/static/src/js/gui.js @@ -362,7 +362,34 @@ var Gui = core.Class.extend({ // if 'contents' is not a string, it is converted into // a JSON representation of the contents. + + // TODO: remove me in master: deprecated in favor of prepare_download_link + // this method is kept for backward compatibility but is likely not going + // to work as many browsers do to not accept fake click events on links download_file: function(contents, name) { + href_params = this.prepare_file_blob(contents,name); + var evt = document.createEvent("HTMLEvents"); + evt.initEvent("click"); + + $("",href_params).get(0).dispatchEvent(evt); + + }, + + prepare_download_link: function(contents, filename, src, target) { + var href_params = this.prepare_file_blob(contents, filename); + + $(target).parent().attr(href_params); + $(src).addClass('oe_hidden'); + $(target).removeClass('oe_hidden'); + + // hide again after click + $(target).click(function() { + $(src).removeClass('oe_hidden'); + $(this).addClass('oe_hidden'); + }); + }, + + prepare_file_blob: function(contents, name) { var URL = window.URL || window.webkitURL; if (typeof contents !== 'string') { @@ -371,13 +398,8 @@ var Gui = core.Class.extend({ var blob = new Blob([contents]); - var evt = document.createEvent("HTMLEvents"); - evt.initEvent("click"); - - $("",{ - download: name || 'document.txt', - href: URL.createObjectURL(blob), - }).get(0).dispatchEvent(evt); + return {download: name || 'document.txt', + href: URL.createObjectURL(blob),} }, /* ---- Gui: EMAILS ---- */ diff --git a/addons/point_of_sale/static/src/js/popups.js b/addons/point_of_sale/static/src/js/popups.js index 17a3fd6ac7c..80ce043561a 100644 --- a/addons/point_of_sale/static/src/js/popups.js +++ b/addons/point_of_sale/static/src/js/popups.js @@ -105,7 +105,9 @@ var ErrorTracebackPopupWidget = ErrorPopupWidget.extend({ this._super(opts); this.$('.download').off('click').click(function(){ - self.gui.download_file(self.options.body,'traceback.txt'); + self.gui.prepare_download_link(self.options.body, + _t('error') + ' ' + moment().format('YYYY-MM-DD-HH-mm-ss') + '.txt', + '.download', '.download_error_file'); }); this.$('.email').off('click').click(function(){ diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index a40e0c50fae..bdfbb6d94bd 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -992,6 +992,9 @@ +
@@ -1293,7 +1296,9 @@