diff --git a/app/controllers/config.controller.js b/app/controllers/config.controller.js index 38f761e..3c26453 100644 --- a/app/controllers/config.controller.js +++ b/app/controllers/config.controller.js @@ -88,22 +88,12 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio //setup JSON.stringify helpers $scope.archetypeConfigRenderModel.toString = stringify; - setConfigPropertyToString(); //encapsulate stringify (should be built into browsers, not sure of IE support) function stringify() { return JSON.stringify(this); } - function setConfigPropertyToString() - { - _.each($scope.archetypeConfigRenderModel.fieldsets, function(fieldset){ - _.each(fieldset.properties, function(property){ - property.config.toString = stringify; - }); - }); - } - //watch for changes $scope.$watch('archetypeConfigRenderModel', function (v) { //console.log(v); @@ -111,17 +101,6 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio $scope.archetypeConfigRenderModel = JSON.parse(v); $scope.archetypeConfigRenderModel.toString = stringify; } - - //add stringify back in - _.each($scope.archetypeConfigRenderModel.fieldsets, function(fieldset){ - _.each(fieldset.properties, function(property){ - if(typeof property.config === 'string') - { - property.config = JSON.parse($scope.archetypeConfigRenderModel.fieldsets[i].properties[j].config); - property.config.toString = stringify; - } - }); - }); }, true); //helper that returns if an item can be removed diff --git a/app/directives/archetypeproperty.js b/app/directives/archetypeproperty.js index 4d9a824..d62ad76 100644 --- a/app/directives/archetypeproperty.js +++ b/app/directives/archetypeproperty.js @@ -29,14 +29,47 @@ var label = configFieldsetModel.properties[scope.propertyConfigIndex].label; var config = configFieldsetModel.properties[scope.propertyConfigIndex].config; var alias = configFieldsetModel.properties[scope.propertyConfigIndex].alias; + var defaultValue = configFieldsetModel.properties[scope.propertyConfigIndex].value; - /* - console.log(config); + //try to convert the config to a JS object if(typeof config == 'string'){ - config = eval(config); + try{ + if(scope.archetypeConfig.developerMode == '1'){ + console.log("Trying to eval config: " + config); + } + config = eval("(" + config + ")"); + } + catch(exception) + { + if(scope.archetypeConfig.developerMode == '1'){ + console.log("Failed to eval config."); + } + } + } + + if(scope.archetypeConfig.developerMode == '1'){ + console.log("Config post-eval: " + config); + } + + //try to convert the defaultValue to a JS object + if(typeof defaultValue == 'string'){ + try{ + if(scope.archetypeConfig.developerMode == '1'){ + console.log("Trying to eval default value: " + defaultValue); + } + defaultValue = eval("(" + defaultValue + ")"); + } + catch(exception) + { + if(scope.archetypeConfig.developerMode == '1'){ + console.log("Failed to eval defaultValue."); + } + } + } + + if(scope.archetypeConfig.developerMode == '1'){ + console.log("Default value post-eval: " + defaultValue); } - angular.isObject(config); - */ if (view) { @@ -58,7 +91,7 @@ if (!renderModelPropertyIndex) { - scope.archetypeRenderModel.fieldsets[scope.fieldsetIndex].properties.push(eval("({alias: '" + alias + "', value:''})")); + scope.archetypeRenderModel.fieldsets[scope.fieldsetIndex].properties.push(eval("({alias: '" + alias + "', value:'" + defaultValue + "'})")); renderModelPropertyIndex = getPropertyIdByAlias(scope.archetypeRenderModel.fieldsets[scope.fieldsetIndex].properties, alias); } scope.model.value = scope.archetypeRenderModel.fieldsets[scope.fieldsetIndex].properties[renderModelPropertyIndex].value; diff --git a/app/views/archetype.config.html b/app/views/archetype.config.html index ddcfdea..596094c 100644 --- a/app/views/archetype.config.html +++ b/app/views/archetype.config.html @@ -55,7 +55,7 @@