/**
 * @ngdoc controller
 * @name ValueConstraintController
 * @description
 * Handles the scope variable for value constraints
 */
angular.module('locApp.modules.profile.controllers')
    .controller('ValueConstraintController', function($scope, Server, localStorageService) {
        $scope.selectList = localStorageService.get('templateRefs');
        $scope.constraintFields = [];
        $scope.templateFields = [];
        $scope.valueFields = [];

        $scope.valueConstraint = {};

        // Method to check for import
        if($scope.importy){
            // override fields
            $scope.valueConstraint = $scope.propertyTemplate.valueConstraint;

            // checked to see if a value constraint is defined
            if($scope.valueConstraint) {
                $scope.importCascade($scope.templateFields, $scope.valueConstraint.valueTemplateRefs);
                $scope.importCascade($scope.valueFields, $scope.valueConstraint.useValuesFrom);

                if($scope.valueConstraint.useValuesFrom == null) {
                    $scope.valueConstraint.useValuesFrom = [];
                }
                if($scope.valueConstraint.valueTemplateRefs == null) {
                    $scope.valueConstraint.valueTemplateRefs = [];
                }
            }
            else {
                // create an empty one if none exists
                $scope.valueConstraint = {};
                $scope.valueConstraint.valueTemplateRefs = [];
                $scope.valueConstraint.useValuesFrom = [];
                $scope.propertyTemplate.valueConstraint = $scope.valueConstraint;
            }

            $scope.constraintFields.push("");
            $scope.loadCount++;
        }
        else {
            $scope.valueConstraint.valueTemplateRefs = [];
            $scope.valueConstraint.useValuesFrom = [];

            $scope.propertyTemplate.valueConstraint = $scope.valueConstraint;

            $scope.constraintFields.push("");
            $scope.loadCount++;
        }

        // Method to get the template references
        if(!$scope.selectList) {
            Server.get('server/getTemplateRefs', {})
                .then(function(response) {
                    $scope.selectList = response;
                    localStorageService.set('templateRefs', $scope.selectList);
                });
        }

        /**
         * @ngdoc function
         * @name addTemplate
         * @description
         * Adds a template reference to the value constraint
         */
        $scope.addTemplate = function() {
            $scope.importy = false;
            $scope.valueConstraint.valueTemplateRefs.push("");
            $scope.templateFields.push($scope.valueConstraint.valueTemplateRefs.length - 1);
        };

        /**
         * @ngdoc function
         * @name deleteTemplate
         * @description
         * Deletes a template reference from the list.
         */
        $scope.deleteTemplate = function() {
            $scope.deleteItem($scope.parentId, $scope.templateFields);
            $scope.deleteItem($scope.parentId, $scope.valueConstraint.valueTemplateRefs);
        };

        /**
         * @ngdoc function
         * @name addValue
         * @description
         * Adds a value data type to the value constraint
         */
        $scope.addValue = function() {
            $scope.importy = false;
            $scope.valueConstraint.useValuesFrom.push("");
            $scope.valueFields.push($scope.valueConstraint.useValuesFrom.length - 1);
        };

        /**
         * @ngdoc function
         * @name deleteValue
         * @description
         * Deletes a value reference from the list
         */
        $scope.deleteValue = function() {
            $scope.deleteItem($scope.parentId, $scope.valueFields);
            $scope.deleteItem($scope.parentId, $scope.valueConstraint.useValuesFrom);
        };
    });

@@ -2100,16 +2100,598 @@
         
+ var rts = %5B%5D;%0A            Server.get('/verso/api/configs?filter%5Bwhere%5D%5BconfigType%5D=profile', %7B%7D)%0A                .then(function(response) %7B%0A                    response.forEach(function(prof) %7B%0A                        prof.json.Profile.resourceTemplates.forEach(function(rt)%7B%0A                            rts.push(rt.id);%0A                        %7D);%0A                    %7D);%0A                    console.log(rts.length);%0A                    $scope.selectList = rts;%0A                    localStorageService.set('templateRefs', $scope.selectList);%0A                %7D);%0A                /*
  Server.
@@ -2759,32 +2759,75 @@
 ion(response) %7B%0A
+                    console.log(response);%0A
                 
@@ -2951,32 +2951,35 @@
              %7D);
+ */
 %0A        %7D%0A%0A    

Read resource template ids from verso profiles.