2016-06-18 18:11:19 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
2016-06-23 18:39:18 +02:00
|
|
|
angular.module('ariaNg').controller('NewTaskController', ['$rootScope', '$scope', '$location', '$timeout', 'aria2SettingService', 'aria2TaskService', 'ariaNgFileService', function ($rootScope, $scope, $location, $timeout, aria2SettingService, aria2TaskService, ariaNgFileService) {
|
2016-06-22 17:12:53 +02:00
|
|
|
var tabOrders = ['links', 'options'];
|
2016-06-18 18:11:19 +02:00
|
|
|
|
2016-06-19 17:10:26 +02:00
|
|
|
$scope.context = {
|
2016-06-22 17:12:53 +02:00
|
|
|
currentTab: 'links',
|
2016-06-19 17:10:26 +02:00
|
|
|
urls: '',
|
2016-06-20 18:20:30 +02:00
|
|
|
availableOptions: (function () {
|
|
|
|
var keys = aria2SettingService.getNewTaskOptionKeys();
|
|
|
|
|
2017-03-25 05:57:07 +01:00
|
|
|
return aria2SettingService.getSpecifiedOptions(keys, {
|
|
|
|
disableRequired: true
|
|
|
|
});
|
2016-06-20 18:20:30 +02:00
|
|
|
})(),
|
2016-06-19 17:10:26 +02:00
|
|
|
globalOptions: null,
|
2016-12-24 18:07:16 +01:00
|
|
|
options: {},
|
|
|
|
optionFilter: {
|
|
|
|
global: true,
|
2017-03-19 08:48:38 +01:00
|
|
|
http: false,
|
|
|
|
bittorrent: false
|
2016-12-24 18:07:16 +01:00
|
|
|
}
|
2016-06-19 17:10:26 +02:00
|
|
|
};
|
|
|
|
|
2016-06-20 17:45:33 +02:00
|
|
|
$scope.changeTab = function (tabName) {
|
2016-08-01 16:49:16 +02:00
|
|
|
if (tabName === 'options') {
|
2016-06-20 17:45:33 +02:00
|
|
|
$scope.loadDefaultOption();
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.context.currentTab = tabName;
|
|
|
|
};
|
|
|
|
|
2016-06-19 17:10:26 +02:00
|
|
|
$rootScope.swipeActions.extentLeftSwipe = function () {
|
|
|
|
var tabIndex = tabOrders.indexOf($scope.context.currentTab);
|
|
|
|
|
|
|
|
if (tabIndex < tabOrders.length - 1) {
|
2016-06-20 17:45:33 +02:00
|
|
|
$scope.changeTab(tabOrders[tabIndex + 1]);
|
2016-06-19 17:10:26 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$rootScope.swipeActions.extentRightSwipe = function () {
|
|
|
|
var tabIndex = tabOrders.indexOf($scope.context.currentTab);
|
|
|
|
|
|
|
|
if (tabIndex > 0) {
|
2016-06-20 17:45:33 +02:00
|
|
|
$scope.changeTab(tabOrders[tabIndex - 1]);
|
2016-06-19 17:10:26 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.loadDefaultOption = function () {
|
|
|
|
if ($scope.context.globalOptions) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$rootScope.loadPromise = aria2SettingService.getGlobalOption(function (response) {
|
|
|
|
if (response.success) {
|
|
|
|
$scope.context.globalOptions = response.data;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-06-23 18:39:18 +02:00
|
|
|
$scope.openTorrent = function () {
|
|
|
|
ariaNgFileService.openFileContent('.torrent', function (result) {
|
|
|
|
var task = {
|
|
|
|
content: result.base64Content,
|
|
|
|
options: angular.copy($scope.context.options)
|
|
|
|
};
|
|
|
|
|
|
|
|
$rootScope.loadPromise = aria2TaskService.newTorrentTask(task, true, function (response) {
|
|
|
|
if (!response.success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$location.path('/task/detail/' + response.data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.openMetalink = function () {
|
|
|
|
ariaNgFileService.openFileContent('.meta4,.metalink', function (result) {
|
|
|
|
var task = {
|
|
|
|
content: result.base64Content,
|
|
|
|
options: angular.copy($scope.context.options)
|
|
|
|
};
|
|
|
|
|
|
|
|
$rootScope.loadPromise = aria2TaskService.newMetalinkTask(task, true, function (response) {
|
|
|
|
if (!response.success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$location.path('/task/detail/' + response.data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-06-19 17:10:26 +02:00
|
|
|
$scope.startDownload = function (pauseOnAdded) {
|
|
|
|
var urls = $scope.context.urls.split('\n');
|
|
|
|
var options = angular.copy($scope.context.options);
|
2016-06-18 18:11:19 +02:00
|
|
|
var tasks = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < urls.length; i++) {
|
2016-08-01 16:49:16 +02:00
|
|
|
if (urls[i] === '' || urls[i].trim() === '') {
|
2016-06-23 16:40:53 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-06-18 18:11:19 +02:00
|
|
|
tasks.push({
|
|
|
|
urls: [urls[i].trim()],
|
2016-06-19 17:10:26 +02:00
|
|
|
options: options
|
2016-06-18 18:11:19 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-20 17:37:25 +02:00
|
|
|
$rootScope.loadPromise = aria2TaskService.newUriTasks(tasks, pauseOnAdded, function (response) {
|
2016-06-18 18:11:19 +02:00
|
|
|
if (!response.hasSuccess) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-19 17:10:26 +02:00
|
|
|
if (pauseOnAdded) {
|
|
|
|
$location.path('/waiting');
|
|
|
|
} else {
|
|
|
|
$location.path('/downloading');
|
|
|
|
}
|
2016-06-18 18:11:19 +02:00
|
|
|
});
|
|
|
|
};
|
2016-06-19 17:10:26 +02:00
|
|
|
|
|
|
|
$scope.setOption = function (key, value, optionStatus) {
|
2016-08-01 16:49:16 +02:00
|
|
|
if (value !== '') {
|
2016-06-19 17:10:26 +02:00
|
|
|
$scope.context.options[key] = value;
|
|
|
|
} else {
|
|
|
|
delete $scope.context.options[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
optionStatus.setReady();
|
|
|
|
};
|
2016-06-23 16:40:53 +02:00
|
|
|
|
2016-07-31 16:33:37 +02:00
|
|
|
$scope.urlTextboxKeyDown = function (event) {
|
2016-08-01 16:49:16 +02:00
|
|
|
if (event.keyCode === 13 && event.ctrlKey && $scope.newTaskForm.$valid) {
|
2016-07-31 16:33:37 +02:00
|
|
|
$scope.startDownload();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-01 16:49:16 +02:00
|
|
|
$rootScope.loadPromise = $timeout(function () {}, 100);
|
2016-06-18 18:11:19 +02:00
|
|
|
}]);
|
2016-08-01 16:49:16 +02:00
|
|
|
}());
|