WebUI: migrate to fetch API
[qBittorrent.git] / src / webui / www / private / rename_rule.html
blob7a079471a00b1949f6d54a12943a88b415850763
1 <!DOCTYPE html>
2 <html lang="${LANG}" class="dark">
4 <head>
5 <meta charset="UTF-8">
6 <title>QBT_TR(Rule renaming)QBT_TR[CONTEXT=AutomatedRssDownloader]</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 window.addEventListener("DOMContentLoaded", () => {
17 window.addEventListener("keydown", (event) => {
18 switch (event.key) {
19 case "Enter":
20 event.preventDefault();
21 $("renameButton").click();
22 break;
23 case "Escape":
24 event.preventDefault();
25 window.parent.qBittorrent.Client.closeFrameWindow(window);
26 break;
28 });
30 const oldName = new URI().getData("rule");
32 $("rename").value = oldName;
33 $("rename").focus();
34 $("rename").setSelectionRange(0, oldName.length);
36 $("renameButton").addEventListener("click", (e) => {
37 e.preventDefault();
38 e.stopPropagation();
40 // check field
41 const newName = $("rename").value.trim();
42 if (newName === "") {
43 alert("QBT_TR(Name cannot be empty)QBT_TR[CONTEXT=HttpServer]");
44 return;
47 if (newName === oldName) {
48 alert("QBT_TR(Name is unchanged)QBT_TR[CONTEXT=HttpServer]");
49 return;
52 $("renameButton").disabled = true;
54 fetch("api/v2/rss/renameRule", {
55 method: "POST",
56 body: new URLSearchParams({
57 "ruleName": oldName,
58 "newRuleName": newName
61 .then((response) => {
62 if (!response.ok)
63 return;
65 window.parent.qBittorrent.RssDownloader.updateRulesList();
66 window.parent.qBittorrent.Client.closeFrameWindow(window);
67 });
68 });
69 });
70 </script>
71 </head>
73 <body>
74 <div style="padding: 10px 10px 0px 10px;">
75 <label for="rename">QBT_TR(Please type the new rule name)QBT_TR[CONTEXT=AutomatedRssDownloader]</label>
76 <input type="text" id="rename" style="width: 320px;">
77 <div style="text-align: center; padding-top: 10px;">
78 <input type="button" value="QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" id="renameButton">
79 </div>
80 </div>
81 </body>
83 </html>