2017-05-14 16:45:35 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('ariaNg').directive('ngSettingDialog', ['ariaNgCommonService', 'aria2SettingService', function (ariaNgCommonService, aria2SettingService) {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
templateUrl: 'views/setting-dialog.html',
|
|
|
|
replace: true,
|
|
|
|
scope: {
|
|
|
|
setting: '='
|
|
|
|
},
|
|
|
|
link: function (scope, element, attrs) {
|
|
|
|
scope.context = {
|
|
|
|
isLoading: false,
|
|
|
|
availableOptions: [],
|
|
|
|
globalOptions: []
|
|
|
|
};
|
|
|
|
|
|
|
|
scope.setGlobalOption = function (key, value, optionStatus) {
|
|
|
|
return aria2SettingService.setGlobalOption(key, value, function (response) {
|
|
|
|
if (response.success && response.data === 'OK') {
|
|
|
|
optionStatus.setSuccess();
|
|
|
|
} else {
|
|
|
|
optionStatus.setFailed(response.data.message);
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
};
|
|
|
|
|
|
|
|
var loadOptions = function (type) {
|
|
|
|
var keys = aria2SettingService.getaria2QuickSettingsAvailableOptions(type);
|
|
|
|
|
|
|
|
if (!keys) {
|
|
|
|
ariaNgCommonService.showError('Type is illegal!');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
scope.context.availableOptions = aria2SettingService.getSpecifiedOptions(keys);
|
|
|
|
};
|
|
|
|
|
|
|
|
var loadAria2OptionsValue = function () {
|
|
|
|
scope.context.isLoading = true;
|
|
|
|
|
|
|
|
return aria2SettingService.getGlobalOption(function (response) {
|
|
|
|
scope.context.isLoading = false;
|
|
|
|
|
|
|
|
if (response.success) {
|
|
|
|
scope.context.globalOptions = response.data;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-06-18 07:46:34 +02:00
|
|
|
angular.element('#quickSettingModal').on('hidden.bs.modal', function () {
|
2017-05-14 16:45:35 +02:00
|
|
|
scope.setting = null;
|
|
|
|
scope.context.availableOptions = [];
|
|
|
|
scope.context.globalOptions = [];
|
|
|
|
});
|
|
|
|
|
|
|
|
scope.$watch('setting', function (setting) {
|
|
|
|
if (setting) {
|
|
|
|
loadOptions(setting.type);
|
|
|
|
loadAria2OptionsValue();
|
|
|
|
|
2017-06-18 07:46:34 +02:00
|
|
|
angular.element('#quickSettingModal').modal('show');
|
2017-05-14 16:45:35 +02:00
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}]);
|
|
|
|
}());
|