<commit_before>﻿/* global angular:false */

(function () {

    "use strict";

    angular.module('jsnbt')
        .directive('ctrlCustom', ['$timeout', 'CONTROL_EVENTS', function ($timeout, CONTROL_EVENTS) {

            return {
                restrict: 'E',
                replace: true,
                transclude: true,

                scope: {
                    ngModel: '=',
                    ngDisabled: '=',
                    ngLabel: '@',
                    ngTip: '@',
                    ngValidating: '=',
                    ngScope: '='
                },
                compile: function (elem, attrs, transclude) {

                    return function (scope, lElem, lAttrs) {
                        lElem.addClass('ctrl');
                        lElem.addClass('ctrl-custom');

                        scope.id = Math.random().toString().replace('.', '');
                        scope.valid = true;

                        var initiated = false;

                        var childScope = scope.$new();

                        var built = false;
                        var build = function () {
                            var container = $('#cstm' + scope.id, lElem);

                            if (container.length > 0 && !built) {

                                console.log('build', container.length);

                                container.empty();

                                childScope.model = scope.ngModel;
                                childScope.ngDisabled = scope.ngDisabled;
                                childScope.ngValidating = scope.ngValidating;

                                if (_.isObject(scope.ngScope)) {
                                    for (var contextName in scope.ngScope) {
                                        childScope[contextName] = scope.ngScope[contextName];
                                    }
                                }

                                childScope.$watch('model', function () {
                                    childScope.$broadcast(CONTROL_EVENTS.validate);
                                });

                                transclude(childScope, function (clone, innerScope) {
                                    container.append(clone);
                                });

                                childScope.$on(CONTROL_EVENTS.valueIsValid, function (sender, value) {
                                    sender.stopPropagation();

                                    scope.$emit(CONTROL_EVENTS.valueIsValid, value);
                                });

                                childScope.$on(CONTROL_EVENTS.initiateValidation, function (sender) {
                                    initiated = true;
                                });

                                childScope.$on(CONTROL_EVENTS.clearValidation, function (sender) {
                                    initiated = false;
                                });

                                built = true;
                            }
                        };

                        scope.$watch('ngModel', function (newValue, prevValue) {
                            build();

                            childScope.model = newValue;
                        });

                        scope.$watch('ngDisabled', function (newValue, prevValue) {
                            childScope.ngDisabled = newValue;
                        });

                        scope.$watch('ngValidating', function (newValue, prevValue) {
                            childScope.ngValidating = newValue;
                        });

                        scope.$watch('ngScope', function (newValue, prevValue) {
                            if (_.isObject(newValue)) {
                                for (var contextName in newValue) {
                                    childScope[contextName] = newValue[contextName];
                                }
                            }
                        }, true);
                    };
                },
                templateUrl: 'tmpl/core/controls/ctrlCustom.html'
            };

        }]);

})();<commit_msg>ctrlCustom fix if model is undefined<commit_after>﻿/* global angular:false */

(function () {

    "use strict";

    angular.module('jsnbt')
        .directive('ctrlCustom', ['$timeout', 'CONTROL_EVENTS', function ($timeout, CONTROL_EVENTS) {

            return {
                restrict: 'E',
                replace: true,
                transclude: true,

                scope: {
                    ngModel: '=',
                    ngDisabled: '=',
                    ngLabel: '@',
                    ngTip: '@',
                    ngValidating: '=',
                    ngScope: '='
                },
                compile: function (elem, attrs, transclude) {

                    return function (scope, lElem, lAttrs) {
                        lElem.addClass('ctrl');
                        lElem.addClass('ctrl-custom');

                        scope.id = Math.random().toString().replace('.', '');
                        scope.valid = true;

                        var initiated = false;

                        var childScope = scope.$new();

                        var built = false;
                        var build = function () {
                            var container = $('#cstm' + scope.id, lElem);

                            if (container.length > 0 && !built) {

                                console.log('build', container.length);

                                container.empty();

                                childScope.model = scope.ngModel;
                                childScope.ngDisabled = scope.ngDisabled;
                                childScope.ngValidating = scope.ngValidating;

                                if (_.isObject(scope.ngScope)) {
                                    for (var contextName in scope.ngScope) {
                                        childScope[contextName] = scope.ngScope[contextName];
                                    }
                                }

                                childScope.$watch('model', function () {
                                    childScope.$broadcast(CONTROL_EVENTS.validate);
                                });

                                transclude(childScope, function (clone, innerScope) {
                                    container.append(clone);
                                });

                                childScope.$on(CONTROL_EVENTS.valueIsValid, function (sender, value) {
                                    sender.stopPropagation();

                                    scope.$emit(CONTROL_EVENTS.valueIsValid, value);
                                });

                                childScope.$on(CONTROL_EVENTS.initiateValidation, function (sender) {
                                    initiated = true;
                                });

                                childScope.$on(CONTROL_EVENTS.clearValidation, function (sender) {
                                    initiated = false;
                                });

                                built = true;
                            }
                        };

                        scope.$watch('ngModel', function (newValue, prevValue) {
                            build();

                            if (newValue === undefined)
                                scope.ngModel = {};

                            childScope.model = scope.ngModel;
                        });

                        scope.$watch('ngDisabled', function (newValue, prevValue) {
                            childScope.ngDisabled = newValue;
                        });

                        scope.$watch('ngValidating', function (newValue, prevValue) {
                            childScope.ngValidating = newValue;
                        });

                        scope.$watch('ngScope', function (newValue, prevValue) {
                            if (_.isObject(newValue)) {
                                for (var contextName in newValue) {
                                    childScope[contextName] = newValue[contextName];
                                }
                            }
                        }, true);
                    };
                },
                templateUrl: 'tmpl/core/controls/ctrlCustom.html'
            };

        }]);

})();
{'fraction_non_alphanumeric': 0.09356243380016477, 'fraction_numerical': 0.00023537719195010004, 'mean_word_length': 0.8173652694610778, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3947835', 'n_tokens_mistral': 1836, 'n_tokens_neox': 1661, 'n_words': 297}