Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big trash refactor #16600

Merged
merged 8 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion _build/data/transport.core.menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@
'action' => 'system/contenttype',
],
// endregion

// region: Trash
[
'text' => 'trash',
'description' => 'trash_desc',
'permissions' => 'menu_trash',
'action' => 'resource/trash',
],
// endregion
],
],
// endregion
Expand Down
6 changes: 0 additions & 6 deletions _build/templates/default/sass/_buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,6 @@ html.ext-strict body #modx-container .x-small-editor .x-form-text {
font-weight: 400;
}

.tree-trash > em > button:before {
@extend %pseudo-font;
content: fa-content($fa-var-trash-alt);
font-weight: 400;
}

/* alignment overrides */
#modx-leftbar .x-toolbar-ct .x-btn .tree-new-symlink > em > button {
top: 4px;
Expand Down
7 changes: 4 additions & 3 deletions _build/templates/default/sass/_tree.scss
Original file line number Diff line number Diff line change
Expand Up @@ -989,14 +989,15 @@
#modx-leftbar-tabpanel__modx-trash-link {
.icon {
opacity: .5;
&:hover {
color: $red;
}
}

&.active {
.icon {
opacity: 1;
}

&:hover .icon {
color: $red;
}
}
}
11 changes: 10 additions & 1 deletion _build/templates/default/sass/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ a.x-grid-link:focus {
background: scale-color($color: $red, $saturation: -10%, $lightness: 94%);
font-weight: 400;
}
// The "Call Stack" header row
// The "Call Stack" header row
&[bgcolor^="#e9b"] {
background: $colorSplash;
color: $white !important;
Expand Down Expand Up @@ -1685,6 +1685,15 @@ iframe[classname="x-hidden"] {
color: $green;
}

#modx-abtn-purge {
background-color: $red;
color: $white;

&:hover {
background-color: darken($red, 10%);
}
}

#modx-abtn-help {
color: $colorSplash;
}
Expand Down
2 changes: 2 additions & 0 deletions core/lexicon/en/resource.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
$_lang['resource_createdon'] = 'Created On';
$_lang['resource_delete'] = 'Delete';
$_lang['resource_delete_confirm'] = 'Are you sure you want to delete the resource: "[[+resource]]"?<br />NOTE: Any child resources will also be deleted!';
$_lang['resource_purge'] = 'Erase resource';
theboxer marked this conversation as resolved.
Show resolved Hide resolved
$_lang['resource_purge_confirm'] = 'Do you really want to finally erase the following resource: "[[+resource]]"?<br />WARNING: This cannot be undone.';
$_lang['resource_description'] = 'Description';
$_lang['resource_description_help'] = 'This is an optional description of the resource.';
$_lang['resource_duplicate'] = 'Duplicate';
Expand Down
2 changes: 2 additions & 0 deletions core/lexicon/en/topmenu.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
$_lang['tools_desc'] = 'Utilities to keep your site sorted';
$_lang['topnav'] = 'Main Navigation';
$_lang['topnav_desc'] = '';
$_lang['trash'] = 'Trash';
$_lang['trash_desc'] = 'Manage deleted resources.';
$_lang['user'] = 'User';
$_lang['usernav'] = 'User Navigation';
$_lang['usernav_desc'] = '';
Expand Down
2 changes: 1 addition & 1 deletion core/lexicon/en/trash.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
$_lang['trash.restore_all'] = 'Restore all';
$_lang['trash.selected_purge'] = 'Erase selected resources';
$_lang['trash.selected_restore'] = 'Restore selected resources';
$_lang['trash.purge'] = 'Erase resource';
$_lang['trash.purge'] = 'Erase';
$_lang['trash.purge_confirm_title'] = 'Erase resource(s)?';
$_lang['trash.purge_confirm_message'] = 'Do you really want to finally erase the following resource(s)? This cannot be undone.<hr>[[+list]]';
$_lang['trash.purge_all_confirm_message'] = 'Do you really want to finally erase the listed [[+count]] resource(s)?<br><br><strong>This cannot be undone, and it affects all currently trashed resources in the grid.</strong><hr>[[+list]]';
Expand Down
1 change: 1 addition & 0 deletions core/src/Revolution/Processors/Resource/GetNodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function prepare()
'edit_document' => $this->modx->hasPermission('edit_document') ? 'pedit' : '',
'delete_document' => $this->modx->hasPermission('delete_document') ? 'pdelete' : '',
'undelete_document' => $this->modx->hasPermission('undelete_document') ? 'pundelete' : '',
'purge_deleted' => $this->modx->hasPermission('purge_deleted') ? 'ppurge' : '',
'publish_document' => $this->modx->hasPermission('publish_document') ? 'ppublish' : '',
'unpublish_document' => $this->modx->hasPermission('unpublish_document') ? 'punpublish' : '',
'resource_duplicate' => $this->modx->hasPermission('resource_duplicate') ? 'pduplicate' : '',
Expand Down
4 changes: 1 addition & 3 deletions core/src/Revolution/Processors/Resource/GetToolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,10 @@ public function process()

$items[] = [
'id' => 'emptifier',
'cls' => 'tree-trash',
'tooltip' => $this->modx->lexicon('trash.manage_recycle_bin_tooltip', [
'count' => $deletedResources
]),
'disabled' => ($deletedResources == 0) ? true : false,
'handler' => 'new Function("this.redirect(\"?a=resource/trash\");");'
'disabled' => $deletedResources === 0
];
}

Expand Down
5 changes: 4 additions & 1 deletion core/src/Revolution/Processors/Resource/Trash/Purge.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,12 @@ public function process()
}
}

$deletedCount = $this->modx->getCount(modResource::class, ['deleted' => 1]);

return $this->success($msg, [
'count_success' => count($success),
'count_failures' => count($this->failures)
'count_failures' => count($this->failures),
'deletedCount' => $deletedCount,
]);
}
}
1 change: 1 addition & 0 deletions core/src/Revolution/modManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function prepareLanguage()
{
$this->modx->lexicon->load('action');
$languageTopics = $this->getLanguageTopics();
$languageTopics[] = 'trash';
foreach ($languageTopics as $topic) {
$this->modx->lexicon->load($topic);
}
Expand Down
23 changes: 20 additions & 3 deletions manager/assets/modext/core/modx.layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ Ext.extend(MODx.Layout, Ext.Viewport, {
,listeners: {
afterrender: function() {
const baseTabs = this,
header = Ext.get('modx-leftbar-header')
header = Ext.get('modx-leftbar-header')
;
MODx.Ajax.request({
url: MODx.config.connector_url,
Expand All @@ -313,8 +313,25 @@ Ext.extend(MODx.Layout, Ext.Viewport, {
if (trashTrigger) {
const trashTab = baseTabs.add({
id: 'modx-trash-link',
title: '<i class="icon icon-trash-o"></i>',
handler: trashTrigger.handler
title: '<a href="?resource/trash"><i class="icon icon-trash-o"></i></a>',
updateState(deletedCount = 0) {
const tab = this;
const tabEl = tab.tabEl;
const tooltipTarget = new Ext.Element(tabEl);

if (deletedCount === 0) {
tab.disable();
tabEl.classList.remove('active');
} else {
tab.enable();
tabEl.classList.add('active');
}

tab.tooltip = new Ext.ToolTip({
target: tooltipTarget,
title: _('trash.manage_recycle_bin_tooltip', { count: deletedCount }),
});
},
});
if (!trashTrigger.disabled) {
trashTab.tabEl.classList.add('active');
Expand Down
2 changes: 1 addition & 1 deletion manager/assets/modext/modx.jsgrps-min.js

Large diffs are not rendered by default.

76 changes: 61 additions & 15 deletions manager/assets/modext/sections/resource/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,35 +107,71 @@ Ext.extend(MODx.page.UpdateResource,MODx.Component,{
}
,listeners: {
success: {fn:function(r) {
var panel = Ext.getCmp('modx-panel-resource');
const panel = Ext.getCmp('modx-panel-resource');
if (panel) {
panel.handlePreview(true);
panel.handleDeleted(true);
}

Ext.getCmp('modx-resource-tree')?.refresh();
Ext.getCmp('modx-trash-link')?.updateState(+r.object.deletedCount);
},scope:this}
}
});
}

,unDeleteResource: function(btn,e) {
,unDeleteResource: function() {
MODx.Ajax.request({
url: MODx.config.connector_url
,params: {
action: 'Resource/Undelete'
,id: this.config.resource
}
,listeners: {
success: {fn:function(r) {
var panel = Ext.getCmp('modx-panel-resource');
if (panel) {
panel.handlePreview(false);
panel.handleDeleted(false);
}
},scope:this}
url: MODx.config.connector_url,
params: {
action: 'Resource/Undelete',
id: this.config.resource,
},
listeners: {
success: {
fn: function(r) {
const panel = Ext.getCmp('modx-panel-resource');
if (panel) {
panel.handlePreview(false);
panel.handleDeleted(false);
}

const tree = Ext.getCmp('modx-resource-tree');
if (tree?.rendered) {
tree.refresh();
}

Ext.getCmp('modx-trash-link')?.updateState(+r.object.deletedCount);
},
scope: this,
}
}
});
}

,purgeResource: function() {
MODx.msg.confirm({
text: _('resource_purge_confirm', {
resource: Ext.util.Format.htmlEncode(this.config.record.pagetitle) + ' ('+ this.config.resource + ')'
}),
url: MODx.config.connector_url,
params: {
action: 'Resource/Trash/Purge',
ids: this.config.resource,
},
listeners: {
success: {
fn: function() {
const fp = Ext.getCmp(this.config.formpanel);
fp.warnUnsavedChanges = false;
MODx.loadPage('?');
},
scope: this,
},
},
});
}

,cancel: function(btn,e) {
var fp = Ext.getCmp(this.config.formpanel);
if (fp && fp.isDirty()) {
Expand Down Expand Up @@ -213,6 +249,16 @@ Ext.extend(MODx.page.UpdateResource,MODx.Component,{
});
}

if (config.canPurge == 1 && !config.locked) {
buttons.push({
text: '<i class="icon icon-remove"></i>',
id: 'modx-abtn-purge',
handler: this.purgeResource,
hidden: !config.record.deleted,
scope: this,
});
}

buttons.push({
text: '<i class="icon icon-question-circle"></i>'
,id: 'modx-abtn-help'
Expand Down
22 changes: 2 additions & 20 deletions manager/assets/modext/widgets/resource/modx.grid.trash.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Ext.extend(MODx.grid.Trash, MODx.grid.Grid, {
'success': {
fn: function (data) {
this.getSelectionModel().clearSelections(true);
this.refreshEverything(data.total);
this.refreshEverything(data.object.deletedCount);
}, scope: this
},
'error': {
Expand Down Expand Up @@ -404,25 +404,7 @@ Ext.extend(MODx.grid.Trash, MODx.grid.Grid, {
},

refreshRecycleBinButton: function (total) {
var trashButton = Ext.getCmp('modx-trash-link');

if (total !== undefined) {
// if no resource is deleted, we disable the icon.
// otherwise we have to update the tooltip
if (total == 0) {
trashButton.disable();
trashButton.tooltip = new Ext.ToolTip({
target: trashButton.tabEl,
title: _('trash.manage_recycle_bin_tooltip')
});
} else {
trashButton.enable();
trashButton.tooltip = new Ext.ToolTip({
target: trashButton.tabEl,
title: _('trash.manage_recycle_bin_tooltip', {count: total})
});
}
}
Ext.getCmp('modx-trash-link')?.updateState(+total);
},

listResources: function (separator) {
Expand Down
38 changes: 22 additions & 16 deletions manager/assets/modext/widgets/resource/modx.panel.resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,30 @@ Ext.extend(MODx.panel.Resource,MODx.FormPanel,{
}
}

,handleDeleted: function(deleted) {
if (this.config.canDelete == 1 && !this.config.locked) {
var deleteBtn = Ext.getCmp('modx-abtn-delete');
var unDeleteBtn = Ext.getCmp('modx-abtn-undelete');
var deleteChk = Ext.getCmp('modx-resource-deleted');
if (deleteBtn && unDeleteBtn) {
if (deleted) {
deleteBtn.hide();
unDeleteBtn.show();
} else {
unDeleteBtn.hide();
deleteBtn.show();
}
}
if (deleteChk) {
deleteChk.setValue(deleted);
,handleDeleted: function(isDeleted) {
const canDelete = this.config.canDelete === 1 && !this.config.locked;

if (!canDelete) {
return;
}

const deleteButton = Ext.getCmp('modx-abtn-delete');
const unDeleteButton = Ext.getCmp('modx-abtn-undelete');
const purgeButton = Ext.getCmp('modx-abtn-purge');

if (deleteButton && unDeleteButton && purgeButton) {
if (isDeleted) {
deleteButton.hide();
purgeButton.show();
unDeleteButton.show();
} else {
deleteButton.show();
purgeButton.hide();
unDeleteButton.hide();
}
}

Ext.getCmp('modx-resource-deleted')?.setValue(isDeleted);
}

,updateTree: function() {
Expand Down
Loading
Loading