From 0e61eb79a81b83883e902c9a49eb936ff2289eff Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 27 Jun 2016 18:27:49 +0200 Subject: [PATCH] U4-8416 Empty recycle bin does not refresh or gives feedback to user --- .../content.emptyrecyclebin.controller.js | 21 ++++++++++++++++--- .../src/views/content/emptyrecyclebin.html | 17 +++++++++++---- .../src/views/media/emptyrecyclebin.html | 15 +++++++++++-- .../media/media.emptyrecyclebin.controller.js | 21 ++++++++++++++++--- src/Umbraco.Web/Editors/ContentController.cs | 3 ++- src/Umbraco.Web/Editors/MediaController.cs | 3 ++- .../WebApi/HttpRequestMessageExtensions.cs | 17 +++++++++++++++ 7 files changed, 83 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/content/content.emptyrecyclebin.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/content.emptyrecyclebin.controller.js index c81f2906d4..9077598424 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/content.emptyrecyclebin.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/content.emptyrecyclebin.controller.js @@ -6,18 +6,33 @@ * @description * The controller for deleting content */ -function ContentEmptyRecycleBinController($scope, contentResource, treeService, navigationService) { +function ContentEmptyRecycleBinController($scope, contentResource, treeService, navigationService, notificationsService, $route) { + + $scope.busy = false; $scope.performDelete = function() { //(used in the UI) + $scope.busy = true; $scope.currentNode.loading = true; - contentResource.emptyRecycleBin($scope.currentNode.id).then(function () { + contentResource.emptyRecycleBin($scope.currentNode.id).then(function (result) { + + $scope.busy = false; $scope.currentNode.loading = false; - //TODO: Need to sync tree, etc... + + //show any notifications + if (angular.isArray(result.notifications)) { + for (var i = 0; i < result.notifications.length; i++) { + notificationsService.showNotification(result.notifications[i]); + } + } + treeService.removeChildNodes($scope.currentNode); navigationService.hideMenu(); + + //reload the current view + $route.reload(); }); }; diff --git a/src/Umbraco.Web.UI.Client/src/views/content/emptyrecyclebin.html b/src/Umbraco.Web.UI.Client/src/views/content/emptyrecyclebin.html index bf2d7af543..0416b25520 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/emptyrecyclebin.html +++ b/src/Umbraco.Web.UI.Client/src/views/content/emptyrecyclebin.html @@ -1,8 +1,17 @@
-
- - - +
+ +
+
+
+

+ When items are deleted from the recycle bin, they will be gone forever. + Are you sure? +

+ + + +
diff --git a/src/Umbraco.Web.UI.Client/src/views/media/emptyrecyclebin.html b/src/Umbraco.Web.UI.Client/src/views/media/emptyrecyclebin.html index 5a05e9ca85..4558a21e2a 100644 --- a/src/Umbraco.Web.UI.Client/src/views/media/emptyrecyclebin.html +++ b/src/Umbraco.Web.UI.Client/src/views/media/emptyrecyclebin.html @@ -1,8 +1,19 @@
- - + +
+
+
+ +

+ When items are deleted from the recycle bin, they will be gone forever. + Are you sure? +

+ + + +
diff --git a/src/Umbraco.Web.UI.Client/src/views/media/media.emptyrecyclebin.controller.js b/src/Umbraco.Web.UI.Client/src/views/media/media.emptyrecyclebin.controller.js index dd6ceb369e..218654b464 100644 --- a/src/Umbraco.Web.UI.Client/src/views/media/media.emptyrecyclebin.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/media/media.emptyrecyclebin.controller.js @@ -6,18 +6,33 @@ * @description * The controller for deleting media */ -function MediaEmptyRecycleBinController($scope, mediaResource, treeService, navigationService) { +function MediaEmptyRecycleBinController($scope, mediaResource, treeService, navigationService, notificationsService, $route) { + + $scope.busy = false; $scope.performDelete = function() { //(used in the UI) + $scope.busy = true; $scope.currentNode.loading = true; - mediaResource.emptyRecycleBin($scope.currentNode.id).then(function () { + mediaResource.emptyRecycleBin($scope.currentNode.id).then(function (result) { + + $scope.busy = false; $scope.currentNode.loading = false; - //TODO: Need to sync tree, etc... + + //show any notifications + if (angular.isArray(result.notifications)) { + for (var i = 0; i < result.notifications.length; i++) { + notificationsService.showNotification(result.notifications[i]); + } + } + treeService.removeChildNodes($scope.currentNode); navigationService.hideMenu(); + + //reload the current view + $route.reload(); }); }; diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index 7abdaf7e69..d003636aac 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -462,7 +462,8 @@ namespace Umbraco.Web.Editors public HttpResponseMessage EmptyRecycleBin() { Services.ContentService.EmptyRecycleBin(); - return Request.CreateResponse(HttpStatusCode.OK); + + return Request.CreateNotificationSuccessResponse(Services.TextService.Localize("defaultdialogs/recycleBinIsEmpty")); } /// diff --git a/src/Umbraco.Web/Editors/MediaController.cs b/src/Umbraco.Web/Editors/MediaController.cs index c718f9ff38..4e3bf1a0ec 100644 --- a/src/Umbraco.Web/Editors/MediaController.cs +++ b/src/Umbraco.Web/Editors/MediaController.cs @@ -365,7 +365,8 @@ namespace Umbraco.Web.Editors public HttpResponseMessage EmptyRecycleBin() { Services.MediaService.EmptyRecycleBin(); - return Request.CreateResponse(HttpStatusCode.OK); + + return Request.CreateNotificationSuccessResponse(Services.TextService.Localize("defaultdialogs/recycleBinIsEmpty")); } /// diff --git a/src/Umbraco.Web/WebApi/HttpRequestMessageExtensions.cs b/src/Umbraco.Web/WebApi/HttpRequestMessageExtensions.cs index 04035c0017..00b66094e8 100644 --- a/src/Umbraco.Web/WebApi/HttpRequestMessageExtensions.cs +++ b/src/Umbraco.Web/WebApi/HttpRequestMessageExtensions.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using System.Web; using System.Web.Http; using System.Web.Http.ModelBinding; +using System.Web.Http.Results; using Microsoft.Owin; using Umbraco.Core; using Umbraco.Web.Models.ContentEditing; @@ -124,6 +125,22 @@ namespace Umbraco.Web.WebApi return request.CreateValidationErrorResponse(notificationModel); } + /// + /// Creates a succressful response with notifications in the result to be displayed in the UI + /// + /// + /// + /// + public static HttpResponseMessage CreateNotificationSuccessResponse(this HttpRequestMessage request, string successMessage) + { + var notificationModel = new SimpleNotificationModel + { + Message = successMessage + }; + notificationModel.AddSuccessNotification(successMessage, string.Empty); + return request.CreateResponse(HttpStatusCode.OK, notificationModel); + } + /// /// Create a 400 response message indicating that a validation error occurred ///