6 <title>QBT_TR(Torrent Upload/Download Ratio Limiting)QBT_TR[CONTEXT=UpDownRatioDialog]
</title>
7 <link rel=
"stylesheet" href=
"css/style.css?v=${CACHEID}" type=
"text/css">
8 <script src=
"scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script>
9 <script src=
"scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script>
10 <script src=
"scripts/misc.js?locale=${LANG}&v=${CACHEID}"></script>
14 const UseGlobalLimit
= -2;
18 defaultEventType
: "keydown",
20 "Enter": function(event
) {
22 event
.preventDefault();
24 "Escape": function(event
) {
25 window
.parent
.qBittorrent
.Client
.closeWindows();
26 event
.preventDefault();
28 "Esc": function(event
) {
29 window
.parent
.qBittorrent
.Client
.closeWindows();
30 event
.preventDefault();
35 window
.addEventListener("DOMContentLoaded", () => {
36 const hashesList
= new URI().getData("hashes").split("|");
37 const origValues
= new URI().getData("orig").split("|");
40 ratioLimit
: window
.qBittorrent
.Misc
.friendlyFloat(origValues
[0], 2),
41 seedingTimeLimit
: parseInt(origValues
[1], 10),
42 inactiveSeedingTimeLimit
: parseInt(origValues
[2], 10),
43 maxRatio
: window
.qBittorrent
.Misc
.friendlyFloat(origValues
[3], 2),
44 maxSeedingTime
: parseInt(origValues
[4], 10),
45 maxInactiveSeedingTime
: parseInt(origValues
[5], 10)
48 // select default when orig values not passed. using double equals to compare string and int
49 if ((origValues
[0] === "")
50 || ((values
.ratioLimit
=== UseGlobalLimit
)
51 && (values
.seedingTimeLimit
=== UseGlobalLimit
)
52 && (values
.inactiveSeedingTimeLimit
=== UseGlobalLimit
))) {
54 setSelectedRadioValue("shareLimit", "default");
56 else if ((values
.maxRatio
=== NoLimit
) && (values
.maxSeedingTime
=== NoLimit
) && (values
.maxInactiveSeedingTime
=== NoLimit
)) {
57 setSelectedRadioValue("shareLimit", "none");
58 // TODO set input boxes to *global* max ratio and seeding time
61 setSelectedRadioValue("shareLimit", "custom");
62 if (values
.ratioLimit
>= 0) {
63 $("setRatio").checked
= true;
64 $("ratio").value
= values
.ratioLimit
;
66 if (values
.seedingTimeLimit
>= 0) {
67 $("setTotalMinutes").checked
= true;
68 $("totalMinutes").value
= values
.seedingTimeLimit
;
70 if (values
.inactiveSeedingTimeLimit
>= 0) {
71 $("setInactiveMinutes").checked
= true;
72 $("inactiveMinutes").value
= values
.inactiveSeedingTimeLimit
;
79 $("save").addEventListener("click", (e
) => {
86 const shareLimit
= getSelectedRadioValue("shareLimit");
87 let ratioLimitValue
= 0.00;
88 let seedingTimeLimitValue
= 0;
89 let inactiveSeedingTimeLimitValue
= 0;
91 if (shareLimit
=== "default") {
92 ratioLimitValue
= seedingTimeLimitValue
= inactiveSeedingTimeLimitValue
= UseGlobalLimit
;
94 else if (shareLimit
=== "none") {
95 ratioLimitValue
= seedingTimeLimitValue
= inactiveSeedingTimeLimitValue
= NoLimit
;
97 else if (shareLimit
=== "custom") {
98 ratioLimitValue
= $("setRatio").checked
? $("ratio").value
: -1;
99 seedingTimeLimitValue
= $("setTotalMinutes").checked
? $("totalMinutes").value
: -1;
100 inactiveSeedingTimeLimitValue
= $("setInactiveMinutes").checked
? $("inactiveMinutes").value
: -1;
107 url
: "api/v2/torrents/setShareLimits",
110 hashes
: hashesList
.join("|"),
111 ratioLimit
: ratioLimitValue
,
112 seedingTimeLimit
: seedingTimeLimitValue
,
113 inactiveSeedingTimeLimit
: inactiveSeedingTimeLimitValue
115 onComplete: function() {
116 window
.parent
.qBittorrent
.Client
.closeWindows();
122 function getSelectedRadioValue(name
) {
123 const radios
= document
.getElementsByName(name
);
125 for (let i
= 0; i
< radios
.length
; ++i
) {
126 const radio
= radios
[i
];
132 function setSelectedRadioValue(name
, value
) {
133 const radios
= document
.getElementsByName(name
);
135 for (let i
= 0; i
< radios
.length
; ++i
) {
136 const radio
= radios
[i
];
137 if (radio
.value
=== value
)
138 radio
.checked
= true;
142 function shareLimitChanged() {
143 const customShareLimit
= getSelectedRadioValue("shareLimit") === "custom";
144 $("setRatio").disabled
= !customShareLimit
;
145 $("setTotalMinutes").disabled
= !customShareLimit
;
146 $("setInactiveMinutes").disabled
= !customShareLimit
;
150 $("save").disabled
= !isFormValid();
153 function enableInputBoxes() {
154 $("ratio").disabled
= $("setRatio").disabled
|| !$("setRatio").checked
;
155 $("totalMinutes").disabled
= $("setTotalMinutes").disabled
|| !$("setTotalMinutes").checked
;
156 $("inactiveMinutes").disabled
= $("setInactiveMinutes").disabled
|| !$("setInactiveMinutes").checked
;
158 $("save").disabled
= !isFormValid();
161 function isFormValid() {
162 return !((getSelectedRadioValue("shareLimit") === "custom") && !$("setRatio").checked
163 && !$("setTotalMinutes").checked
&& !$("setInactiveMinutes").checked
);
169 <div style=
"padding: 10px 10px 0px 10px;">
170 <input type=
"radio" name=
"shareLimit" id=
"default" value=
"default" onchange=
"shareLimitChanged()" checked
style=
"margin-bottom: 5px;"><label for=
"default">QBT_TR(Use global share limit)QBT_TR[CONTEXT=UpDownRatioDialog]
</label><br>
171 <input type=
"radio" name=
"shareLimit" id=
"shareLimitNone" value=
"none" onchange=
"shareLimitChanged()" style=
"margin-bottom: 5px;"><label for=
"shareLimitNone">QBT_TR(Set no share limit)QBT_TR[CONTEXT=UpDownRatioDialog]
</label><br>
172 <input type=
"radio" name=
"shareLimit" id=
"shareLimitCustom" value=
"custom" onchange=
"shareLimitChanged()" style=
"margin-bottom: 5px;"><label for=
"shareLimitCustom">QBT_TR(Set share limit to)QBT_TR[CONTEXT=UpDownRatioDialog]
</label><br>
174 <div style=
"margin-left: 40px; margin-bottom: 5px;">
175 <input type=
"checkbox" id=
"setRatio" class=
"shareLimitInput" onclick=
"enableInputBoxes()">
176 <label id=
"ratioLabel" for=
"setRatio">QBT_TR(ratio)QBT_TR[CONTEXT=UpDownRatioDialog]
</label>
177 <input type=
"number" id=
"ratio" value=
"0.00" step=
".01" min=
"0" max=
"9999" class=
"shareLimitInput" aria-labelledby=
"ratioLabel">
179 <div style=
"margin-left: 40px; margin-bottom: 5px;">
180 <input type=
"checkbox" id=
"setTotalMinutes" class=
"shareLimitInput" onclick=
"enableInputBoxes()">
181 <label id=
"totalMinutesLabel" for=
"setTotalMinutes">QBT_TR(total minutes)QBT_TR[CONTEXT=UpDownRatioDialog]
</label>
182 <input type=
"number" id=
"totalMinutes" value=
"0" step=
"1" min=
"0" max=
"525600" class=
"shareLimitInput" aria-labelledby=
"totalMinutesLabel">
184 <div style=
"margin-left: 40px; margin-bottom: 5px;">
185 <input type=
"checkbox" id=
"setInactiveMinutes" class=
"shareLimitInput" onclick=
"enableInputBoxes()">
186 <label id=
"inactiveMinutesLabel" for=
"setInactiveMinutes">QBT_TR(inactive minutes)QBT_TR[CONTEXT=UpDownRatioDialog]
</label>
187 <input type=
"number" id=
"inactiveMinutes" value=
"0" step=
"1" min=
"0" max=
"525600" class=
"shareLimitInput" aria-labelledby=
"inactiveMinutesLabel">
189 <div style=
"text-align: center; padding-top: 10px;">
190 <input type=
"button" value=
"QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" id=
"save">