2016-06-01 17:31:48 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module("ariaNg").directive('ngSetting', ['$timeout', 'ariaNgConstants', function ($timeout, ariaNgConstants) {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
templateUrl: "views/setting.html",
|
|
|
|
require: '?ngModel',
|
|
|
|
replace: true,
|
|
|
|
scope: {
|
|
|
|
option: '=',
|
|
|
|
ngModel: '=',
|
|
|
|
status: '=',
|
2016-06-01 18:02:10 +02:00
|
|
|
onPendingChangeValue: '&',
|
2016-06-01 17:31:48 +02:00
|
|
|
onChangeValue: '&'
|
|
|
|
},
|
|
|
|
link: function (scope, element, attrs, ngModel) {
|
|
|
|
var pendingSaveRequest = null;
|
|
|
|
var options = {
|
|
|
|
lazySaveTimeout: ariaNgConstants.lazySaveTimeout
|
|
|
|
};
|
|
|
|
|
|
|
|
angular.extend(options, attrs);
|
|
|
|
|
|
|
|
scope.getTotalCount = function () {
|
|
|
|
if (!scope.optionValue && !angular.isString(scope.optionValue)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return scope.optionValue.split(scope.option.split).length;
|
|
|
|
};
|
|
|
|
|
|
|
|
scope.changeValue = function (optionValue, lazySave) {
|
|
|
|
scope.optionValue = optionValue;
|
|
|
|
|
|
|
|
if (!scope.option || !scope.option.key || scope.option.readonly) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
key: scope.option.key,
|
|
|
|
value: optionValue
|
|
|
|
};
|
|
|
|
|
2016-06-01 18:02:10 +02:00
|
|
|
if (scope.onPendingChangeValue) {
|
|
|
|
scope.onPendingChangeValue(data);
|
2016-06-01 17:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pendingSaveRequest) {
|
|
|
|
$timeout.cancel(pendingSaveRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scope.onChangeValue) {
|
|
|
|
if (lazySave) {
|
|
|
|
pendingSaveRequest = $timeout(function () {
|
|
|
|
scope.onChangeValue(data);
|
|
|
|
}, options.lazySaveTimeout);
|
|
|
|
} else {
|
|
|
|
scope.onChangeValue(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
scope.$watch(function () {
|
|
|
|
return ngModel.$viewValue;
|
|
|
|
}, function (value) {
|
|
|
|
scope.optionValue = value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}]);
|
|
|
|
})();
|