From 7df641cf2b767eba66722466a549ae5cd2182794 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 20 Aug 2013 18:10:19 +1000 Subject: [PATCH] Got Data Type Creation working. Need to look at fixing up the issues with creating content/media tomorrow. --- .../services/contenteditinghelper.service.js | 4 +-- .../common/services/menuactions.service.js | 6 +++- .../views/content/content.edit.controller.js | 1 + .../datatype/datatype.edit.controller.js | 35 +++++++++---------- .../src/views/media/media.edit.controller.js | 1 + .../views/prevalueeditors/requiredfield.html | 3 +- src/Umbraco.Web/Editors/DataTypeController.cs | 6 ++++ .../Editors/DataTypeValidateAttribute.cs | 5 ++- .../Models/ContentEditing/DataTypeDisplay.cs | 5 ++- .../Models/Mapping/DataTypeModelMapper.cs | 3 +- .../Models/Mapping/PreValueDisplayResolver.cs | 17 ++++++--- 11 files changed, 57 insertions(+), 29 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/services/contenteditinghelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/contenteditinghelper.service.js index db9e05dc22..10bb81b4d4 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/contenteditinghelper.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/contenteditinghelper.service.js @@ -147,7 +147,7 @@ function contentEditingHelper($location, $routeParams, notificationsService, ser this.handleValidationErrors(args.allNewProps, args.err.data.ModelState); - if (!this.redirectToCreatedContent(args.err.data.id, args.err.data.ModelState)) { + if (!args.redirectOnFailure || !this.redirectToCreatedContent(args.err.data.id, args.err.data.ModelState)) { //we are not redirecting because this is not new content, it is existing content. In this case // we need to detect what properties have changed and re-bind them with the server data. Then we need // to re-bind any server validation errors after the digest takes place. @@ -204,7 +204,7 @@ function contentEditingHelper($location, $routeParams, notificationsService, ser } args.scope.$broadcast("saved", { scope: args.scope }); - if (!this.redirectToCreatedContent(args.scope.content.id)) { + if (!this.redirectToCreatedContent(args.newContent.id)) { //we are not redirecting because this is not new content, it is existing content. In this case // we need to detect what properties have changed and re-bind them with the server data. diff --git a/src/Umbraco.Web.UI.Client/src/common/services/menuactions.service.js b/src/Umbraco.Web.UI.Client/src/common/services/menuactions.service.js index 583678b86f..28bc971096 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/menuactions.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/menuactions.service.js @@ -8,7 +8,7 @@ * @description * Defines the methods that are called when menu items declare only an action to execute */ -function umbracoMenuActions($q, treeService, $location) { +function umbracoMenuActions($q, treeService, $location, navigationService) { return { @@ -41,9 +41,13 @@ function umbracoMenuActions($q, treeService, $location) { * @param {object} args.section The current section */ "CreateChildEntity": function (args) { + + navigationService.hideNavigation(); + var route = "/" + args.section + "/" + treeService.getTreeAlias(args.treeNode) + "/edit/" + args.treeNode.id; //change to new path $location.path(route).search({ create: true }); + } }; } diff --git a/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js index 7e290796dc..1c15c89b08 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js @@ -73,6 +73,7 @@ function ContentEditController($scope, $routeParams, $location, contentResource, contentEditingHelper.handleSaveError({ err: err, + redirectOnFailure: true, allNewProps: allNewProps, allOrigProps: contentEditingHelper.getAllProps($scope.content), rebindCallback: contentEditingHelper.reBindChangedProperties(allOrigProps, allNewProps) diff --git a/src/Umbraco.Web.UI.Client/src/views/datatype/datatype.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/datatype/datatype.edit.controller.js index a6ac7b319e..206f4c4a50 100644 --- a/src/Umbraco.Web.UI.Client/src/views/datatype/datatype.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/datatype/datatype.edit.controller.js @@ -8,22 +8,7 @@ */ function DataTypeEditController($scope, $routeParams, $location, dataTypeResource, notificationsService, angularHelper, serverValidationManager, contentEditingHelper) { - //set up the standard data type props - function createDisplayProps() { - $scope.properties = { - selectedEditor: { - alias: "selectedEditor", - description: "Select a property editor", - label: "Property editor" - }, - selectedEditorId: { - alias: "selectedEditorId", - label: "Property editor GUID" - } - }; - } - - //setup the pre-values as props + //method used to configure the pre-values when we retreive them from the server function createPreValueProps(preVals) { $scope.preValues = []; for (var i = 0; i < preVals.length; i++) { @@ -38,6 +23,22 @@ function DataTypeEditController($scope, $routeParams, $location, dataTypeResourc } } + //set up the standard data type props + $scope.properties = { + selectedEditor: { + alias: "selectedEditor", + description: "Select a property editor", + label: "Property editor" + }, + selectedEditorId: { + alias: "selectedEditorId", + label: "Property editor GUID" + } + }; + + //setup the pre-values as props + $scope.preValues = []; + if ($routeParams.create) { //we are creating so get an empty content item dataTypeResource.getScaffold($routeParams.id, $routeParams.doctype) @@ -45,7 +46,6 @@ function DataTypeEditController($scope, $routeParams, $location, dataTypeResourc $scope.loaded = true; $scope.preValuesLoaded = true; $scope.content = data; - createDisplayProps(); }); } else { @@ -55,7 +55,6 @@ function DataTypeEditController($scope, $routeParams, $location, dataTypeResourc $scope.loaded = true; $scope.preValuesLoaded = true; $scope.content = data; - createDisplayProps(); createPreValueProps($scope.content.preValues); //in one particular special case, after we've created a new item we redirect back to the edit diff --git a/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js index 088d0ee4a5..18ccc0aaf9 100644 --- a/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js @@ -71,6 +71,7 @@ function mediaEditController($scope, $routeParams, mediaResource, notificationsS contentEditingHelper.handleSaveError({ err: err, + redirectOnFailure: true, allNewProps: allNewProps, allOrigProps: contentEditingHelper.getAllProps($scope.content), rebindCallback: contentEditingHelper.reBindChangedProperties(allOrigProps, allNewProps) diff --git a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/requiredfield.html b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/requiredfield.html index 5012926855..14c06d29d6 100644 --- a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/requiredfield.html +++ b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/requiredfield.html @@ -1,7 +1,8 @@ 
+ required + val-server="value" /> Required {{propertyForm.requiredField.errorMsg}} diff --git a/src/Umbraco.Web/Editors/DataTypeController.cs b/src/Umbraco.Web/Editors/DataTypeController.cs index ba66776276..f84fd9b48a 100644 --- a/src/Umbraco.Web/Editors/DataTypeController.cs +++ b/src/Umbraco.Web/Editors/DataTypeController.cs @@ -44,6 +44,12 @@ namespace Umbraco.Web.Editors return Mapper.Map(dataType); } + public DataTypeDisplay GetEmpty() + { + var dt = new DataTypeDefinition(-1, Guid.Empty); + return Mapper.Map(dt); + } + /// /// Returns the pre-values for the specified property editor /// diff --git a/src/Umbraco.Web/Editors/DataTypeValidateAttribute.cs b/src/Umbraco.Web/Editors/DataTypeValidateAttribute.cs index 07b839eabe..1d6d2f5b12 100644 --- a/src/Umbraco.Web/Editors/DataTypeValidateAttribute.cs +++ b/src/Umbraco.Web/Editors/DataTypeValidateAttribute.cs @@ -8,6 +8,7 @@ using System.Web.Http.Filters; using AutoMapper; using Umbraco.Core; using Umbraco.Core.Models; +using Umbraco.Core.Models.EntityBase; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; using Umbraco.Web.Models.ContentEditing; @@ -70,9 +71,11 @@ namespace Umbraco.Web.Editors case ContentSaveAction.SaveNew: //create the persisted model from mapping the saved model persisted = Mapper.Map(dataType); + ((DataTypeDefinition)persisted).ResetIdentity(); break; default: - throw new HttpResponseException(HttpStatusCode.NotFound); + actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.NotFound, new ArgumentOutOfRangeException()); + return; } //now assign the persisted entity to the model so we can use it in the action diff --git a/src/Umbraco.Web/Models/ContentEditing/DataTypeDisplay.cs b/src/Umbraco.Web/Models/ContentEditing/DataTypeDisplay.cs index a19d8e93d5..4c9e159595 100644 --- a/src/Umbraco.Web/Models/ContentEditing/DataTypeDisplay.cs +++ b/src/Umbraco.Web/Models/ContentEditing/DataTypeDisplay.cs @@ -16,9 +16,12 @@ namespace Umbraco.Web.Models.ContentEditing Notifications = new List(); } + /// + /// This is nullable because when we are creating a new one, it is nothing + /// [DataMember(Name = "selectedEditor", IsRequired = true)] [Required] - public Guid SelectedEditor { get; set; } + public Guid? SelectedEditor { get; set; } [DataMember(Name = "availableEditors")] public IEnumerable AvailableEditors { get; set; } diff --git a/src/Umbraco.Web/Models/Mapping/DataTypeModelMapper.cs b/src/Umbraco.Web/Models/Mapping/DataTypeModelMapper.cs index 0e2e9b448b..0f4a53f9e2 100644 --- a/src/Umbraco.Web/Models/Mapping/DataTypeModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/DataTypeModelMapper.cs @@ -30,7 +30,8 @@ namespace Umbraco.Web.Models.Mapping .ForMember(display => display.AvailableEditors, expression => expression.ResolveUsing()) .ForMember(display => display.PreValues, expression => expression.ResolveUsing( new PreValueDisplayResolver(lazyDataTypeService))) - .ForMember(display => display.SelectedEditor, expression => expression.MapFrom(definition => definition.ControlId)); + .ForMember(display => display.SelectedEditor, expression => expression.MapFrom( + definition => definition.ControlId == Guid.Empty ? null : (Guid?) definition.ControlId)); config.CreateMap() .ConstructUsing(save => new DataTypeDefinition(-1, save.SelectedEditor) {CreateDate = DateTime.Now}) diff --git a/src/Umbraco.Web/Models/Mapping/PreValueDisplayResolver.cs b/src/Umbraco.Web/Models/Mapping/PreValueDisplayResolver.cs index a52822fed7..f89047a83d 100644 --- a/src/Umbraco.Web/Models/Mapping/PreValueDisplayResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/PreValueDisplayResolver.cs @@ -22,17 +22,26 @@ namespace Umbraco.Web.Models.Mapping protected override IEnumerable ResolveCore(IDataTypeDefinition source) { - var propEd = PropertyEditorResolver.Current.GetById(source.ControlId); - if (propEd == null) + PropertyEditor propEd = null; + if (source.ControlId != Guid.Empty) { - throw new InvalidOperationException("Could not find property editor with id " + source.ControlId); + propEd = PropertyEditorResolver.Current.GetById(source.ControlId); + if (propEd == null) + { + throw new InvalidOperationException("Could not find property editor with id " + source.ControlId); + } } + var dataTypeService = (DataTypeService) _dataTypeService.Value; var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(source.Id); var dictionaryVals = PreValueCollection.AsDictionary(preVals); - var result = propEd.PreValueEditor.Fields.Select(Mapper.Map).ToArray(); + var result = Enumerable.Empty(); + if (propEd != null) + { + result = propEd.PreValueEditor.Fields.Select(Mapper.Map).ToArray(); + } var currentIndex = 0; //used if the collection is non-dictionary based. foreach (var field in result) {