Browse Source

Merge pull request #11103 from Piccirello/webui-explicit-export

Move JavaScript code into explicit namespaces
adaptive-webui-19844
Mike Tzou 5 years ago committed by GitHub
parent
commit
209831d3b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/webui/www/private/addpeers.html
  2. 4
      src/webui/www/private/download.html
  3. 14
      src/webui/www/private/newcategory.html
  4. 4
      src/webui/www/private/newtag.html
  5. 83
      src/webui/www/private/scripts/client.js
  6. 44
      src/webui/www/private/scripts/contextmenu.js
  7. 39
      src/webui/www/private/scripts/download.js
  8. 143
      src/webui/www/private/scripts/dynamicTable.js
  9. 42
      src/webui/www/private/scripts/file-tree.js
  10. 35
      src/webui/www/private/scripts/filesystem.js
  11. 72
      src/webui/www/private/scripts/misc.js
  12. 2
      src/webui/www/private/scripts/mocha-init.js
  13. 18
      src/webui/www/private/scripts/preferences.js
  14. 35
      src/webui/www/private/scripts/progressbar.js
  15. 217
      src/webui/www/private/scripts/prop-files.js
  16. 68
      src/webui/www/private/scripts/prop-general.js
  17. 42
      src/webui/www/private/scripts/prop-peers.js
  18. 60
      src/webui/www/private/scripts/prop-trackers.js
  19. 34
      src/webui/www/private/scripts/prop-webseeds.js
  20. 2
      src/webui/www/private/setlocation.html
  21. 4
      src/webui/www/private/shareratio.html
  22. 4
      src/webui/www/private/upload.html
  23. 2
      src/webui/www/private/views/about.html
  24. 2
      src/webui/www/private/views/aboutToolbar.html
  25. 19
      src/webui/www/private/views/filters.html
  26. 28
      src/webui/www/private/views/installsearchplugin.html
  27. 179
      src/webui/www/private/views/preferences.html
  28. 2
      src/webui/www/private/views/preferencesToolbar.html
  29. 2
      src/webui/www/private/views/properties.html
  30. 77
      src/webui/www/private/views/search.html
  31. 67
      src/webui/www/private/views/searchplugins.html
  32. 18
      src/webui/www/private/views/transferlist.html

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

@ -61,7 +61,7 @@
<p>QBT_TR(List of peers to add (one IP per line):)QBT_TR[CONTEXT=PeersAdditionDialog]</p> <p>QBT_TR(List of peers to add (one IP per line):)QBT_TR[CONTEXT=PeersAdditionDialog]</p>
<textarea id="peers" rows="10" style="width: 100%;" placeholder="QBT_TR(Format: IPv4:port / [IPv6]:port)QBT_TR[CONTEXT=PeersAdditionDialog]"></textarea> <textarea id="peers" rows="10" style="width: 100%;" placeholder="QBT_TR(Format: IPv4:port / [IPv6]:port)QBT_TR[CONTEXT=PeersAdditionDialog]"></textarea>
<div style="margin-top: 10px; text-align: center;"> <div style="margin-top: 10px; text-align: center;">
<button onclick="window.parent.closeWindows();">QBT_TR(Cancel)QBT_TR[CONTEXT=PeersAdditionDialog]</button> <button onclick="parent.closeWindows();">QBT_TR(Cancel)QBT_TR[CONTEXT=PeersAdditionDialog]</button>
<button id="addPeersOk">QBT_TR(Ok)QBT_TR[CONTEXT=PeersAdditionDialog]</button> <button id="addPeersOk">QBT_TR(Ok)QBT_TR[CONTEXT=PeersAdditionDialog]</button>
</div> </div>
</div> </div>

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

@ -27,7 +27,7 @@
<label for="autoTMM">QBT_TR(Torrent Management Mode:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label> <label for="autoTMM">QBT_TR(Torrent Management Mode:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
</td> </td>
<td> <td>
<select id="autoTMM" name="autoTMM" onchange="changeTMM(this)"> <select id="autoTMM" name="autoTMM" onchange="qBittorrent.Download.changeTMM(this)">
<option selected value="false">Manual</option> <option selected value="false">Manual</option>
<option value="true">Automatic</option> <option value="true">Automatic</option>
</select> </select>
@ -63,7 +63,7 @@
</td> </td>
<td> <td>
<div class="select-watched-folder-editable"> <div class="select-watched-folder-editable">
<select id="categorySelect" onchange="changeCategorySelect(this)"> <select id="categorySelect" onchange="qBittorrent.Download.changeCategorySelect(this)">
<option selected value="\other"></option> <option selected value="\other"></option>
</select> </select>
<input name="category" type="text" value="" /> <input name="category" type="text" value="" />

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

@ -30,18 +30,18 @@
}).activate(); }).activate();
window.addEvent('domready', function() { window.addEvent('domready', function() {
const uriAction = safeTrim(new URI().getData('action')); const uriAction = window.qBittorrent.Misc.safeTrim(new URI().getData('action'));
const uriHashes = safeTrim(new URI().getData('hashes')); const uriHashes = window.qBittorrent.Misc.safeTrim(new URI().getData('hashes'));
const uriCategoryName = safeTrim(new URI().getData('categoryName')); const uriCategoryName = window.qBittorrent.Misc.safeTrim(new URI().getData('categoryName'));
const uriSavePath = safeTrim(new URI().getData('savePath')); const uriSavePath = window.qBittorrent.Misc.safeTrim(new URI().getData('savePath'));
if (uriAction === "edit") { if (uriAction === "edit") {
if (!uriCategoryName) if (!uriCategoryName)
return false; return false;
$('categoryName').set('disabled', true); $('categoryName').set('disabled', true);
$('categoryName').set('value', escapeHtml(uriCategoryName)); $('categoryName').set('value', window.qBittorrent.Misc.escapeHtml(uriCategoryName));
$('savePath').set('value', escapeHtml(uriSavePath)); $('savePath').set('value', window.qBittorrent.Misc.escapeHtml(uriSavePath));
$('savePath').focus(); $('savePath').focus();
} }
else { else {
@ -90,7 +90,7 @@
}).send(); }).send();
}, },
onError: function() { onError: function() {
alert("QBT_TR(Unable to create category)QBT_TR[CONTEXT=HttpServer] " + escapeHtml(categoryName)); alert("QBT_TR(Unable to create category)QBT_TR[CONTEXT=HttpServer] " + window.qBittorrent.Misc.escapeHtml(categoryName));
} }
}).send(); }).send();
break; break;

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

@ -30,8 +30,8 @@
}).activate(); }).activate();
window.addEvent('domready', function() { window.addEvent('domready', function() {
const uriAction = safeTrim(new URI().getData('action')); const uriAction = window.qBittorrent.Misc.safeTrim(new URI().getData('action'));
const uriHashes = safeTrim(new URI().getData('hashes')); const uriHashes = window.qBittorrent.Misc.safeTrim(new URI().getData('hashes'));
if (uriAction === 'create') if (uriAction === 'create')
$('legendText').innerText = 'QBT_TR(Tag:)QBT_TR[CONTEXT=TagFilterWidget]'; $('legendText').innerText = 'QBT_TR(Tag:)QBT_TR[CONTEXT=TagFilterWidget]';

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

@ -24,21 +24,10 @@
'use strict'; 'use strict';
this.torrentsTable = new TorrentsTable(); this.torrentsTable = new window.qBittorrent.DynamicTable.TorrentsTable();
const torrentTrackersTable = new TorrentTrackersTable();
const torrentPeersTable = new TorrentPeersTable();
const torrentFilesTable = new TorrentFilesTable();
const searchResultsTable = new SearchResultsTable();
const searchPluginsTable = new SearchPluginsTable();
let updatePropertiesPanel = function() {}; let updatePropertiesPanel = function() {};
let updateTorrentData = function() {};
let updateTrackersData = function() {};
let updateTorrentPeersData = function() {};
let updateWebSeedsData = function() {};
let updateTorrentFilesData = function() {};
this.updateMainData = function() {}; this.updateMainData = function() {};
let alternativeSpeedLimits = false; let alternativeSpeedLimits = false;
let queueing_enabled = true; let queueing_enabled = true;
@ -365,12 +354,12 @@ window.addEvent('load', function() {
const create_link = function(hash, text, count) { const create_link = function(hash, text, count) {
const html = '<a href="#" onclick="setCategoryFilter(' + hash + ');return false;">' const html = '<a href="#" onclick="setCategoryFilter(' + hash + ');return false;">'
+ '<img src="images/qbt-theme/inode-directory.svg"/>' + '<img src="images/qbt-theme/inode-directory.svg"/>'
+ escapeHtml(text) + ' (' + count + ')' + '</a>'; + window.qBittorrent.Misc.escapeHtml(text) + ' (' + count + ')' + '</a>';
const el = new Element('li', { const el = new Element('li', {
id: hash, id: hash,
html: html html: html
}); });
categoriesFilterContextMenu.addTarget(el); window.qBittorrent.Filters.categoriesFilterContextMenu.addTarget(el);
return el; return el;
}; };
@ -422,12 +411,12 @@ window.addEvent('load', function() {
const createLink = function(hash, text, count) { const createLink = function(hash, text, count) {
const html = '<a href="#" onclick="setTagFilter(' + hash + ');return false;">' const html = '<a href="#" onclick="setTagFilter(' + hash + ');return false;">'
+ '<img src="images/qbt-theme/inode-directory.svg"/>' + '<img src="images/qbt-theme/inode-directory.svg"/>'
+ escapeHtml(text) + ' (' + count + ')' + '</a>'; + window.qBittorrent.Misc.escapeHtml(text) + ' (' + count + ')' + '</a>';
const el = new Element('li', { const el = new Element('li', {
id: hash, id: hash,
html: html html: html
}); });
tagsFilterContextMenu.addTarget(el); window.qBittorrent.Filters.tagsFilterContextMenu.addTarget(el);
return el; return el;
}; };
@ -579,11 +568,11 @@ window.addEvent('load', function() {
updateFiltersList(); updateFiltersList();
if (update_categories) { if (update_categories) {
updateCategoryList(); updateCategoryList();
torrentsTableContextMenu.updateCategoriesSubMenu(category_list); window.qBittorrent.TransferList.contextMenu.updateCategoriesSubMenu(category_list);
} }
if (updateTags) { if (updateTags) {
updateTagList(); updateTagList();
torrentsTableContextMenu.updateTagsSubMenu(tagList); window.qBittorrent.TransferList.contextMenu.updateTagsSubMenu(tagList);
} }
if (full_update) if (full_update)
@ -603,39 +592,39 @@ window.addEvent('load', function() {
}; };
const processServerState = function() { const processServerState = function() {
let transfer_info = friendlyUnit(serverState.dl_info_speed, true); let transfer_info = window.qBittorrent.Misc.friendlyUnit(serverState.dl_info_speed, true);
if (serverState.dl_rate_limit > 0) if (serverState.dl_rate_limit > 0)
transfer_info += " [" + friendlyUnit(serverState.dl_rate_limit, true) + "]"; transfer_info += " [" + window.qBittorrent.Misc.friendlyUnit(serverState.dl_rate_limit, true) + "]";
transfer_info += " (" + friendlyUnit(serverState.dl_info_data, false) + ")"; transfer_info += " (" + window.qBittorrent.Misc.friendlyUnit(serverState.dl_info_data, false) + ")";
$("DlInfos").set('html', transfer_info); $("DlInfos").set('html', transfer_info);
transfer_info = friendlyUnit(serverState.up_info_speed, true); transfer_info = window.qBittorrent.Misc.friendlyUnit(serverState.up_info_speed, true);
if (serverState.up_rate_limit > 0) if (serverState.up_rate_limit > 0)
transfer_info += " [" + friendlyUnit(serverState.up_rate_limit, true) + "]"; transfer_info += " [" + window.qBittorrent.Misc.friendlyUnit(serverState.up_rate_limit, true) + "]";
transfer_info += " (" + friendlyUnit(serverState.up_info_data, false) + ")"; transfer_info += " (" + window.qBittorrent.Misc.friendlyUnit(serverState.up_info_data, false) + ")";
$("UpInfos").set('html', transfer_info); $("UpInfos").set('html', transfer_info);
if (speedInTitle) { if (speedInTitle) {
document.title = "QBT_TR([D: %1, U: %2] qBittorrent %3)QBT_TR[CONTEXT=MainWindow]".replace("%1", friendlyUnit(serverState.dl_info_speed, true)).replace("%2", friendlyUnit(serverState.up_info_speed, true)).replace("%3", qbtVersion()); document.title = "QBT_TR([D: %1, U: %2] qBittorrent %3)QBT_TR[CONTEXT=MainWindow]".replace("%1", window.qBittorrent.Misc.friendlyUnit(serverState.dl_info_speed, true)).replace("%2", window.qBittorrent.Misc.friendlyUnit(serverState.up_info_speed, true)).replace("%3", qbtVersion());
document.title += " QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]"; document.title += " QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]";
} }
else else
document.title = ("qBittorrent " + qbtVersion() + " QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]"); document.title = ("qBittorrent " + qbtVersion() + " QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]");
$('freeSpaceOnDisk').set('html', 'QBT_TR(Free space: %1)QBT_TR[CONTEXT=HttpServer]'.replace("%1", friendlyUnit(serverState.free_space_on_disk))); $('freeSpaceOnDisk').set('html', 'QBT_TR(Free space: %1)QBT_TR[CONTEXT=HttpServer]'.replace("%1", window.qBittorrent.Misc.friendlyUnit(serverState.free_space_on_disk)));
$('DHTNodes').set('html', 'QBT_TR(DHT: %1 nodes)QBT_TR[CONTEXT=StatusBar]'.replace("%1", serverState.dht_nodes)); $('DHTNodes').set('html', 'QBT_TR(DHT: %1 nodes)QBT_TR[CONTEXT=StatusBar]'.replace("%1", serverState.dht_nodes));
// Statistics dialog // Statistics dialog
if (document.getElementById("statisticspage")) { if (document.getElementById("statisticspage")) {
$('AlltimeDL').set('html', friendlyUnit(serverState.alltime_dl, false)); $('AlltimeDL').set('html', window.qBittorrent.Misc.friendlyUnit(serverState.alltime_dl, false));
$('AlltimeUL').set('html', friendlyUnit(serverState.alltime_ul, false)); $('AlltimeUL').set('html', window.qBittorrent.Misc.friendlyUnit(serverState.alltime_ul, false));
$('TotalWastedSession').set('html', friendlyUnit(serverState.total_wasted_session, false)); $('TotalWastedSession').set('html', window.qBittorrent.Misc.friendlyUnit(serverState.total_wasted_session, false));
$('GlobalRatio').set('html', serverState.global_ratio); $('GlobalRatio').set('html', serverState.global_ratio);
$('TotalPeerConnections').set('html', serverState.total_peer_connections); $('TotalPeerConnections').set('html', serverState.total_peer_connections);
$('ReadCacheHits').set('html', serverState.read_cache_hits + "%"); $('ReadCacheHits').set('html', serverState.read_cache_hits + "%");
$('TotalBuffersSize').set('html', friendlyUnit(serverState.total_buffers_size, false)); $('TotalBuffersSize').set('html', window.qBittorrent.Misc.friendlyUnit(serverState.total_buffers_size, false));
$('WriteCacheOverload').set('html', serverState.write_cache_overload + "%"); $('WriteCacheOverload').set('html', serverState.write_cache_overload + "%");
$('ReadCacheOverload').set('html', serverState.read_cache_overload + "%"); $('ReadCacheOverload').set('html', serverState.read_cache_overload + "%");
$('QueuedIOJobs').set('html', serverState.queued_io_jobs); $('QueuedIOJobs').set('html', serverState.queued_io_jobs);
$('AverageTimeInQueue').set('html', serverState.average_time_queue + " ms"); $('AverageTimeInQueue').set('html', serverState.average_time_queue + " ms");
$('TotalQueuedSize').set('html', friendlyUnit(serverState.total_queued_size, false)); $('TotalQueuedSize').set('html', window.qBittorrent.Misc.friendlyUnit(serverState.total_queued_size, false));
} }
if (serverState.connection_status == "connected") if (serverState.connection_status == "connected")
@ -790,7 +779,7 @@ window.addEvent('load', function() {
const showSearchTab = function() { const showSearchTab = function() {
if (!searchTabInitialized) { if (!searchTabInitialized) {
initSearchTab(); window.qBittorrent.Search.init();
searchTabInitialized = true; searchTabInitialized = true;
} }
@ -878,16 +867,26 @@ window.addEvent('load', function() {
MochaUI.initializeTabs('propertiesTabs'); MochaUI.initializeTabs('propertiesTabs');
updatePropertiesPanel = function() { updatePropertiesPanel = function() {
if (!$('prop_general').hasClass('invisible')) if (!$('prop_general').hasClass('invisible')) {
updateTorrentData(); if (window.qBittorrent.PropGeneral !== undefined)
else if (!$('prop_trackers').hasClass('invisible')) window.qBittorrent.PropGeneral.updateData();
updateTrackersData(); }
else if (!$('prop_peers').hasClass('invisible')) else if (!$('prop_trackers').hasClass('invisible')) {
updateTorrentPeersData(); if (window.qBittorrent.PropTrackers !== undefined)
else if (!$('prop_webseeds').hasClass('invisible')) window.qBittorrent.PropTrackers.updateData();
updateWebSeedsData(); }
else if (!$('prop_files').hasClass('invisible')) else if (!$('prop_peers').hasClass('invisible')) {
updateTorrentFilesData(); if (window.qBittorrent.PropPeers !== undefined)
window.qBittorrent.PropPeers.updateData();
}
else if (!$('prop_webseeds').hasClass('invisible')) {
if (window.qBittorrent.PropWebseeds !== undefined)
window.qBittorrent.PropWebseeds.updateData();
}
else if (!$('prop_files').hasClass('invisible')) {
if (window.qBittorrent.PropFiles !== undefined)
window.qBittorrent.PropFiles.updateData();
}
}; };
$('PropGeneralLink').addEvent('click', function(e) { $('PropGeneralLink').addEvent('click', function(e) {

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

@ -28,8 +28,23 @@
'use strict'; 'use strict';
let lastShownContextMenu = null; if (window.qBittorrent === undefined) {
const ContextMenu = new Class({ window.qBittorrent = {};
}
window.qBittorrent.ContextMenu = (function() {
const exports = function() {
return {
ContextMenu: ContextMenu,
TorrentsTableContextMenu: TorrentsTableContextMenu,
CategoriesFilterContextMenu: CategoriesFilterContextMenu,
TagsFilterContextMenu: TagsFilterContextMenu,
SearchPluginsTableContextMenu: SearchPluginsTableContextMenu
};
};
let lastShownContextMenu = null;
const ContextMenu = new Class({
//implements //implements
Implements: [Options, Events], Implements: [Options, Events],
@ -275,9 +290,9 @@ const ContextMenu = new Class({
} }
return this; return this;
} }
}); });
const TorrentsTableContextMenu = new Class({ const TorrentsTableContextMenu = new Class({
Extends: ContextMenu, Extends: ContextMenu,
updateMenuItems: function() { updateMenuItems: function() {
@ -431,7 +446,7 @@ const TorrentsTableContextMenu = new Class({
Object.each(sortedCategories, function(categoryName) { Object.each(sortedCategories, function(categoryName) {
const categoryHash = genHash(categoryName); const categoryHash = genHash(categoryName);
const el = new Element('li', { const el = new Element('li', {
html: '<a href="javascript:torrentSetCategoryFN(\'' + categoryHash + '\');"><img src="images/qbt-theme/inode-directory.svg"/> ' + escapeHtml(categoryName) + '</a>' html: '<a href="javascript:torrentSetCategoryFN(\'' + categoryHash + '\');"><img src="images/qbt-theme/inode-directory.svg"/> ' + window.qBittorrent.Misc.escapeHtml(categoryName) + '</a>'
}); });
if (first) { if (first) {
el.addClass('separator'); el.addClass('separator');
@ -469,7 +484,7 @@ const TorrentsTableContextMenu = new Class({
const tagHash = genHash(tagName); const tagHash = genHash(tagName);
const el = new Element('li', { const el = new Element('li', {
html: '<a href="#Tag/' + tagHash + '" onclick="event.preventDefault(); torrentSetTagsFN(\'' + tagHash + '\', !event.currentTarget.getElement(\'input[type=checkbox]\').checked);">' 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) + '<input type="checkbox" onclick="this.checked = !this.checked;"> ' + window.qBittorrent.Misc.escapeHtml(tagName)
+ '</a>' + '</a>'
}); });
if (i === 0) if (i === 0)
@ -477,9 +492,9 @@ const TorrentsTableContextMenu = new Class({
contextTagList.appendChild(el); contextTagList.appendChild(el);
} }
} }
}); });
const CategoriesFilterContextMenu = new Class({ const CategoriesFilterContextMenu = new Class({
Extends: ContextMenu, Extends: ContextMenu,
updateMenuItems: function() { updateMenuItems: function() {
const id = this.options.element.id; const id = this.options.element.id;
@ -492,9 +507,9 @@ const CategoriesFilterContextMenu = new Class({
this.hideItem('deleteCategory'); this.hideItem('deleteCategory');
} }
} }
}); });
const TagsFilterContextMenu = new Class({ const TagsFilterContextMenu = new Class({
Extends: ContextMenu, Extends: ContextMenu,
updateMenuItems: function() { updateMenuItems: function() {
const id = this.options.element.id; const id = this.options.element.id;
@ -503,9 +518,9 @@ const TagsFilterContextMenu = new Class({
else else
this.hideItem('deleteTag'); this.hideItem('deleteTag');
} }
}); });
const SearchPluginsTableContextMenu = new Class({ const SearchPluginsTableContextMenu = new Class({
Extends: ContextMenu, Extends: ContextMenu,
updateMenuItems: function() { updateMenuItems: function() {
@ -521,4 +536,7 @@ const SearchPluginsTableContextMenu = new Class({
this.showItem('Uninstall'); this.showItem('Uninstall');
} }
}); });
return exports();
})();

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

@ -23,10 +23,22 @@
'use strict'; 'use strict';
let categories = {}; if (window.qBittorrent === undefined) {
let defaultSavePath = ""; window.qBittorrent = {};
}
const getCategories = function() { window.qBittorrent.Download = (function() {
const exports = function() {
return {
changeCategorySelect: changeCategorySelect,
changeTMM: changeTMM
};
};
let categories = {};
let defaultSavePath = "";
const getCategories = function() {
new Request.JSON({ new Request.JSON({
url: 'api/v2/torrents/categories', url: 'api/v2/torrents/categories',
noCache: true, noCache: true,
@ -44,9 +56,9 @@ const getCategories = function() {
} }
} }
}).send(); }).send();
}; };
const getPreferences = function() { const getPreferences = function() {
new Request.JSON({ new Request.JSON({
url: 'api/v2/app/preferences', url: 'api/v2/app/preferences',
method: 'get', method: 'get',
@ -72,9 +84,9 @@ const getPreferences = function() {
} }
} }
}).send(); }).send();
}; };
const changeCategorySelect = function(item) { const changeCategorySelect = function(item) {
if (item.value == "\\other") { if (item.value == "\\other") {
item.nextElementSibling.hidden = false; item.nextElementSibling.hidden = false;
item.nextElementSibling.value = ""; item.nextElementSibling.value = "";
@ -97,9 +109,9 @@ const changeCategorySelect = function(item) {
$('savepath').value = savePath; $('savepath').value = savePath;
} }
} }
}; };
const changeTMM = function(item) { const changeTMM = function(item) {
if (item.selectedIndex == 1) { if (item.selectedIndex == 1) {
$('savepath').disabled = true; $('savepath').disabled = true;
@ -112,9 +124,12 @@ const changeTMM = function(item) {
$('savepath').disabled = false; $('savepath').disabled = false;
$('savepath').value = defaultSavePath; $('savepath').value = defaultSavePath;
} }
}; };
$(window).addEventListener("load", function() { $(window).addEventListener("load", function() {
getPreferences(); getPreferences();
getCategories(); getCategories();
}); });
return exports();
})();

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

@ -33,10 +33,26 @@
'use strict'; 'use strict';
let DynamicTableHeaderContextMenuClass = null; if (window.qBittorrent === undefined) {
let ProgressColumnWidth = -1; window.qBittorrent = {};
}
const DynamicTable = new Class({ window.qBittorrent.DynamicTable = (function() {
const exports = function() {
return {
TorrentsTable: TorrentsTable,
TorrentPeersTable: TorrentPeersTable,
SearchResultsTable: SearchResultsTable,
SearchPluginsTable: SearchPluginsTable,
TorrentTrackersTable: TorrentTrackersTable,
TorrentFilesTable: TorrentFilesTable
};
};
let DynamicTableHeaderContextMenuClass = null;
let ProgressColumnWidth = -1;
const DynamicTable = new Class({
initialize: function() {}, initialize: function() {},
@ -266,7 +282,7 @@ const DynamicTable = new Class({
setupDynamicTableHeaderContextMenuClass: function() { setupDynamicTableHeaderContextMenuClass: function() {
if (!DynamicTableHeaderContextMenuClass) { if (!DynamicTableHeaderContextMenuClass) {
DynamicTableHeaderContextMenuClass = new Class({ DynamicTableHeaderContextMenuClass = new Class({
Extends: ContextMenu, Extends: window.qBittorrent.ContextMenu.ContextMenu,
updateMenuItems: function() { updateMenuItems: function() {
for (let i = 0; i < this.dynamicTable.columns.length; ++i) { for (let i = 0; i < this.dynamicTable.columns.length; ++i) {
if (this.dynamicTable.columns[i].caption === '') if (this.dynamicTable.columns[i].caption === '')
@ -298,7 +314,7 @@ const DynamicTable = new Class({
}); });
const createLi = function(columnName, text) { const createLi = function(columnName, text) {
const html = '<a href="#' + columnName + '" ><img src="images/qbt-theme/checked.svg"/>' + escapeHtml(text) + '</a>'; const html = '<a href="#' + columnName + '" ><img src="images/qbt-theme/checked.svg"/>' + window.qBittorrent.Misc.escapeHtml(text) + '</a>';
return new Element('li', { return new Element('li', {
html: html html: html
}); });
@ -791,9 +807,9 @@ const DynamicTable = new Class({
getRowIds: function() { getRowIds: function() {
return this.rows.getKeys(); return this.rows.getKeys();
}, },
}); });
const TorrentsTable = new Class({ const TorrentsTable = new Class({
Extends: DynamicTable, Extends: DynamicTable,
initColumns: function() { initColumns: function() {
@ -989,7 +1005,7 @@ const TorrentsTable = new Class({
// name, category, tags // name, category, tags
this.columns['name'].updateTd = function(td, row) { this.columns['name'].updateTd = function(td, row) {
const name = escapeHtml(this.getRowValue(row)) const name = window.qBittorrent.Misc.escapeHtml(this.getRowValue(row))
td.set('html', name); td.set('html', name);
td.set('title', name); td.set('title', name);
}; };
@ -1006,7 +1022,7 @@ const TorrentsTable = new Class({
// size // size
this.columns['size'].updateTd = function(td, row) { this.columns['size'].updateTd = function(td, row) {
const size = friendlyUnit(this.getRowValue(row), false); const size = window.qBittorrent.Misc.friendlyUnit(this.getRowValue(row), false);
td.set('html', size); td.set('html', size);
td.set('title', size); td.set('title', size);
}; };
@ -1030,7 +1046,7 @@ const TorrentsTable = new Class({
else { else {
if (ProgressColumnWidth < 0) if (ProgressColumnWidth < 0)
ProgressColumnWidth = td.offsetWidth; ProgressColumnWidth = td.offsetWidth;
td.adopt(new ProgressBar(progressFormated.toFloat(), { td.adopt(new window.qBittorrent.ProgressBar.ProgressBar(progressFormated.toFloat(), {
'width': ProgressColumnWidth - 5 'width': ProgressColumnWidth - 5
})); }));
td.resized = false; td.resized = false;
@ -1084,7 +1100,7 @@ const TorrentsTable = new Class({
// dlspeed // dlspeed
this.columns['dlspeed'].updateTd = function(td, row) { this.columns['dlspeed'].updateTd = function(td, row) {
const speed = friendlyUnit(this.getRowValue(row), true); const speed = window.qBittorrent.Misc.friendlyUnit(this.getRowValue(row), true);
td.set('html', speed); td.set('html', speed);
td.set('title', speed); td.set('title', speed);
}; };
@ -1094,7 +1110,7 @@ const TorrentsTable = new Class({
// eta // eta
this.columns['eta'].updateTd = function(td, row) { this.columns['eta'].updateTd = function(td, row) {
const eta = friendlyDuration(this.getRowValue(row)); const eta = window.qBittorrent.Misc.friendlyDuration(this.getRowValue(row));
td.set('html', eta); td.set('html', eta);
td.set('title', eta); td.set('title', eta);
}; };
@ -1102,7 +1118,7 @@ const TorrentsTable = new Class({
// ratio // ratio
this.columns['ratio'].updateTd = function(td, row) { this.columns['ratio'].updateTd = function(td, row) {
const ratio = this.getRowValue(row); const ratio = this.getRowValue(row);
const string = (ratio === -1) ? '∞' : toFixedPointString(ratio, 2); const string = (ratio === -1) ? '∞' : window.qBittorrent.Misc.toFixedPointString(ratio, 2);
td.set('html', string); td.set('html', string);
td.set('title', string); td.set('title', string);
}; };
@ -1139,7 +1155,7 @@ const TorrentsTable = new Class({
td.set('title', '∞'); td.set('title', '∞');
} }
else { else {
const formattedSpeed = friendlyUnit(speed, true); const formattedSpeed = window.qBittorrent.Misc.friendlyUnit(speed, true);
td.set('html', formattedSpeed); td.set('html', formattedSpeed);
td.set('title', formattedSpeed); td.set('title', formattedSpeed);
} }
@ -1172,7 +1188,7 @@ const TorrentsTable = new Class({
td.set('title', '∞'); td.set('title', '∞');
} }
else { else {
const formattedVal = 'QBT_TR(%1 ago)QBT_TR[CONTEXT=TransferListDelegate]'.replace('%1', friendlyDuration((new Date()) / 1000 - val)); const formattedVal = 'QBT_TR(%1 ago)QBT_TR[CONTEXT=TransferListDelegate]'.replace('%1', window.qBittorrent.Misc.friendlyDuration((new Date()) / 1000 - val));
td.set('html', formattedVal); td.set('html', formattedVal);
td.set('title', formattedVal); td.set('title', formattedVal);
} }
@ -1180,14 +1196,14 @@ const TorrentsTable = new Class({
// time active // time active
this.columns['time_active'].updateTd = function(td, row) { this.columns['time_active'].updateTd = function(td, row) {
const time = friendlyDuration(this.getRowValue(row)); const time = window.qBittorrent.Misc.friendlyDuration(this.getRowValue(row));
td.set('html', time); td.set('html', time);
td.set('title', time); td.set('title', time);
}; };
// availability // availability
this.columns['availability'].updateTd = function(td, row) { this.columns['availability'].updateTd = function(td, row) {
const value = toFixedPointString(this.getRowValue(row), 3); const value = window.qBittorrent.Misc.toFixedPointString(this.getRowValue(row), 3);
td.set('html', value); td.set('html', value);
td.set('title', value); td.set('title', value);
}; };
@ -1275,7 +1291,7 @@ const TorrentsTable = new Class({
} }
if ((filterTerms !== undefined) && (filterTerms !== null) if ((filterTerms !== undefined) && (filterTerms !== null)
&& (filterTerms.length > 0) && !containsAllTerms(name, filterTerms)) && (filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(name, filterTerms))
return false; return false;
return true; return true;
@ -1349,9 +1365,9 @@ const TorrentsTable = new Class({
onSelectedRowChanged: function() { onSelectedRowChanged: function() {
updatePropertiesPanel(); updatePropertiesPanel();
} }
}); });
const TorrentPeersTable = new Class({ const TorrentPeersTable = new Class({
Extends: DynamicTable, Extends: DynamicTable,
initColumns: function() { initColumns: function() {
@ -1446,7 +1462,7 @@ const TorrentPeersTable = new Class({
td.set('title', ''); td.set('title', '');
} }
else { else {
const formattedSpeed = friendlyUnit(speed, true); const formattedSpeed = window.qBittorrent.Misc.friendlyUnit(speed, true);
td.set('html', formattedSpeed); td.set('html', formattedSpeed);
td.set('title', formattedSpeed); td.set('title', formattedSpeed);
} }
@ -1457,7 +1473,7 @@ const TorrentPeersTable = new Class({
// downloaded, uploaded // downloaded, uploaded
this.columns['downloaded'].updateTd = function(td, row) { this.columns['downloaded'].updateTd = function(td, row) {
const downloaded = friendlyUnit(this.getRowValue(row), false); const downloaded = window.qBittorrent.Misc.friendlyUnit(this.getRowValue(row), false);
td.set('html', downloaded); td.set('html', downloaded);
td.set('title', downloaded); td.set('title', downloaded);
}; };
@ -1474,14 +1490,14 @@ const TorrentPeersTable = new Class({
// files // files
this.columns['files'].updateTd = function(td, row) { this.columns['files'].updateTd = function(td, row) {
td.innerHTML = escapeHtml(this.getRowValue(row, 0).replace(/\n/g, ';')); td.innerHTML = window.qBittorrent.Misc.escapeHtml(this.getRowValue(row, 0).replace(/\n/g, ';'));
td.title = escapeHtml(this.getRowValue(row, 0)); td.title = window.qBittorrent.Misc.escapeHtml(this.getRowValue(row, 0));
}; };
} }
}); });
const SearchResultsTable = new Class({ const SearchResultsTable = new Class({
Extends: DynamicTable, Extends: DynamicTable,
initColumns: function() { initColumns: function() {
@ -1496,17 +1512,17 @@ const SearchResultsTable = new Class({
initColumnsFunctions: function() { initColumnsFunctions: function() {
const displayText = function(td, row) { const displayText = function(td, row) {
const value = escapeHtml(this.getRowValue(row)); const value = window.qBittorrent.Misc.escapeHtml(this.getRowValue(row));
td.set('html', value); td.set('html', value);
td.set('title', value); td.set('title', value);
} }
const displaySize = function(td, row) { const displaySize = function(td, row) {
const size = friendlyUnit(this.getRowValue(row), false); const size = window.qBittorrent.Misc.friendlyUnit(this.getRowValue(row), false);
td.set('html', size); td.set('html', size);
td.set('title', size); td.set('title', size);
} }
const displayNum = function(td, row) { const displayNum = function(td, row) {
const value = escapeHtml(this.getRowValue(row)); const value = window.qBittorrent.Misc.escapeHtml(this.getRowValue(row));
const formattedValue = (value === "-1") ? "Unknown" : value; const formattedValue = (value === "-1") ? "Unknown" : value;
td.set('html', formattedValue); td.set('html', formattedValue);
td.set('title', formattedValue); td.set('title', formattedValue);
@ -1521,8 +1537,8 @@ const SearchResultsTable = new Class({
getFilteredAndSortedRows: function() { getFilteredAndSortedRows: function() {
const getSizeFilters = function() { const getSizeFilters = function() {
let minSize = (searchSizeFilter.min > 0.00) ? (searchSizeFilter.min * Math.pow(1024, searchSizeFilter.minUnit)) : 0.00; let minSize = (window.qBittorrent.Search.searchSizeFilter.min > 0.00) ? (window.qBittorrent.Search.searchSizeFilter.min * Math.pow(1024, window.qBittorrent.Search.searchSizeFilter.minUnit)) : 0.00;
let maxSize = (searchSizeFilter.max > 0.00) ? (searchSizeFilter.max * Math.pow(1024, searchSizeFilter.maxUnit)) : 0.00; let maxSize = (window.qBittorrent.Search.searchSizeFilter.max > 0.00) ? (window.qBittorrent.Search.searchSizeFilter.max * Math.pow(1024, window.qBittorrent.Search.searchSizeFilter.maxUnit)) : 0.00;
if ((minSize > maxSize) && (maxSize > 0.00)) { if ((minSize > maxSize) && (maxSize > 0.00)) {
const tmp = minSize; const tmp = minSize;
@ -1537,8 +1553,8 @@ const SearchResultsTable = new Class({
}; };
const getSeedsFilters = function() { const getSeedsFilters = function() {
let minSeeds = (searchSeedsFilter.min > 0) ? searchSeedsFilter.min : 0; let minSeeds = (window.qBittorrent.Search.searchSeedsFilter.min > 0) ? window.qBittorrent.Search.searchSeedsFilter.min : 0;
let maxSeeds = (searchSeedsFilter.max > 0) ? searchSeedsFilter.max : 0; let maxSeeds = (window.qBittorrent.Search.searchSeedsFilter.max > 0) ? window.qBittorrent.Search.searchSeedsFilter.max : 0;
if ((minSeeds > maxSeeds) && (maxSeeds > 0)) { if ((minSeeds > maxSeeds) && (maxSeeds > 0)) {
const tmp = minSeeds; const tmp = minSeeds;
@ -1554,18 +1570,18 @@ const SearchResultsTable = new Class({
let filteredRows = []; let filteredRows = [];
const rows = this.rows.getValues(); const rows = this.rows.getValues();
const searchTerms = searchPattern.toLowerCase().split(" "); const searchTerms = window.qBittorrent.Search.searchText.pattern.toLowerCase().split(" ");
const filterTerms = searchFilterPattern.toLowerCase().split(" "); const filterTerms = window.qBittorrent.Search.searchText.filterPattern.toLowerCase().split(" ");
const sizeFilters = getSizeFilters(); const sizeFilters = getSizeFilters();
const seedsFilters = getSeedsFilters(); const seedsFilters = getSeedsFilters();
const searchInTorrentName = $('searchInTorrentName').get('value') === "names"; const searchInTorrentName = $('searchInTorrentName').get('value') === "names";
if (searchInTorrentName || (filterTerms.length > 0) || (searchSizeFilter.min > 0.00) || (searchSizeFilter.max > 0.00)) { if (searchInTorrentName || (filterTerms.length > 0) || (window.qBittorrent.Search.searchSizeFilter.min > 0.00) || (window.qBittorrent.Search.searchSizeFilter.max > 0.00)) {
for (let i = 0; i < rows.length; ++i) { for (let i = 0; i < rows.length; ++i) {
const row = rows[i]; const row = rows[i];
if (searchInTorrentName && !containsAllTerms(row.full_data.fileName, searchTerms)) continue; if (searchInTorrentName && !window.qBittorrent.Misc.containsAllTerms(row.full_data.fileName, searchTerms)) continue;
if ((filterTerms.length > 0) && !containsAllTerms(row.full_data.fileName, filterTerms)) continue; if ((filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(row.full_data.fileName, filterTerms)) continue;
if ((sizeFilters.min > 0.00) && (row.full_data.fileSize < sizeFilters.min)) continue; if ((sizeFilters.min > 0.00) && (row.full_data.fileSize < sizeFilters.min)) continue;
if ((sizeFilters.max > 0.00) && (row.full_data.fileSize > sizeFilters.max)) continue; if ((sizeFilters.max > 0.00) && (row.full_data.fileSize > sizeFilters.max)) continue;
if ((seedsFilters.min > 0) && (row.full_data.nbSeeders < seedsFilters.min)) continue; if ((seedsFilters.min > 0) && (row.full_data.nbSeeders < seedsFilters.min)) continue;
@ -1593,9 +1609,9 @@ const SearchResultsTable = new Class({
setupTr: function(tr) { setupTr: function(tr) {
tr.addClass("searchTableRow"); tr.addClass("searchTableRow");
} }
}); });
const SearchPluginsTable = new Class({ const SearchPluginsTable = new Class({
Extends: DynamicTable, Extends: DynamicTable,
initColumns: function() { initColumns: function() {
@ -1609,7 +1625,7 @@ const SearchPluginsTable = new Class({
initColumnsFunctions: function() { initColumnsFunctions: function() {
const displayText = function(td, row) { const displayText = function(td, row) {
const value = escapeHtml(this.getRowValue(row)); const value = window.qBittorrent.Misc.escapeHtml(this.getRowValue(row));
td.set('html', value); td.set('html', value);
td.set('title', value); td.set('title', value);
} }
@ -1637,9 +1653,9 @@ const SearchPluginsTable = new Class({
setupTr: function(tr) { setupTr: function(tr) {
tr.addClass("searchPluginsTableRow"); tr.addClass("searchPluginsTableRow");
} }
}); });
const TorrentTrackersTable = new Class({ const TorrentTrackersTable = new Class({
Extends: DynamicTable, Extends: DynamicTable,
initColumns: function() { initColumns: function() {
@ -1652,9 +1668,9 @@ const TorrentTrackersTable = new Class({
this.newColumn('downloaded', '', 'QBT_TR(Downloaded)QBT_TR[CONTEXT=TrackerListWidget]', 100, true); this.newColumn('downloaded', '', 'QBT_TR(Downloaded)QBT_TR[CONTEXT=TrackerListWidget]', 100, true);
this.newColumn('message', '', 'QBT_TR(Message)QBT_TR[CONTEXT=TrackerListWidget]', 250, true); this.newColumn('message', '', 'QBT_TR(Message)QBT_TR[CONTEXT=TrackerListWidget]', 250, true);
}, },
}); });
const TorrentFilesTable = new Class({ const TorrentFilesTable = new Class({
Extends: DynamicTable, Extends: DynamicTable,
filterTerms: [], filterTerms: [],
@ -1663,7 +1679,7 @@ const TorrentFilesTable = new Class({
prevFilteredRows: [], prevFilteredRows: [],
prevSortedColumn: null, prevSortedColumn: null,
prevReverseSort: null, prevReverseSort: null,
fileTree: new FileTree(), fileTree: new window.qBittorrent.FileTree.FileTree(),
populateTable: function(root) { populateTable: function(root) {
this.fileTree.setRoot(root); this.fileTree.setRoot(root);
@ -1682,7 +1698,7 @@ const TorrentFilesTable = new Class({
checked: node.checked, checked: node.checked,
remaining: node.remaining, remaining: node.remaining,
progress: node.progress, progress: node.progress,
priority: normalizePriority(node.priority), priority: window.qBittorrent.PropFiles.normalizePriority(node.priority),
availability: node.availability, availability: node.availability,
fileId: -1, fileId: -1,
name: node.name name: node.name
@ -1731,12 +1747,12 @@ const TorrentFilesTable = new Class({
initColumnsFunctions: function() { initColumnsFunctions: function() {
const that = this; const that = this;
const displaySize = function(td, row) { const displaySize = function(td, row) {
const size = friendlyUnit(this.getRowValue(row), false); const size = window.qBittorrent.Misc.friendlyUnit(this.getRowValue(row), false);
td.set('html', size); td.set('html', size);
td.set('title', size); td.set('title', size);
} }
const displayPercentage = function(td, row) { const displayPercentage = function(td, row) {
const value = friendlyPercentage(this.getRowValue(row)); const value = window.qBittorrent.Misc.friendlyPercentage(this.getRowValue(row));
td.set('html', value); td.set('html', value);
td.set('title', value); td.set('title', value);
}; };
@ -1752,7 +1768,7 @@ const TorrentFilesTable = new Class({
const dirImgId = 'filesTableDirImg' + id; const dirImgId = 'filesTableDirImg' + id;
if ($(dirImgId)) { if ($(dirImgId)) {
// just update file name // just update file name
$(fileNameId).textContent = escapeHtml(value); $(fileNameId).textContent = window.qBittorrent.Misc.escapeHtml(value);
} }
else { else {
const collapseIcon = new Element('img', { const collapseIcon = new Element('img', {
@ -1763,10 +1779,10 @@ const TorrentFilesTable = new Class({
class: "filesTableCollapseIcon", class: "filesTableCollapseIcon",
id: collapseIconId, id: collapseIconId,
"data-id": id, "data-id": id,
onclick: "collapseIconClicked(this)" onclick: "qBittorrent.PropFiles.collapseIconClicked(this)"
}); });
const span = new Element('span', { const span = new Element('span', {
text: escapeHtml(value), text: window.qBittorrent.Misc.escapeHtml(value),
id: fileNameId id: fileNameId
}); });
const dirImg = new Element('img', { const dirImg = new Element('img', {
@ -1785,7 +1801,7 @@ const TorrentFilesTable = new Class({
else { else {
const value = this.getRowValue(row); const value = this.getRowValue(row);
const span = new Element('span', { const span = new Element('span', {
text: escapeHtml(value), text: window.qBittorrent.Misc.escapeHtml(value),
id: fileNameId, id: fileNameId,
styles: { styles: {
'margin-left': ((node.depth + 1) * 20) 'margin-left': ((node.depth + 1) * 20)
@ -1799,8 +1815,8 @@ const TorrentFilesTable = new Class({
const id = row.rowId; const id = row.rowId;
const value = this.getRowValue(row); const value = this.getRowValue(row);
if (isDownloadCheckboxExists(id)) { if (window.qBittorrent.PropFiles.isDownloadCheckboxExists(id)) {
updateDownloadCheckbox(id, value); window.qBittorrent.PropFiles.updateDownloadCheckbox(id, value);
} }
else { else {
const treeImg = new Element('img', { const treeImg = new Element('img', {
@ -1809,7 +1825,7 @@ const TorrentFilesTable = new Class({
'margin-bottom': -2 'margin-bottom': -2
} }
}); });
td.adopt(treeImg, createDownloadCheckbox(id, row.full_data.fileId, value)); td.adopt(treeImg, window.qBittorrent.PropFiles.createDownloadCheckbox(id, row.full_data.fileId, value));
} }
}; };
@ -1821,7 +1837,7 @@ const TorrentFilesTable = new Class({
const progressBar = $('pbf_' + id); const progressBar = $('pbf_' + id);
if (progressBar === null) { if (progressBar === null) {
td.adopt(new ProgressBar(value.toFloat(), { td.adopt(new window.qBittorrent.ProgressBar.ProgressBar(value.toFloat(), {
id: 'pbf_' + id, id: 'pbf_' + id,
width: 80 width: 80
})); }));
@ -1835,10 +1851,10 @@ const TorrentFilesTable = new Class({
const id = row.rowId; const id = row.rowId;
const value = this.getRowValue(row); const value = this.getRowValue(row);
if (isPriorityComboExists(id)) if (window.qBittorrent.PropFiles.isPriorityComboExists(id))
updatePriorityCombo(id, value); window.qBittorrent.PropFiles.updatePriorityCombo(id, value);
else else
td.adopt(createPriorityCombo(id, row.full_data.fileId, value)); td.adopt(window.qBittorrent.PropFiles.createPriorityCombo(id, row.full_data.fileId, value));
}; };
this.columns['remaining'].updateTd = displaySize; this.columns['remaining'].updateTd = displaySize;
@ -1900,7 +1916,7 @@ const TorrentFilesTable = new Class({
} }
} }
if (containsAllTerms(node.name, filterTerms)) { if (window.qBittorrent.Misc.containsAllTerms(node.name, filterTerms)) {
const row = this.getRow(node); const row = this.getRow(node);
filteredRows.push(row); filteredRows.push(row);
return true; return true;
@ -1983,6 +1999,9 @@ const TorrentFilesTable = new Class({
else else
row.full_data.remaining = (row.full_data.size * (1.0 - (row.full_data.progress / 100))); row.full_data.remaining = (row.full_data.size * (1.0 - (row.full_data.progress / 100)));
} }
}); });
return exports();
})();
/*************************************************************/ /*************************************************************/

42
src/webui/www/private/scripts/file-tree.js

@ -28,23 +28,38 @@
'use strict'; 'use strict';
const FilePriority = { if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.FileTree = (function() {
const exports = function() {
return {
FilePriority: FilePriority,
TriState: TriState,
FileTree: FileTree,
FileNode: FileNode,
FolderNode: FolderNode,
};
};
const FilePriority = {
"Ignored": 0, "Ignored": 0,
"Normal": 1, "Normal": 1,
"High": 6, "High": 6,
"Maximum": 7, "Maximum": 7,
"Mixed": -1 "Mixed": -1
}; };
Object.freeze(FilePriority); Object.freeze(FilePriority);
const TriState = { const TriState = {
"Unchecked": 0, "Unchecked": 0,
"Checked": 1, "Checked": 1,
"Partial": 2 "Partial": 2
}; };
Object.freeze(TriState); Object.freeze(TriState);
const FileTree = new Class({ const FileTree = new Class({
root: null, root: null,
nodeMap: {}, nodeMap: {},
@ -98,9 +113,9 @@ const FileTree = new Class({
this._getArrayOfNodes(child, array); this._getArrayOfNodes(child, array);
}.bind(this)); }.bind(this));
} }
}); });
const FileNode = new Class({ const FileNode = new Class({
name: "", name: "",
rowId: null, rowId: null,
size: 0, size: 0,
@ -114,9 +129,9 @@ const FileNode = new Class({
data: null, data: null,
isFolder: false, isFolder: false,
children: [], children: [],
}); });
const FolderNode = new Class({ const FolderNode = new Class({
Extends: FileNode, Extends: FileNode,
initialize: function() { initialize: function() {
@ -173,4 +188,7 @@ const FolderNode = new Class({
this.priority = priority; this.priority = priority;
this.availability = (availability / size); this.availability = (availability / size);
} }
}); });
return exports();
})();

35
src/webui/www/private/scripts/filesystem.js

@ -30,13 +30,27 @@
// This file is the JavaScript implementation of base/utils/fs.cpp // This file is the JavaScript implementation of base/utils/fs.cpp
const QB_EXT = '.!qB'; if (window.qBittorrent === undefined) {
const PathSeparator = '/'; window.qBittorrent = {};
}
window.qBittorrent.Filesystem = (function() {
const exports = function() {
return {
PathSeparator: PathSeparator,
fileExtension: fileExtension,
fileName: fileName,
folderName: folderName
};
};
/** const QB_EXT = '.!qB';
const PathSeparator = '/';
/**
* Returns the file extension part of a file name. * Returns the file extension part of a file name.
*/ */
function fileExtension(filename) { const fileExtension = function(filename) {
const name = filename.endsWith(QB_EXT) const name = filename.endsWith(QB_EXT)
? filename.substring(0, filename.length - QB_EXT.length) ? filename.substring(0, filename.length - QB_EXT.length)
: filename; : filename;
@ -44,18 +58,21 @@ function fileExtension(filename) {
if (pointIndex === -1) if (pointIndex === -1)
return ''; return '';
return name.substring(pointIndex + 1); return name.substring(pointIndex + 1);
} };
function fileName(filepath) { const fileName = function(filepath) {
const slashIndex = filepath.lastIndexOf(PathSeparator); const slashIndex = filepath.lastIndexOf(PathSeparator);
if (slashIndex === -1) if (slashIndex === -1)
return filepath; return filepath;
return filepath.substring(slashIndex + 1); return filepath.substring(slashIndex + 1);
} };
function folderName(filepath) { const folderName = function(filepath) {
const slashIndex = filepath.lastIndexOf(PathSeparator); const slashIndex = filepath.lastIndexOf(PathSeparator);
if (slashIndex === -1) if (slashIndex === -1)
return filepath; return filepath;
return filepath.substring(0, slashIndex); return filepath.substring(0, slashIndex);
} };
return exports();
})();

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

@ -28,10 +28,29 @@
'use strict'; 'use strict';
/* if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.Misc = (function() {
const exports = function() {
return {
friendlyUnit: friendlyUnit,
friendlyDuration: friendlyDuration,
friendlyPercentage: friendlyPercentage,
friendlyFloat: friendlyFloat,
parseHtmlLinks: parseHtmlLinks,
escapeHtml: escapeHtml,
safeTrim: safeTrim,
toFixedPointString: toFixedPointString,
containsAllTerms: containsAllTerms
};
};
/*
* JS counterpart of the function in src/misc.cpp * JS counterpart of the function in src/misc.cpp
*/ */
function friendlyUnit(value, isSpeed) { const friendlyUnit = function(value, isSpeed) {
const units = [ const units = [
"QBT_TR(B)QBT_TR[CONTEXT=misc]", "QBT_TR(B)QBT_TR[CONTEXT=misc]",
"QBT_TR(KiB)QBT_TR[CONTEXT=misc]", "QBT_TR(KiB)QBT_TR[CONTEXT=misc]",
@ -70,12 +89,12 @@ function friendlyUnit(value, isSpeed) {
if (isSpeed) if (isSpeed)
ret += "QBT_TR(/s)QBT_TR[CONTEXT=misc]"; ret += "QBT_TR(/s)QBT_TR[CONTEXT=misc]";
return ret; return ret;
} }
/* /*
* JS counterpart of the function in src/misc.cpp * JS counterpart of the function in src/misc.cpp
*/ */
function friendlyDuration(seconds) { const friendlyDuration = function(seconds) {
const MAX_ETA = 8640000; const MAX_ETA = 8640000;
if (seconds < 0 || seconds >= MAX_ETA) if (seconds < 0 || seconds >= MAX_ETA)
return "∞"; return "∞";
@ -95,25 +114,25 @@ function friendlyDuration(seconds) {
if (days < 100) if (days < 100)
return "QBT_TR(%1d %2h)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(days)).replace("%2", parseInt(hours)); return "QBT_TR(%1d %2h)QBT_TR[CONTEXT=misc]".replace("%1", parseInt(days)).replace("%2", parseInt(hours));
return "∞"; return "∞";
} }
function friendlyPercentage(value) { const friendlyPercentage = function(value) {
let percentage = (value * 100).round(1); let percentage = (value * 100).round(1);
if (isNaN(percentage) || (percentage < 0)) if (isNaN(percentage) || (percentage < 0))
percentage = 0; percentage = 0;
if (percentage > 100) if (percentage > 100)
percentage = 100; percentage = 100;
return percentage.toFixed(1) + "%"; return percentage.toFixed(1) + "%";
} }
function friendlyFloat(value, precision) { const friendlyFloat = function(value, precision) {
return parseFloat(value).toFixed(precision); return parseFloat(value).toFixed(precision);
} }
/* /*
* From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString * From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
*/ */
if (!Date.prototype.toISOString) { if (!Date.prototype.toISOString) {
(function() { (function() {
function pad(number) { function pad(number) {
@ -135,23 +154,23 @@ if (!Date.prototype.toISOString) {
}; };
}()); }());
} }
/* /*
* JS counterpart of the function in src/misc.cpp * JS counterpart of the function in src/misc.cpp
*/ */
function parseHtmlLinks(text) { const parseHtmlLinks = function(text) {
const 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>"); return text.replace(exp, "<a target='_blank' href='$1'>$1</a>");
} }
function escapeHtml(str) { const escapeHtml = function(str) {
const div = document.createElement('div'); const div = document.createElement('div');
div.appendChild(document.createTextNode(str)); div.appendChild(document.createTextNode(str));
return div.innerHTML; return div.innerHTML;
} }
function safeTrim(value) { const safeTrim = function(value) {
try { try {
return value.trim(); return value.trim();
} }
@ -160,21 +179,21 @@ function safeTrim(value) {
return ""; return "";
throw e; throw e;
} }
} }
function toFixedPointString(number, digits) { const toFixedPointString = function(number, digits) {
// Do not round up number // Do not round up number
const power = Math.pow(10, digits); const power = Math.pow(10, digits);
return (Math.floor(power * number) / power).toFixed(digits); return (Math.floor(power * number) / power).toFixed(digits);
} }
/** /**
* *
* @param {String} text the text to search * @param {String} text the text to search
* @param {Array<String>} terms terms to search for within the text * @param {Array<String>} terms terms to search for within the text
* @returns {Boolean} true if all terms match the text, false otherwise * @returns {Boolean} true if all terms match the text, false otherwise
*/ */
function containsAllTerms(text, terms) { const containsAllTerms = function(text, terms) {
const textToSearch = text.toLowerCase(); const textToSearch = text.toLowerCase();
return terms.every((function(term) { return terms.every((function(term) {
const isTermRequired = (term[0] === '+'); const isTermRequired = (term[0] === '+');
@ -190,4 +209,7 @@ function containsAllTerms(text, terms) {
const textContainsTerm = (textToSearch.indexOf(term) !== -1); const textContainsTerm = (textToSearch.indexOf(term) !== -1);
return isTermExcluded ? !textContainsTerm : textContainsTerm; return isTermExcluded ? !textContainsTerm : textContainsTerm;
})); }));
} }
return exports();
})();

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

@ -38,7 +38,7 @@
----------------------------------------------------------------- */ ----------------------------------------------------------------- */
'use strict'; 'use strict';
const LocalPreferences = new LocalPreferencesClass(); const LocalPreferences = new window.qBittorrent.LocalPreferences.LocalPreferencesClass();
let saveWindowSize = function() {}; let saveWindowSize = function() {};
let loadWindowWidth = function() {}; let loadWindowWidth = function() {};

18
src/webui/www/private/scripts/preferences.js

@ -28,7 +28,18 @@
'use strict'; 'use strict';
const LocalPreferencesClass = new Class({ if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.LocalPreferences = (function() {
const exports = function() {
return {
LocalPreferencesClass: LocalPreferencesClass
};
};
const LocalPreferencesClass = new Class({
get: function(key, defaultValue) { get: function(key, defaultValue) {
const value = localStorage.getItem(key); const value = localStorage.getItem(key);
return ((value === null) && (defaultValue !== undefined)) return ((value === null) && (defaultValue !== undefined))
@ -44,4 +55,7 @@ const LocalPreferencesClass = new Class({
console.error(err); console.error(err);
} }
} }
}) })
return exports();
})();

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

@ -28,7 +28,19 @@
'use strict'; 'use strict';
const ProgressBar = new Class({ if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.ProgressBar = (function() {
const exports = function() {
return {
ProgressBar: ProgressBar
};
};
let ProgressBars = 0;
const ProgressBar = new Class({
initialize: function(value, parameters) { initialize: function(value, parameters) {
const vals = { const vals = {
'id': 'progressbar_' + (ProgressBars++), 'id': 'progressbar_' + (ProgressBars++),
@ -94,13 +106,13 @@ const ProgressBar = new Class({
else setTimeout('ProgressBar_checkForParent("' + obj.id + '")', 1); else setTimeout('ProgressBar_checkForParent("' + obj.id + '")', 1);
return obj; return obj;
} }
}); });
function ProgressBar_getValue() { function ProgressBar_getValue() {
return this.vals.value; return this.vals.value;
} }
function ProgressBar_setValue(value) { function ProgressBar_setValue(value) {
value = parseFloat(value); value = parseFloat(value);
if (isNaN(value)) value = 0; if (isNaN(value)) value = 0;
if (value > 100) value = 100; if (value > 100) value = 100;
@ -113,9 +125,9 @@ function ProgressBar_setValue(value) {
const 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.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)'); this.vals.light.setStyle('clip', 'rect(0,' + this.vals.width + 'px,' + this.vals.height + 'px,' + r + 'px)');
} }
function ProgressBar_setWidth(value) { function ProgressBar_setWidth(value) {
if (this.vals.width !== value) { if (this.vals.width !== value) {
this.vals.width = value; this.vals.width = value;
this.setStyle('width', value); this.setStyle('width', value);
@ -123,9 +135,9 @@ function ProgressBar_setWidth(value) {
this.vals.light.setStyle('width', value); this.vals.light.setStyle('width', value);
this.setValue(this.vals.value); this.setValue(this.vals.value);
} }
} }
function ProgressBar_checkForParent(id) { function ProgressBar_checkForParent(id) {
const obj = $(id); const obj = $(id);
if (!obj) return; if (!obj) return;
if (!obj.parentNode) return setTimeout('ProgressBar_checkForParent("' + id + '")', 1); if (!obj.parentNode) return setTimeout('ProgressBar_checkForParent("' + id + '")', 1);
@ -135,6 +147,7 @@ function ProgressBar_checkForParent(id) {
obj.vals.light.setStyle('width', w); obj.vals.light.setStyle('width', w);
obj.vals.width = w; obj.vals.width = w;
obj.setValue(obj.vals.value); obj.setValue(obj.vals.value);
} }
let ProgressBars = 0; return exports();
})();

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

@ -28,10 +28,32 @@
'use strict'; 'use strict';
let is_seed = true; if (window.qBittorrent === undefined) {
this.current_hash = ""; window.qBittorrent = {};
}
const normalizePriority = function(priority) { window.qBittorrent.PropFiles = (function() {
const exports = function() {
return {
normalizePriority: normalizePriority,
isDownloadCheckboxExists: isDownloadCheckboxExists,
createDownloadCheckbox: createDownloadCheckbox,
updateDownloadCheckbox: updateDownloadCheckbox,
isPriorityComboExists: isPriorityComboExists,
createPriorityCombo: createPriorityCombo,
updatePriorityCombo: updatePriorityCombo,
updateData: updateData,
collapseIconClicked: collapseIconClicked
};
};
const torrentFilesTable = new window.qBittorrent.DynamicTable.TorrentFilesTable();
const FilePriority = window.qBittorrent.FileTree.FilePriority;
const TriState = window.qBittorrent.FileTree.TriState;
let is_seed = true;
let current_hash = "";
const normalizePriority = function(priority) {
switch (priority) { switch (priority) {
case FilePriority.Ignored: case FilePriority.Ignored:
case FilePriority.Normal: case FilePriority.Normal:
@ -42,9 +64,9 @@ const normalizePriority = function(priority) {
default: default:
return FilePriority.Normal; return FilePriority.Normal;
} }
}; };
const getAllChildren = function(id, fileId) { const getAllChildren = function(id, fileId) {
const node = torrentFilesTable.getNode(id); const node = torrentFilesTable.getNode(id);
if (!node.isFolder) { if (!node.isFolder) {
return { return {
@ -76,9 +98,9 @@ const getAllChildren = function(id, fileId) {
rowIds: rowIds, rowIds: rowIds,
fileIds: fileIds fileIds: fileIds
}; };
}; };
const fileCheckboxClicked = function(e) { const fileCheckboxClicked = function(e) {
e.stopPropagation(); e.stopPropagation();
const checkbox = e.target; const checkbox = e.target;
@ -90,9 +112,9 @@ const fileCheckboxClicked = function(e) {
setFilePriority(rows.rowIds, rows.fileIds, priority); setFilePriority(rows.rowIds, rows.fileIds, priority);
updateGlobalCheckbox(); updateGlobalCheckbox();
}; };
const fileComboboxChanged = function(e) { const fileComboboxChanged = function(e) {
const combobox = e.target; const combobox = e.target;
const priority = combobox.value; const priority = combobox.value;
const id = combobox.get('data-id'); const id = combobox.get('data-id');
@ -102,13 +124,13 @@ const fileComboboxChanged = function(e) {
setFilePriority(rows.rowIds, rows.fileIds, priority); setFilePriority(rows.rowIds, rows.fileIds, priority);
updateGlobalCheckbox(); updateGlobalCheckbox();
}; };
const isDownloadCheckboxExists = function(id) { const isDownloadCheckboxExists = function(id) {
return ($('cbPrio' + id) !== null); return ($('cbPrio' + id) !== null);
}; };
const createDownloadCheckbox = function(id, fileId, checked) { const createDownloadCheckbox = function(id, fileId, checked) {
const checkbox = new Element('input'); const checkbox = new Element('input');
checkbox.set('type', 'checkbox'); checkbox.set('type', 'checkbox');
checkbox.set('id', 'cbPrio' + id); checkbox.set('id', 'cbPrio' + id);
@ -119,14 +141,14 @@ const createDownloadCheckbox = function(id, fileId, checked) {
updateCheckbox(checkbox, checked); updateCheckbox(checkbox, checked);
return checkbox; return checkbox;
}; };
const updateDownloadCheckbox = function(id, checked) { const updateDownloadCheckbox = function(id, checked) {
const checkbox = $('cbPrio' + id); const checkbox = $('cbPrio' + id);
updateCheckbox(checkbox, checked); updateCheckbox(checkbox, checked);
}; };
const updateCheckbox = function(checkbox, checked) { const updateCheckbox = function(checkbox, checked) {
switch (checked) { switch (checked) {
case TriState.Checked: case TriState.Checked:
setCheckboxChecked(checkbox); setCheckboxChecked(checkbox);
@ -138,22 +160,22 @@ const updateCheckbox = function(checkbox, checked) {
setCheckboxPartial(checkbox); setCheckboxPartial(checkbox);
break; break;
} }
} }
const isPriorityComboExists = function(id) { const isPriorityComboExists = function(id) {
return ($('comboPrio' + id) !== null); return ($('comboPrio' + id) !== null);
}; };
const createPriorityOptionElement = function(priority, selected, html) { const createPriorityOptionElement = function(priority, selected, html) {
const elem = new Element('option'); const elem = new Element('option');
elem.set('value', priority.toString()); elem.set('value', priority.toString());
elem.set('html', html); elem.set('html', html);
if (selected) if (selected)
elem.setAttribute('selected', ''); elem.setAttribute('selected', '');
return elem; return elem;
}; };
const createPriorityCombo = function(id, fileId, selectedPriority) { const createPriorityCombo = function(id, fileId, selectedPriority) {
const select = new Element('select'); const select = new Element('select');
select.set('id', 'comboPrio' + id); select.set('id', 'comboPrio' + id);
select.set('data-id', id); select.set('data-id', id);
@ -173,9 +195,9 @@ const createPriorityCombo = function(id, fileId, selectedPriority) {
mixedPriorityOption.injectInside(select); mixedPriorityOption.injectInside(select);
return select; return select;
}; };
const updatePriorityCombo = function(id, selectedPriority) { const updatePriorityCombo = function(id, selectedPriority) {
const combobox = $('comboPrio' + id); const combobox = $('comboPrio' + id);
if (parseInt(combobox.value) !== selectedPriority) if (parseInt(combobox.value) !== selectedPriority)
@ -183,9 +205,9 @@ const updatePriorityCombo = function(id, selectedPriority) {
if (combobox.disabled !== is_seed) if (combobox.disabled !== is_seed)
combobox.disabled = is_seed; combobox.disabled = is_seed;
}; };
const selectComboboxPriority = function(combobox, priority) { const selectComboboxPriority = function(combobox, priority) {
const options = combobox.options; const options = combobox.options;
for (let i = 0; i < options.length; ++i) { for (let i = 0; i < options.length; ++i) {
const option = options[i]; const option = options[i];
@ -196,9 +218,9 @@ const selectComboboxPriority = function(combobox, priority) {
} }
combobox.value = priority; combobox.value = priority;
}; };
const switchCheckboxState = function(e) { const switchCheckboxState = function(e) {
e.stopPropagation(); e.stopPropagation();
const rowIds = []; const rowIds = [];
@ -238,9 +260,9 @@ const switchCheckboxState = function(e) {
if (rowIds.length > 0) if (rowIds.length > 0)
setFilePriority(rowIds, fileIds, priority); setFilePriority(rowIds, fileIds, priority);
}; };
const updateGlobalCheckbox = function() { const updateGlobalCheckbox = function() {
const checkbox = $('tristate_cb'); const checkbox = $('tristate_cb');
if (isAllCheckboxesChecked()) if (isAllCheckboxesChecked())
setCheckboxChecked(checkbox); setCheckboxChecked(checkbox);
@ -248,44 +270,44 @@ const updateGlobalCheckbox = function() {
setCheckboxUnchecked(checkbox); setCheckboxUnchecked(checkbox);
else else
setCheckboxPartial(checkbox); setCheckboxPartial(checkbox);
}; };
const setCheckboxChecked = function(checkbox) { const setCheckboxChecked = function(checkbox) {
checkbox.state = "checked"; checkbox.state = "checked";
checkbox.indeterminate = false; checkbox.indeterminate = false;
checkbox.checked = true; checkbox.checked = true;
}; };
const setCheckboxUnchecked = function(checkbox) { const setCheckboxUnchecked = function(checkbox) {
checkbox.state = "unchecked"; checkbox.state = "unchecked";
checkbox.indeterminate = false; checkbox.indeterminate = false;
checkbox.checked = false; checkbox.checked = false;
}; };
const setCheckboxPartial = function(checkbox) { const setCheckboxPartial = function(checkbox) {
checkbox.state = "partial"; checkbox.state = "partial";
checkbox.indeterminate = true; checkbox.indeterminate = true;
}; };
const isAllCheckboxesChecked = function() { const isAllCheckboxesChecked = function() {
const checkboxes = $$('input.DownloadedCB'); const checkboxes = $$('input.DownloadedCB');
for (let i = 0; i < checkboxes.length; ++i) { for (let i = 0; i < checkboxes.length; ++i) {
if (!checkboxes[i].checked) if (!checkboxes[i].checked)
return false; return false;
} }
return true; return true;
}; };
const isAllCheckboxesUnchecked = function() { const isAllCheckboxesUnchecked = function() {
const checkboxes = $$('input.DownloadedCB'); const checkboxes = $$('input.DownloadedCB');
for (let i = 0; i < checkboxes.length; ++i) { for (let i = 0; i < checkboxes.length; ++i) {
if (checkboxes[i].checked) if (checkboxes[i].checked)
return false; return false;
} }
return true; return true;
}; };
const setFilePriority = function(ids, fileIds, priority) { const setFilePriority = function(ids, fileIds, priority) {
if (current_hash === "") return; if (current_hash === "") return;
clearTimeout(loadTorrentFilesDataTimer); clearTimeout(loadTorrentFilesDataTimer);
@ -312,10 +334,10 @@ const setFilePriority = function(ids, fileIds, priority) {
}); });
torrentFilesTable.updateTable(false); torrentFilesTable.updateTable(false);
}; };
let loadTorrentFilesDataTimer; let loadTorrentFilesDataTimer;
const loadTorrentFilesData = function() { const loadTorrentFilesData = function() {
if ($('prop_files').hasClass('invisible') if ($('prop_files').hasClass('invisible')
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) { || $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
// Tab changed, don't do anything // Tab changed, don't do anything
@ -356,14 +378,14 @@ const loadTorrentFilesData = function() {
} }
} }
}).send(); }).send();
}; };
updateTorrentFilesData = function() { const updateData = function() {
clearTimeout(loadTorrentFilesDataTimer); clearTimeout(loadTorrentFilesDataTimer);
loadTorrentFilesData(); loadTorrentFilesData();
}; };
const handleNewTorrentFiles = function(files) { const handleNewTorrentFiles = function(files) {
is_seed = (files.length > 0) ? files[0].is_seed : true; is_seed = (files.length > 0) ? files[0].is_seed : true;
const rows = files.map(function(file, index) { const rows = files.map(function(file, index) {
@ -371,7 +393,7 @@ const handleNewTorrentFiles = function(files) {
if ((progress === 100) && (file.progress < 1)) if ((progress === 100) && (file.progress < 1))
progress = 99.9; progress = 99.9;
const name = escapeHtml(file.name); const name = window.qBittorrent.Misc.escapeHtml(file.name);
const ignore = (file.priority === FilePriority.Ignored); const ignore = (file.priority === FilePriority.Ignored);
const checked = (ignore ? TriState.Unchecked : TriState.Checked); const checked = (ignore ? TriState.Unchecked : TriState.Checked);
const remaining = (ignore ? 0 : (file.size * (1.0 - file.progress))); const remaining = (ignore ? 0 : (file.size * (1.0 - file.progress)));
@ -379,7 +401,7 @@ const handleNewTorrentFiles = function(files) {
fileId: index, fileId: index,
checked: checked, checked: checked,
fileName: name, fileName: name,
name: fileName(name), name: window.qBittorrent.Filesystem.fileName(name),
size: file.size, size: file.size,
progress: progress, progress: progress,
priority: normalizePriority(file.priority), priority: normalizePriority(file.priority),
@ -392,17 +414,17 @@ const handleNewTorrentFiles = function(files) {
addRowsToTable(rows); addRowsToTable(rows);
updateGlobalCheckbox(); updateGlobalCheckbox();
}; };
const addRowsToTable = function(rows) { const addRowsToTable = function(rows) {
const selectedFiles = torrentFilesTable.selectedRowsIds(); const selectedFiles = torrentFilesTable.selectedRowsIds();
let rowId = 0; let rowId = 0;
const rootNode = new FolderNode(); const rootNode = new window.qBittorrent.FileTree.FolderNode();
rows.forEach(function(row) { rows.forEach(function(row) {
let parent = rootNode; let parent = rootNode;
const pathFolders = row.fileName.split(PathSeparator); const pathFolders = row.fileName.split(window.qBittorrent.Filesystem.PathSeparator);
pathFolders.pop(); pathFolders.pop();
pathFolders.forEach(function(folderName) { pathFolders.forEach(function(folderName) {
if (folderName === '.unwanted') if (folderName === '.unwanted')
@ -419,7 +441,7 @@ const addRowsToTable = function(rows) {
} }
} }
if (parentNode === null) { if (parentNode === null) {
parentNode = new FolderNode(); parentNode = new window.qBittorrent.FileTree.FolderNode();
parentNode.name = folderName; parentNode.name = folderName;
parentNode.rowId = rowId; parentNode.rowId = rowId;
parentNode.root = parent; parentNode.root = parent;
@ -433,7 +455,7 @@ const addRowsToTable = function(rows) {
const isChecked = row.checked ? TriState.Checked : TriState.Unchecked; const isChecked = row.checked ? TriState.Checked : TriState.Unchecked;
const remaining = (row.priority === FilePriority.Ignored) ? 0 : row.remaining; const remaining = (row.priority === FilePriority.Ignored) ? 0 : row.remaining;
const childNode = new FileNode(); const childNode = new window.qBittorrent.FileTree.FileNode();
childNode.name = row.name; childNode.name = row.name;
childNode.rowId = rowId; childNode.rowId = rowId;
childNode.size = row.size; childNode.size = row.size;
@ -455,9 +477,9 @@ const addRowsToTable = function(rows) {
if (selectedFiles.length > 0) if (selectedFiles.length > 0)
torrentFilesTable.reselectRows(selectedFiles); torrentFilesTable.reselectRows(selectedFiles);
}; };
const collapseIconClicked = function(event) { const collapseIconClicked = function(event) {
const id = event.get("data-id"); const id = event.get("data-id");
const node = torrentFilesTable.getNode(id); const node = torrentFilesTable.getNode(id);
const isCollapsed = (event.parentElement.get("data-collapsed") === "true"); const isCollapsed = (event.parentElement.get("data-collapsed") === "true");
@ -466,9 +488,9 @@ const collapseIconClicked = function(event) {
expandNode(node); expandNode(node);
else else
collapseNode(node); collapseNode(node);
}; };
const filesPriorityMenuClicked = function(priority) { const filesPriorityMenuClicked = function(priority) {
const selectedRows = torrentFilesTable.selectedRowsIds(); const selectedRows = torrentFilesTable.selectedRowsIds();
if (selectedRows.length === 0) return; if (selectedRows.length === 0) return;
@ -493,9 +515,9 @@ const filesPriorityMenuClicked = function(priority) {
} }
setFilePriority(Object.keys(uniqueRowIds), Object.keys(uniqueFileIds), priority); setFilePriority(Object.keys(uniqueRowIds), Object.keys(uniqueFileIds), priority);
}; };
const torrentFilesContextMenu = new ContextMenu({ const torrentFilesContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({
targets: '#torrentFilesTableDiv tr', targets: '#torrentFilesTableDiv tr',
menu: 'torrentFilesMenu', menu: 'torrentFilesMenu',
actions: { actions: {
@ -523,12 +545,12 @@ const torrentFilesContextMenu = new ContextMenu({
else else
this.showItem('FilePrio'); this.showItem('FilePrio');
} }
}); });
torrentFilesTable.setup('torrentFilesTableDiv', 'torrentFilesTableFixedHeaderDiv', torrentFilesContextMenu); torrentFilesTable.setup('torrentFilesTableDiv', 'torrentFilesTableFixedHeaderDiv', torrentFilesContextMenu);
// inject checkbox into table header // inject checkbox into table header
const tableHeaders = $$('#torrentFilesTableFixedHeaderDiv .dynamicTableHeader th'); const tableHeaders = $$('#torrentFilesTableFixedHeaderDiv .dynamicTableHeader th');
if (tableHeaders.length > 0) { if (tableHeaders.length > 0) {
const checkbox = new Element('input'); const checkbox = new Element('input');
checkbox.set('type', 'checkbox'); checkbox.set('type', 'checkbox');
checkbox.set('id', 'tristate_cb'); checkbox.set('id', 'tristate_cb');
@ -536,16 +558,16 @@ if (tableHeaders.length > 0) {
const checkboxTH = tableHeaders[0]; const checkboxTH = tableHeaders[0];
checkbox.injectInside(checkboxTH); checkbox.injectInside(checkboxTH);
} }
// default sort by name column // default sort by name column
if (torrentFilesTable.getSortedColumn() === null) if (torrentFilesTable.getSortedColumn() === null)
torrentFilesTable.setSortedColumn('name'); torrentFilesTable.setSortedColumn('name');
let prevTorrentFilesFilterValue; let prevTorrentFilesFilterValue;
let torrentFilesFilterInputTimer = null; let torrentFilesFilterInputTimer = null;
// listen for changes to torrentFilesFilterInput // listen for changes to torrentFilesFilterInput
$('torrentFilesFilterInput').addEvent('input', function() { $('torrentFilesFilterInput').addEvent('input', function() {
const value = $('torrentFilesFilterInput').get("value"); const value = $('torrentFilesFilterInput').get("value");
if (value !== prevTorrentFilesFilterValue) { if (value !== prevTorrentFilesFilterValue) {
prevTorrentFilesFilterValue = value; prevTorrentFilesFilterValue = value;
@ -561,12 +583,12 @@ $('torrentFilesFilterInput').addEvent('input', function() {
expandAllNodes(); expandAllNodes();
}, 400); }, 400);
} }
}); });
/** /**
* Show/hide a node's row * Show/hide a node's row
*/ */
const _hideNode = function(node, shouldHide) { const _hideNode = function(node, shouldHide) {
const span = $('filesTablefileName' + node.rowId); const span = $('filesTablefileName' + node.rowId);
// span won't exist if row has been filtered out // span won't exist if row has been filtered out
if (span === null) if (span === null)
@ -576,12 +598,12 @@ const _hideNode = function(node, shouldHide) {
rowElem.addClass("invisible"); rowElem.addClass("invisible");
else else
rowElem.removeClass("invisible"); rowElem.removeClass("invisible");
} }
/** /**
* Update a node's collapsed state and icon * Update a node's collapsed state and icon
*/ */
const _updateNodeState = function(node, isCollapsed) { const _updateNodeState = function(node, isCollapsed) {
const span = $('filesTablefileName' + node.rowId); const span = $('filesTablefileName' + node.rowId);
// span won't exist if row has been filtered out // span won't exist if row has been filtered out
if (span === null) if (span === null)
@ -598,28 +620,28 @@ const _updateNodeState = function(node, isCollapsed) {
collapseIcon.addClass("rotate"); collapseIcon.addClass("rotate");
else else
collapseIcon.removeClass("rotate"); collapseIcon.removeClass("rotate");
} }
const _isCollapsed = function(node) { const _isCollapsed = function(node) {
const span = $('filesTablefileName' + node.rowId); const span = $('filesTablefileName' + node.rowId);
if (span === null) if (span === null)
return true; return true;
const td = span.parentElement; const td = span.parentElement;
return (td.get("data-collapsed") === "true"); return (td.get("data-collapsed") === "true");
}; };
const expandNode = function(node) { const expandNode = function(node) {
_collapseNode(node, false, false, false); _collapseNode(node, false, false, false);
torrentFilesTable.altRow(); torrentFilesTable.altRow();
}; };
const collapseNode = function(node) { const collapseNode = function(node) {
_collapseNode(node, true, false, false); _collapseNode(node, true, false, false);
torrentFilesTable.altRow(); torrentFilesTable.altRow();
}; };
const expandAllNodes = function() { const expandAllNodes = function() {
const root = torrentFilesTable.getRoot(); const root = torrentFilesTable.getRoot();
root.children.each(function(node) { root.children.each(function(node) {
node.children.each(function(child) { node.children.each(function(child) {
@ -627,9 +649,9 @@ const expandAllNodes = function() {
}); });
}); });
torrentFilesTable.altRow(); torrentFilesTable.altRow();
}; };
const collapseAllNodes = function() { const collapseAllNodes = function() {
const root = torrentFilesTable.getRoot(); const root = torrentFilesTable.getRoot();
root.children.each(function(node) { root.children.each(function(node) {
node.children.each(function(child) { node.children.each(function(child) {
@ -637,16 +659,16 @@ const collapseAllNodes = function() {
}); });
}); });
torrentFilesTable.altRow(); torrentFilesTable.altRow();
} }
/** /**
* Collapses a folder node with the option to recursively collapse all children * Collapses a folder node with the option to recursively collapse all children
* @param {FolderNode} node the node to collapse/expand * @param {FolderNode} node the node to collapse/expand
* @param {boolean} shouldCollapse true if the node should be collapsed, false if it should be expanded * @param {boolean} shouldCollapse true if the node should be collapsed, false if it should be expanded
* @param {boolean} applyToChildren true if the node's children should also be collapsed, recursively * @param {boolean} applyToChildren true if the node's children should also be collapsed, recursively
* @param {boolean} isChildNode true if the current node is a child of the original node we collapsed/expanded * @param {boolean} isChildNode true if the current node is a child of the original node we collapsed/expanded
*/ */
const _collapseNode = function(node, shouldCollapse, applyToChildren, isChildNode) { const _collapseNode = function(node, shouldCollapse, applyToChildren, isChildNode) {
if (!node.isFolder) if (!node.isFolder)
return; return;
@ -671,4 +693,7 @@ const _collapseNode = function(node, shouldCollapse, applyToChildren, isChildNod
_collapseNode(child, shouldCollapse, applyToChildren, true); _collapseNode(child, shouldCollapse, applyToChildren, true);
}); });
}; };
return exports();
})();

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

@ -28,7 +28,18 @@
'use strict'; 'use strict';
const clearData = function() { if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.PropGeneral = (function() {
const exports = function() {
return {
updateData: updateData
};
};
const clearData = function() {
$('time_elapsed').set('html', ''); $('time_elapsed').set('html', '');
$('eta').set('html', ''); $('eta').set('html', '');
$('nb_connections').set('html', ''); $('nb_connections').set('html', '');
@ -53,10 +64,10 @@ const clearData = function() {
$('torrent_hash').set('html', ''); $('torrent_hash').set('html', '');
$('save_path').set('html', ''); $('save_path').set('html', '');
$('comment').set('html', ''); $('comment').set('html', '');
}; };
let loadTorrentDataTimer; let loadTorrentDataTimer;
const loadTorrentData = function() { const loadTorrentData = function() {
if ($('prop_general').hasClass('invisible') if ($('prop_general').hasClass('invisible')
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) { || $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
// Tab changed, don't do anything // Tab changed, don't do anything
@ -88,13 +99,13 @@ const loadTorrentData = function() {
// Update Torrent data // Update Torrent data
if (data.seeding_time > 0) if (data.seeding_time > 0)
temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]" temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", friendlyDuration(data.time_elapsed)) .replace("%1", window.qBittorrent.Misc.friendlyDuration(data.time_elapsed))
.replace("%2", friendlyDuration(data.seeding_time)); .replace("%2", window.qBittorrent.Misc.friendlyDuration(data.seeding_time));
else else
temp = friendlyDuration(data.time_elapsed); temp = window.qBittorrent.Misc.friendlyDuration(data.time_elapsed);
$('time_elapsed').set('html', temp); $('time_elapsed').set('html', temp);
$('eta').set('html', friendlyDuration(data.eta)); $('eta').set('html', window.qBittorrent.Misc.friendlyDuration(data.eta));
temp = "QBT_TR(%1 (%2 max))QBT_TR[CONTEXT=PropertiesWidget]" temp = "QBT_TR(%1 (%2 max))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", data.nb_connections) .replace("%1", data.nb_connections)
@ -102,32 +113,32 @@ const loadTorrentData = function() {
$('nb_connections').set('html', temp); $('nb_connections').set('html', temp);
temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]" temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", friendlyUnit(data.total_downloaded)) .replace("%1", window.qBittorrent.Misc.friendlyUnit(data.total_downloaded))
.replace("%2", friendlyUnit(data.total_downloaded_session)); .replace("%2", window.qBittorrent.Misc.friendlyUnit(data.total_downloaded_session));
$('total_downloaded').set('html', temp); $('total_downloaded').set('html', temp);
temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]" temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", friendlyUnit(data.total_uploaded)) .replace("%1", window.qBittorrent.Misc.friendlyUnit(data.total_uploaded))
.replace("%2", friendlyUnit(data.total_uploaded_session)); .replace("%2", window.qBittorrent.Misc.friendlyUnit(data.total_uploaded_session));
$('total_uploaded').set('html', temp); $('total_uploaded').set('html', temp);
temp = "QBT_TR(%1 (%2 avg.))QBT_TR[CONTEXT=PropertiesWidget]" temp = "QBT_TR(%1 (%2 avg.))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", friendlyUnit(data.dl_speed, true)) .replace("%1", window.qBittorrent.Misc.friendlyUnit(data.dl_speed, true))
.replace("%2", friendlyUnit(data.dl_speed_avg, true)); .replace("%2", window.qBittorrent.Misc.friendlyUnit(data.dl_speed_avg, true));
$('dl_speed').set('html', temp); $('dl_speed').set('html', temp);
temp = "QBT_TR(%1 (%2 avg.))QBT_TR[CONTEXT=PropertiesWidget]" temp = "QBT_TR(%1 (%2 avg.))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", friendlyUnit(data.up_speed, true)) .replace("%1", window.qBittorrent.Misc.friendlyUnit(data.up_speed, true))
.replace("%2", friendlyUnit(data.up_speed_avg, true)); .replace("%2", window.qBittorrent.Misc.friendlyUnit(data.up_speed_avg, true));
$('up_speed').set('html', temp); $('up_speed').set('html', temp);
temp = (data.dl_limit == -1 ? "∞" : friendlyUnit(data.dl_limit, true)); temp = (data.dl_limit == -1 ? "∞" : window.qBittorrent.Misc.friendlyUnit(data.dl_limit, true));
$('dl_limit').set('html', temp); $('dl_limit').set('html', temp);
temp = (data.up_limit == -1 ? "∞" : friendlyUnit(data.up_limit, true)); temp = (data.up_limit == -1 ? "∞" : window.qBittorrent.Misc.friendlyUnit(data.up_limit, true));
$('up_limit').set('html', temp); $('up_limit').set('html', temp);
$('total_wasted').set('html', friendlyUnit(data.total_wasted)); $('total_wasted').set('html', window.qBittorrent.Misc.friendlyUnit(data.total_wasted));
temp = "QBT_TR(%1 (%2 total))QBT_TR[CONTEXT=PropertiesWidget]" temp = "QBT_TR(%1 (%2 total))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", data.seeds) .replace("%1", data.seeds)
@ -141,7 +152,7 @@ const loadTorrentData = function() {
$('share_ratio').set('html', data.share_ratio.toFixed(2)); $('share_ratio').set('html', data.share_ratio.toFixed(2));
$('reannounce').set('html', friendlyDuration(data.reannounce)); $('reannounce').set('html', window.qBittorrent.Misc.friendlyDuration(data.reannounce));
if (data.last_seen != -1) if (data.last_seen != -1)
temp = new Date(data.last_seen * 1000).toLocaleString(); temp = new Date(data.last_seen * 1000).toLocaleString();
@ -149,18 +160,18 @@ const loadTorrentData = function() {
temp = "QBT_TR(Never)QBT_TR[CONTEXT=PropertiesWidget]"; temp = "QBT_TR(Never)QBT_TR[CONTEXT=PropertiesWidget]";
$('last_seen').set('html', temp); $('last_seen').set('html', temp);
$('total_size').set('html', friendlyUnit(data.total_size)); $('total_size').set('html', window.qBittorrent.Misc.friendlyUnit(data.total_size));
if (data.pieces_num != -1) if (data.pieces_num != -1)
temp = "QBT_TR(%1 x %2 (have %3))QBT_TR[CONTEXT=PropertiesWidget]" temp = "QBT_TR(%1 x %2 (have %3))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", data.pieces_num) .replace("%1", data.pieces_num)
.replace("%2", friendlyUnit(data.piece_size)) .replace("%2", window.qBittorrent.Misc.friendlyUnit(data.piece_size))
.replace("%3", data.pieces_have); .replace("%3", data.pieces_have);
else else
temp = "QBT_TR(Unknown)QBT_TR[CONTEXT=HttpServer]"; temp = "QBT_TR(Unknown)QBT_TR[CONTEXT=HttpServer]";
$('pieces').set('html', temp); $('pieces').set('html', temp);
$('created_by').set('html', escapeHtml(data.created_by)); $('created_by').set('html', window.qBittorrent.Misc.escapeHtml(data.created_by));
if (data.addition_date != -1) if (data.addition_date != -1)
temp = new Date(data.addition_date * 1000).toLocaleString(); temp = new Date(data.addition_date * 1000).toLocaleString();
else else
@ -182,7 +193,7 @@ const loadTorrentData = function() {
$('save_path').set('html', data.save_path); $('save_path').set('html', data.save_path);
$('comment').set('html', parseHtmlLinks(escapeHtml(data.comment))); $('comment').set('html', window.qBittorrent.Misc.parseHtmlLinks(window.qBittorrent.Misc.escapeHtml(data.comment)));
} }
else { else {
clearData(); clearData();
@ -191,9 +202,12 @@ const loadTorrentData = function() {
loadTorrentDataTimer = loadTorrentData.delay(5000); loadTorrentDataTimer = loadTorrentData.delay(5000);
} }
}).send(); }).send();
}; };
updateTorrentData = function() { const updateData = function() {
clearTimeout(loadTorrentDataTimer); clearTimeout(loadTorrentDataTimer);
loadTorrentData(); loadTorrentData();
}; };
return exports();
})();

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

@ -28,10 +28,23 @@
'use strict'; 'use strict';
let loadTorrentPeersTimer; if (window.qBittorrent === undefined) {
let syncTorrentPeersLastResponseId = 0; window.qBittorrent = {};
let show_flags = true; }
const loadTorrentPeersData = function() {
window.qBittorrent.PropPeers = (function() {
const exports = function() {
return {
updateData: updateData
}
};
const torrentPeersTable = new window.qBittorrent.DynamicTable.TorrentPeersTable();
let loadTorrentPeersTimer;
let syncTorrentPeersLastResponseId = 0;
let show_flags = true;
const loadTorrentPeersData = function() {
if ($('prop_peers').hasClass('invisible') if ($('prop_peers').hasClass('invisible')
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) { || $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
syncTorrentPeersLastResponseId = 0; syncTorrentPeersLastResponseId = 0;
@ -70,7 +83,7 @@ const loadTorrentPeersData = function() {
response['peers'][key]['rowId'] = key; response['peers'][key]['rowId'] = key;
if (response['peers'][key]['client']) if (response['peers'][key]['client'])
response['peers'][key]['client'] = escapeHtml(response['peers'][key]['client']); response['peers'][key]['client'] = window.qBittorrent.Misc.escapeHtml(response['peers'][key]['client']);
torrentPeersTable.updateRowData(response['peers'][key]); torrentPeersTable.updateRowData(response['peers'][key]);
} }
@ -96,14 +109,14 @@ const loadTorrentPeersData = function() {
} }
} }
}).send(); }).send();
}; };
updateTorrentPeersData = function() { const updateData = function() {
clearTimeout(loadTorrentPeersTimer); clearTimeout(loadTorrentPeersTimer);
loadTorrentPeersData(); loadTorrentPeersData();
}; };
const torrentPeersContextMenu = new ContextMenu({ const torrentPeersContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({
targets: '#torrentPeersTableDiv', targets: '#torrentPeersTableDiv',
menu: 'torrentPeersMenu', menu: 'torrentPeersMenu',
actions: { actions: {
@ -160,12 +173,15 @@ const torrentPeersContextMenu = new ContextMenu({
this.hideItem('banPeer'); this.hideItem('banPeer');
} }
} }
}); });
new ClipboardJS('#CopyPeerInfo', { new ClipboardJS('#CopyPeerInfo', {
text: function(trigger) { text: function(trigger) {
return torrentPeersTable.selectedRowsIds().join("\n"); return torrentPeersTable.selectedRowsIds().join("\n");
} }
}); });
torrentPeersTable.setup('torrentPeersTableDiv', 'torrentPeersTableFixedHeaderDiv', torrentPeersContextMenu);
torrentPeersTable.setup('torrentPeersTableDiv', 'torrentPeersTableFixedHeaderDiv', torrentPeersContextMenu); return exports();
})();

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

@ -28,10 +28,23 @@
'use strict'; 'use strict';
this.current_hash = ""; if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.PropTrackers = (function() {
const exports = function() {
return {
updateData: updateData
};
};
let current_hash = "";
let loadTrackersDataTimer; const torrentTrackersTable = new window.qBittorrent.DynamicTable.TorrentTrackersTable();
const loadTrackersData = function() { let loadTrackersDataTimer;
const loadTrackersData = function() {
if ($('prop_trackers').hasClass('invisible') if ($('prop_trackers').hasClass('invisible')
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) { || $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
// Tab changed, don't do anything // Tab changed, don't do anything
@ -63,7 +76,7 @@ const loadTrackersData = function() {
if (trackers) { if (trackers) {
trackers.each(function(tracker) { trackers.each(function(tracker) {
const url = escapeHtml(tracker.url); const url = window.qBittorrent.Misc.escapeHtml(tracker.url);
let status; let status;
switch (tracker.status) { switch (tracker.status) {
case 0: case 0:
@ -92,7 +105,7 @@ const loadTrackersData = function() {
seeds: (tracker.num_seeds >= 0) ? tracker.num_seeds : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]", seeds: (tracker.num_seeds >= 0) ? tracker.num_seeds : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]",
leeches: (tracker.num_leeches >= 0) ? tracker.num_leeches : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]", leeches: (tracker.num_leeches >= 0) ? tracker.num_leeches : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]",
downloaded: (tracker.num_downloaded >= 0) ? tracker.num_downloaded : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]", downloaded: (tracker.num_downloaded >= 0) ? tracker.num_downloaded : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]",
message: escapeHtml(tracker.msg) message: window.qBittorrent.Misc.escapeHtml(tracker.msg)
}; };
torrentTrackersTable.updateRowData(row); torrentTrackersTable.updateRowData(row);
@ -106,14 +119,14 @@ const loadTrackersData = function() {
} }
} }
}).send(); }).send();
}; };
updateTrackersData = function() { const updateData = function() {
clearTimeout(loadTrackersDataTimer); clearTimeout(loadTrackersDataTimer);
loadTrackersData(); loadTrackersData();
}; };
const torrentTrackersContextMenu = new ContextMenu({ const torrentTrackersContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({
targets: '#torrentTrackersTableDiv', targets: '#torrentTrackersTableDiv',
menu: 'torrentTrackersMenu', menu: 'torrentTrackersMenu',
actions: { actions: {
@ -150,9 +163,9 @@ const torrentTrackersContextMenu = new ContextMenu({
this.showItem('CopyTrackerUrl'); this.showItem('CopyTrackerUrl');
} }
} }
}); });
const addTrackerFN = function() { const addTrackerFN = function() {
if (current_hash.length === 0) return; if (current_hash.length === 0) return;
new MochaUI.Window({ new MochaUI.Window({
id: 'trackersPage', id: 'trackersPage',
@ -168,12 +181,12 @@ const addTrackerFN = function() {
width: 500, width: 500,
height: 250, height: 250,
onCloseComplete: function() { onCloseComplete: function() {
updateTrackersData(); updateData();
} }
}); });
}; };
const editTrackerFN = function(element) { const editTrackerFN = function(element) {
if (current_hash.length === 0) return; if (current_hash.length === 0) return;
const trackerUrl = encodeURIComponent(element.childNodes[1].innerText); const trackerUrl = encodeURIComponent(element.childNodes[1].innerText);
@ -191,12 +204,12 @@ const editTrackerFN = function(element) {
width: 500, width: 500,
height: 150, height: 150,
onCloseComplete: function() { onCloseComplete: function() {
updateTrackersData(); updateData();
} }
}); });
}; };
const removeTrackerFN = function(element) { const removeTrackerFN = function(element) {
if (current_hash.length === 0) return; if (current_hash.length === 0) return;
const selectedTrackers = torrentTrackersTable.selectedRowsIds(); const selectedTrackers = torrentTrackersTable.selectedRowsIds();
@ -208,15 +221,18 @@ const removeTrackerFN = function(element) {
urls: selectedTrackers.join("|") urls: selectedTrackers.join("|")
}, },
onSuccess: function() { onSuccess: function() {
updateTrackersData(); updateData();
} }
}).send(); }).send();
}; };
new ClipboardJS('#CopyTrackerUrl', { new ClipboardJS('#CopyTrackerUrl', {
text: function(trigger) { text: function(trigger) {
return torrentTrackersTable.selectedRowsIds().join("\n"); return torrentTrackersTable.selectedRowsIds().join("\n");
} }
}); });
torrentTrackersTable.setup('torrentTrackersTableDiv', 'torrentTrackersTableFixedHeaderDiv', torrentTrackersContextMenu);
torrentTrackersTable.setup('torrentTrackersTableDiv', 'torrentTrackersTableFixedHeaderDiv', torrentTrackersContextMenu); return exports();
})();

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

@ -28,7 +28,18 @@
'use strict'; 'use strict';
const webseedsDynTable = new Class({ if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.PropWebseeds = (function() {
const exports = function() {
return {
updateData: updateData
};
};
const webseedsDynTable = new Class({
initialize: function() {}, initialize: function() {},
@ -78,12 +89,12 @@ const webseedsDynTable = new Class({
} }
tr.injectInside(this.table); tr.injectInside(this.table);
}, },
}); });
this.current_hash = ""; let current_hash = "";
let loadWebSeedsDataTimer; let loadWebSeedsDataTimer;
const loadWebSeedsData = function() { const loadWebSeedsData = function() {
if ($('prop_webseeds').hasClass('invisible') if ($('prop_webseeds').hasClass('invisible')
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) { || $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
// Tab changed, don't do anything // Tab changed, don't do anything
@ -128,12 +139,15 @@ const loadWebSeedsData = function() {
loadWebSeedsDataTimer = loadWebSeedsData.delay(10000); loadWebSeedsDataTimer = loadWebSeedsData.delay(10000);
} }
}).send(); }).send();
}; };
updateWebSeedsData = function() { const updateData = function() {
clearTimeout(loadWebSeedsDataTimer); clearTimeout(loadWebSeedsDataTimer);
loadWebSeedsData(); loadWebSeedsData();
}; };
const wsTable = new webseedsDynTable();
wsTable.setup($('webseedsTable'));
const wsTable = new webseedsDynTable(); return exports();
wsTable.setup($('webseedsTable')); })();

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

@ -33,7 +33,7 @@
const path = new URI().getData('path'); const path = new URI().getData('path');
// set text field to current value // set text field to current value
if (path) if (path)
$('setLocation').value = escapeHtml(decodeURIComponent(path)); $('setLocation').value = window.qBittorrent.Misc.escapeHtml(decodeURIComponent(path));
$('setLocation').focus(); $('setLocation').focus();
$('setLocationButton').addEvent('click', function(e) { $('setLocationButton').addEvent('click', function(e) {

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

@ -37,9 +37,9 @@
const origValues = new URI().getData('orig').split('|'); const origValues = new URI().getData('orig').split('|');
const values = { const values = {
ratioLimit: friendlyFloat(origValues[0], 2), ratioLimit: window.qBittorrent.Misc.friendlyFloat(origValues[0], 2),
seedingTimeLimit: parseInt(origValues[1]), seedingTimeLimit: parseInt(origValues[1]),
maxRatio: friendlyFloat(origValues[2], 2), maxRatio: window.qBittorrent.Misc.friendlyFloat(origValues[2], 2),
maxSeedingTime: parseInt(origValues[3]) maxSeedingTime: parseInt(origValues[3])
}; };

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

@ -23,7 +23,7 @@
<label for="autoTMM">QBT_TR(Torrent Management Mode:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label> <label for="autoTMM">QBT_TR(Torrent Management Mode:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
</td> </td>
<td> <td>
<select id="autoTMM" name="autoTMM" onchange="changeTMM(this)"> <select id="autoTMM" name="autoTMM" onchange="qBittorrent.Download.changeTMM(this)">
<option selected value="false">Manual</option> <option selected value="false">Manual</option>
<option value="true">Automatic</option> <option value="true">Automatic</option>
</select> </select>
@ -51,7 +51,7 @@
</td> </td>
<td> <td>
<div class="select-watched-folder-editable"> <div class="select-watched-folder-editable">
<select id="categorySelect" onchange="changeCategorySelect(this)"> <select id="categorySelect" onchange="qBittorrent.Download.changeCategorySelect(this)">
<option selected value="\other"></option> <option selected value="\other"></option>
</select> </select>
<input name="category" type="text" value="" /> <input name="category" type="text" value="" />

2
src/webui/www/private/views/about.html

@ -681,6 +681,7 @@
<script> <script>
'use strict'; 'use strict';
(function() {
$('qbittorrentVersion').innerText = ("qBittorrent " + qbtVersion() $('qbittorrentVersion').innerText = ("qBittorrent " + qbtVersion()
+ " QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]"); + " QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]");
@ -699,4 +700,5 @@
$('qbittorrentVersion').textContent += " (" + info.bitness + "-bit)"; $('qbittorrentVersion').textContent += " (" + info.bitness + "-bit)";
} }
}).send(); }).send();
})();
</script> </script>

2
src/webui/www/private/views/aboutToolbar.html

@ -13,6 +13,7 @@
<script> <script>
'use strict'; 'use strict';
(function() {
MochaUI.initializeTabs('aboutTabs'); MochaUI.initializeTabs('aboutTabs');
$('aboutAboutLink').addEvent('click', function() { $('aboutAboutLink').addEvent('click', function() {
@ -44,4 +45,5 @@
$$('.aboutTabContent').addClass('invisible'); $$('.aboutTabContent').addClass('invisible');
$('aboutLibrariesContent').removeClass('invisible'); $('aboutLibrariesContent').removeClass('invisible');
}); });
})();
</script> </script>

19
src/webui/www/private/views/filters.html

@ -32,7 +32,19 @@
<script> <script>
'use strict'; 'use strict';
const categoriesFilterContextMenu = new CategoriesFilterContextMenu({ if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.Filters = (function() {
const exports = function() {
return {
categoriesFilterContextMenu: categoriesFilterContextMenu,
tagsFilterContextMenu: tagsFilterContextMenu
};
};
const categoriesFilterContextMenu = new window.qBittorrent.ContextMenu.CategoriesFilterContextMenu({
targets: '.categoriesFilterContextMenuTarget', targets: '.categoriesFilterContextMenuTarget',
menu: 'categoriesFilterMenu', menu: 'categoriesFilterMenu',
actions: { actions: {
@ -67,7 +79,7 @@
} }
}); });
const tagsFilterContextMenu = new TagsFilterContextMenu({ const tagsFilterContextMenu = new window.qBittorrent.ContextMenu.TagsFilterContextMenu({
targets: '.tagsFilterContextMenuTarget', targets: '.tagsFilterContextMenuTarget',
menu: 'tagsFilterMenu', menu: 'tagsFilterMenu',
actions: { actions: {
@ -107,4 +119,7 @@
if (LocalPreferences.get('filter_tag_collapsed') === "true") if (LocalPreferences.get('filter_tag_collapsed') === "true")
toggleFilterDisplay('tag'); toggleFilterDisplay('tag');
return exports();
})();
</script> </script>

28
src/webui/www/private/views/installsearchplugin.html

@ -20,8 +20,8 @@
<div> <div>
<input type="text" id="newPluginPath" placeholder="QBT_TR(URL or local directory)QBT_TR[CONTEXT=PluginSourceDlg]" autocorrect="off" autocapitalize="none" /> <input type="text" id="newPluginPath" placeholder="QBT_TR(URL or local directory)QBT_TR[CONTEXT=PluginSourceDlg]" autocorrect="off" autocapitalize="none" />
<div style="margin-top: 10px; text-align: center;"> <div style="margin-top: 10px; text-align: center;">
<button id="newPluginCancel" onclick="closeSearchWindow('installSearchPlugin');">QBT_TR(Cancel)QBT_TR[CONTEXT=PluginSourceDlg]</button> <button id="newPluginCancel" onclick="qBittorrent.SearchPlugins.closeSearchWindow('installSearchPlugin');">QBT_TR(Cancel)QBT_TR[CONTEXT=PluginSourceDlg]</button>
<button id="newPluginOk" onclick="newPluginOk();">QBT_TR(Ok)QBT_TR[CONTEXT=PluginSourceDlg]</button> <button id="newPluginOk" onclick="qBittorrent.InstallSearchPlugin.newPluginOk();">QBT_TR(Ok)QBT_TR[CONTEXT=PluginSourceDlg]</button>
</div> </div>
</div> </div>
</div> </div>
@ -29,7 +29,18 @@
<script> <script>
'use strict'; 'use strict';
this.initInstallSearchPlugin = function() { if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.InstallSearchPlugin = (function() {
const exports = function() {
return {
newPluginOk: newPluginOk
};
};
const init = function() {
new Keyboard({ new Keyboard({
defaultEventType: 'keydown', defaultEventType: 'keydown',
events: { events: {
@ -41,7 +52,7 @@
if ((elem.id === "newPluginPath") || (elem.id === "newPluginOk")) if ((elem.id === "newPluginPath") || (elem.id === "newPluginOk"))
newPluginOk(); newPluginOk();
else if (elem.id === "newPluginCancel") else if (elem.id === "newPluginCancel")
closeSearchWindow('installSearchPlugin'); window.qBittorrent.SearchPlugins.closeSearchWindow('installSearchPlugin');
} }
} }
}).activate(); }).activate();
@ -49,7 +60,7 @@
$('newPluginPath').select(); $('newPluginPath').select();
}; };
this.newPluginOk = function() { const newPluginOk = function() {
const path = $("newPluginPath").get("value").trim(); const path = $("newPluginPath").get("value").trim();
if (path) if (path)
new Request({ new Request({
@ -60,10 +71,13 @@
sources: path, sources: path,
}, },
onRequest: function() { onRequest: function() {
closeSearchWindow('installSearchPlugin'); window.qBittorrent.SearchPlugins.closeSearchWindow('installSearchPlugin');
} }
}).send(); }).send();
}; };
initInstallSearchPlugin(); init();
return exports();
})();
</script> </script>

179
src/webui/www/private/views/preferences.html

@ -85,7 +85,7 @@
</tr> </tr>
<tr> <tr>
<td> <td>
<input type="checkbox" id="temppath_checkbox" onclick="updateTempDirEnabled();" /> <input type="checkbox" id="temppath_checkbox" onclick="qBittorrent.Preferences.updateTempDirEnabled();" />
<label for="temppath_checkbox">QBT_TR(Keep incomplete torrents in:)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="temppath_checkbox">QBT_TR(Keep incomplete torrents in:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td> </td>
<td> <td>
@ -94,7 +94,7 @@
</tr> </tr>
<tr> <tr>
<td> <td>
<input type="checkbox" id="exportdir_checkbox" onclick="updateExportDirEnabled();" /> <input type="checkbox" id="exportdir_checkbox" onclick="qBittorrent.Preferences.updateExportDirEnabled();" />
<label for="exportdir_checkbox">QBT_TR(Copy .torrent files to:)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="exportdir_checkbox">QBT_TR(Copy .torrent files to:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td> </td>
<td> <td>
@ -103,7 +103,7 @@
</tr> </tr>
<tr> <tr>
<td> <td>
<input type="checkbox" id="exportdirfin_checkbox" onclick="updateExportDirFinEnabled();" /> <input type="checkbox" id="exportdirfin_checkbox" onclick="qBittorrent.Preferences.updateExportDirFinEnabled();" />
<label for="exportdirfin_checkbox">QBT_TR(Copy .torrent files for finished downloads to:)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="exportdirfin_checkbox">QBT_TR(Copy .torrent files for finished downloads to:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td> </td>
<td> <td>
@ -128,13 +128,13 @@
<td style="padding-top:4px;"><input type="text" id="new_watch_folder_txt" autocorrect="off" autocapitalize="none" /></td> <td style="padding-top:4px;"><input type="text" id="new_watch_folder_txt" autocorrect="off" autocapitalize="none" /></td>
<td style="padding-top:4px;"> <td style="padding-top:4px;">
<div class="select-watched-folder-editable"> <div class="select-watched-folder-editable">
<select id="new_watch_folder_select" onchange="changeWatchFolderSelect(this)"> <select id="new_watch_folder_select" onchange="qBittorrent.Preferences.changeWatchFolderSelect(this)">
<option selected value="watch_folder">QBT_TR(Monitored folder)QBT_TR[CONTEXT=ScanFoldersModel]</option> <option selected 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> <option value="default_folder">QBT_TR(Default save location)QBT_TR[CONTEXT=ScanFoldersModel]</option>
<option value="other">QBT_TR(Other...)QBT_TR[CONTEXT=HttpServer]</option> <option value="other">QBT_TR(Other...)QBT_TR[CONTEXT=HttpServer]</option>
</select> </select>
<input id="new_watch_folder_other_txt" type="text" value="QBT_TR(Monitored folder)QBT_TR[CONTEXT=ScanFoldersModel]" hidden /> <input id="new_watch_folder_other_txt" type="text" value="QBT_TR(Monitored folder)QBT_TR[CONTEXT=ScanFoldersModel]" hidden />
<img src="images/qbt-theme/list-add.svg" alt="Add" style="padding-left:170px;width:16px;cursor:pointer;" onclick="addWatchFolder();" /> <img src="images/qbt-theme/list-add.svg" alt="Add" style="padding-left:170px;width:16px;cursor:pointer;" onclick="qBittorrent.Preferences.addWatchFolder();" />
</div> </div>
</td> </td>
</tr> </tr>
@ -144,7 +144,7 @@
<fieldset class="settings"> <fieldset class="settings">
<legend> <legend>
<input type="checkbox" id="mail_notification_checkbox" onclick="updateMailNotification();" /> <input type="checkbox" id="mail_notification_checkbox" onclick="qBittorrent.Preferences.updateMailNotification();" />
<label for="mail_notification_checkbox">QBT_TR(Email notification upon download completion)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="mail_notification_checkbox">QBT_TR(Email notification upon download completion)QBT_TR[CONTEXT=OptionsDialog]</label>
</legend> </legend>
<table> <table>
@ -178,7 +178,7 @@
</div> </div>
<fieldset class="settings"> <fieldset class="settings">
<legend> <legend>
<input type="checkbox" id="mail_auth_checkbox" onclick="updateMailAuthSettings();" /> <input type="checkbox" id="mail_auth_checkbox" onclick="qBittorrent.Preferences.updateMailAuthSettings();" />
<label for="mail_auth_checkbox">QBT_TR(Authentication)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="mail_auth_checkbox">QBT_TR(Authentication)QBT_TR[CONTEXT=OptionsDialog]</label>
</legend> </legend>
<table> <table>
@ -204,7 +204,7 @@
<fieldset class="settings"> <fieldset class="settings">
<legend> <legend>
<input type="checkbox" id="autorun_checkbox" onclick="updateAutoRun();" /> <input type="checkbox" id="autorun_checkbox" onclick="qBittorrent.Preferences.updateAutoRun();" />
<label for="autorun_checkbox">QBT_TR(Run external program on torrent completion)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="autorun_checkbox">QBT_TR(Run external program on torrent completion)QBT_TR[CONTEXT=OptionsDialog]</label>
</legend> </legend>
<div class="formRow"> <div class="formRow">
@ -242,14 +242,14 @@
<div class="formRow"> <div class="formRow">
<label for="port_value">QBT_TR(Port used for incoming connections:)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="port_value">QBT_TR(Port used for incoming connections:)QBT_TR[CONTEXT=OptionsDialog]</label>
<input type="text" id="port_value" style="width: 4em;" /> <input type="text" id="port_value" style="width: 4em;" />
<button style="margin-left: 1em;" onclick="generateRandomPort();">Random</button> <button style="margin-left: 1em;" onclick="qBittorrent.Preferences.generateRandomPort();">Random</button>
</div> </div>
<div class="formRow"> <div class="formRow">
<input type="checkbox" id="upnp_checkbox" /> <input type="checkbox" id="upnp_checkbox" />
<label for="upnp_checkbox">QBT_TR(Use UPnP / NAT-PMP port forwarding from my router)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="upnp_checkbox">QBT_TR(Use UPnP / NAT-PMP port forwarding from my router)QBT_TR[CONTEXT=OptionsDialog]</label>
</div> </div>
<div class="formRow"> <div class="formRow">
<input type="checkbox" id="random_port_checkbox" onclick="updatePortValueEnabled();" /> <input type="checkbox" id="random_port_checkbox" onclick="qBittorrent.Preferences.updatePortValueEnabled();" />
<label for="random_port_checkbox">QBT_TR(Use different port on each startup)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="random_port_checkbox">QBT_TR(Use different port on each startup)QBT_TR[CONTEXT=OptionsDialog]</label>
</div> </div>
</fieldset> </fieldset>
@ -259,28 +259,28 @@
<table> <table>
<tr> <tr>
<td> <td>
<input type="checkbox" id="max_connec_checkbox" onclick="updateMaxConnecEnabled();" /> <input type="checkbox" id="max_connec_checkbox" onclick="qBittorrent.Preferences.updateMaxConnecEnabled();" />
<label for="max_connec_checkbox">QBT_TR(Global maximum number of connections:)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="max_connec_checkbox">QBT_TR(Global maximum number of connections:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td> </td>
<td><input type="text" id="max_connec_value" style="width: 4em;" /></td> <td><input type="text" id="max_connec_value" style="width: 4em;" /></td>
</tr> </tr>
<tr> <tr>
<td> <td>
<input type="checkbox" id="max_connec_per_torrent_checkbox" onclick="updateMaxConnecPerTorrentEnabled();" /> <input type="checkbox" id="max_connec_per_torrent_checkbox" onclick="qBittorrent.Preferences.updateMaxConnecPerTorrentEnabled();" />
<label for="max_connec_per_torrent_checkbox">QBT_TR(Maximum number of connections per torrent:)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="max_connec_per_torrent_checkbox">QBT_TR(Maximum number of connections per torrent:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td> </td>
<td><input type="text" id="max_connec_per_torrent_value" style="width: 4em;" /></td> <td><input type="text" id="max_connec_per_torrent_value" style="width: 4em;" /></td>
</tr> </tr>
<tr> <tr>
<td> <td>
<input type="checkbox" id="max_uploads_checkbox" onclick="updateMaxUploadsEnabled();" /> <input type="checkbox" id="max_uploads_checkbox" onclick="qBittorrent.Preferences.updateMaxUploadsEnabled();" />
<label for="max_uploads_checkbox">QBT_TR(Global maximum number of upload slots:)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="max_uploads_checkbox">QBT_TR(Global maximum number of upload slots:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td> </td>
<td><input type="text" id="max_uploads_value" style="width: 4em;" /></td> <td><input type="text" id="max_uploads_value" style="width: 4em;" /></td>
</tr> </tr>
<tr> <tr>
<td> <td>
<input type="checkbox" id="max_uploads_per_torrent_checkbox" onclick="updateMaxUploadsPerTorrentEnabled();" /> <input type="checkbox" id="max_uploads_per_torrent_checkbox" onclick="qBittorrent.Preferences.updateMaxUploadsPerTorrentEnabled();" />
<label for="max_uploads_per_torrent_checkbox">QBT_TR(Maximum number of upload slots per torrent:)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="max_uploads_per_torrent_checkbox">QBT_TR(Maximum number of upload slots per torrent:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td> </td>
<td><input type="text" id="max_uploads_per_torrent_value" style="width: 4em;" /></td> <td><input type="text" id="max_uploads_per_torrent_value" style="width: 4em;" /></td>
@ -296,7 +296,7 @@
<label for="peer_proxy_type_select">QBT_TR(Type:)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="peer_proxy_type_select">QBT_TR(Type:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td> </td>
<td> <td>
<select id="peer_proxy_type_select" onchange="updatePeerProxySettings();"> <select id="peer_proxy_type_select" onchange="qBittorrent.Preferences.updatePeerProxySettings();">
<option value="none">QBT_TR((None))QBT_TR[CONTEXT=OptionsDialog]</option> <option value="none">QBT_TR((None))QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="socks4">QBT_TR(SOCKS4)QBT_TR[CONTEXT=OptionsDialog]</option> <option value="socks4">QBT_TR(SOCKS4)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="socks5">QBT_TR(SOCKS5)QBT_TR[CONTEXT=OptionsDialog]</option> <option value="socks5">QBT_TR(SOCKS5)QBT_TR[CONTEXT=OptionsDialog]</option>
@ -327,7 +327,7 @@
</div> </div>
<fieldset class="settings"> <fieldset class="settings">
<legend> <legend>
<input type="checkbox" id="peer_proxy_auth_checkbox" onclick="updatePeerProxyAuthSettings();" /> <input type="checkbox" id="peer_proxy_auth_checkbox" onclick="qBittorrent.Preferences.updatePeerProxyAuthSettings();" />
<label for="peer_proxy_auth_checkbox">QBT_TR(Authentication)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="peer_proxy_auth_checkbox">QBT_TR(Authentication)QBT_TR[CONTEXT=OptionsDialog]</label>
</legend> </legend>
<table> <table>
@ -356,7 +356,7 @@
<fieldset class="settings"> <fieldset class="settings">
<legend> <legend>
<input type="checkbox" id="ipfilter_enabled_checkbox" onclick="updateFilterSettings();" /> <input type="checkbox" id="ipfilter_enabled_checkbox" onclick="qBittorrent.Preferences.updateFilterSettings();" />
<label for="ipfilter_enabled_checkbox">QBT_TR(IP Filtering)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="ipfilter_enabled_checkbox">QBT_TR(IP Filtering)QBT_TR[CONTEXT=OptionsDialog]</label>
</legend> </legend>
<div class="formRow"> <div class="formRow">
@ -414,7 +414,7 @@
<fieldset class="settings"> <fieldset class="settings">
<legend> <legend>
<input type="checkbox" id="limit_sheduling_checkbox" onclick="updateSchedulingEnabled();" /> <input type="checkbox" id="limit_sheduling_checkbox" onclick="qBittorrent.Preferences.updateSchedulingEnabled();" />
<label for="limit_sheduling_checkbox">QBT_TR(Schedule the use of alternative rate limits)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="limit_sheduling_checkbox">QBT_TR(Schedule the use of alternative rate limits)QBT_TR[CONTEXT=OptionsDialog]</label>
</legend> </legend>
<div class="formRow"> <div class="formRow">
@ -488,7 +488,7 @@
<fieldset class="settings"> <fieldset class="settings">
<legend> <legend>
<input type="checkbox" id="queueing_checkbox" onclick="updateQueueingSystem();" /> <input type="checkbox" id="queueing_checkbox" onclick="qBittorrent.Preferences.updateQueueingSystem();" />
<label for="queueing_checkbox">QBT_TR(Torrent Queueing)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="queueing_checkbox">QBT_TR(Torrent Queueing)QBT_TR[CONTEXT=OptionsDialog]</label>
</legend> </legend>
<table> <table>
@ -519,7 +519,7 @@
</table> </table>
<fieldset class="settings"> <fieldset class="settings">
<legend> <legend>
<input type="checkbox" id="dont_count_slow_torrents_checkbox" onclick="updateSlowTorrentsSettings();" /> <input type="checkbox" id="dont_count_slow_torrents_checkbox" onclick="qBittorrent.Preferences.updateSlowTorrentsSettings();" />
<label for="dont_count_slow_torrents_checkbox">QBT_TR(Do not count slow torrents in these limits)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="dont_count_slow_torrents_checkbox">QBT_TR(Do not count slow torrents in these limits)QBT_TR[CONTEXT=OptionsDialog]</label>
</legend> </legend>
<table> <table>
@ -556,7 +556,7 @@
<table> <table>
<tr> <tr>
<td> <td>
<input type="checkbox" id="max_ratio_checkbox" onclick="updateMaxRatioTimeEnabled();" /> <input type="checkbox" id="max_ratio_checkbox" onclick="qBittorrent.Preferences.updateMaxRatioTimeEnabled();" />
<label for="max_ratio_checkbox">QBT_TR(Seed torrents until their ratio reaches)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="max_ratio_checkbox">QBT_TR(Seed torrents until their ratio reaches)QBT_TR[CONTEXT=OptionsDialog]</label>
</td> </td>
<td> <td>
@ -564,7 +564,7 @@
</td> </td>
<tr> <tr>
<td> <td>
<input type="checkbox" id="max_seeding_time_checkbox" onclick="updateMaxRatioTimeEnabled();" /> <input type="checkbox" id="max_seeding_time_checkbox" onclick="qBittorrent.Preferences.updateMaxRatioTimeEnabled();" />
<label for="max_seeding_time_checkbox">QBT_TR(Seed torrents until their seeding time reaches)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="max_seeding_time_checkbox">QBT_TR(Seed torrents until their seeding time reaches)QBT_TR[CONTEXT=OptionsDialog]</label>
</td> </td>
<td> <td>
@ -588,7 +588,7 @@
<fieldset class="settings"> <fieldset class="settings">
<legend> <legend>
<input type="checkbox" id="add_trackers_checkbox" onclick="updateAddTrackersEnabled();" /> <input type="checkbox" id="add_trackers_checkbox" onclick="qBittorrent.Preferences.updateAddTrackersEnabled();" />
<label for="add_trackers_checkbox">QBT_TR(Automatically add these trackers to new downloads:)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="add_trackers_checkbox">QBT_TR(Automatically add these trackers to new downloads:)QBT_TR[CONTEXT=OptionsDialog]</label>
</legend> </legend>
<textarea id="add_trackers_textarea" rows="5" cols="70"></textarea> <textarea id="add_trackers_textarea" rows="5" cols="70"></textarea>
@ -673,7 +673,7 @@
</div> </div>
<fieldset class="settings"> <fieldset class="settings">
<legend> <legend>
<input type="checkbox" id="use_https_checkbox" onclick="updateHttpsSettings();" /> <input type="checkbox" id="use_https_checkbox" onclick="qBittorrent.Preferences.updateHttpsSettings();" />
<label for="use_https_checkbox">QBT_TR(Use HTTPS instead of HTTP)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="use_https_checkbox">QBT_TR(Use HTTPS instead of HTTP)QBT_TR[CONTEXT=OptionsDialog]</label>
</legend> </legend>
<table> <table>
@ -722,7 +722,7 @@
<label for="bypass_local_auth_checkbox">QBT_TR(Bypass authentication for clients on localhost)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="bypass_local_auth_checkbox">QBT_TR(Bypass authentication for clients on localhost)QBT_TR[CONTEXT=OptionsDialog]</label>
</div> </div>
<div class="formRow"> <div class="formRow">
<input type="checkbox" id="bypass_auth_subnet_whitelist_checkbox" onclick="updateBypasssAuthSettings();" /> <input type="checkbox" id="bypass_auth_subnet_whitelist_checkbox" onclick="qBittorrent.Preferences.updateBypasssAuthSettings();" />
<label for="bypass_auth_subnet_whitelist_checkbox">QBT_TR(Bypass authentication for clients in whitelisted IP subnets)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="bypass_auth_subnet_whitelist_checkbox">QBT_TR(Bypass authentication for clients in whitelisted IP subnets)QBT_TR[CONTEXT=OptionsDialog]</label>
</div> </div>
<div class="formRow" style="padding-left: 30px; padding-top: 5px;"> <div class="formRow" style="padding-left: 30px; padding-top: 5px;">
@ -737,7 +737,7 @@
</fieldset> </fieldset>
<fieldset class="settings"> <fieldset class="settings">
<legend><input type="checkbox" id="use_alt_webui_checkbox" onclick="updateAlternativeWebUISettings();" /> <legend><input type="checkbox" id="use_alt_webui_checkbox" onclick="qBittorrent.Preferences.updateAlternativeWebUISettings();" />
<label for="use_alt_webui_checkbox">QBT_TR(Use alternative Web UI)QBT_TR[CONTEXT=OptionsDialog]</label></legend> <label for="use_alt_webui_checkbox">QBT_TR(Use alternative Web UI)QBT_TR[CONTEXT=OptionsDialog]</label></legend>
<div class="formRow"> <div class="formRow">
<label for="webui_files_location_textarea">QBT_TR(Files location:)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="webui_files_location_textarea">QBT_TR(Files location:)QBT_TR[CONTEXT=OptionsDialog]</label>
@ -758,7 +758,7 @@
<fieldset class="settings"> <fieldset class="settings">
<legend> <legend>
<input type="checkbox" id="host_header_validation_checkbox" onclick="updateHostHeaderValidationSettings();" /> <input type="checkbox" id="host_header_validation_checkbox" onclick="qBittorrent.Preferences.updateHostHeaderValidationSettings();" />
<label for="host_header_validation_checkbox">QBT_TR(Enable Host header validation)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="host_header_validation_checkbox">QBT_TR(Enable Host header validation)QBT_TR[CONTEXT=OptionsDialog]</label>
</legend> </legend>
<table> <table>
@ -777,14 +777,14 @@
<fieldset class="settings"> <fieldset class="settings">
<legend> <legend>
<input type="checkbox" id="use_dyndns_checkbox" onclick="updateDynDnsSettings();" /> <input type="checkbox" id="use_dyndns_checkbox" onclick="qBittorrent.Preferences.updateDynDnsSettings();" />
<label for="use_dyndns_checkbox">QBT_TR(Update my dynamic domain name)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="use_dyndns_checkbox">QBT_TR(Update my dynamic domain name)QBT_TR[CONTEXT=OptionsDialog]</label>
</legend> </legend>
<select id="dyndns_select"> <select id="dyndns_select">
<option value="0">DynDNS</option> <option value="0">DynDNS</option>
<option value="1">NO-IP</option> <option value="1">NO-IP</option>
</select> </select>
<input type="button" value="QBT_TR(Register)QBT_TR[CONTEXT=OptionsDialog]" onclick="registerDynDns();" /> <input type="button" value="QBT_TR(Register)QBT_TR[CONTEXT=OptionsDialog]" onclick="qBittorrent.Preferences.registerDynDns();" />
<table style="margin-top: 10px;"> <table style="margin-top: 10px;">
<tr> <tr>
<td> <td>
@ -1079,20 +1079,60 @@
</fieldset> </fieldset>
</div> </div>
<div style="text-align: center; margin-top: 1em;"><input type="button" value="QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" onclick="applyPreferences();" /></div> <div style="text-align: center; margin-top: 1em;"><input type="button" value="QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" onclick="qBittorrent.Preferences.applyPreferences();" /></div>
<script> <script>
'use strict'; 'use strict';
if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.Preferences = (function() {
const exports = function() {
return {
updateTempDirEnabled: updateTempDirEnabled,
updateExportDirEnabled: updateExportDirEnabled,
updateExportDirFinEnabled: updateExportDirFinEnabled,
addWatchFolder: addWatchFolder,
changeWatchFolderSelect: changeWatchFolderSelect,
updateMailNotification: updateMailNotification,
updateMailAuthSettings: updateMailAuthSettings,
updateAutoRun: updateAutoRun,
generateRandomPort: generateRandomPort,
updatePortValueEnabled: updatePortValueEnabled,
updateMaxConnecEnabled: updateMaxConnecEnabled,
updateMaxConnecPerTorrentEnabled: updateMaxConnecPerTorrentEnabled,
updateMaxUploadsEnabled: updateMaxUploadsEnabled,
updateMaxUploadsPerTorrentEnabled: updateMaxUploadsPerTorrentEnabled,
updatePeerProxySettings: updatePeerProxySettings,
updatePeerProxyAuthSettings: updatePeerProxyAuthSettings,
updateFilterSettings: updateFilterSettings,
updateSchedulingEnabled: updateSchedulingEnabled,
updateQueueingSystem: updateQueueingSystem,
updateSlowTorrentsSettings: updateSlowTorrentsSettings,
updateMaxRatioTimeEnabled: updateMaxRatioTimeEnabled,
updateMaxRatioTimeEnabled: updateMaxRatioTimeEnabled,
updateAddTrackersEnabled: updateAddTrackersEnabled,
updateHttpsSettings: updateHttpsSettings,
updateBypasssAuthSettings: updateBypasssAuthSettings,
updateAlternativeWebUISettings: updateAlternativeWebUISettings,
updateHostHeaderValidationSettings: updateHostHeaderValidationSettings,
updateDynDnsSettings: updateDynDnsSettings,
registerDynDns: registerDynDns,
applyPreferences: applyPreferences
};
};
// Downloads tab // Downloads tab
this.WatchedFoldersTable = new HtmlTable($("watched_folders_tab")); const WatchedFoldersTable = new HtmlTable($("watched_folders_tab"));
this.updateTempDirEnabled = function() { const updateTempDirEnabled = function() {
const isTempDirEnabled = $('temppath_checkbox').getProperty('checked'); const isTempDirEnabled = $('temppath_checkbox').getProperty('checked');
$('temppath_text').setProperty('disabled', !isTempDirEnabled); $('temppath_text').setProperty('disabled', !isTempDirEnabled);
}; };
this.addWatchFolder = function() { const addWatchFolder = function() {
const new_folder = $('new_watch_folder_txt').getProperty('value').trim(); const new_folder = $('new_watch_folder_txt').getProperty('value').trim();
if (new_folder.length <= 0) return; if (new_folder.length <= 0) return;
@ -1112,7 +1152,7 @@
$('new_watch_folder_other_txt').setProperty('value', text); $('new_watch_folder_other_txt').setProperty('value', text);
}; };
this.changeWatchFolderSelect = function(item) { const changeWatchFolderSelect = function(item) {
if (item.value == "other") { if (item.value == "other") {
item.nextElementSibling.hidden = false; item.nextElementSibling.hidden = false;
item.nextElementSibling.value = 'QBT_TR(Type folder here)QBT_TR[CONTEXT=HttpServer]'; item.nextElementSibling.value = 'QBT_TR(Type folder here)QBT_TR[CONTEXT=HttpServer]';
@ -1125,11 +1165,11 @@
} }
}; };
this.pushWatchFolder = function(pos, folder, sel, other) { const pushWatchFolder = function(pos, folder, sel, other) {
const myinput = "<input id='text_watch_" + pos + "' type='text' value='" + folder + "'>"; const myinput = "<input id='text_watch_" + pos + "' type='text' value='" + folder + "'>";
const disableInput = (sel != "other"); const disableInput = (sel != "other");
const mycb = "<div class='select-watched-folder-editable'>" const mycb = "<div class='select-watched-folder-editable'>"
+ "<select id ='cb_watch_" + pos + "' onchange='changeWatchFolderSelect(this)'>" + "<select id ='cb_watch_" + pos + "' onchange='qBittorrent.Preferences.changeWatchFolderSelect(this)'>"
+ "<option value='watch_folder'>QBT_TR(Monitored folder)QBT_TR[CONTEXT=ScanFoldersModel]</option>" + "<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>" + "<option value='default_folder'>QBT_TR(Default save location)QBT_TR[CONTEXT=ScanFoldersModel]</option>"
+ "<option value='other'>QBT_TR(Other...)QBT_TR[CONTEXT=HttpServer]</option>" + "<option value='other'>QBT_TR(Other...)QBT_TR[CONTEXT=HttpServer]</option>"
@ -1145,7 +1185,7 @@
$('cb_watch_txt_' + pos).setProperty('value', other); $('cb_watch_txt_' + pos).setProperty('value', other);
}; };
this.getWatchedFolders = function() { const getWatchedFolders = function() {
const nb_folders = $("watched_folders_tab").getChildren("tbody")[0].getChildren("tr").length; const nb_folders = $("watched_folders_tab").getChildren("tbody")[0].getChildren("tr").length;
const folders = new Hash(); const folders = new Hash();
for (let i = 0; i < nb_folders; ++i) { for (let i = 0; i < nb_folders; ++i) {
@ -1165,17 +1205,17 @@
return folders; return folders;
}; };
this.updateExportDirEnabled = function() { const updateExportDirEnabled = function() {
const isExportDirEnabled = $('exportdir_checkbox').getProperty('checked'); const isExportDirEnabled = $('exportdir_checkbox').getProperty('checked');
$('exportdir_text').setProperty('disabled', !isExportDirEnabled); $('exportdir_text').setProperty('disabled', !isExportDirEnabled);
}; };
this.updateExportDirFinEnabled = function() { const updateExportDirFinEnabled = function() {
const isExportDirFinEnabled = $('exportdirfin_checkbox').getProperty('checked'); const isExportDirFinEnabled = $('exportdirfin_checkbox').getProperty('checked');
$('exportdirfin_text').setProperty('disabled', !isExportDirFinEnabled); $('exportdirfin_text').setProperty('disabled', !isExportDirFinEnabled);
}; };
this.updateMailNotification = function() { const updateMailNotification = function() {
const isMailNotificationEnabled = $('mail_notification_checkbox').getProperty('checked'); const isMailNotificationEnabled = $('mail_notification_checkbox').getProperty('checked');
$('src_email_txt').setProperty('disabled', !isMailNotificationEnabled); $('src_email_txt').setProperty('disabled', !isMailNotificationEnabled);
$('dest_email_txt').setProperty('disabled', !isMailNotificationEnabled); $('dest_email_txt').setProperty('disabled', !isMailNotificationEnabled);
@ -1189,44 +1229,44 @@
} }
}; };
this.updateMailAuthSettings = function() { const updateMailAuthSettings = function() {
const isMailAuthEnabled = $('mail_auth_checkbox').getProperty('checked'); const isMailAuthEnabled = $('mail_auth_checkbox').getProperty('checked');
$('mail_username_text').setProperty('disabled', !isMailAuthEnabled); $('mail_username_text').setProperty('disabled', !isMailAuthEnabled);
$('mail_password_text').setProperty('disabled', !isMailAuthEnabled); $('mail_password_text').setProperty('disabled', !isMailAuthEnabled);
}; };
this.updateAutoRun = function() { const updateAutoRun = function() {
const isAutoRunEnabled = $('autorun_checkbox').getProperty('checked'); const isAutoRunEnabled = $('autorun_checkbox').getProperty('checked');
$('autorunProg_txt').setProperty('disabled', !isAutoRunEnabled); $('autorunProg_txt').setProperty('disabled', !isAutoRunEnabled);
}; };
// Connection tab // Connection tab
this.updatePortValueEnabled = function() { const updatePortValueEnabled = function() {
const checked = $('random_port_checkbox').getProperty('checked'); const checked = $('random_port_checkbox').getProperty('checked');
$('port_value').setProperty('disabled', checked); $('port_value').setProperty('disabled', checked);
}; };
this.updateMaxConnecEnabled = function() { const updateMaxConnecEnabled = function() {
const isMaxConnecEnabled = $('max_connec_checkbox').getProperty('checked'); const isMaxConnecEnabled = $('max_connec_checkbox').getProperty('checked');
$('max_connec_value').setProperty('disabled', !isMaxConnecEnabled); $('max_connec_value').setProperty('disabled', !isMaxConnecEnabled);
}; };
this.updateMaxConnecPerTorrentEnabled = function() { const updateMaxConnecPerTorrentEnabled = function() {
const isMaxConnecPerTorrentEnabled = $('max_connec_per_torrent_checkbox').getProperty('checked'); const isMaxConnecPerTorrentEnabled = $('max_connec_per_torrent_checkbox').getProperty('checked');
$('max_connec_per_torrent_value').setProperty('disabled', !isMaxConnecPerTorrentEnabled); $('max_connec_per_torrent_value').setProperty('disabled', !isMaxConnecPerTorrentEnabled);
}; };
this.updateMaxUploadsEnabled = function() { const updateMaxUploadsEnabled = function() {
const isMaxUploadsEnabled = $('max_uploads_checkbox').getProperty('checked'); const isMaxUploadsEnabled = $('max_uploads_checkbox').getProperty('checked');
$('max_uploads_value').setProperty('disabled', !isMaxUploadsEnabled); $('max_uploads_value').setProperty('disabled', !isMaxUploadsEnabled);
}; };
this.updateMaxUploadsPerTorrentEnabled = function() { const updateMaxUploadsPerTorrentEnabled = function() {
const isMaxUploadsPerTorrentEnabled = $('max_uploads_per_torrent_checkbox').getProperty('checked'); const isMaxUploadsPerTorrentEnabled = $('max_uploads_per_torrent_checkbox').getProperty('checked');
$('max_uploads_per_torrent_value').setProperty('disabled', !isMaxUploadsPerTorrentEnabled); $('max_uploads_per_torrent_value').setProperty('disabled', !isMaxUploadsPerTorrentEnabled);
}; };
this.updatePeerProxySettings = function() { const updatePeerProxySettings = function() {
const isPeerProxyTypeSelected = $('peer_proxy_type_select').getProperty('value') != "none"; const isPeerProxyTypeSelected = $('peer_proxy_type_select').getProperty('value') != "none";
$('peer_proxy_host_text').setProperty('disabled', !isPeerProxyTypeSelected); $('peer_proxy_host_text').setProperty('disabled', !isPeerProxyTypeSelected);
$('peer_proxy_port_value').setProperty('disabled', !isPeerProxyTypeSelected); $('peer_proxy_port_value').setProperty('disabled', !isPeerProxyTypeSelected);
@ -1249,13 +1289,13 @@
} }
}; };
this.updatePeerProxyAuthSettings = function() { const updatePeerProxyAuthSettings = function() {
const isPeerProxyAuthEnabled = $('peer_proxy_auth_checkbox').getProperty('checked'); const isPeerProxyAuthEnabled = $('peer_proxy_auth_checkbox').getProperty('checked');
$('peer_proxy_username_text').setProperty('disabled', !isPeerProxyAuthEnabled); $('peer_proxy_username_text').setProperty('disabled', !isPeerProxyAuthEnabled);
$('peer_proxy_password_text').setProperty('disabled', !isPeerProxyAuthEnabled); $('peer_proxy_password_text').setProperty('disabled', !isPeerProxyAuthEnabled);
}; };
this.updateFilterSettings = function() { const updateFilterSettings = function() {
const isIPFilterEnabled = $('ipfilter_enabled_checkbox').getProperty('checked'); const isIPFilterEnabled = $('ipfilter_enabled_checkbox').getProperty('checked');
$('ipfilter_text').setProperty('disabled', !isIPFilterEnabled); $('ipfilter_text').setProperty('disabled', !isIPFilterEnabled);
$('ipfilter_trackers_checkbox').setProperty('disabled', !isIPFilterEnabled); $('ipfilter_trackers_checkbox').setProperty('disabled', !isIPFilterEnabled);
@ -1263,7 +1303,7 @@
}; };
// Speed tab // Speed tab
this.updateSchedulingEnabled = function() { const updateSchedulingEnabled = function() {
const isLimitSchedulingEnabled = $('limit_sheduling_checkbox').getProperty('checked'); const isLimitSchedulingEnabled = $('limit_sheduling_checkbox').getProperty('checked');
$('schedule_from_hour').setProperty('disabled', !isLimitSchedulingEnabled); $('schedule_from_hour').setProperty('disabled', !isLimitSchedulingEnabled);
$('schedule_from_min').setProperty('disabled', !isLimitSchedulingEnabled); $('schedule_from_min').setProperty('disabled', !isLimitSchedulingEnabled);
@ -1273,7 +1313,7 @@
}; };
// Bittorrent tab // Bittorrent tab
this.updateQueueingSystem = function() { const updateQueueingSystem = function() {
const isQueueingEnabled = $('queueing_checkbox').getProperty('checked'); const isQueueingEnabled = $('queueing_checkbox').getProperty('checked');
$('max_active_dl_value').setProperty('disabled', !isQueueingEnabled); $('max_active_dl_value').setProperty('disabled', !isQueueingEnabled);
$('max_active_up_value').setProperty('disabled', !isQueueingEnabled); $('max_active_up_value').setProperty('disabled', !isQueueingEnabled);
@ -1282,14 +1322,14 @@
updateSlowTorrentsSettings(); updateSlowTorrentsSettings();
}; };
this.updateSlowTorrentsSettings = function() { const updateSlowTorrentsSettings = function() {
const isDontCountSlowTorrentsEnabled = (!$('dont_count_slow_torrents_checkbox').getProperty('disabled')) && $('dont_count_slow_torrents_checkbox').getProperty('checked'); const isDontCountSlowTorrentsEnabled = (!$('dont_count_slow_torrents_checkbox').getProperty('disabled')) && $('dont_count_slow_torrents_checkbox').getProperty('checked');
$('dl_rate_threshold').setProperty('disabled', !isDontCountSlowTorrentsEnabled); $('dl_rate_threshold').setProperty('disabled', !isDontCountSlowTorrentsEnabled);
$('ul_rate_threshold').setProperty('disabled', !isDontCountSlowTorrentsEnabled); $('ul_rate_threshold').setProperty('disabled', !isDontCountSlowTorrentsEnabled);
$('torrent_inactive_timer').setProperty('disabled', !isDontCountSlowTorrentsEnabled); $('torrent_inactive_timer').setProperty('disabled', !isDontCountSlowTorrentsEnabled);
}; };
this.updateMaxRatioTimeEnabled = function() { const updateMaxRatioTimeEnabled = function() {
const isMaxRatioEnabled = $('max_ratio_checkbox').getProperty('checked'); const isMaxRatioEnabled = $('max_ratio_checkbox').getProperty('checked');
$('max_ratio_value').setProperty('disabled', !isMaxRatioEnabled); $('max_ratio_value').setProperty('disabled', !isMaxRatioEnabled);
@ -1299,34 +1339,34 @@
$('max_ratio_act').setProperty('disabled', !(isMaxRatioEnabled || isMaxSeedingTimeEnabled)); $('max_ratio_act').setProperty('disabled', !(isMaxRatioEnabled || isMaxSeedingTimeEnabled));
}; };
this.updateAddTrackersEnabled = function() { const updateAddTrackersEnabled = function() {
const isAddTrackersEnabled = $('add_trackers_checkbox').getProperty('checked'); const isAddTrackersEnabled = $('add_trackers_checkbox').getProperty('checked');
$('add_trackers_textarea').setProperty('disabled', !isAddTrackersEnabled); $('add_trackers_textarea').setProperty('disabled', !isAddTrackersEnabled);
}; };
// Web UI tab // Web UI tab
this.updateHttpsSettings = function() { const updateHttpsSettings = function() {
const isUseHttpsEnabled = $('use_https_checkbox').getProperty('checked'); const isUseHttpsEnabled = $('use_https_checkbox').getProperty('checked');
$('ssl_cert_text').setProperty('disabled', !isUseHttpsEnabled); $('ssl_cert_text').setProperty('disabled', !isUseHttpsEnabled);
$('ssl_key_text').setProperty('disabled', !isUseHttpsEnabled); $('ssl_key_text').setProperty('disabled', !isUseHttpsEnabled);
}; };
this.updateBypasssAuthSettings = function() { const updateBypasssAuthSettings = function() {
const isBypassAuthSubnetWhitelistEnabled = $('bypass_auth_subnet_whitelist_checkbox').getProperty('checked'); const isBypassAuthSubnetWhitelistEnabled = $('bypass_auth_subnet_whitelist_checkbox').getProperty('checked');
$('bypass_auth_subnet_whitelist_textarea').setProperty('disabled', !isBypassAuthSubnetWhitelistEnabled); $('bypass_auth_subnet_whitelist_textarea').setProperty('disabled', !isBypassAuthSubnetWhitelistEnabled);
}; };
this.updateAlternativeWebUISettings = function() { const updateAlternativeWebUISettings = function() {
const isUseAlternativeWebUIEnabled = $('use_alt_webui_checkbox').getProperty('checked'); const isUseAlternativeWebUIEnabled = $('use_alt_webui_checkbox').getProperty('checked');
$('webui_files_location_textarea').setProperty('disabled', !isUseAlternativeWebUIEnabled); $('webui_files_location_textarea').setProperty('disabled', !isUseAlternativeWebUIEnabled);
}; };
this.updateHostHeaderValidationSettings = function() { const updateHostHeaderValidationSettings = function() {
const isHostHeaderValidationEnabled = $('host_header_validation_checkbox').getProperty('checked'); const isHostHeaderValidationEnabled = $('host_header_validation_checkbox').getProperty('checked');
$('webui_domain_textarea').setProperty('disabled', !isHostHeaderValidationEnabled); $('webui_domain_textarea').setProperty('disabled', !isHostHeaderValidationEnabled);
}; };
this.updateDynDnsSettings = function() { const updateDynDnsSettings = function() {
const isDynDnsEnabled = $('use_dyndns_checkbox').getProperty('checked'); const isDynDnsEnabled = $('use_dyndns_checkbox').getProperty('checked');
$('dyndns_select').setProperty('disabled', !isDynDnsEnabled); $('dyndns_select').setProperty('disabled', !isDynDnsEnabled);
$('dyndns_domain_text').setProperty('disabled', !isDynDnsEnabled); $('dyndns_domain_text').setProperty('disabled', !isDynDnsEnabled);
@ -1334,7 +1374,7 @@
$('dyndns_password_text').setProperty('disabled', !isDynDnsEnabled); $('dyndns_password_text').setProperty('disabled', !isDynDnsEnabled);
}; };
this.registerDynDns = function() { const registerDynDns = function() {
if ($('dyndns_select').getProperty('value').toInt() == 1) { if ($('dyndns_select').getProperty('value').toInt() == 1) {
window.open("http://www.no-ip.com/services/managed_dns/free_dynamic_dns.html", "NO-IP Registration"); window.open("http://www.no-ip.com/services/managed_dns/free_dynamic_dns.html", "NO-IP Registration");
} }
@ -1343,14 +1383,14 @@
} }
}; };
this.generateRandomPort = function() { const generateRandomPort = function() {
const min = 1024; const min = 1024;
const max = 65535; const max = 65535;
const port = Math.floor(Math.random() * (max - min + 1) + min); const port = Math.floor(Math.random() * (max - min + 1) + min);
$('port_value').setProperty('value', port); $('port_value').setProperty('value', port);
}; };
this.time_padding = function(val) { const time_padding = function(val) {
let ret = val.toString(); let ret = val.toString();
if (ret.length == 1) if (ret.length == 1)
ret = '0' + ret; ret = '0' + ret;
@ -1358,7 +1398,7 @@
}; };
// Advanced Tab // Advanced Tab
this.updateNetworkInterfaces = function(default_iface) { const updateNetworkInterfaces = function(default_iface) {
const url = 'api/v2/app/networkInterfaceList'; const url = 'api/v2/app/networkInterfaceList';
$('networkInterface').empty(); $('networkInterface').empty();
new Request.JSON({ new Request.JSON({
@ -1380,7 +1420,7 @@
}).send(); }).send();
}; };
this.updateInterfaceAddresses = function(iface, default_addr) { const updateInterfaceAddresses = function(iface, default_addr) {
const url = 'api/v2/app/networkInterfaceAddressList'; const url = 'api/v2/app/networkInterfaceAddressList';
$('optionalIPAddressToBind').empty(); $('optionalIPAddressToBind').empty();
new Request.JSON({ new Request.JSON({
@ -1405,7 +1445,7 @@
}).send(); }).send();
} }
this.loadPreferences = function() { const loadPreferences = function() {
const url = 'api/v2/app/preferences'; const url = 'api/v2/app/preferences';
new Request.JSON({ new Request.JSON({
url: url, url: url,
@ -1425,7 +1465,7 @@
$('preallocateall_checkbox').setProperty('checked', pref.preallocate_all); $('preallocateall_checkbox').setProperty('checked', pref.preallocate_all);
$('appendext_checkbox').setProperty('checked', pref.incomplete_files_ext); $('appendext_checkbox').setProperty('checked', pref.incomplete_files_ext);
// Saving Managmenet // Saving Management
$('default_tmm_combobox').setProperty('value', pref.auto_tmm_enabled); $('default_tmm_combobox').setProperty('value', pref.auto_tmm_enabled);
$('torrent_changed_tmm_combobox').setProperty('value', pref.torrent_changed_tmm_enabled); $('torrent_changed_tmm_combobox').setProperty('value', pref.torrent_changed_tmm_enabled);
$('save_path_changed_tmm_combobox').setProperty('value', pref.save_path_changed_tmm_enabled); $('save_path_changed_tmm_combobox').setProperty('value', pref.save_path_changed_tmm_enabled);
@ -1708,7 +1748,7 @@
}).send(); }).send();
}; };
this.applyPreferences = function() { const applyPreferences = function() {
const settings = new Hash(); const settings = new Hash();
// Validate form data // Validate form data
// Downloads tab // Downloads tab
@ -2094,4 +2134,7 @@
}); });
loadPreferences(); loadPreferences();
return exports();
})();
</script> </script>

2
src/webui/www/private/views/preferencesToolbar.html

@ -14,6 +14,7 @@
<script> <script>
'use strict'; 'use strict';
(function() {
// Tabs // Tabs
MochaUI.initializeTabs('preferencesTabs'); MochaUI.initializeTabs('preferencesTabs');
@ -41,4 +42,5 @@
$$('.PrefTab').addClass('invisible'); $$('.PrefTab').addClass('invisible');
$('AdvancedTab').removeClass('invisible'); $('AdvancedTab').removeClass('invisible');
}); });
})();
</script> </script>

2
src/webui/www/private/views/properties.html

@ -155,7 +155,9 @@
<script> <script>
'use strict'; 'use strict';
(function() {
const selectedTab = $(LocalPreferences.get('selected_tab', 'PropGeneralLink')); const selectedTab = $(LocalPreferences.get('selected_tab', 'PropGeneralLink'));
if (selectedTab) if (selectedTab)
selectedTab.click(); selectedTab.click();
})();
</script> </script>

77
src/webui/www/private/views/search.html

@ -59,9 +59,9 @@
<div style="overflow: hidden; height: 70px;"> <div style="overflow: hidden; height: 70px;">
<div style="margin: 20px 0; height: 30px;"> <div style="margin: 20px 0; height: 30px;">
<input type="text" id="searchPattern" class="searchInputField" placeholder="QBT_TR(Search)QBT_TR[CONTEXT=SearchEngineWidget]" autocorrect="off" autocapitalize="none" /> <input type="text" id="searchPattern" class="searchInputField" placeholder="QBT_TR(Search)QBT_TR[CONTEXT=SearchEngineWidget]" autocorrect="off" autocapitalize="none" />
<select id="categorySelect" class="searchInputField" onchange="categorySelected()"></select> <select id="categorySelect" class="searchInputField" onchange="qBittorrent.Search.categorySelected()"></select>
<select id="pluginsSelect" class="searchInputField" onchange="pluginSelected()"></select> <select id="pluginsSelect" class="searchInputField" onchange="qBittorrent.Search.pluginSelected()"></select>
<button id="startSearchButton" class="searchInputField" onclick="startStopSearch()">QBT_TR(Search)QBT_TR[CONTEXT=SearchEngineWidget]</button> <button id="startSearchButton" class="searchInputField" onclick="qBittorrent.Search.startStopSearch()">QBT_TR(Search)QBT_TR[CONTEXT=SearchEngineWidget]</button>
</div> </div>
</div> </div>
@ -85,19 +85,19 @@
<div style="display: inline-block; float: right;"> <div style="display: inline-block; float: right;">
<label for="searchInTorrentName" style="margin-left: 15px;">QBT_TR(Search in:)QBT_TR[CONTEXT=SearchEngineWidget]</label> <label for="searchInTorrentName" style="margin-left: 15px;">QBT_TR(Search in:)QBT_TR[CONTEXT=SearchEngineWidget]</label>
<select id="searchInTorrentName" onchange="searchInTorrentName()"> <select id="searchInTorrentName" onchange="qBittorrent.Search.searchInTorrentName()">
<option value="names">QBT_TR(Torrent names only)QBT_TR[CONTEXT=SearchEngineWidget]</option> <option value="names">QBT_TR(Torrent names only)QBT_TR[CONTEXT=SearchEngineWidget]</option>
<option value="everywhere">QBT_TR(Everywhere)QBT_TR[CONTEXT=SearchEngineWidget]</option> <option value="everywhere">QBT_TR(Everywhere)QBT_TR[CONTEXT=SearchEngineWidget]</option>
</select> </select>
<span style="margin-left: 15px;">QBT_TR(Seeds:)QBT_TR[CONTEXT=SearchEngineWidget]</span> <span style="margin-left: 15px;">QBT_TR(Seeds:)QBT_TR[CONTEXT=SearchEngineWidget]</span>
<input type="number" min="0" max="1000" id="searchMinSeedsFilter" value="0" onchange="searchSeedsFilterChanged()"> <input type="number" min="0" max="1000" id="searchMinSeedsFilter" value="0" onchange="qBittorrent.Search.searchSeedsFilterChanged()">
<span>to</span> <span>to</span>
<input type="number" min="0" max="1000" id="searchMaxSeedsFilter" value="0" onchange="searchSeedsFilterChanged()"> <input type="number" min="0" max="1000" id="searchMaxSeedsFilter" value="0" onchange="qBittorrent.Search.searchSeedsFilterChanged()">
<span style="margin-left: 15px;">QBT_TR(Size:)QBT_TR[CONTEXT=SearchEngineWidget]</span> <span style="margin-left: 15px;">QBT_TR(Size:)QBT_TR[CONTEXT=SearchEngineWidget]</span>
<input type="number" min="0" max="1000" step=".01" value="0.00" id="searchMinSizeFilter" onchange="searchSizeFilterChanged()"> <input type="number" min="0" max="1000" step=".01" value="0.00" id="searchMinSizeFilter" onchange="qBittorrent.Search.searchSizeFilterChanged()">
<select id="searchMinSizePrefix" onchange="searchSizeFilterPrefixChanged()"> <select id="searchMinSizePrefix" onchange="qBittorrent.Search.searchSizeFilterPrefixChanged()">
<option value="0">QBT_TR(B)QBT_TR[CONTEXT=misc]</option> <option value="0">QBT_TR(B)QBT_TR[CONTEXT=misc]</option>
<option value="1">QBT_TR(KiB)QBT_TR[CONTEXT=misc]</option> <option value="1">QBT_TR(KiB)QBT_TR[CONTEXT=misc]</option>
<option value="2" selected>QBT_TR(MiB)QBT_TR[CONTEXT=misc]</option> <option value="2" selected>QBT_TR(MiB)QBT_TR[CONTEXT=misc]</option>
@ -107,8 +107,8 @@
<option value="6">QBT_TR(EiB)QBT_TR[CONTEXT=misc]</option> <option value="6">QBT_TR(EiB)QBT_TR[CONTEXT=misc]</option>
</select> </select>
<span>to</span> <span>to</span>
<input type="number" min="0" max="1000" step=".01" value="0.00" id="searchMaxSizeFilter" onchange="searchSizeFilterChanged()"> <input type="number" min="0" max="1000" step=".01" value="0.00" id="searchMaxSizeFilter" onchange="qBittorrent.Search.searchSizeFilterChanged()">
<select id="searchMaxSizePrefix" onchange="searchSizeFilterPrefixChanged()"> <select id="searchMaxSizePrefix" onchange="qBittorrent.Search.searchSizeFilterPrefixChanged()">
<option value="0">QBT_TR(B)QBT_TR[CONTEXT=misc]</option> <option value="0">QBT_TR(B)QBT_TR[CONTEXT=misc]</option>
<option value="1">QBT_TR(KiB)QBT_TR[CONTEXT=misc]</option> <option value="1">QBT_TR(KiB)QBT_TR[CONTEXT=misc]</option>
<option value="2" selected>QBT_TR(MiB)QBT_TR[CONTEXT=misc]</option> <option value="2" selected>QBT_TR(MiB)QBT_TR[CONTEXT=misc]</option>
@ -139,7 +139,7 @@
</div> </div>
<div style="height: 30px; padding-top: 10px;"> <div style="height: 30px; padding-top: 10px;">
<button id="manageSearchPlugins" onclick="manageSearchPlugins()">QBT_TR(Search plugins...)QBT_TR[CONTEXT=SearchEngineWidget]</button> <button id="manageSearchPlugins" onclick="qBittorrent.Search.manageSearchPlugins()">QBT_TR(Search plugins...)QBT_TR[CONTEXT=SearchEngineWidget]</button>
</div> </div>
</div> </div>
@ -159,15 +159,42 @@
<script> <script>
'use strict'; 'use strict';
if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.Search = (function() {
const exports = function() {
return {
startStopSearch: startStopSearch,
manageSearchPlugins: manageSearchPlugins,
searchPlugins: searchPlugins,
searchText: searchText,
searchSeedsFilter: searchSeedsFilter,
searchSizeFilter: searchSizeFilter,
init: init,
getPlugin: getPlugin,
searchInTorrentName: searchInTorrentName,
categorySelected: categorySelected,
pluginSelected: pluginSelected,
searchSeedsFilterChanged: searchSeedsFilterChanged,
searchSizeFilterChanged: searchSizeFilterChanged,
searchSizeFilterPrefixChanged: searchSizeFilterPrefixChanged
};
};
let searchResultsTable;
let loadSearchResultsTimer; let loadSearchResultsTimer;
let loadSearchPluginsTimer; let loadSearchPluginsTimer;
let searchResultsRowId = 0; let searchResultsRowId = 0;
let searchRunning = false; let searchRunning = false;
let requestCount = 0; let requestCount = 0;
let searchPlugins = []; const searchPlugins = [];
let prevSearchPluginsResponse; let prevSearchPluginsResponse;
let searchPattern = ""; const searchText = {
let searchFilterPattern = ""; pattern: "",
filterPattern: ""
};
const searchSeedsFilter = { const searchSeedsFilter = {
min: 0, min: 0,
max: 0 max: 0
@ -184,10 +211,10 @@
let prevSelectedPlugin; let prevSelectedPlugin;
let activeSearchId = null; let activeSearchId = null;
const initSearchTab = function() { const init = function() {
// load "Search in" preference from local storage // load "Search in" preference from local storage
$('searchInTorrentName').set('value', (LocalPreferences.get('search_in_filter') === "names") ? "names" : "everywhere"); $('searchInTorrentName').set('value', (LocalPreferences.get('search_in_filter') === "names") ? "names" : "everywhere");
const searchResultsTableContextMenu = new ContextMenu({ const searchResultsTableContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({
targets: '.searchTableRow', targets: '.searchTableRow',
menu: 'searchResultsTableMenu', menu: 'searchResultsTableMenu',
actions: { actions: {
@ -199,6 +226,7 @@
y: -53 y: -53
} }
}); });
searchResultsTable = new window.qBittorrent.DynamicTable.SearchResultsTable();
searchResultsTable.setup('searchResultsTableDiv', 'searchResultsTableFixedHeaderDiv', searchResultsTableContextMenu); searchResultsTable.setup('searchResultsTableDiv', 'searchResultsTableFixedHeaderDiv', searchResultsTableContextMenu);
getPlugins(); getPlugins();
@ -210,7 +238,7 @@
prevNameFilterValue = value; prevNameFilterValue = value;
clearTimeout(searchInNameFilterTimer); clearTimeout(searchInNameFilterTimer);
searchInNameFilterTimer = setTimeout(function() { searchInNameFilterTimer = setTimeout(function() {
searchFilterPattern = value; searchText.filterPattern = value;
searchFilterChanged(); searchFilterChanged();
}, 400); }, 400);
} }
@ -293,7 +321,7 @@
resetFilters(); resetFilters();
searchPattern = pattern; searchText.pattern = pattern;
startSearch(pattern, category, plugins); startSearch(pattern, category, plugins);
} }
else { else {
@ -459,7 +487,10 @@
onSuccess: function(response) { onSuccess: function(response) {
if (response !== prevSearchPluginsResponse) { if (response !== prevSearchPluginsResponse) {
prevSearchPluginsResponse = response; prevSearchPluginsResponse = response;
searchPlugins = response; searchPlugins.length = 0;
response.forEach(function(plugin) {
searchPlugins.push(plugin);
})
const pluginsHtml = []; const pluginsHtml = [];
pluginsHtml.push('<option value="enabled">QBT_TR(Only enabled)QBT_TR[CONTEXT=SearchEngineWidget]</option>'); pluginsHtml.push('<option value="enabled">QBT_TR(Only enabled)QBT_TR[CONTEXT=SearchEngineWidget]</option>');
@ -487,7 +518,7 @@
allPlugins.each(function(plugin) { allPlugins.each(function(plugin) {
if (plugin.enabled === true) if (plugin.enabled === true)
pluginsHtml.push("<option value='" + escapeHtml(plugin.name) + "'>" + escapeHtml(plugin.fullName) + "</option>"); pluginsHtml.push("<option value='" + window.qBittorrent.Misc.escapeHtml(plugin.name) + "'>" + window.qBittorrent.Misc.escapeHtml(plugin.fullName) + "</option>");
}); });
if (pluginsHtml.length > 2) if (pluginsHtml.length > 2)
@ -501,8 +532,8 @@
$('pluginsSelect').setProperty('disabled', searchPluginsEmpty); $('pluginsSelect').setProperty('disabled', searchPluginsEmpty);
$('startSearchButton').setProperty('disabled', searchPluginsEmpty); $('startSearchButton').setProperty('disabled', searchPluginsEmpty);
if (typeof updateSearchPluginsTable === "function") if (window.qBittorrent.SearchPlugins !== undefined)
updateSearchPluginsTable(); window.qBittorrent.SearchPlugins.updateTable();
reselectPlugin(); reselectPlugin();
} }
@ -676,4 +707,6 @@
} }
}); });
return exports();
})();
</script> </script>

67
src/webui/www/private/views/searchplugins.html

@ -65,9 +65,9 @@
<span>QBT_TR(Warning: Be sure to comply with your country's copyright laws when downloading torrents from any of these search engines.)QBT_TR[CONTEXT=PluginSelectDlg]</span> <span>QBT_TR(Warning: Be sure to comply with your country's copyright laws when downloading torrents from any of these search engines.)QBT_TR[CONTEXT=PluginSelectDlg]</span>
<span style="font-style: italic;">QBT_TR(You can get new search engine plugins here:)QBT_TR[CONTEXT=PluginSelectDlg] <a href="http://plugins.qbittorrent.org" target="_blank">http://plugins.qbittorrent.org</a></span> <span style="font-style: italic;">QBT_TR(You can get new search engine plugins here:)QBT_TR[CONTEXT=PluginSelectDlg] <a href="http://plugins.qbittorrent.org" target="_blank">http://plugins.qbittorrent.org</a></span>
<div style="width: 100%; margin-top: 10px;"> <div style="width: 100%; margin-top: 10px;">
<button style="width: 33%; line-height: 1.4em;" onclick="installPlugin();">QBT_TR(Install new plugin)QBT_TR[CONTEXT=PluginSelectDlg]</button> <button style="width: 33%; line-height: 1.4em;" onclick="qBittorrent.SearchPlugins.installPlugin();">QBT_TR(Install new plugin)QBT_TR[CONTEXT=PluginSelectDlg]</button>
<button style="width: 33%; line-height: 1.4em;" onclick="checkForUpdates();">QBT_TR(Check for updates)QBT_TR[CONTEXT=PluginSelectDlg]</button> <button style="width: 33%; line-height: 1.4em;" onclick="qBittorrent.SearchPlugins.checkForUpdates();">QBT_TR(Check for updates)QBT_TR[CONTEXT=PluginSelectDlg]</button>
<button style="width: 32%; line-height: 1.4em;" onclick="closeSearchWindow('searchPlugins');">QBT_TR(Close)QBT_TR[CONTEXT=PluginSelectDlg]</button> <button style="width: 32%; line-height: 1.4em;" onclick="qBittorrent.SearchPlugins.closeSearchWindow('searchPlugins');">QBT_TR(Close)QBT_TR[CONTEXT=PluginSelectDlg]</button>
</div> </div>
</div> </div>
@ -79,12 +79,28 @@
<script> <script>
'use strict'; 'use strict';
this.searchPluginsTableContextMenu = undefined; if (window.qBittorrent === undefined) {
this.prevOffsetLeft = undefined; window.qBittorrent = {};
this.prevOffsetTop = undefined; }
this.initSearchPlugins = function() { window.qBittorrent.SearchPlugins = (function() {
searchPluginsTableContextMenu = new SearchPluginsTableContextMenu({ const exports = function() {
return {
closeSearchWindow: closeSearchWindow,
installPlugin: installPlugin,
checkForUpdates: checkForUpdates,
updateTable: updateTable
};
};
let searchPluginsTable;
let searchPluginsTableContextMenu;
let prevOffsetLeft;
let prevOffsetTop;
const initSearchPlugins = function() {
searchPluginsTable = new window.qBittorrent.DynamicTable.SearchPluginsTable();
searchPluginsTableContextMenu = new window.qBittorrent.ContextMenu.SearchPluginsTableContextMenu({
targets: '.searchPluginsTableRow', targets: '.searchPluginsTableRow',
menu: 'searchPluginsTableMenu', menu: 'searchPluginsTableMenu',
actions: { actions: {
@ -94,14 +110,14 @@
offsets: calculateContextMenuOffsets() offsets: calculateContextMenuOffsets()
}); });
searchPluginsTable.setup('searchPluginsTableDiv', 'searchPluginsTableFixedHeaderDiv', searchPluginsTableContextMenu); searchPluginsTable.setup('searchPluginsTableDiv', 'searchPluginsTableFixedHeaderDiv', searchPluginsTableContextMenu);
updateSearchPluginsTable(); updateTable();
}; };
this.closeSearchWindow = function(id) { const closeSearchWindow = function(id) {
window.parent.MochaUI.closeWindow(window.parent.$(id)); window.parent.MochaUI.closeWindow(window.parent.$(id));
}; };
this.installPlugin = function(path) { const installPlugin = function(path) {
new MochaUI.Window({ new MochaUI.Window({
id: 'installSearchPlugin', id: 'installSearchPlugin',
title: "QBT_TR(Install plugin)QBT_TR[CONTEXT=PluginSourceDlg]", title: "QBT_TR(Install plugin)QBT_TR[CONTEXT=PluginSourceDlg]",
@ -117,7 +133,7 @@
}); });
}; };
this.uninstallPlugin = function() { const uninstallPlugin = function() {
const plugins = searchPluginsTable.selectedRowsIds().join('|'); const plugins = searchPluginsTable.selectedRowsIds().join('|');
const url = new URI('api/v2/search/uninstallPlugin'); const url = new URI('api/v2/search/uninstallPlugin');
new Request({ new Request({
@ -130,11 +146,11 @@
}).send(); }).send();
}; };
this.enablePlugin = function() { const enablePlugin = function() {
const plugins = searchPluginsTable.selectedRowsIds(); const plugins = searchPluginsTable.selectedRowsIds();
let enable = true; let enable = true;
if (plugins && plugins.length) if (plugins && plugins.length)
enable = !getPlugin(plugins[0]).enabled; enable = !window.qBittorrent.Search.getPlugin(plugins[0]).enabled;
const url = new URI('api/v2/search/enablePlugin'); const url = new URI('api/v2/search/enablePlugin');
new Request({ new Request({
@ -148,7 +164,7 @@
}).send(); }).send();
}; };
this.checkForUpdates = function() { const checkForUpdates = function() {
const url = new URI('api/v2/search/updatePlugins'); const url = new URI('api/v2/search/updatePlugins');
new Request({ new Request({
url: url, url: url,
@ -157,7 +173,7 @@
}).send(); }).send();
}; };
this.calculateContextMenuOffsets = function() { const calculateContextMenuOffsets = function() {
prevOffsetLeft = document.getElementById("searchPlugins").getBoundingClientRect().left; prevOffsetLeft = document.getElementById("searchPlugins").getBoundingClientRect().left;
prevOffsetTop = document.getElementById("searchPlugins").getBoundingClientRect().top; prevOffsetTop = document.getElementById("searchPlugins").getBoundingClientRect().top;
@ -167,13 +183,13 @@
}; };
}; };
this.updateSearchPluginsTableContextMenuOffset = function() { const updateSearchPluginsTableContextMenuOffset = function() {
// only re-calculate if window has moved // only re-calculate if window has moved
if ((prevOffsetLeft !== document.getElementById("searchPlugins").getBoundingClientRect().left) || (prevOffsetTop !== document.getElementById("searchPlugins").getBoundingClientRect().top)) if ((prevOffsetLeft !== document.getElementById("searchPlugins").getBoundingClientRect().left) || (prevOffsetTop !== document.getElementById("searchPlugins").getBoundingClientRect().top))
searchPluginsTableContextMenu.options.offsets = calculateContextMenuOffsets(); searchPluginsTableContextMenu.options.offsets = calculateContextMenuOffsets();
}; };
this.setupSearchPluginTableEvents = function(enable) { const setupSearchPluginTableEvents = function(enable) {
if (enable) if (enable)
$$(".searchPluginsTableRow").each(function(target) { $$(".searchPluginsTableRow").each(function(target) {
target.addEventListener('dblclick', enablePlugin, false); target.addEventListener('dblclick', enablePlugin, false);
@ -186,7 +202,7 @@
}); });
}; };
this.updateSearchPluginsTable = function() { const updateTable = function() {
// clear event listeners // clear event listeners
setupSearchPluginTableEvents(false); setupSearchPluginTableEvents(false);
@ -194,8 +210,8 @@
// remove old rows from the table // remove old rows from the table
for (let i = 0; i < oldPlugins.length; ++i) { for (let i = 0; i < oldPlugins.length; ++i) {
let found = false; let found = false;
for (let j = 0; j < searchPlugins.length; ++j) { for (let j = 0; j < window.qBittorrent.Search.searchPlugins.length; ++j) {
if (searchPlugins[j].name === oldPlugins[i]) { if (window.qBittorrent.Search.searchPlugins[j].name === oldPlugins[i]) {
found = true; found = true;
break; break;
} }
@ -204,9 +220,9 @@
searchPluginsTable.removeRow(oldPlugins[i]); searchPluginsTable.removeRow(oldPlugins[i]);
} }
for (let i = 0; i < searchPlugins.length; ++i) { for (let i = 0; i < window.qBittorrent.Search.searchPlugins.length; ++i) {
searchPlugins[i].rowId = searchPlugins[i].name; window.qBittorrent.Search.searchPlugins[i].rowId = window.qBittorrent.Search.searchPlugins[i].name;
searchPluginsTable.updateRowData(searchPlugins[i]); searchPluginsTable.updateRowData(window.qBittorrent.Search.searchPlugins[i]);
} }
searchPluginsTable.updateTable(); searchPluginsTable.updateTable();
@ -217,4 +233,7 @@
}; };
initSearchPlugins(); initSearchPlugins();
return exports();
})();
</script> </script>

18
src/webui/www/private/views/transferlist.html

@ -18,8 +18,19 @@
<script> <script>
'use strict'; 'use strict';
if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.TransferList = (function() {
const exports = function() {
return {
contextMenu: contextMenu,
};
};
//create a context menu //create a context menu
const torrentsTableContextMenu = new TorrentsTableContextMenu({ const contextMenu = new window.qBittorrent.ContextMenu.TorrentsTableContextMenu({
targets: '.torrentsTableContextMenuTarget', targets: '.torrentsTableContextMenuTarget',
menu: 'torrentsTableMenu', menu: 'torrentsTableMenu',
actions: { actions: {
@ -94,5 +105,8 @@
} }
}); });
torrentsTable.setup('torrentsTableDiv', 'torrentsTableFixedHeaderDiv', torrentsTableContextMenu); torrentsTable.setup('torrentsTableDiv', 'torrentsTableFixedHeaderDiv', contextMenu);
return exports();
})();
</script> </script>

Loading…
Cancel
Save