U4-10681 Restore option in media recycle bin (#2342)
This commit is contained in:
committed by
Sebastiaan Janssen
parent
c0cdf727ca
commit
60910efc53
@@ -1,5 +1,5 @@
|
||||
angular.module("umbraco").controller("Umbraco.Editors.Content.RestoreController",
|
||||
function ($scope, relationResource, contentResource, navigationService, appState, treeService) {
|
||||
function ($scope, relationResource, contentResource, navigationService, appState, treeService, localizationService) {
|
||||
var dialogOptions = $scope.dialogOptions;
|
||||
|
||||
var node = dialogOptions.currentNode;
|
||||
@@ -12,9 +12,9 @@ angular.module("umbraco").controller("Umbraco.Editors.Content.RestoreController"
|
||||
if (data.length == 0) {
|
||||
$scope.success = false;
|
||||
$scope.error = {
|
||||
errorMsg: "Cannot automatically restore this item",
|
||||
errorMsg: localizationService.localize('recycleBin_itemCannotBeRestored'),
|
||||
data: {
|
||||
Message: "There is no 'restore' relation found for this node. Use the Move menu item to move it manually."
|
||||
Message: localizationService.localize('recycleBin_noRestoreRelation')
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -32,9 +32,11 @@ angular.module("umbraco").controller("Umbraco.Editors.Content.RestoreController"
|
||||
// make sure the target item isn't in the recycle bin
|
||||
if($scope.target.path.indexOf("-20") !== -1) {
|
||||
$scope.error = {
|
||||
errorMsg: "Cannot automatically restore this item",
|
||||
errorMsg: localizationService.localize('recycleBin_itemCannotBeRestored'),
|
||||
data: {
|
||||
Message: "The item you want to restore it under (" + $scope.target.name + ") is in the recycle bin. Use the Move menu item to move the item manually."
|
||||
Message: localizationService.localize('recycleBin_restoreUnderRecycled').then(function (value) {
|
||||
value.replace('%0%', $scope.target.name);
|
||||
})
|
||||
}
|
||||
};
|
||||
$scope.success = false;
|
||||
@@ -80,4 +82,4 @@ angular.module("umbraco").controller("Umbraco.Editors.Content.RestoreController"
|
||||
$scope.error = err;
|
||||
});
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
<div class="umb-dialog-body">
|
||||
<umb-pane>
|
||||
|
||||
<p class="abstract" ng-hide="error != null || success == true">
|
||||
Restore <strong>{{currentNode.name}}</strong> under <strong>{{target.name}}</strong>?
|
||||
</p>
|
||||
<p class="abstract" ng-hide="error != null || success == true">
|
||||
<localize key="actions_restore">Restore</localize> <strong>{{currentNode.name}}</strong> <localize key="general_under">under</localize> <strong>{{target.name}}</strong>?
|
||||
</p>
|
||||
|
||||
<div class="alert alert-error" ng-show="error != null">
|
||||
<div><strong>{{error.errorMsg}}</strong></div>
|
||||
@@ -12,15 +12,15 @@
|
||||
</div>
|
||||
|
||||
<div class="alert alert-success" ng-show="success == true">
|
||||
<p><strong>{{currentNode.name}}</strong> was moved underneath <strong>{{target.name}}</strong></p>
|
||||
<button class="btn btn-primary" ng-click="nav.hideDialog()">OK</button>
|
||||
<p><strong>{{currentNode.name}}</strong> <localize key="editdatatype_wasMoved">was moved underneath</localize> <strong>{{target.name}}</strong></p>
|
||||
<button class="btn btn-primary" ng-click="nav.hideDialog()"><localize key="general_ok">OK</localize></button>
|
||||
</div>
|
||||
|
||||
</umb-pane>
|
||||
</div>
|
||||
|
||||
<div class="umb-dialog-footer btn-toolbar umb-btn-toolbar" ng-hide="success == true">
|
||||
<a class="btn btn-link" ng-click="nav.hideDialog()">Cancel</a>
|
||||
<button class="btn btn-primary" ng-click="restore()" ng-show="error == null">Restore</button>
|
||||
<a class="btn btn-link" ng-click="nav.hideDialog()"><localize key="general_cancel">Cancel</localize></a>
|
||||
<button class="btn btn-primary" ng-click="restore()" ng-show="error == null"><localize key="actions_restore">Restore</localize></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
angular.module("umbraco").controller("Umbraco.Editors.Media.RestoreController",
|
||||
function ($scope, relationResource, mediaResource, navigationService, appState, treeService, localizationService) {
|
||||
var dialogOptions = $scope.dialogOptions;
|
||||
|
||||
var node = dialogOptions.currentNode;
|
||||
|
||||
$scope.error = null;
|
||||
$scope.success = false;
|
||||
|
||||
relationResource.getByChildId(node.id, "relateParentDocumentOnDelete").then(function (data) {
|
||||
|
||||
if (data.length == 0) {
|
||||
$scope.success = false;
|
||||
$scope.error = {
|
||||
errorMsg: localizationService.localize('recycleBin_itemCannotBeRestored'),
|
||||
data: {
|
||||
Message: localizationService.localize('recycleBin_noRestoreRelation')
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.relation = data[0];
|
||||
|
||||
if ($scope.relation.parentId == -1) {
|
||||
$scope.target = { id: -1, name: "Root" };
|
||||
|
||||
} else {
|
||||
mediaResource.getById($scope.relation.parentId).then(function (data) {
|
||||
$scope.target = data;
|
||||
|
||||
// make sure the target item isn't in the recycle bin
|
||||
if ($scope.target.path.indexOf("-20") !== -1) {
|
||||
$scope.error = {
|
||||
errorMsg: localizationService.localize('recycleBin_itemCannotBeRestored'),
|
||||
data: {
|
||||
Message: localizationService.localize('recycleBin_restoreUnderRecycled').then(function (value) {
|
||||
value.replace('%0%', $scope.target.name);
|
||||
})
|
||||
}
|
||||
};
|
||||
$scope.success = false;
|
||||
}
|
||||
|
||||
}, function (err) {
|
||||
$scope.success = false;
|
||||
$scope.error = err;
|
||||
});
|
||||
}
|
||||
|
||||
}, function (err) {
|
||||
$scope.success = false;
|
||||
$scope.error = err;
|
||||
});
|
||||
|
||||
$scope.restore = function () {
|
||||
// this code was copied from `content.move.controller.js`
|
||||
mediaResource.move({ parentId: $scope.target.id, id: node.id })
|
||||
.then(function (path) {
|
||||
|
||||
$scope.success = true;
|
||||
|
||||
//first we need to remove the node that launched the dialog
|
||||
treeService.removeNode($scope.currentNode);
|
||||
|
||||
//get the currently edited node (if any)
|
||||
var activeNode = appState.getTreeState("selectedNode");
|
||||
|
||||
//we need to do a double sync here: first sync to the moved media item - but don't activate the node,
|
||||
//then sync to the currenlty edited media item (note: this might not be the media item that was moved!!)
|
||||
|
||||
navigationService.syncTree({ tree: "media", path: path, forceReload: true, activate: false }).then(function (args) {
|
||||
if (activeNode) {
|
||||
var activeNodePath = treeService.getPath(activeNode).join();
|
||||
//sync to this node now - depending on what was copied this might already be synced but might not be
|
||||
navigationService.syncTree({ tree: "media", path: activeNodePath, forceReload: false, activate: true });
|
||||
}
|
||||
});
|
||||
|
||||
}, function (err) {
|
||||
$scope.success = false;
|
||||
$scope.error = err;
|
||||
});
|
||||
};
|
||||
});
|
||||
26
src/Umbraco.Web.UI.Client/src/views/media/restore.html
Normal file
26
src/Umbraco.Web.UI.Client/src/views/media/restore.html
Normal file
@@ -0,0 +1,26 @@
|
||||
<div ng-controller="Umbraco.Editors.Media.RestoreController">
|
||||
<div class="umb-dialog-body">
|
||||
<umb-pane>
|
||||
|
||||
<p class="abstract" ng-hide="error != null || success == true">
|
||||
<localize key="actions_restore">Restore</localize> <strong>{{currentNode.name}}</strong> <localize key="general_under">under</localize> <strong>{{target.name}}</strong>?
|
||||
</p>
|
||||
|
||||
<div class="alert alert-error" ng-show="error != null">
|
||||
<div><strong>{{error.errorMsg}}</strong></div>
|
||||
<div>{{error.data.Message}}</div>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-success" ng-show="success == true">
|
||||
<p><strong>{{currentNode.name}}</strong> <localize key="editdatatype_wasMoved">was moved underneath</localize> <strong>{{target.name}}</strong></p>
|
||||
<button class="btn btn-primary" ng-click="nav.hideDialog()"><localize key="general_ok">OK</localize></button>
|
||||
</div>
|
||||
|
||||
</umb-pane>
|
||||
</div>
|
||||
|
||||
<div class="umb-dialog-footer btn-toolbar umb-btn-toolbar" ng-hide="success == true">
|
||||
<a class="btn btn-link" ng-click="nav.hideDialog()"><localize key="general_cancel">Cancel</localize></a>
|
||||
<button class="btn btn-primary" ng-click="restore()" ng-show="error == null"><localize key="actions_restore">Restore</localize></button>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user