Añadidos módulos de OCA/e-commerce para la tienda online
This commit is contained in:
parent
10bfdb5a49
commit
c14ed5b4ef
99 changed files with 5359 additions and 0 deletions
|
@ -0,0 +1,108 @@
|
|||
// Copyright 2020 Tecnativa - Alexandre Díaz
|
||||
// License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
|
||||
odoo.define("website_snippet_carousel_product.s_product_carousel", function (require) {
|
||||
"use strict";
|
||||
|
||||
var core = require("web.core");
|
||||
var sAnimation = require("website.content.snippets.animation");
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
sAnimation.registry.js_product_carousel = sAnimation.Class.extend({
|
||||
selector: ".js_product_carousel",
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
start: function () {
|
||||
var self = this;
|
||||
var limit = Number(this.$target.attr("data-products-limit")) || 12;
|
||||
var domain = this.$target.attr("data-domain") || "[]";
|
||||
var products_per_slide =
|
||||
Number(this.$target.attr("data-products-per-slide")) || 4;
|
||||
var interval = Number(this.$target.attr("data-interval"));
|
||||
if (_.isNaN(interval)) {
|
||||
interval = 5000;
|
||||
}
|
||||
|
||||
// Prevent user edition
|
||||
this.$target.attr("contenteditable", "False");
|
||||
|
||||
// Loading Indicator
|
||||
this.$target.html(
|
||||
$("<div/>", {class: "text-center p-5 my-5 text-muted"})
|
||||
.append($("<i/>", {
|
||||
class: "fa fa-circle-o-notch fa-spin fa-3x fa-fwg mr-1"
|
||||
}))
|
||||
);
|
||||
|
||||
var def = this._rpc({
|
||||
route: "/website/render_product_carousel",
|
||||
params: {
|
||||
limit: limit,
|
||||
domain: JSON.parse(domain),
|
||||
products_per_slide: products_per_slide,
|
||||
},
|
||||
})
|
||||
.then(
|
||||
function (object_html) {
|
||||
var $object_html = $(object_html);
|
||||
var count = $object_html
|
||||
.find("input[name='product_count']")
|
||||
.val();
|
||||
if (!count) {
|
||||
self.$target.append(
|
||||
$("<div/>", {class: "col-md-6 offset-md-3"}).append(
|
||||
$("<div/>", {
|
||||
class:
|
||||
"alert alert-warning" +
|
||||
" alert-dismissible text-center",
|
||||
text: _t(
|
||||
"No products was found." +
|
||||
" Make sure you have products" +
|
||||
" published on the website."
|
||||
),
|
||||
})
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
self.$target.html($object_html);
|
||||
self.$target.find('.carousel').carousel({
|
||||
interval: interval,
|
||||
});
|
||||
// Initialize 'animations' for the product card.
|
||||
// This is necessary because the snippet is asynchonously
|
||||
// rendered on the server.
|
||||
self.trigger_up('animation_start_demand', {
|
||||
$target: self.$target.find('.oe_website_sale'),
|
||||
});
|
||||
},
|
||||
function () {
|
||||
if (self.editableMode) {
|
||||
self.$target.append(
|
||||
$("<p/>", {
|
||||
class: "text-danger",
|
||||
text: _t(
|
||||
"An error occured with this product" +
|
||||
" carousel block. If the problem" +
|
||||
" persists, please consider deleting" +
|
||||
" it and adding a new one"
|
||||
),
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
return $.when(this._super.apply(this, arguments), def);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
destroy: function () {
|
||||
this.$target.empty();
|
||||
this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
});
|
|
@ -0,0 +1,144 @@
|
|||
// Copyright 2020 Tecnativa - Alexandre Díaz
|
||||
// License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
|
||||
odoo.define("website_snippet_carousel_product.snippet_options", function (require) {
|
||||
"use strict";
|
||||
|
||||
var core = require("web.core");
|
||||
var options = require("web_editor.snippets.options");
|
||||
var wUtils = require("website.utils");
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
options.registry.js_product_carousel = options.Class.extend({
|
||||
popup_template_id: "editor_new_product_carousel_domain",
|
||||
popup_title: _t("Add a products carousel"),
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_onLinkClick: function (ev) {
|
||||
// Get the selected menu item
|
||||
var $elm = $(ev.target);
|
||||
if ($elm.is(".s_carousel_set_domain")) {
|
||||
this.select_domain();
|
||||
} else if ($elm.is("[data-products-per-slide]")) {
|
||||
this.$target.attr(
|
||||
"data-products-per-slide",
|
||||
$elm.attr("data-products-per-slide")
|
||||
);
|
||||
this._refreshAnimations();
|
||||
} else if ($elm.is("[data-products-limit]")) {
|
||||
this.$target.attr(
|
||||
"data-products-limit",
|
||||
$elm.attr("data-products-limit")
|
||||
);
|
||||
this._refreshAnimations();
|
||||
} else if ($elm.is("[data-interval]")) {
|
||||
this.$target.attr(
|
||||
"data-interval",
|
||||
$elm.attr("data-interval")
|
||||
);
|
||||
this._refreshAnimations();
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
onBuilt: function () {
|
||||
this._super();
|
||||
this.select_domain();
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_setActive: function () {
|
||||
var self = this;
|
||||
this._super.apply(this, arguments);
|
||||
// Active 'Limit' option
|
||||
this.$el
|
||||
.find("[data-products-limit]")
|
||||
.addBack("[data-products-limit]")
|
||||
.removeClass("active")
|
||||
.filter(function () {
|
||||
var limit = $(this).attr("data-products-limit");
|
||||
var old_limit =
|
||||
self.$target.attr("data-products-limit") || '12';
|
||||
return old_limit === limit;
|
||||
})
|
||||
.addClass("active");
|
||||
// Active 'Show' option
|
||||
this.$el
|
||||
.find("[data-products-per-slide]")
|
||||
.addBack("[data-products-per-slide]")
|
||||
.removeClass("active")
|
||||
.filter(function () {
|
||||
var pps = $(this).attr("data-products-per-slide");
|
||||
var old_pps =
|
||||
self.$target.attr("data-products-per-slide") || '4';
|
||||
return old_pps === pps;
|
||||
})
|
||||
.addClass("active");
|
||||
// Active 'Interval' option
|
||||
this.$el
|
||||
.find("[data-interval]")
|
||||
.addBack("[data-interval]")
|
||||
.removeClass("active")
|
||||
.filter(function () {
|
||||
var interval = $(this).attr("data-interval");
|
||||
var old_interval =
|
||||
self.$target.attr("data-interval") || '5000';
|
||||
return old_interval === interval;
|
||||
})
|
||||
.addClass("active");
|
||||
},
|
||||
|
||||
/**
|
||||
* Open domain selector dialog
|
||||
* @returns {Promise}
|
||||
*/
|
||||
select_domain: function () {
|
||||
var self = this;
|
||||
var def = wUtils.prompt({
|
||||
id: this.popup_template_id,
|
||||
window_title: this.popup_title,
|
||||
input: _t("Domain (can be empty)"),
|
||||
init: function () {
|
||||
return self.$target.attr("data-domain");
|
||||
},
|
||||
});
|
||||
return def.always(function (domain) {
|
||||
var sdomain = domain || '';
|
||||
self.$target.attr("data-domain", sdomain.replace(/'/g, '"'));
|
||||
self._refreshAnimations();
|
||||
// The change is made after the option selection, so we
|
||||
// need send a new "option change" to make sure the new
|
||||
// changes are saved.
|
||||
self.__click = true;
|
||||
self._select(false, self.$target);
|
||||
self.$target.trigger('snippet-option-change', [self]);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
cleanForSave: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this.$target.empty();
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
interval: function (previewMode, value) {
|
||||
this.$target.find('.carousel:first')
|
||||
.carousel('dispose')
|
||||
.carousel({
|
||||
interval: Number(value),
|
||||
});
|
||||
},
|
||||
});
|
||||
});
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright 2020 Tecnativa - Alexandre Díaz
|
||||
// License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
|
||||
.s_product_carousel {
|
||||
.oe_product {
|
||||
border-width: 0;
|
||||
|
||||
.oe_product_image, .oe_product_image img {
|
||||
position: unset;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue