Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Tom Fulton
    @tomfulton
    OHAI
    Taylor Smith
    @taylorsmith
    HAHA HI
    this is neat
    Tom Fulton
    @tomfulton
    very
    you at home again today?
    Taylor Smith
    @taylorsmith
    trying to decide
    Tom Fulton
    @tomfulton
    haha
    Taylor Smith
    @taylorsmith
    i might be hungover
    Tom Fulton
    @tomfulton
    slacker
    nice!
    Taylor Smith
    @taylorsmith
    i want to come in
    but i also don't feel good
    Tom Fulton
    @tomfulton
    • [ ] Come in
    • [ ] Nap
    • [ ] ...
    • [ ] Profit
    markdown fail
    Taylor Smith
    @taylorsmith
    haha
    Tom Fulton
    @tomfulton
    i beg to differ
    Taylor Smith
    @taylorsmith
    angular.module("umbraco").controller("Imulus.ArchetypeController", function ($scope, $http, assetsService, angularHelper, notificationsService) {
    //$scope.model.value = "";
    
    //get a reference to the current form
    var form = angularHelper.getCurrentForm($scope);
    
    //set the config equal to our prevalue config
    $scope.model.config = $scope.model.config.archetypeConfig;
    
    //ini the model
    $scope.model.value = $scope.model.value || { fieldsets: [getEmptyRenderFieldset($scope.model.config.fieldsets[0])] };
    
    //ini the render model
    $scope.archetypeRenderModel = {};
    initArchetypeRenderModel();
    
    //helper to get $eval the labelTemplate
    $scope.getFieldsetTitle = function(fieldsetConfigModel, fieldsetIndex) {
        var fieldset = $scope.archetypeRenderModel.fieldsets[fieldsetIndex];
        var fieldsetConfig = $scope.getConfigFieldsetByAlias(fieldset.alias);
        var template = fieldsetConfigModel.labelTemplate;
    
        if (template.length < 1)
            return fieldsetConfig.label;
    
        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;
    };
    
    //sort config
    $scope.sortableOptions = {
        axis: 'y',
        cursor: "move",
        handle: ".handle",
        update: function (ev, ui) {
    
        },
        stop: function (ev, ui) {
    
        }
    };
    
    //handles a fieldset add
    $scope.addRow = function (fieldsetAlias, $index) {
        if ($scope.canAdd())
        {
            if ($scope.model.config.fieldsets)
            {
                var newFieldset = getEmptyRenderFieldset($scope.getConfigFieldsetByAlias(fieldsetAlias));
    
                if (typeof $index != 'undefined')
                {
                    $scope.archetypeRenderModel.fieldsets.splice($index + 1, 0, newFieldset);
                }
                else
                {
                    $scope.archetypeRenderModel.fieldsets.push(newFieldset);
                }
            }
            newFieldset.collapse = true;
            $scope.focusFieldset(newFieldset);
        }
    }
    
    //rather than splice the archetypeRenderModel, we're hiding this and cleaning onFormSubmitting
    $scope.removeRow = function ($index) {
        if ($scope.canRemove()) {
            if (confirm('Are you sure you want to remove this?')) {
                $scope.archetypeRenderModel.fieldsets[$index].remove = true;
            }
        }
    }
    
    //helpers for determining if a user can do something
    $scope.canAdd = function ()
    {
        if ($scope.model.config.maxFieldsets)
        {
            return countVisible() < $scope.model.config.maxFieldsets;
        }
    
        return true;
    }
    
    //helper that returns if an item can be removed
    $scope.canRemove = function ()
    {   
        return countVisible() > 1;
    }
    
    //helper that returns if an item can be sorted
    $scope.canSort = function ()
    {
        return countVisible() > 1;
    }
    
    //helper, ini the render model from the server (model.value)
    function initArchetypeRenderModel() {
        $scope.archetypeRenderModel = $scope.model.value;
    
        _.each($scope.archetypeRenderModel.fieldsets, function (fieldset)
        {
            fieldset.remove = false;
            fieldset.collapse = false;
            fieldset.isValid = true;
        });      
    }
    
    //helper to get the correct fieldset from config
    $scope.getConfigFieldsetByAlias = function(alias) {
        return _.find($scope.model.config.fieldsets, function(fieldset){
            return fieldset.alias == alias;
        });
    }
    
    //helper to get a property by alias from a fieldset
    $scope.getPropertyValueByAlias = function(fieldset, propertyAlias) {
        var property = _.find(fieldset.prope
    dat syntax highlighting
    Tom Fulton
    @tomfulton
    wow.