diff --git a/src/Umbraco.Core/Services/ContentTypeService.cs b/src/Umbraco.Core/Services/ContentTypeService.cs index 418a1cd527..91a0a45cfb 100644 --- a/src/Umbraco.Core/Services/ContentTypeService.cs +++ b/src/Umbraco.Core/Services/ContentTypeService.cs @@ -156,6 +156,11 @@ namespace Umbraco.Core.Services return RenameTypeContainer(id, name, Constants.ObjectTypes.MediaTypeContainerGuid); } + public Attempt> RenameDataTypeContainer(int id, string name, int userId = 0) + { + return RenameTypeContainer(id, name, Constants.ObjectTypes.MediaTypeContainerGuid); + } + public Attempt SaveContentTypeContainer(EntityContainer container, int userId = 0) { return SaveContainer( @@ -253,7 +258,7 @@ namespace Umbraco.Core.Services public IEnumerable GetMediaTypeContainers(IMediaType mediaType) { - var ancestorIds = mediaType.Path.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries) + var ancestorIds = mediaType.Path.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => { var asInt = x.TryConvertTo(); @@ -282,7 +287,7 @@ namespace Umbraco.Core.Services public IEnumerable GetContentTypeContainers(IContentType contentType) { - var ancestorIds = contentType.Path.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries) + var ancestorIds = contentType.Path.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => { var asInt = x.TryConvertTo(); @@ -479,7 +484,7 @@ namespace Umbraco.Core.Services clone.Name = name; - var compositionAliases = clone.CompositionAliases().Except(new[] {alias}).ToList(); + var compositionAliases = clone.CompositionAliases().Except(new[] { alias }).ToList(); //remove all composition that is not it's current alias foreach (var a in compositionAliases) { @@ -902,7 +907,7 @@ namespace Umbraco.Core.Services { using (var uow = UowProvider.GetUnitOfWork()) { - var deleteEventArgs = new DeleteEventArgs(contentType); + var deleteEventArgs = new DeleteEventArgs(contentType); if (uow.Events.DispatchCancelable(DeletingContentType, this, deleteEventArgs)) { uow.Commit(); @@ -912,7 +917,7 @@ namespace Umbraco.Core.Services var repository = RepositoryFactory.CreateContentTypeRepository(uow); //If we are deleting this content type, we are also deleting it's descendents! - var deletedContentTypes = new List {contentType}; + var deletedContentTypes = new List { contentType }; deletedContentTypes.AddRange(GetDescendants(contentType)); _contentService.DeleteContentOfTypes(deletedContentTypes.Select(x => x.Id), userId); diff --git a/src/Umbraco.Core/Services/IContentTypeService.cs b/src/Umbraco.Core/Services/IContentTypeService.cs index 0e80526b93..c6fbb14b02 100644 --- a/src/Umbraco.Core/Services/IContentTypeService.cs +++ b/src/Umbraco.Core/Services/IContentTypeService.cs @@ -30,6 +30,7 @@ namespace Umbraco.Core.Services Attempt> CreateContentTypeContainer(int parentId, string name, int userId = 0); Attempt> RenameContentTypeContainer(int id, string name, int userId = 0); + Attempt> RenameDataTypeContainer(int id, string name, int userId = 0); Attempt> CreateMediaTypeContainer(int parentId, string name, int userId = 0); Attempt SaveContentTypeContainer(EntityContainer container, int userId = 0); Attempt SaveMediaTypeContainer(EntityContainer container, int userId = 0); diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/datatype.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/datatype.resource.js index 7bc65c89a6..bb81ab1e9d 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/datatype.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/datatype.resource.js @@ -357,6 +357,14 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) { "PostCreateContainer", { parentId: parentId, name: name })), 'Failed to create a folder under parent id ' + parentId); + }, + + renameContainer: function(id, name) { + return umbRequestHelper.resourcePromise( + http.post(umbRequestHelper.getApiUrl("dataTypeApiBaseUrl", + "PostRenameContainer", + { id: id, name: name })), + "Failed to rename the folder with id " + id); } }; } diff --git a/src/Umbraco.Web.UI.Client/src/views/datatypes/rename.html b/src/Umbraco.Web.UI.Client/src/views/datatypes/rename.html new file mode 100644 index 0000000000..6840e58565 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/datatypes/rename.html @@ -0,0 +1,22 @@ + + diff --git a/src/Umbraco.Web/Editors/DataTypeController.cs b/src/Umbraco.Web/Editors/DataTypeController.cs index 522c1f2b48..d42b158cfb 100644 --- a/src/Umbraco.Web/Editors/DataTypeController.cs +++ b/src/Umbraco.Web/Editors/DataTypeController.cs @@ -22,8 +22,8 @@ using System.Net.Http; using System.Text; namespace Umbraco.Web.Editors -{ - +{ + /// /// The API controller used for editing data types /// @@ -75,8 +75,8 @@ namespace Umbraco.Web.Editors if (foundType == null) { throw new HttpResponseException(HttpStatusCode.NotFound); - } - + } + Services.DataTypeService.Delete(foundType, Security.CurrentUser.Id); return Request.CreateResponse(HttpStatusCode.OK); @@ -111,17 +111,17 @@ namespace Umbraco.Web.Editors /// public DataTypeDisplay PostCreateCustomListView(string contentTypeAlias) { - var dt = Services.DataTypeService.GetDataTypeDefinitionByName(Constants.Conventions.DataTypes.ListViewPrefix + contentTypeAlias); - - //if it doesnt exist yet, we will create it. + var dt = Services.DataTypeService.GetDataTypeDefinitionByName(Constants.Conventions.DataTypes.ListViewPrefix + contentTypeAlias); + + //if it doesnt exist yet, we will create it. if (dt == null) { - dt = new DataTypeDefinition( Constants.PropertyEditors.ListViewAlias ); + dt = new DataTypeDefinition(Constants.PropertyEditors.ListViewAlias); dt.Name = Constants.Conventions.DataTypes.ListViewPrefix + contentTypeAlias; Services.DataTypeService.Save(dt); } - return Mapper.Map(dt); + return Mapper.Map(dt); } /// @@ -161,7 +161,7 @@ namespace Umbraco.Web.Editors } //these are new pre-values, so just return the field editors with default values - return Mapper.Map>(propEd); + return Mapper.Map>(propEd); } /// @@ -243,31 +243,40 @@ namespace Umbraco.Web.Editors return Request.CreateResponse(HttpStatusCode.NotFound); } - var result = Services.DataTypeService.Move(toMove, move.ParentId); - if (result.Success) - { - var response = Request.CreateResponse(HttpStatusCode.OK); - response.Content = new StringContent(toMove.Path, Encoding.UTF8, "application/json"); - return response; - } - - switch (result.Result.StatusType) - { - case MoveOperationStatusType.FailedParentNotFound: - return Request.CreateResponse(HttpStatusCode.NotFound); + var result = Services.DataTypeService.Move(toMove, move.ParentId); + if (result.Success) + { + var response = Request.CreateResponse(HttpStatusCode.OK); + response.Content = new StringContent(toMove.Path, Encoding.UTF8, "application/json"); + return response; + } + + switch (result.Result.StatusType) + { + case MoveOperationStatusType.FailedParentNotFound: + return Request.CreateResponse(HttpStatusCode.NotFound); case MoveOperationStatusType.FailedCancelledByEvent: //returning an object of INotificationModel will ensure that any pending // notification messages are added to the response. - return Request.CreateValidationErrorResponse(new SimpleNotificationModel()); - case MoveOperationStatusType.FailedNotAllowedByPath: + return Request.CreateValidationErrorResponse(new SimpleNotificationModel()); + case MoveOperationStatusType.FailedNotAllowedByPath: var notificationModel = new SimpleNotificationModel(); - notificationModel.AddErrorNotification(Services.TextService.Localize("moveOrCopy/notAllowedByPath"), ""); + notificationModel.AddErrorNotification(Services.TextService.Localize("moveOrCopy/notAllowedByPath"), ""); return Request.CreateValidationErrorResponse(notificationModel); - default: - throw new ArgumentOutOfRangeException(); + default: + throw new ArgumentOutOfRangeException(); } } + public HttpResponseMessage PostRenameContainer(int id, string name) + { + var result = Services.ContentTypeService.RenameDataTypeContainer(id, name, Security.CurrentUser.Id); + + return result + ? Request.CreateResponse(HttpStatusCode.OK, result.Result) + : Request.CreateNotificationValidationErrorResponse(result.Exception.Message); + } + #region ReadOnly actions to return basic data - allow access for: content ,media, members, settings, developer /// /// Gets the content json for all data types @@ -308,7 +317,7 @@ namespace Umbraco.Web.Editors foreach (var dataType in dataTypes) { var propertyEditor = propertyEditors.SingleOrDefault(x => x.Alias == dataType.Alias); - if(propertyEditor != null) + if (propertyEditor != null) dataType.HasPrevalues = propertyEditor.PreValueEditor.Fields.Any(); ; } @@ -331,8 +340,8 @@ namespace Umbraco.Web.Editors Constants.Applications.Settings, Constants.Applications.Developer)] public IDictionary> GetGroupedPropertyEditors() { - var datatypes = new List(); - + var datatypes = new List(); + var propertyEditors = PropertyEditorResolver.Current.PropertyEditors; foreach (var propertyEditor in propertyEditors) {