Skip to content
Snippets Groups Projects
Commit 1a8c0694 authored by Quentin Mourier's avatar Quentin Mourier Committed by Thibault Delavallée
Browse files

[FIX] website_slides: fix empty section flag display in frontend

Before this commit, empty sections were not flagged correctly whenever a slide
got archived or dragged to another section. This is due to the empty flag is
not updated accordingly.

Taskid: 2090927
X-original-commit: 43f05c0b92cf24812187490fb326fb6cfd9ca021
parent 12c6d77e
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,8 @@ odoo.define('website_slides.course.slides.list', function (require) {
'use strict';
var publicWidget = require('web.public.widget');
var core = require('web.core');
var _t = core._t;
publicWidget.registry.websiteSlidesCourseSlidesList = publicWidget.Widget.extend({
selector: '.o_wslides_slides_list',
......@@ -52,12 +54,18 @@ publicWidget.registry.websiteSlidesCourseSlidesList = publicWidget.Widget.extend
* @private
*/
_checkForEmptySections: function (){
this.$('.o_wslides_js_slides_list_container ul').each(function (){
var $emptyCategory = $(this).find('.o_wslides_js_slides_list_empty');
if ($(this).find('li.o_wslides_slides_list_slide[data-slide-id]').length === 0) {
$emptyCategory.removeClass('d-none').addClass('d-flex');
} else {
$emptyCategory.addClass('d-none').removeClass('d-flex');
this.$('.o_wslides_slide_list_category').each(function (){
var $categoryHeader = $(this).find('.o_wslides_slide_list_category_header');
var categorySlideCount = $(this).find('.o_wslides_slides_list_slide:not(.o_not_editable)').length;
var $emptyFlagContainer = $categoryHeader.find('.o_wslides_slides_list_drag').first();
var $emptyFlag = $emptyFlagContainer.find('small');
if (categorySlideCount === 0 && $emptyFlag.length === 0){
$emptyFlagContainer.append($('<small>', {
'class': "ml-1 text-muted font-weight-bold",
text: _t("(empty)")
}));
} else if (categorySlideCount > 0 && $emptyFlag.length > 0){
$emptyFlag.remove();
}
});
},
......@@ -77,6 +85,8 @@ publicWidget.registry.websiteSlidesCourseSlidesList = publicWidget.Widget.extend
model: "slide.slide",
ids: self._getSlides()
}
}).then(function (res) {
self._checkForEmptySections();
});
},
......
......@@ -30,6 +30,20 @@ var SlideArchiveDialog = Dialog.extend({
this.slideId = this.$slideTarget.data('slideId');
this._super(parent, options);
},
_checkForEmptySections: function (){
$('.o_wslides_slide_list_category').each(function (){
var $categoryHeader = $(this).find('.o_wslides_slide_list_category_header');
var categorySlideCount = $(this).find('.o_wslides_slides_list_slide:not(.o_not_editable)').length;
var $emptyFlagContainer = $categoryHeader.find('.o_wslides_slides_list_drag').first();
var $emptyFlag = $emptyFlagContainer.find('small');
if (categorySlideCount === 0 && $emptyFlag.length === 0){
$emptyFlagContainer.append($('<small>', {
'class': "ml-1 text-muted font-weight-bold",
text: _t("(empty)")
}));
}
});
},
//--------------------------------------------------------------------------
// Handlers
......@@ -46,8 +60,11 @@ var SlideArchiveDialog = Dialog.extend({
params: {
slide_id: this.slideId
},
}).then(function () {
self.$slideTarget.closest('.o_wslides_slides_list_slide').remove();
}).then(function (isArchived) {
if (isArchived){
self.$slideTarget.closest('.o_wslides_slides_list_slide').remove();
self._checkForEmptySections();
}
self.close();
});
}
......
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