From 42841824bf0280b120891d4fabdcada2a4af7000 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 4 Jan 2017 11:31:46 +0100 Subject: [PATCH 1/6] add client side validation --- .../src/views/templates/edit.controller.js | 27 ++++++++++++++++--- .../template-editor-controller.spec.js | 4 +++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/templates/edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/templates/edit.controller.js index beac32be95..a2cc29a0d4 100644 --- a/src/Umbraco.Web.UI.Client/src/views/templates/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/templates/edit.controller.js @@ -1,10 +1,11 @@ (function () { "use strict"; - function TemplatesEditController($scope, $routeParams, templateResource, assetsService, notificationsService, editorState, navigationService, appState, macroService, treeService, angularHelper) { + function TemplatesEditController($scope, $routeParams, $timeout, templateResource, assetsService, notificationsService, editorState, navigationService, appState, macroService, treeService, contentEditingHelper, localizationService, angularHelper) { var vm = this; var oldMasterTemplateAlias = null; + var localizeSaving = localizationService.localize("general_saving"); vm.page = {}; vm.page.loading = true; @@ -20,8 +21,18 @@ vm.template.content = vm.editor.getValue(); - templateResource.save(vm.template).then(function (saved) { - + contentEditingHelper.contentEditorPerformSave({ + statusMessage: localizeSaving, + saveMethod: templateResource.save, + scope: $scope, + content: vm.template, + //We do not redirect on failure for templates - this is because it is not possible to actually save the doc + // type when server side validation fails - as opposed to content where we are capable of saving the content + // item if server side validation fails + redirectOnFailure: false, + rebindCallback: function (orignal, saved) {} + }).then(function (saved) { + notificationsService.success("Template saved"); vm.page.saveButtonState = "success"; vm.template = saved; @@ -58,9 +69,17 @@ }, function (err) { - notificationsService.error("Template save failed"); + vm.page.saveButtonState = "error"; + + localizationService.localize("speechBubbles_validationFailedHeader").then(function (headerValue) { + localizationService.localize("speechBubbles_validationFailedMessage").then(function(msgValue) { + notificationsService.error(headerValue, msgValue); + }); + }); + }); + }; vm.init = function () { diff --git a/src/Umbraco.Web.UI.Client/test/unit/app/templates/template-editor-controller.spec.js b/src/Umbraco.Web.UI.Client/test/unit/app/templates/template-editor-controller.spec.js index aae0694876..a5009f5eb8 100644 --- a/src/Umbraco.Web.UI.Client/test/unit/app/templates/template-editor-controller.spec.js +++ b/src/Umbraco.Web.UI.Client/test/unit/app/templates/template-editor-controller.spec.js @@ -89,6 +89,10 @@ getSectionState : function() { return {}; } }, macroService: {}, + contentEditingHelper: {}, + localizationService: { + localize: resolvedPromise({}) + }, angularHelper: { getCurrentForm: function() { return { From 13007647706181ee8bfe14667267c287a6735445 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Wed, 4 Jan 2017 14:12:45 +0000 Subject: [PATCH 2/6] Adding in server side validation - but need to clarify that this is the 'right' way to do it that wires up correctly/magically back to the UI components --- src/Umbraco.Web/Editors/TemplateController.cs | 13 +++++++++++++ .../Models/ContentEditing/TemplateDisplay.cs | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/src/Umbraco.Web/Editors/TemplateController.cs b/src/Umbraco.Web/Editors/TemplateController.cs index eec76ca34e..d0c17b7f4b 100644 --- a/src/Umbraco.Web/Editors/TemplateController.cs +++ b/src/Umbraco.Web/Editors/TemplateController.cs @@ -6,8 +6,10 @@ using System.Web.Http; using AutoMapper; using Umbraco.Core.IO; using Umbraco.Core.Models; +using Umbraco.Core.Services; using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Mvc; +using Umbraco.Web.WebApi; using Umbraco.Web.WebApi.Filters; using Constants = Umbraco.Core.Constants; @@ -86,6 +88,17 @@ namespace Umbraco.Web.Editors /// public TemplateDisplay PostSave(TemplateDisplay display) { + + //Checking the submitted is valid with the Required attributes decorated on the ViewModel + if (ModelState.IsValid == false) + { + //Unsure of the standard or set way to do this?! + //throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("MISSING NAME")); + + throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); + } + + if (display.Id > 0) { // update diff --git a/src/Umbraco.Web/Models/ContentEditing/TemplateDisplay.cs b/src/Umbraco.Web/Models/ContentEditing/TemplateDisplay.cs index dacccb8ceb..3c1ebe16c3 100644 --- a/src/Umbraco.Web/Models/ContentEditing/TemplateDisplay.cs +++ b/src/Umbraco.Web/Models/ContentEditing/TemplateDisplay.cs @@ -1,21 +1,26 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; +using Umbraco.Core.Models.Validation; namespace Umbraco.Web.Models.ContentEditing { [DataContract(Name = "template", Namespace = "")] public class TemplateDisplay { + [DataMember(Name = "id")] public int Id { get; set; } + [Required] [DataMember(Name = "name")] public string Name { get; set; } + [RequiredForPersistence] [DataMember(Name = "alias")] public string Alias { get; set; } From 5b88c57d94c8b194278e0341f940f65bd1056f31 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Mon, 9 Jan 2017 13:05:20 +0000 Subject: [PATCH 3/6] Replace RequiredForPersistance with Required --- src/Umbraco.Web/Models/ContentEditing/TemplateDisplay.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web/Models/ContentEditing/TemplateDisplay.cs b/src/Umbraco.Web/Models/ContentEditing/TemplateDisplay.cs index 3c1ebe16c3..235eb3d360 100644 --- a/src/Umbraco.Web/Models/ContentEditing/TemplateDisplay.cs +++ b/src/Umbraco.Web/Models/ContentEditing/TemplateDisplay.cs @@ -20,7 +20,7 @@ namespace Umbraco.Web.Models.ContentEditing [DataMember(Name = "name")] public string Name { get; set; } - [RequiredForPersistence] + [Required] [DataMember(Name = "alias")] public string Alias { get; set; } From b2815d5e63c384f04c3c7619dd0b6db393325c47 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Mon, 9 Jan 2017 13:34:20 +0000 Subject: [PATCH 4/6] Remove commented code --- src/Umbraco.Web/Editors/TemplateController.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Umbraco.Web/Editors/TemplateController.cs b/src/Umbraco.Web/Editors/TemplateController.cs index d0c17b7f4b..54c43b4f29 100644 --- a/src/Umbraco.Web/Editors/TemplateController.cs +++ b/src/Umbraco.Web/Editors/TemplateController.cs @@ -92,9 +92,6 @@ namespace Umbraco.Web.Editors //Checking the submitted is valid with the Required attributes decorated on the ViewModel if (ModelState.IsValid == false) { - //Unsure of the standard or set way to do this?! - //throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("MISSING NAME")); - throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } From 4c461a733bc3c02cd302d9ca7af14ddbec95d45e Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 10 Jan 2017 12:16:12 +0100 Subject: [PATCH 5/6] remove inline validation on name --- src/Umbraco.Web.UI.Client/src/less/panel.less | 2 ++ .../src/views/components/editor/umb-editor-header.html | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/less/panel.less b/src/Umbraco.Web.UI.Client/src/less/panel.less index 19159638a4..ded8411dea 100644 --- a/src/Umbraco.Web.UI.Client/src/less/panel.less +++ b/src/Umbraco.Web.UI.Client/src/less/panel.less @@ -484,6 +484,8 @@ input.umb-panel-header-description { font-size: 12px; margin-left: 2px; margin-top: 3px; + height: 25px; + line-height: 25px; } .umb-editor-drawer-content { diff --git a/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html b/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html index 558f94d387..f218e983e7 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html @@ -28,8 +28,6 @@ umb-auto-focus val-server-field="Name" required /> -
Required name
-
{{ name }}
From 9718324e6eb4243cf162e61db6f4915968c48b2d Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 10 Jan 2017 12:22:18 +0100 Subject: [PATCH 6/6] add check for master not being equal to template --- src/Umbraco.Web/Editors/TemplateController.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web/Editors/TemplateController.cs b/src/Umbraco.Web/Editors/TemplateController.cs index 256f0df45b..58a4053de1 100644 --- a/src/Umbraco.Web/Editors/TemplateController.cs +++ b/src/Umbraco.Web/Editors/TemplateController.cs @@ -110,11 +110,16 @@ namespace Umbraco.Web.Editors { if (string.IsNullOrEmpty(display.MasterTemplateAlias) == false) { + var master = Services.FileService.GetTemplate(display.MasterTemplateAlias); - if (master != null) - { - template.SetMasterTemplate(master); + if(master == null || master.Id == display.Id) + { + template.SetMasterTemplate(null); + }else + { + template.SetMasterTemplate(master); } + } else {