});
$(document).on('click', '[data-action="rename"]', function () {
- var h3 = $('.box h3');
+ var h3 = $('.box>h3:eq(0)');
$(h3).text(window.prompt('Please enter the box name', $(h3).text()));
$this.save();
$this.updateBoxesSelector();
});
$(document).on('click', '[data-action="export"]', function () {
- $this.exportBoxes();
+ $this.exportBoxes();
+ return false;
+ });
+
+ $(document).on('click', '[data-action="printbox"]', function () {
+ $this.exportBoxes(true);
+ return false;
});
},
- exportBoxes:function(){
+ getExportFileName: function () {
+ var date = new Date();
+ return 'GrandVision boxes - ' + date.getFullYear() + '-' + date.getMonth() + '-' + date.getDay();
+ },
+
+ exportBoxes: function (print) {
+ this.fluidbook.displayLoader();
+ var $this = this;
+ if ($("#grandvision-pdf").length === 0) {
+ $('body').append('<div id="grandvision-pdf"></div>');
+ }
+
+ var c = $('#grandvision-pdf');
+ $(c).html('');
+ $.each(this.boxes, function (index, box) {
+ $(c).append($this.getBox(index));
+ });
+
+ var element = $(c).get(0);
+ var options = {
+ margin: 0,
+ filename: this.getExportFileName() + '.pdf',
+ image: {type: 'png'},
+ html2canvas: {dpi: 150, scale: 4, letterRendering: false},
+ jsPDF: {unit: 'mm', format: 'A4', orientation: 'portrait'}
+ };
+
+ if (print === true) {
+ html2pdf().set(options).from(element).toPdf().get('pdf').then(function (pdfObj) {
+ pdfObj.autoPrint();
+ window.open(pdfObj.output('bloburl'), '_blank');
+ $this.fluidbook.hideLoader(2);
+ });
+ } else {
+ html2pdf().set(options).from(element).save().then(function () {
+ $this.fluidbook.hideLoader(2);
+ });
+ }
},
addNewBox: function () {
initRightSortable() {
var $this = this;
new Sortable(document.getElementById('grandvision-selection-slots'), {
+ swap: true,
group: {
name: 'shared',
},
index = Math.max(0, Math.min(this.boxes.length - 1, index));
+
+ $(".boxholder").html(this.getBox(index));
+
+ this.initRightSortable();
+ },
+
+ getBox: function (index) {
+ var $this = this;
var b = this.boxes[index];
- res = '<div class="box">';
+ var res = '<div class="box">';
res += '<h3>' + b.name + '</h3>';
res += '<div class="slots override-delete" id="grandvision-selection-slots">';
for (var i = 0; i < 10; i++) {
if (b.refs[i] === undefined || b.refs[i] === null) {
res += '<div class="slot" data-tooltip="Drag an item from your selection here"></div>';
} else {
- res += $this.getItemHTML(b.refs[i], false);
+ res += this.getItemHTML(b.refs[i], false);
}
}
res += '</div>';
res += '<div class="actions">';
res += '<a href="#" data-action="rename">' + getSpriteIcon('grandvision-rename') + ' Rename</a>';
- res += '<a href="#" data-action="print">' + getSpriteIcon('nav-print') + ' Print</a>';
+ res += '<a href="#" data-action="printbox">' + getSpriteIcon('nav-print') + ' Print</a>';
res += '<a href="#" data-action="export">' + getSpriteIcon('grandvision-export') + ' Export</a>';
res += '<a href="#" data-action="delete">' + getSpriteIcon('grandvision-delete') + ' Delete</a>';
res += '</div>';
res += '</div>';
-
- $(".boxholder").html(res);
-
- this.initRightSortable();
+ return res;
},
getProductSlideshow: function (ref, data) {