72 lines
2.9 KiB
JavaScript
72 lines
2.9 KiB
JavaScript
angular.module('umbraco.services').factory('archetypeService', function () {
|
|
|
|
//public
|
|
return {
|
|
//helper that returns a JS ojbect from 'value' string or the original string
|
|
jsonOrString: function (value, developerMode, debugLabel){
|
|
if(value && typeof value == 'string'){
|
|
try{
|
|
if(developerMode == '1'){
|
|
console.log("Trying to parse " + debugLabel + ": " + value);
|
|
}
|
|
value = JSON.parse(value);
|
|
}
|
|
catch(exception)
|
|
{
|
|
if(developerMode == '1'){
|
|
console.log("Failed to parse " + debugLabel + ".");
|
|
}
|
|
}
|
|
}
|
|
|
|
if(value && developerMode == '1'){
|
|
console.log(debugLabel + " post-parsing: ");
|
|
console.log(value);
|
|
}
|
|
|
|
return value;
|
|
},
|
|
getFieldsetByAlias: function (fieldsets, alias)
|
|
{
|
|
return _.find(fieldsets, function(fieldset){
|
|
return fieldset.alias == alias;
|
|
});
|
|
},
|
|
getPropertyIndexByAlias: function(properties, alias){
|
|
for (var i in properties)
|
|
{
|
|
if (properties[i].alias == alias) {
|
|
return i;
|
|
}
|
|
}
|
|
},
|
|
getPropertyByAlias: function (fieldset, alias){
|
|
return _.find(fieldset.properties, function(property){
|
|
return property.alias == alias;
|
|
});
|
|
},
|
|
getUniquePropertyAlias: function (currentScope, propertyAliasParts) {
|
|
if (currentScope.hasOwnProperty('fieldsetIndex') && currentScope.hasOwnProperty('property') && currentScope.hasOwnProperty('propertyConfigIndex'))
|
|
{
|
|
var currentPropertyAlias = "f" + currentScope.fieldsetIndex + "-" + currentScope.property.alias + "-p" + currentScope.propertyConfigIndex;
|
|
propertyAliasParts.push(currentPropertyAlias);
|
|
}
|
|
else if (currentScope.hasOwnProperty('isPreValue')) // Crappy way to identify this is the umbraco property scope
|
|
{
|
|
var umbracoPropertyAlias = currentScope.$parent.$parent.property.alias; // Crappy way to get the umbraco host alias once we identify its scope
|
|
propertyAliasParts.push(umbracoPropertyAlias);
|
|
}
|
|
|
|
if (currentScope.$parent)
|
|
this.getUniquePropertyAlias(currentScope.$parent, propertyAliasParts);
|
|
|
|
return _.unique(propertyAliasParts).reverse().join("-");
|
|
},
|
|
getFieldset: function(scope) {
|
|
return scope.archetypeRenderModel.fieldsets[scope.fieldsetIndex];
|
|
},
|
|
getFieldsetProperty: function (scope) {
|
|
return this.getFieldset(scope).properties[scope.renderModelPropertyIndex];
|
|
}
|
|
}
|
|
}); |