diff --git a/src/Umbraco.Core/Services/ContentTypeService.cs b/src/Umbraco.Core/Services/ContentTypeService.cs index 418a1cd527..7de374b140 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.DataTypeContainerGuid); + } + 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..11b6969479 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 @@ -35,12 +35,12 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) { } return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "dataTypeApiBaseUrl", - "GetPreValues", - [{ editorAlias: editorAlias }, { dataTypeId: dataTypeId }])), - "Failed to retrieve pre values for editor alias " + editorAlias); + $http.get( + umbRequestHelper.getApiUrl( + "dataTypeApiBaseUrl", + "GetPreValues", + [{ editorAlias: editorAlias }, { dataTypeId: dataTypeId }])), + "Failed to retrieve pre values for editor alias " + editorAlias); }, /** @@ -66,12 +66,12 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) { getById: function (id) { return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "dataTypeApiBaseUrl", - "GetById", - [{ id: id }])), - "Failed to retrieve data for data type id " + id); + $http.get( + umbRequestHelper.getApiUrl( + "dataTypeApiBaseUrl", + "GetById", + [{ id: id }])), + "Failed to retrieve data for data type id " + id); }, /** @@ -97,24 +97,24 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) { getByName: function (name) { return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "dataTypeApiBaseUrl", - "GetByName", - [{ name: name }])), - "Failed to retrieve data for data type with name: " + name); + $http.get( + umbRequestHelper.getApiUrl( + "dataTypeApiBaseUrl", + "GetByName", + [{ name: name }])), + "Failed to retrieve data for data type with name: " + name); }, getAll: function () { return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "dataTypeApiBaseUrl", - "GetAll")), - "Failed to retrieve data"); + $http.get( + umbRequestHelper.getApiUrl( + "dataTypeApiBaseUrl", + "GetAll")), + "Failed to retrieve data"); }, - + getGroupedDataTypes: function () { return umbRequestHelper.resourcePromise( $http.get( @@ -124,7 +124,7 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) { "Failed to retrieve data"); }, - getGroupedPropertyEditors : function(){ + getGroupedPropertyEditors: function () { return umbRequestHelper.resourcePromise( $http.get( umbRequestHelper.getApiUrl( @@ -173,11 +173,11 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) { getScaffold: function (parentId) { return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "dataTypeApiBaseUrl", - "GetEmpty", { parentId: parentId })), - "Failed to retrieve data for empty datatype"); + $http.get( + umbRequestHelper.getApiUrl( + "dataTypeApiBaseUrl", + "GetEmpty", { parentId: parentId })), + "Failed to retrieve data for empty datatype"); }, /** * @ngdoc method @@ -199,7 +199,7 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) { * @returns {Promise} resourcePromise object. * */ - deleteById: function(id) { + deleteById: function (id) { return umbRequestHelper.resourcePromise( $http.post( umbRequestHelper.getApiUrl( @@ -212,12 +212,12 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) { deleteContainerById: function (id) { return umbRequestHelper.resourcePromise( - $http.post( - umbRequestHelper.getApiUrl( - "dataTypeApiBaseUrl", - "DeleteContainer", - [{ id: id }])), - 'Failed to delete content type contaier'); + $http.post( + umbRequestHelper.getApiUrl( + "dataTypeApiBaseUrl", + "DeleteContainer", + [{ id: id }])), + 'Failed to delete content type contaier'); }, @@ -242,16 +242,16 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) { * */ - getCustomListView: function (contentTypeAlias) { - return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "dataTypeApiBaseUrl", - "GetCustomListView", - { contentTypeAlias: contentTypeAlias } - )), - "Failed to retrieve data for custom listview datatype"); - }, + getCustomListView: function (contentTypeAlias) { + return umbRequestHelper.resourcePromise( + $http.get( + umbRequestHelper.getApiUrl( + "dataTypeApiBaseUrl", + "GetCustomListView", + { contentTypeAlias: contentTypeAlias } + )), + "Failed to retrieve data for custom listview datatype"); + }, /** * @ngdoc method @@ -271,16 +271,16 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) { * @returns {Promise} resourcePromise object containing the listview datatype. * */ - createCustomListView: function (contentTypeAlias) { - return umbRequestHelper.resourcePromise( + createCustomListView: function (contentTypeAlias) { + return umbRequestHelper.resourcePromise( $http.post( umbRequestHelper.getApiUrl( "dataTypeApiBaseUrl", "PostCreateCustomListView", { contentTypeAlias: contentTypeAlias } - )), + )), "Failed to create a custom listview datatype"); - }, + }, /** * @ngdoc method @@ -301,7 +301,7 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) { var saveModel = umbDataFormatter.formatDataTypePostData(dataType, preValues, "save" + (isNew ? "New" : "")); return umbRequestHelper.resourcePromise( - $http.post(umbRequestHelper.getApiUrl("dataTypeApiBaseUrl", "PostSave"), saveModel), + $http.post(umbRequestHelper.getApiUrl("dataTypeApiBaseUrl", "PostSave"), saveModel), "Failed to save data for data type id " + dataType.id); }, @@ -351,12 +351,22 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) { createContainer: function (parentId, name) { return umbRequestHelper.resourcePromise( - $http.post( + $http.post( umbRequestHelper.getApiUrl( - "dataTypeApiBaseUrl", - "PostCreateContainer", - { parentId: parentId, name: name })), + "dataTypeApiBaseUrl", + "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) { diff --git a/src/Umbraco.Web/Trees/DataTypeTreeController.cs b/src/Umbraco.Web/Trees/DataTypeTreeController.cs index b19d79c817..70da27c1bf 100644 --- a/src/Umbraco.Web/Trees/DataTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/DataTypeTreeController.cs @@ -105,12 +105,18 @@ namespace Umbraco.Web.Trees menu.Items.Add(Services.TextService.Localize(string.Format("actions/{0}", ActionNew.Instance.Alias))); + menu.Items.Add(new MenuItem("rename", Services.TextService.Localize(String.Format("actions/{0}", "rename"))) + { + Icon = "icon icon-edit" + }); + if (container.HasChildren() == false) { //can delete data type menu.Items.Add(Services.TextService.Localize(string.Format("actions/{0}", ActionDelete.Instance.Alias))); } - menu.Items.Add(Services.TextService.Localize(string.Format("actions/{0}", ActionRefresh.Instance.Alias)), hasSeparator: true); + menu.Items.Add(Services.TextService.Localize(string.Format("actions/{0}", ActionRefresh.Instance.Alias)), hasSeparator: true); + } else {