2022-10-18 22:39:32 -04:00
<!DOCTYPE html>
< html lang = "${LANG}" >
< head >
< meta charset = "UTF-8" / >
2022-11-30 13:49:48 -05:00
< title > Torrent Upload/Download Ratio Limiting< / title >
2022-10-18 22:39:32 -04:00
< link rel = "stylesheet" href = "css/style.css?v=${CACHEID}" type = "text/css" / >
2023-03-13 21:31:54 -04:00
< link rel = "stylesheet" type = "text/css" href = "css/Core.css?v=${CACHEID}" / >
2022-10-18 22:39:32 -04:00
< script src = "scripts/lib/MooTools-Core-1.6.0-compat-compressed.js" > < / script >
< script src = "scripts/lib/MooTools-More-1.6.0-compat-compressed.js" > < / script >
< script src = "scripts/misc.js?locale=${LANG}&v=${CACHEID}" > < / script >
< script >
'use strict';
const UseGlobalLimit = -2;
const NoLimit = -1;
new Keyboard({
defaultEventType: 'keydown',
events: {
'Enter': function(event) {
$('save').click();
event.preventDefault();
},
'Escape': function(event) {
window.parent.closeWindows();
event.preventDefault();
},
'Esc': function(event) {
window.parent.closeWindows();
event.preventDefault();
}
}
}).activate();
window.addEvent('domready', function() {
const hashesList = new URI().getData('hashes').split('|');
const origValues = new URI().getData('orig').split('|');
const values = {
ratioLimit: window.qBittorrent.Misc.friendlyFloat(origValues[0], 2),
seedingTimeLimit: parseInt(origValues[1]),
2024-01-07 17:04:03 -05:00
inactiveSeedingTimeLimit: parseInt(origValues[2]),
maxRatio: window.qBittorrent.Misc.friendlyFloat(origValues[3], 2),
maxSeedingTime: parseInt(origValues[4]),
maxInactiveSeedingTime: parseInt(origValues[5])
2022-10-18 22:39:32 -04:00
};
// select default when orig values not passed. using double equals to compare string and int
2024-01-07 17:04:03 -05:00
if ((origValues[0] === "") || ((values.ratioLimit == UseGlobalLimit) & & (values.seedingTimeLimit == UseGlobalLimit))
& & (values.inactiveSeedingTimeLimit == UseGlobalLimit)) {
2022-10-18 22:39:32 -04:00
// use default option
setSelectedRadioValue('shareLimit', 'default');
}
2024-01-07 17:04:03 -05:00
else if ((values.maxRatio == NoLimit) & & (values.maxSeedingTime == NoLimit) & & (values.maxInactiveSeedingTime == NoLimit)) {
2022-10-18 22:39:32 -04:00
setSelectedRadioValue('shareLimit', 'none');
// TODO set input boxes to *global* max ratio and seeding time
}
else {
setSelectedRadioValue('shareLimit', 'custom');
if (values.ratioLimit >= 0) {
$('setRatio').set('checked', true);
$('ratio').set('value', values.ratioLimit);
}
if (values.seedingTimeLimit >= 0) {
2024-01-07 17:04:03 -05:00
$('setTotalMinutes').set('checked', true);
$('totalMinutes').set('value', values.seedingTimeLimit);
}
if (values.inactiveSeedingTimeLimit >= 0) {
$('setInactiveMinutes').set('checked', true);
$('inactiveMinutes').set('value', values.inactiveSeedingTimeLimit);
2022-10-18 22:39:32 -04:00
}
}
shareLimitChanged();
$('default').focus();
$('save').addEvent('click', function(e) {
new Event(e).stop();
if (!isFormValid()) {
return false;
}
const shareLimit = getSelectedRadioValue('shareLimit');
let ratioLimitValue = 0.00;
let seedingTimeLimitValue = 0;
2024-01-07 17:04:03 -05:00
let inactiveSeedingTimeLimitValue = 0;
2022-10-18 22:39:32 -04:00
if (shareLimit === 'default') {
2024-01-07 17:04:03 -05:00
ratioLimitValue = seedingTimeLimitValue = inactiveSeedingTimeLimitValue = UseGlobalLimit;
2022-10-18 22:39:32 -04:00
}
else if (shareLimit === 'none') {
2024-01-07 17:04:03 -05:00
ratioLimitValue = seedingTimeLimitValue = inactiveSeedingTimeLimitValue = NoLimit;
2022-10-18 22:39:32 -04:00
}
else if (shareLimit === 'custom') {
ratioLimitValue = $('setRatio').get('checked') ? $('ratio').get('value') : -1;
2024-01-07 17:04:03 -05:00
seedingTimeLimitValue = $('setTotalMinutes').get('checked') ? $('totalMinutes').get('value') : -1;
inactiveSeedingTimeLimitValue = $('setInactiveMinutes').get('checked') ? $('inactiveMinutes').get('value') : -1;
2022-10-18 22:39:32 -04:00
}
else {
return false;
}
new Request({
url: 'api/v2/torrents/setShareLimits',
method: 'post',
data: {
hashes: hashesList.join('|'),
ratioLimit: ratioLimitValue,
2024-01-07 17:04:03 -05:00
seedingTimeLimit: seedingTimeLimitValue,
inactiveSeedingTimeLimit: inactiveSeedingTimeLimitValue
2022-10-18 22:39:32 -04:00
},
onComplete: function() {
window.parent.closeWindows();
}
}).send();
});
});
function getSelectedRadioValue(name) {
const radios = document.getElementsByName(name);
for (let i = 0; i < radios.length ; + + i ) {
const radio = radios[i];
if (radio.checked) {
return (radio).get('value');
}
}
}
function setSelectedRadioValue(name, value) {
const radios = document.getElementsByName(name);
for (let i = 0; i < radios.length ; + + i ) {
const radio = radios[i];
if (radio.value === value)
radio.checked = true;
}
}
function shareLimitChanged() {
const customShareLimit = getSelectedRadioValue('shareLimit') === 'custom';
$('setRatio').set('disabled', !customShareLimit);
2024-01-07 17:04:03 -05:00
$('setTotalMinutes').set('disabled', !customShareLimit);
$('setInactiveMinutes').set('disabled', !customShareLimit);
2022-10-18 22:39:32 -04:00
enableInputBoxes();
$('save').set('disabled', !isFormValid());
}
function enableInputBoxes() {
$('ratio').set('disabled', ($('setRatio').get('disabled') || !$('setRatio').get('checked')));
2024-01-07 17:04:03 -05:00
$('totalMinutes').set('disabled', ($('setTotalMinutes').get('disabled') || !$('setTotalMinutes').get('checked')));
$('inactiveMinutes').set('disabled', ($('setInactiveMinutes').get('disabled') || !$('setInactiveMinutes').get('checked')));
2022-10-18 22:39:32 -04:00
$('save').set('disabled', !isFormValid());
}
function isFormValid() {
2024-01-07 17:04:03 -05:00
return !((getSelectedRadioValue('shareLimit') === 'custom') & & !$('setRatio').get('checked')
& & !$('setTotalMinutes').get('checked') & & !$('setInactiveMinutes').get('checked'));
2022-10-18 22:39:32 -04:00
}
< / script >
< / head >
< body >
< div style = "padding: 10px 10px 0px 10px;" >
2024-01-07 17:04:03 -05:00
< input type = "radio" name = "shareLimit" id = "default" value = "default" onchange = "shareLimitChanged()" checked style = "margin-bottom: 5px;" / > Use global share limit< br / >
< input type = "radio" name = "shareLimit" value = "none" onchange = "shareLimitChanged()" style = "margin-bottom: 5px;" / > Set no share limit< br / >
< input type = "radio" name = "shareLimit" value = "custom" onchange = "shareLimitChanged()" style = "margin-bottom: 5px;" / > Set share limit to< br / >
2022-10-18 22:39:32 -04:00
< div style = "margin-left: 40px; margin-bottom: 5px;" >
< input type = "checkbox" id = "setRatio" class = "shareLimitInput" onclick = "enableInputBoxes()" / >
2022-11-30 13:49:48 -05:00
< label for = "setRatio" > ratio< / label >
2022-10-18 22:39:32 -04:00
< input type = "number" id = "ratio" value = "0.00" step = ".01" min = "0" max = "9999" class = "shareLimitInput" / >
< / div >
< div style = "margin-left: 40px; margin-bottom: 5px;" >
2024-01-07 17:04:03 -05:00
< input type = "checkbox" id = "setTotalMinutes" class = "shareLimitInput" onclick = "enableInputBoxes()" / >
< label for = "setTotalMinutes" > total minutes< / label >
< input type = "number" id = "totalMinutes" value = "0" step = "1" min = "0" max = "525600" class = "shareLimitInput" / >
< / div >
< div style = "margin-left: 40px; margin-bottom: 5px;" >
< input type = "checkbox" id = "setInactiveMinutes" class = "shareLimitInput" onclick = "enableInputBoxes()" / >
< label for = "setInactiveMinutes" > inactive minutes< / label >
< input type = "number" id = "inactiveMinutes" value = "0" step = "1" min = "0" max = "525600" class = "shareLimitInput" / >
2022-10-18 22:39:32 -04:00
< / div >
< div style = "text-align: center; padding-top: 10px;" >
2024-01-07 17:04:03 -05:00
< input type = "button" value = "Save" id = "save" / >
2022-10-18 22:39:32 -04:00
< / div >
< / div >
< / body >
< / html >