Alter config and defaultValue

- Turn into strings and try to eval on render
This commit is contained in:
Kevin Giszewski
2014-01-16 15:03:41 -05:00
parent d80f828b29
commit deb771e456
3 changed files with 40 additions and 28 deletions
-21
View File
@@ -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
+39 -6
View File
@@ -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;
+1 -1
View File
@@ -55,7 +55,7 @@
<div>
<label>View</label><select ng-model="property.view" ng-options="view.path as view.name for view in availableViews"></select>
</div>
<div ng-hide="true">
<div>
<label>Default Value</label><input type="text" ng-model="property.value" />
</div>
<div>