whitef0x0/tellform

View on GitHub
public/modules/forms/config/forms.client.config.js

Summary

Maintainability
C
1 day
Test Coverage
'use strict';

// Configuring the Forms drop-down menus
angular.module('forms').run(['Menus',
    function(Menus) {
        // Set top bar menu items
        Menus.addMenuItem('topbar', 'My Forms', 'forms', '', '/forms', false);
    }
]).filter('secondsToDateTime', [function() {
    return function(seconds) {
        return new Date(1970, 0, 1).setSeconds(seconds);
    };
}]).filter('formValidity', [function(){
        return function(formObj){
            if(formObj && formObj.form_fields && formObj.visible_form_fields){

                //get keys
                var formKeys = Object.keys(formObj);

                //we only care about things that don't start with $
                var fieldKeys = formKeys.filter(function(key){
                    return key[0] !== '$';
                });

                var fields = formObj.form_fields;

                var valid_count = fields.filter(function(field){
                    if(typeof field === 'object' && field.fieldType !== 'statement' && field.fieldType !== 'rating'){
                        return !!(field.fieldValue);
                    } else if(field.fieldType === 'rating'){
                        return true;
                    }

                }).length;
                return valid_count - (formObj.form_fields.length - formObj.visible_form_fields.length);
            }
            return 0;
        };
}]).filter('trustSrc', ['$sce', function($sce){
        return function(formUrl){
            return $sce.trustAsResourceUrl(formUrl);
        };
}]).config(['$provide', function ($provide){
    $provide.decorator('accordionDirective', function($delegate) {
        var directive = $delegate[0];
        directive.replace = true;
        return $delegate;
    });
}]);