WebUI: migrate to fetch API
[qBittorrent.git] / src / webui / www / private / newfeed.html
blob5197189af59ee526cf6caf4501f9dd54a7c19e36
1 <!DOCTYPE html>
2 <html lang="${LANG}" class="dark">
4 <head>
5 <meta charset="UTF-8">
6 <title>QBT_TR(Please type a RSS feed URL)QBT_TR[CONTEXT=RSSWidget]</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 $("submitButton").click();
22 break;
23 case "Escape":
24 event.preventDefault();
25 window.parent.qBittorrent.Client.closeFrameWindow(window);
26 break;
28 });
30 $("feedURL").focus();
31 const path = new URI().getData("path");
32 $("submitButton").addEventListener("click", (e) => {
33 e.preventDefault();
34 e.stopPropagation();
36 // check field
37 const feedURL = $("feedURL").value.trim();
38 if (feedURL === "") {
39 alert("QBT_TR(Name cannot be empty)QBT_TR[CONTEXT=HttpServer]");
40 return;
43 $("submitButton").disabled = true;
45 fetch("api/v2/rss/addFeed", {
46 method: "POST",
47 body: new URLSearchParams({
48 "url": feedURL,
49 "path": path ? (path + "\\" + feedURL) : ""
52 .then(async (response) => {
53 if (!response.ok) {
54 if (response.status === 409)
55 alert(await response.text());
56 $("submitButton").disabled = false;
57 return;
60 window.parent.qBittorrent.Rss.updateRssFeedList();
61 window.parent.qBittorrent.Client.closeFrameWindow(window);
62 });
63 });
64 });
65 </script>
66 </head>
68 <body>
69 <div style="padding: 10px 10px 0px 10px;">
70 <label for="feedURL" style="font-weight: bold;">QBT_TR(Feed URL:)QBT_TR[CONTEXT=RSSWidget]</label>
71 <input type="text" id="feedURL" style="width: 320px;">
72 <div style="text-align: center; padding-top: 10px;">
73 <input type="button" value="QBT_TR(OK)QBT_TR[CONTEXT=HttpServer]" id="submitButton">
74 </div>
75 </div>
76 </body>
78 </html>