Browse Source

Merge pull request #10527 from fusioneer-GitHub/webui_tags

Implement tag management for WebUI
adaptive-webui-19844
Mike Tzou 5 years ago committed by GitHub
parent
commit
cf47342cec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/webui/api/synccontroller.cpp
  2. 64
      src/webui/api/torrentscontroller.cpp
  3. 5
      src/webui/api/torrentscontroller.h
  4. 2
      src/webui/www/private/addtrackers.html
  5. 6
      src/webui/www/private/confirmdeletion.html
  6. 5
      src/webui/www/private/css/style.css
  7. 6
      src/webui/www/private/download.html
  8. 6
      src/webui/www/private/downloadlimit.html
  9. 6
      src/webui/www/private/edittracker.html
  10. 44
      src/webui/www/private/filters.html
  11. 12
      src/webui/www/private/index.html
  12. 8
      src/webui/www/private/installsearchplugin.html
  13. 14
      src/webui/www/private/newcategory.html
  14. 105
      src/webui/www/private/newtag.html
  15. 244
      src/webui/www/private/preferences_content.html
  16. 2
      src/webui/www/private/properties_content.html
  17. 6
      src/webui/www/private/rename.html
  18. 338
      src/webui/www/private/scripts/client.js
  19. 158
      src/webui/www/private/scripts/contextmenu.js
  20. 32
      src/webui/www/private/scripts/download.js
  21. 440
      src/webui/www/private/scripts/dynamicTable.js
  22. 24
      src/webui/www/private/scripts/misc.js
  23. 352
      src/webui/www/private/scripts/mocha-init.js
  24. 14
      src/webui/www/private/scripts/progressbar.js
  25. 124
      src/webui/www/private/scripts/prop-files.js
  26. 14
      src/webui/www/private/scripts/prop-general.js
  27. 16
      src/webui/www/private/scripts/prop-peers.js
  28. 36
      src/webui/www/private/scripts/prop-trackers.js
  29. 34
      src/webui/www/private/scripts/prop-webseeds.js
  30. 40
      src/webui/www/private/scripts/speedslider.js
  31. 148
      src/webui/www/private/search.html
  32. 48
      src/webui/www/private/searchplugins.html
  33. 6
      src/webui/www/private/setlocation.html
  34. 30
      src/webui/www/private/shareratio.html
  35. 2
      src/webui/www/private/transferlist.html
  36. 2
      src/webui/www/private/upload.html
  37. 6
      src/webui/www/private/uploadlimit.html
  38. 10
      src/webui/www/public/scripts/login.js
  39. 1
      src/webui/www/webui.qrc

6
src/webui/api/synccontroller.cpp

@ -445,6 +445,12 @@ void SyncController::maindataAction() @@ -445,6 +445,12 @@ void SyncController::maindataAction()
data["categories"] = categories;
QVariantList tags;
for (const QString &tag : asConst(session->tags()))
tags << tag;
data["tags"] = tags;
QVariantMap serverState = getTranserInfo();
serverState[KEY_TRANSFER_FREESPACEONDISK] = getFreeDiskSpace();
serverState[KEY_SYNC_MAINDATA_QUEUEING] = session->isQueueingSystemEnabled();

64
src/webui/api/torrentscontroller.cpp

@ -1041,3 +1041,67 @@ void TorrentsController::categoriesAction() @@ -1041,3 +1041,67 @@ void TorrentsController::categoriesAction()
setResult(categories);
}
void TorrentsController::addTagsAction()
{
checkParams({"hashes", "tags"});
const QStringList hashes {params()["hashes"].split('|')};
const QStringList tags {params()["tags"].split(',', QString::SkipEmptyParts)};
for (const QString &tag : tags) {
const QString tagTrimmed {tag.trimmed()};
applyToTorrents(hashes, [&tagTrimmed](BitTorrent::TorrentHandle *const torrent)
{
torrent->addTag(tagTrimmed);
});
}
}
void TorrentsController::removeTagsAction()
{
checkParams({"hashes"});
const QStringList hashes {params()["hashes"].split('|')};
const QStringList tags {params()["tags"].split(',', QString::SkipEmptyParts)};
for (const QString &tag : tags) {
const QString tagTrimmed {tag.trimmed()};
applyToTorrents(hashes, [&tagTrimmed](BitTorrent::TorrentHandle *const torrent)
{
torrent->removeTag(tagTrimmed);
});
}
if (tags.isEmpty()) {
applyToTorrents(hashes, [](BitTorrent::TorrentHandle *const torrent)
{
torrent->removeAllTags();
});
}
}
void TorrentsController::createTagsAction()
{
checkParams({"tags"});
const QStringList tags {params()["tags"].split(',', QString::SkipEmptyParts)};
for (const QString &tag : tags)
BitTorrent::Session::instance()->addTag(tag.trimmed());
}
void TorrentsController::deleteTagsAction()
{
checkParams({"tags"});
const QStringList tags {params()["tags"].split(',', QString::SkipEmptyParts)};
for (const QString &tag : tags)
BitTorrent::Session::instance()->removeTag(tag.trimmed());
}
void TorrentsController::tagsAction()
{
const QStringList tags = BitTorrent::Session::instance()->tags().toList();
setResult(QJsonArray::fromStringList(tags));
}

5
src/webui/api/torrentscontroller.h

@ -56,6 +56,11 @@ private slots: @@ -56,6 +56,11 @@ private slots:
void editCategoryAction();
void removeCategoriesAction();
void categoriesAction();
void addTagsAction();
void removeTagsAction();
void createTagsAction();
void deleteTagsAction();
void tagsAction();
void addAction();
void deleteAction();
void addTrackersAction();

2
src/webui/www/private/addtrackers.html

@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
$('trackersUrls').focus();
$('addTrackersButton').addEvent('click', function(e) {
new Event(e).stop();
var hash = new URI().getData('hash');
const hash = new URI().getData('hash');
new Request({
url: 'api/v2/torrents/addTrackers',
method: 'post',

6
src/webui/www/private/confirmdeletion.html

@ -10,8 +10,8 @@ @@ -10,8 +10,8 @@
<script>
'use strict';
var hashes = new URI().getData('hashes').split('|');
window.addEvent('domready', function() {
const hashes = new URI().getData('hashes').split('|');
$('cancelBtn').focus();
$('cancelBtn').addEvent('click', function(e) {
new Event(e).stop();
@ -20,8 +20,8 @@ @@ -20,8 +20,8 @@
$('confirmBtn').addEvent('click', function(e) {
parent.torrentsTable.deselectAll();
new Event(e).stop();
var cmd = 'api/v2/torrents/delete';
var deleteFiles = $('deleteFromDiskCB').get('checked');
const cmd = 'api/v2/torrents/delete';
const deleteFiles = $('deleteFromDiskCB').get('checked');
new Request({
url: cmd,
method: 'post',

5
src/webui/www/private/css/style.css

@ -258,6 +258,11 @@ a.propButton img { @@ -258,6 +258,11 @@ a.propButton img {
-ms-interpolation-mode: bicubic;
}
.contextMenu li input[type=checkbox] {
position: relative;
top: 3px;
}
/* Sliders */
.slider {

6
src/webui/www/private/download.html

@ -140,9 +140,9 @@ @@ -140,9 +140,9 @@
<script>
'use strict';
var encodedUrls = new URI().getData('urls');
const encodedUrls = new URI().getData('urls');
if (encodedUrls) {
var urls = [];
const urls = [];
encodedUrls.split('|').each(function(url) {
urls.push(decodeURIComponent(url));
});
@ -151,7 +151,7 @@ @@ -151,7 +151,7 @@
$('urls').set('value', urls.join("\n"));
}
var submitted = false;
let submitted = false;
$('downloadForm').addEventListener("submit", function() {
$('startTorrentHidden').value = $('startTorrent').checked ? 'false' : 'true';

6
src/webui/www/private/downloadlimit.html

@ -24,9 +24,9 @@ @@ -24,9 +24,9 @@
<script>
'use strict';
var hashes = new URI().getData('hashes').split('|');
var setDlLimit = function() {
var limit = $("dllimitUpdatevalue").value.toInt() * 1024;
const hashes = new URI().getData('hashes').split('|');
const setDlLimit = function() {
const limit = $("dllimitUpdatevalue").value.toInt() * 1024;
if (hashes[0] == "global") {
new Request({
url: 'api/v2/transfer/setDownloadLimit',

6
src/webui/www/private/edittracker.html

@ -29,17 +29,17 @@ @@ -29,17 +29,17 @@
}
}).activate();
var currentUrl = new URI().getData('url');
const currentUrl = new URI().getData('url');
if (!currentUrl)
return false;
var decodedUrl = decodeURIComponent(currentUrl);
const decodedUrl = decodeURIComponent(currentUrl);
$('trackerUrl').value = decodedUrl;
$('trackerUrl').focus();
$('editTrackerButton').addEvent('click', function(e) {
new Event(e).stop();
var hash = new URI().getData('hash');
const hash = new URI().getData('hash');
new Request({
url: 'api/v2/torrents/editTracker',
method: 'post',

44
src/webui/www/private/filters.html

@ -21,11 +21,18 @@ @@ -21,11 +21,18 @@
<ul class="filterList" id="categoryFilterList">
</ul>
</div>
<div class="filterWrapper">
<span class="filterTitle" onclick="toggleFilterDisplay('tag');">
<img src="images/qbt-theme/go-down.svg">QBT_TR(Tags)QBT_TR[CONTEXT=TransferListFiltersWidget]
</span>
<ul class="filterList" id="tagFilterList">
</ul>
</div>
<script>
'use strict';
var categoriesFilterContextMenu = new CategoriesFilterContextMenu({
const categoriesFilterContextMenu = new CategoriesFilterContextMenu({
targets: '.categoriesFilterContextMenuTarget',
menu: 'categoriesFilterMenu',
actions: {
@ -60,9 +67,44 @@ @@ -60,9 +67,44 @@
}
});
const tagsFilterContextMenu = new TagsFilterContextMenu({
targets: '.tagsFilterContextMenuTarget',
menu: 'tagsFilterMenu',
actions: {
createTag: function(element, ref) {
createTagFN();
},
deleteTag: function(element, ref) {
removeTagFN(element.id);
},
deleteUnusedTags: function(element, ref) {
deleteUnusedTagsFN();
},
startTorrentsByTag: function(element, ref) {
startTorrentsByTagFN(element.id);
},
pauseTorrentsByTag: function(element, ref) {
pauseTorrentsByTagFN(element.id);
},
deleteTorrentsByTag: function(element, ref) {
deleteTorrentsByTagFN(element.id);
}
},
offsets: {
x: -15,
y: 2
},
onShow: function() {
this.options.element.firstChild.click();
}
});
if (localStorage.getItem('filter_status_collapsed') === "true")
toggleFilterDisplay('status');
if (localStorage.getItem('filter_category_collapsed') === "true")
toggleFilterDisplay('category');
if (localStorage.getItem('filter_tag_collapsed') === "true")
toggleFilterDisplay('tag');
</script>

12
src/webui/www/private/index.html

@ -132,6 +132,10 @@ @@ -132,6 +132,10 @@
<a href="#Category" class="arrow-right"><img src="images/qbt-theme/view-categories.svg" alt="QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget]</a>
<ul id="contextCategoryList" class="scrollableMenu"></ul>
</li>
<li>
<a href="#Tags" class="arrow-right"><img src="images/qbt-theme/view-categories.svg" alt="QBT_TR(Tags)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Tags)QBT_TR[CONTEXT=TransferListWidget]</a>
<ul id="contextTagList" class="scrollableMenu"></ul>
</li>
<li>
<a href="#autoTorrentManagement"><img src="images/qbt-theme/checked.svg" alt="QBT_TR(Automatic Torrent Management)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Automatic Torrent Management)QBT_TR[CONTEXT=TransferListWidget]</a>
</li>
@ -170,6 +174,14 @@ @@ -170,6 +174,14 @@
<li><a href="#pauseTorrentsByCategory"><img src="images/qbt-theme/media-playback-pause.svg" alt="QBT_TR(Pause torrents)QBT_TR[CONTEXT=CategoryFilterWidget]"/> QBT_TR(Pause torrents)QBT_TR[CONTEXT=CategoryFilterWidget]</a></li>
<li><a href="#deleteTorrentsByCategory"><img src="images/qbt-theme/edit-delete.svg" alt="QBT_TR(Delete torrents)QBT_TR[CONTEXT=CategoryFilterWidget]"/> QBT_TR(Delete torrents)QBT_TR[CONTEXT=CategoryFilterWidget]</a></li>
</ul>
<ul id="tagsFilterMenu" class="contextMenu">
<li><a href="#createTag"><img src="images/qbt-theme/list-add.svg" alt="QBT_TR(Add tag...)QBT_TR[CONTEXT=TagFilterWidget]"/> QBT_TR(Add tag...)QBT_TR[CONTEXT=TagFilterWidget]</a></li>
<li><a href="#deleteTag"><img src="images/qbt-theme/list-remove.svg" alt="QBT_TR(Remove tag)QBT_TR[CONTEXT=TagFilterWidget]"/> QBT_TR(Remove tag)QBT_TR[CONTEXT=TagFilterWidget]</a></li>
<li><a href="#deleteUnusedTags"><img src="images/qbt-theme/list-remove.svg" alt="QBT_TR(Remove unused tags)QBT_TR[CONTEXT=TagFilterWidget]"/> QBT_TR(Remove unused tags)QBT_TR[CONTEXT=TagFilterWidget]</a></li>
<li class="separator"><a href="#startTorrentsByTag"><img src="images/qbt-theme/media-playback-start.svg" alt="QBT_TR(Resume torrents)QBT_TR[CONTEXT=TagFilterWidget]"/> QBT_TR(Resume torrents)QBT_TR[CONTEXT=TagFilterWidget]</a></li>
<li><a href="#pauseTorrentsByTag"><img src="images/qbt-theme/media-playback-pause.svg" alt="QBT_TR(Pause torrents)QBT_TR[CONTEXT=TagFilterWidget]"/> QBT_TR(Pause torrents)QBT_TR[CONTEXT=TagFilterWidget]</a></li>
<li><a href="#deleteTorrentsByTag"><img src="images/qbt-theme/edit-delete.svg" alt="QBT_TR(Delete torrents)QBT_TR[CONTEXT=TagFilterWidget]"/> QBT_TR(Delete torrents)QBT_TR[CONTEXT=TagFilterWidget]</a></li>
</ul>
<ul id="torrentTrackersMenu" class="contextMenu">
<li><a href="#AddTracker"><img src="images/qbt-theme/list-add.svg" alt="QBT_TR(Add a new tracker...)QBT_TR[CONTEXT=TrackerListWidget]"/> QBT_TR(Add a new tracker...)QBT_TR[CONTEXT=TrackerListWidget]</a></li>
<li class="separator"><a href="#EditTracker"><img src="images/qbt-theme/document-edit.svg" alt="QBT_TR(Edit tracker URL...)QBT_TR[CONTEXT=TrackerListWidget]"/> QBT_TR(Edit tracker URL...)QBT_TR[CONTEXT=TrackerListWidget]</a></li>

8
src/webui/www/private/installsearchplugin.html

@ -29,7 +29,7 @@ @@ -29,7 +29,7 @@
<script>
'use strict';
var initInstallSearchPlugin = function() {
this.initInstallSearchPlugin = function() {
new Keyboard({
defaultEventType: 'keydown',
events: {
@ -37,7 +37,7 @@ @@ -37,7 +37,7 @@
// accept enter key as a click
new Event(e).stop();
var elem = e.event.srcElement;
const elem = e.event.srcElement;
if ((elem.id === "newPluginPath") || (elem.id === "newPluginOk"))
newPluginOk();
else if (elem.id === "newPluginCancel")
@ -49,8 +49,8 @@ @@ -49,8 +49,8 @@
$('newPluginPath').select();
};
var newPluginOk = function() {
var path = $("newPluginPath").get("value").trim();
this.newPluginOk = function() {
const path = $("newPluginPath").get("value").trim();
if (path)
new Request({
url: 'api/v2/search/installPlugin',

14
src/webui/www/private/newcategory.html

@ -30,10 +30,10 @@ @@ -30,10 +30,10 @@
}).activate();
window.addEvent('domready', function() {
var uriAction = safeTrim(new URI().getData('action'));
var uriHashes = safeTrim(new URI().getData('hashes'));
var uriCategoryName = safeTrim(new URI().getData('categoryName'));
var uriSavePath = safeTrim(new URI().getData('savePath'));
const uriAction = safeTrim(new URI().getData('action'));
const uriHashes = safeTrim(new URI().getData('hashes'));
const uriCategoryName = safeTrim(new URI().getData('categoryName'));
const uriSavePath = safeTrim(new URI().getData('savePath'));
if (uriAction === "edit") {
if (!uriCategoryName)
@ -51,10 +51,10 @@ @@ -51,10 +51,10 @@
$('categoryNameButton').addEvent('click', function(e) {
new Event(e).stop();
var savePath = $('savePath').value.trim();
var categoryName = $('categoryName').value.trim();
const savePath = $('savePath').value.trim();
const categoryName = $('categoryName').value.trim();
var verifyCategoryName = function(name) {
const verifyCategoryName = function(name) {
if ((name === null) || (name === ""))
return false;
if (name.match("^([^\\\\\\/]|[^\\\\\\/]([^\\\\\\/]|\\/(?=[^\\/]))*[^\\\\\\/])$") === null) {

105
src/webui/www/private/newtag.html

@ -0,0 +1,105 @@ @@ -0,0 +1,105 @@
<!DOCTYPE html>
<html lang="${LANG}">
<head>
<meta charset="UTF-8" />
<title>QBT_TR(Add Tags)QBT_TR[CONTEXT=TransferListWidget]</title>
<link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css" />
<script src="scripts/lib/mootools-1.2-core-yc.js"></script>
<script src="scripts/lib/mootools-1.2-more.js"></script>
<script src="scripts/misc.js?locale=${LANG}&v=${CACHEID}"></script>
<script>
'use strict';
new Keyboard({
defaultEventType: 'keydown',
events: {
'Enter': function(event) {
$('tagNameButton').click();
event.preventDefault();
},
'Escape': function(event) {
window.parent.closeWindows();
event.preventDefault();
},
'Esc': function(event) {
window.parent.closeWindows();
event.preventDefault();
}
}
}).activate();
window.addEvent('domready', function() {
const uriAction = safeTrim(new URI().getData('action'));
const uriHashes = safeTrim(new URI().getData('hashes'));
if (uriAction === 'create')
$('legendText').innerText = 'QBT_TR(Tag:)QBT_TR[CONTEXT=TagFilterWidget]';
$('tagName').focus();
$('tagNameButton').addEvent('click', function(e) {
new Event(e).stop();
const tagName = $('tagName').value.trim();
const verifyTagName = function(name) {
if ((name === null) || (name === ""))
return false;
if (name.indexOf(",") >= 0) {
alert("QBT_TR(Invalid tag name)QBT_TR[CONTEXT=TagFilterWidget]");
return false;
}
return true;
};
switch (uriAction) {
case "set":
if (uriHashes === "")
return;
new Request({
url: 'api/v2/torrents/addTags',
method: 'post',
data: {
hashes: uriHashes,
tags: tagName,
},
onComplete: function() {
window.parent.closeWindows();
}
}).send();
break;
case "create":
if (!verifyTagName(tagName))
return;
new Request({
url: 'api/v2/torrents/createTags',
method: 'post',
data: {
tags: tagName,
},
onComplete: function() {
window.parent.closeWindows();
}
}).send();
break;
}
});
});
</script>
</head>
<body>
<div style="padding: 10px 10px 0px 10px;">
<p id="legendText" style="font-weight: bold;">QBT_TR(Comma-separated tags:)QBT_TR[CONTEXT=TransferListWidget]</p>
<input type="text" id="tagName" value="" maxlength="100" style="width: 220px;" />
<div style="text-align: center; padding-top: 10px;">
<input type="button" value="QBT_TR(Add)QBT_TR[CONTEXT=HttpServer]" id="tagNameButton" />
</div>
</div>
</body>
</html>

244
src/webui/www/private/preferences_content.html

@ -1084,34 +1084,34 @@ @@ -1084,34 +1084,34 @@
'use strict';
// Downloads tab
var WatchedFoldersTable = new HtmlTable($("watched_folders_tab"));
this.WatchedFoldersTable = new HtmlTable($("watched_folders_tab"));
var updateTempDirEnabled = function() {
var isTempDirEnabled = $('temppath_checkbox').getProperty('checked');
this.updateTempDirEnabled = function() {
const isTempDirEnabled = $('temppath_checkbox').getProperty('checked');
$('temppath_text').setProperty('disabled', !isTempDirEnabled);
};
var addWatchFolder = function() {
var new_folder = $('new_watch_folder_txt').getProperty('value').trim();
this.addWatchFolder = function() {
const new_folder = $('new_watch_folder_txt').getProperty('value').trim();
if (new_folder.length <= 0) return;
var new_other = $('new_watch_folder_other_txt').getProperty('value').trim();
const new_other = $('new_watch_folder_other_txt').getProperty('value').trim();
if (new_other.length <= 0) return;
var new_select = $('new_watch_folder_select').getProperty('value').trim();
const new_select = $('new_watch_folder_select').getProperty('value').trim();
var i = $('watched_folders_tab').getChildren('tbody')[0].getChildren('tr').length;
const i = $('watched_folders_tab').getChildren('tbody')[0].getChildren('tr').length;
pushWatchFolder(i, new_folder, new_select, new_other);
// Clear fields
$('new_watch_folder_txt').setProperty('value', '');
var elt = $('new_watch_folder_select');
const elt = $('new_watch_folder_select');
elt.setProperty('value', 'watch_folder');
var text = elt.options[elt.selectedIndex].innerHTML;
const text = elt.options[elt.selectedIndex].innerHTML;
$('new_watch_folder_other_txt').setProperty('value', text);
};
var changeWatchFolderSelect = function(item) {
this.changeWatchFolderSelect = function(item) {
if (item.value == "other") {
item.nextElementSibling.hidden = false;
item.nextElementSibling.value = 'QBT_TR(Type folder here)QBT_TR[CONTEXT=HttpServer]';
@ -1119,15 +1119,15 @@ @@ -1119,15 +1119,15 @@
}
else {
item.nextElementSibling.hidden = true;
var text = item.options[item.selectedIndex].innerHTML;
const text = item.options[item.selectedIndex].innerHTML;
item.nextElementSibling.value = text;
}
};
var pushWatchFolder = function(pos, folder, sel, other) {
var myinput = "<input id='text_watch_" + pos + "' type='text' value='" + folder + "'>";
var disableInput = (sel != "other");
var mycb = "<div class='select-watched-folder-editable'>"
this.pushWatchFolder = function(pos, folder, sel, other) {
const myinput = "<input id='text_watch_" + pos + "' type='text' value='" + folder + "'>";
const disableInput = (sel != "other");
const mycb = "<div class='select-watched-folder-editable'>"
+ "<select id ='cb_watch_" + pos + "' onchange='changeWatchFolderSelect(this)'>"
+ "<option value='watch_folder'>QBT_TR(Monitored folder)QBT_TR[CONTEXT=ScanFoldersModel]</option>"
+ "<option value='default_folder'>QBT_TR(Default save location)QBT_TR[CONTEXT=ScanFoldersModel]</option>"
@ -1138,20 +1138,20 @@ @@ -1138,20 +1138,20 @@
WatchedFoldersTable.push([myinput, mycb]);
$('cb_watch_' + pos).setProperty('value', sel);
if (disableInput) {
var elt = $('cb_watch_' + pos);
const elt = $('cb_watch_' + pos);
other = elt.options[elt.selectedIndex].innerHTML;
}
$('cb_watch_txt_' + pos).setProperty('value', other);
};
var getWatchedFolders = function() {
var nb_folders = $("watched_folders_tab").getChildren("tbody")[0].getChildren("tr").length;
var folders = new Hash();
for (var i = 0; i < nb_folders; ++i) {
var fpath = $('text_watch_' + i).getProperty('value').trim();
this.getWatchedFolders = function() {
const nb_folders = $("watched_folders_tab").getChildren("tbody")[0].getChildren("tr").length;
const folders = new Hash();
for (let i = 0; i < nb_folders; ++i) {
const fpath = $('text_watch_' + i).getProperty('value').trim();
if (fpath.length > 0) {
var other;
var sel = $('cb_watch_' + i).getProperty('value').trim();
let other;
const sel = $('cb_watch_' + i).getProperty('value').trim();
if (sel == "other") {
other = $('cb_watch_txt_' + i).getProperty('value').trim();
}
@ -1164,18 +1164,18 @@ @@ -1164,18 +1164,18 @@
return folders;
};
var updateExportDirEnabled = function() {
var isExportDirEnabled = $('exportdir_checkbox').getProperty('checked');
this.updateExportDirEnabled = function() {
const isExportDirEnabled = $('exportdir_checkbox').getProperty('checked');
$('exportdir_text').setProperty('disabled', !isExportDirEnabled);
};
var updateExportDirFinEnabled = function() {
var isExportDirFinEnabled = $('exportdirfin_checkbox').getProperty('checked');
this.updateExportDirFinEnabled = function() {
const isExportDirFinEnabled = $('exportdirfin_checkbox').getProperty('checked');
$('exportdirfin_text').setProperty('disabled', !isExportDirFinEnabled);
};
var updateMailNotification = function() {
var isMailNotificationEnabled = $('mail_notification_checkbox').getProperty('checked');
this.updateMailNotification = function() {
const isMailNotificationEnabled = $('mail_notification_checkbox').getProperty('checked');
$('src_email_txt').setProperty('disabled', !isMailNotificationEnabled);
$('dest_email_txt').setProperty('disabled', !isMailNotificationEnabled);
$('smtp_server_txt').setProperty('disabled', !isMailNotificationEnabled);
@ -1188,47 +1188,47 @@ @@ -1188,47 +1188,47 @@
}
};
var updateMailAuthSettings = function() {
var isMailAuthEnabled = $('mail_auth_checkbox').getProperty('checked');
this.updateMailAuthSettings = function() {
const isMailAuthEnabled = $('mail_auth_checkbox').getProperty('checked');
$('mail_username_text').setProperty('disabled', !isMailAuthEnabled);
$('mail_password_text').setProperty('disabled', !isMailAuthEnabled);
};
var updateAutoRun = function() {
var isAutoRunEnabled = $('autorun_checkbox').getProperty('checked');
this.updateAutoRun = function() {
const isAutoRunEnabled = $('autorun_checkbox').getProperty('checked');
$('autorunProg_txt').setProperty('disabled', !isAutoRunEnabled);
};
// Connection tab
var updateMaxConnecEnabled = function() {
var isMaxConnecEnabled = $('max_connec_checkbox').getProperty('checked');
this.updateMaxConnecEnabled = function() {
const isMaxConnecEnabled = $('max_connec_checkbox').getProperty('checked');
$('max_connec_value').setProperty('disabled', !isMaxConnecEnabled);
};
var updateMaxConnecPerTorrentEnabled = function() {
var isMaxConnecPerTorrentEnabled = $('max_connec_per_torrent_checkbox').getProperty('checked');
this.updateMaxConnecPerTorrentEnabled = function() {
const isMaxConnecPerTorrentEnabled = $('max_connec_per_torrent_checkbox').getProperty('checked');
$('max_connec_per_torrent_value').setProperty('disabled', !isMaxConnecPerTorrentEnabled);
};
var updateMaxUploadsEnabled = function() {
var isMaxUploadsEnabled = $('max_uploads_checkbox').getProperty('checked');
this.updateMaxUploadsEnabled = function() {
const isMaxUploadsEnabled = $('max_uploads_checkbox').getProperty('checked');
$('max_uploads_value').setProperty('disabled', !isMaxUploadsEnabled);
};
var updateMaxUploadsPerTorrentEnabled = function() {
var isMaxUploadsPerTorrentEnabled = $('max_uploads_per_torrent_checkbox').getProperty('checked');
this.updateMaxUploadsPerTorrentEnabled = function() {
const isMaxUploadsPerTorrentEnabled = $('max_uploads_per_torrent_checkbox').getProperty('checked');
$('max_uploads_per_torrent_value').setProperty('disabled', !isMaxUploadsPerTorrentEnabled);
};
var updatePeerProxySettings = function() {
var isPeerProxyTypeSelected = $('peer_proxy_type_select').getProperty('value') != "none";
this.updatePeerProxySettings = function() {
const isPeerProxyTypeSelected = $('peer_proxy_type_select').getProperty('value') != "none";
$('peer_proxy_host_text').setProperty('disabled', !isPeerProxyTypeSelected);
$('peer_proxy_port_value').setProperty('disabled', !isPeerProxyTypeSelected);
$('use_peer_proxy_checkbox').setProperty('disabled', !isPeerProxyTypeSelected);
$('proxy_only_for_torrents_checkbox').setProperty('disabled', !isPeerProxyTypeSelected);
if (isPeerProxyTypeSelected) {
var isPeerProxyTypeSocks5 = $('peer_proxy_type_select').getProperty('value') == "socks5";
const isPeerProxyTypeSocks5 = $('peer_proxy_type_select').getProperty('value') == "socks5";
$('peer_proxy_auth_checkbox').setProperty('disabled', !isPeerProxyTypeSocks5);
if (!isPeerProxyTypeSocks5) {
@ -1243,22 +1243,22 @@ @@ -1243,22 +1243,22 @@
}
};
var updatePeerProxyAuthSettings = function() {
var isPeerProxyAuthEnabled = $('peer_proxy_auth_checkbox').getProperty('checked');
this.updatePeerProxyAuthSettings = function() {
const isPeerProxyAuthEnabled = $('peer_proxy_auth_checkbox').getProperty('checked');
$('peer_proxy_username_text').setProperty('disabled', !isPeerProxyAuthEnabled);
$('peer_proxy_password_text').setProperty('disabled', !isPeerProxyAuthEnabled);
};
var updateFilterSettings = function() {
var isIPFilterEnabled = $('ipfilter_enabled_checkbox').getProperty('checked');
this.updateFilterSettings = function() {
const isIPFilterEnabled = $('ipfilter_enabled_checkbox').getProperty('checked');
$('ipfilter_text').setProperty('disabled', !isIPFilterEnabled);
$('ipfilter_trackers_checkbox').setProperty('disabled', !isIPFilterEnabled);
$('banned_IPs_textarea').setProperty('disabled', !isIPFilterEnabled);
};
// Speed tab
var updateSchedulingEnabled = function() {
var isLimitSchedulingEnabled = $('limit_sheduling_checkbox').getProperty('checked');
this.updateSchedulingEnabled = function() {
const isLimitSchedulingEnabled = $('limit_sheduling_checkbox').getProperty('checked');
$('schedule_from_hour').setProperty('disabled', !isLimitSchedulingEnabled);
$('schedule_from_min').setProperty('disabled', !isLimitSchedulingEnabled);
$('schedule_to_hour').setProperty('disabled', !isLimitSchedulingEnabled);
@ -1267,8 +1267,8 @@ @@ -1267,8 +1267,8 @@
};
// Bittorrent tab
var updateQueueingSystem = function() {
var isQueueingEnabled = $('queueing_checkbox').getProperty('checked');
this.updateQueueingSystem = function() {
const isQueueingEnabled = $('queueing_checkbox').getProperty('checked');
$('max_active_dl_value').setProperty('disabled', !isQueueingEnabled);
$('max_active_up_value').setProperty('disabled', !isQueueingEnabled);
$('max_active_to_value').setProperty('disabled', !isQueueingEnabled);
@ -1276,59 +1276,59 @@ @@ -1276,59 +1276,59 @@
updateSlowTorrentsSettings();
};
var updateSlowTorrentsSettings = function() {
var isDontCountSlowTorrentsEnabled = (!$('dont_count_slow_torrents_checkbox').getProperty('disabled')) && $('dont_count_slow_torrents_checkbox').getProperty('checked');
this.updateSlowTorrentsSettings = function() {
const isDontCountSlowTorrentsEnabled = (!$('dont_count_slow_torrents_checkbox').getProperty('disabled')) && $('dont_count_slow_torrents_checkbox').getProperty('checked');
$('dl_rate_threshold').setProperty('disabled', !isDontCountSlowTorrentsEnabled);
$('ul_rate_threshold').setProperty('disabled', !isDontCountSlowTorrentsEnabled);
$('torrent_inactive_timer').setProperty('disabled', !isDontCountSlowTorrentsEnabled);
};
var updateMaxRatioTimeEnabled = function() {
var isMaxRatioEnabled = $('max_ratio_checkbox').getProperty('checked');
this.updateMaxRatioTimeEnabled = function() {
const isMaxRatioEnabled = $('max_ratio_checkbox').getProperty('checked');
$('max_ratio_value').setProperty('disabled', !isMaxRatioEnabled);
var isMaxSeedingTimeEnabled = $('max_seeding_time_checkbox').getProperty('checked');
const isMaxSeedingTimeEnabled = $('max_seeding_time_checkbox').getProperty('checked');
$('max_seeding_time_value').setProperty('disabled', !isMaxSeedingTimeEnabled);
$('max_ratio_act').setProperty('disabled', !(isMaxRatioEnabled || isMaxSeedingTimeEnabled));
};
var updateAddTrackersEnabled = function() {
var isAddTrackersEnabled = $('add_trackers_checkbox').getProperty('checked');
this.updateAddTrackersEnabled = function() {
const isAddTrackersEnabled = $('add_trackers_checkbox').getProperty('checked');
$('add_trackers_textarea').setProperty('disabled', !isAddTrackersEnabled);
};
// Web UI tab
var updateHttpsSettings = function() {
var isUseHttpsEnabled = $('use_https_checkbox').getProperty('checked');
this.updateHttpsSettings = function() {
const isUseHttpsEnabled = $('use_https_checkbox').getProperty('checked');
$('ssl_cert_text').setProperty('disabled', !isUseHttpsEnabled);
$('ssl_key_text').setProperty('disabled', !isUseHttpsEnabled);
};
var updateBypasssAuthSettings = function() {
var isBypassAuthSubnetWhitelistEnabled = $('bypass_auth_subnet_whitelist_checkbox').getProperty('checked');
this.updateBypasssAuthSettings = function() {
const isBypassAuthSubnetWhitelistEnabled = $('bypass_auth_subnet_whitelist_checkbox').getProperty('checked');
$('bypass_auth_subnet_whitelist_textarea').setProperty('disabled', !isBypassAuthSubnetWhitelistEnabled);
};
var updateAlternativeWebUISettings = function() {
var isUseAlternativeWebUIEnabled = $('use_alt_webui_checkbox').getProperty('checked');
this.updateAlternativeWebUISettings = function() {
const isUseAlternativeWebUIEnabled = $('use_alt_webui_checkbox').getProperty('checked');
$('webui_files_location_textarea').setProperty('disabled', !isUseAlternativeWebUIEnabled);
};
var updateHostHeaderValidationSettings = function() {
var isHostHeaderValidationEnabled = $('host_header_validation_checkbox').getProperty('checked');
this.updateHostHeaderValidationSettings = function() {
const isHostHeaderValidationEnabled = $('host_header_validation_checkbox').getProperty('checked');
$('webui_domain_textarea').setProperty('disabled', !isHostHeaderValidationEnabled);
};
var updateDynDnsSettings = function() {
var isDynDnsEnabled = $('use_dyndns_checkbox').getProperty('checked');
this.updateDynDnsSettings = function() {
const isDynDnsEnabled = $('use_dyndns_checkbox').getProperty('checked');
$('dyndns_select').setProperty('disabled', !isDynDnsEnabled);
$('dyndns_domain_text').setProperty('disabled', !isDynDnsEnabled);
$('dyndns_username_text').setProperty('disabled', !isDynDnsEnabled);
$('dyndns_password_text').setProperty('disabled', !isDynDnsEnabled);
};
var registerDynDns = function() {
this.registerDynDns = function() {
if ($('dyndns_select').getProperty('value').toInt() == 1) {
window.open("http://www.no-ip.com/services/managed_dns/free_dynamic_dns.html", "NO-IP Registration");
}
@ -1337,22 +1337,22 @@ @@ -1337,22 +1337,22 @@
}
};
var generateRandomPort = function() {
var min = 1024;
var max = 65535;
var port = Math.floor(Math.random() * (max - min + 1) + min);
this.generateRandomPort = function() {
const min = 1024;
const max = 65535;
const port = Math.floor(Math.random() * (max - min + 1) + min);
$('port_value').setProperty('value', port);
};
var time_padding = function(val) {
var ret = val.toString();
this.time_padding = function(val) {
let ret = val.toString();
if (ret.length == 1)
ret = '0' + ret;
return ret;
};
// Advanced Tab
var updateNetworkInterfaces = function(default_iface) {
this.updateNetworkInterfaces = function(default_iface) {
const url = 'api/v2/app/networkInterfaceList';
$('networkInterface').empty();
new Request.JSON({
@ -1374,7 +1374,7 @@ @@ -1374,7 +1374,7 @@
}).send();
};
var updateInterfaceAddresses = function(iface, default_addr) {
this.updateInterfaceAddresses = function(iface, default_addr) {
const url = 'api/v2/app/networkInterfaceAddressList';
$('optionalIPAddressToBind').empty();
new Request.JSON({
@ -1399,8 +1399,8 @@ @@ -1399,8 +1399,8 @@
}).send();
}
var loadPreferences = function() {
var url = 'api/v2/app/preferences';
this.loadPreferences = function() {
const url = 'api/v2/app/preferences';
new Request.JSON({
url: url,
method: 'get',
@ -1448,10 +1448,10 @@ @@ -1448,10 +1448,10 @@
updateExportDirFinEnabled();
// Automatically add torrents from
var i = 0;
for (var folder in pref.scan_dirs) {
var sel;
var other = "";
let i = 0;
for (const folder in pref.scan_dirs) {
let sel;
let other = "";
if (typeof pref.scan_dirs[folder] == "string") {
other = pref.scan_dirs[folder];
sel = "other";
@ -1486,7 +1486,7 @@ @@ -1486,7 +1486,7 @@
$('random_port_checkbox').setProperty('checked', pref.random_port);
// Connections Limits
var max_connec = pref.max_connec.toInt();
const max_connec = pref.max_connec.toInt();
if (max_connec <= 0) {
$('max_connec_checkbox').setProperty('checked', false);
$('max_connec_value').setProperty('value', 500);
@ -1496,7 +1496,7 @@ @@ -1496,7 +1496,7 @@
$('max_connec_value').setProperty('value', max_connec);
}
updateMaxConnecEnabled();
var max_connec_per_torrent = pref.max_connec_per_torrent.toInt();
const max_connec_per_torrent = pref.max_connec_per_torrent.toInt();
if (max_connec_per_torrent <= 0) {
$('max_connec_per_torrent_checkbox').setProperty('checked', false);
$('max_connec_per_torrent_value').setProperty('value', 100);
@ -1506,7 +1506,7 @@ @@ -1506,7 +1506,7 @@
$('max_connec_per_torrent_value').setProperty('value', max_connec_per_torrent);
}
updateMaxConnecPerTorrentEnabled();
var max_uploads = pref.max_uploads.toInt();
const max_uploads = pref.max_uploads.toInt();
if (max_uploads <= 0) {
$('max_uploads_checkbox').setProperty('checked', false);
$('max_uploads_value').setProperty('value', 8);
@ -1516,7 +1516,7 @@ @@ -1516,7 +1516,7 @@
$('max_uploads_value').setProperty('value', max_uploads);
}
updateMaxUploadsEnabled();
var max_uploads_per_torrent = pref.max_uploads_per_torrent.toInt();
const max_uploads_per_torrent = pref.max_uploads_per_torrent.toInt();
if (max_uploads_per_torrent <= 0) {
$('max_uploads_per_torrent_checkbox').setProperty('checked', false);
$('max_uploads_per_torrent_value').setProperty('value', 4);
@ -1587,7 +1587,7 @@ @@ -1587,7 +1587,7 @@
$('dht_checkbox').setProperty('checked', pref.dht);
$('pex_checkbox').setProperty('checked', pref.pex);
$('lsd_checkbox').setProperty('checked', pref.lsd);
var encryption = pref.encryption.toInt();
const encryption = pref.encryption.toInt();
$('encryption_select').getChildren('option')[encryption].setAttribute('selected', '');
$('anonymous_mode_checkbox').setProperty('checked', pref.anonymous_mode);
@ -1608,14 +1608,12 @@ @@ -1608,14 +1608,12 @@
$('max_ratio_value').setProperty('value', pref.max_ratio);
else
$('max_ratio_value').setProperty('value', 1);
var max_ratio_act = pref.max_ratio_act.toInt();
$('max_ratio_act').getChildren('option')[max_ratio_act].setAttribute('selected', '');
$('max_seeding_time_checkbox').setProperty('checked', pref.max_seeding_time_enabled);
if (pref.max_seeding_time_enabled)
$('max_seeding_time_value').setProperty('value', pref.max_seeding_time.toInt());
else
$('max_seeding_time_value').setProperty('value', 1440);
var max_ratio_act = pref.max_ratio_act.toInt();
const max_ratio_act = pref.max_ratio_act.toInt();
$('max_ratio_act').getChildren('option')[max_ratio_act].setAttribute('selected', '');
updateMaxRatioTimeEnabled();
@ -1703,8 +1701,8 @@ @@ -1703,8 +1701,8 @@
}).send();
};
var applyPreferences = function() {
var settings = new Hash();
this.applyPreferences = function() {
const settings = new Hash();
// Validate form data
// Downloads tab
// When adding a torrent
@ -1751,7 +1749,7 @@ @@ -1751,7 +1749,7 @@
// Connection tab
// Listening Port
var listen_port = $('port_value').getProperty('value').toInt();
const listen_port = $('port_value').getProperty('value').toInt();
if (isNaN(listen_port) || listen_port < 1 || listen_port > 65535) {
alert("QBT_TR(The port used for incoming connections must be between 1 and 65535.)QBT_TR[CONTEXT=HttpServer]");
return;
@ -1761,7 +1759,7 @@ @@ -1761,7 +1759,7 @@
settings.set('random_port', $('random_port_checkbox').getProperty('checked'));
// Connections Limits
var max_connec = -1;
let max_connec = -1;
if ($('max_connec_checkbox').getProperty('checked')) {
max_connec = $('max_connec_value').getProperty('value').toInt();
if (isNaN(max_connec) || max_connec <= 0) {
@ -1770,7 +1768,7 @@ @@ -1770,7 +1768,7 @@
}
}
settings.set('max_connec', max_connec);
var max_connec_per_torrent = -1;
let max_connec_per_torrent = -1;
if ($('max_connec_per_torrent_checkbox').getProperty('checked')) {
max_connec_per_torrent = $('max_connec_per_torrent_value').getProperty('value').toInt();
if (isNaN(max_connec_per_torrent) || max_connec_per_torrent <= 0) {
@ -1779,7 +1777,7 @@ @@ -1779,7 +1777,7 @@
}
}
settings.set('max_connec_per_torrent', max_connec_per_torrent);
var max_uploads = -1;
let max_uploads = -1;
if ($('max_uploads_checkbox').getProperty('checked')) {
max_uploads = $('max_uploads_value').getProperty('value').toInt();
if (isNaN(max_uploads) || max_uploads <= 0) {
@ -1788,7 +1786,7 @@ @@ -1788,7 +1786,7 @@
}
}
settings.set('max_uploads', max_uploads);
var max_uploads_per_torrent = -1;
let max_uploads_per_torrent = -1;
if ($('max_uploads_per_torrent_checkbox').getProperty('checked')) {
max_uploads_per_torrent = $('max_uploads_per_torrent_value').getProperty('value').toInt();
if (isNaN(max_uploads_per_torrent) || max_uploads_per_torrent <= 0) {
@ -1799,9 +1797,9 @@ @@ -1799,9 +1797,9 @@
settings.set('max_uploads_per_torrent', max_uploads_per_torrent);
// Proxy Server
var proxy_type_str = $('peer_proxy_type_select').getProperty('value');
var proxy_type = 0;
var proxy_auth_enabled = false;
const proxy_type_str = $('peer_proxy_type_select').getProperty('value');
let proxy_type = 0;
let proxy_auth_enabled = false;
if (proxy_type_str == "socks5") {
if ($('peer_proxy_auth_checkbox').getProperty('checked')) {
proxy_type = 4;
@ -1844,14 +1842,14 @@ @@ -1844,14 +1842,14 @@
// Speed tab
// Global Rate Limits
var up_limit = $('up_limit_value').getProperty('value').toInt() * 1024;
const up_limit = $('up_limit_value').getProperty('value').toInt() * 1024;
if (isNaN(up_limit) || up_limit < 0) {
alert("QBT_TR(Global upload rate limit must be greater than 0 or disabled.)QBT_TR[CONTEXT=HttpServer]");
return;
}
settings.set('up_limit', up_limit);
var dl_limit = $('dl_limit_value').getProperty('value').toInt() * 1024;
const dl_limit = $('dl_limit_value').getProperty('value').toInt() * 1024;
if (isNaN(dl_limit) || dl_limit < 0) {
alert("QBT_TR(Global download rate limit must be greater than 0 or disabled.)QBT_TR[CONTEXT=HttpServer]");
return;
@ -1859,14 +1857,14 @@ @@ -1859,14 +1857,14 @@
settings.set('dl_limit', dl_limit);
// Alternative Global Rate Limits
var alt_up_limit = $('alt_up_limit_value').getProperty('value').toInt() * 1024;
const alt_up_limit = $('alt_up_limit_value').getProperty('value').toInt() * 1024;
if (isNaN(alt_up_limit) || alt_up_limit < 0) {
alert("QBT_TR(Alternative upload rate limit must be greater than 0 or disabled.)QBT_TR[CONTEXT=HttpServer]");
return;
}
settings.set('alt_up_limit', alt_up_limit);
var alt_dl_limit = $('alt_dl_limit_value').getProperty('value').toInt() * 1024;
const alt_dl_limit = $('alt_dl_limit_value').getProperty('value').toInt() * 1024;
if (isNaN(alt_dl_limit) || alt_dl_limit < 0) {
alert("QBT_TR(Alternative download rate limit must be greater than 0 or disabled.)QBT_TR[CONTEXT=HttpServer]");
return;
@ -1879,7 +1877,7 @@ @@ -1879,7 +1877,7 @@
settings.set('limit_lan_peers', $('limit_lan_peers_checkbox').getProperty('checked'));
// Scheduler
var scheduling_enabled = $('limit_sheduling_checkbox').getProperty('checked');
const scheduling_enabled = $('limit_sheduling_checkbox').getProperty('checked');
settings.set('scheduler_enabled', scheduling_enabled);
if (scheduling_enabled) {
settings.set('schedule_from_hour', $('schedule_from_hour').getProperty('value').toInt());
@ -1900,38 +1898,38 @@ @@ -1900,38 +1898,38 @@
// Torrent Queueing
settings.set('queueing_enabled', $('queueing_checkbox').getProperty('checked'));
if ($('queueing_checkbox').getProperty('checked')) {
var max_active_downloads = $('max_active_dl_value').getProperty('value').toInt();
const max_active_downloads = $('max_active_dl_value').getProperty('value').toInt();
if (isNaN(max_active_downloads) || max_active_downloads < -1) {
alert("QBT_TR(Maximum active downloads must be greater than -1.)QBT_TR[CONTEXT=HttpServer]");
return;
}
settings.set('max_active_downloads', max_active_downloads);
var max_active_uploads = $('max_active_up_value').getProperty('value').toInt();
const max_active_uploads = $('max_active_up_value').getProperty('value').toInt();
if (isNaN(max_active_uploads) || max_active_uploads < -1) {
alert("QBT_TR(Maximum active uploads must be greater than -1.)QBT_TR[CONTEXT=HttpServer]");
return;
}
settings.set('max_active_uploads', max_active_uploads);
var max_active_torrents = $('max_active_to_value').getProperty('value').toInt();
const max_active_torrents = $('max_active_to_value').getProperty('value').toInt();
if (isNaN(max_active_torrents) || max_active_torrents < -1) {
alert("QBT_TR(Maximum active torrents must be greater than -1.)QBT_TR[CONTEXT=HttpServer]");
return;
}
settings.set('max_active_torrents', max_active_torrents);
settings.set('dont_count_slow_torrents', $('dont_count_slow_torrents_checkbox').getProperty('checked'));
var dl_rate_threshold = $('dl_rate_threshold').getProperty('value').toInt();
const dl_rate_threshold = $('dl_rate_threshold').getProperty('value').toInt();
if (isNaN(dl_rate_threshold) || (dl_rate_threshold < 1)) {
alert("QBT_TR(Download rate threshold must be greater than 0.)QBT_TR[CONTEXT=HttpServer]");
return;
}
settings.set('slow_torrent_dl_rate_threshold', dl_rate_threshold);
var ul_rate_threshold = $('ul_rate_threshold').getProperty('value').toInt();
const ul_rate_threshold = $('ul_rate_threshold').getProperty('value').toInt();
if (isNaN(ul_rate_threshold) || (ul_rate_threshold < 1)) {
alert("QBT_TR(Upload rate threshold must be greater than 0.)QBT_TR[CONTEXT=HttpServer]");
return;
}
settings.set('slow_torrent_ul_rate_threshold', ul_rate_threshold);
var torrent_inactive_timer = $('torrent_inactive_timer').getProperty('value').toInt();
const torrent_inactive_timer = $('torrent_inactive_timer').getProperty('value').toInt();
if (isNaN(torrent_inactive_timer) || (torrent_inactive_timer < 1)) {
alert("QBT_TR(Torrent inactivity timer must be greater than 0.)QBT_TR[CONTEXT=HttpServer]");
return;
@ -1940,7 +1938,7 @@ @@ -1940,7 +1938,7 @@
}
// Share Ratio Limiting
var max_ratio = -1;
let max_ratio = -1;
if ($('max_ratio_checkbox').getProperty('checked')) {
max_ratio = $('max_ratio_value').getProperty('value');
if (isNaN(max_ratio) || max_ratio < 0 || max_ratio > 9998) {
@ -1952,7 +1950,7 @@ @@ -1952,7 +1950,7 @@
settings.set('max_ratio', max_ratio);
settings.set('max_ratio_act', $('max_ratio_act').getProperty('value').toInt());
var max_seeding_time = -1;
let max_seeding_time = -1;
if ($('max_seeding_time_checkbox').getProperty('checked')) {
max_seeding_time = $('max_seeding_time_value').getProperty('value').toInt();
if (isNaN(max_seeding_time) || max_seeding_time < 0 || max_seeding_time > 525600) {
@ -1974,8 +1972,8 @@ @@ -1974,8 +1972,8 @@
// HTTP Server
settings.set('web_ui_domain_list', $('webui_domain_textarea').getProperty('value'));
var web_ui_address = $('webui_address_value').getProperty('value').toString();
var web_ui_port = $('webui_port_value').getProperty('value').toInt();
const web_ui_address = $('webui_address_value').getProperty('value').toString();
const web_ui_port = $('webui_port_value').getProperty('value').toInt();
if (isNaN(web_ui_port) || web_ui_port < 1 || web_ui_port > 65535) {
alert("QBT_TR(The port used for the Web UI must be between 1 and 65535.)QBT_TR[CONTEXT=HttpServer]");
return;
@ -1988,12 +1986,12 @@ @@ -1988,12 +1986,12 @@
settings.set('web_ui_https_key_path', $('ssl_key_text').getProperty('value'));
// Authentication
var web_ui_username = $('webui_username_text').getProperty('value');
const web_ui_username = $('webui_username_text').getProperty('value');
if (web_ui_username.length < 3) {
alert("QBT_TR(The Web UI username must be at least 3 characters long.)QBT_TR[CONTEXT=OptionsDialog]");
return;
}
var web_ui_password = $('webui_password_text').getProperty('value');
const web_ui_password = $('webui_password_text').getProperty('value');
if ((0 < web_ui_password.length) && (web_ui_password.length < 6)) {
alert("QBT_TR(The Web UI password must be at least 6 characters long.)QBT_TR[CONTEXT=OptionsDialog]");
return;
@ -2008,8 +2006,8 @@ @@ -2008,8 +2006,8 @@
settings.set('web_ui_session_timeout', $('webUISessionTimeoutInput').getProperty('value'));
// Use alternative Web UI
var alternative_webui_enabled = $('use_alt_webui_checkbox').getProperty('checked');
var webui_files_location_textarea = $('webui_files_location_textarea').getProperty('value');
const alternative_webui_enabled = $('use_alt_webui_checkbox').getProperty('checked');
const webui_files_location_textarea = $('webui_files_location_textarea').getProperty('value');
if (alternative_webui_enabled && (webui_files_location_textarea.trim() === "")) {
alert("QBT_TR(The alternative Web UI files location cannot be blank.)QBT_TR[CONTEXT=OptionsDialog]");
return;
@ -2064,7 +2062,7 @@ @@ -2064,7 +2062,7 @@
settings.set('announce_ip', $('announceIP').getProperty('value'));
// Send it to qBT
var json_str = JSON.encode(settings);
const json_str = JSON.encode(settings);
new Request({
url: 'api/v2/app/setPreferences',

2
src/webui/www/private/properties_content.html

@ -155,7 +155,7 @@ @@ -155,7 +155,7 @@
<script>
'use strict';
var selectedTab = $(getLocalStorageItem('selected_tab', 'PropGeneralLink'));
const selectedTab = $(getLocalStorageItem('selected_tab', 'PropGeneralLink'));
if (selectedTab)
selectedTab.click();
</script>

6
src/webui/www/private/rename.html

@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
}).activate();
window.addEvent('domready', function() {
var name = new URI().getData('name');
const name = new URI().getData('name');
// set text field to current value
if (name)
$('rename').value = decodeURIComponent(name);
@ -39,11 +39,11 @@ @@ -39,11 +39,11 @@
$('renameButton').addEvent('click', function(e) {
new Event(e).stop();
// check field
var name = $('rename').value.trim();
const name = $('rename').value.trim();
if (name === null || name === "")
return false;
var hash = new URI().getData('hash');
const hash = new URI().getData('hash');
if (hash) {
new Request({
url: 'api/v2/torrents/rename',

338
src/webui/www/private/scripts/client.js

@ -24,50 +24,63 @@ @@ -24,50 +24,63 @@
'use strict';
var torrentsTable = new TorrentsTable();
var torrentTrackersTable = new TorrentTrackersTable();
var torrentPeersTable = new TorrentPeersTable();
var torrentFilesTable = new TorrentFilesTable();
var searchResultsTable = new SearchResultsTable();
var searchPluginsTable = new SearchPluginsTable();
this.torrentsTable = new TorrentsTable();
const torrentTrackersTable = new TorrentTrackersTable();
const torrentPeersTable = new TorrentPeersTable();
const torrentFilesTable = new TorrentFilesTable();
const searchResultsTable = new SearchResultsTable();
const searchPluginsTable = new SearchPluginsTable();
var updatePropertiesPanel = function() {};
let updatePropertiesPanel = function() {};
var updateTorrentData = function() {};
var updateTrackersData = function() {};
var updateTorrentPeersData = function() {};
var updateWebSeedsData = function() {};
var updateTorrentFilesData = function() {};
let updateTorrentData = function() {};
let updateTrackersData = function() {};
let updateTorrentPeersData = function() {};
let updateWebSeedsData = function() {};
let updateTorrentFilesData = function() {};
var updateMainData = function() {};
var alternativeSpeedLimits = false;
var queueing_enabled = true;
var serverSyncMainDataInterval = 1500;
var customSyncMainDataInterval = null;
this.updateMainData = function() {};
let alternativeSpeedLimits = false;
let queueing_enabled = true;
let serverSyncMainDataInterval = 1500;
let customSyncMainDataInterval = null;
var clipboardEvent;
let clipboardEvent;
var CATEGORIES_ALL = 1;
var CATEGORIES_UNCATEGORIZED = 2;
const CATEGORIES_ALL = 1;
const CATEGORIES_UNCATEGORIZED = 2;
var category_list = {};
let category_list = {};
var selected_category = CATEGORIES_ALL;
var setCategoryFilter = function() {};
let selected_category = CATEGORIES_ALL;
let setCategoryFilter = function() {};
var selected_filter = getLocalStorageItem('selected_filter', 'all');
var setFilter = function() {};
var toggleFilterDisplay = function() {};
const TAGS_ALL = 1;
const TAGS_UNTAGGED = 2;
var loadSelectedCategory = function() {
let tagList = {};
let selectedTag = TAGS_ALL;
let setTagFilter = function() {};
let selected_filter = getLocalStorageItem('selected_filter', 'all');
let setFilter = function() {};
let toggleFilterDisplay = function() {};
const loadSelectedCategory = function() {
selected_category = getLocalStorageItem('selected_category', CATEGORIES_ALL);
};
loadSelectedCategory();
const loadSelectedTag = function() {
selectedTag = getLocalStorageItem('selected_tag', TAGS_ALL);
};
loadSelectedTag();
function genHash(string) {
var hash = 0;
for (var i = 0; i < string.length; ++i) {
var c = string.charCodeAt(i);
let hash = 0;
for (let i = 0; i < string.length; ++i) {
const c = string.charCodeAt(i);
hash = (c + hash * 31) | 0;
}
return hash;
@ -98,9 +111,9 @@ const qbtVersion = function() { @@ -98,9 +111,9 @@ const qbtVersion = function() {
window.addEvent('load', function() {
var saveColumnSizes = function() {
var filters_width = $('Filters').getSize().x;
var properties_height_rel = $('propertiesPanel').getSize().y / Window.getSize().y;
const saveColumnSizes = function() {
const filters_width = $('Filters').getSize().x;
const properties_height_rel = $('propertiesPanel').getSize().y / Window.getSize().y;
localStorage.setItem('filters_width', filters_width);
localStorage.setItem('properties_height_rel', properties_height_rel);
};
@ -118,8 +131,8 @@ window.addEvent('load', function() { @@ -118,8 +131,8 @@ window.addEvent('load', function() {
});*/
MochaUI.Desktop.initialize();
var buildTransfersTab = function() {
var filt_w = localStorage.getItem('filters_width');
const buildTransfersTab = function() {
let filt_w = localStorage.getItem('filters_width');
if ($defined(filt_w))
filt_w = filt_w.toInt();
else
@ -138,7 +151,7 @@ window.addEvent('load', function() { @@ -138,7 +151,7 @@ window.addEvent('load', function() {
});
};
var buildSearchTab = function() {
const buildSearchTab = function() {
new MochaUI.Column({
id: 'searchTabColumn',
placement: 'main',
@ -161,6 +174,14 @@ window.addEvent('load', function() { @@ -161,6 +174,14 @@ window.addEvent('load', function() {
updateMainData();
};
setTagFilter = function(hash) {
selectedTag = hash.toString();
localStorage.setItem('selected_tag', selectedTag);
highlightSelectedTag();
if (torrentsTable.tableBody !== undefined)
updateMainData();
};
setFilter = function(f) {
// Visually Select the right filter
$("all_filter").removeClass("selectedFilter");
@ -181,11 +202,11 @@ window.addEvent('load', function() { @@ -181,11 +202,11 @@ window.addEvent('load', function() {
};
toggleFilterDisplay = function(filter) {
var element = filter + "FilterList";
const element = filter + "FilterList";
localStorage.setItem('filter_' + filter + "_collapsed", !$(element).hasClass("invisible"));
$(element).toggleClass("invisible")
var parent = $(element).getParent(".filterWrapper");
var toggleIcon = $(parent).getChildren(".filterTitle img");
const parent = $(element).getParent(".filterWrapper");
const toggleIcon = $(parent).getChildren(".filterTitle img");
if (toggleIcon)
toggleIcon[0].toggleClass("rotate");
};
@ -211,7 +232,7 @@ window.addEvent('load', function() { @@ -211,7 +232,7 @@ window.addEvent('load', function() {
initializeWindows();
// Show Top Toolbar is enabled by default
var showTopToolbar = true;
let showTopToolbar = true;
if (localStorage.getItem('show_top_toolbar') !== null)
showTopToolbar = localStorage.getItem('show_top_toolbar') == "true";
if (!showTopToolbar) {
@ -220,7 +241,7 @@ window.addEvent('load', function() { @@ -220,7 +241,7 @@ window.addEvent('load', function() {
}
// Show Status Bar is enabled by default
var showStatusBar = true;
let showStatusBar = true;
if (localStorage.getItem('show_status_bar') !== null)
showStatusBar = localStorage.getItem('show_status_bar') === "true";
if (!showStatusBar) {
@ -228,12 +249,12 @@ window.addEvent('load', function() { @@ -228,12 +249,12 @@ window.addEvent('load', function() {
$('desktopFooterWrapper').addClass('invisible');
}
var speedInTitle = localStorage.getItem('speed_in_browser_title_bar') == "true";
let speedInTitle = localStorage.getItem('speed_in_browser_title_bar') == "true";
if (!speedInTitle)
$('speedInBrowserTitleBarLink').firstChild.style.opacity = '0';
// After showing/hiding the toolbar + status bar
var showSearchEngine = localStorage.getItem('show_search_engine') === "true";
let showSearchEngine = localStorage.getItem('show_search_engine') === "true";
if (!showSearchEngine) {
// uncheck menu option
$('showSearchEngineLink').firstChild.style.opacity = '0';
@ -244,13 +265,13 @@ window.addEvent('load', function() { @@ -244,13 +265,13 @@ window.addEvent('load', function() {
// After Show Top Toolbar
MochaUI.Desktop.setDesktopSize();
var syncMainDataLastResponseId = 0;
var serverState = {};
let syncMainDataLastResponseId = 0;
const serverState = {};
var removeTorrentFromCategoryList = function(hash) {
const removeTorrentFromCategoryList = function(hash) {
if (hash === null || hash === "")
return false;
var removed = false;
let removed = false;
Object.each(category_list, function(category) {
if (Object.contains(category.torrents, hash)) {
removed = true;
@ -260,15 +281,15 @@ window.addEvent('load', function() { @@ -260,15 +281,15 @@ window.addEvent('load', function() {
return removed;
};
var addTorrentToCategoryList = function(torrent) {
var category = torrent['category'];
const addTorrentToCategoryList = function(torrent) {
const category = torrent['category'];
if (typeof category === 'undefined')
return false;
if (category.length === 0) { // Empty category
removeTorrentFromCategoryList(torrent['hash']);
return true;
}
var categoryHash = genHash(category);
const categoryHash = genHash(category);
if (category_list[categoryHash] === null) // This should not happen
category_list[categoryHash] = {
name: category,
@ -282,11 +303,47 @@ window.addEvent('load', function() { @@ -282,11 +303,47 @@ window.addEvent('load', function() {
return false;
};
var updateFilter = function(filter, filterTitle) {
$(filter + '_filter').firstChild.childNodes[1].nodeValue = filterTitle.replace('%1', torrentsTable.getFilteredTorrentsNumber(filter, CATEGORIES_ALL));
const removeTorrentFromTagList = function(hash) {
if ((hash === null) || (hash === ""))
return false;
let removed = false;
for (const key in tagList) {
const tag = tagList[key];
if (Object.contains(tag.torrents, hash)) {
removed = true;
tag.torrents.splice(tag.torrents.indexOf(hash), 1);
}
}
return removed;
};
var updateFiltersList = function() {
const addTorrentToTagList = function(torrent) {
if (torrent['tags'] === undefined) // Tags haven't changed
return false;
removeTorrentFromTagList(torrent['hash']);
if (torrent['tags'].length === 0) // No tags
return true;
const tags = torrent['tags'].split(',');
let added = false;
for (let i = 0; i < tags.length; ++i) {
const tagHash = genHash(tags[i].trim());
if (!Object.contains(tagList[tagHash].torrents, torrent['hash'])) {
added = true;
tagList[tagHash].torrents.push(torrent['hash']);
}
}
return added;
};
const updateFilter = function(filter, filterTitle) {
$(filter + '_filter').firstChild.childNodes[1].nodeValue = filterTitle.replace('%1', torrentsTable.getFilteredTorrentsNumber(filter, CATEGORIES_ALL, TAGS_ALL));
};
const updateFiltersList = function() {
updateFilter('all', 'QBT_TR(All (%1))QBT_TR[CONTEXT=StatusFilterWidget]');
updateFilter('downloading', 'QBT_TR(Downloading (%1))QBT_TR[CONTEXT=StatusFilterWidget]');
updateFilter('seeding', 'QBT_TR(Seeding (%1))QBT_TR[CONTEXT=StatusFilterWidget]');
@ -298,17 +355,17 @@ window.addEvent('load', function() { @@ -298,17 +355,17 @@ window.addEvent('load', function() {
updateFilter('errored', 'QBT_TR(Errored (%1))QBT_TR[CONTEXT=StatusFilterWidget]');
};
var updateCategoryList = function() {
var categoryList = $('categoryFilterList');
const updateCategoryList = function() {
const categoryList = $('categoryFilterList');
if (!categoryList)
return;
categoryList.empty();
var create_link = function(hash, text, count) {
var html = '<a href="#" onclick="setCategoryFilter(' + hash + ');return false;">'
const create_link = function(hash, text, count) {
const html = '<a href="#" onclick="setCategoryFilter(' + hash + ');return false;">'
+ '<img src="images/qbt-theme/inode-directory.svg"/>'
+ escapeHtml(text) + ' (' + count + ')' + '</a>';
var el = new Element('li', {
const el = new Element('li', {
id: hash,
html: html
});
@ -316,8 +373,8 @@ window.addEvent('load', function() { @@ -316,8 +373,8 @@ window.addEvent('load', function() {
return el;
};
var all = torrentsTable.getRowIds().length;
var uncategorized = 0;
const all = torrentsTable.getRowIds().length;
let uncategorized = 0;
Object.each(torrentsTable.rows, function(row) {
if (row['full_data'].category.length === 0)
uncategorized += 1;
@ -325,44 +382,98 @@ window.addEvent('load', function() { @@ -325,44 +382,98 @@ window.addEvent('load', function() {
categoryList.appendChild(create_link(CATEGORIES_ALL, 'QBT_TR(All)QBT_TR[CONTEXT=CategoryFilterModel]', all));
categoryList.appendChild(create_link(CATEGORIES_UNCATEGORIZED, 'QBT_TR(Uncategorized)QBT_TR[CONTEXT=CategoryFilterModel]', uncategorized));
var sortedCategories = [];
const sortedCategories = [];
Object.each(category_list, function(category) {
sortedCategories.push(category.name);
});
sortedCategories.sort();
Object.each(sortedCategories, function(categoryName) {
var categoryHash = genHash(categoryName);
var categoryCount = category_list[categoryHash].torrents.length;
const categoryHash = genHash(categoryName);
const categoryCount = category_list[categoryHash].torrents.length;
categoryList.appendChild(create_link(categoryHash, categoryName, categoryCount));
});
highlightSelectedCategory();
};
var highlightSelectedCategory = function() {
var categoryList = $('categoryFilterList');
const highlightSelectedCategory = function() {
const categoryList = $('categoryFilterList');
if (!categoryList)
return;
var childrens = categoryList.childNodes;
for (var i = 0; i < childrens.length; ++i) {
if (childrens[i].id == selected_category)
childrens[i].className = "selectedFilter";
const children = categoryList.childNodes;
for (let i = 0; i < children.length; ++i) {
if (children[i].id == selected_category)
children[i].className = "selectedFilter";
else
childrens[i].className = "";
children[i].className = "";
}
};
var syncMainDataTimer;
var syncMainData = function() {
var url = new URI('api/v2/sync/maindata');
const updateTagList = function() {
const tagFilterList = $('tagFilterList');
if (tagFilterList === null)
return;
while (tagFilterList.firstChild !== null)
tagFilterList.removeChild(tagFilterList.firstChild);
const createLink = function(hash, text, count) {
const html = '<a href="#" onclick="setTagFilter(' + hash + ');return false;">'
+ '<img src="images/qbt-theme/inode-directory.svg"/>'
+ escapeHtml(text) + ' (' + count + ')' + '</a>';
const el = new Element('li', {
id: hash,
html: html
});
tagsFilterContextMenu.addTarget(el);
return el;
};
const torrentsCount = torrentsTable.getRowIds().length;
let untagged = 0;
for (const key in torrentsTable.rows) {
if (torrentsTable.rows.hasOwnProperty(key) && torrentsTable.rows[key]['full_data'].tags.length === 0)
untagged += 1;
}
tagFilterList.appendChild(createLink(TAGS_ALL, 'QBT_TR(All)QBT_TR[CONTEXT=TagFilterModel]', torrentsCount));
tagFilterList.appendChild(createLink(TAGS_UNTAGGED, 'QBT_TR(Untagged)QBT_TR[CONTEXT=TagFilterModel]', untagged));
const sortedTags = [];
for (const key in tagList)
sortedTags.push(tagList[key].name);
sortedTags.sort();
for (let i = 0; i < sortedTags.length; ++i) {
const tagName = sortedTags[i];
const tagHash = genHash(tagName);
const tagCount = tagList[tagHash].torrents.length;
tagFilterList.appendChild(createLink(tagHash, tagName, tagCount));
}
highlightSelectedTag();
};
const highlightSelectedTag = function() {
const tagFilterList = $('tagFilterList');
if (!tagFilterList)
return;
const children = tagFilterList.childNodes;
for (let i = 0; i < children.length; ++i)
children[i].className = (children[i].id === selectedTag) ? "selectedFilter" : "";
};
let syncMainDataTimer;
const syncMainData = function() {
const url = new URI('api/v2/sync/maindata');
url.setData('rid', syncMainDataLastResponseId);
new Request.JSON({
url: url,
noCache: true,
method: 'get',
onFailure: function() {
var errorDiv = $('error_div');
const errorDiv = $('error_div');
if (errorDiv)
errorDiv.set('html', 'QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]');
clearTimeout(syncMainDataTimer);
@ -372,21 +483,23 @@ window.addEvent('load', function() { @@ -372,21 +483,23 @@ window.addEvent('load', function() {
$('error_div').set('html', '');
if (response) {
clearTimeout(torrentsFilterInputTimer);
var torrentsTableSelectedRows;
var update_categories = false;
var full_update = (response['full_update'] === true);
let torrentsTableSelectedRows;
let update_categories = false;
let updateTags = false;
const full_update = (response['full_update'] === true);
if (full_update) {
torrentsTableSelectedRows = torrentsTable.selectedRowsIds();
torrentsTable.clear();
category_list = {};
tagList = {};
}
if (response['rid']) {
syncMainDataLastResponseId = response['rid'];
}
if (response['categories']) {
for (var key in response['categories']) {
var category = response['categories'][key];
var categoryHash = genHash(key);
for (const key in response['categories']) {
const category = response['categories'][key];
const categoryHash = genHash(key);
if (category_list[categoryHash] !== undefined) {
// only the save path can change for existing categories
category_list[categoryHash].savePath = category.savePath;
@ -403,14 +516,33 @@ window.addEvent('load', function() { @@ -403,14 +516,33 @@ window.addEvent('load', function() {
}
if (response['categories_removed']) {
response['categories_removed'].each(function(category) {
var categoryHash = genHash(category);
const categoryHash = genHash(category);
delete category_list[categoryHash];
});
update_categories = true;
}
if (response['tags']) {
for (const tag of response['tags']) {
const tagHash = genHash(tag);
if (!tagList[tagHash]) {
tagList[tagHash] = {
name: tag,
torrents: []
};
}
}
updateTags = true;
}
if (response['tags_removed']) {
for (let i = 0; i < response['tags_removed'].length; ++i) {
const tagHash = genHash(response['tags_removed'][i]);
delete tagList[tagHash];
}
updateTags = true;
}
if (response['torrents']) {
var updateTorrentList = false;
for (var key in response['torrents']) {
let updateTorrentList = false;
for (const key in response['torrents']) {
response['torrents'][key]['hash'] = key;
response['torrents'][key]['rowId'] = key;
if (response['torrents'][key]['state'])
@ -418,6 +550,8 @@ window.addEvent('load', function() { @@ -418,6 +550,8 @@ window.addEvent('load', function() {
torrentsTable.updateRowData(response['torrents'][key]);
if (addTorrentToCategoryList(response['torrents'][key]))
update_categories = true;
if (addTorrentToTagList(response['torrents'][key]))
updateTags = true;
if (response['torrents'][key]['name'])
updateTorrentList = true;
}
@ -430,12 +564,14 @@ window.addEvent('load', function() { @@ -430,12 +564,14 @@ window.addEvent('load', function() {
torrentsTable.removeRow(hash);
removeTorrentFromCategoryList(hash);
update_categories = true; // Always to update All category
removeTorrentFromTagList(hash);
updateTags = true; // Always to update All tag
});
torrentsTable.updateTable(full_update);
torrentsTable.altRow();
if (response['server_state']) {
var tmp = response['server_state'];
for (var k in tmp)
const tmp = response['server_state'];
for (const k in tmp)
serverState[k] = tmp[k];
processServerState();
}
@ -444,6 +580,10 @@ window.addEvent('load', function() { @@ -444,6 +580,10 @@ window.addEvent('load', function() {
updateCategoryList();
torrentsTableContextMenu.updateCategoriesSubMenu(category_list);
}
if (updateTags) {
updateTagList();
torrentsTableContextMenu.updateTagsSubMenu(tagList);
}
if (full_update)
// re-select previously selected rows
@ -461,8 +601,8 @@ window.addEvent('load', function() { @@ -461,8 +601,8 @@ window.addEvent('load', function() {
syncMainDataTimer = syncMainData.delay(100);
};
var processServerState = function() {
var transfer_info = friendlyUnit(serverState.dl_info_speed, true);
const processServerState = function() {
let transfer_info = friendlyUnit(serverState.dl_info_speed, true);
if (serverState.dl_rate_limit > 0)
transfer_info += " [" + friendlyUnit(serverState.dl_rate_limit, true) + "]";
transfer_info += " (" + friendlyUnit(serverState.dl_info_data, false) + ")";
@ -534,7 +674,7 @@ window.addEvent('load', function() { @@ -534,7 +674,7 @@ window.addEvent('load', function() {
serverSyncMainDataInterval = Math.max(serverState.refresh_interval, 500);
};
var updateAltSpeedIcon = function(enabled) {
const updateAltSpeedIcon = function(enabled) {
if (enabled)
$('alternativeSpeedLimits').src = "images/slow.svg";
else
@ -628,7 +768,7 @@ window.addEvent('load', function() { @@ -628,7 +768,7 @@ window.addEvent('load', function() {
// main window tabs
var showTransfersTab = function() {
const showTransfersTab = function() {
$("filtersColumn").removeClass("invisible");
$("filtersColumn_handle").removeClass("invisible");
$("mainColumn").removeClass("invisible");
@ -640,35 +780,35 @@ window.addEvent('load', function() { @@ -640,35 +780,35 @@ window.addEvent('load', function() {
hideSearchTab();
};
var hideTransfersTab = function() {
const hideTransfersTab = function() {
$("filtersColumn").addClass("invisible");
$("filtersColumn_handle").addClass("invisible");
$("mainColumn").addClass("invisible");
MochaUI.Desktop.resizePanels();
};
var showSearchTab = function() {
const showSearchTab = function() {
$("searchTabColumn").removeClass("invisible");
customSyncMainDataInterval = 30000;
hideTransfersTab();
};
var hideSearchTab = function() {
const hideSearchTab = function() {
$("searchTabColumn").addClass("invisible");
MochaUI.Desktop.resizePanels();
};
var addMainWindowTabsEventListener = function() {
const addMainWindowTabsEventListener = function() {
$('transfersTabLink').addEvent('click', showTransfersTab);
$('searchTabLink').addEvent('click', showSearchTab);
};
var removeMainWindowTabsEventListener = function() {
const removeMainWindowTabsEventListener = function() {
$('transfersTabLink').removeEvent('click', showTransfersTab);
$('searchTabLink').removeEvent('click', showSearchTab);
};
var addSearchPanel = function() {
const addSearchPanel = function() {
new MochaUI.Panel({
id: 'SearchPanel',
title: 'Search',
@ -707,7 +847,7 @@ window.addEvent('load', function() { @@ -707,7 +847,7 @@ window.addEvent('load', function() {
onResize: saveColumnSizes,
height: null
});
var prop_h = localStorage.getItem('properties_height_rel');
let prop_h = localStorage.getItem('properties_height_rel');
if ($defined(prop_h))
prop_h = prop_h.toFloat() * Window.getSize().y;
else
@ -787,11 +927,11 @@ window.addEvent('load', function() { @@ -787,11 +927,11 @@ window.addEvent('load', function() {
height: prop_h
});
var prevTorrentsFilterValue;
var torrentsFilterInputTimer = null;
let prevTorrentsFilterValue;
let torrentsFilterInputTimer = null;
// listen for changes to torrentsFilterInput
$('torrentsFilterInput').addEvent('input', function() {
var value = $('torrentsFilterInput').get("value");
const value = $('torrentsFilterInput').get("value");
if (value !== prevTorrentsFilterValue) {
prevTorrentsFilterValue = value;
clearTimeout(torrentsFilterInputTimer);

158
src/webui/www/private/scripts/contextmenu.js

@ -28,8 +28,8 @@ @@ -28,8 +28,8 @@
'use strict';
var lastShownContexMenu = null;
var ContextMenu = new Class({
let lastShownContextMenu = null;
const ContextMenu = new Class({
//implements
Implements: [Options, Events],
@ -87,7 +87,7 @@ var ContextMenu = new Class({ @@ -87,7 +87,7 @@ var ContextMenu = new Class({
adjustMenuPosition: function(e) {
this.updateMenuItems();
var scrollableMenuMaxHeight = document.documentElement.clientHeight * 0.75;
const scrollableMenuMaxHeight = document.documentElement.clientHeight * 0.75;
if (this.menu.hasClass('scrollableMenu'))
this.menu.setStyle('max-height', scrollableMenuMaxHeight);
@ -99,8 +99,8 @@ var ContextMenu = new Class({ @@ -99,8 +99,8 @@ var ContextMenu = new Class({
});
// position the menu
var xPosMenu = e.page.x + this.options.offsets.x;
var yPosMenu = e.page.y + this.options.offsets.y;
let xPosMenu = e.page.x + this.options.offsets.x;
let yPosMenu = e.page.y + this.options.offsets.y;
if (xPosMenu + this.menu.offsetWidth > document.documentElement.clientWidth)
xPosMenu -= this.menu.offsetWidth;
if (yPosMenu + this.menu.offsetHeight > document.documentElement.clientHeight)
@ -117,16 +117,16 @@ var ContextMenu = new Class({ @@ -117,16 +117,16 @@ var ContextMenu = new Class({
});
// position the sub-menu
var uls = this.menu.getElementsByTagName('ul');
for (var i = 0; i < uls.length; ++i) {
var ul = uls[i];
const uls = this.menu.getElementsByTagName('ul');
for (let i = 0; i < uls.length; ++i) {
const ul = uls[i];
if (ul.hasClass('scrollableMenu'))
ul.setStyle('max-height', scrollableMenuMaxHeight);
var rectParent = ul.parentNode.getBoundingClientRect();
var xPosOrigin = rectParent.left;
var yPosOrigin = rectParent.bottom;
var xPos = xPosOrigin + rectParent.width - 1;
var yPos = yPosOrigin - rectParent.height - 1;
const rectParent = ul.parentNode.getBoundingClientRect();
const xPosOrigin = rectParent.left;
const yPosOrigin = rectParent.bottom;
let xPos = xPosOrigin + rectParent.width - 1;
let yPos = yPosOrigin - rectParent.height - 1;
if (xPos + ul.offsetWidth > document.documentElement.clientWidth)
xPos -= (ul.offsetWidth + rectParent.width - 2);
if (yPos + ul.offsetHeight > document.documentElement.clientHeight)
@ -214,12 +214,12 @@ var ContextMenu = new Class({ @@ -214,12 +214,12 @@ var ContextMenu = new Class({
//show menu
show: function(trigger) {
if (lastShownContexMenu && lastShownContexMenu != this)
lastShownContexMenu.hide();
if (lastShownContextMenu && lastShownContextMenu != this)
lastShownContextMenu.hide();
this.fx.start(1);
this.fireEvent('show');
this.shown = true;
lastShownContexMenu = this;
lastShownContextMenu = this;
return this;
},
@ -277,26 +277,27 @@ var ContextMenu = new Class({ @@ -277,26 +277,27 @@ var ContextMenu = new Class({
}
});
var TorrentsTableContextMenu = new Class({
const TorrentsTableContextMenu = new Class({
Extends: ContextMenu,
updateMenuItems: function() {
var all_are_seq_dl = true;
var there_are_seq_dl = false;
var all_are_f_l_piece_prio = true;
var there_are_f_l_piece_prio = false;
var all_are_downloaded = true;
var all_are_paused = true;
var there_are_paused = false;
var all_are_force_start = true;
var there_are_force_start = false;
var all_are_super_seeding = true;
var all_are_auto_tmm = true;
var there_are_auto_tmm = false;
var h = torrentsTable.selectedRowsIds();
let all_are_seq_dl = true;
let there_are_seq_dl = false;
let all_are_f_l_piece_prio = true;
let there_are_f_l_piece_prio = false;
let all_are_downloaded = true;
let all_are_paused = true;
let there_are_paused = false;
let all_are_force_start = true;
let there_are_force_start = false;
let all_are_super_seeding = true;
let all_are_auto_tmm = true;
let there_are_auto_tmm = false;
const tagsSelectionState = Object.clone(tagList);
const h = torrentsTable.selectedRowsIds();
h.each(function(item, index) {
var data = torrentsTable.rows.get(item).full_data;
const data = torrentsTable.rows.get(item).full_data;
if (data['seq_dl'] !== true)
all_are_seq_dl = false;
@ -327,14 +328,26 @@ var TorrentsTableContextMenu = new Class({ @@ -327,14 +328,26 @@ var TorrentsTableContextMenu = new Class({
there_are_auto_tmm = true;
else
all_are_auto_tmm = false;
const torrentTags = data['tags'].split(', ');
for (const key in tagsSelectionState) {
const tag = tagsSelectionState[key];
const tagExists = torrentTags.contains(tag.name);
if ((tag.checked !== undefined) && (tag.checked != tagExists))
tag.indeterminate = true;
if (tag.checked === undefined)
tag.checked = tagExists;
else
tag.checked = tag.checked && tagExists;
}
});
var show_seq_dl = true;
let show_seq_dl = true;
if (!all_are_seq_dl && there_are_seq_dl)
show_seq_dl = false;
var show_f_l_piece_prio = true;
let show_f_l_piece_prio = true;
if (!all_are_f_l_piece_prio && there_are_f_l_piece_prio)
show_f_l_piece_prio = false;
@ -389,10 +402,17 @@ var TorrentsTableContextMenu = new Class({ @@ -389,10 +402,17 @@ var TorrentsTableContextMenu = new Class({
this.setItemChecked('autoTorrentManagement', all_are_auto_tmm);
}
const contextTagList = $('contextTagList');
for (const tagHash in tagList) {
const checkbox = contextTagList.getElement('a[href=#Tag/' + tagHash + '] input[type=checkbox]');
const checkboxState = tagsSelectionState[tagHash];
checkbox.indeterminate = checkboxState.indeterminate;
checkbox.checked = checkboxState.checked;
}
},
updateCategoriesSubMenu: function(category_list) {
var categoryList = $('contextCategoryList');
const categoryList = $('contextCategoryList');
categoryList.empty();
categoryList.appendChild(new Element('li', {
html: '<a href="javascript:torrentNewCategoryFN();"><img src="images/qbt-theme/list-add.svg" alt="QBT_TR(New...)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(New...)QBT_TR[CONTEXT=TransferListWidget]</a>'
@ -401,16 +421,16 @@ var TorrentsTableContextMenu = new Class({ @@ -401,16 +421,16 @@ var TorrentsTableContextMenu = new Class({
html: '<a href="javascript:torrentSetCategoryFN(0);"><img src="images/qbt-theme/edit-clear.svg" alt="QBT_TR(Reset)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Reset)QBT_TR[CONTEXT=TransferListWidget]</a>'
}));
var sortedCategories = [];
const sortedCategories = [];
Object.each(category_list, function(category) {
sortedCategories.push(category.name);
});
sortedCategories.sort();
var first = true;
let first = true;
Object.each(sortedCategories, function(categoryName) {
var categoryHash = genHash(categoryName);
var el = new Element('li', {
const categoryHash = genHash(categoryName);
const el = new Element('li', {
html: '<a href="javascript:torrentSetCategoryFN(\'' + categoryHash + '\');"><img src="images/qbt-theme/inode-directory.svg"/> ' + escapeHtml(categoryName) + '</a>'
});
if (first) {
@ -419,13 +439,50 @@ var TorrentsTableContextMenu = new Class({ @@ -419,13 +439,50 @@ var TorrentsTableContextMenu = new Class({
}
categoryList.appendChild(el);
});
},
updateTagsSubMenu: function(tagList) {
const contextTagList = $('contextTagList');
while (contextTagList.firstChild !== null)
contextTagList.removeChild(contextTagList.firstChild);
contextTagList.appendChild(new Element('li', {
html: '<a href="javascript:torrentAddTagsFN();">'
+ '<img src="images/qbt-theme/list-add.svg" alt="QBT_TR(Add...)QBT_TR[CONTEXT=TransferListWidget]"/>'
+ ' QBT_TR(Add...)QBT_TR[CONTEXT=TransferListWidget]'
+ '</a>'
}));
contextTagList.appendChild(new Element('li', {
html: '<a href="javascript:torrentRemoveAllTagsFN();">'
+ '<img src="images/qbt-theme/edit-clear.svg" alt="QBT_TR(Remove All)QBT_TR[CONTEXT=TransferListWidget]"/>'
+ ' QBT_TR(Remove All)QBT_TR[CONTEXT=TransferListWidget]'
+ '</a>'
}));
const sortedTags = [];
for (const key in tagList)
sortedTags.push(tagList[key].name);
sortedTags.sort();
for (let i = 0; i < sortedTags.length; ++i) {
const tagName = sortedTags[i];
const tagHash = genHash(tagName);
const el = new Element('li', {
html: '<a href="#Tag/' + tagHash + '" onclick="event.preventDefault(); torrentSetTagsFN(\'' + tagHash + '\', !event.currentTarget.getElement(\'input[type=checkbox]\').checked);">'
+ '<input type="checkbox" onclick="this.checked = !this.checked;"> ' + escapeHtml(tagName)
+ '</a>'
});
if (i === 0)
el.addClass('separator');
contextTagList.appendChild(el);
}
}
});
var CategoriesFilterContextMenu = new Class({
const CategoriesFilterContextMenu = new Class({
Extends: ContextMenu,
updateMenuItems: function() {
var id = this.options.element.id;
const id = this.options.element.id;
if ((id != CATEGORIES_ALL) && (id != CATEGORIES_UNCATEGORIZED)) {
this.showItem('editCategory');
this.showItem('deleteCategory');
@ -437,13 +494,24 @@ var CategoriesFilterContextMenu = new Class({ @@ -437,13 +494,24 @@ var CategoriesFilterContextMenu = new Class({
}
});
var SearchPluginsTableContextMenu = new Class({
const TagsFilterContextMenu = new Class({
Extends: ContextMenu,
updateMenuItems: function() {
const id = this.options.element.id;
if ((id !== TAGS_ALL.toString()) && (id !== TAGS_UNTAGGED.toString()))
this.showItem('deleteTag');
else
this.hideItem('deleteTag');
}
});
const SearchPluginsTableContextMenu = new Class({
Extends: ContextMenu,
updateMenuItems: function() {
var enabledColumnIndex = function(text) {
var columns = $("searchPluginsTableFixedHeaderRow").getChildren("th");
for (var i = 0; i < columns.length; ++i)
const enabledColumnIndex = function(text) {
const columns = $("searchPluginsTableFixedHeaderRow").getChildren("th");
for (let i = 0; i < columns.length; ++i)
if (columns[i].get("html") === "Enabled")
return i;
};

32
src/webui/www/private/scripts/download.js

@ -23,10 +23,10 @@ @@ -23,10 +23,10 @@
'use strict';
var categories = {};
var defaultSavePath = "";
let categories = {};
let defaultSavePath = "";
var getCategories = function() {
const getCategories = function() {
new Request.JSON({
url: 'api/v2/torrents/categories',
noCache: true,
@ -34,9 +34,9 @@ var getCategories = function() { @@ -34,9 +34,9 @@ var getCategories = function() {
onSuccess: function(data) {
if (data) {
categories = data;
for (var i in data) {
var category = data[i];
var option = new Element("option");
for (const i in data) {
const category = data[i];
const option = new Element("option");
option.set('value', category.name);
option.set('html', category.name);
$('categorySelect').appendChild(option);
@ -46,7 +46,7 @@ var getCategories = function() { @@ -46,7 +46,7 @@ var getCategories = function() {
}).send();
};
var getPreferences = function() {
const getPreferences = function() {
new Request.JSON({
url: 'api/v2/app/preferences',
method: 'get',
@ -74,7 +74,7 @@ var getPreferences = function() { @@ -74,7 +74,7 @@ var getPreferences = function() {
}).send();
};
var changeCategorySelect = function(item) {
const changeCategorySelect = function(item) {
if (item.value == "\\other") {
item.nextElementSibling.hidden = false;
item.nextElementSibling.value = "";
@ -85,13 +85,13 @@ var changeCategorySelect = function(item) { @@ -85,13 +85,13 @@ var changeCategorySelect = function(item) {
}
else {
item.nextElementSibling.hidden = true;
var text = item.options[item.selectedIndex].innerHTML;
const text = item.options[item.selectedIndex].innerHTML;
item.nextElementSibling.value = text;
if ($('autoTMM').selectedIndex == 1) {
var categoryName = item.value;
var category = categories[categoryName];
var savePath = defaultSavePath;
const categoryName = item.value;
const category = categories[categoryName];
let savePath = defaultSavePath;
if (category !== undefined)
savePath = (category['savePath'] !== "") ? category['savePath'] : (defaultSavePath + categoryName);
$('savepath').value = savePath;
@ -99,13 +99,13 @@ var changeCategorySelect = function(item) { @@ -99,13 +99,13 @@ var changeCategorySelect = function(item) {
}
};
var changeTMM = function(item) {
const changeTMM = function(item) {
if (item.selectedIndex == 1) {
$('savepath').disabled = true;
var categorySelect = $('categorySelect');
var categoryName = categorySelect.options[categorySelect.selectedIndex].value;
var category = categories[categoryName];
const categorySelect = $('categorySelect');
const categoryName = categorySelect.options[categorySelect.selectedIndex].value;
const category = categories[categoryName];
$('savepath').value = (category === undefined) ? "" : category['savePath'];
}
else {

440
src/webui/www/private/scripts/dynamicTable.js

File diff suppressed because it is too large Load Diff

24
src/webui/www/private/scripts/misc.js

@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
* JS counterpart of the function in src/misc.cpp
*/
function friendlyUnit(value, isSpeed) {
var units = [
const units = [
"QBT_TR(B)QBT_TR[CONTEXT=misc]",
"QBT_TR(KiB)QBT_TR[CONTEXT=misc]",
"QBT_TR(MiB)QBT_TR[CONTEXT=misc]",
@ -45,7 +45,7 @@ function friendlyUnit(value, isSpeed) { @@ -45,7 +45,7 @@ function friendlyUnit(value, isSpeed) {
if ((value === undefined) || (value === null) || (value < 0))
return "QBT_TR(Unknown)QBT_TR[CONTEXT=misc]";
var i = 0;
let i = 0;
while (value >= 1024.0 && i < 6) {
value /= 1024.0;
++i;
@ -57,12 +57,12 @@ function friendlyUnit(value, isSpeed) { @@ -57,12 +57,12 @@ function friendlyUnit(value, isSpeed) {
else return 3; // TiB, PiB, EiB
}
var ret;
let ret;
if (i === 0)
ret = value + " " + units[i];
else {
var precision = friendlyUnitPrecision(i);
var offset = Math.pow(10, precision);
const precision = friendlyUnitPrecision(i);
const offset = Math.pow(10, precision);
// Don't round up
ret = (Math.floor(offset * value) / offset).toFixed(precision) + " " + units[i];
}
@ -76,21 +76,21 @@ function friendlyUnit(value, isSpeed) { @@ -76,21 +76,21 @@ function friendlyUnit(value, isSpeed) {
* JS counterpart of the function in src/misc.cpp
*/
function friendlyDuration(seconds) {
var MAX_ETA = 8640000;
const MAX_ETA = 8640000;
if (seconds < 0 || seconds >= MAX_ETA)
return "∞";
if (seconds === 0)
return "0";
if (seconds < 60)
return "QBT_TR(< 1m)QBT_TR[CONTEXT=misc]";
var minutes = seconds / 60;
let minutes = seconds / 60;
if (minutes < 60)
return "QBT_TR(%1m)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(minutes));
var hours = minutes / 60;
let hours = minutes / 60;
minutes = minutes % 60;
if (hours < 24)
return "QBT_TR(%1h %2m)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes));
var days = hours / 24;
const days = hours / 24;
hours = hours % 24;
if (days < 100)
return "QBT_TR(%1d %2h)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(days)).replace("%2", parseInt(hours));
@ -98,7 +98,7 @@ function friendlyDuration(seconds) { @@ -98,7 +98,7 @@ function friendlyDuration(seconds) {
}
function friendlyPercentage(value) {
var percentage = (value * 100).round(1);
let percentage = (value * 100).round(1);
if (isNaN(percentage) || (percentage < 0))
percentage = 0;
if (percentage > 100)
@ -141,12 +141,12 @@ if (!Date.prototype.toISOString) { @@ -141,12 +141,12 @@ if (!Date.prototype.toISOString) {
* JS counterpart of the function in src/misc.cpp
*/
function parseHtmlLinks(text) {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
const exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return text.replace(exp, "<a target='_blank' href='$1'>$1</a>");
}
function escapeHtml(str) {
var div = document.createElement('div');
const div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML;
}

352
src/webui/www/private/scripts/mocha-init.js

@ -53,51 +53,60 @@ if (typeof localStorage == 'undefined') { @@ -53,51 +53,60 @@ if (typeof localStorage == 'undefined') {
}
function getLocalStorageItem(name, defaultVal) {
var val = localStorage.getItem(name);
let val = localStorage.getItem(name);
if (val === null || val === undefined)
val = defaultVal;
return val;
}
var saveWindowSize = function() {};
var loadWindowWidth = function() {};
var loadWindowHeight = function() {};
var showDownloadPage = function() {};
var globalUploadLimitFN = function() {};
var uploadLimitFN = function() {};
var shareRatioFN = function() {};
var toggleSequentialDownloadFN = function() {};
var toggleFirstLastPiecePrioFN = function() {};
var setSuperSeedingFN = function() {};
var setForceStartFN = function() {};
var globalDownloadLimitFN = function() {};
var StatisticsLinkFN = function() {};
var downloadLimitFN = function() {};
var deleteFN = function() {};
var pauseFN = function() {};
var startFN = function() {};
var autoTorrentManagementFN = function() {};
var recheckFN = function() {};
var reannounceFN = function() {};
var setLocationFN = function() {};
var renameFN = function() {};
var torrentNewCategoryFN = function() {};
var torrentSetCategoryFN = function() {};
var createCategoryFN = function() {};
var editCategoryFN = function() {};
var removeCategoryFN = function() {};
var deleteUnusedCategoriesFN = function() {};
var startTorrentsByCategoryFN = function() {};
var pauseTorrentsByCategoryFN = function() {};
var deleteTorrentsByCategoryFN = function() {};
var copyNameFN = function() {};
var copyMagnetLinkFN = function() {};
var copyHashFN = function() {};
var setQueuePositionFN = function() {};
var initializeWindows = function() {
let saveWindowSize = function() {};
let loadWindowWidth = function() {};
let loadWindowHeight = function() {};
let showDownloadPage = function() {};
let globalUploadLimitFN = function() {};
let uploadLimitFN = function() {};
let shareRatioFN = function() {};
let toggleSequentialDownloadFN = function() {};
let toggleFirstLastPiecePrioFN = function() {};
let setSuperSeedingFN = function() {};
let setForceStartFN = function() {};
let globalDownloadLimitFN = function() {};
let StatisticsLinkFN = function() {};
let downloadLimitFN = function() {};
let deleteFN = function() {};
let pauseFN = function() {};
let startFN = function() {};
let autoTorrentManagementFN = function() {};
let recheckFN = function() {};
let reannounceFN = function() {};
let setLocationFN = function() {};
let renameFN = function() {};
let torrentNewCategoryFN = function() {};
let torrentSetCategoryFN = function() {};
let createCategoryFN = function() {};
let editCategoryFN = function() {};
let removeCategoryFN = function() {};
let deleteUnusedCategoriesFN = function() {};
let startTorrentsByCategoryFN = function() {};
let pauseTorrentsByCategoryFN = function() {};
let deleteTorrentsByCategoryFN = function() {};
let torrentAddTagsFN = function() {};
let torrentSetTagsFN = function() {};
let torrentRemoveAllTagsFN = function() {};
let createTagFN = function() {};
let removeTagFN = function() {};
let deleteUnusedTagsFN = function() {};
let startTorrentsByTagFN = function() {};
let pauseTorrentsByTagFN = function() {};
let deleteTorrentsByTagFN = function() {};
let copyNameFN = function() {};
let copyMagnetLinkFN = function() {};
let copyHashFN = function() {};
let setQueuePositionFN = function() {};
const initializeWindows = function() {
saveWindowSize = function(windowId) {
var size = $(windowId).getSize();
const size = $(windowId).getSize();
localStorage.setItem('window_' + windowId + '_width', size.x);
localStorage.setItem('window_' + windowId + '_height', size.y);
};
@ -124,8 +133,8 @@ var initializeWindows = function() { @@ -124,8 +133,8 @@ var initializeWindows = function() {
});
showDownloadPage = function(urls) {
var id = 'downloadPage';
var contentUrl = 'download.html';
const id = 'downloadPage';
let contentUrl = 'download.html';
if (urls && urls.length)
contentUrl += '?urls=' + urls.join("|");
@ -151,7 +160,7 @@ var initializeWindows = function() { @@ -151,7 +160,7 @@ var initializeWindows = function() {
addClickEvent('preferences', function(e) {
new Event(e).stop();
var id = 'preferencesPage';
const id = 'preferencesPage';
new MochaUI.Window({
id: id,
title: "QBT_TR(Options)QBT_TR[CONTEXT=OptionsDialog]",
@ -176,7 +185,7 @@ var initializeWindows = function() { @@ -176,7 +185,7 @@ var initializeWindows = function() {
addClickEvent('upload', function(e) {
new Event(e).stop();
var id = 'uploadPage';
const id = 'uploadPage';
new MochaUI.Window({
id: id,
title: "QBT_TR(Upload local torrent)QBT_TR[CONTEXT=HttpServer]",
@ -213,7 +222,7 @@ var initializeWindows = function() { @@ -213,7 +222,7 @@ var initializeWindows = function() {
};
uploadLimitFN = function() {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new MochaUI.Window({
id: 'uploadLimitPage',
@ -232,16 +241,16 @@ var initializeWindows = function() { @@ -232,16 +241,16 @@ var initializeWindows = function() {
};
shareRatioFN = function() {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
var shareRatio = null;
var torrentsHaveSameShareRatio = true;
let shareRatio = null;
let torrentsHaveSameShareRatio = true;
// check if all selected torrents have same share ratio
for (var i = 0; i < hashes.length; ++i) {
var hash = hashes[i];
var row = torrentsTable.rows[hash].full_data;
var origValues = row.ratio_limit + "|" + row.seeding_time_limit + "|" + row.max_ratio + "|" + row.max_seeding_time;
for (let i = 0; i < hashes.length; ++i) {
const hash = hashes[i];
const row = torrentsTable.rows[hash].full_data;
const origValues = row.ratio_limit + "|" + row.seeding_time_limit + "|" + row.max_ratio + "|" + row.max_seeding_time;
// initialize value
if (shareRatio === null)
@ -254,7 +263,7 @@ var initializeWindows = function() { @@ -254,7 +263,7 @@ var initializeWindows = function() {
}
// if all torrents have same share ratio, display that share ratio. else use the default
var orig = torrentsHaveSameShareRatio ? shareRatio : "";
const orig = torrentsHaveSameShareRatio ? shareRatio : "";
new MochaUI.Window({
id: 'shareRatioPage',
title: "QBT_TR(Torrent Upload/Download Ratio Limiting)QBT_TR[CONTEXT=UpDownRatioDialog]",
@ -271,7 +280,7 @@ var initializeWindows = function() { @@ -271,7 +280,7 @@ var initializeWindows = function() {
};
toggleSequentialDownloadFN = function() {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new Request({
url: 'api/v2/torrents/toggleSequentialDownload',
@ -285,7 +294,7 @@ var initializeWindows = function() { @@ -285,7 +294,7 @@ var initializeWindows = function() {
};
toggleFirstLastPiecePrioFN = function() {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new Request({
url: 'api/v2/torrents/toggleFirstLastPiecePrio',
@ -299,7 +308,7 @@ var initializeWindows = function() { @@ -299,7 +308,7 @@ var initializeWindows = function() {
};
setSuperSeedingFN = function(val) {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new Request({
url: 'api/v2/torrents/setSuperSeeding',
@ -314,7 +323,7 @@ var initializeWindows = function() { @@ -314,7 +323,7 @@ var initializeWindows = function() {
};
setForceStartFN = function() {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new Request({
url: 'api/v2/torrents/setForceStart',
@ -345,7 +354,7 @@ var initializeWindows = function() { @@ -345,7 +354,7 @@ var initializeWindows = function() {
};
StatisticsLinkFN = function() {
var id = 'statisticspage';
const id = 'statisticspage';
new MochaUI.Window({
id: id,
title: 'QBT_TR(Statistics)QBT_TR[CONTEXT=StatsDialog]',
@ -362,7 +371,7 @@ var initializeWindows = function() { @@ -362,7 +371,7 @@ var initializeWindows = function() {
};
downloadLimitFN = function() {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new MochaUI.Window({
id: 'downloadLimitPage',
@ -381,7 +390,7 @@ var initializeWindows = function() { @@ -381,7 +390,7 @@ var initializeWindows = function() {
};
deleteFN = function() {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new MochaUI.Window({
id: 'confirmDeletionPage',
@ -405,7 +414,7 @@ var initializeWindows = function() { @@ -405,7 +414,7 @@ var initializeWindows = function() {
});
pauseFN = function() {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new Request({
url: 'api/v2/torrents/pause',
@ -419,7 +428,7 @@ var initializeWindows = function() { @@ -419,7 +428,7 @@ var initializeWindows = function() {
};
startFN = function() {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new Request({
url: 'api/v2/torrents/resume',
@ -433,11 +442,11 @@ var initializeWindows = function() { @@ -433,11 +442,11 @@ var initializeWindows = function() {
};
autoTorrentManagementFN = function() {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
var enable = false;
let enable = false;
hashes.each(function(hash, index) {
var row = torrentsTable.rows[hash];
const row = torrentsTable.rows[hash];
if (!row.full_data.auto_tmm)
enable = true;
});
@ -454,7 +463,7 @@ var initializeWindows = function() { @@ -454,7 +463,7 @@ var initializeWindows = function() {
};
recheckFN = function() {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new Request({
url: 'api/v2/torrents/recheck',
@ -468,7 +477,7 @@ var initializeWindows = function() { @@ -468,7 +477,7 @@ var initializeWindows = function() {
};
reannounceFN = function() {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new Request({
url: 'api/v2/torrents/reannounce',
@ -482,11 +491,11 @@ var initializeWindows = function() { @@ -482,11 +491,11 @@ var initializeWindows = function() {
};
setLocationFN = function() {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
var hash = hashes[0];
var row = torrentsTable.rows[hash];
var path = encodeURIComponent(row.full_data.save_path);
const hash = hashes[0];
const row = torrentsTable.rows[hash];
const path = encodeURIComponent(row.full_data.save_path);
new MochaUI.Window({
id: 'setLocationPage',
title: "QBT_TR(Set location)QBT_TR[CONTEXT=TransferListWidget]",
@ -504,10 +513,10 @@ var initializeWindows = function() { @@ -504,10 +513,10 @@ var initializeWindows = function() {
};
renameFN = function() {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length == 1) {
var hash = hashes[0];
var row = torrentsTable.rows[hash];
const hash = hashes[0];
const row = torrentsTable.rows[hash];
if (row) {
new MochaUI.Window({
id: 'renamePage',
@ -527,8 +536,8 @@ var initializeWindows = function() { @@ -527,8 +536,8 @@ var initializeWindows = function() {
};
torrentNewCategoryFN = function() {
var action = "set";
var hashes = torrentsTable.selectedRowsIds();
const action = "set";
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new MochaUI.Window({
id: 'newCategoryPage',
@ -547,10 +556,10 @@ var initializeWindows = function() { @@ -547,10 +556,10 @@ var initializeWindows = function() {
};
torrentSetCategoryFN = function(categoryHash) {
var categoryName = '';
let categoryName = '';
if (categoryHash != 0)
categoryName = category_list[categoryHash].name;
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new Request({
url: 'api/v2/torrents/setCategory',
@ -564,7 +573,7 @@ var initializeWindows = function() { @@ -564,7 +573,7 @@ var initializeWindows = function() {
};
createCategoryFN = function() {
var action = "create";
const action = "create";
new MochaUI.Window({
id: 'newCategoryPage',
title: "QBT_TR(New Category)QBT_TR[CONTEXT=CategoryFilterWidget]",
@ -582,9 +591,9 @@ var initializeWindows = function() { @@ -582,9 +591,9 @@ var initializeWindows = function() {
};
editCategoryFN = function(categoryHash) {
var action = "edit";
var categoryName = category_list[categoryHash].name;
var savePath = category_list[categoryHash].savePath;
const action = "edit";
const categoryName = category_list[categoryHash].name;
const savePath = category_list[categoryHash].savePath;
new MochaUI.Window({
id: 'editCategoryPage',
title: "QBT_TR(Edit Category)QBT_TR[CONTEXT=TransferListWidget]",
@ -602,7 +611,7 @@ var initializeWindows = function() { @@ -602,7 +611,7 @@ var initializeWindows = function() {
};
removeCategoryFN = function(categoryHash) {
var categoryName = category_list[categoryHash].name;
const categoryName = category_list[categoryHash].name;
new Request({
url: 'api/v2/torrents/removeCategories',
method: 'post',
@ -614,9 +623,9 @@ var initializeWindows = function() { @@ -614,9 +623,9 @@ var initializeWindows = function() {
};
deleteUnusedCategoriesFN = function() {
var categories = [];
for (var hash in category_list) {
if (torrentsTable.getFilteredTorrentsNumber('all', hash) === 0)
const categories = [];
for (const hash in category_list) {
if (torrentsTable.getFilteredTorrentsNumber('all', hash, TAGS_ALL) === 0)
categories.push(category_list[hash].name);
}
new Request({
@ -630,7 +639,7 @@ var initializeWindows = function() { @@ -630,7 +639,7 @@ var initializeWindows = function() {
};
startTorrentsByCategoryFN = function(categoryHash) {
var hashes = torrentsTable.getFilteredTorrentsHashes('all', categoryHash);
const hashes = torrentsTable.getFilteredTorrentsHashes('all', categoryHash, TAGS_ALL);
if (hashes.length) {
new Request({
url: 'api/v2/torrents/resume',
@ -644,7 +653,7 @@ var initializeWindows = function() { @@ -644,7 +653,7 @@ var initializeWindows = function() {
};
pauseTorrentsByCategoryFN = function(categoryHash) {
var hashes = torrentsTable.getFilteredTorrentsHashes('all', categoryHash);
const hashes = torrentsTable.getFilteredTorrentsHashes('all', categoryHash, TAGS_ALL);
if (hashes.length) {
new Request({
url: 'api/v2/torrents/pause',
@ -658,7 +667,148 @@ var initializeWindows = function() { @@ -658,7 +667,148 @@ var initializeWindows = function() {
};
deleteTorrentsByCategoryFN = function(categoryHash) {
var hashes = torrentsTable.getFilteredTorrentsHashes('all', categoryHash);
const hashes = torrentsTable.getFilteredTorrentsHashes('all', categoryHash, TAGS_ALL);
if (hashes.length) {
new MochaUI.Window({
id: 'confirmDeletionPage',
title: "QBT_TR(Deletion confirmation)QBT_TR[CONTEXT=confirmDeletionDlg]",
loadMethod: 'iframe',
contentURL: 'confirmdeletion.html?hashes=' + hashes.join("|"),
scrollbars: false,
resizable: false,
maximizable: false,
padding: 10,
width: 424,
height: 140
});
updateMainData();
}
};
torrentAddTagsFN = function() {
const action = "set";
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new MochaUI.Window({
id: 'newTagPage',
title: "QBT_TR(Add Tags)QBT_TR[CONTEXT=TransferListWidget]",
loadMethod: 'iframe',
contentURL: 'newtag.html?action=' + action + '&hashes=' + hashes.join('|'),
scrollbars: false,
resizable: false,
maximizable: false,
paddingVertical: 0,
paddingHorizontal: 0,
width: 250,
height: 100
});
}
};
torrentSetTagsFN = function(tagHash, isSet) {
const tagName = ((tagHash === '0') ? '' : tagList[tagHash].name);
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new Request({
url: (isSet ? 'api/v2/torrents/addTags' : 'api/v2/torrents/removeTags'),
method: 'post',
data: {
hashes: hashes.join("|"),
tags: tagName,
}
}).send();
}
};
torrentRemoveAllTagsFN = function() {
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new Request({
url: ('api/v2/torrents/removeTags'),
method: 'post',
data: {
hashes: hashes.join("|"),
}
}).send();
}
};
createTagFN = function() {
const action = "create";
new MochaUI.Window({
id: 'newTagPage',
title: "QBT_TR(New Tag)QBT_TR[CONTEXT=TagFilterWidget]",
loadMethod: 'iframe',
contentURL: 'newtag.html?action=' + action,
scrollbars: false,
resizable: false,
maximizable: false,
paddingVertical: 0,
paddingHorizontal: 0,
width: 250,
height: 100
});
updateMainData();
};
removeTagFN = function(tagHash) {
const tagName = tagList[tagHash].name;
new Request({
url: 'api/v2/torrents/deleteTags',
method: 'post',
data: {
tags: tagName
}
}).send();
setTagFilter(TAGS_ALL);
};
deleteUnusedTagsFN = function() {
const tags = [];
for (const hash in tagList) {
if (torrentsTable.getFilteredTorrentsNumber('all', CATEGORIES_ALL, hash) === 0)
tags.push(tagList[hash].name);
}
new Request({
url: 'api/v2/torrents/deleteTags',
method: 'post',
data: {
tags: tags.join(',')
}
}).send();
setTagFilter(TAGS_ALL);
};
startTorrentsByTagFN = function(tagHash) {
const hashes = torrentsTable.getFilteredTorrentsHashes('all', CATEGORIES_ALL, tagHash);
if (hashes.length) {
new Request({
url: 'api/v2/torrents/resume',
method: 'post',
data: {
hashes: hashes.join("|")
}
}).send();
updateMainData();
}
};
pauseTorrentsByTagFN = function(tagHash) {
const hashes = torrentsTable.getFilteredTorrentsHashes('all', CATEGORIES_ALL, tagHash);
if (hashes.length) {
new Request({
url: 'api/v2/torrents/pause',
method: 'post',
data: {
hashes: hashes.join("|")
}
}).send();
updateMainData();
}
};
deleteTorrentsByTagFN = function(tagHash) {
const hashes = torrentsTable.getFilteredTorrentsHashes('all', CATEGORIES_ALL, tagHash);
if (hashes.length) {
new MochaUI.Window({
id: 'confirmDeletionPage',
@ -677,12 +827,12 @@ var initializeWindows = function() { @@ -677,12 +827,12 @@ var initializeWindows = function() {
};
copyNameFN = function() {
var selectedRows = torrentsTable.selectedRowsIds();
var names = [];
const selectedRows = torrentsTable.selectedRowsIds();
const names = [];
if (selectedRows.length) {
var rows = torrentsTable.getFilteredAndSortedRows();
for (var i = 0; i < selectedRows.length; ++i) {
var hash = selectedRows[i];
const rows = torrentsTable.getFilteredAndSortedRows();
for (let i = 0; i < selectedRows.length; ++i) {
const hash = selectedRows[i];
names.push(rows[hash].full_data.name);
}
}
@ -690,12 +840,12 @@ var initializeWindows = function() { @@ -690,12 +840,12 @@ var initializeWindows = function() {
};
copyMagnetLinkFN = function() {
var selectedRows = torrentsTable.selectedRowsIds();
var magnets = [];
const selectedRows = torrentsTable.selectedRowsIds();
const magnets = [];
if (selectedRows.length) {
var rows = torrentsTable.getFilteredAndSortedRows();
for (var i = 0; i < selectedRows.length; ++i) {
var hash = selectedRows[i];
const rows = torrentsTable.getFilteredAndSortedRows();
for (let i = 0; i < selectedRows.length; ++i) {
const hash = selectedRows[i];
magnets.push(rows[hash].full_data.magnet_uri);
}
}
@ -723,7 +873,7 @@ var initializeWindows = function() { @@ -723,7 +873,7 @@ var initializeWindows = function() {
['pause', 'resume', 'recheck'].each(function(item) {
addClickEvent(item, function(e) {
new Event(e).stop();
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
hashes.each(function(hash, index) {
new Request({
@ -747,7 +897,7 @@ var initializeWindows = function() { @@ -747,7 +897,7 @@ var initializeWindows = function() {
});
setQueuePositionFN = function(cmd) {
var hashes = torrentsTable.selectedRowsIds();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new Request({
url: 'api/v2/torrents/' + cmd,
@ -762,7 +912,7 @@ var initializeWindows = function() { @@ -762,7 +912,7 @@ var initializeWindows = function() {
addClickEvent('about', function(e) {
new Event(e).stop();
var id = 'aboutpage';
const id = 'aboutpage';
new MochaUI.Window({
id: id,
title: 'QBT_TR(About qBittorrent)QBT_TR[CONTEXT=AboutDialog]',

14
src/webui/www/private/scripts/progressbar.js

@ -28,9 +28,9 @@ @@ -28,9 +28,9 @@
'use strict';
var ProgressBar = new Class({
const ProgressBar = new Class({
initialize: function(value, parameters) {
var vals = {
const vals = {
'id': 'progressbar_' + (ProgressBars++),
'value': $pick(value, 0),
'width': 0,
@ -42,7 +42,7 @@ var ProgressBar = new Class({ @@ -42,7 +42,7 @@ var ProgressBar = new Class({
};
if (parameters && $type(parameters) == 'object') $extend(vals, parameters);
if (vals.height < 12) vals.height = 12;
var obj = new Element('div', {
const obj = new Element('div', {
'id': vals.id,
'class': 'progressbar_wrapper',
'styles': {
@ -110,7 +110,7 @@ function ProgressBar_setValue(value) { @@ -110,7 +110,7 @@ function ProgressBar_setValue(value) {
this.vals.light.empty();
this.vals.dark.appendText(value.round(1).toFixed(1) + '%');
this.vals.light.appendText(value.round(1).toFixed(1) + '%');
var r = parseInt(this.vals.width * (value / 100));
const r = parseInt(this.vals.width * (value / 100));
this.vals.dark.setStyle('clip', 'rect(0,' + r + 'px,' + this.vals.height + 'px,0)');
this.vals.light.setStyle('clip', 'rect(0,' + this.vals.width + 'px,' + this.vals.height + 'px,' + r + 'px)');
}
@ -126,15 +126,15 @@ function ProgressBar_setWidth(value) { @@ -126,15 +126,15 @@ function ProgressBar_setWidth(value) {
}
function ProgressBar_checkForParent(id) {
var obj = $(id);
const obj = $(id);
if (!obj) return;
if (!obj.parentNode) return setTimeout('ProgressBar_checkForParent("' + id + '")', 1);
obj.setStyle('width', '100%');
var w = obj.offsetWidth;
const w = obj.offsetWidth;
obj.vals.dark.setStyle('width', w);
obj.vals.light.setStyle('width', w);
obj.vals.width = w;
obj.setValue(obj.vals.value);
}
var ProgressBars = 0;
let ProgressBars = 0;

124
src/webui/www/private/scripts/prop-files.js

@ -28,10 +28,10 @@ @@ -28,10 +28,10 @@
'use strict';
var is_seed = true;
var current_hash = "";
let is_seed = true;
this.current_hash = "";
var FilePriority = {
const FilePriority = {
"Ignored": 0,
"Normal": 1,
"High": 6,
@ -39,7 +39,7 @@ var FilePriority = { @@ -39,7 +39,7 @@ var FilePriority = {
"Mixed": -1
};
var normalizePriority = function(priority) {
const normalizePriority = function(priority) {
switch (priority) {
case FilePriority.Ignored:
case FilePriority.Normal:
@ -52,30 +52,30 @@ var normalizePriority = function(priority) { @@ -52,30 +52,30 @@ var normalizePriority = function(priority) {
}
};
var fileCheckboxChanged = function(e) {
var checkbox = e.target;
var priority = checkbox.checked ? FilePriority.Normal : FilePriority.Ignored;
var id = checkbox.get('data-id');
const fileCheckboxChanged = function(e) {
const checkbox = e.target;
const priority = checkbox.checked ? FilePriority.Normal : FilePriority.Ignored;
const id = checkbox.get('data-id');
setFilePriority(id, priority);
setGlobalCheckboxState();
return true;
};
var fileComboboxChanged = function(e) {
var combobox = e.target;
var newPriority = combobox.value;
var id = combobox.get('data-id');
const fileComboboxChanged = function(e) {
const combobox = e.target;
const newPriority = combobox.value;
const id = combobox.get('data-id');
setFilePriority(id, newPriority);
};
var isDownloadCheckboxExists = function(id) {
const isDownloadCheckboxExists = function(id) {
return ($('cbPrio' + id) !== null);
};
var createDownloadCheckbox = function(id, download) {
var checkbox = new Element('input');
const createDownloadCheckbox = function(id, download) {
const checkbox = new Element('input');
checkbox.set('type', 'checkbox');
if (download)
checkbox.set('checked', 'checked');
@ -86,17 +86,17 @@ var createDownloadCheckbox = function(id, download) { @@ -86,17 +86,17 @@ var createDownloadCheckbox = function(id, download) {
return checkbox;
};
var updateDownloadCheckbox = function(id, download) {
var checkbox = $('cbPrio' + id);
const updateDownloadCheckbox = function(id, download) {
const checkbox = $('cbPrio' + id);
checkbox.checked = download;
};
var isPriorityComboExists = function(id) {
const isPriorityComboExists = function(id) {
return ($('comboPrio' + id) !== null);
};
var createPriorityOptionElement = function(priority, selected, html) {
var elem = new Element('option');
const createPriorityOptionElement = function(priority, selected, html) {
const elem = new Element('option');
elem.set('value', priority.toString());
elem.set('html', html);
if (selected)
@ -104,8 +104,8 @@ var createPriorityOptionElement = function(priority, selected, html) { @@ -104,8 +104,8 @@ var createPriorityOptionElement = function(priority, selected, html) {
return elem;
};
var createPriorityCombo = function(id, selectedPriority) {
var select = new Element('select');
const createPriorityCombo = function(id, selectedPriority) {
const select = new Element('select');
select.set('id', 'comboPrio' + id);
select.set('data-id', id);
select.set('disabled', is_seed);
@ -120,8 +120,8 @@ var createPriorityCombo = function(id, selectedPriority) { @@ -120,8 +120,8 @@ var createPriorityCombo = function(id, selectedPriority) {
return select;
};
var updatePriorityCombo = function(id, selectedPriority) {
var combobox = $('comboPrio' + id);
const updatePriorityCombo = function(id, selectedPriority) {
const combobox = $('comboPrio' + id);
if (parseInt(combobox.value) !== selectedPriority)
selectComboboxPriority(combobox, selectedPriority);
@ -130,10 +130,10 @@ var updatePriorityCombo = function(id, selectedPriority) { @@ -130,10 +130,10 @@ var updatePriorityCombo = function(id, selectedPriority) {
combobox.disabled = is_seed;
};
var selectComboboxPriority = function(combobox, priority) {
var options = combobox.options;
for (var i = 0; i < options.length; ++i) {
var option = options[i];
const selectComboboxPriority = function(combobox, priority) {
const options = combobox.options;
for (let i = 0; i < options.length; ++i) {
const option = options[i];
if (parseInt(option.value) === priority)
option.setAttribute('selected', '');
else
@ -143,9 +143,9 @@ var selectComboboxPriority = function(combobox, priority) { @@ -143,9 +143,9 @@ var selectComboboxPriority = function(combobox, priority) {
combobox.value = priority;
};
var switchCheckboxState = function() {
var rows = [];
var priority = FilePriority.Ignored;
const switchCheckboxState = function() {
const rows = [];
let priority = FilePriority.Ignored;
if ($('tristate_cb').state === "checked") {
setGlobalCheckboxUnchecked();
@ -169,7 +169,7 @@ var switchCheckboxState = function() { @@ -169,7 +169,7 @@ var switchCheckboxState = function() {
setFilePriority(rows, priority);
};
var setGlobalCheckboxState = function() {
const setGlobalCheckboxState = function() {
if (isAllCheckboxesChecked())
setGlobalCheckboxChecked();
else if (isAllCheckboxesUnchecked())
@ -178,44 +178,44 @@ var setGlobalCheckboxState = function() { @@ -178,44 +178,44 @@ var setGlobalCheckboxState = function() {
setGlobalCheckboxPartial();
};
var setGlobalCheckboxChecked = function() {
const setGlobalCheckboxChecked = function() {
$('tristate_cb').state = "checked";
$('tristate_cb').indeterminate = false;
$('tristate_cb').checked = true;
};
var setGlobalCheckboxUnchecked = function() {
const setGlobalCheckboxUnchecked = function() {
$('tristate_cb').state = "unchecked";
$('tristate_cb').indeterminate = false;
$('tristate_cb').checked = false;
};
var setGlobalCheckboxPartial = function() {
const setGlobalCheckboxPartial = function() {
$('tristate_cb').state = "partial";
$('tristate_cb').indeterminate = true;
};
var isAllCheckboxesChecked = function() {
var checkboxes = $$('input.DownloadedCB');
for (var i = 0; i < checkboxes.length; ++i) {
const isAllCheckboxesChecked = function() {
const checkboxes = $$('input.DownloadedCB');
for (let i = 0; i < checkboxes.length; ++i) {
if (!checkboxes[i].checked)
return false;
}
return true;
};
var isAllCheckboxesUnchecked = function() {
var checkboxes = $$('input.DownloadedCB');
for (var i = 0; i < checkboxes.length; ++i) {
const isAllCheckboxesUnchecked = function() {
const checkboxes = $$('input.DownloadedCB');
for (let i = 0; i < checkboxes.length; ++i) {
if (checkboxes[i].checked)
return false;
}
return true;
};
var setFilePriority = function(id, priority) {
const setFilePriority = function(id, priority) {
if (current_hash === "") return;
var ids = Array.isArray(id) ? id : [id];
const ids = Array.isArray(id) ? id : [id];
clearTimeout(loadTorrentFilesDataTimer);
new Request({
@ -232,20 +232,20 @@ var setFilePriority = function(id, priority) { @@ -232,20 +232,20 @@ var setFilePriority = function(id, priority) {
}).send();
ids.forEach(function(_id) {
var combobox = $('comboPrio' + _id);
const combobox = $('comboPrio' + _id);
if (combobox !== null)
selectComboboxPriority(combobox, priority);
});
};
var loadTorrentFilesDataTimer;
var loadTorrentFilesData = function() {
let loadTorrentFilesDataTimer;
const loadTorrentFilesData = function() {
if ($('prop_files').hasClass('invisible')
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
// Tab changed, don't do anything
return;
}
var new_hash = torrentsTable.getCurrentTorrentHash();
const new_hash = torrentsTable.getCurrentTorrentHash();
if (new_hash === "") {
torrentFilesTable.clear();
clearTimeout(loadTorrentFilesDataTimer);
@ -256,7 +256,7 @@ var loadTorrentFilesData = function() { @@ -256,7 +256,7 @@ var loadTorrentFilesData = function() {
torrentFilesTable.clear();
current_hash = new_hash;
}
var url = new URI('api/v2/torrents/files?hash=' + current_hash);
const url = new URI('api/v2/torrents/files?hash=' + current_hash);
new Request.JSON({
url: url,
noCache: true,
@ -266,19 +266,19 @@ var loadTorrentFilesData = function() { @@ -266,19 +266,19 @@ var loadTorrentFilesData = function() {
loadTorrentFilesDataTimer = loadTorrentFilesData.delay(5000);
},
onSuccess: function(files) {
var selectedFiles = torrentFilesTable.selectedRowsIds();
const selectedFiles = torrentFilesTable.selectedRowsIds();
if (!files) {
torrentFilesTable.clear();
return;
}
var i = 0;
let i = 0;
files.each(function(file) {
if (i === 0)
is_seed = file.is_seed;
var row = {
const row = {
rowId: i,
checked: (file.priority !== FilePriority.Ignored),
name: escapeHtml(file.name),
@ -307,35 +307,35 @@ var loadTorrentFilesData = function() { @@ -307,35 +307,35 @@ var loadTorrentFilesData = function() {
}).send();
};
var updateTorrentFilesData = function() {
updateTorrentFilesData = function() {
clearTimeout(loadTorrentFilesDataTimer);
loadTorrentFilesData();
};
var torrentFilesContextMenu = new ContextMenu({
const torrentFilesContextMenu = new ContextMenu({
targets: '#torrentFilesTableDiv tr',
menu: 'torrentFilesMenu',
actions: {
FilePrioIgnore: function(element, ref) {
var selectedRows = torrentFilesTable.selectedRowsIds();
const selectedRows = torrentFilesTable.selectedRowsIds();
if (selectedRows.length === 0) return;
setFilePriority(selectedRows, FilePriority.Ignored);
},
FilePrioNormal: function(element, ref) {
var selectedRows = torrentFilesTable.selectedRowsIds();
const selectedRows = torrentFilesTable.selectedRowsIds();
if (selectedRows.length === 0) return;
setFilePriority(selectedRows, FilePriority.Normal);
},
FilePrioHigh: function(element, ref) {
var selectedRows = torrentFilesTable.selectedRowsIds();
const selectedRows = torrentFilesTable.selectedRowsIds();
if (selectedRows.length === 0) return;
setFilePriority(selectedRows, FilePriority.High);
},
FilePrioMaximum: function(element, ref) {
var selectedRows = torrentFilesTable.selectedRowsIds();
const selectedRows = torrentFilesTable.selectedRowsIds();
if (selectedRows.length === 0) return;
setFilePriority(selectedRows, FilePriority.Maximum);
@ -346,8 +346,6 @@ var torrentFilesContextMenu = new ContextMenu({ @@ -346,8 +346,6 @@ var torrentFilesContextMenu = new ContextMenu({
y: 2
},
onShow: function() {
var selectedRows = torrentFilesTable.selectedRowsIds();
if (is_seed)
this.hideItem('FilePrio');
else
@ -357,17 +355,17 @@ var torrentFilesContextMenu = new ContextMenu({ @@ -357,17 +355,17 @@ var torrentFilesContextMenu = new ContextMenu({
torrentFilesTable.setup('torrentFilesTableDiv', 'torrentFilesTableFixedHeaderDiv', torrentFilesContextMenu);
// inject checkbox into table header
var tableHeaders = $$('#torrentFilesTableFixedHeaderDiv .dynamicTableHeader th');
const tableHeaders = $$('#torrentFilesTableFixedHeaderDiv .dynamicTableHeader th');
if (tableHeaders.length > 0) {
var checkbox = new Element('input');
const checkbox = new Element('input');
checkbox.set('type', 'checkbox');
checkbox.set('id', 'tristate_cb');
checkbox.addEvent('click', switchCheckboxState);
var checkboxTH = tableHeaders[0];
const checkboxTH = tableHeaders[0];
checkbox.injectInside(checkboxTH);
}
// default sort by name column
if (torrentFilesTable.getSortedColunn() === null)
if (torrentFilesTable.getSortedColumn() === null)
torrentFilesTable.setSortedColumn('name');

14
src/webui/www/private/scripts/prop-general.js

@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
'use strict';
var clearData = function() {
const clearData = function() {
$('time_elapsed').set('html', '');
$('eta').set('html', '');
$('nb_connections').set('html', '');
@ -55,14 +55,14 @@ var clearData = function() { @@ -55,14 +55,14 @@ var clearData = function() {
$('comment').set('html', '');
};
var loadTorrentDataTimer;
var loadTorrentData = function() {
let loadTorrentDataTimer;
const loadTorrentData = function() {
if ($('prop_general').hasClass('invisible')
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
// Tab changed, don't do anything
return;
}
var current_hash = torrentsTable.getCurrentTorrentHash();
const current_hash = torrentsTable.getCurrentTorrentHash();
if (current_hash === "") {
clearData();
clearTimeout(loadTorrentDataTimer);
@ -71,7 +71,7 @@ var loadTorrentData = function() { @@ -71,7 +71,7 @@ var loadTorrentData = function() {
}
// Display hash
$('torrent_hash').set('html', current_hash);
var url = new URI('api/v2/torrents/properties?hash=' + current_hash);
const url = new URI('api/v2/torrents/properties?hash=' + current_hash);
new Request.JSON({
url: url,
noCache: true,
@ -84,7 +84,7 @@ var loadTorrentData = function() { @@ -84,7 +84,7 @@ var loadTorrentData = function() {
onSuccess: function(data) {
$('error_div').set('html', '');
if (data) {
var temp;
let temp;
// Update Torrent data
if (data.seeding_time > 0)
temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]"
@ -193,7 +193,7 @@ var loadTorrentData = function() { @@ -193,7 +193,7 @@ var loadTorrentData = function() {
}).send();
};
var updateTorrentData = function() {
updateTorrentData = function() {
clearTimeout(loadTorrentDataTimer);
loadTorrentData();
};

16
src/webui/www/private/scripts/prop-peers.js

@ -28,17 +28,17 @@ @@ -28,17 +28,17 @@
'use strict';
var loadTorrentPeersTimer;
var syncTorrentPeersLastResponseId = 0;
var show_flags = true;
var loadTorrentPeersData = function() {
let loadTorrentPeersTimer;
let syncTorrentPeersLastResponseId = 0;
let show_flags = true;
const loadTorrentPeersData = function() {
if ($('prop_peers').hasClass('invisible')
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
syncTorrentPeersLastResponseId = 0;
torrentPeersTable.clear();
return;
}
var current_hash = torrentsTable.getCurrentTorrentHash();
const current_hash = torrentsTable.getCurrentTorrentHash();
if (current_hash === "") {
syncTorrentPeersLastResponseId = 0;
torrentPeersTable.clear();
@ -46,7 +46,7 @@ var loadTorrentPeersData = function() { @@ -46,7 +46,7 @@ var loadTorrentPeersData = function() {
loadTorrentPeersTimer = loadTorrentPeersData.delay(getSyncMainDataInterval());
return;
}
var url = new URI('api/v2/sync/torrentPeers');
const url = new URI('api/v2/sync/torrentPeers');
url.setData('rid', syncTorrentPeersLastResponseId);
url.setData('hash', current_hash);
new Request.JSON({
@ -60,13 +60,13 @@ var loadTorrentPeersData = function() { @@ -60,13 +60,13 @@ var loadTorrentPeersData = function() {
onSuccess: function(response) {
$('error_div').set('html', '');
if (response) {
var full_update = (response['full_update'] === true);
const full_update = (response['full_update'] === true);
if (full_update)
torrentPeersTable.clear();
if (response['rid'])
syncTorrentPeersLastResponseId = response['rid'];
if (response['peers']) {
for (var key in response['peers']) {
for (const key in response['peers']) {
response['peers'][key]['rowId'] = key;
if (response['peers'][key]['client'])

36
src/webui/www/private/scripts/prop-trackers.js

@ -28,16 +28,16 @@ @@ -28,16 +28,16 @@
'use strict';
var current_hash = "";
this.current_hash = "";
var loadTrackersDataTimer;
var loadTrackersData = function() {
let loadTrackersDataTimer;
const loadTrackersData = function() {
if ($('prop_trackers').hasClass('invisible')
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
// Tab changed, don't do anything
return;
}
var new_hash = torrentsTable.getCurrentTorrentHash();
const new_hash = torrentsTable.getCurrentTorrentHash();
if (new_hash === "") {
torrentTrackersTable.clear();
clearTimeout(loadTrackersDataTimer);
@ -48,7 +48,7 @@ var loadTrackersData = function() { @@ -48,7 +48,7 @@ var loadTrackersData = function() {
torrentTrackersTable.clear();
current_hash = new_hash;
}
var url = new URI('api/v2/torrents/trackers?hash=' + current_hash);
const url = new URI('api/v2/torrents/trackers?hash=' + current_hash);
new Request.JSON({
url: url,
noCache: true,
@ -58,13 +58,13 @@ var loadTrackersData = function() { @@ -58,13 +58,13 @@ var loadTrackersData = function() {
loadTrackersDataTimer = loadTrackersData.delay(10000);
},
onSuccess: function(trackers) {
var selectedTrackers = torrentTrackersTable.selectedRowsIds();
const selectedTrackers = torrentTrackersTable.selectedRowsIds();
torrentTrackersTable.clear();
if (trackers) {
trackers.each(function(tracker) {
var url = escapeHtml(tracker.url);
var status;
const url = escapeHtml(tracker.url);
let status;
switch (tracker.status) {
case 0:
status = "QBT_TR(Disabled)QBT_TR[CONTEXT=TrackerListWidget]";
@ -83,7 +83,7 @@ var loadTrackersData = function() { @@ -83,7 +83,7 @@ var loadTrackersData = function() {
break;
}
var row = {
const row = {
rowId: url,
tier: tracker.tier,
url: url,
@ -108,12 +108,12 @@ var loadTrackersData = function() { @@ -108,12 +108,12 @@ var loadTrackersData = function() {
}).send();
};
var updateTrackersData = function() {
updateTrackersData = function() {
clearTimeout(loadTrackersDataTimer);
loadTrackersData();
};
var torrentTrackersContextMenu = new ContextMenu({
const torrentTrackersContextMenu = new ContextMenu({
targets: '#torrentTrackersTableDiv',
menu: 'torrentTrackersMenu',
actions: {
@ -134,8 +134,8 @@ var torrentTrackersContextMenu = new ContextMenu({ @@ -134,8 +134,8 @@ var torrentTrackersContextMenu = new ContextMenu({
y: 2
},
onShow: function() {
var selectedTrackers = torrentTrackersTable.selectedRowsIds();
var containsStaticTracker = selectedTrackers.some(function(tracker) {
const selectedTrackers = torrentTrackersTable.selectedRowsIds();
const containsStaticTracker = selectedTrackers.some(function(tracker) {
return (tracker.indexOf("** [") === 0);
});
@ -152,7 +152,7 @@ var torrentTrackersContextMenu = new ContextMenu({ @@ -152,7 +152,7 @@ var torrentTrackersContextMenu = new ContextMenu({
}
});
var addTrackerFN = function() {
const addTrackerFN = function() {
if (current_hash.length === 0) return;
new MochaUI.Window({
id: 'trackersPage',
@ -173,10 +173,10 @@ var addTrackerFN = function() { @@ -173,10 +173,10 @@ var addTrackerFN = function() {
});
};
var editTrackerFN = function(element) {
const editTrackerFN = function(element) {
if (current_hash.length === 0) return;
var trackerUrl = encodeURIComponent(element.childNodes[1].innerText);
const trackerUrl = encodeURIComponent(element.childNodes[1].innerText);
new MochaUI.Window({
id: 'trackersPage',
title: "QBT_TR(Tracker editing)QBT_TR[CONTEXT=TrackerListWidget]",
@ -196,10 +196,10 @@ var editTrackerFN = function(element) { @@ -196,10 +196,10 @@ var editTrackerFN = function(element) {
});
};
var removeTrackerFN = function(element) {
const removeTrackerFN = function(element) {
if (current_hash.length === 0) return;
var selectedTrackers = torrentTrackersTable.selectedRowsIds();
const selectedTrackers = torrentTrackersTable.selectedRowsIds();
new Request({
url: 'api/v2/torrents/removeTrackers',
method: 'post',

34
src/webui/www/private/scripts/prop-webseeds.js

@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
'use strict';
var webseedsDynTable = new Class({
const webseedsDynTable = new Class({
initialize: function() {},
@ -39,7 +39,7 @@ var webseedsDynTable = new Class({ @@ -39,7 +39,7 @@ var webseedsDynTable = new Class({
removeRow: function(url) {
if (this.rows.has(url)) {
var tr = this.rows.get(url);
const tr = this.rows.get(url);
tr.dispose();
this.rows.erase(url);
return true;
@ -54,25 +54,25 @@ var webseedsDynTable = new Class({ @@ -54,25 +54,25 @@ var webseedsDynTable = new Class({
},
updateRow: function(tr, row) {
var tds = tr.getElements('td');
for (var i = 0; i < row.length; ++i) {
const tds = tr.getElements('td');
for (let i = 0; i < row.length; ++i) {
tds[i].set('html', row[i]);
}
return true;
},
insertRow: function(row) {
var url = row[0];
const url = row[0];
if (this.rows.has(url)) {
var tableRow = this.rows.get(url);
const tableRow = this.rows.get(url);
this.updateRow(tableRow, row);
return;
}
//this.removeRow(id);
var tr = new Element('tr');
const tr = new Element('tr');
this.rows.set(url, tr);
for (var i = 0; i < row.length; ++i) {
var td = new Element('td');
for (let i = 0; i < row.length; ++i) {
const td = new Element('td');
td.set('html', row[i]);
td.injectInside(tr);
}
@ -80,16 +80,16 @@ var webseedsDynTable = new Class({ @@ -80,16 +80,16 @@ var webseedsDynTable = new Class({
},
});
var current_hash = "";
this.current_hash = "";
var loadWebSeedsDataTimer;
var loadWebSeedsData = function() {
let loadWebSeedsDataTimer;
const loadWebSeedsData = function() {
if ($('prop_webseeds').hasClass('invisible')
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
// Tab changed, don't do anything
return;
}
var new_hash = torrentsTable.getCurrentTorrentHash();
const new_hash = torrentsTable.getCurrentTorrentHash();
if (new_hash === "") {
wsTable.removeAllRows();
clearTimeout(loadWebSeedsDataTimer);
@ -100,7 +100,7 @@ var loadWebSeedsData = function() { @@ -100,7 +100,7 @@ var loadWebSeedsData = function() {
wsTable.removeAllRows();
current_hash = new_hash;
}
var url = new URI('api/v2/torrents/webseeds?hash=' + current_hash);
const url = new URI('api/v2/torrents/webseeds?hash=' + current_hash);
new Request.JSON({
url: url,
noCache: true,
@ -115,7 +115,7 @@ var loadWebSeedsData = function() { @@ -115,7 +115,7 @@ var loadWebSeedsData = function() {
if (webseeds) {
// Update WebSeeds data
webseeds.each(function(webseed) {
var row = [];
const row = [];
row.length = 1;
row[0] = webseed.url;
wsTable.insertRow(row);
@ -130,10 +130,10 @@ var loadWebSeedsData = function() { @@ -130,10 +130,10 @@ var loadWebSeedsData = function() {
}).send();
};
var updateWebSeedsData = function() {
updateWebSeedsData = function() {
clearTimeout(loadWebSeedsDataTimer);
loadWebSeedsData();
};
var wsTable = new webseedsDynTable();
const wsTable = new webseedsDynTable();
wsTable.setup($('webseedsTable'));

40
src/webui/www/private/scripts/speedslider.js

@ -31,17 +31,15 @@ @@ -31,17 +31,15 @@
MochaUI.extend({
addUpLimitSlider: function(hashes) {
if ($('uplimitSliderarea')) {
var windowOptions = MochaUI.Windows.windowOptions;
var sliderFirst = true;
// Get global upload limit
var maximum = 500;
var req = new Request({
let maximum = 500;
new Request({
url: 'api/v2/transfer/uploadLimit',
method: 'post',
data: {},
onSuccess: function(data) {
if (data) {
var tmp = data.toInt();
const tmp = data.toInt();
if (tmp > 0) {
maximum = tmp / 1024.0;
}
@ -55,10 +53,10 @@ MochaUI.extend({ @@ -55,10 +53,10 @@ MochaUI.extend({
// Get torrents upload limit
// And create slider
if (hashes[0] == 'global') {
var up_limit = maximum;
let up_limit = maximum;
if (up_limit < 0) up_limit = 0;
maximum = 10000;
var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), {
new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), {
steps: maximum,
offset: 0,
initialStep: up_limit.round(),
@ -84,7 +82,7 @@ MochaUI.extend({ @@ -84,7 +82,7 @@ MochaUI.extend({
}
}
else {
var req = new Request.JSON({
new Request.JSON({
url: 'api/v2/torrents/uploadLimit',
noCache : true,
method: 'post',
@ -93,14 +91,14 @@ MochaUI.extend({ @@ -93,14 +91,14 @@ MochaUI.extend({
},
onSuccess: function(data) {
if (data) {
var up_limit = data[hashes[0]];
for(var key in data)
let up_limit = data[hashes[0]];
for(const key in data)
if (up_limit != data[key]) {
up_limit = 0;
break;
}
if (up_limit < 0) up_limit = 0;
var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), {
new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), {
steps: maximum,
offset: 0,
initialStep: (up_limit / 1024.0).round(),
@ -135,17 +133,15 @@ MochaUI.extend({ @@ -135,17 +133,15 @@ MochaUI.extend({
addDlLimitSlider: function(hashes) {
if ($('dllimitSliderarea')) {
var windowOptions = MochaUI.Windows.windowOptions;
var sliderFirst = true;
// Get global upload limit
var maximum = 500;
var req = new Request({
let maximum = 500;
new Request({
url: 'api/v2/transfer/downloadLimit',
method: 'post',
data: {},
onSuccess: function(data) {
if (data) {
var tmp = data.toInt();
const tmp = data.toInt();
if (tmp > 0) {
maximum = tmp / 1024.0;
}
@ -159,10 +155,10 @@ MochaUI.extend({ @@ -159,10 +155,10 @@ MochaUI.extend({
// Get torrents download limit
// And create slider
if (hashes[0] == 'global') {
var dl_limit = maximum;
let dl_limit = maximum;
if (dl_limit < 0) dl_limit = 0;
maximum = 10000;
var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), {
new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), {
steps: maximum,
offset: 0,
initialStep: dl_limit.round(),
@ -188,7 +184,7 @@ MochaUI.extend({ @@ -188,7 +184,7 @@ MochaUI.extend({
}
}
else {
var req = new Request.JSON({
new Request.JSON({
url: 'api/v2/torrents/downloadLimit',
noCache : true,
method: 'post',
@ -197,14 +193,14 @@ MochaUI.extend({ @@ -197,14 +193,14 @@ MochaUI.extend({
},
onSuccess: function(data) {
if (data) {
var dl_limit = data[hashes[0]];
for(var key in data)
let dl_limit = data[hashes[0]];
for(const key in data)
if (dl_limit != data[key]) {
dl_limit = 0;
break;
}
if (dl_limit < 0) dl_limit = 0;
var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), {
new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), {
steps: maximum,
offset: 0,
initialStep: (dl_limit / 1024.0).round(),

148
src/webui/www/private/search.html

@ -153,42 +153,42 @@ @@ -153,42 +153,42 @@
<script>
'use strict';
var loadSearchResultsTimer;
var loadSearchPluginsTimer;
var searchResultsRowId = 0;
var searchRunning = false;
var requestCount = 0;
var searchPlugins = [];
var prevSearchPluginsResponse;
var searchPattern = "";
var searchFilterPattern = "";
var searchSeedsFilter = {
let loadSearchResultsTimer;
let loadSearchPluginsTimer;
let searchResultsRowId = 0;
let searchRunning = false;
let requestCount = 0;
let searchPlugins = [];
let prevSearchPluginsResponse;
let searchPattern = "";
let searchFilterPattern = "";
const searchSeedsFilter = {
min: 0,
max: 0
};
var searchSizeFilter = {
const searchSizeFilter = {
min: 0.00,
minUnit: 2, // B = 0, KiB = 1, MiB = 2, GiB = 3, TiB = 4, PiB = 5, EiB = 6
max: 0.00,
maxUnit: 3
};
var prevNameFilterValue;
var selectedCategory = "QBT_TR(All categories)QBT_TR[CONTEXT=SearchEngineWidget]";
var selectedPlugin = "all";
var prevSelectedPlugin;
var activeSearchId = null;
let prevNameFilterValue;
let selectedCategory = "QBT_TR(All categories)QBT_TR[CONTEXT=SearchEngineWidget]";
let selectedPlugin = "all";
let prevSelectedPlugin;
let activeSearchId = null;
var initSearchTab = function() {
const initSearchTab = function() {
// load "Search in" preference from local storage
$('searchInTorrentName').set('value', (localStorage.getItem('search_in_filter') === "names") ? "names" : "everywhere");
searchResultsTable.setup('searchResultsTableDiv', 'searchResultsTableFixedHeaderDiv', null);
getPlugins();
var searchInNameFilterTimer = null;
let searchInNameFilterTimer = null;
// listen for changes to searchInNameFilter
$('searchInNameFilter').addEvent('input', function() {
var value = $('searchInNameFilter').get("value");
const value = $('searchInNameFilter').get("value");
if (value !== prevNameFilterValue) {
prevNameFilterValue = value;
clearTimeout(searchInNameFilterTimer);
@ -206,7 +206,7 @@ @@ -206,7 +206,7 @@
// accept enter key as a click
new Event(e).stop();
var elem = e.event.srcElement;
const elem = e.event.srcElement;
if (elem.className.contains("searchInputField")) {
$('startSearchButton').click();
return;
@ -231,7 +231,7 @@ @@ -231,7 +231,7 @@
}).activate();
};
var startSearch = function(pattern, category, plugins) {
const startSearch = function(pattern, category, plugins) {
clearTimeout(loadSearchResultsTimer);
searchResultsTable.clear();
$('numSearchResultsVisible').set('html', searchResultsTable.getFilteredAndSortedRows().length);
@ -239,7 +239,7 @@ @@ -239,7 +239,7 @@
searchResultsRowId = 0;
requestCount = 0;
var url = new URI('api/v2/search/start');
const url = new URI('api/v2/search/start');
new Request.JSON({
url: url,
noCache: true,
@ -258,8 +258,8 @@ @@ -258,8 +258,8 @@
}).send();
};
var stopSearch = function() {
var url = new URI('api/v2/search/stop');
const stopSearch = function() {
const url = new URI('api/v2/search/stop');
new Request({
url: url,
noCache: true,
@ -273,11 +273,11 @@ @@ -273,11 +273,11 @@
}).send();
};
var startStopSearch = function() {
const startStopSearch = function() {
if (!searchRunning || !activeSearchId) {
var pattern = $('searchPattern').getProperty('value').trim();
var category = $('categorySelect').getProperty('value');
var plugins = $('pluginsSelect').getProperty('value');
const pattern = $('searchPattern').getProperty('value').trim();
let category = $('categorySelect').getProperty('value');
const plugins = $('pluginsSelect').getProperty('value');
if (!pattern || !category || !plugins) return;
if (category === "QBT_TR(All categories)QBT_TR[CONTEXT=SearchEngineWidget]")
@ -293,22 +293,22 @@ @@ -293,22 +293,22 @@
}
};
var openSearchTorrentDescription = function() {
const openSearchTorrentDescription = function() {
searchResultsTable.selectedRowsIds().each(function(rowId) {
window.open(searchResultsTable.rows.get(rowId).full_data.descrLink, "_blank");
});
};
var copySearchTorrentUrl = function() {
var urls = [];
const copySearchTorrentUrl = function() {
const urls = [];
searchResultsTable.selectedRowsIds().each(function(rowId) {
urls.push(searchResultsTable.rows.get(rowId).full_data.descrLink);
});
return urls.join("\n");
};
var downloadSearchTorrent = function() {
var urls = [];
const downloadSearchTorrent = function() {
const urls = [];
searchResultsTable.selectedRowsIds().each(function(rowId) {
urls.push(encodeURIComponent(searchResultsTable.rows.get(rowId).full_data.fileUrl));
});
@ -319,8 +319,8 @@ @@ -319,8 +319,8 @@
showDownloadPage(urls);
};
var manageSearchPlugins = function() {
var id = 'searchPlugins';
const manageSearchPlugins = function() {
const id = 'searchPlugins';
if (!$(id))
new MochaUI.Window({
id: id,
@ -345,16 +345,16 @@ @@ -345,16 +345,16 @@
});
};
var loadSearchPlugins = function() {
const loadSearchPlugins = function() {
getPlugins();
loadSearchPluginsTimer = loadSearchPlugins.delay(2000);
};
var categorySelected = function() {
const categorySelected = function() {
selectedCategory = $("categorySelect").get("value");
};
var pluginSelected = function() {
const pluginSelected = function() {
selectedPlugin = $("pluginsSelect").get("value");
if (selectedPlugin !== prevSelectedPlugin) {
@ -363,23 +363,23 @@ @@ -363,23 +363,23 @@
}
};
var reselectCategory = function() {
for (var i = 0; i < $("categorySelect").options.length; ++i)
const reselectCategory = function() {
for (let i = 0; i < $("categorySelect").options.length; ++i)
if ($("categorySelect").options[i].get("value") === selectedCategory)
$("categorySelect").options[i].selected = true;
categorySelected();
};
var reselectPlugin = function() {
for (var i = 0; i < $("pluginsSelect").options.length; ++i)
const reselectPlugin = function() {
for (let i = 0; i < $("pluginsSelect").options.length; ++i)
if ($("pluginsSelect").options[i].get("value") === selectedPlugin)
$("pluginsSelect").options[i].selected = true;
pluginSelected();
};
var resetSearchState = function() {
const resetSearchState = function() {
clearTimeout(loadSearchResultsTimer);
$('startSearchButton').set('text', 'QBT_TR(Search)QBT_TR[CONTEXT=SearchEngineWidget]');
searchResultsRowId = 0;
@ -387,9 +387,9 @@ @@ -387,9 +387,9 @@
activeSearchId = null;
};
var getSearchCategories = function() {
var populateCategorySelect = function(categories) {
var categoryHtml = [];
const getSearchCategories = function() {
const populateCategorySelect = function(categories) {
const categoryHtml = [];
categories.each(function(category) {
categoryHtml.push("<option>" + category + "</option>");
});
@ -402,9 +402,9 @@ @@ -402,9 +402,9 @@
$('categorySelect').set('html', categoryHtml.join(""));
};
var selectedPlugin = $('pluginsSelect').get("value");
const selectedPlugin = $('pluginsSelect').get("value");
if ((selectedPlugin === "all") || (selectedPlugin === "enabled")) {
var url = new URI('api/v2/search/categories');
const url = new URI('api/v2/search/categories');
url.setData('name', selectedPlugin);
new Request.JSON({
url: url,
@ -416,8 +416,8 @@ @@ -416,8 +416,8 @@
}).send();
}
else {
var plugins = ["QBT_TR(All categories)QBT_TR[CONTEXT=SearchEngineWidget]"];
var plugin = getPlugin(selectedPlugin);
let plugins = ["QBT_TR(All categories)QBT_TR[CONTEXT=SearchEngineWidget]"];
const plugin = getPlugin(selectedPlugin);
if (plugin !== null)
plugins = plugins.concat(plugin.supportedCategories);
@ -427,7 +427,7 @@ @@ -427,7 +427,7 @@
reselectCategory();
};
var getPlugins = function() {
const getPlugins = function() {
new Request.JSON({
url: new URI('api/v2/search/plugins'),
noCache: true,
@ -437,11 +437,11 @@ @@ -437,11 +437,11 @@
prevSearchPluginsResponse = response;
searchPlugins = response;
var pluginsHtml = [];
const pluginsHtml = [];
pluginsHtml.push('<option value="enabled">QBT_TR(Only enabled)QBT_TR[CONTEXT=SearchEngineWidget]</option>');
pluginsHtml.push('<option value="all">QBT_TR(All plugins)QBT_TR[CONTEXT=SearchEngineWidget]</option>');
var searchPluginsEmpty = (searchPlugins.length === 0);
const searchPluginsEmpty = (searchPlugins.length === 0);
if (searchPluginsEmpty) {
$('searchResultsNoPlugins').style.display = "block";
$('searchResultsFilters').style.display = "none";
@ -453,9 +453,9 @@ @@ -453,9 +453,9 @@
$('searchResultsTableContainer').style.display = "block";
// sort plugins alphabetically
var allPlugins = searchPlugins.sort(function(pluginA, pluginB) {
var a = pluginA.fullName.toLowerCase();
var b = pluginB.fullName.toLowerCase();
const allPlugins = searchPlugins.sort(function(pluginA, pluginB) {
const a = pluginA.fullName.toLowerCase();
const b = pluginB.fullName.toLowerCase();
if (a < b) return -1;
if (a > b) return 1;
return 0;
@ -489,15 +489,15 @@ @@ -489,15 +489,15 @@
}).send();
};
var getPlugin = function(name) {
for (var i = 0; i < searchPlugins.length; ++i)
const getPlugin = function(name) {
for (let i = 0; i < searchPlugins.length; ++i)
if (searchPlugins[i].name === name)
return searchPlugins[i];
return null;
};
var searchInTorrentName = function() {
const searchInTorrentName = function() {
if ($('searchInTorrentName').get('value') === "names")
localStorage.setItem('search_in_filter', "names");
else
@ -506,7 +506,7 @@ @@ -506,7 +506,7 @@
searchFilterChanged();
};
var resetFilters = function() {
const resetFilters = function() {
// reset filters
$('searchMinSeedsFilter').set('value', '0');
$('searchMaxSeedsFilter').set('value', '0');
@ -516,14 +516,14 @@ @@ -516,14 +516,14 @@
$('searchMaxSizePrefix').set('value', '3'); // GiB
};
var searchSeedsFilterChanged = function() {
const searchSeedsFilterChanged = function() {
searchSeedsFilter.min = $('searchMinSeedsFilter').get('value');
searchSeedsFilter.max = $('searchMaxSeedsFilter').get('value');
searchFilterChanged();
};
var searchSizeFilterChanged = function() {
const searchSizeFilterChanged = function() {
searchSizeFilter.min = $('searchMinSizeFilter').get('value');
searchSizeFilter.minUnit = $('searchMinSizePrefix').get('value');
searchSizeFilter.max = $('searchMaxSizeFilter').get('value');
@ -532,17 +532,17 @@ @@ -532,17 +532,17 @@
searchFilterChanged();
};
var searchSizeFilterPrefixChanged = function() {
const searchSizeFilterPrefixChanged = function() {
if (($('searchMinSizeFilter').get('value') != 0) || ($('searchMaxSizeFilter').get('value') != 0))
searchSizeFilterChanged();
};
var searchFilterChanged = function() {
const searchFilterChanged = function() {
searchResultsTable.updateTable();
$('numSearchResultsVisible').set('html', searchResultsTable.getFilteredAndSortedRows().length);
};
var setupSearchTableEvents = function(enable) {
const setupSearchTableEvents = function(enable) {
if (enable)
$$(".searchTableRow").each(function(target) {
target.addEventListener('dblclick', downloadSearchTorrent, false);
@ -553,9 +553,9 @@ @@ -553,9 +553,9 @@
});
};
var loadSearchResultsData = function() {
var maxResults = 500;
var url = new URI('api/v2/search/results');
const loadSearchResultsData = function() {
const maxResults = 500;
const url = new URI('api/v2/search/results');
new Request.JSON({
url: url,
noCache: true,
@ -589,10 +589,10 @@ @@ -589,10 +589,10 @@
setupSearchTableEvents(false);
if (response.results) {
var results = response.results;
for (var i = 0; i < results.length; ++i) {
var result = results[i];
var row = {
const results = response.results;
for (let i = 0; i < results.length; ++i) {
const result = results[i];
const row = {
rowId: searchResultsRowId,
descrLink: result.descrLink,
fileName: result.fileName,
@ -622,7 +622,7 @@ @@ -622,7 +622,7 @@
setupSearchTableEvents(true);
}
var timeout = 1000;
let timeout = 1000;
if (requestCount > 30)
timeout = 3000;
else if (requestCount > 10)
@ -635,7 +635,7 @@ @@ -635,7 +635,7 @@
}).send();
};
var updateSearchResultsData = function() {
const updateSearchResultsData = function() {
clearTimeout(loadSearchResultsTimer);
loadSearchResultsTimer = loadSearchResultsData.delay(500);
};

48
src/webui/www/private/searchplugins.html

@ -79,11 +79,11 @@ @@ -79,11 +79,11 @@
<script>
'use strict';
var searchPluginsTableContextMenu;
var prevOffsetLeft;
var prevOffsetTop;
this.searchPluginsTableContextMenu = undefined;
this.prevOffsetLeft = undefined;
this.prevOffsetTop = undefined;
var initSearchPlugins = function() {
this.initSearchPlugins = function() {
searchPluginsTableContextMenu = new SearchPluginsTableContextMenu({
targets: '.searchPluginsTableRow',
menu: 'searchPluginsTableMenu',
@ -97,11 +97,11 @@ @@ -97,11 +97,11 @@
updateSearchPluginsTable();
};
var closeSearchWindow = function(id) {
this.closeSearchWindow = function(id) {
window.parent.MochaUI.closeWindow(window.parent.$(id));
};
var installPlugin = function(path) {
this.installPlugin = function(path) {
new MochaUI.Window({
id: 'installSearchPlugin',
title: "QBT_TR(Install plugin)QBT_TR[CONTEXT=PluginSourceDlg]",
@ -117,9 +117,9 @@ @@ -117,9 +117,9 @@
});
};
var uninstallPlugin = function() {
var plugins = searchPluginsTable.selectedRowsIds().join('|');
var url = new URI('api/v2/search/uninstallPlugin');
this.uninstallPlugin = function() {
const plugins = searchPluginsTable.selectedRowsIds().join('|');
const url = new URI('api/v2/search/uninstallPlugin');
new Request({
url: url,
noCache: true,
@ -130,13 +130,13 @@ @@ -130,13 +130,13 @@
}).send();
};
var enablePlugin = function() {
var plugins = searchPluginsTable.selectedRowsIds();
var enable = true;
this.enablePlugin = function() {
const plugins = searchPluginsTable.selectedRowsIds();
let enable = true;
if (plugins && plugins.length)
enable = !getPlugin(plugins[0]).enabled;
var url = new URI('api/v2/search/enablePlugin');
const url = new URI('api/v2/search/enablePlugin');
new Request({
url: url,
noCache: true,
@ -148,8 +148,8 @@ @@ -148,8 +148,8 @@
}).send();
};
var checkForUpdates = function() {
var url = new URI('api/v2/search/updatePlugins');
this.checkForUpdates = function() {
const url = new URI('api/v2/search/updatePlugins');
new Request({
url: url,
noCache: true,
@ -157,7 +157,7 @@ @@ -157,7 +157,7 @@
}).send();
};
var calculateContextMenuOffsets = function() {
this.calculateContextMenuOffsets = function() {
prevOffsetLeft = document.getElementById("searchPlugins").getBoundingClientRect().left;
prevOffsetTop = document.getElementById("searchPlugins").getBoundingClientRect().top;
@ -167,13 +167,13 @@ @@ -167,13 +167,13 @@
};
};
var updateSearchPluginsTableContextMenuOffset = function() {
this.updateSearchPluginsTableContextMenuOffset = function() {
// only re-calculate if window has moved
if ((prevOffsetLeft !== document.getElementById("searchPlugins").getBoundingClientRect().left) || (prevOffsetTop !== document.getElementById("searchPlugins").getBoundingClientRect().top))
searchPluginsTableContextMenu.options.offsets = calculateContextMenuOffsets();
};
var setupSearchPluginTableEvents = function(enable) {
this.setupSearchPluginTableEvents = function(enable) {
if (enable)
$$(".searchPluginsTableRow").each(function(target) {
target.addEventListener('dblclick', enablePlugin, false);
@ -186,15 +186,15 @@ @@ -186,15 +186,15 @@
});
};
var updateSearchPluginsTable = function() {
this.updateSearchPluginsTable = function() {
// clear event listeners
setupSearchPluginTableEvents(false);
var oldPlugins = Object.keys(searchPluginsTable.rows);
const oldPlugins = Object.keys(searchPluginsTable.rows);
// remove old rows from the table
for (var i = 0; i < oldPlugins.length; ++i) {
var found = false;
for (var j = 0; j < searchPlugins.length; ++j) {
for (let i = 0; i < oldPlugins.length; ++i) {
let found = false;
for (let j = 0; j < searchPlugins.length; ++j) {
if (searchPlugins[j].name === oldPlugins[i]) {
found = true;
break;
@ -204,7 +204,7 @@ @@ -204,7 +204,7 @@
searchPluginsTable.removeRow(oldPlugins[i]);
}
for (var i = 0; i < searchPlugins.length; ++i) {
for (let i = 0; i < searchPlugins.length; ++i) {
searchPlugins[i].rowId = searchPlugins[i].name;
searchPluginsTable.updateRowData(searchPlugins[i]);
}

6
src/webui/www/private/setlocation.html

@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
}).activate();
window.addEvent('domready', function() {
var path = new URI().getData('path');
const path = new URI().getData('path');
// set text field to current value
if (path)
$('setLocation').value = escapeHtml(decodeURIComponent(path));
@ -39,13 +39,13 @@ @@ -39,13 +39,13 @@
$('setLocationButton').addEvent('click', function(e) {
new Event(e).stop();
// check field
var location = $('setLocation').value.trim();
const location = $('setLocation').value.trim();
if (location === null || location === "") {
$('error_div').set('text', 'QBT_TR(Save path is empty)QBT_TR[CONTEXT=TorrentsController]');
return false;
}
var hashesList = new URI().getData('hashes');
const hashesList = new URI().getData('hashes');
new Request({
url: 'api/v2/torrents/setLocation',
method: 'post',

30
src/webui/www/private/shareratio.html

@ -11,8 +11,8 @@ @@ -11,8 +11,8 @@
<script>
'use strict';
var UseGlobalLimit = -2;
var NoLimit = -1;
const UseGlobalLimit = -2;
const NoLimit = -1;
new Keyboard({
defaultEventType: 'keydown',
@ -33,10 +33,10 @@ @@ -33,10 +33,10 @@
}).activate();
window.addEvent('domready', function() {
var hashesList = new URI().getData('hashes').split('|');
var origValues = new URI().getData('orig').split('|');
const hashesList = new URI().getData('hashes').split('|');
const origValues = new URI().getData('orig').split('|');
var values = {
const values = {
ratioLimit: friendlyFloat(origValues[0], 2),
seedingTimeLimit: parseInt(origValues[1]),
maxRatio: friendlyFloat(origValues[2], 2),
@ -74,9 +74,9 @@ @@ -74,9 +74,9 @@
return false;
}
var shareLimit = getSelectedRadioValue('shareLimit');
var ratioLimitValue = 0.00;
var seedingTimeLimitValue = 0;
const shareLimit = getSelectedRadioValue('shareLimit');
let ratioLimitValue = 0.00;
let seedingTimeLimitValue = 0;
if (shareLimit === 'default') {
ratioLimitValue = seedingTimeLimitValue = UseGlobalLimit;
@ -108,10 +108,10 @@ @@ -108,10 +108,10 @@
});
function getSelectedRadioValue(name) {
var radios = document.getElementsByName(name);
const radios = document.getElementsByName(name);
for (var i = 0; i < radios.length; ++i) {
var radio = radios[i];
for (let i = 0; i < radios.length; ++i) {
const radio = radios[i];
if (radio.checked) {
return (radio).get('value');
}
@ -119,17 +119,17 @@ @@ -119,17 +119,17 @@
}
function setSelectedRadioValue(name, value) {
var radios = document.getElementsByName(name);
const radios = document.getElementsByName(name);
for (var i = 0; i < radios.length; ++i) {
var radio = radios[i];
for (let i = 0; i < radios.length; ++i) {
const radio = radios[i];
if (radio.value === value)
radio.checked = true;
}
}
function shareLimitChanged() {
var customShareLimit = getSelectedRadioValue('shareLimit') === 'custom';
const customShareLimit = getSelectedRadioValue('shareLimit') === 'custom';
$('setRatio').set('disabled', !customShareLimit);
$('setMinutes').set('disabled', !customShareLimit);

2
src/webui/www/private/transferlist.html

@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
'use strict';
//create a context menu
var torrentsTableContextMenu = new TorrentsTableContextMenu({
const torrentsTableContextMenu = new TorrentsTableContextMenu({
targets: '.torrentsTableContextMenuTarget',
menu: 'torrentsTableMenu',
actions: {

2
src/webui/www/private/upload.html

@ -127,7 +127,7 @@ @@ -127,7 +127,7 @@
<script>
'use strict';
var submitted = false;
let submitted = false;
$('uploadForm').addEventListener("submit", function() {
$('startTorrentHidden').value = $('startTorrent').checked ? 'false' : 'true';

6
src/webui/www/private/uploadlimit.html

@ -24,9 +24,9 @@ @@ -24,9 +24,9 @@
<script>
'use strict';
var hashes = new URI().getData('hashes').split('|');
var setUpLimit = function() {
var limit = $("uplimitUpdatevalue").value.toInt() * 1024;
const hashes = new URI().getData('hashes').split('|');
const setUpLimit = function() {
const limit = $("uplimitUpdatevalue").value.toInt() * 1024;
if (hashes[0] == "global") {
new Request({
url: 'api/v2/transfer/setUploadLimit',

10
src/webui/www/public/scripts/login.js

@ -38,9 +38,9 @@ document.addEventListener('DOMContentLoaded', function() { @@ -38,9 +38,9 @@ document.addEventListener('DOMContentLoaded', function() {
});
function submitLoginForm() {
var errorMsgElement = document.getElementById('error_msg');
const errorMsgElement = document.getElementById('error_msg');
var xhr = new XMLHttpRequest();
const xhr = new XMLHttpRequest();
xhr.open('POST', 'api/v2/auth/login', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=utf-8');
xhr.addEventListener('readystatechange', function() {
@ -57,9 +57,9 @@ function submitLoginForm() { @@ -57,9 +57,9 @@ function submitLoginForm() {
: 'QBT_TR(Unable to log in, qBittorrent is probably unreachable.)QBT_TR[CONTEXT=HttpServer]';
});
var usernameElement = document.getElementById('username');
var passwordElement = document.getElementById('password');
var queryString = "username=" + encodeURIComponent(usernameElement.value) + "&password=" + encodeURIComponent(passwordElement.value);
const usernameElement = document.getElementById('username');
const passwordElement = document.getElementById('password');
const queryString = "username=" + encodeURIComponent(usernameElement.value) + "&password=" + encodeURIComponent(passwordElement.value);
xhr.send(queryString);
// clear the field

1
src/webui/www/webui.qrc

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
<file>private/index.html</file>
<file>private/installsearchplugin.html</file>
<file>private/newcategory.html</file>
<file>private/newtag.html</file>
<file>private/preferences.html</file>
<file>private/preferences_content.html</file>
<file>private/properties.html</file>

Loading…
Cancel
Save