'use strict'; var uiDirectives = angular.module('uiDirectives', []); uiDirectives.directive('ngSelect2', ['$timeout', function ($timeout) { return { scope: { 'model': '=ngModel', 'disabled': '=ngDisabed', formatResult: '&select2FormatResult', }, link: function (scope, elem, attrs) { $timeout(function () { var $select = $(elem); var opts = { value: scope.model, allowClear: attrs.allowclear, dropdownAutoWidth: attrs.dropdownautowidth, placeholder: attrs.placeholder, dropdownCss: attrs.dropdowncss, minimumResultsForSearch: +attrs.minimumresultsforsearch, formatResult: scope.formatResult(), width: attrs.width }; $select.select2(opts).on('change', function (e) { var newVal = e.val; scope.$apply(function () { scope.model = newVal; //console.log('select2.onChange name=' + $select.attr('name') + '; newVal=' + newVal + ';children=' + $select.children().length); }); }); //if (opts.width) // $select.parent().css("width", opts.width); scope.$watch('model', function (newVal, oldVal) { $timeout(function () { //console.log('select2 name=' + $select.attr('name') + '; newVal=' + newVal + '; oldVal=' + oldVal + ';children=' + $select.children().length); $select.select2('val', newVal); }, 0, false); }); scope.$watch('disabled', function (newVal, oldVal) { $timeout(function () { $select.select2('enable', !newVal); }, 0, false); }); $select.on('$destroy', function () { $select.select2('destroy'); }); }, 0, false); } } }]); uiDirectives.directive('ngSwitcher', ['$timeout', function ($timeout) { return { scope: { 'ngDisabled': '=?ngDisabled', formatResult: '&select2FormatResult' }, require: ['?ngModel'], link: function (scope, elem, attrs, ctrls) { var $elem = $(elem); var opts = { on_state_content: attrs.ngSwOnStateContent, off_state_content: attrs.ngSwOffStateContent, width: attrs.ngSwWidth }; if (scope.ngDisabled) $elem.prop('disabled', true); $elem.switcher(opts); if (opts.width) $elem.parent().css("width", opts.width); if (ctrls[0]) { var ngModelCtrl = ctrls[0]; var listener = function (ev) { ngModelCtrl.$setViewValue(elem[0].checked, ev && ev.type); }; elem.on('click', listener); ngModelCtrl.$render = function () { $timeout(function () { elem[0].checked = ngModelCtrl.$viewValue; $(elem[0]).switcher('refreshView'); }, 0, false); }; // Override the standard `$isEmpty` because the $viewValue of an empty checkbox is always set to `false` // This is because of the parser below, which compares the `$modelValue` with `trueValue` to convert // it to a boolean. ngModelCtrl.$isEmpty = function (value) { return (value === false); }; ngModelCtrl.$formatters.push(function (value) { return (value === true); }); ngModelCtrl.$parsers.push(function (value) { return value; }); } scope.$watch('ngDisabled', function (newVal, oldVal) { $timeout(function () { if (isNaN(newVal)) return; if (newVal && !oldVal) $elem.switcher('disable'); else if (!newVal && oldVal) $elem.switcher('enable'); }, 0, false); }); $elem.on('$destroy', function () { $elem.switcher('destroy'); }); } } }]); uiDirectives.directive('ngInitWidget', function () { return { restrict: 'A', priority: 1200, // we need to init widget before ng-repeat added data to the table and change it's size controller: ['$scope', '$element', function ($scope, $element) { $($element).activityCalendarGrid('init'); }], }; }); uiDirectives.directive('optionClassExpr', ['$compile', function ($compile) { var NG_OPTIONS_REGEXP = /^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/; return { restrict: 'A', link: function optionClassExprPostLink(scope, elem, attrs) { var optionsExp = attrs.ngOptions; if (!optionsExp) return; var match = optionsExp.match(NG_OPTIONS_REGEXP); if (!match) return; var values = match[7]; scope.$watchCollection(function () { return elem.children(); }, function (newValue) { angular.forEach(newValue, function (child, index) { var child = angular.element(child); var val = child.val(); if (val) { child.attr('ng-class', values + '[' + (index - 1) + '].' + attrs.optionClassExpr); $compile(child)(scope); } }); }); } }; }]); // This is a directive used to move page preference
  • items from current