Allow to refresh existing search
[qBittorrent.git] / src / webui / www / private / shareratio.html
blobce5131d5bbbc8b841ea72b181cbfab20ef594b0d
1 <!DOCTYPE html>
2 <html lang="${LANG}" class="dark">
4 <head>
5 <meta charset="UTF-8">
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/localpreferences.js?v=${CACHEID}"></script>
11 <script src="scripts/color-scheme.js?v=${CACHEID}"></script>
12 <script src="scripts/misc.js?locale=${LANG}&v=${CACHEID}"></script>
13 <script>
14 "use strict";
16 const UseGlobalLimit = -2;
17 const NoLimit = -1;
19 window.addEventListener("DOMContentLoaded", () => {
20 window.addEventListener("keydown", (event) => {
21 switch (event.key) {
22 case "Enter":
23 event.preventDefault();
24 $("save").click();
25 break;
26 case "Escape":
27 event.preventDefault();
28 window.parent.qBittorrent.Client.closeFrameWindow(window);
29 break;
31 });
33 const hashesList = new URI().getData("hashes").split("|");
34 const origValues = new URI().getData("orig").split("|");
36 const values = {
37 ratioLimit: window.qBittorrent.Misc.friendlyFloat(origValues[0], 2),
38 seedingTimeLimit: Number(origValues[1]),
39 inactiveSeedingTimeLimit: Number(origValues[2]),
40 maxRatio: window.qBittorrent.Misc.friendlyFloat(origValues[3], 2),
41 maxSeedingTime: Number(origValues[4]),
42 maxInactiveSeedingTime: Number(origValues[5])
45 // select default when orig values not passed. using double equals to compare string and int
46 if ((origValues[0] === "")
47 || ((values.ratioLimit === UseGlobalLimit)
48 && (values.seedingTimeLimit === UseGlobalLimit)
49 && (values.inactiveSeedingTimeLimit === UseGlobalLimit))) {
50 // use default option
51 setSelectedRadioValue("shareLimit", "default");
53 else if ((values.maxRatio === NoLimit) && (values.maxSeedingTime === NoLimit) && (values.maxInactiveSeedingTime === NoLimit)) {
54 setSelectedRadioValue("shareLimit", "none");
55 // TODO set input boxes to *global* max ratio and seeding time
57 else {
58 setSelectedRadioValue("shareLimit", "custom");
59 if (values.ratioLimit >= 0) {
60 $("setRatio").checked = true;
61 $("ratio").value = values.ratioLimit;
63 if (values.seedingTimeLimit >= 0) {
64 $("setTotalMinutes").checked = true;
65 $("totalMinutes").value = values.seedingTimeLimit;
67 if (values.inactiveSeedingTimeLimit >= 0) {
68 $("setInactiveMinutes").checked = true;
69 $("inactiveMinutes").value = values.inactiveSeedingTimeLimit;
73 shareLimitChanged();
75 $("default").focus();
76 $("save").addEventListener("click", (e) => {
77 e.preventDefault();
78 e.stopPropagation();
80 if (!isFormValid())
81 return;
83 const shareLimit = getSelectedRadioValue("shareLimit");
84 let ratioLimitValue = 0.00;
85 let seedingTimeLimitValue = 0;
86 let inactiveSeedingTimeLimitValue = 0;
88 if (shareLimit === "default") {
89 ratioLimitValue = seedingTimeLimitValue = inactiveSeedingTimeLimitValue = UseGlobalLimit;
91 else if (shareLimit === "none") {
92 ratioLimitValue = seedingTimeLimitValue = inactiveSeedingTimeLimitValue = NoLimit;
94 else if (shareLimit === "custom") {
95 ratioLimitValue = $("setRatio").checked ? $("ratio").value : -1;
96 seedingTimeLimitValue = $("setTotalMinutes").checked ? $("totalMinutes").value : -1;
97 inactiveSeedingTimeLimitValue = $("setInactiveMinutes").checked ? $("inactiveMinutes").value : -1;
99 else {
100 return;
103 fetch("api/v2/torrents/setShareLimits", {
104 method: "POST",
105 body: new URLSearchParams({
106 hashes: hashesList.join("|"),
107 ratioLimit: ratioLimitValue,
108 seedingTimeLimit: seedingTimeLimitValue,
109 inactiveSeedingTimeLimit: inactiveSeedingTimeLimitValue
112 .then(async (response) => {
113 if (!response.ok)
114 return;
116 window.parent.qBittorrent.Client.closeFrameWindow(window);
121 const getSelectedRadioValue = (name) => {
122 const radios = document.getElementsByName(name);
124 for (let i = 0; i < radios.length; ++i) {
125 const radio = radios[i];
126 if (radio.checked)
127 return radio.value;
131 const setSelectedRadioValue = (name, value) => {
132 const radios = document.getElementsByName(name);
134 for (let i = 0; i < radios.length; ++i) {
135 const radio = radios[i];
136 if (radio.value === value)
137 radio.checked = true;
141 const shareLimitChanged = () => {
142 const customShareLimit = getSelectedRadioValue("shareLimit") === "custom";
143 $("setRatio").disabled = !customShareLimit;
144 $("setTotalMinutes").disabled = !customShareLimit;
145 $("setInactiveMinutes").disabled = !customShareLimit;
147 enableInputBoxes();
149 $("save").disabled = !isFormValid();
152 const enableInputBoxes = () => {
153 $("ratio").disabled = $("setRatio").disabled || !$("setRatio").checked;
154 $("totalMinutes").disabled = $("setTotalMinutes").disabled || !$("setTotalMinutes").checked;
155 $("inactiveMinutes").disabled = $("setInactiveMinutes").disabled || !$("setInactiveMinutes").checked;
157 $("save").disabled = !isFormValid();
160 const isFormValid = () => {
161 return !((getSelectedRadioValue("shareLimit") === "custom") && !$("setRatio").checked
162 && !$("setTotalMinutes").checked && !$("setInactiveMinutes").checked);
164 </script>
165 </head>
167 <body>
168 <div style="padding: 10px 10px 0px 10px;">
169 <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>
170 <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>
171 <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>
173 <div style="margin-left: 40px; margin-bottom: 5px;">
174 <input type="checkbox" id="setRatio" class="shareLimitInput" onclick="enableInputBoxes()">
175 <label id="ratioLabel" for="setRatio">QBT_TR(ratio)QBT_TR[CONTEXT=UpDownRatioDialog]</label>
176 <input type="number" id="ratio" value="0.00" step=".01" min="0" max="9999" class="shareLimitInput" aria-labelledby="ratioLabel">
177 </div>
178 <div style="margin-left: 40px; margin-bottom: 5px;">
179 <input type="checkbox" id="setTotalMinutes" class="shareLimitInput" onclick="enableInputBoxes()">
180 <label id="totalMinutesLabel" for="setTotalMinutes">QBT_TR(total minutes)QBT_TR[CONTEXT=UpDownRatioDialog]</label>
181 <input type="number" id="totalMinutes" value="0" step="1" min="0" max="525600" class="shareLimitInput" aria-labelledby="totalMinutesLabel">
182 </div>
183 <div style="margin-left: 40px; margin-bottom: 5px;">
184 <input type="checkbox" id="setInactiveMinutes" class="shareLimitInput" onclick="enableInputBoxes()">
185 <label id="inactiveMinutesLabel" for="setInactiveMinutes">QBT_TR(inactive minutes)QBT_TR[CONTEXT=UpDownRatioDialog]</label>
186 <input type="number" id="inactiveMinutes" value="0" step="1" min="0" max="525600" class="shareLimitInput" aria-labelledby="inactiveMinutesLabel">
187 </div>
188 <div style="text-align: center; padding-top: 10px;">
189 <input type="button" value="QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" id="save">
190 </div>
191 </div>
192 </body>
194 </html>