[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
This commit is contained in:
committed by
Thibault Delavallée
parent
12c6d77e7f
commit
1a8c0694c8
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user