From 9055c7549eb5dc27c40b79c9976c856e66414df0 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sat, 25 Mar 2017 12:57:07 +0800 Subject: [PATCH] allow setting empty value in new task page and task detail page --- src/scripts/controllers/new.js | 4 +++- src/scripts/controllers/task-detail.js | 8 +++----- src/scripts/directives/setting.js | 8 ++++---- src/scripts/services/aria2SettingService.js | 12 ++++++++++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/scripts/controllers/new.js b/src/scripts/controllers/new.js index 66c0f39..7584dfb 100644 --- a/src/scripts/controllers/new.js +++ b/src/scripts/controllers/new.js @@ -10,7 +10,9 @@ availableOptions: (function () { var keys = aria2SettingService.getNewTaskOptionKeys(); - return aria2SettingService.getSpecifiedOptions(keys); + return aria2SettingService.getSpecifiedOptions(keys, { + disableRequired: true + }); })(), globalOptions: null, options: {}, diff --git a/src/scripts/controllers/task-detail.js b/src/scripts/controllers/task-detail.js index 41837be..6f1a0bf 100644 --- a/src/scripts/controllers/task-detail.js +++ b/src/scripts/controllers/task-detail.js @@ -9,11 +9,9 @@ var getAvailableOptions = function (status, isBittorrent) { var keys = aria2SettingService.getAvailableTaskOptionKeys(status, isBittorrent); - if (!keys) { - return; - } - - return aria2SettingService.getSpecifiedOptions(keys); + return aria2SettingService.getSpecifiedOptions(keys, { + disableRequired: true + }); }; var processTask = function (task) { diff --git a/src/scripts/directives/setting.js b/src/scripts/directives/setting.js index 5083379..fe6dd40 100644 --- a/src/scripts/directives/setting.js +++ b/src/scripts/directives/setting.js @@ -170,17 +170,17 @@ return; } - if (scope.option.type === 'integer' && !/^-?\d+$/.test(optionValue)) { + if (optionValue !== '' && scope.option.type === 'integer' && !/^-?\d+$/.test(optionValue)) { scope.optionStatus.setError('Input number is invalid!'); return; } - if (scope.option.type === 'float' && !/^-?(\d*\.)?\d+$/.test(optionValue)) { + if (optionValue !== '' && scope.option.type === 'float' && !/^-?(\d*\.)?\d+$/.test(optionValue)) { scope.optionStatus.setError('Input number is invalid!'); return; } - if ((scope.option.type === 'integer' || scope.option.type === 'float') && (angular.isDefined(scope.option.min) || angular.isDefined(scope.option.max))) { + if (optionValue !== '' && (scope.option.type === 'integer' || scope.option.type === 'float') && (angular.isDefined(scope.option.min) || angular.isDefined(scope.option.max))) { var number = optionValue; if (scope.option.type === 'integer') { @@ -200,7 +200,7 @@ } } - if (angular.isDefined(scope.option.pattern) && !(new RegExp(scope.option.pattern).test(optionValue))) { + if (optionValue !== '' && angular.isDefined(scope.option.pattern) && !(new RegExp(scope.option.pattern).test(optionValue))) { scope.optionStatus.setError('Input value is invalid!'); return; } diff --git a/src/scripts/services/aria2SettingService.js b/src/scripts/services/aria2SettingService.js index 4510456..be81d62 100644 --- a/src/scripts/services/aria2SettingService.js +++ b/src/scripts/services/aria2SettingService.js @@ -68,7 +68,7 @@ return availableOptions; }, - getNewTaskOptionKeys: function (isBittorrent) { + getNewTaskOptionKeys: function () { var allOptions = aria2TaskAvailableOptions.taskOptions; var availableOptions = []; @@ -92,9 +92,13 @@ return availableOptions; }, - getSpecifiedOptions: function (keys) { + getSpecifiedOptions: function (keys, extendSettings) { var options = []; + if (!keys) { + return options; + } + for (var i = 0; i < keys.length; i++) { var key = keys[i]; var readonly = false; @@ -132,6 +136,10 @@ option.readonly = true; } + if (extendSettings && extendSettings.disableRequired) { + option.required = false; + } + if (option.options) { var availableOptions = [];