WebUI: use native function for selecting elements
[qBittorrent.git] / src / webui / www / private / views / installsearchplugin.html
blobde77a46e167dafda14af8391da3a5c50d6ee1b77
1 <style>
2 #installSearchPluginContainer {
3 margin: 10px;
6 #installSearchPluginContainer button {
7 padding: 3px 20px;
10 #newPluginPath {
11 width: 100%;
14 </style>
16 <div id="installSearchPluginContainer">
17 <label for="newPluginPath">QBT_TR(Plugin path:)QBT_TR[CONTEXT=PluginSourceDlg]</label>
19 <div>
20 <input type="text" id="newPluginPath" placeholder="QBT_TR(URL or local directory)QBT_TR[CONTEXT=PluginSourceDlg]" autocorrect="off" autocapitalize="none">
21 <div style="margin-top: 10px; text-align: center;">
22 <button type="button" id="newPluginCancel" onclick="window.qBittorrent.Client.closeWindow(document.getElementById('installSearchPlugin'));">QBT_TR(Cancel)QBT_TR[CONTEXT=PluginSourceDlg]</button>
23 <button type="button" id="newPluginOk" onclick="qBittorrent.InstallSearchPlugin.newPluginOk();">QBT_TR(Ok)QBT_TR[CONTEXT=PluginSourceDlg]</button>
24 </div>
25 </div>
26 </div>
28 <script>
29 "use strict";
31 window.qBittorrent ??= {};
32 window.qBittorrent.InstallSearchPlugin ??= (() => {
33 const exports = () => {
34 return {
35 setup: setup,
36 newPluginOk: newPluginOk
40 const setup = () => {
41 const windowEl = document.getElementById("installSearchPlugin");
43 windowEl.addEventListener("keydown", (event) => {
44 switch (event.key) {
45 case "Enter":
46 // accept enter key as a click
47 event.preventDefault();
48 event.stopPropagation();
50 switch (event.target.id) {
51 case "newPluginCancel":
52 window.qBittorrent.Client.closeWindow(windowEl);
53 break;
54 case "newPluginOk":
55 case "newPluginPath":
56 newPluginOk();
57 break;
60 break;
62 });
64 $("newPluginPath").select();
67 const newPluginOk = () => {
68 const path = $("newPluginPath").value.trim();
69 if (path) {
70 fetch("api/v2/search/installPlugin", {
71 method: "POST",
72 body: new URLSearchParams({
73 sources: path
76 .then((response) => {
77 if (!response.ok)
78 return;
80 window.qBittorrent.Client.closeWindow(document.getElementById("installSearchPlugin"));
81 });
85 return exports();
86 })();
87 Object.freeze(window.qBittorrent.InstallSearchPlugin);
89 window.qBittorrent.InstallSearchPlugin.setup();
90 </script>