WIP
This commit is contained in:
@@ -239,60 +239,6 @@
|
||||
return JSON.parse('{"alias": "' + fieldsetModel.alias + '", "remove": false, "isValid": true, "properties": []}');
|
||||
}
|
||||
|
||||
//helper for validation
|
||||
function getValidation()
|
||||
{
|
||||
var validation = {}
|
||||
validation.isValid = true;
|
||||
validation.requiredAliases = [];
|
||||
validation.invalidProperties = [];
|
||||
|
||||
//determine which fields are required
|
||||
_.each($scope.model.config.fieldsets, function(fieldset){
|
||||
_.each(fieldset.properties, function(property){
|
||||
if(property.required)
|
||||
{
|
||||
validation.requiredAliases.push(property.alias);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//if nothing required; let's go
|
||||
if(validation.requiredAliases.length == 0)
|
||||
{
|
||||
return validation;
|
||||
}
|
||||
|
||||
//otherwise we need to check the required aliases
|
||||
_.each($scope.archetypeRenderModel.fieldsets, function(fieldset){
|
||||
fieldset.isValid = true;
|
||||
|
||||
_.each(fieldset.properties, function(property){
|
||||
property.isValid = true;
|
||||
|
||||
//if a required field
|
||||
if(_.find(validation.requiredAliases, function(alias){ return alias == property.alias }))
|
||||
{
|
||||
//TODO: do a better validation test
|
||||
if(property.value == ""){
|
||||
fieldset.isValid = false;
|
||||
property.isValid = false;
|
||||
validation.isValid = false;
|
||||
|
||||
validation.invalidProperties.push(property);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if($scope.model.config.developerMode == '1')
|
||||
{
|
||||
console.log(validation);
|
||||
}
|
||||
|
||||
return validation;
|
||||
}
|
||||
|
||||
//helper to lookup validity when given a fieldsetIndex and property alias
|
||||
$scope.getPropertyValidity = function(fieldsetIndex, alias)
|
||||
{
|
||||
@@ -312,18 +258,14 @@
|
||||
//test for form; may have to do this differently for nested archetypes
|
||||
if(!form)
|
||||
return;
|
||||
|
||||
var validation = getValidation();
|
||||
|
||||
if(!validation.isValid)
|
||||
if(form.$invalid)
|
||||
{
|
||||
notificationsService.warning("Cannot Save Document", "The document could not be saved because of missing required fields.")
|
||||
form.$setValidity("archetypeError", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
syncModelToRenderModel();
|
||||
form.$setValidity("archetypeError", true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ angular.module("umbraco").directive('archetypeProperty', function ($compile, $ht
|
||||
return value;
|
||||
}
|
||||
|
||||
var linker = function (scope, element, attrs) {
|
||||
var linker = function (scope, element, attrs, ngModelCtrl) {
|
||||
var configFieldsetModel = getFieldsetByAlias(scope.archetypeConfig.fieldsets, scope.fieldset.alias);
|
||||
var view = "";
|
||||
var label = configFieldsetModel.properties[scope.propertyConfigIndex].label;
|
||||
@@ -76,13 +76,32 @@ angular.module("umbraco").directive('archetypeProperty', function ($compile, $ht
|
||||
}
|
||||
var mergedConfig = _.extend(defaultConfigObj, config);
|
||||
|
||||
loadView(pathToView, mergedConfig, defaultValue, alias, scope, element);
|
||||
loadView(pathToView, mergedConfig, defaultValue, alias, scope, element, ngModelCtrl);
|
||||
});
|
||||
});
|
||||
|
||||
ngModelCtrl.$parsers.push(validate);
|
||||
ngModelCtrl.$formatters.push(validate);
|
||||
|
||||
function validate(renderModel){
|
||||
var valid = true;
|
||||
|
||||
_.each(renderModel, function(fieldset){
|
||||
_.each(fieldset.properties, function(property){
|
||||
property.isValid = true;
|
||||
if(property.value == ""){
|
||||
property.isValid = false;
|
||||
valid = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
ngModelCtrl.$setValidity('validation', valid);
|
||||
return renderModel;
|
||||
}
|
||||
}
|
||||
|
||||
function loadView(view, config, defaultValue, alias, scope, element) {
|
||||
function loadView(view, config, defaultValue, alias, scope, element, ngModelCtrl) {
|
||||
if (view)
|
||||
{
|
||||
$http.get(view).success(function (data) {
|
||||
@@ -115,6 +134,9 @@ angular.module("umbraco").directive('archetypeProperty', function ($compile, $ht
|
||||
//watch for changes since there is no two-way binding with the local model.value
|
||||
scope.$watch('model.value', function (newValue, oldValue) {
|
||||
scope.archetypeRenderModel.fieldsets[scope.fieldsetIndex].properties[renderModelPropertyIndex].value = newValue;
|
||||
|
||||
//trigger the validation pipeline
|
||||
ngModelCtrl.$setViewValue(ngModelCtrl.$viewValue);
|
||||
});
|
||||
|
||||
element.html(data).show();
|
||||
@@ -125,6 +147,7 @@ angular.module("umbraco").directive('archetypeProperty', function ($compile, $ht
|
||||
}
|
||||
|
||||
return {
|
||||
require: "^ngModel",
|
||||
restrict: "E",
|
||||
rep1ace: true,
|
||||
link: linker,
|
||||
|
||||
Reference in New Issue
Block a user