settingDialog.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. (function () {
  2. 'use strict';
  3. angular.module('ariaNg').directive('ngSettingDialog', ['ariaNgCommonService', 'aria2SettingService', 'ariaNgNativeElectronService', function (ariaNgCommonService, aria2SettingService, ariaNgNativeElectronService) {
  4. return {
  5. restrict: 'E',
  6. templateUrl: 'views/setting-dialog.html',
  7. replace: true,
  8. scope: {
  9. setting: '='
  10. },
  11. link: function (scope, element, attrs) {
  12. scope.context = {
  13. isLoading: false,
  14. availableOptions: [],
  15. globalOptions: []
  16. };
  17. scope.setGlobalOption = function (key, value, optionStatus) {
  18. return aria2SettingService.setGlobalOption(key, value, function (response) {
  19. if (response.success && response.data === 'OK') {
  20. optionStatus.setSuccess();
  21. } else {
  22. optionStatus.setFailed(response.data.message);
  23. }
  24. }, true);
  25. };
  26. var loadOptions = function (type) {
  27. var keys = aria2SettingService.getAria2QuickSettingsAvailableOptions(type);
  28. if (!keys) {
  29. ariaNgCommonService.showError('Type is illegal!');
  30. return;
  31. }
  32. scope.context.availableOptions = aria2SettingService.getSpecifiedOptions(keys);
  33. };
  34. var loadAria2OptionsValue = function () {
  35. scope.context.isLoading = true;
  36. return aria2SettingService.getGlobalOption(function (response) {
  37. scope.context.isLoading = false;
  38. if (response.success) {
  39. scope.context.globalOptions = response.data;
  40. }
  41. });
  42. };
  43. angular.element(element).on('show.bs.modal', function () {
  44. ariaNgNativeElectronService.updateTitleBarBackgroundColorWithModalOverlay();
  45. });
  46. angular.element(element).on('hide.bs.modal', function () {
  47. ariaNgNativeElectronService.updateTitleBarBackgroundColor();
  48. });
  49. angular.element(element).on('hidden.bs.modal', function () {
  50. scope.$apply(function () {
  51. scope.setting = null;
  52. scope.context.availableOptions = [];
  53. scope.context.globalOptions = [];
  54. });
  55. });
  56. scope.$watch('setting', function (setting) {
  57. if (setting) {
  58. loadOptions(setting.type);
  59. loadAria2OptionsValue();
  60. angular.element(element).modal('show');
  61. }
  62. }, true);
  63. }
  64. };
  65. }]);
  66. }());