V8: Fix and clean up the restore media dialog (#3781)
This commit is contained in:
committed by
Sebastiaan Janssen
parent
d431e80df2
commit
b173b41ce0
@@ -1,62 +1,74 @@
|
||||
angular.module("umbraco").controller("Umbraco.Editors.Media.RestoreController",
|
||||
function ($scope, relationResource, mediaResource, navigationService, appState, treeService, localizationService) {
|
||||
|
||||
var node = $scope.currentNode;
|
||||
$scope.source = _.clone($scope.currentNode);
|
||||
|
||||
$scope.error = null;
|
||||
$scope.success = false;
|
||||
$scope.loading = true;
|
||||
|
||||
relationResource.getByChildId(node.id, "relateParentDocumentOnDelete").then(function (data) {
|
||||
relationResource.getByChildId($scope.source.id, "relateParentDocumentOnDelete").then(function (data) {
|
||||
$scope.loading = false;
|
||||
|
||||
if (data.length == 0) {
|
||||
$scope.success = false;
|
||||
$scope.error = {
|
||||
errorMsg: localizationService.localize('recycleBin_itemCannotBeRestored'),
|
||||
data: {
|
||||
Message: localizationService.localize('recycleBin_noRestoreRelation')
|
||||
}
|
||||
}
|
||||
if (!data.length) {
|
||||
localizationService.localizeMany(["recycleBin_itemCannotBeRestored", "recycleBin_noRestoreRelation"])
|
||||
.then(function(values) {
|
||||
$scope.success = false;
|
||||
$scope.error = {
|
||||
errorMsg: values[0],
|
||||
data: {
|
||||
Message: values[1]
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.relation = data[0];
|
||||
|
||||
if ($scope.relation.parentId == -1) {
|
||||
if ($scope.relation.parentId === -1) {
|
||||
$scope.target = { id: -1, name: "Root" };
|
||||
|
||||
} else {
|
||||
$scope.loading = true;
|
||||
mediaResource.getById($scope.relation.parentId).then(function (data) {
|
||||
$scope.loading = false;
|
||||
$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);
|
||||
})
|
||||
}
|
||||
};
|
||||
// make sure the target item isn't in the recycle bin
|
||||
if ($scope.target.path.indexOf("-21") !== -1) {
|
||||
localizationService.localizeMany(["recycleBin_itemCannotBeRestored", "recycleBin_restoreUnderRecycled"])
|
||||
.then(function (values) {
|
||||
$scope.success = false;
|
||||
$scope.error = {
|
||||
errorMsg: values[0],
|
||||
data: {
|
||||
Message: values[1].replace('%0%', $scope.target.name)
|
||||
}
|
||||
}
|
||||
});
|
||||
$scope.success = false;
|
||||
}
|
||||
|
||||
}, function (err) {
|
||||
$scope.success = false;
|
||||
$scope.error = err;
|
||||
$scope.loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
}, function (err) {
|
||||
$scope.success = false;
|
||||
$scope.error = err;
|
||||
$scope.loading = false;
|
||||
});
|
||||
|
||||
$scope.restore = function () {
|
||||
$scope.loading = true;
|
||||
// this code was copied from `content.move.controller.js`
|
||||
mediaResource.move({ parentId: $scope.target.id, id: node.id })
|
||||
mediaResource.move({ parentId: $scope.target.id, id: $scope.source.id })
|
||||
.then(function (path) {
|
||||
|
||||
$scope.loading = false;
|
||||
$scope.success = true;
|
||||
|
||||
//first we need to remove the node that launched the dialog
|
||||
@@ -79,6 +91,7 @@ angular.module("umbraco").controller("Umbraco.Editors.Media.RestoreController",
|
||||
}, function (err) {
|
||||
$scope.success = false;
|
||||
$scope.error = err;
|
||||
$scope.loading = false;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -2,24 +2,32 @@
|
||||
<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>?
|
||||
<umb-load-indicator
|
||||
ng-show="loading">
|
||||
</umb-load-indicator>
|
||||
|
||||
<p class="abstract" ng-hide="loading || error != null || success">
|
||||
<localize key="actions_restore">Restore</localize> <strong>{{source.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 ng-show="error">
|
||||
<div class="alert alert-error">
|
||||
<div><strong>{{error.errorMsg}}</strong></div>
|
||||
<div>{{error.data.Message}}</div>
|
||||
</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>
|
||||
<div ng-show="success">
|
||||
<div class="alert alert-success">
|
||||
<strong>{{source.name}}</strong> <localize key="editdatatype_wasMoved">was moved underneath</localize> <strong>{{target.name}}</strong>
|
||||
</div>
|
||||
<button class="btn btn-primary" ng-click="close()"><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">
|
||||
<div class="umb-dialog-footer btn-toolbar umb-btn-toolbar" ng-hide="loading || success">
|
||||
<a class="btn btn-link" ng-click="close()"><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>
|
||||
|
||||
Reference in New Issue
Block a user