<commit_before>/**
 * Created by alexandr.dascal on 2/25/2015.
 */

(function () {
    'use strict';

    angular.module('angular-m-validation.directives')
        .directive('mValidation', ['$injector', function ($injector) {
            var $scope,
                mValidationProvider,
                schemaElements = [],
                formElements = [];

            var setup = function(injector) {
                $scope = injector.get('$scope');
                mValidationProvider = injector.get('mValidationProvider');
            };

            return {
                restrict: 'A',
                require: '^ngForm',
                compile: function(form, formAttrs) {
                    setup($injector);

                    var schemaName = formAttrs.schema;

                    var schema = $scope[schemaName] || mValidationProvider.getSchema(schemaName);

                    if (!schema) {
                        throw new Error('Schema not found');
                    }

                    var schemaGlobals = schema.globals || {};
                    var schemaProperties = schema.properties || {};

                    var formValidateOn = formAttrs.validateOn || schemaGlobals.validateOn;
                    var formElements = form.querySelectorAll('input, select, textarea');
                }
            };
        }]);
})();<commit_msg>validation<commit_after>/**
 * Created by alexandr.dascal on 2/25/2015.
 */

(function () {
    'use strict';

    angular.module('angular-m-validation.directives')
        .directive('mValidation', ['$injector', function ($injector) {
            var $scope,
                mValidationProvider,
                $this = this;

            var setup = function (injector) {
                $scope = injector.get('$scope');
                mValidationProvider = injector.get('mValidationProvider');
            };

            $this.parseSchema = function (schemaName) {
                var schema = $scope[schemaName] || mValidationProvider.getSchema(schemaName);

                if (!schema) {
                    throw new Error('Schema not found');
                }
                return schema;
            };

            $this.parseSchemaElements = function (schema, validateOn) {
                var schemaElements = [];
                for (var prop in schema) {
                    if (schema.hasOwnProperty(prop)) {
                        var schemaGlobals = schema.globals || schema.__globals;

                        var schemaElement = angular.copy(schema[prop]);

                        schemaElement.validateOn = schemaElement.validateOn ||
                                                    schema.validateOn ||
                                                    schemaGlobals.validateOn ||
                                                    validateOn;

                        if (validateOn === 'change') {
                            // remove old watcher
                            if (schemaElement.watcher) {
                                schemaElement.watcher();
                            }

                            var schemaElementName = schemaElement.name || prop;
                            schemaElement.watcher = $scope.$watch(schemaElementName, function() {
                                // validate
                            });
                        }

                        schemaElements.push(schemaElement);
                    }
                }

                return schemaElements;
            };

            return {
                restrict: 'AE',
                compile: function (element, attrs) {
                    setup($injector);

                    if (angular.isUndefined(attrs.schema)) {
                        throw new Error('Schema is not defined');
                    }

                    var schema = $this.parseSchema(attrs.schema);
                    var schemaElements = $this.parseSchemaElements(schema, attrs.validateOn);

                    attrs.$observe('schema', function (schemaName) {
                        var schema = $this.parseSchema(schemaName);
                        var schemaElements = $this.parseSchemaElements(schema, attrs.validateOn);
                    });

                    attrs.$observe('validateOn', function (validateOn) {
                        var schemaElements = $this.parseSchemaElements(schema, validateOn);
                    });
                }
            };
        }]);
})();
{'fraction_non_alphanumeric': 0.1000667111407605, 'fraction_numerical': 0.00311318656882366, 'mean_word_length': 1.1877431906614786, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4724858', 'n_tokens_mistral': 1031, 'n_tokens_neox': 946, 'n_words': 192}