Skip to content
Snippets Groups Projects
Commit ede6a907 authored by Thibault Delavallée's avatar Thibault Delavallée
Browse files

[REF] website_slides: lint slide like / dislike widget

Just apply some linting and naming convention.

Commit linked to task ID 1942852 and PR #31394.
parent a0f923c3
No related branches found
No related tags found
No related merge requests found
odoo.define('website_slides.slides_like', function (require) {
odoo.define('website_slides.slides.slide.like', function (require) {
'use strict';
var core = require('web.core');
var Widget = require('web.Widget');
var localStorage = require('web.local_storage');
var sAnimations = require('website.content.snippets.animation');
require('website_slides.slides');
var _t = core._t;
var LikeButton = Widget.extend({
var SlideLikeWidget = Widget.extend({
events: {
'click .o_wslides_like_up': '_onClickUp',
'click .o_wslides_like_down': '_onClickDown',
'click .o_wslides_js_slide_like_up': '_onClickUp',
'click .o_wslides_js_slide_like_down': '_onClickDown',
},
//--------------------------------------------------------------------------
......@@ -53,8 +52,8 @@ var LikeButton = Widget.extend({
},
}).then(function (data) {
if (! data.error) {
self.$el.find('span.o_wslides_like_up span').text(data.likes);
self.$el.find('span.o_wslides_like_down span').text(data.dislikes);
self.$el.find('span.o_wslides_js_slide_like_up span').text(data.likes);
self.$el.find('span.o_wslides_js_slide_like_down span').text(data.dislikes);
} else {
if (data.error === 'public_user') {
self._popoverAlert(self.$el, _.str.sprintf(_t('Please <a href="/web/login?redirect=%s">login</a> to vote this slide'), (document.URL)));
......@@ -67,18 +66,18 @@ var LikeButton = Widget.extend({
});
},
_onClickUp: function (event) {
var slideId = $(event.currentTarget).data('slide-id');
_onClickUp: function (ev) {
var slideId = $(ev.currentTarget).data('slide-id');
return this._onClick(slideId, 'like');
},
_onClickDown: function (event) {
var slideId = $(event.currentTarget).data('slide-id');
_onClickDown: function (ev) {
var slideId = $(ev.currentTarget).data('slide-id');
return this._onClick(slideId, 'dislike');
},
});
sAnimations.registry.websiteSlidesLike = sAnimations.Class.extend({
sAnimations.registry.websiteSlidesSlideLike = sAnimations.Class.extend({
selector: '#wrapwrap',
/**
......@@ -88,10 +87,16 @@ sAnimations.registry.websiteSlidesLike = sAnimations.Class.extend({
start: function () {
var self = this;
var defs = [this._super.apply(this, arguments)];
$('.o_wslides_like').each(function () {
defs.push(new LikeButton(self).attachTo($(this)));
$('.o_wslides_js_slide_like').each(function () {
defs.push(new SlideLikeWidget(self).attachTo($(this)));
});
return $.when.apply($, defs);
},
});
return {
slideLikeWidget: SlideLikeWidget,
websiteSlidesSlideLike: sAnimations.registry.websiteSlidesSlideLike
};
});
// FIXME may be useless (check initial code here: https://github.com/odoo/odoo/blob/51be5bbfb38db784cb3406877cc0e8806b1bf55a/addons/website_slides/static/src/less/website_slides.less#L1)
$nav-tabs-border-color: #dddddd !default;
$body-bg: #FFFFFF !default;
$link-color: theme-color('primary') !default;
$MAX-Z-INDEX : 2147483647 !default;
......@@ -37,6 +36,11 @@ $MAX-Z-INDEX : 2147483647 !default;
border-width: 0 0 3px 0;
}
.o_wslides_js_slide_like_up,
.o_wslides_js_slide_like_down {
cursor: pointer;
color: $link-color;
}
// tools
// ****************************************
......@@ -312,11 +316,6 @@ $MAX-Z-INDEX : 2147483647 !default;
max-height: 500px;
}
.o_wslides_like_up, .o_wslides_like_down {
cursor: pointer;
color: $link-color;
}
// Thumbnails
.oe_slides_ellipsis {
white-space: nowrap;
......
......@@ -12,11 +12,11 @@
</xpath>
<xpath expr="//script[last()]" position="after">
<script type="text/javascript" src="/website_slides/static/src/js/slides.js"/>
<script type="text/javascript" src="/website_slides/static/src/js/slides_like.js"/>
<script type="text/javascript" src="/website_slides/static/src/js/slides_share.js"/>
<script type="text/javascript" src="/website_slides/static/src/js/slides_upload.js"/>
<script type="text/javascript" src="/website_slides/static/src/js/slides_category_add.js"/>
<script type="text/javascript" src="/website_slides/static/src/js/slides_slide_archive.js"/>
<script type="text/javascript" src="/website_slides/static/src/js/slides_slide_like.js"/>
<script type="text/javascript" src="/website_slides/static/src/js/slides_course_slides_list.js"/>
<script type="text/javascript" src="/website_slides/static/src/js/slides_course_progress_bar.js"/>
<script type="text/javascript" src="/website_slides/static/src/js/slides_course_fullscreen_player.js"/>
......
......@@ -455,12 +455,12 @@
<div class="card-footer border-top-0 text-600">
<div class="d-flex align-items-center small">
<span class="font-weight-bold mr-auto" t-field="slide.completion_time" t-options='{"widget": "float_time"}'/>
<div class="o_wslides_like mr-2">
<span class="o_wslides_like_up" tabindex="0" data-toggle="popover" t-att-data-slide-id="slide.id">
<div class="o_wslides_js_slide_like mr-2">
<span class="o_wslides_js_slide_like_up" tabindex="0" data-toggle="popover" t-att-data-slide-id="slide.id">
<i class="fa fa-thumbs-up fa-1x" role="img" aria-label="Likes" title="Likes"></i>
<span t-esc="slide.likes"/>
</span>
<span class="o_wslides_like_down" tabindex="0" data-toggle="popover" t-att-data-slide-id="slide.id">
<span class="o_wslides_js_slide_like_down" tabindex="0" data-toggle="popover" t-att-data-slide-id="slide.id">
<i class="fa fa-thumbs-down fa-1x" role="img" aria-label="Dislikes" title="Dislikes"></i>
<span t-esc="slide.dislikes"/>
</span>
......
......@@ -190,9 +190,9 @@
<!-- LikeButton widget -->
<div t-if="slide.channel_id.channel_type == 'documentation' and slide.channel_id.allow_comment" class="text-muted mt4">
<div class="float-right mb16 text-right o_wslides_like">
<div class="float-right mb16 text-right o_wslides_js_slide_like">
<span
class="o_wslides_like_up"
class="o_wslides_js_slide_like_up"
t-att-data-slide-id="slide.id"
tabindex="0"
data-toggle="popover">
......@@ -200,7 +200,7 @@
<span t-esc="slide.likes"/>
</span>
<span
class="o_wslides_like_down"
class="o_wslides_js_slide_like_down"
t-att-data-slide-id="slide.id"
tabindex="0"
data-toggle="popover">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment