From 963447ba38fe16f6b774d1b6d27afd31350327c7 Mon Sep 17 00:00:00 2001 From: Tom Fulton Date: Wed, 15 Jan 2014 23:27:33 -0700 Subject: [PATCH] Replace fieldset label expressions with basic templates The Label Expr. field can now be defined like this: Person: {{firstName}} {{lastName}} Where firstName and lastName are the property alias of a property on the current fieldset --- app/controllers/controller.js | 29 +++++++++++++++++++++++------ app/views/archetype.html | 2 +- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/controllers/controller.js b/app/controllers/controller.js index 438ced0..706f687 100644 --- a/app/controllers/controller.js +++ b/app/controllers/controller.js @@ -15,12 +15,21 @@ initArchetypeRenderModel(); //helper to get $eval the labelExpression - $scope.getFieldsetTitle = function(expression, fieldsetIndex) - { - if(!expression) return ""; - - return expression.replace(/\$fieldsetIndex/g, fieldsetIndex); - } + $scope.getFieldsetTitle = function(fieldsetConfigModel, fieldsetIndex) { + var fieldset = $scope.archetypeRenderModel.fieldsets[fieldsetIndex]; + var template = fieldsetConfigModel.labelExpression; + var rgx = /{{(.*?)}}*/g; + var results; + var parsedTemplate = template; + + while ((results = rgx.exec(template)) !== null) { + var propertyAlias = results[1]; + var propertyValue = $scope.getPropertyValueByAlias(fieldset, propertyAlias); + parsedTemplate = parsedTemplate.replace(results[0], propertyValue); + } + + return parsedTemplate; + }; /* add/remove/sort */ @@ -112,6 +121,14 @@ } } } + + //helper to get a property by alias from a fieldset + $scope.getPropertyValueByAlias = function(fieldset, propertyAlias) { + var property = _.find(fieldset.properties, function(p) { + return p.alias == propertyAlias; + }); + return (typeof property !== 'undefined') ? property.value : ''; + }; //helper for collapsing $scope.focusFieldset = function(fieldset){ diff --git a/app/views/archetype.html b/app/views/archetype.html index 35a7231..ab70331 100644 --- a/app/views/archetype.html +++ b/app/views/archetype.html @@ -13,7 +13,7 @@