<commit_before>angular.module("schemaForm").run(["$templateCache", function($templateCache) {$templateCache.put("directives/decorators/bootstrap/uiselect/multi.html","<div class=\"form-group\" ng-class=\"{\'has-error\': hasError(), \'has-success\': hasSuccess(), \'has-feedback\': form.feedback !== false}\" ng-init=\"form.select_models=(form.schema.items| whereMulti : \'value\' : ($$value$$||[]))\">\n  <label class=\"control-label\" ng-show=\"showTitle()\">{{form.title}}</label>\n  <div class=\"form-group\" ng-controller=\"UiSelectController\">\n    <ui-select multiple sortable-options=\"{{form.sortableOptions}}\" ng-if=\"!(form.options.tagging||false)\" ng-model=\"form.select_models\" theme=\"bootstrap\" on-select=\"$$value$$.push($item.value)\" on-remove=\"$$value$$.splice($$value$$.indexOf($item.value), 1)\" class=\"{{form.options.uiClass}}\">\n      <ui-select-match class=\"ui-select-match\" placeholder=\"{{form.placeholder || form.schema.placeholder || (\'placeholders.select\' | translate)}}\">{{$item.label}}</ui-select-match>\n      <ui-select-choices class=\"ui-select-choices\" refresh=\"fetchResult(form.schema, form.options, $select.search)\"\n         refresh-delay=\"form.options.refreshDelay\" group-by=\"form.options.groupBy\"  repeat=\"item in form.schema.items | propsFilter: {label: $select.search, description: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\') }\">\n        <div ng-bind-html=\"item.label | highlight: $select.search\"></div>\n        <div ng-if=\"item.description\">\n          <span ng-bind-html=\"\'<small>\' + (\'\'+item.description | highlight: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\'))+ \'</small>\'\"></span>\n        </div>\n    </ui-select-choices>\n    </ui-select>\n    <ui-select ng-controller=\"UiSelectController\" multiple ng-if=\"(form.options.tagging||false) && !(form.options.groupBy || false)\" tagging=\"form.options.tagging||false\" tagging-label=\"form.options.taggingLabel\" tagging-tokens=\"form.options.taggingTokens\" sortable-options=\"{{form.sortableOptions}}\" ng-model=\"form.select_models\" theme=\"bootstrap\" on-select=\"$$value$$.push($item.value)\" on-remove=\"$$value$$.splice($$value$$.indexOf($item.value), 1)\" class=\"{{form.options.uiClass}}\">\n      <ui-select-match class=\"ui-select-match\" placeholder=\"{{form.placeholder || form.schema.placeholder || (\'placeholders.select\' | translate)}}\">{{$item.label}}&nbsp;<small>{{($item.isTag===true ?  form.options.taggingLabel : \'\')}}</small></ui-select-match>\n      <ui-select-choices class=\"ui-select-choices\" refresh-delay=\"form.options.refreshDelay\" refresh=\"fetchResult(form.schema, form.options, $select.search)\"\n         refresh-delay=\"form.options.refreshDelay\" repeat=\"item in form.schema.items | propsFilter: {label: $select.search, description: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\') }\">\n          <div ng-if=\"item.isTag\" ng-bind-html=\"\'<div>\' + (item.label   | highlight: $select.search) + \' \' + form.options.taggingLabel + \'</div><div class=&quot;divider&quot;></div>\'\"></div>\n          <div ng-if=\"!item.isTag\" ng-bind-html=\"item.label + item.isTag | highlight: $select.search\"></div>\n      <div ng-if=\"item.description\"> \n        <span ng-bind-html=\"\'<small>\' + (\'\'+item.description | highlight: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\')) + \'</small>\'\"></span>\n      </div>\n    </ui-select-choices>\n      <!--repeat code because tagging does not display properly under group by but is still useful -->\n    </ui-select>\n\n    <ui-select ng-controller=\"UiSelectController\" multiple ng-if=\"(form.options.tagging||false) && (form.options.groupBy || false)\" tagging=\"form.options.tagging||false\" tagging-label=\"form.options.taggingLabel\" tagging-tokens=\"form.options.taggingTokens\" sortable-options=\"{{form.sortableOptions}}\" ng-model=\"form.select_models\" theme=\"bootstrap\" on-select=\"$$value$$.push($item.value)\" on-remove=\"$$value$$.splice($$value$$.indexOf($item.value), 1)\" class=\"{{form.options.uiClass}}\">\n      <ui-select-match class=\"ui-select-match\" placeholder=\"{{form.placeholder || form.schema.placeholder || (\'placeholders.select\' | translate)}}\">{{$item.label}}&nbsp;<small>{{($item.isTag===true ?  form.options.taggingLabel : \'\')}}</small></ui-select-match>\n      <ui-select-choices class=\"ui-select-choices\" group-by=\"form.options.groupBy\" refresh-delay=\"form.options.refreshDelay\" refresh=\"fetchResult(form.schema, form.options, $select.search)\"\n         refresh-delay=\"form.options.refreshDelay\" repeat=\"item in form.schema.items | propsFilter: {label: $select.search, description: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\') }\">\n          <div ng-if=\"item.isTag\" ng-bind-html=\"\'<div>\' + (item.label   | highlight: $select.search) + \' \' + form.options.taggingLabel + \'</div><div class=&quot;divider&quot;></div>\'\"></div>\n          <div ng-if=\"!item.isTag\" ng-bind-html=\"item.label + item.isTag | highlight: $select.search\"></div>\n      <div ng-if=\"item.description\"> \n        <span ng-bind-html=\"\'<small>\' + (\'\'+item.description | highlight: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\')) + \'</small>\'\"></span>\n      </div>\n    </ui-select-choices>\n\n    </ui-select>\n    <input name=\"{{form.key.slice(-1)[0]}}\" toggle-model type=\"hidden\" ng-model=\"insideModel\" sf-changed=\"form\" schema-validate=\"form\" />\n    <span ng-if=\"form.feedback !== false\"\n      class=\"form-control-feedback\"\n      ng-class=\"evalInScope(form.feedback) || {\'glyphicon\': true, \'glyphicon-ok\': hasSuccess(), \'glyphicon-remove\': hasError() }\"></span>\n    <div class=\"help-block\"\n      ng-show=\"(hasError() && errorMessage(schemaError())) || form.description\"\n      ng-bind-html=\"(hasError() && errorMessage(schemaError())) || form.description\"></div>\n  </div>\n</div>\n");
$templateCache.put("directives/decorators/bootstrap/uiselect/single.html","<div class=\"form-group\" ng-class=\"{\'has-error\': hasError(), \'has-success\': hasSuccess(), \'has-feedback\': form.feedback !== false}\" ng-init=\"select_models=(form.schema.items | where : {value: $$value$$})\">\n  <label class=\"control-label\" ng-show=\"showTitle()\">{{form.title}}</label>\n  <div class=\"form-group\" ng-init=\"select_model.selected=select_models[0]\">\n    <div class=\"input-group\">\n      <ui-select ng-model=\"select_model.selected\" ng-controller=\"UiSelectController\"  ng-if=\"!(form.options.tagging||false)\" theme=\"bootstrap\" ng-disabled=\"form.disabled\" on-select=\"$$value$$=$item.value\" class=\"{{form.options.uiClass}}\" append-to-body=\"true\">\n        <ui-select-match class=\"ui-select-match\" placeholder=\"{{form.placeholder || form.schema.placeholder || (\'placeholders.select\' | translate)}}\">{{select_model.selected.label}}</ui-select-match>\n        <ui-select-choices class=\"ui-select-choices\" refresh=\"fetchResult(form.schema, form.options, $select.search)\"\n               refresh-delay=\"form.options.refreshDelay\" group-by=\"form.options.groupBy\"  repeat=\"item in form.schema.items | propsFilter: {label: $select.search, description: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\') }\">\n                  <div ng-bind-html=\"item.label | highlight: $select.search\"></div>\n        <div ng-if=\"item.description\">\n          <span ng-bind-html=\"\'<small>\' + (\'\'+item.description | highlight: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\'))+ \'</small>\'\"></span></div>\n        </ui-select-choices>\n      </ui-select>\n      <ui-select ng-controller=\"UiSelectController\"  ng-model=\"select_model.selected\" ng-if=\"(form.options.tagging||false) && !(form.options.groupBy || false)\" tagging=\"form.options.tagging||false\" tagging-label=\"form.options.taggingLabel\" tagging-tokens=\"form.options.taggingTokens\"\n        theme=\"bootstrap\" ng-disabled=\"form.disabled\" on-select=\"$$value$$=$item.value\" class=\"{{form.options.uiClass}}\" append-to-body=\"true\">\n        <ui-select-match class=\"ui-select-match\" placeholder=\"{{form.placeholder || form.schema.placeholder || (\'placeholders.select\' | translate)}}\">{{select_model.selected.label}}&nbsp;<small>{{(select_model.selected.isTag===true ? form.options.taggingLabel : \'\')}}</small></ui-select-match>\n        <!--repeat code because tagging does not display properly under group by but is still useful -->\n        <ui-select-choices class=\"ui-select-choices\" refresh=\"form.options.refreshMethod(form.schema, $select.search)\"\n               refresh-delay=\"form.options.refreshDelay\" repeat=\"item in form.schema.items | propsFilter: {label: $select.search, description: (form.options.searchDescription===true ? $select.search : \'NOTSEARCHINGFORTHIS\') }\">\n          <div ng-if=\"item.isTag\" ng-bind-html=\"\'<div>\' + (item.label   | highlight: $select.search) + \' \' + form.options.taggingLabel + \'</div><div class=&quot;divider&quot;></div>\'\"></div><div ng-if=\"!item.isTag\" ng-bind-html=\"item.label + item.isTag| highlight: $select.search\"></div>\n        <div ng-if=\"item.description\">\n          <span  ng-bind-html=\"\'<small>\' + (\'\'+item.description | highlight: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\')) + \'</small>\'\"></span>\n        </div>\n      </ui-select-choices>\n      </ui-select>\n\n        <!--repeat code because tagging does not display properly under group by but is still useful -->\n\n      <ui-select ng-controller=\"UiSelectController\"  ng-model=\"select_model.selected\" ng-if=\"(form.options.tagging||false) && (form.options.groupBy || false)\"  tagging=\"form.options.tagging||false\" tagging-label=\"form.options.taggingLabel\" tagging-tokens=\"form.options.taggingTokens\"\n        theme=\"bootstrap\" ng-disabled=\"form.disabled\" on-select=\"$$value$$=$item.value\" class=\"{{form.options.uiClass}}\" append-to-body=\"true\">\n        <ui-select-match class=\"ui-select-match\" placeholder=\"{{form.placeholder || form.schema.placeholder || (\'placeholders.select\' | translate)}}\">{{select_model.selected.label}}&nbsp;<small>{{(select_model.selected.isTag===true ? form.options.taggingLabel : \'\')}}</small></ui-select-match>\n        <ui-select-choices class=\"ui-select-choices\" group-by=\"form.options.groupBy\" refresh=\"form.options.refreshMethod(form.schema, $select.search)\"\n               refresh-delay=\"form.options.refreshDelay\" repeat=\"item in form.schema.items | propsFilter: {label: $select.search, description: (form.options.searchDescription===true ? $select.search : \'NOTSEARCHINGFORTHIS\') }\">\n          <div ng-if=\"item.isTag\" ng-bind-html=\"\'<div>\' + (item.label   | highlight: $select.search) + \' \' + form.options.taggingLabel + \'</div><div class=&quot;divider&quot;></div>\'\"></div><div ng-if=\"!item.isTag\" ng-bind-html=\"item.label + item.isTag| highlight: $select.search\"></div>\n        <div ng-if=\"item.description\">\n          <span  ng-bind-html=\"\'<small>\' + (\'\'+item.description | highlight: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\')) + \'</small>\'\"></span>\n        </div>\n      </ui-select-choices>\n      </ui-select>\n      <span class=\"input-group-btn\">\n          <button ng-click=\"$$value$$ = undefined\" class=\"btn btn-default\" type=\"button\">\n              <span class=\"fa fa-trash\"></span>\n          </button>\n      </span>\n    </div>\n    <input name=\"{{form.key.slice(-1)[0]}}\" type=\"hidden\" toggle-single-model sf-changed=\"form\" ng-model=\"insideModel\" schema-validate=\"form\" />\n    <span ng-if=\"form.feedback !== false\"\n      class=\"form-control-feedback\"\n      ng-class=\"evalInScope(form.feedback) || {\'glyphicon\': true, \'glyphicon-ok\': hasSuccess(), \'glyphicon-remove\': hasError() }\"></span>\n    <div class=\"help-block\"\n      ng-show=\"(hasError() && errorMessage(schemaError())) || form.description\"\n      ng-bind-html=\"(hasError() && errorMessage(schemaError())) || form.description\"></div>\n  </div>\n</div>\n");}]);
angular.module('schemaForm').config(
    ['schemaFormProvider', 'schemaFormDecoratorsProvider', 'sfPathProvider',
        function (schemaFormProvider, schemaFormDecoratorsProvider, sfPathProvider) {

            var uiselect = function (name, schema, options) {
                if (schema.type === 'string' && schema.format == 'uiselect') {
                    var f = schemaFormProvider.stdFormObj(name, schema, options);
                    f.key = options.path;
                    f.type = 'uiselect';
                    options.lookup[sfPathProvider.stringify(options.path)] = f;
                    return f;
                }
            };

            schemaFormProvider.defaults.string.unshift(uiselect);

            var uiselect = function (name, schema, options) {
                if (schema.type === 'number' && schema.format == 'uiselect') {
                    var f = schemaFormProvider.stdFormObj(name, schema, options);
                    f.key = options.path;
                    f.type = 'uiselect';
                    options.lookup[sfPathProvider.stringify(options.path)] = f;
                    return f;
                }
            };

            schemaFormProvider.defaults.number.unshift(uiselect);

            var uimultiselect = function (name, schema, options) {
                if (schema.type === 'array' && schema.format == 'uiselect') {
                    var f = schemaFormProvider.stdFormObj(name, schema, options);
                    f.key = options.path;
                    f.type = 'uimultiselect';
                    options.lookup[sfPathProvider.stringify(options.path)] = f;
                    return f;
                }
            };
            schemaFormProvider.defaults.array.unshift(uimultiselect);


            //Add to the bootstrap directive
            schemaFormDecoratorsProvider.addMapping('bootstrapDecorator', 'uiselect',
                'directives/decorators/bootstrap/uiselect/single.html');
            schemaFormDecoratorsProvider.createDirective('uiselect',
                'directives/decorators/bootstrap/uiselect/single.html');
            schemaFormDecoratorsProvider.addMapping('bootstrapDecorator', 'uimultiselect',
                'directives/decorators/bootstrap/uiselect/multi.html');
            schemaFormDecoratorsProvider.createDirective('uimultiselect',
                'directives/decorators/bootstrap/uiselect/multi.html');
        }])
    .directive("toggleSingleModel", function ($timeout) {
        // some how we get this to work ...
        return {
            require: 'ngModel',
            restrict: "A",
            scope: {},
            replace: true,
            controller: ['$scope', function ($scope) {

                /**
                 * Selects active option when:
                 * a) model value is changed
                 * b) dropdown options are changed
                 *
                 * @param {string} val Selected value
                 * @param {bool} doResetIfNotFound Boolean - if true and value not found in options list dropdown value is reset
                 */
                var doSelect = function (val, doResetIfNotFound) {

                    if (!angular.isDefined(val)) {
                        // value not passed (or empty value passed) - reset dropdown value
                        $scope.$parent.select_model.selected = undefined;
                    } else {

                        // value passed, check if it is available in the options list, if so - select it
                        var exists = false;
                        angular.forEach($scope.$parent.form.schema.items, function ($item) {
                            if ($item.value == val) {
                                $scope.$parent.select_model.selected = $item;
                                exists = true;
                            }
                        });

                        // value is not found in options list and flag (that dropdown should be reset) is passed, reset value
                        if (!exists && doResetIfNotFound) {
                            $scope.$parent.select_model.selected = undefined;
                        }
                    }

                    $timeout(function () {
                        $scope.$parent.ngModel.$setPristine();
                        $scope.$parent.ngModel.$$parentForm.$setPristine();
                    });
                };

                var getModelKey = function () {

                    var key = $scope.$parent.form.key;

                    // Redact part of the key, used in arrays
                    // KISS keyRedaction is a number.
                    if ($scope.$parent.state && $scope.$parent.state.keyRedaction) {
                        key = key.slice($scope.$parent.state.keyRedaction);
                    } else if (Array.isArray(key)) {
                        key = key[0];
                    }

                    return key;
                };

                // model value changed in outside
                $scope.$parent.$watch('model.$$value$$'.replace('$$value$$', getModelKey()), function (val) {
                    doSelect(val, false);
                });

                // select items changed
                $scope.$parent.$watch('form.schema.items', function () {
                    if ($scope.$parent.model && $scope.$parent.model[getModelKey()]) {
                        doSelect($scope.$parent.model[getModelKey()], true);
                    }
                }, true);

                $scope.$parent.$watch('select_model.selected', function () {
                    $scope.$parent.insideModel = $scope.$parent.select_model.selected ? $scope.$parent.select_model.selected.value : undefined;
                    $scope.$parent.ngModel.$setViewValue($scope.$parent.select_model.selected ? $scope.$parent.select_model.selected.value : undefined);
                });
            }],
        };
    })
    .directive("toggleModel", function ($timeout) {
        // some how we get this to work ...
        return {
            require: 'ngModel',
            restrict: "A",
            scope: {},
            replace: true,
            controller: ['$scope', 'sfSelect', function ($scope, sfSelect) {
                var list = sfSelect($scope.$parent.form.key, $scope.$parent.model);
                //as per base array implemenation if the array is undefined it must be set as empty for data binding to work
                if (angular.isUndefined(list)) {
                    list = [];
                    sfSelect($scope.$parent.form.key, $scope.$parent.model, list);
                }

                var doSelect = function (selectedItems) {

                    // clean selected options
                    while ($scope.$parent.form.select_models.length) {
                        $scope.$parent.form.select_models.pop();
                    }

                    // reselect values
                    angular.forEach($scope.$parent.form.schema.items, function ($item) {
                        angular.forEach(selectedItems, function (selectedItem) {
                            if ($item.value == selectedItem) {
                                $scope.$parent.form.select_models.push($item);
                            }
                        });
                    });

                    $timeout(function () {
                        $scope.$parent.ngModel.$setPristine();
                        $scope.$parent.ngModel.$$parentForm.$setPristine();
                    });<commit_msg>Reset input and form state after select initialization<commit_after>angular.module("schemaForm").run(["$templateCache", function($templateCache) {$templateCache.put("directives/decorators/bootstrap/uiselect/multi.html","<div class=\"form-group\" ng-class=\"{\'has-error\': hasError(), \'has-success\': hasSuccess(), \'has-feedback\': form.feedback !== false}\" ng-init=\"form.select_models=(form.schema.items| whereMulti : \'value\' : ($$value$$||[]))\">\n  <label class=\"control-label\" ng-show=\"showTitle()\">{{form.title}}</label>\n  <div class=\"form-group\" ng-controller=\"UiSelectController\">\n    <ui-select multiple sortable-options=\"{{form.sortableOptions}}\" ng-if=\"!(form.options.tagging||false)\" ng-model=\"form.select_models\" theme=\"bootstrap\" on-select=\"$$value$$.push($item.value)\" on-remove=\"$$value$$.splice($$value$$.indexOf($item.value), 1)\" class=\"{{form.options.uiClass}}\">\n      <ui-select-match class=\"ui-select-match\" placeholder=\"{{form.placeholder || form.schema.placeholder || (\'placeholders.select\' | translate)}}\">{{$item.label}}</ui-select-match>\n      <ui-select-choices class=\"ui-select-choices\" refresh=\"fetchResult(form.schema, form.options, $select.search)\"\n         refresh-delay=\"form.options.refreshDelay\" group-by=\"form.options.groupBy\"  repeat=\"item in form.schema.items | propsFilter: {label: $select.search, description: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\') }\">\n        <div ng-bind-html=\"item.label | highlight: $select.search\"></div>\n        <div ng-if=\"item.description\">\n          <span ng-bind-html=\"\'<small>\' + (\'\'+item.description | highlight: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\'))+ \'</small>\'\"></span>\n        </div>\n    </ui-select-choices>\n    </ui-select>\n    <ui-select ng-controller=\"UiSelectController\" multiple ng-if=\"(form.options.tagging||false) && !(form.options.groupBy || false)\" tagging=\"form.options.tagging||false\" tagging-label=\"form.options.taggingLabel\" tagging-tokens=\"form.options.taggingTokens\" sortable-options=\"{{form.sortableOptions}}\" ng-model=\"form.select_models\" theme=\"bootstrap\" on-select=\"$$value$$.push($item.value)\" on-remove=\"$$value$$.splice($$value$$.indexOf($item.value), 1)\" class=\"{{form.options.uiClass}}\">\n      <ui-select-match class=\"ui-select-match\" placeholder=\"{{form.placeholder || form.schema.placeholder || (\'placeholders.select\' | translate)}}\">{{$item.label}}&nbsp;<small>{{($item.isTag===true ?  form.options.taggingLabel : \'\')}}</small></ui-select-match>\n      <ui-select-choices class=\"ui-select-choices\" refresh-delay=\"form.options.refreshDelay\" refresh=\"fetchResult(form.schema, form.options, $select.search)\"\n         refresh-delay=\"form.options.refreshDelay\" repeat=\"item in form.schema.items | propsFilter: {label: $select.search, description: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\') }\">\n          <div ng-if=\"item.isTag\" ng-bind-html=\"\'<div>\' + (item.label   | highlight: $select.search) + \' \' + form.options.taggingLabel + \'</div><div class=&quot;divider&quot;></div>\'\"></div>\n          <div ng-if=\"!item.isTag\" ng-bind-html=\"item.label + item.isTag | highlight: $select.search\"></div>\n      <div ng-if=\"item.description\"> \n        <span ng-bind-html=\"\'<small>\' + (\'\'+item.description | highlight: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\')) + \'</small>\'\"></span>\n      </div>\n    </ui-select-choices>\n      <!--repeat code because tagging does not display properly under group by but is still useful -->\n    </ui-select>\n\n    <ui-select ng-controller=\"UiSelectController\" multiple ng-if=\"(form.options.tagging||false) && (form.options.groupBy || false)\" tagging=\"form.options.tagging||false\" tagging-label=\"form.options.taggingLabel\" tagging-tokens=\"form.options.taggingTokens\" sortable-options=\"{{form.sortableOptions}}\" ng-model=\"form.select_models\" theme=\"bootstrap\" on-select=\"$$value$$.push($item.value)\" on-remove=\"$$value$$.splice($$value$$.indexOf($item.value), 1)\" class=\"{{form.options.uiClass}}\">\n      <ui-select-match class=\"ui-select-match\" placeholder=\"{{form.placeholder || form.schema.placeholder || (\'placeholders.select\' | translate)}}\">{{$item.label}}&nbsp;<small>{{($item.isTag===true ?  form.options.taggingLabel : \'\')}}</small></ui-select-match>\n      <ui-select-choices class=\"ui-select-choices\" group-by=\"form.options.groupBy\" refresh-delay=\"form.options.refreshDelay\" refresh=\"fetchResult(form.schema, form.options, $select.search)\"\n         refresh-delay=\"form.options.refreshDelay\" repeat=\"item in form.schema.items | propsFilter: {label: $select.search, description: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\') }\">\n          <div ng-if=\"item.isTag\" ng-bind-html=\"\'<div>\' + (item.label   | highlight: $select.search) + \' \' + form.options.taggingLabel + \'</div><div class=&quot;divider&quot;></div>\'\"></div>\n          <div ng-if=\"!item.isTag\" ng-bind-html=\"item.label + item.isTag | highlight: $select.search\"></div>\n      <div ng-if=\"item.description\"> \n        <span ng-bind-html=\"\'<small>\' + (\'\'+item.description | highlight: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\')) + \'</small>\'\"></span>\n      </div>\n    </ui-select-choices>\n\n    </ui-select>\n    <input name=\"{{form.key.slice(-1)[0]}}\" toggle-model type=\"hidden\" ng-model=\"insideModel\" sf-changed=\"form\" schema-validate=\"form\" />\n    <span ng-if=\"form.feedback !== false\"\n      class=\"form-control-feedback\"\n      ng-class=\"evalInScope(form.feedback) || {\'glyphicon\': true, \'glyphicon-ok\': hasSuccess(), \'glyphicon-remove\': hasError() }\"></span>\n    <div class=\"help-block\"\n      ng-show=\"(hasError() && errorMessage(schemaError())) || form.description\"\n      ng-bind-html=\"(hasError() && errorMessage(schemaError())) || form.description\"></div>\n  </div>\n</div>\n");
$templateCache.put("directives/decorators/bootstrap/uiselect/single.html","<div class=\"form-group\" ng-class=\"{\'has-error\': hasError(), \'has-success\': hasSuccess(), \'has-feedback\': form.feedback !== false}\" ng-init=\"select_models=(form.schema.items | where : {value: $$value$$})\">\n  <label class=\"control-label\" ng-show=\"showTitle()\">{{form.title}}</label>\n  <div class=\"form-group\" ng-init=\"select_model.selected=select_models[0]\">\n    <div class=\"input-group\">\n      <ui-select ng-model=\"select_model.selected\" ng-controller=\"UiSelectController\"  ng-if=\"!(form.options.tagging||false)\" theme=\"bootstrap\" ng-disabled=\"form.disabled\" on-select=\"$$value$$=$item.value\" class=\"{{form.options.uiClass}}\" append-to-body=\"true\">\n        <ui-select-match class=\"ui-select-match\" placeholder=\"{{form.placeholder || form.schema.placeholder || (\'placeholders.select\' | translate)}}\">{{select_model.selected.label}}</ui-select-match>\n        <ui-select-choices class=\"ui-select-choices\" refresh=\"fetchResult(form.schema, form.options, $select.search)\"\n               refresh-delay=\"form.options.refreshDelay\" group-by=\"form.options.groupBy\"  repeat=\"item in form.schema.items | propsFilter: {label: $select.search, description: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\') }\">\n                  <div ng-bind-html=\"item.label | highlight: $select.search\"></div>\n        <div ng-if=\"item.description\">\n          <span ng-bind-html=\"\'<small>\' + (\'\'+item.description | highlight: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\'))+ \'</small>\'\"></span></div>\n        </ui-select-choices>\n      </ui-select>\n      <ui-select ng-controller=\"UiSelectController\"  ng-model=\"select_model.selected\" ng-if=\"(form.options.tagging||false) && !(form.options.groupBy || false)\" tagging=\"form.options.tagging||false\" tagging-label=\"form.options.taggingLabel\" tagging-tokens=\"form.options.taggingTokens\"\n        theme=\"bootstrap\" ng-disabled=\"form.disabled\" on-select=\"$$value$$=$item.value\" class=\"{{form.options.uiClass}}\" append-to-body=\"true\">\n        <ui-select-match class=\"ui-select-match\" placeholder=\"{{form.placeholder || form.schema.placeholder || (\'placeholders.select\' | translate)}}\">{{select_model.selected.label}}&nbsp;<small>{{(select_model.selected.isTag===true ? form.options.taggingLabel : \'\')}}</small></ui-select-match>\n        <!--repeat code because tagging does not display properly under group by but is still useful -->\n        <ui-select-choices class=\"ui-select-choices\" refresh=\"form.options.refreshMethod(form.schema, $select.search)\"\n               refresh-delay=\"form.options.refreshDelay\" repeat=\"item in form.schema.items | propsFilter: {label: $select.search, description: (form.options.searchDescription===true ? $select.search : \'NOTSEARCHINGFORTHIS\') }\">\n          <div ng-if=\"item.isTag\" ng-bind-html=\"\'<div>\' + (item.label   | highlight: $select.search) + \' \' + form.options.taggingLabel + \'</div><div class=&quot;divider&quot;></div>\'\"></div><div ng-if=\"!item.isTag\" ng-bind-html=\"item.label + item.isTag| highlight: $select.search\"></div>\n        <div ng-if=\"item.description\">\n          <span  ng-bind-html=\"\'<small>\' + (\'\'+item.description | highlight: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\')) + \'</small>\'\"></span>\n        </div>\n      </ui-select-choices>\n      </ui-select>\n\n        <!--repeat code because tagging does not display properly under group by but is still useful -->\n\n      <ui-select ng-controller=\"UiSelectController\"  ng-model=\"select_model.selected\" ng-if=\"(form.options.tagging||false) && (form.options.groupBy || false)\"  tagging=\"form.options.tagging||false\" tagging-label=\"form.options.taggingLabel\" tagging-tokens=\"form.options.taggingTokens\"\n        theme=\"bootstrap\" ng-disabled=\"form.disabled\" on-select=\"$$value$$=$item.value\" class=\"{{form.options.uiClass}}\" append-to-body=\"true\">\n        <ui-select-match class=\"ui-select-match\" placeholder=\"{{form.placeholder || form.schema.placeholder || (\'placeholders.select\' | translate)}}\">{{select_model.selected.label}}&nbsp;<small>{{(select_model.selected.isTag===true ? form.options.taggingLabel : \'\')}}</small></ui-select-match>\n        <ui-select-choices class=\"ui-select-choices\" group-by=\"form.options.groupBy\" refresh=\"form.options.refreshMethod(form.schema, $select.search)\"\n               refresh-delay=\"form.options.refreshDelay\" repeat=\"item in form.schema.items | propsFilter: {label: $select.search, description: (form.options.searchDescription===true ? $select.search : \'NOTSEARCHINGFORTHIS\') }\">\n          <div ng-if=\"item.isTag\" ng-bind-html=\"\'<div>\' + (item.label   | highlight: $select.search) + \' \' + form.options.taggingLabel + \'</div><div class=&quot;divider&quot;></div>\'\"></div><div ng-if=\"!item.isTag\" ng-bind-html=\"item.label + item.isTag| highlight: $select.search\"></div>\n        <div ng-if=\"item.description\">\n          <span  ng-bind-html=\"\'<small>\' + (\'\'+item.description | highlight: (form.options.searchDescriptions===true ? $select.search : \'NOTSEARCHINGFORTHIS\')) + \'</small>\'\"></span>\n        </div>\n      </ui-select-choices>\n      </ui-select>\n      <span class=\"input-group-btn\">\n          <button ng-click=\"$$value$$ = undefined\" class=\"btn btn-default\" type=\"button\">\n              <span class=\"fa fa-trash\"></span>\n          </button>\n      </span>\n    </div>\n    <input name=\"{{form.key.slice(-1)[0]}}\" type=\"hidden\" toggle-single-model sf-changed=\"form\" ng-model=\"insideModel\" schema-validate=\"form\" />\n    <span ng-if=\"form.feedback !== false\"\n      class=\"form-control-feedback\"\n      ng-class=\"evalInScope(form.feedback) || {\'glyphicon\': true, \'glyphicon-ok\': hasSuccess(), \'glyphicon-remove\': hasError() }\"></span>\n    <div class=\"help-block\"\n      ng-show=\"(hasError() && errorMessage(schemaError())) || form.description\"\n      ng-bind-html=\"(hasError() && errorMessage(schemaError())) || form.description\"></div>\n  </div>\n</div>\n");}]);
angular.module('schemaForm').config(
    ['schemaFormProvider', 'schemaFormDecoratorsProvider', 'sfPathProvider',
        function (schemaFormProvider, schemaFormDecoratorsProvider, sfPathProvider) {

            var uiselect = function (name, schema, options) {
                if (schema.type === 'string' && schema.format == 'uiselect') {
                    var f = schemaFormProvider.stdFormObj(name, schema, options);
                    f.key = options.path;
                    f.type = 'uiselect';
                    options.lookup[sfPathProvider.stringify(options.path)] = f;
                    return f;
                }
            };

            schemaFormProvider.defaults.string.unshift(uiselect);

            var uiselect = function (name, schema, options) {
                if (schema.type === 'number' && schema.format == 'uiselect') {
                    var f = schemaFormProvider.stdFormObj(name, schema, options);
                    f.key = options.path;
                    f.type = 'uiselect';
                    options.lookup[sfPathProvider.stringify(options.path)] = f;
                    return f;
                }
            };

            schemaFormProvider.defaults.number.unshift(uiselect);

            var uimultiselect = function (name, schema, options) {
                if (schema.type === 'array' && schema.format == 'uiselect') {
                    var f = schemaFormProvider.stdFormObj(name, schema, options);
                    f.key = options.path;
                    f.type = 'uimultiselect';
                    options.lookup[sfPathProvider.stringify(options.path)] = f;
                    return f;
                }
            };
            schemaFormProvider.defaults.array.unshift(uimultiselect);


            //Add to the bootstrap directive
            schemaFormDecoratorsProvider.addMapping('bootstrapDecorator', 'uiselect',
                'directives/decorators/bootstrap/uiselect/single.html');
            schemaFormDecoratorsProvider.createDirective('uiselect',
                'directives/decorators/bootstrap/uiselect/single.html');
            schemaFormDecoratorsProvider.addMapping('bootstrapDecorator', 'uimultiselect',
                'directives/decorators/bootstrap/uiselect/multi.html');
            schemaFormDecoratorsProvider.createDirective('uimultiselect',
                'directives/decorators/bootstrap/uiselect/multi.html');
        }])
    .directive("toggleSingleModel", function ($timeout) {
        // some how we get this to work ...
        return {
            require: 'ngModel',
            restrict: "A",
            scope: {},
            replace: true,
            controller: ['$scope', function ($scope) {

                /**
                 * Selects active option when:
                 * a) model value is changed
                 * b) dropdown options are changed
                 *
                 * @param {string} val Selected value
                 * @param {bool} doResetIfNotFound Boolean - if true and value not found in options list dropdown value is reset
                 */
                var doSelect = function (val, doResetIfNotFound) {

                    if (!angular.isDefined(val)) {
                        // value not passed (or empty value passed) - reset dropdown value
                        $scope.$parent.select_model.selected = undefined;
                    } else {

                        // value passed, check if it is available in the options list, if so - select it
                        var exists = false;
                        angular.forEach($scope.$parent.form.schema.items, function ($item) {
                            if ($item.value == val) {
                                $scope.$parent.select_model.selected = $item;
                                exists = true;
                            }
                        });

                        // value is not found in options list and flag (that dropdown should be reset) is passed, reset value
                        if (!exists && doResetIfNotFound) {
                            $scope.$parent.select_model.selected = undefined;
                        }
                    }

                    $timeout(function () {
                        $scope.$parent.ngModel ? $scope.$parent.ngModel.$setPristine() : false;
                        $scope.$parent.ngModel && $scope.$parent.ngModel.$$parentForm ? $scope.$parent.ngModel.$$parentForm.$setPristine() : false;
                    });
                };

                var getModelKey = function () {

                    var key = $scope.$parent.form.key;

                    // Redact part of the key, used in arrays
                    // KISS keyRedaction is a number.
                    if ($scope.$parent.state && $scope.$parent.state.keyRedaction) {
                        key = key.slice($scope.$parent.state.keyRedaction);
                    } else if (Array.isArray(key)) {
                        key = key[0];
                    }

                    return key;
                };

                // model value changed in outside
                $scope.$parent.$watch('model.$$value$$'.replace('$$value$$', getModelKey()), function (val) {
                    doSelect(val, false);
                });

                // select items changed
                $scope.$parent.$watch('form.schema.items', function () {
                    if ($scope.$parent.model && $scope.$parent.model[getModelKey()]) {
                        doSelect($scope.$parent.model[getModelKey()], true);
                    }
                }, true);

                $scope.$parent.$watch('select_model.selected', function () {
                    $scope.$parent.insideModel = $scope.$parent.select_model.selected ? $scope.$parent.select_model.selected.value : undefined;
                    $scope.$parent.ngModel.$setViewValue($scope.$parent.select_model.selected ? $scope.$parent.select_model.selected.value : undefined);
                });
            }],
        };
    })
    .directive("toggleModel", function ($timeout) {
        // some how we get this to work ...
        return {
            require: 'ngModel',
            restrict: "A",
            scope: {},
            replace: true,
            controller: ['$scope', 'sfSelect', function ($scope, sfSelect) {
                var list = sfSelect($scope.$parent.form.key, $scope.$parent.model);
                //as per base array implemenation if the array is undefined it must be set as empty for data binding to work
                if (angular.isUndefined(list)) {
                    list = [];
                    sfSelect($scope.$parent.form.key, $scope.$parent.model, list);
                }

                var doSelect = function (selectedItems) {

                    // clean selected options
                    while ($scope.$parent.form.select_models.length) {
                        $scope.$parent.form.select_models.pop();
                    }

                    // reselect values
                    angular.forEach($scope.$parent.form.schema.items, function ($item) {
                        angular.forEach(selectedItems, function (selectedItem) {
                            if ($item.value == selectedItem) {
                                $scope.$parent.form.select_models.push($item);
                            }
                        });
                    });

                    $timeout(function () {
                        $scope.$parent.ngModel ? $scope.$parent.ngModel.$setPristine() : false;
                        $scope.$parent.ngModel && $scope.$parent.ngModel.$$parentForm ? $scope.$parent.ngModel.$$parentForm.$setPristine() : false;
                    });
{'fraction_non_alphanumeric': 0.19224929686138836, 'fraction_numerical': 0.00044801752246310077, 'mean_word_length': 2.5188299176738482, 'pattern_counts': {'":': 0, '<': 301, '<?xml version=': 0, '>': 301, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3672677', 'n_tokens_mistral': 11518, 'n_tokens_neox': 11091, 'n_words': 1833}