--- /dev/null
+function FluidbookCartMIF(cart) {
+ var $this = this;
+ this.cart = cart;
+ this.fluidbook = this.cart.fluidbook;
+ this.data = this.fluidbook.settings.basketReferences;
+ this.init();
+}
+
+FluidbookCartMIF.prototype = {
+ init: function () {
+ var $this = this;
+ this.items = this.fluidbook.cache.get('cart', []);
+ $(document).on('click', '.exportCartPDF', function () {
+ $this.exportPDF();
+ return false;
+ });
+ $(document).on('click', '.sendAsEmail', function () {
+ try {
+ $this.sendCartAsEmail();
+ } catch (err) {
+ console.log(err);
+ }
+ return false;
+ });
+ },
+
+ addToCart: function (ref, quantity) {
+ if (this.items.indexOf(ref) === -1) {
+ this.items.push(ref);
+ this.save();
+ }
+ return true;
+ },
+
+ removeFromCart: function (key) {
+ this.items.splice(key, 1);
+ this.save();
+ },
+
+ save: function () {
+ this.fluidbook.cache.set('cart', this.items);
+ this.fluidbook.cart.updateLinks();
+ },
+ getItemsReferences: function () {
+ return this.items;
+ },
+ getItemsNumbers: function () {
+ return this.items.length;
+ },
+ getAllQuantities: function () {
+ return this.getItemsNumbers();
+ },
+
+ updateCart: function () {
+ if ($('#mifcart').length > 0) {
+ $('#mifcart .content').html(this.getCartContent());
+ }
+ },
+
+ updateIcon: function () {
+ $(this.fluidbook).trigger('fluidbook.cart.updateIcon', {number: this.getItemsNumbers()});
+ },
+
+ openMenu: function (p1, p2, callback) {
+ this.fluidbook.menu.quickCloseView();
+ return this.openCart(p2, callback);
+ },
+
+ openCart: function (p2, callback) {
+ this._endMenu('my cart', this.getCartContent(), function () {
+ callback();
+ });
+ },
+
+ getCartContent: function () {
+ if (this.getItemsNumbers() == 0) {
+ return '<div class="cart-empty">' + this.fluidbook.l10n.__('your cart is empty') + '</div>';
+ }
+
+ var $this = this;
+ var content = '<table id="mifcarttable" class="cart-items" cellpadding="0" cellspacing="0">';
+ content += '<thead><tr>';
+ content += '<th>Catégorie</th>';
+ content += '<th>Marque</th>';
+ content += '<th>Nom du produit</th>';
+ content += '<th>Prix</th>';
+ content += '<th>Image</th>';
+ content += '<th></th>';
+ content += '</tr></thead>';
+ content += '<tbody>';
+ $.each(this.items, function (i, ref) {
+ var item = $this.data[ref];
+ if (item === undefined) {
+ return;
+ }
+ content += '<tr data-pseudolink-href="' + item.Lien + '" data-pseudolink-target="_blank">';
+ content += '<td class="categorie"><span>' + item.Categorie + '</span></td>';
+ content += '<td class="marque"><span>' + item.Marque + '</span></td>';
+ content += '<td class="produit"><span>' + item.Produit + '</span></td>';
+ content += '<td class="prix"><span>' + item.Prix + '</span></td>';
+ var image = '';
+ if (item['zoom_image']) {
+ image = '<img src="' + item['zoom_image'] + '" />';
+ } else {
+ image = '-';
+ }
+ content += '<td class="image"><span>' + image + '</span></td>';
+ content += '<td><a href="#" data-cart-delete="' + i + '">' + getSpriteIcon('interface-close') + '</a></td>';
+ content += '</tr>';
+ });
+ content += '</tbody>';
+ content += '</table>';
+ content += '<div class="cart-footer">';
+ content += '<div class="fonctions"><a href="#" class="exportCartPDF">Télécharger ma liste (PDF)</a><a href="#" class="sendAsEmail">Envoyer ma liste par e-mail</a></div>';
+ content += '</div>';
+
+ return content;
+ },
+
+ sendCartAsEmail: function () {
+ var $this = this;
+
+ var subject = 'Ma liste de Noël'
+ var body = 'Ma liste de Noël : ' + "\n\n";
+
+ $.each(this.items, function (i, ref) {
+ var item = $this.fluidbook.settings.basketReferences[ref];
+ if (item === undefined) {
+ return;
+ }
+ body += item.Produit + ' (' + item.Marque + ') - ' + item.Prix + " :\n";
+ body += item.Lien + "\n\n";
+ });
+ window.location.href = 'mailto:?subject=' + encodeURIComponent(subject) + '&body=' + encodeURIComponent(body);
+ },
+
+ exportPDF: function () {
+
+ var element = $('#mifcarttable').get(0);
+ var options = {
+ margin: 15,
+ filename: this.getExportFileName() + '.pdf',
+ image: {type: 'jpeg', quality: 0.98},
+ html2canvas: {dpi: 150, scale: 2, letterRendering: true},
+ jsPDF: {unit: 'mm', format: 'A4', orientation: 'portrait'}
+ };
+ $(element).addClass('print')
+ html2pdf().set(options).from(element).save().then(function () {
+ $(element).removeClass('print');
+ });
+
+ setTimeout(function () {
+ $(element).removeClass('print');
+ }, 2000);
+ },
+
+ getExportFileName: function () {
+ var date = new Date();
+ return this.fluidbook.settings.title + ' - Cart - ' + date.getFullYear() + '-' + date.getMonth() + '-' + date.getDay();
+ },
+
+ _endMenu: function (title, content, callback) {
+ var view = '<div id="mifcart">';
+ view += this.fluidbook.menu.getCaption(title);
+ view += '<div class="content">';
+ view += "" + content;
+ view += '</div>';
+ view += '</div>';
+ this.fluidbook.menu.viewWrap(view, 'cart');
+ callback();
+ },
+
+ getMenuWidth: function () {
+ return 1200;
+ },
+
+ parseFloat: function (s) {
+ if (typeof s === 'number') {
+ return s;
+ }
+ if (s === undefined || s === null || s === '') {
+ return 0;
+ }
+ s = s.replace(/\s/g, '');
+ return parseFloat(s);
+ },
+
+ parseInt: function (s) {
+ if (typeof s === 'number') {
+ return Math.round(s);
+ }
+ if (s === undefined || s === null || s === '') {
+ return 0;
+ }
+ s = s.replace(/\s/g, '');
+ return parseInt(s);
+ },
+};
\ No newline at end of file
});
- $(document).on('click', 'a', function () {
+ $(document).on('click', 'a, [data-pseudolink-href]', function () {
+ console.log(this);
if ($(this).is('#wopen')) {
return true;
}
- var target = $(this).attr('target');
+ var target = $(this).is('[data-pseudolink-href]') ? $(this).data('pseudolink-target') : $(this).attr('target');
if (!target) {
target = '_self';
}
+ var href = $(this).is('[data-pseudolink-href]') ? $(this).data('pseudolink-href') : $(this).attr('href');
-
- var href = $(this).attr('href');
if (href === undefined) {
return true;
}
},
handleExternalHref: function (link) {
- var href = $(link).attr('href');
+ var href = $(link).is('[data-pseudolink-href]') ? $(link).data('pseudolink-href') : $(link).attr('href');
+ ;
var change = false;
if (this.fluidbook.stats.relay_url_params !== '' && !$(link).hasClass('relay_appended')) {
$(link).addClass('relay_appended');
}
if (change) {
- $(link).attr('href', href);
+ if ($(link).is('[data-pseudolink-href]')) {
+ $(link).attr('[data-pseudolink-href]', href).data('pseudolink-href', href);
+ } else {
+ $(link).attr('href', href);
+ }
}
return href;