Merge pull request #1673 from umbraco/temp-U4-9324

Fixes: U4-9324 New template editor is lacking all validation (both client side and server side)
This commit is contained in:
Mads Rasmussen
2017-01-10 12:23:35 +01:00
committed by GitHub
6 changed files with 52 additions and 9 deletions

View File

@@ -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 {

View File

@@ -28,8 +28,6 @@
umb-auto-focus
val-server-field="Name"
required />
<div class="umb-validation-label" val-msg-for="headerName" val-toggle-msg="required"><localize key="general_required">Required</localize> <localize key="general_name">name</localize></div>
<div class="umb-validation-label" val-msg-for="headerName" val-toggle-msg="valServerField"></div>
</ng-form>
<div class="umb-panel-header-name" ng-if="nameLocked">{{ name }}</div>

View File

@@ -1,10 +1,11 @@
(function () {
"use strict";
function TemplatesEditController($scope, $routeParams, templateResource, assetsService, notificationsService, editorState, navigationService, appState, macroService, treeService, angularHelper, $timeout) {
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 () {

View File

@@ -90,6 +90,10 @@
getSectionState : function() { return {}; }
},
macroService: {},
contentEditingHelper: {},
localizationService: {
localize: resolvedPromise({})
},
angularHelper: {
getCurrentForm: function() {
return {

View File

@@ -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,14 @@ namespace Umbraco.Web.Editors
/// <returns></returns>
public TemplateDisplay PostSave(TemplateDisplay display)
{
//Checking the submitted is valid with the Required attributes decorated on the ViewModel
if (ModelState.IsValid == false)
{
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
}
if (display.Id > 0)
{
// update
@@ -100,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
{

View File

@@ -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 : INotificationModel
{
[DataMember(Name = "id")]
public int Id { get; set; }
[Required]
[DataMember(Name = "name")]
public string Name { get; set; }
[Required]
[DataMember(Name = "alias")]
public string Alias { get; set; }