diff --git a/app/scripts/controllers/settings-aria2.js b/app/scripts/controllers/settings-aria2.js index c7ebbe3..70400f7 100644 --- a/app/scripts/controllers/settings-aria2.js +++ b/app/scripts/controllers/settings-aria2.js @@ -15,18 +15,15 @@ return aria2SettingService.getSpecifiedOptions(keys); }; - $scope.optionStatus = {}; $scope.availableOptions = getAvailableOptions(location); - $scope.pendingGlobalOption = function (key, value) { - $scope.optionStatus[key] = 'pending'; - }; - - $scope.setGlobalOption = function (key, value) { - $scope.optionStatus[key] = 'saving'; - + $scope.setGlobalOption = function (key, value, optionStatus) { return aria2SettingService.setGlobalOption(key, value, function (result) { - $scope.optionStatus[key] = 'saved'; + if (result == 'OK') { + optionStatus.setSuccess(); + } else { + optionStatus.setFailed(); + } }); }; diff --git a/app/scripts/controllers/task-detail.js b/app/scripts/controllers/task-detail.js index 1c5736b..63e588a 100644 --- a/app/scripts/controllers/task-detail.js +++ b/app/scripts/controllers/task-detail.js @@ -53,7 +53,6 @@ }; $scope.healthPercent = 0; - $scope.optionStatus = {}; $scope.availableOptions = []; $rootScope.swipeActions.extentLeftSwipe = function () { @@ -106,15 +105,13 @@ }); }; - $scope.pendingOption = function (key, value) { - $scope.optionStatus[key] = 'pending'; - }; - - $scope.setOption = function (key, value) { - $scope.optionStatus[key] = 'saving'; - + $scope.setOption = function (key, value, optionStatus) { return aria2TaskService.setTaskOption($scope.task.gid, key, value, function (result) { - $scope.optionStatus[key] = 'saved'; + if (result == 'OK') { + optionStatus.setSuccess(); + } else { + optionStatus.setFailed(); + } }); }; diff --git a/app/scripts/directives/setting.js b/app/scripts/directives/setting.js index fd7d9f2..fd4e43b 100644 --- a/app/scripts/directives/setting.js +++ b/app/scripts/directives/setting.js @@ -10,8 +10,6 @@ scope: { option: '=', ngModel: '=', - status: '=', - onPendingChangeValue: '&', onChangeValue: '&' }, link: function (scope, element, attrs, ngModel) { @@ -22,6 +20,63 @@ angular.extend(options, attrs); + scope.optionStatus = (function () { + var value = 'ready'; + + return { + getValue: function () { + return value; + }, + setReady: function () { + value = 'ready'; + }, + setPending: function () { + value = 'pending'; + }, + setSaving: function () { + value = 'pending'; + }, + setSuccess: function () { + value = 'success'; + }, + setFailed: function () { + value = 'failed'; + }, + setError: function () { + value = 'error'; + }, + getStatusFeedbackStyle: function () { + if (value == 'success') { + return 'has-success'; + } else if (value == 'failed') { + return 'has-warning'; + } else if (value == 'error') { + return 'has-error'; + } else { + return ''; + } + }, + getStatusIcon: function () { + if (value == 'pending') { + return 'fa-hourglass-start'; + } else if (value == 'saving') { + return 'fa-spin fa-pulse fa-spinner'; + } else if (value == 'success') { + return 'fa-check'; + } else if (value == 'failed') { + return 'fa-exclamation'; + } else if (value == 'error') { + return 'fa-times'; + } else { + return ''; + } + }, + isShowStatusIcon: function () { + return this.getStatusIcon() != ''; + } + }; + })(); + scope.getTotalCount = function () { if (!scope.optionValue && !angular.isString(scope.optionValue)) { return 0; @@ -32,6 +87,7 @@ scope.changeValue = function (optionValue, lazySave) { scope.optionValue = optionValue; + scope.optionStatus.setReady(); if (!scope.option || !scope.option.key || scope.option.readonly) { return; @@ -39,24 +95,28 @@ var data = { key: scope.option.key, - value: optionValue + value: optionValue, + optionStatus: scope.optionStatus }; - if (scope.onPendingChangeValue) { - scope.onPendingChangeValue(data); - } - if (pendingSaveRequest) { $timeout.cancel(pendingSaveRequest); } + var invokeChange = function () { + scope.optionStatus.setSaving(); + scope.onChangeValue(data); + }; + if (scope.onChangeValue) { if (lazySave) { + scope.optionStatus.setPending(); + pendingSaveRequest = $timeout(function () { - scope.onChangeValue(data); + invokeChange(); }, options.lazySaveTimeout); } else { - scope.onChangeValue(data); + invokeChange(); } } }; diff --git a/app/scripts/services/aria2HttpRpcService.js b/app/scripts/services/aria2HttpRpcService.js index 930664e..139991d 100644 --- a/app/scripts/services/aria2HttpRpcService.js +++ b/app/scripts/services/aria2HttpRpcService.js @@ -25,7 +25,13 @@ context.callback(data.result); } }).error(function (data, header, config, status) { - //Do Nothing + if (!data) { + return; + } + + if (context.callback) { + context.callback(data.result); + } }); } }; diff --git a/app/views/setting.html b/app/views/setting.html index 226a836..de590b8 100644 --- a/app/views/setting.html +++ b/app/views/setting.html @@ -9,42 +9,41 @@
-
+
-
- +
+
-
+
-
- +
+
-
+
-
- +
+
-
+
-
- +
+
diff --git a/app/views/settings-aria2.html b/app/views/settings-aria2.html index fbc726e..112d98b 100644 --- a/app/views/settings-aria2.html +++ b/app/views/settings-aria2.html @@ -1,6 +1,6 @@
- +
diff --git a/app/views/task-detail.html b/app/views/task-detail.html index 21e5b13..0a2ff25 100644 --- a/app/views/task-detail.html +++ b/app/views/task-detail.html @@ -209,9 +209,7 @@
+ ng-model="options[option.key]" on-change-value="setOption(key, value, optionStatus)">