[IMP] website: add 'Delete Page' button in page properties dialog

With this commit, it is now possible to delete a page directly from it's page
properties dialog.

Before this commit, you had to go into the page manager and then find your page
that could take some time.

task-1850578
Closes #24861
This commit is contained in:
Romain Derie
2018-05-24 10:54:16 +02:00
parent c9b7cf140c
commit 683b432315
+54 -28
View File
@@ -55,6 +55,14 @@ var PagePropertiesDialog = weWidgets.Dialog.extend({
},
});
}
buttons.push({
text: _t("Delete Page"),
icon: 'fa-trash',
classes: 'btn-link pull-right',
click: function (e) {
_deletePage.call(this, self.page_id, options.fromPageManagement);
},
});
this._super(parent, _.extend({}, {
title: _t("Page Properties"),
size: 'medium',
@@ -136,7 +144,6 @@ var PagePropertiesDialog = weWidgets.Dialog.extend({
});
}));
var l10n = _t.database.parameters;
var datepickersOptions = {
minDate: moment({y: 1900}),
maxDate: moment().add(200, 'y'),
@@ -761,36 +768,55 @@ var PageManagement = Widget.extend({
},
_onDeletePageButtonClick: function (ev) {
var pageId = $(ev.currentTarget).data('id');
var self = this;
var context = weContext.get();
var def = $.Deferred();
// Search the page dependencies
this._getPageDependencies(pageId, context)
.then(function (dependencies) {
// Inform the user about those dependencies and ask him confirmation
var confirmDef = $.Deferred();
Dialog.safeConfirm(self, "", {
title: _t("Delete Page"),
$content: $(qweb.render('website.delete_page', {dependencies: dependencies})),
confirm_callback: confirmDef.resolve.bind(confirmDef),
cancel_callback: def.resolve.bind(self),
});
return confirmDef;
}).then(function () {
// Delete the page if the user confirmed
return self._rpc({
model: 'website.page',
method: 'delete_page',
args: [pageId],
context: context,
});
}).then(function () {
window.location.reload(true);
}, def.reject.bind(def));
_deletePage.call(this, pageId, true);
},
});
/**
* Deletes the page after showing a dependencies warning for the given page id.
*
* @private
* @param {integer} pageId - The ID of the page to be deleted
* @param {Boolean} fromPageManagement
* Is the function called by the page manager?
* It will affect redirect after page deletion: reload or '/'
*/
// TODO: This function should be integrated in a widget in the future
function _deletePage(pageId, fromPageManagement) {
var self = this;
var context = weContext.get();
var def = $.Deferred();
// Search the page dependencies
this._getPageDependencies(pageId, context)
.then(function (dependencies) {
// Inform the user about those dependencies and ask him confirmation
var confirmDef = $.Deferred();
Dialog.safeConfirm(self, "", {
title: _t("Delete Page"),
$content: $(qweb.render('website.delete_page', {dependencies: dependencies})),
confirm_callback: confirmDef.resolve.bind(confirmDef),
cancel_callback: def.resolve.bind(self),
});
return confirmDef;
}).then(function () {
// Delete the page if the user confirmed
return self._rpc({
model: 'website.page',
method: 'delete_page',
args: [pageId],
context: context,
});
}).then(function () {
if (fromPageManagement) {
window.location.reload(true);
}
else {
window.location.href = '/';
}
}, def.reject.bind(def));
}
websiteNavbarData.websiteNavbarRegistry.add(ContentMenu, '#content-menu');
websiteRootData.websiteRootRegistry.add(PageManagement, '#edit_website_pages');