this.cart = cart;
this.fluidbook = this.cart.fluidbook;
this.data = this.fluidbook.settings.basketReferences;
+ this.exportFileName = '';
this.init();
}
var $this = this;
this.items = this.fluidbook.cache.get('cart', []);
$(document).on(this.fluidbook.input.clickEvent, '.exportCartPDF', function () {
- $this.exportPDF();
+ $this.chooseFileName(function () {
+ $this.exportPDF();
+ });
return false;
});
$(document).on(this.fluidbook.input.clickEvent, '.exportCartXLS', function () {
try {
- $this.exportXLS();
+ $this.chooseFileName(function () {
+ $this.exportXLS();
+ });
} catch (err) {
console.log(err);
}
});
$(document).on(this.fluidbook.input.clickEvent, '.exportEANXLS', function () {
try {
- $this.exportEANXLS();
+ $this.chooseFileName(function () {
+ $this.exportEANXLS();
+ });
} catch (err) {
console.log(err);
}
}, 2000);
},
- getExportFileName: function (label) {
- if (label === undefined) {
- label = 'Cart';
+ getExportFileName: function () {
+ if (this.exportFileName !== '') {
+ return this.exportFileName;
}
var date = new Date();
- return this.fluidbook.settings.title + ' - ' + label + ' - ' + date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate();
+ return this.fluidbook.settings.title + ' - ' + date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate();
},
exportEANXLS: function () {
const url = window.URL.createObjectURL(blob);
const anchor = document.createElement('a');
anchor.href = url;
- anchor.download = $this.getExportFileName('EAN') + '.xlsx';
+ anchor.download = $this.getExportFileName() + '.xlsx';
anchor.click();
window.URL.revokeObjectURL(url);
});
},
+ chooseFileName: function (callback) {
+ var $this = this;
+ $.confirm({
+ title: 'Name your file',
+ content: '' +
+ '<form action="" class="formName">' +
+ '<div class="form-group">' +
+ '<input type="text" value="' + this.getExportFileName() + '" placeholder="File name" class="name form-control" required />' +
+ '</div>' +
+ '</form>',
+ buttons: {
+ formSubmit: {
+ text: 'Submit',
+ btnClass: 'btn-ok',
+ action: function () {
+ $this.exportFileName = this.$content.find('.name').val();
+ callback();
+ }
+ },
+ cancel: function () {
+ //close
+ },
+ },
+ onContentReady: function () {
+ // bind to events
+ var jc = this;
+ this.$content.find('form').on('submit', function (e) {
+ // if the user submits the form by pressing enter in the field.
+ e.preventDefault();
+ jc.$$formSubmit.trigger('click'); // reference the button and click it
+ });
+ }
+ });
+ },
+
exportXLS: function () {
var $this = this;
const workbook = new ExcelJS.Workbook();