[IMP] website_slides: allow to delete slide category from frontend
- Before this commit, deleting slide category from frontend was not possible - After this commit, there is a 'trash' icon on the category while hovering on it (just like slides), clicking which will delete that category and reload the page to re-arragne the content. If there are slides under the category being deleted, they will be uncategorized and move to the top. Task: 2093671 Closes #49646 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
committed by
Dharmraj Jhala
parent
d7af73dcb1
commit
9fd602bffa
@@ -0,0 +1,79 @@
|
||||
odoo.define('website_slides.category.delete', function (require) {
|
||||
'use strict';
|
||||
|
||||
const publicWidget = require('web.public.widget');
|
||||
const Dialog = require('web.Dialog');
|
||||
const core = require('web.core');
|
||||
const _t = core._t;
|
||||
|
||||
const categoryDeleteDialog = Dialog.extend({
|
||||
template: 'slides.category.delete',
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Widget} parent
|
||||
* @param {DOM Object} slideTarget
|
||||
*/
|
||||
init(parent, slideTarget) {
|
||||
this.categoryId = parseInt(slideTarget.dataset.categoryId);
|
||||
this._super(parent, {
|
||||
title: _t('Delete Category'),
|
||||
size: 'medium',
|
||||
buttons: [{
|
||||
text: _t('Delete'),
|
||||
classes: 'btn-primary',
|
||||
click: () => this._onClickDelete(),
|
||||
}, {
|
||||
text: _t('Cancel'),
|
||||
close: true
|
||||
}]
|
||||
});
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Calls 'unlink' method on slides.slide to delete the category and
|
||||
* reloads page after deletion to re-arrange the content on UI
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_onClickDelete() {
|
||||
this._rpc({
|
||||
model: 'slide.slide',
|
||||
method: 'unlink',
|
||||
args: [this.categoryId],
|
||||
}).then(function () {
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
publicWidget.registry.websiteSlidesCategoryDelete = publicWidget.Widget.extend({
|
||||
selector: '.o_wslides_js_category_delete',
|
||||
xmlDependencies: ['/website_slides/static/src/xml/slide_management.xml'],
|
||||
events: {
|
||||
'click': '_onClickDeleteCateogry',
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {MouseEvent} ev
|
||||
*/
|
||||
_onClickDeleteCateogry(ev) {
|
||||
new categoryDeleteDialog(this, ev.currentTarget).open();
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
categoryDeleteDialog: categoryDeleteDialog,
|
||||
websiteSlidesCategoryDelete: publicWidget.registry.websiteSlidesCategoryDelete
|
||||
};
|
||||
|
||||
});
|
||||
@@ -379,6 +379,12 @@ $o-wslides-fs-side-width: 300px;
|
||||
& + ul {
|
||||
z-index: 0;
|
||||
}
|
||||
.o_wslides_js_category_delete {
|
||||
display: none;
|
||||
}
|
||||
&:hover .o_wslides_js_category_delete {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.o_text_link {
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="slides.category.delete">
|
||||
<div>
|
||||
<p>Are you sure you want to delete this category ?</p>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="slides.category.add">
|
||||
<div>
|
||||
<form action="/slides/category/add" method="POST" id="slide_category_add_form">
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
<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_category_delete.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_toggle_is_preview.js"/>
|
||||
<script type="text/javascript" src="/website_slides/static/src/js/slides_slide_like.js"/>
|
||||
|
||||
@@ -398,9 +398,17 @@
|
||||
<span t-if="category_id" t-field="category['category'].name"/>
|
||||
<small t-if="not category['total_slides'] and category_id" class="ml-1 text-muted"><b>(empty)</b></small>
|
||||
</div>
|
||||
<div t-if="category_id" class="o_text_link d-flex border-left">
|
||||
<div t-if="category_id" class="d-flex border-left">
|
||||
<a t-if="channel.can_publish"
|
||||
class="o_text_link text-danger o_wslides_js_category_delete px-3 py-2 border-right"
|
||||
role="button"
|
||||
aria-label="Delete Category"
|
||||
href="#"
|
||||
t-att-data-category-id="category_id">
|
||||
<i class="fa fa-trash"/>
|
||||
</a>
|
||||
<a t-if="channel.can_upload"
|
||||
class="o_wslides_js_slide_upload px-3 py-2"
|
||||
class="o_text_link o_wslides_js_slide_upload px-3 py-2"
|
||||
role="button"
|
||||
aria-label="Upload Presentation"
|
||||
href="#"
|
||||
|
||||
Reference in New Issue
Block a user