Started on data type editor

This commit is contained in:
Shannon
2013-08-15 19:20:06 +10:00
parent 2153dc2f56
commit f2f1106034
6 changed files with 86 additions and 42 deletions

View File

@@ -53,7 +53,11 @@ function valPropertyMsg(serverValidationManager) {
hasError = true;
//update the validation message if we don't already have one assigned.
if (showValidation && scope.errorMsg === "") {
var err = serverValidationManager.getPropertyError(scope.property.alias, "");
var err;
//this can be null if no property was assigned
if (scope.property) {
err = serverValidationManager.getPropertyError(scope.property.alias, "");
}
scope.errorMsg = err ? err.errorMsg : "Property has errors";
}
}
@@ -72,7 +76,11 @@ function valPropertyMsg(serverValidationManager) {
scope.$on("saving", function (ev, args) {
showValidation = true;
if (hasError && scope.errorMsg === "") {
var err = serverValidationManager.getPropertyError(scope.property.alias, "");
var err;
//this can be null if no property was assigned
if (scope.property) {
err = serverValidationManager.getPropertyError(scope.property.alias, "");
}
scope.errorMsg = err ? err.errorMsg : "Property has errors";
}
else if (!hasError) {
@@ -109,27 +117,30 @@ function valPropertyMsg(serverValidationManager) {
// It's important to note that we need to subscribe to server validation changes here because we always must
// indicate that a content property is invalid at the property level since developers may not actually implement
// the correct field validation in their property editors.
serverValidationManager.subscribe(scope.property.alias, "", function (isValid, propertyErrors, allErrors) {
hasError = !isValid;
if (hasError) {
//set the error message to the server message
scope.errorMsg = propertyErrors[0].errorMsg;
//flag that the current validator is invalid
formCtrl.$setValidity('valPropertyMsg', false);
}
else {
scope.errorMsg = "";
//flag that the current validator is valid
formCtrl.$setValidity('valPropertyMsg', true);
}
});
//when the element is disposed we need to unsubscribe!
// NOTE: this is very important otherwise when this controller re-binds the previous subscriptsion will remain
// but they are a different callback instance than the above.
element.bind('$destroy', function () {
serverValidationManager.unsubscribe(scope.property.alias, "");
});
if (scope.property) { //this can be null if no property was assigned
serverValidationManager.subscribe(scope.property.alias, "", function(isValid, propertyErrors, allErrors) {
hasError = !isValid;
if (hasError) {
//set the error message to the server message
scope.errorMsg = propertyErrors[0].errorMsg;
//flag that the current validator is invalid
formCtrl.$setValidity('valPropertyMsg', false);
}
else {
scope.errorMsg = "";
//flag that the current validator is valid
formCtrl.$setValidity('valPropertyMsg', true);
}
});
//when the element is disposed we need to unsubscribe!
// NOTE: this is very important otherwise when this controller re-binds the previous subscriptsion will remain
// but they are a different callback instance than the above.
element.bind('$destroy', function() {
serverValidationManager.unsubscribe(scope.property.alias, "");
});
}
}
};
}

View File

@@ -15,8 +15,9 @@ function valToggleMsg(serverValidationManager) {
throw "valToggleMsg requires that the attribute valMsgFor exists on the element";
}
//assign the form control to our isolated scope so we can watch it's values
scope.formCtrl = formCtrl;
//we need to copy the form controller val to our isolated scope so that
//we'll also maintain the current form name.
scope[formCtrl.$name] = formCtrl;
//if there's any remaining errors in the server validation service then we should show them.
var showValidation = serverValidationManager.items.length > 0;

View File

@@ -13,7 +13,15 @@ angular.module('umbraco.mocks').
var dataType = {
id: id,
name: "Data type " + id,
selectedEditor: String.CreateGuid()
selectedEditor: String.CreateGuid(),
availableEditors: [
{ name: "Some editor 1", editorId: String.CreateGuid() },
{ name: "Some editor 2", editorId: String.CreateGuid() },
{ name: "Some editor 3", editorId: String.CreateGuid() },
{ name: "Some editor 4", editorId: String.CreateGuid() },
{ name: "Some editor 5", editorId: String.CreateGuid() },
{ name: "Some editor 6", editorId: String.CreateGuid() }
]
};
return [200, dataType, null];

View File

@@ -7,7 +7,21 @@
* The controller for the content editor
*/
function DataTypeEditController($scope, $routeParams, $location, dataTypeResource, notificationsService, angularHelper, serverValidationManager, contentEditingHelper) {
function createDisplayProps() {
$scope.properties = {
selectedEditor: {
alias: "selectedEditor",
description: "Select a property editor",
label: "Property editor"
},
selectedEditorId: {
alias: "selectedEditorId",
label: "Property editor GUID"
}
};
}
if ($routeParams.create) {
//we are creating so get an empty content item
dataTypeResource.getScaffold($routeParams.id, $routeParams.doctype)
@@ -22,6 +36,7 @@ function DataTypeEditController($scope, $routeParams, $location, dataTypeResourc
.then(function(data) {
$scope.loaded = true;
$scope.content = data;
createDisplayProps();
//in one particular special case, after we've created a new item we redirect back to the edit
// route but there might be server validation errors in the collection which we need to display
@@ -55,4 +70,4 @@ function DataTypeEditController($scope, $routeParams, $location, dataTypeResourc
}
angular.module("umbraco").controller("Umbraco.Editors.DataType.EditController", DataTypeEditController);
angular.module("umbraco").controller("Umbraco.Editors.DataType.EditController", DataTypeEditController);

View File

@@ -20,21 +20,30 @@
</div>
</div>
</umb-header>
<umb-tab-view>
<umb-tab id="tab0" rel="0">
<div class="umb-panel-body umb-scrollable row-fluid" auto-scale="1">
<div class="tab-content form-horizontal">
<div class="umb-pane">
<umb-property
property="property"
ng-repeat="property in properties">
<umb-property property="properties.selectedEditor">
<umb-editor model="property"></umb-editor>
<!-- TODO: We have more issues with transcluding and ng-form so the current validator toggle is not
executin, will investigate more tomorrow, if you are readin this, I discovered some crazy stuf with
ng-form controllers and transclusion which makes things interesting. //-->
<div>
<select name="selectedEditor"
ng-model="availableEditors"
required
ng-options="e.name for e in content.availableEditors track by e.editorId"></select>
<span class="help-inline" val-msg-for="selectedEditor" val-toggle-msg="requires">Requires</span>
</div>
</umb-property>
<umb-property property="properties.selectedEditorId">
<div>{{content.selectedEditor}}</div>
</umb-property>
</div>
</umb-tab>
</umb-tab-view>
</div>
</div>
</umb-panel>
</div>

View File

@@ -1,12 +1,12 @@
<div>
<p>Enter a numeric value</p>
<input type="text" ng-model="model.value" id="{{model.alias}}" class="umb-textstring span7 textstring"
<input name="myInput" type="text" ng-model="model.value" class="umb-textstring span7 textstring"
required
val-regex="^\d*$"
val-server="value" />
<span class="help-inline" val-msg-for="regex" val-toggle-msg="required">Required!</span>
<span class="help-inline" val-msg-for="regex" val-toggle-msg="valRegex">The value entered is not a number</span>
<span class="help-inline" val-msg-for="regex" val-toggle-msg="valServer">A server error occurred</span>
<span class="help-inline" val-msg-for="myInput" val-toggle-msg="required">Required!</span>
<span class="help-inline" val-msg-for="myInput" val-toggle-msg="valRegex">The value entered is not a number</span>
<span class="help-inline" val-msg-for="myInput" val-toggle-msg="valServer">A server error occurred</span>
</div>