2016-05-17 17:13:47 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
2016-05-31 16:51:12 +02:00
|
|
|
angular.module('ariaNg').controller('Aria2SettingsController', ['$rootScope', '$scope', '$location', '$timeout', 'ariaNgConstants', 'ariaNgCommonService', 'aria2SettingService', function ($rootScope, $scope, $location, $timeout, ariaNgConstants, ariaNgCommonService, aria2SettingService) {
|
2016-05-22 19:17:13 +02:00
|
|
|
var location = $location.path().substring($location.path().lastIndexOf('/') + 1);
|
2016-05-31 16:51:12 +02:00
|
|
|
var pendingSaveRequests = {};
|
2016-05-22 19:17:13 +02:00
|
|
|
|
2016-05-31 16:51:12 +02:00
|
|
|
var getAvailableOptions = function (type) {
|
|
|
|
var keys = aria2SettingService.getAvailableOptionsKeys(type);
|
2016-05-29 11:37:14 +02:00
|
|
|
|
|
|
|
if (!keys) {
|
2016-05-31 16:51:12 +02:00
|
|
|
ariaNgCommonService.alert('Type is illegal!');
|
2016-05-29 11:37:14 +02:00
|
|
|
return;
|
2016-05-22 19:17:13 +02:00
|
|
|
}
|
2016-05-29 11:37:14 +02:00
|
|
|
|
2016-05-31 16:51:12 +02:00
|
|
|
return aria2SettingService.getSpecifiedOptions(keys);
|
2016-05-22 19:17:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.optionStatus = {};
|
|
|
|
$scope.availableOptions = getAvailableOptions(location);
|
2016-05-31 16:51:12 +02:00
|
|
|
|
2016-05-22 19:17:13 +02:00
|
|
|
$scope.setGlobalOption = function (option, value, lazySave) {
|
|
|
|
if (!option || !option.key || option.readonly) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var key = option.key;
|
|
|
|
var invoke = function () {
|
|
|
|
$scope.optionStatus[key] = 'saving';
|
|
|
|
|
2016-05-31 16:51:12 +02:00
|
|
|
return aria2SettingService.setGlobalOption(key, value, function (result) {
|
|
|
|
$scope.optionStatus[key] = 'saved';
|
2016-05-22 19:17:13 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
delete $scope.optionStatus[key];
|
|
|
|
|
|
|
|
if (lazySave) {
|
2016-05-31 16:51:12 +02:00
|
|
|
if (pendingSaveRequests[key]) {
|
|
|
|
$timeout.cancel(pendingSaveRequests[key]);
|
2016-05-22 19:17:13 +02:00
|
|
|
}
|
|
|
|
|
2016-05-31 16:51:12 +02:00
|
|
|
pendingSaveRequests[key] = $timeout(function () {
|
2016-05-22 19:17:13 +02:00
|
|
|
invoke();
|
|
|
|
}, ariaNgConstants.lazySaveTimeout);
|
|
|
|
} else {
|
|
|
|
invoke();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-30 19:26:41 +02:00
|
|
|
$rootScope.loadPromise = (function () {
|
2016-05-31 16:51:12 +02:00
|
|
|
return aria2SettingService.getGlobalOption(function (result) {
|
|
|
|
$scope.globalOptions = result;
|
2016-05-29 07:25:12 +02:00
|
|
|
});
|
2016-05-22 19:17:13 +02:00
|
|
|
})();
|
2016-05-17 17:13:47 +02:00
|
|
|
}]);
|
|
|
|
})();
|