WebUI: migrate to fetch API
[qBittorrent.git] / src / webui / www / private / downloadlimit.html
blob296edbc230c8e898cb4853df3195f84e404f6203
1 <!DOCTYPE html>
2 <html lang="${LANG}" class="dark">
4 <head>
5 <meta charset="UTF-8">
6 <title>QBT_TR(Torrent Download Speed Limiting)QBT_TR[CONTEXT=TransferListWidget]</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/lib/mocha.min.js"></script>
11 <script src="scripts/localpreferences.js?v=${CACHEID}"></script>
12 <script src="scripts/color-scheme.js?v=${CACHEID}"></script>
13 <script src="scripts/speedslider.js?v=${CACHEID}"></script>
14 </head>
16 <body>
17 <div style="padding-top: 10px; width: 100%; text-align: center; margin: 0 auto; overflow: hidden">
18 <div id="dllimitSlider" class="slider">
19 <div id="dllimitUpdate" class="update">
20 <label for="dllimitUpdatevalue">QBT_TR(Download limit:)QBT_TR[CONTEXT=PropertiesWidget]</label>
21 <input type="text" id="dllimitUpdatevalue" size="6" placeholder="∞" style="text-align: center;">
22 <span id="dlLimitUnit">QBT_TR(KiB/s)QBT_TR[CONTEXT=SpeedLimitDialog]</span>
23 </div>
24 <div class="sliderWrapper">
25 <div id="dllimitSliderknob" class="sliderknob"></div>
26 <div id="dllimitSliderarea" class="sliderarea"></div>
27 </div>
28 <div class="clear"></div>
29 </div>
30 <input type="button" id="applyButton" value="QBT_TR(Apply)QBT_TR[CONTEXT=HttpServer]" onclick="setDlLimit()">
31 </div>
33 <script>
34 "use strict";
36 window.addEventListener("keydown", (event) => {
37 switch (event.key) {
38 case "Enter":
39 event.preventDefault();
40 $("applyButton").click();
41 break;
42 case "Escape":
43 event.preventDefault();
44 window.parent.qBittorrent.Client.closeFrameWindow(window);
45 break;
47 });
49 const hashes = new URI().getData("hashes").split("|");
50 const setDlLimit = () => {
51 const limit = Number($("dllimitUpdatevalue").value) * 1024;
52 if (hashes[0] === "global") {
53 fetch("api/v2/transfer/setDownloadLimit", {
54 method: "POST",
55 body: new URLSearchParams({
56 "limit": limit
59 .then(async (response) => {
60 if (!response.ok)
61 return;
63 window.parent.updateMainData();
64 window.parent.qBittorrent.Client.closeFrameWindow(window);
65 });
67 else {
68 fetch("api/v2/torrents/setDownloadLimit", {
69 method: "POST",
70 body: new URLSearchParams({
71 "hashes": hashes.join("|"),
72 "limit": limit
75 .then(async (response) => {
76 if (!response.ok)
77 return;
79 window.parent.qBittorrent.Client.closeFrameWindow(window);
80 });
84 $("dllimitUpdatevalue").focus();
86 MochaUI.addDlLimitSlider(hashes);
87 </script>
88 </body>
90 </html>