2008-07-03 14:59:31 +00:00
|
|
|
/*
|
|
|
|
* MIT License
|
|
|
|
* Copyright (c) 2008 Ishan Arora <ishan@qbittorrent.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2014-11-30 14:14:09 +01:00
|
|
|
*
|
2008-07-03 14:59:31 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2014-11-30 14:14:09 +01:00
|
|
|
*
|
2008-07-03 14:59:31 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
2008-07-04 07:48:15 +00:00
|
|
|
*/
|
2015-10-22 00:06:36 -04:30
|
|
|
|
2018-11-30 18:30:26 +08:00
|
|
|
'use strict';
|
|
|
|
|
2018-10-19 01:56:47 -04:00
|
|
|
var categories = {};
|
|
|
|
var defaultSavePath = "";
|
|
|
|
|
|
|
|
getCategories = function() {
|
|
|
|
new Request.JSON({
|
|
|
|
url: 'api/v2/torrents/categories',
|
|
|
|
noCache: true,
|
|
|
|
method: 'get',
|
|
|
|
onSuccess: function(data) {
|
|
|
|
if (data) {
|
|
|
|
categories = data;
|
|
|
|
for (var i in data) {
|
|
|
|
var category = data[i];
|
|
|
|
var option = new Element("option");
|
|
|
|
option.set('value', category.name);
|
|
|
|
option.set('html', category.name);
|
|
|
|
$('categorySelect').appendChild(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
};
|
2018-10-24 22:15:40 -04:00
|
|
|
|
|
|
|
getPreferences = function() {
|
|
|
|
new Request.JSON({
|
|
|
|
url: 'api/v2/app/preferences',
|
2017-07-01 00:42:20 -04:00
|
|
|
method: 'get',
|
|
|
|
noCache: true,
|
|
|
|
onFailure: function() {
|
|
|
|
alert("Could not contact qBittorrent");
|
|
|
|
},
|
2018-10-24 22:15:40 -04:00
|
|
|
onSuccess: function(pref) {
|
|
|
|
if (pref) {
|
2018-10-19 01:56:47 -04:00
|
|
|
defaultSavePath = pref.save_path;
|
|
|
|
$('savepath').setProperty('value', defaultSavePath);
|
2018-10-19 02:11:10 -04:00
|
|
|
$('root_folder').checked = pref.create_subfolder_enabled;
|
|
|
|
$('start_torrent').checked = !pref.start_paused_enabled;
|
|
|
|
|
2018-10-24 22:15:40 -04:00
|
|
|
if (pref.auto_tmm_enabled == 1) {
|
|
|
|
$('autoTMM').selectedIndex = 1;
|
|
|
|
$('savepath').disabled = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('autoTMM').selectedIndex = 0;
|
|
|
|
}
|
2017-07-01 00:42:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
};
|
2015-10-22 00:06:36 -04:30
|
|
|
|
2018-10-19 01:56:47 -04:00
|
|
|
changeCategorySelect = function(item) {
|
|
|
|
if (item.value == "\\other") {
|
|
|
|
item.nextElementSibling.hidden = false;
|
|
|
|
item.nextElementSibling.value = "";
|
|
|
|
item.nextElementSibling.select();
|
|
|
|
|
|
|
|
if ($('autotmm').selectedIndex == 1)
|
|
|
|
$('savepath').value = defaultSavePath;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item.nextElementSibling.hidden = true;
|
|
|
|
var text = item.options[item.selectedIndex].innerHTML;
|
|
|
|
item.nextElementSibling.value = text;
|
|
|
|
|
|
|
|
if ($('autotmm').selectedIndex == 1) {
|
|
|
|
var categoryName = item.value;
|
|
|
|
var category = categories[categoryName];
|
|
|
|
var savePath = defaultSavePath;
|
|
|
|
if (category !== undefined)
|
|
|
|
savePath = (category['savePath'] !== "") ? category['savePath'] : (defaultSavePath + categoryName);
|
|
|
|
$('savepath').value = savePath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-24 22:15:40 -04:00
|
|
|
changeTMM = function(item) {
|
|
|
|
if (item.selectedIndex == 1) {
|
|
|
|
$('savepath').disabled = true;
|
2018-10-19 01:56:47 -04:00
|
|
|
|
|
|
|
var categorySelect = $('categorySelect');
|
|
|
|
var categoryName = categorySelect.options[categorySelect.selectedIndex].value;
|
|
|
|
var category = categories[categoryName];
|
|
|
|
$('savepath').value = (category === undefined) ? "" : category['savePath'];
|
2018-10-24 22:15:40 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('savepath').disabled = false;
|
2018-10-19 01:56:47 -04:00
|
|
|
$('savepath').value = defaultSavePath;
|
2018-10-24 22:15:40 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-22 00:06:36 -04:30
|
|
|
$(window).addEventListener("load", function() {
|
2018-10-24 22:15:40 -04:00
|
|
|
getPreferences();
|
2018-10-19 01:56:47 -04:00
|
|
|
getCategories();
|
2015-10-22 00:06:36 -04:30
|
|
|
});
|