Move WebUI views into separate folder
[qBittorrent.git] / src / webui / www / private / scripts / mocha-init.js
blob023a1befbfa33e920b55efd0117aa005508e80b5
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2008 Christophe Dumez <chris@qbittorrent.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
29 /* -----------------------------------------------------------------
31 ATTACH MOCHA LINK EVENTS
32 Notes: Here is where you define your windows and the events that open them.
33 If you are not using links to run Mocha methods you can remove this function.
35 If you need to add link events to links within windows you are creating, do
36 it in the onContentLoaded function of the new window.
38 ----------------------------------------------------------------- */
39 'use strict';
41 /* Define localStorage object for older browsers */
42 if (typeof localStorage == 'undefined') {
43 window['localStorage'] = {
44 getItem: function(name) {
45 return Cookie.read(name);
47 setItem: function(name, value) {
48 Cookie.write(name, value, {
49 duration: 365 * 10
50 });
55 function getLocalStorageItem(name, defaultVal) {
56 let val = localStorage.getItem(name);
57 if (val === null || val === undefined)
58 val = defaultVal;
59 return val;
62 let saveWindowSize = function() {};
63 let loadWindowWidth = function() {};
64 let loadWindowHeight = function() {};
65 let showDownloadPage = function() {};
66 let globalUploadLimitFN = function() {};
67 let uploadLimitFN = function() {};
68 let shareRatioFN = function() {};
69 let toggleSequentialDownloadFN = function() {};
70 let toggleFirstLastPiecePrioFN = function() {};
71 let setSuperSeedingFN = function() {};
72 let setForceStartFN = function() {};
73 let globalDownloadLimitFN = function() {};
74 let StatisticsLinkFN = function() {};
75 let downloadLimitFN = function() {};
76 let deleteFN = function() {};
77 let pauseFN = function() {};
78 let startFN = function() {};
79 let autoTorrentManagementFN = function() {};
80 let recheckFN = function() {};
81 let reannounceFN = function() {};
82 let setLocationFN = function() {};
83 let renameFN = function() {};
84 let torrentNewCategoryFN = function() {};
85 let torrentSetCategoryFN = function() {};
86 let createCategoryFN = function() {};
87 let editCategoryFN = function() {};
88 let removeCategoryFN = function() {};
89 let deleteUnusedCategoriesFN = function() {};
90 let startTorrentsByCategoryFN = function() {};
91 let pauseTorrentsByCategoryFN = function() {};
92 let deleteTorrentsByCategoryFN = function() {};
93 let torrentAddTagsFN = function() {};
94 let torrentSetTagsFN = function() {};
95 let torrentRemoveAllTagsFN = function() {};
96 let createTagFN = function() {};
97 let removeTagFN = function() {};
98 let deleteUnusedTagsFN = function() {};
99 let startTorrentsByTagFN = function() {};
100 let pauseTorrentsByTagFN = function() {};
101 let deleteTorrentsByTagFN = function() {};
102 let copyNameFN = function() {};
103 let copyMagnetLinkFN = function() {};
104 let copyHashFN = function() {};
105 let setQueuePositionFN = function() {};
107 const initializeWindows = function() {
108 saveWindowSize = function(windowId) {
109 const size = $(windowId).getSize();
110 localStorage.setItem('window_' + windowId + '_width', size.x);
111 localStorage.setItem('window_' + windowId + '_height', size.y);
114 loadWindowWidth = function(windowId, defaultValue) {
115 return getLocalStorageItem('window_' + windowId + '_width', defaultValue);
118 loadWindowHeight = function(windowId, defaultValue) {
119 return getLocalStorageItem('window_' + windowId + '_height', defaultValue);
122 function addClickEvent(el, fn) {
123 ['Link', 'Button'].each(function(item) {
124 if ($(el + item)) {
125 $(el + item).addEvent('click', fn);
130 addClickEvent('download', function(e) {
131 new Event(e).stop();
132 showDownloadPage();
135 showDownloadPage = function(urls) {
136 const id = 'downloadPage';
137 let contentUrl = 'download.html';
138 if (urls && (urls.length > 0)) {
139 contentUrl += ('?urls=' + urls.map(function(url) {
140 return encodeURIComponent(url);
141 }).join("|"));
144 new MochaUI.Window({
145 id: id,
146 title: "QBT_TR(Download from URLs)QBT_TR[CONTEXT=downloadFromURL]",
147 loadMethod: 'iframe',
148 contentURL: contentUrl,
149 addClass: 'windowFrame', // fixes iframe scrolling on iOS Safari
150 scrollbars: true,
151 maximizable: false,
152 closable: true,
153 paddingVertical: 0,
154 paddingHorizontal: 0,
155 width: loadWindowWidth(id, 500),
156 height: loadWindowHeight(id, 600),
157 onResize: function() {
158 saveWindowSize(id);
161 updateMainData();
164 addClickEvent('preferences', function(e) {
165 new Event(e).stop();
166 const id = 'preferencesPage';
167 new MochaUI.Window({
168 id: id,
169 title: "QBT_TR(Options)QBT_TR[CONTEXT=OptionsDialog]",
170 loadMethod: 'xhr',
171 toolbar: true,
172 contentURL: 'views/preferences.html',
173 require: {
174 css: ['css/Tabs.css']
176 toolbarURL: 'views/preferencesToolbar.html',
177 maximizable: false,
178 closable: true,
179 paddingVertical: 0,
180 paddingHorizontal: 0,
181 width: loadWindowWidth(id, 700),
182 height: loadWindowHeight(id, 600),
183 onResize: function() {
184 saveWindowSize(id);
189 addClickEvent('upload', function(e) {
190 new Event(e).stop();
191 const id = 'uploadPage';
192 new MochaUI.Window({
193 id: id,
194 title: "QBT_TR(Upload local torrent)QBT_TR[CONTEXT=HttpServer]",
195 loadMethod: 'iframe',
196 contentURL: 'upload.html',
197 addClass: 'windowFrame', // fixes iframe scrolling on iOS Safari
198 scrollbars: true,
199 maximizable: false,
200 paddingVertical: 0,
201 paddingHorizontal: 0,
202 width: loadWindowWidth(id, 500),
203 height: loadWindowHeight(id, 460),
204 onResize: function() {
205 saveWindowSize(id);
208 updateMainData();
211 globalUploadLimitFN = function() {
212 new MochaUI.Window({
213 id: 'uploadLimitPage',
214 title: "QBT_TR(Global Upload Speed Limit)QBT_TR[CONTEXT=MainWindow]",
215 loadMethod: 'iframe',
216 contentURL: 'uploadlimit.html?hashes=global',
217 scrollbars: false,
218 resizable: false,
219 maximizable: false,
220 paddingVertical: 0,
221 paddingHorizontal: 0,
222 width: 424,
223 height: 80
227 uploadLimitFN = function() {
228 const hashes = torrentsTable.selectedRowsIds();
229 if (hashes.length) {
230 new MochaUI.Window({
231 id: 'uploadLimitPage',
232 title: "QBT_TR(Torrent Upload Speed Limiting)QBT_TR[CONTEXT=TransferListWidget]",
233 loadMethod: 'iframe',
234 contentURL: 'uploadlimit.html?hashes=' + hashes.join("|"),
235 scrollbars: false,
236 resizable: false,
237 maximizable: false,
238 paddingVertical: 0,
239 paddingHorizontal: 0,
240 width: 424,
241 height: 80
246 shareRatioFN = function() {
247 const hashes = torrentsTable.selectedRowsIds();
248 if (hashes.length) {
249 let shareRatio = null;
250 let torrentsHaveSameShareRatio = true;
252 // check if all selected torrents have same share ratio
253 for (let i = 0; i < hashes.length; ++i) {
254 const hash = hashes[i];
255 const row = torrentsTable.rows[hash].full_data;
256 const origValues = row.ratio_limit + "|" + row.seeding_time_limit + "|" + row.max_ratio + "|" + row.max_seeding_time;
258 // initialize value
259 if (shareRatio === null)
260 shareRatio = origValues;
262 if (origValues !== shareRatio) {
263 torrentsHaveSameShareRatio = false;
264 break;
268 // if all torrents have same share ratio, display that share ratio. else use the default
269 const orig = torrentsHaveSameShareRatio ? shareRatio : "";
270 new MochaUI.Window({
271 id: 'shareRatioPage',
272 title: "QBT_TR(Torrent Upload/Download Ratio Limiting)QBT_TR[CONTEXT=UpDownRatioDialog]",
273 loadMethod: 'iframe',
274 contentURL: 'shareratio.html?hashes=' + hashes.join("|") + '&orig=' + orig,
275 scrollbars: false,
276 maximizable: false,
277 paddingVertical: 0,
278 paddingHorizontal: 0,
279 width: 424,
280 height: 175
285 toggleSequentialDownloadFN = function() {
286 const hashes = torrentsTable.selectedRowsIds();
287 if (hashes.length) {
288 new Request({
289 url: 'api/v2/torrents/toggleSequentialDownload',
290 method: 'post',
291 data: {
292 hashes: hashes.join("|")
294 }).send();
295 updateMainData();
299 toggleFirstLastPiecePrioFN = function() {
300 const hashes = torrentsTable.selectedRowsIds();
301 if (hashes.length) {
302 new Request({
303 url: 'api/v2/torrents/toggleFirstLastPiecePrio',
304 method: 'post',
305 data: {
306 hashes: hashes.join("|")
308 }).send();
309 updateMainData();
313 setSuperSeedingFN = function(val) {
314 const hashes = torrentsTable.selectedRowsIds();
315 if (hashes.length) {
316 new Request({
317 url: 'api/v2/torrents/setSuperSeeding',
318 method: 'post',
319 data: {
320 value: val,
321 hashes: hashes.join("|")
323 }).send();
324 updateMainData();
328 setForceStartFN = function() {
329 const hashes = torrentsTable.selectedRowsIds();
330 if (hashes.length) {
331 new Request({
332 url: 'api/v2/torrents/setForceStart',
333 method: 'post',
334 data: {
335 value: 'true',
336 hashes: hashes.join("|")
338 }).send();
339 updateMainData();
343 globalDownloadLimitFN = function() {
344 new MochaUI.Window({
345 id: 'downloadLimitPage',
346 title: "QBT_TR(Global Download Speed Limit)QBT_TR[CONTEXT=MainWindow]",
347 loadMethod: 'iframe',
348 contentURL: 'downloadlimit.html?hashes=global',
349 scrollbars: false,
350 resizable: false,
351 maximizable: false,
352 paddingVertical: 0,
353 paddingHorizontal: 0,
354 width: 424,
355 height: 80
359 StatisticsLinkFN = function() {
360 const id = 'statisticspage';
361 new MochaUI.Window({
362 id: id,
363 title: 'QBT_TR(Statistics)QBT_TR[CONTEXT=StatsDialog]',
364 loadMethod: 'xhr',
365 contentURL: 'views/statistics.html',
366 maximizable: false,
367 padding: 10,
368 width: loadWindowWidth(id, 275),
369 height: loadWindowHeight(id, 370),
370 onResize: function() {
371 saveWindowSize(id);
376 downloadLimitFN = function() {
377 const hashes = torrentsTable.selectedRowsIds();
378 if (hashes.length) {
379 new MochaUI.Window({
380 id: 'downloadLimitPage',
381 title: "QBT_TR(Torrent Download Speed Limiting)QBT_TR[CONTEXT=TransferListWidget]",
382 loadMethod: 'iframe',
383 contentURL: 'downloadlimit.html?hashes=' + hashes.join("|"),
384 scrollbars: false,
385 resizable: false,
386 maximizable: false,
387 paddingVertical: 0,
388 paddingHorizontal: 0,
389 width: 424,
390 height: 80
395 deleteFN = function() {
396 const hashes = torrentsTable.selectedRowsIds();
397 if (hashes.length) {
398 new MochaUI.Window({
399 id: 'confirmDeletionPage',
400 title: "QBT_TR(Deletion confirmation)QBT_TR[CONTEXT=confirmDeletionDlg]",
401 loadMethod: 'iframe',
402 contentURL: 'confirmdeletion.html?hashes=' + hashes.join("|"),
403 scrollbars: false,
404 resizable: false,
405 maximizable: false,
406 padding: 10,
407 width: 424,
408 height: 140
410 updateMainData();
414 addClickEvent('delete', function(e) {
415 new Event(e).stop();
416 deleteFN();
419 pauseFN = function() {
420 const hashes = torrentsTable.selectedRowsIds();
421 if (hashes.length) {
422 new Request({
423 url: 'api/v2/torrents/pause',
424 method: 'post',
425 data: {
426 hashes: hashes.join("|")
428 }).send();
429 updateMainData();
433 startFN = function() {
434 const hashes = torrentsTable.selectedRowsIds();
435 if (hashes.length) {
436 new Request({
437 url: 'api/v2/torrents/resume',
438 method: 'post',
439 data: {
440 hashes: hashes.join("|")
442 }).send();
443 updateMainData();
447 autoTorrentManagementFN = function() {
448 const hashes = torrentsTable.selectedRowsIds();
449 if (hashes.length) {
450 let enable = false;
451 hashes.each(function(hash, index) {
452 const row = torrentsTable.rows[hash];
453 if (!row.full_data.auto_tmm)
454 enable = true;
456 new Request({
457 url: 'api/v2/torrents/setAutoManagement',
458 method: 'post',
459 data: {
460 hashes: hashes.join("|"),
461 enable: enable
463 }).send();
464 updateMainData();
468 recheckFN = function() {
469 const hashes = torrentsTable.selectedRowsIds();
470 if (hashes.length) {
471 new Request({
472 url: 'api/v2/torrents/recheck',
473 method: 'post',
474 data: {
475 hashes: hashes.join("|"),
477 }).send();
478 updateMainData();
482 reannounceFN = function() {
483 const hashes = torrentsTable.selectedRowsIds();
484 if (hashes.length) {
485 new Request({
486 url: 'api/v2/torrents/reannounce',
487 method: 'post',
488 data: {
489 hashes: hashes.join("|"),
491 }).send();
492 updateMainData();
496 setLocationFN = function() {
497 const hashes = torrentsTable.selectedRowsIds();
498 if (hashes.length) {
499 const hash = hashes[0];
500 const row = torrentsTable.rows[hash];
501 const path = encodeURIComponent(row.full_data.save_path);
502 new MochaUI.Window({
503 id: 'setLocationPage',
504 title: "QBT_TR(Set location)QBT_TR[CONTEXT=TransferListWidget]",
505 loadMethod: 'iframe',
506 contentURL: 'setlocation.html?hashes=' + hashes.join('|') + '&path=' + path,
507 scrollbars: false,
508 resizable: false,
509 maximizable: false,
510 paddingVertical: 0,
511 paddingHorizontal: 0,
512 width: 400,
513 height: 130
518 renameFN = function() {
519 const hashes = torrentsTable.selectedRowsIds();
520 if (hashes.length == 1) {
521 const hash = hashes[0];
522 const row = torrentsTable.rows[hash];
523 if (row) {
524 new MochaUI.Window({
525 id: 'renamePage',
526 title: "QBT_TR(Rename)QBT_TR[CONTEXT=TransferListWidget]",
527 loadMethod: 'iframe',
528 contentURL: 'rename.html?hash=' + hash + '&name=' + encodeURIComponent(row.full_data.name),
529 scrollbars: false,
530 resizable: false,
531 maximizable: false,
532 paddingVertical: 0,
533 paddingHorizontal: 0,
534 width: 250,
535 height: 100
541 torrentNewCategoryFN = function() {
542 const action = "set";
543 const hashes = torrentsTable.selectedRowsIds();
544 if (hashes.length) {
545 new MochaUI.Window({
546 id: 'newCategoryPage',
547 title: "QBT_TR(New Category)QBT_TR[CONTEXT=TransferListWidget]",
548 loadMethod: 'iframe',
549 contentURL: 'newcategory.html?action=' + action + '&hashes=' + hashes.join('|'),
550 scrollbars: false,
551 resizable: false,
552 maximizable: false,
553 paddingVertical: 0,
554 paddingHorizontal: 0,
555 width: 250,
556 height: 150
561 torrentSetCategoryFN = function(categoryHash) {
562 let categoryName = '';
563 if (categoryHash != 0)
564 categoryName = category_list[categoryHash].name;
565 const hashes = torrentsTable.selectedRowsIds();
566 if (hashes.length) {
567 new Request({
568 url: 'api/v2/torrents/setCategory',
569 method: 'post',
570 data: {
571 hashes: hashes.join("|"),
572 category: categoryName
574 }).send();
578 createCategoryFN = function() {
579 const action = "create";
580 new MochaUI.Window({
581 id: 'newCategoryPage',
582 title: "QBT_TR(New Category)QBT_TR[CONTEXT=CategoryFilterWidget]",
583 loadMethod: 'iframe',
584 contentURL: 'newcategory.html?action=' + action,
585 scrollbars: false,
586 resizable: false,
587 maximizable: false,
588 paddingVertical: 0,
589 paddingHorizontal: 0,
590 width: 250,
591 height: 150
593 updateMainData();
596 editCategoryFN = function(categoryHash) {
597 const action = "edit";
598 const categoryName = category_list[categoryHash].name;
599 const savePath = category_list[categoryHash].savePath;
600 new MochaUI.Window({
601 id: 'editCategoryPage',
602 title: "QBT_TR(Edit Category)QBT_TR[CONTEXT=TransferListWidget]",
603 loadMethod: 'iframe',
604 contentURL: 'newcategory.html?action=' + action + '&categoryName=' + categoryName + '&savePath=' + savePath,
605 scrollbars: false,
606 resizable: false,
607 maximizable: false,
608 paddingVertical: 0,
609 paddingHorizontal: 0,
610 width: 250,
611 height: 150
613 updateMainData();
616 removeCategoryFN = function(categoryHash) {
617 const categoryName = category_list[categoryHash].name;
618 new Request({
619 url: 'api/v2/torrents/removeCategories',
620 method: 'post',
621 data: {
622 categories: categoryName
624 }).send();
625 setCategoryFilter(CATEGORIES_ALL);
628 deleteUnusedCategoriesFN = function() {
629 const categories = [];
630 for (const hash in category_list) {
631 if (torrentsTable.getFilteredTorrentsNumber('all', hash, TAGS_ALL) === 0)
632 categories.push(category_list[hash].name);
634 new Request({
635 url: 'api/v2/torrents/removeCategories',
636 method: 'post',
637 data: {
638 categories: categories.join('\n')
640 }).send();
641 setCategoryFilter(CATEGORIES_ALL);
644 startTorrentsByCategoryFN = function(categoryHash) {
645 const hashes = torrentsTable.getFilteredTorrentsHashes('all', categoryHash, TAGS_ALL);
646 if (hashes.length) {
647 new Request({
648 url: 'api/v2/torrents/resume',
649 method: 'post',
650 data: {
651 hashes: hashes.join("|")
653 }).send();
654 updateMainData();
658 pauseTorrentsByCategoryFN = function(categoryHash) {
659 const hashes = torrentsTable.getFilteredTorrentsHashes('all', categoryHash, TAGS_ALL);
660 if (hashes.length) {
661 new Request({
662 url: 'api/v2/torrents/pause',
663 method: 'post',
664 data: {
665 hashes: hashes.join("|")
667 }).send();
668 updateMainData();
672 deleteTorrentsByCategoryFN = function(categoryHash) {
673 const hashes = torrentsTable.getFilteredTorrentsHashes('all', categoryHash, TAGS_ALL);
674 if (hashes.length) {
675 new MochaUI.Window({
676 id: 'confirmDeletionPage',
677 title: "QBT_TR(Deletion confirmation)QBT_TR[CONTEXT=confirmDeletionDlg]",
678 loadMethod: 'iframe',
679 contentURL: 'confirmdeletion.html?hashes=' + hashes.join("|"),
680 scrollbars: false,
681 resizable: false,
682 maximizable: false,
683 padding: 10,
684 width: 424,
685 height: 140
687 updateMainData();
691 torrentAddTagsFN = function() {
692 const action = "set";
693 const hashes = torrentsTable.selectedRowsIds();
694 if (hashes.length) {
695 new MochaUI.Window({
696 id: 'newTagPage',
697 title: "QBT_TR(Add Tags)QBT_TR[CONTEXT=TransferListWidget]",
698 loadMethod: 'iframe',
699 contentURL: 'newtag.html?action=' + action + '&hashes=' + hashes.join('|'),
700 scrollbars: false,
701 resizable: false,
702 maximizable: false,
703 paddingVertical: 0,
704 paddingHorizontal: 0,
705 width: 250,
706 height: 100
711 torrentSetTagsFN = function(tagHash, isSet) {
712 const tagName = ((tagHash === '0') ? '' : tagList[tagHash].name);
713 const hashes = torrentsTable.selectedRowsIds();
714 if (hashes.length) {
715 new Request({
716 url: (isSet ? 'api/v2/torrents/addTags' : 'api/v2/torrents/removeTags'),
717 method: 'post',
718 data: {
719 hashes: hashes.join("|"),
720 tags: tagName,
722 }).send();
726 torrentRemoveAllTagsFN = function() {
727 const hashes = torrentsTable.selectedRowsIds();
728 if (hashes.length) {
729 new Request({
730 url: ('api/v2/torrents/removeTags'),
731 method: 'post',
732 data: {
733 hashes: hashes.join("|"),
735 }).send();
739 createTagFN = function() {
740 const action = "create";
741 new MochaUI.Window({
742 id: 'newTagPage',
743 title: "QBT_TR(New Tag)QBT_TR[CONTEXT=TagFilterWidget]",
744 loadMethod: 'iframe',
745 contentURL: 'newtag.html?action=' + action,
746 scrollbars: false,
747 resizable: false,
748 maximizable: false,
749 paddingVertical: 0,
750 paddingHorizontal: 0,
751 width: 250,
752 height: 100
754 updateMainData();
757 removeTagFN = function(tagHash) {
758 const tagName = tagList[tagHash].name;
759 new Request({
760 url: 'api/v2/torrents/deleteTags',
761 method: 'post',
762 data: {
763 tags: tagName
765 }).send();
766 setTagFilter(TAGS_ALL);
769 deleteUnusedTagsFN = function() {
770 const tags = [];
771 for (const hash in tagList) {
772 if (torrentsTable.getFilteredTorrentsNumber('all', CATEGORIES_ALL, hash) === 0)
773 tags.push(tagList[hash].name);
775 new Request({
776 url: 'api/v2/torrents/deleteTags',
777 method: 'post',
778 data: {
779 tags: tags.join(',')
781 }).send();
782 setTagFilter(TAGS_ALL);
785 startTorrentsByTagFN = function(tagHash) {
786 const hashes = torrentsTable.getFilteredTorrentsHashes('all', CATEGORIES_ALL, tagHash);
787 if (hashes.length) {
788 new Request({
789 url: 'api/v2/torrents/resume',
790 method: 'post',
791 data: {
792 hashes: hashes.join("|")
794 }).send();
795 updateMainData();
799 pauseTorrentsByTagFN = function(tagHash) {
800 const hashes = torrentsTable.getFilteredTorrentsHashes('all', CATEGORIES_ALL, tagHash);
801 if (hashes.length) {
802 new Request({
803 url: 'api/v2/torrents/pause',
804 method: 'post',
805 data: {
806 hashes: hashes.join("|")
808 }).send();
809 updateMainData();
813 deleteTorrentsByTagFN = function(tagHash) {
814 const hashes = torrentsTable.getFilteredTorrentsHashes('all', CATEGORIES_ALL, tagHash);
815 if (hashes.length) {
816 new MochaUI.Window({
817 id: 'confirmDeletionPage',
818 title: "QBT_TR(Deletion confirmation)QBT_TR[CONTEXT=confirmDeletionDlg]",
819 loadMethod: 'iframe',
820 contentURL: 'confirmdeletion.html?hashes=' + hashes.join("|"),
821 scrollbars: false,
822 resizable: false,
823 maximizable: false,
824 padding: 10,
825 width: 424,
826 height: 140
828 updateMainData();
832 copyNameFN = function() {
833 const selectedRows = torrentsTable.selectedRowsIds();
834 const names = [];
835 if (selectedRows.length) {
836 const rows = torrentsTable.getFilteredAndSortedRows();
837 for (let i = 0; i < selectedRows.length; ++i) {
838 const hash = selectedRows[i];
839 names.push(rows[hash].full_data.name);
842 return names.join("\n");
845 copyMagnetLinkFN = function() {
846 const selectedRows = torrentsTable.selectedRowsIds();
847 const magnets = [];
848 if (selectedRows.length) {
849 const rows = torrentsTable.getFilteredAndSortedRows();
850 for (let i = 0; i < selectedRows.length; ++i) {
851 const hash = selectedRows[i];
852 magnets.push(rows[hash].full_data.magnet_uri);
855 return magnets.join("\n");
858 copyHashFN = function() {
859 return torrentsTable.selectedRowsIds().join("\n");
862 ['pause', 'resume'].each(function(item) {
863 addClickEvent(item + 'All', function(e) {
864 new Event(e).stop();
865 new Request({
866 url: 'api/v2/torrents/' + item,
867 method: 'post',
868 data: {
869 hashes: "all"
871 }).send();
872 updateMainData();
876 ['pause', 'resume', 'recheck'].each(function(item) {
877 addClickEvent(item, function(e) {
878 new Event(e).stop();
879 const hashes = torrentsTable.selectedRowsIds();
880 if (hashes.length) {
881 hashes.each(function(hash, index) {
882 new Request({
883 url: 'api/v2/torrents/' + item,
884 method: 'post',
885 data: {
886 hashes: hash
888 }).send();
890 updateMainData();
895 ['decreasePrio', 'increasePrio', 'topPrio', 'bottomPrio'].each(function(item) {
896 addClickEvent(item, function(e) {
897 new Event(e).stop();
898 setQueuePositionFN(item);
902 setQueuePositionFN = function(cmd) {
903 const hashes = torrentsTable.selectedRowsIds();
904 if (hashes.length) {
905 new Request({
906 url: 'api/v2/torrents/' + cmd,
907 method: 'post',
908 data: {
909 hashes: hashes.join("|")
911 }).send();
912 updateMainData();
916 addClickEvent('about', function(e) {
917 new Event(e).stop();
918 const id = 'aboutpage';
919 new MochaUI.Window({
920 id: id,
921 title: 'QBT_TR(About qBittorrent)QBT_TR[CONTEXT=AboutDialog]',
922 loadMethod: 'xhr',
923 contentURL: 'views/about.html',
924 require: {
925 css: ['css/Tabs.css']
927 toolbar: true,
928 toolbarURL: 'views/aboutToolbar.html',
929 padding: 10,
930 width: loadWindowWidth(id, 550),
931 height: loadWindowHeight(id, 360),
932 onResize: function() {
933 saveWindowSize(id);
938 addClickEvent('logout', function(e) {
939 new Event(e).stop();
940 new Request({
941 url: 'api/v2/auth/logout',
942 method: 'post',
943 onSuccess: function() {
944 window.location.reload(true);
946 }).send();
949 addClickEvent('shutdown', function(e) {
950 new Event(e).stop();
951 if (confirm('QBT_TR(Are you sure you want to quit qBittorrent?)QBT_TR[CONTEXT=MainWindow]')) {
952 new Request({
953 url: 'api/v2/app/shutdown',
954 onSuccess: function() {
955 document.write('<!doctype html><html lang="${LANG}"><head> <meta charset="utf-8"> <title>QBT_TR(qBittorrent has been shutdown)QBT_TR[CONTEXT=HttpServer]</title></head><body> <h1 style="text-align: center;">QBT_TR(qBittorrent has been shutdown)QBT_TR[CONTEXT=HttpServer]</h1></body></html>');
956 stop();
958 }).send();
962 // Deactivate menu header links
963 $$('a.returnFalse').each(function(el) {
964 el.addEvent('click', function(e) {
965 new Event(e).stop();