From d46ae5b993fbc345454c461b2b1478ed5ecaa7c3 Mon Sep 17 00:00:00 2001 From: Kevin Giszewski Date: Thu, 16 Jan 2014 19:43:15 -0500 Subject: [PATCH] Fix validation bug, rename labelExpression, change error style --- app/controllers/config.controller.js | 6 +++--- app/controllers/controller.js | 20 ++++++++++++++------ app/directives/archetypeproperty.js | 8 ++++---- app/less/archetype.less | 5 ++++- app/views/archetype.config.html | 2 +- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/app/controllers/config.controller.js b/app/controllers/config.controller.js index 3c26453..8a6734f 100644 --- a/app/controllers/config.controller.js +++ b/app/controllers/config.controller.js @@ -3,9 +3,9 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio //$scope.model.value = ""; //console.log($scope.model.value); - var newPropertyModel = '{alias: "", remove: false, collapse: false, label: "", helpText: "", view: "", value: "", config: {}}'; - var newFieldsetModel = '{alias: "", remove: false, collapse: false, labelExpression: "", tooltip: "", icon: "", label: "", headerText: "", footerText: "", properties:[' + newPropertyModel + ']}'; - var defaultFieldsetConfigModel = eval("({showAdvancedOptions: false, hideFieldsetToolbar: false, enableMultipleFieldsets: false, hideFieldsetControls: false, hideFieldsetLabels: false, hidePropertyLabel: false, maxFieldsets:1, fieldsets: [" + newFieldsetModel + "]})"); + var newPropertyModel = '{alias: "", remove: false, collapse: false, label: "", helpText: "", view: "", value: "", config: ""}'; + var newFieldsetModel = '{alias: "", remove: false, collapse: false, labelTemplate: "", tooltip: "", icon: "", label: "", headerText: "", footerText: "", properties:[' + newPropertyModel + ']}'; + var defaultFieldsetConfigModel = eval("({showAdvancedOptions: false, hideFieldsetToolbar: false, enableMultipleFieldsets: false, hideFieldsetControls: false, hideFieldsetLabels: false, hidePropertyLabel: false, maxFieldsets: null, fieldsets: [" + newFieldsetModel + "]})"); $scope.model.value = $scope.model.value || defaultFieldsetConfigModel; diff --git a/app/controllers/controller.js b/app/controllers/controller.js index 2bbe1ca..39beb32 100644 --- a/app/controllers/controller.js +++ b/app/controllers/controller.js @@ -14,10 +14,10 @@ $scope.archetypeRenderModel = {}; initArchetypeRenderModel(); - //helper to get $eval the labelExpression + //helper to get $eval the labelTemplate $scope.getFieldsetTitle = function(fieldsetConfigModel, fieldsetIndex) { var fieldset = $scope.archetypeRenderModel.fieldsets[fieldsetIndex]; - var template = fieldsetConfigModel.labelExpression; + var template = fieldsetConfigModel.labelTemplate; var rgx = /{{(.*?)}}*/g; var results; var parsedTemplate = template; @@ -35,7 +35,6 @@ //defines the options for the jquery sortable //i used an ng-model="archetypeRenderModel" so the sort updates the right model - $scope.sortableOptions = { axis: 'y', cursor: "move", @@ -240,13 +239,17 @@ { var validation = {} validation.isValid = true; + validation.requiredAliases = []; validation.invalidProperties = []; //determine which fields are required _.each($scope.model.config.fieldsets, function(fieldset){ - validation.requiredAliases = _.find(fieldset.properties, function(property){ - return property.required; - }) || []; + _.each(fieldset.properties, function(property){ + if(property.required) + { + validation.requiredAliases.push(property.alias); + } + }); }); //if nothing required; let's go @@ -277,6 +280,11 @@ }); }); + if($scope.model.config.developerMode == '1') + { + console.log(validation); + } + return validation; } diff --git a/app/directives/archetypeproperty.js b/app/directives/archetypeproperty.js index d62ad76..06dc6da 100644 --- a/app/directives/archetypeproperty.js +++ b/app/directives/archetypeproperty.js @@ -32,7 +32,7 @@ var defaultValue = configFieldsetModel.properties[scope.propertyConfigIndex].value; //try to convert the config to a JS object - if(typeof config == 'string'){ + if(config && typeof config == 'string'){ try{ if(scope.archetypeConfig.developerMode == '1'){ console.log("Trying to eval config: " + config); @@ -47,12 +47,12 @@ } } - if(scope.archetypeConfig.developerMode == '1'){ + if(config && scope.archetypeConfig.developerMode == '1'){ console.log("Config post-eval: " + config); } //try to convert the defaultValue to a JS object - if(typeof defaultValue == 'string'){ + if(defaultValue && typeof defaultValue == 'string'){ try{ if(scope.archetypeConfig.developerMode == '1'){ console.log("Trying to eval default value: " + defaultValue); @@ -67,7 +67,7 @@ } } - if(scope.archetypeConfig.developerMode == '1'){ + if(defaultValue && scope.archetypeConfig.developerMode == '1'){ console.log("Default value post-eval: " + defaultValue); } diff --git a/app/less/archetype.less b/app/less/archetype.less index 352d8bd..9595008 100644 --- a/app/less/archetype.less +++ b/app/less/archetype.less @@ -32,6 +32,7 @@ .archetypeEditor .archetypeProperty{ clear: both; overflow: hidden; + margin-top: 3px; } .archetypeEditor .umb-contentpicker{ @@ -95,7 +96,7 @@ } .archetypeConfig label{ - width: 100px; + width: 120px; } .archetypeConfig .archetypeFieldsetWrapper{ @@ -184,4 +185,6 @@ background-color: #8b0000; color: #fff; margin-bottom: 5px; + padding-top: 3px; + padding-bottom: 3px; } \ No newline at end of file diff --git a/app/views/archetype.config.html b/app/views/archetype.config.html index 596094c..c8695f8 100644 --- a/app/views/archetype.config.html +++ b/app/views/archetype.config.html @@ -16,7 +16,7 @@
- +