Move JavaScript code into explicit namespaces

This cleans up the global namespace by explicitly exporting shared values. All html and JavaScript files have been converted to use explicit exports except for client.js and mocha-init.js
This commit is contained in:
Thomas Piccirello 2019-08-11 23:53:20 -07:00
parent b144d3b797
commit 1439bcc864
32 changed files with 6204 additions and 5838 deletions

View file

@ -61,7 +61,7 @@
<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>
<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>
</div>
</div>

View file

@ -27,7 +27,7 @@
<label for="autoTMM">QBT_TR(Torrent Management Mode:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
</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 value="true">Automatic</option>
</select>
@ -63,7 +63,7 @@
</td>
<td>
<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>
</select>
<input name="category" type="text" value="" />

View file

@ -30,18 +30,18 @@
}).activate();
window.addEvent('domready', function() {
const uriAction = safeTrim(new URI().getData('action'));
const uriHashes = safeTrim(new URI().getData('hashes'));
const uriCategoryName = safeTrim(new URI().getData('categoryName'));
const uriSavePath = safeTrim(new URI().getData('savePath'));
const uriAction = window.qBittorrent.Misc.safeTrim(new URI().getData('action'));
const uriHashes = window.qBittorrent.Misc.safeTrim(new URI().getData('hashes'));
const uriCategoryName = window.qBittorrent.Misc.safeTrim(new URI().getData('categoryName'));
const uriSavePath = window.qBittorrent.Misc.safeTrim(new URI().getData('savePath'));
if (uriAction === "edit") {
if (!uriCategoryName)
return false;
$('categoryName').set('disabled', true);
$('categoryName').set('value', escapeHtml(uriCategoryName));
$('savePath').set('value', escapeHtml(uriSavePath));
$('categoryName').set('value', window.qBittorrent.Misc.escapeHtml(uriCategoryName));
$('savePath').set('value', window.qBittorrent.Misc.escapeHtml(uriSavePath));
$('savePath').focus();
}
else {
@ -90,7 +90,7 @@
}).send();
},
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();
break;

View file

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

View file

@ -24,21 +24,10 @@
'use strict';
this.torrentsTable = new TorrentsTable();
const torrentTrackersTable = new TorrentTrackersTable();
const torrentPeersTable = new TorrentPeersTable();
const torrentFilesTable = new TorrentFilesTable();
const searchResultsTable = new SearchResultsTable();
const searchPluginsTable = new SearchPluginsTable();
this.torrentsTable = new window.qBittorrent.DynamicTable.TorrentsTable();
let updatePropertiesPanel = function() {};
let updateTorrentData = function() {};
let updateTrackersData = function() {};
let updateTorrentPeersData = function() {};
let updateWebSeedsData = function() {};
let updateTorrentFilesData = function() {};
this.updateMainData = function() {};
let alternativeSpeedLimits = false;
let queueing_enabled = true;
@ -365,12 +354,12 @@ window.addEvent('load', function() {
const create_link = function(hash, text, count) {
const html = '<a href="#" onclick="setCategoryFilter(' + hash + ');return false;">'
+ '<img src="images/qbt-theme/inode-directory.svg"/>'
+ escapeHtml(text) + ' (' + count + ')' + '</a>';
+ window.qBittorrent.Misc.escapeHtml(text) + ' (' + count + ')' + '</a>';
const el = new Element('li', {
id: hash,
html: html
});
categoriesFilterContextMenu.addTarget(el);
window.qBittorrent.Filters.categoriesFilterContextMenu.addTarget(el);
return el;
};
@ -422,12 +411,12 @@ window.addEvent('load', function() {
const createLink = function(hash, text, count) {
const html = '<a href="#" onclick="setTagFilter(' + hash + ');return false;">'
+ '<img src="images/qbt-theme/inode-directory.svg"/>'
+ escapeHtml(text) + ' (' + count + ')' + '</a>';
+ window.qBittorrent.Misc.escapeHtml(text) + ' (' + count + ')' + '</a>';
const el = new Element('li', {
id: hash,
html: html
});
tagsFilterContextMenu.addTarget(el);
window.qBittorrent.Filters.tagsFilterContextMenu.addTarget(el);
return el;
};
@ -579,11 +568,11 @@ window.addEvent('load', function() {
updateFiltersList();
if (update_categories) {
updateCategoryList();
torrentsTableContextMenu.updateCategoriesSubMenu(category_list);
window.qBittorrent.TransferList.contextMenu.updateCategoriesSubMenu(category_list);
}
if (updateTags) {
updateTagList();
torrentsTableContextMenu.updateTagsSubMenu(tagList);
window.qBittorrent.TransferList.contextMenu.updateTagsSubMenu(tagList);
}
if (full_update)
@ -603,39 +592,39 @@ window.addEvent('load', 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)
transfer_info += " [" + friendlyUnit(serverState.dl_rate_limit, true) + "]";
transfer_info += " (" + friendlyUnit(serverState.dl_info_data, false) + ")";
transfer_info += " [" + window.qBittorrent.Misc.friendlyUnit(serverState.dl_rate_limit, true) + "]";
transfer_info += " (" + window.qBittorrent.Misc.friendlyUnit(serverState.dl_info_data, false) + ")";
$("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)
transfer_info += " [" + friendlyUnit(serverState.up_rate_limit, true) + "]";
transfer_info += " (" + friendlyUnit(serverState.up_info_data, false) + ")";
transfer_info += " [" + window.qBittorrent.Misc.friendlyUnit(serverState.up_rate_limit, true) + "]";
transfer_info += " (" + window.qBittorrent.Misc.friendlyUnit(serverState.up_info_data, false) + ")";
$("UpInfos").set('html', transfer_info);
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]";
}
else
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));
// Statistics dialog
if (document.getElementById("statisticspage")) {
$('AlltimeDL').set('html', friendlyUnit(serverState.alltime_dl, false));
$('AlltimeUL').set('html', friendlyUnit(serverState.alltime_ul, false));
$('TotalWastedSession').set('html', friendlyUnit(serverState.total_wasted_session, false));
$('AlltimeDL').set('html', window.qBittorrent.Misc.friendlyUnit(serverState.alltime_dl, false));
$('AlltimeUL').set('html', window.qBittorrent.Misc.friendlyUnit(serverState.alltime_ul, false));
$('TotalWastedSession').set('html', window.qBittorrent.Misc.friendlyUnit(serverState.total_wasted_session, false));
$('GlobalRatio').set('html', serverState.global_ratio);
$('TotalPeerConnections').set('html', serverState.total_peer_connections);
$('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 + "%");
$('ReadCacheOverload').set('html', serverState.read_cache_overload + "%");
$('QueuedIOJobs').set('html', serverState.queued_io_jobs);
$('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")
@ -790,7 +779,7 @@ window.addEvent('load', function() {
const showSearchTab = function() {
if (!searchTabInitialized) {
initSearchTab();
window.qBittorrent.Search.init();
searchTabInitialized = true;
}
@ -878,16 +867,26 @@ window.addEvent('load', function() {
MochaUI.initializeTabs('propertiesTabs');
updatePropertiesPanel = function() {
if (!$('prop_general').hasClass('invisible'))
updateTorrentData();
else if (!$('prop_trackers').hasClass('invisible'))
updateTrackersData();
else if (!$('prop_peers').hasClass('invisible'))
updateTorrentPeersData();
else if (!$('prop_webseeds').hasClass('invisible'))
updateWebSeedsData();
else if (!$('prop_files').hasClass('invisible'))
updateTorrentFilesData();
if (!$('prop_general').hasClass('invisible')) {
if (window.qBittorrent.PropGeneral !== undefined)
window.qBittorrent.PropGeneral.updateData();
}
else if (!$('prop_trackers').hasClass('invisible')) {
if (window.qBittorrent.PropTrackers !== undefined)
window.qBittorrent.PropTrackers.updateData();
}
else if (!$('prop_peers').hasClass('invisible')) {
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) {

View file

@ -28,6 +28,21 @@
'use strict';
if (window.qBittorrent === undefined) {
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
@ -431,7 +446,7 @@ const TorrentsTableContextMenu = new Class({
Object.each(sortedCategories, function(categoryName) {
const categoryHash = genHash(categoryName);
const el = new Element('li', {
html: '<a href="javascript:torrentSetCategoryFN(\'' + categoryHash + '\');"><img src="images/qbt-theme/inode-directory.svg"/> ' + escapeHtml(categoryName) + '</a>'
html: '<a href="javascript:torrentSetCategoryFN(\'' + categoryHash + '\');"><img src="images/qbt-theme/inode-directory.svg"/> ' + window.qBittorrent.Misc.escapeHtml(categoryName) + '</a>'
});
if (first) {
el.addClass('separator');
@ -469,7 +484,7 @@ const TorrentsTableContextMenu = new Class({
const tagHash = genHash(tagName);
const el = new Element('li', {
html: '<a href="#Tag/' + tagHash + '" onclick="event.preventDefault(); torrentSetTagsFN(\'' + tagHash + '\', !event.currentTarget.getElement(\'input[type=checkbox]\').checked);">'
+ '<input type="checkbox" onclick="this.checked = !this.checked;"> ' + escapeHtml(tagName)
+ '<input type="checkbox" onclick="this.checked = !this.checked;"> ' + window.qBittorrent.Misc.escapeHtml(tagName)
+ '</a>'
});
if (i === 0)
@ -522,3 +537,6 @@ const SearchPluginsTableContextMenu = new Class({
this.showItem('Uninstall');
}
});
return exports();
})();

View file

@ -23,6 +23,18 @@
'use strict';
if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.Download = (function() {
const exports = function() {
return {
changeCategorySelect: changeCategorySelect,
changeTMM: changeTMM
};
};
let categories = {};
let defaultSavePath = "";
@ -118,3 +130,6 @@ $(window).addEventListener("load", function() {
getPreferences();
getCategories();
});
return exports();
})();

View file

@ -33,6 +33,22 @@
'use strict';
if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
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;
@ -266,7 +282,7 @@ const DynamicTable = new Class({
setupDynamicTableHeaderContextMenuClass: function() {
if (!DynamicTableHeaderContextMenuClass) {
DynamicTableHeaderContextMenuClass = new Class({
Extends: ContextMenu,
Extends: window.qBittorrent.ContextMenu.ContextMenu,
updateMenuItems: function() {
for (let i = 0; i < this.dynamicTable.columns.length; ++i) {
if (this.dynamicTable.columns[i].caption === '')
@ -298,7 +314,7 @@ const DynamicTable = new Class({
});
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', {
html: html
});
@ -989,7 +1005,7 @@ const TorrentsTable = new Class({
// name, category, tags
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('title', name);
};
@ -1006,7 +1022,7 @@ const TorrentsTable = new Class({
// size
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('title', size);
};
@ -1030,7 +1046,7 @@ const TorrentsTable = new Class({
else {
if (ProgressColumnWidth < 0)
ProgressColumnWidth = td.offsetWidth;
td.adopt(new ProgressBar(progressFormated.toFloat(), {
td.adopt(new window.qBittorrent.ProgressBar.ProgressBar(progressFormated.toFloat(), {
'width': ProgressColumnWidth - 5
}));
td.resized = false;
@ -1084,7 +1100,7 @@ const TorrentsTable = new Class({
// dlspeed
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('title', speed);
};
@ -1094,7 +1110,7 @@ const TorrentsTable = new Class({
// eta
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('title', eta);
};
@ -1102,7 +1118,7 @@ const TorrentsTable = new Class({
// ratio
this.columns['ratio'].updateTd = function(td, 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('title', string);
};
@ -1139,7 +1155,7 @@ const TorrentsTable = new Class({
td.set('title', '∞');
}
else {
const formattedSpeed = friendlyUnit(speed, true);
const formattedSpeed = window.qBittorrent.Misc.friendlyUnit(speed, true);
td.set('html', formattedSpeed);
td.set('title', formattedSpeed);
}
@ -1172,7 +1188,7 @@ const TorrentsTable = new Class({
td.set('title', '∞');
}
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('title', formattedVal);
}
@ -1180,14 +1196,14 @@ const TorrentsTable = new Class({
// time active
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('title', time);
};
// availability
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('title', value);
};
@ -1275,7 +1291,7 @@ const TorrentsTable = new Class({
}
if ((filterTerms !== undefined) && (filterTerms !== null)
&& (filterTerms.length > 0) && !containsAllTerms(name, filterTerms))
&& (filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(name, filterTerms))
return false;
return true;
@ -1446,7 +1462,7 @@ const TorrentPeersTable = new Class({
td.set('title', '');
}
else {
const formattedSpeed = friendlyUnit(speed, true);
const formattedSpeed = window.qBittorrent.Misc.friendlyUnit(speed, true);
td.set('html', formattedSpeed);
td.set('title', formattedSpeed);
}
@ -1457,7 +1473,7 @@ const TorrentPeersTable = new Class({
// downloaded, uploaded
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('title', downloaded);
};
@ -1474,8 +1490,8 @@ const TorrentPeersTable = new Class({
// files
this.columns['files'].updateTd = function(td, row) {
td.innerHTML = escapeHtml(this.getRowValue(row, 0).replace(/\n/g, ';'));
td.title = escapeHtml(this.getRowValue(row, 0));
td.innerHTML = window.qBittorrent.Misc.escapeHtml(this.getRowValue(row, 0).replace(/\n/g, ';'));
td.title = window.qBittorrent.Misc.escapeHtml(this.getRowValue(row, 0));
};
}
@ -1496,17 +1512,17 @@ const SearchResultsTable = new Class({
initColumnsFunctions: function() {
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('title', value);
}
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('title', size);
}
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;
td.set('html', formattedValue);
td.set('title', formattedValue);
@ -1521,8 +1537,8 @@ const SearchResultsTable = new Class({
getFilteredAndSortedRows: function() {
const getSizeFilters = function() {
let minSize = (searchSizeFilter.min > 0.00) ? (searchSizeFilter.min * Math.pow(1024, searchSizeFilter.minUnit)) : 0.00;
let maxSize = (searchSizeFilter.max > 0.00) ? (searchSizeFilter.max * Math.pow(1024, searchSizeFilter.maxUnit)) : 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 = (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)) {
const tmp = minSize;
@ -1537,8 +1553,8 @@ const SearchResultsTable = new Class({
};
const getSeedsFilters = function() {
let minSeeds = (searchSeedsFilter.min > 0) ? searchSeedsFilter.min : 0;
let maxSeeds = (searchSeedsFilter.max > 0) ? searchSeedsFilter.max : 0;
let minSeeds = (window.qBittorrent.Search.searchSeedsFilter.min > 0) ? window.qBittorrent.Search.searchSeedsFilter.min : 0;
let maxSeeds = (window.qBittorrent.Search.searchSeedsFilter.max > 0) ? window.qBittorrent.Search.searchSeedsFilter.max : 0;
if ((minSeeds > maxSeeds) && (maxSeeds > 0)) {
const tmp = minSeeds;
@ -1554,18 +1570,18 @@ const SearchResultsTable = new Class({
let filteredRows = [];
const rows = this.rows.getValues();
const searchTerms = searchPattern.toLowerCase().split(" ");
const filterTerms = searchFilterPattern.toLowerCase().split(" ");
const searchTerms = window.qBittorrent.Search.searchText.pattern.toLowerCase().split(" ");
const filterTerms = window.qBittorrent.Search.searchText.filterPattern.toLowerCase().split(" ");
const sizeFilters = getSizeFilters();
const seedsFilters = getSeedsFilters();
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) {
const row = rows[i];
if (searchInTorrentName && !containsAllTerms(row.full_data.fileName, searchTerms)) continue;
if ((filterTerms.length > 0) && !containsAllTerms(row.full_data.fileName, filterTerms)) continue;
if (searchInTorrentName && !window.qBittorrent.Misc.containsAllTerms(row.full_data.fileName, searchTerms)) 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.max > 0.00) && (row.full_data.fileSize > sizeFilters.max)) continue;
if ((seedsFilters.min > 0) && (row.full_data.nbSeeders < seedsFilters.min)) continue;
@ -1609,7 +1625,7 @@ const SearchPluginsTable = new Class({
initColumnsFunctions: function() {
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('title', value);
}
@ -1663,7 +1679,7 @@ const TorrentFilesTable = new Class({
prevFilteredRows: [],
prevSortedColumn: null,
prevReverseSort: null,
fileTree: new FileTree(),
fileTree: new window.qBittorrent.FileTree.FileTree(),
populateTable: function(root) {
this.fileTree.setRoot(root);
@ -1682,7 +1698,7 @@ const TorrentFilesTable = new Class({
checked: node.checked,
remaining: node.remaining,
progress: node.progress,
priority: normalizePriority(node.priority),
priority: window.qBittorrent.PropFiles.normalizePriority(node.priority),
availability: node.availability,
fileId: -1,
name: node.name
@ -1731,12 +1747,12 @@ const TorrentFilesTable = new Class({
initColumnsFunctions: function() {
const that = this;
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('title', size);
}
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('title', value);
};
@ -1752,7 +1768,7 @@ const TorrentFilesTable = new Class({
const dirImgId = 'filesTableDirImg' + id;
if ($(dirImgId)) {
// just update file name
$(fileNameId).textContent = escapeHtml(value);
$(fileNameId).textContent = window.qBittorrent.Misc.escapeHtml(value);
}
else {
const collapseIcon = new Element('img', {
@ -1763,10 +1779,10 @@ const TorrentFilesTable = new Class({
class: "filesTableCollapseIcon",
id: collapseIconId,
"data-id": id,
onclick: "collapseIconClicked(this)"
onclick: "qBittorrent.PropFiles.collapseIconClicked(this)"
});
const span = new Element('span', {
text: escapeHtml(value),
text: window.qBittorrent.Misc.escapeHtml(value),
id: fileNameId
});
const dirImg = new Element('img', {
@ -1785,7 +1801,7 @@ const TorrentFilesTable = new Class({
else {
const value = this.getRowValue(row);
const span = new Element('span', {
text: escapeHtml(value),
text: window.qBittorrent.Misc.escapeHtml(value),
id: fileNameId,
styles: {
'margin-left': ((node.depth + 1) * 20)
@ -1799,8 +1815,8 @@ const TorrentFilesTable = new Class({
const id = row.rowId;
const value = this.getRowValue(row);
if (isDownloadCheckboxExists(id)) {
updateDownloadCheckbox(id, value);
if (window.qBittorrent.PropFiles.isDownloadCheckboxExists(id)) {
window.qBittorrent.PropFiles.updateDownloadCheckbox(id, value);
}
else {
const treeImg = new Element('img', {
@ -1809,7 +1825,7 @@ const TorrentFilesTable = new Class({
'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);
if (progressBar === null) {
td.adopt(new ProgressBar(value.toFloat(), {
td.adopt(new window.qBittorrent.ProgressBar.ProgressBar(value.toFloat(), {
id: 'pbf_' + id,
width: 80
}));
@ -1835,10 +1851,10 @@ const TorrentFilesTable = new Class({
const id = row.rowId;
const value = this.getRowValue(row);
if (isPriorityComboExists(id))
updatePriorityCombo(id, value);
if (window.qBittorrent.PropFiles.isPriorityComboExists(id))
window.qBittorrent.PropFiles.updatePriorityCombo(id, value);
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;
@ -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);
filteredRows.push(row);
return true;
@ -1985,4 +2001,7 @@ const TorrentFilesTable = new Class({
}
});
return exports();
})();
/*************************************************************/

View file

@ -28,6 +28,21 @@
'use strict';
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,
"Normal": 1,
@ -174,3 +189,6 @@ const FolderNode = new Class({
this.availability = (availability / size);
}
});
return exports();
})();

View file

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

View file

@ -28,10 +28,29 @@
'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
*/
function friendlyUnit(value, isSpeed) {
const friendlyUnit = function(value, isSpeed) {
const units = [
"QBT_TR(B)QBT_TR[CONTEXT=misc]",
"QBT_TR(KiB)QBT_TR[CONTEXT=misc]",
@ -75,7 +94,7 @@ function friendlyUnit(value, isSpeed) {
/*
* JS counterpart of the function in src/misc.cpp
*/
function friendlyDuration(seconds) {
const friendlyDuration = function(seconds) {
const MAX_ETA = 8640000;
if (seconds < 0 || seconds >= MAX_ETA)
return "∞";
@ -97,7 +116,7 @@ function friendlyDuration(seconds) {
return "∞";
}
function friendlyPercentage(value) {
const friendlyPercentage = function(value) {
let percentage = (value * 100).round(1);
if (isNaN(percentage) || (percentage < 0))
percentage = 0;
@ -106,7 +125,7 @@ function friendlyPercentage(value) {
return percentage.toFixed(1) + "%";
}
function friendlyFloat(value, precision) {
const friendlyFloat = function(value, precision) {
return parseFloat(value).toFixed(precision);
}
@ -140,18 +159,18 @@ if (!Date.prototype.toISOString) {
/*
* 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;
return text.replace(exp, "<a target='_blank' href='$1'>$1</a>");
}
function escapeHtml(str) {
const escapeHtml = function(str) {
const div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML;
}
function safeTrim(value) {
const safeTrim = function(value) {
try {
return value.trim();
}
@ -162,7 +181,7 @@ function safeTrim(value) {
}
}
function toFixedPointString(number, digits) {
const toFixedPointString = function(number, digits) {
// Do not round up number
const power = Math.pow(10, digits);
return (Math.floor(power * number) / power).toFixed(digits);
@ -174,7 +193,7 @@ function toFixedPointString(number, digits) {
* @param {Array<String>} terms terms to search for within the text
* @returns {Boolean} true if all terms match the text, false otherwise
*/
function containsAllTerms(text, terms) {
const containsAllTerms = function(text, terms) {
const textToSearch = text.toLowerCase();
return terms.every((function(term) {
const isTermRequired = (term[0] === '+');
@ -191,3 +210,6 @@ function containsAllTerms(text, terms) {
return isTermExcluded ? !textContainsTerm : textContainsTerm;
}));
}
return exports();
})();

View file

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

View file

@ -28,6 +28,17 @@
'use strict';
if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.LocalPreferences = (function() {
const exports = function() {
return {
LocalPreferencesClass: LocalPreferencesClass
};
};
const LocalPreferencesClass = new Class({
get: function(key, defaultValue) {
const value = localStorage.getItem(key);
@ -45,3 +56,6 @@ const LocalPreferencesClass = new Class({
}
}
})
return exports();
})();

View file

@ -28,6 +28,18 @@
'use strict';
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) {
const vals = {
@ -137,4 +149,5 @@ function ProgressBar_checkForParent(id) {
obj.setValue(obj.vals.value);
}
let ProgressBars = 0;
return exports();
})();

View file

@ -28,8 +28,30 @@
'use strict';
if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
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;
this.current_hash = "";
let current_hash = "";
const normalizePriority = function(priority) {
switch (priority) {
@ -358,7 +380,7 @@ const loadTorrentFilesData = function() {
}).send();
};
updateTorrentFilesData = function() {
const updateData = function() {
clearTimeout(loadTorrentFilesDataTimer);
loadTorrentFilesData();
};
@ -371,7 +393,7 @@ const handleNewTorrentFiles = function(files) {
if ((progress === 100) && (file.progress < 1))
progress = 99.9;
const name = escapeHtml(file.name);
const name = window.qBittorrent.Misc.escapeHtml(file.name);
const ignore = (file.priority === FilePriority.Ignored);
const checked = (ignore ? TriState.Unchecked : TriState.Checked);
const remaining = (ignore ? 0 : (file.size * (1.0 - file.progress)));
@ -379,7 +401,7 @@ const handleNewTorrentFiles = function(files) {
fileId: index,
checked: checked,
fileName: name,
name: fileName(name),
name: window.qBittorrent.Filesystem.fileName(name),
size: file.size,
progress: progress,
priority: normalizePriority(file.priority),
@ -398,11 +420,11 @@ const addRowsToTable = function(rows) {
const selectedFiles = torrentFilesTable.selectedRowsIds();
let rowId = 0;
const rootNode = new FolderNode();
const rootNode = new window.qBittorrent.FileTree.FolderNode();
rows.forEach(function(row) {
let parent = rootNode;
const pathFolders = row.fileName.split(PathSeparator);
const pathFolders = row.fileName.split(window.qBittorrent.Filesystem.PathSeparator);
pathFolders.pop();
pathFolders.forEach(function(folderName) {
if (folderName === '.unwanted')
@ -419,7 +441,7 @@ const addRowsToTable = function(rows) {
}
}
if (parentNode === null) {
parentNode = new FolderNode();
parentNode = new window.qBittorrent.FileTree.FolderNode();
parentNode.name = folderName;
parentNode.rowId = rowId;
parentNode.root = parent;
@ -433,7 +455,7 @@ const addRowsToTable = function(rows) {
const isChecked = row.checked ? TriState.Checked : TriState.Unchecked;
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.rowId = rowId;
childNode.size = row.size;
@ -495,7 +517,7 @@ const filesPriorityMenuClicked = function(priority) {
setFilePriority(Object.keys(uniqueRowIds), Object.keys(uniqueFileIds), priority);
};
const torrentFilesContextMenu = new ContextMenu({
const torrentFilesContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({
targets: '#torrentFilesTableDiv tr',
menu: 'torrentFilesMenu',
actions: {
@ -672,3 +694,6 @@ const _collapseNode = function(node, shouldCollapse, applyToChildren, isChildNod
_collapseNode(child, shouldCollapse, applyToChildren, true);
});
};
return exports();
})();

View file

@ -28,6 +28,17 @@
'use strict';
if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.PropGeneral = (function() {
const exports = function() {
return {
updateData: updateData
};
};
const clearData = function() {
$('time_elapsed').set('html', '');
$('eta').set('html', '');
@ -88,13 +99,13 @@ const loadTorrentData = function() {
// Update Torrent data
if (data.seeding_time > 0)
temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", friendlyDuration(data.time_elapsed))
.replace("%2", friendlyDuration(data.seeding_time));
.replace("%1", window.qBittorrent.Misc.friendlyDuration(data.time_elapsed))
.replace("%2", window.qBittorrent.Misc.friendlyDuration(data.seeding_time));
else
temp = friendlyDuration(data.time_elapsed);
temp = window.qBittorrent.Misc.friendlyDuration(data.time_elapsed);
$('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]"
.replace("%1", data.nb_connections)
@ -102,32 +113,32 @@ const loadTorrentData = function() {
$('nb_connections').set('html', temp);
temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", friendlyUnit(data.total_downloaded))
.replace("%2", friendlyUnit(data.total_downloaded_session));
.replace("%1", window.qBittorrent.Misc.friendlyUnit(data.total_downloaded))
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.total_downloaded_session));
$('total_downloaded').set('html', temp);
temp = "QBT_TR(%1 (%2 this session))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", friendlyUnit(data.total_uploaded))
.replace("%2", friendlyUnit(data.total_uploaded_session));
.replace("%1", window.qBittorrent.Misc.friendlyUnit(data.total_uploaded))
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.total_uploaded_session));
$('total_uploaded').set('html', temp);
temp = "QBT_TR(%1 (%2 avg.))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", friendlyUnit(data.dl_speed, true))
.replace("%2", friendlyUnit(data.dl_speed_avg, true));
.replace("%1", window.qBittorrent.Misc.friendlyUnit(data.dl_speed, true))
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.dl_speed_avg, true));
$('dl_speed').set('html', temp);
temp = "QBT_TR(%1 (%2 avg.))QBT_TR[CONTEXT=PropertiesWidget]"
.replace("%1", friendlyUnit(data.up_speed, true))
.replace("%2", friendlyUnit(data.up_speed_avg, true));
.replace("%1", window.qBittorrent.Misc.friendlyUnit(data.up_speed, true))
.replace("%2", window.qBittorrent.Misc.friendlyUnit(data.up_speed_avg, true));
$('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);
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);
$('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]"
.replace("%1", data.seeds)
@ -141,7 +152,7 @@ const loadTorrentData = function() {
$('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)
temp = new Date(data.last_seen * 1000).toLocaleString();
@ -149,18 +160,18 @@ const loadTorrentData = function() {
temp = "QBT_TR(Never)QBT_TR[CONTEXT=PropertiesWidget]";
$('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)
temp = "QBT_TR(%1 x %2 (have %3))QBT_TR[CONTEXT=PropertiesWidget]"
.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);
else
temp = "QBT_TR(Unknown)QBT_TR[CONTEXT=HttpServer]";
$('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)
temp = new Date(data.addition_date * 1000).toLocaleString();
else
@ -182,7 +193,7 @@ const loadTorrentData = function() {
$('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 {
clearData();
@ -193,7 +204,10 @@ const loadTorrentData = function() {
}).send();
};
updateTorrentData = function() {
const updateData = function() {
clearTimeout(loadTorrentDataTimer);
loadTorrentData();
};
return exports();
})();

View file

@ -28,9 +28,22 @@
'use strict';
if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
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')
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
@ -70,7 +83,7 @@ const loadTorrentPeersData = function() {
response['peers'][key]['rowId'] = key;
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]);
}
@ -98,12 +111,12 @@ const loadTorrentPeersData = function() {
}).send();
};
updateTorrentPeersData = function() {
const updateData = function() {
clearTimeout(loadTorrentPeersTimer);
loadTorrentPeersData();
};
const torrentPeersContextMenu = new ContextMenu({
const torrentPeersContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({
targets: '#torrentPeersTableDiv',
menu: 'torrentPeersMenu',
actions: {
@ -169,3 +182,6 @@ new ClipboardJS('#CopyPeerInfo', {
});
torrentPeersTable.setup('torrentPeersTableDiv', 'torrentPeersTableFixedHeaderDiv', torrentPeersContextMenu);
return exports();
})();

View file

@ -28,9 +28,22 @@
'use strict';
this.current_hash = "";
if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.PropTrackers = (function() {
const exports = function() {
return {
updateData: updateData
};
};
let current_hash = "";
const torrentTrackersTable = new window.qBittorrent.DynamicTable.TorrentTrackersTable();
let loadTrackersDataTimer;
const loadTrackersData = function() {
if ($('prop_trackers').hasClass('invisible')
|| $('propertiesPanel_collapseToggle').hasClass('panel-expand')) {
@ -63,7 +76,7 @@ const loadTrackersData = function() {
if (trackers) {
trackers.each(function(tracker) {
const url = escapeHtml(tracker.url);
const url = window.qBittorrent.Misc.escapeHtml(tracker.url);
let status;
switch (tracker.status) {
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]",
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]",
message: escapeHtml(tracker.msg)
message: window.qBittorrent.Misc.escapeHtml(tracker.msg)
};
torrentTrackersTable.updateRowData(row);
@ -108,12 +121,12 @@ const loadTrackersData = function() {
}).send();
};
updateTrackersData = function() {
const updateData = function() {
clearTimeout(loadTrackersDataTimer);
loadTrackersData();
};
const torrentTrackersContextMenu = new ContextMenu({
const torrentTrackersContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({
targets: '#torrentTrackersTableDiv',
menu: 'torrentTrackersMenu',
actions: {
@ -168,7 +181,7 @@ const addTrackerFN = function() {
width: 500,
height: 250,
onCloseComplete: function() {
updateTrackersData();
updateData();
}
});
};
@ -191,7 +204,7 @@ const editTrackerFN = function(element) {
width: 500,
height: 150,
onCloseComplete: function() {
updateTrackersData();
updateData();
}
});
};
@ -208,7 +221,7 @@ const removeTrackerFN = function(element) {
urls: selectedTrackers.join("|")
},
onSuccess: function() {
updateTrackersData();
updateData();
}
}).send();
};
@ -220,3 +233,6 @@ new ClipboardJS('#CopyTrackerUrl', {
});
torrentTrackersTable.setup('torrentTrackersTableDiv', 'torrentTrackersTableFixedHeaderDiv', torrentTrackersContextMenu);
return exports();
})();

View file

@ -28,6 +28,17 @@
'use strict';
if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
window.qBittorrent.PropWebseeds = (function() {
const exports = function() {
return {
updateData: updateData
};
};
const webseedsDynTable = new Class({
initialize: function() {},
@ -80,7 +91,7 @@ const webseedsDynTable = new Class({
},
});
this.current_hash = "";
let current_hash = "";
let loadWebSeedsDataTimer;
const loadWebSeedsData = function() {
@ -130,10 +141,13 @@ const loadWebSeedsData = function() {
}).send();
};
updateWebSeedsData = function() {
const updateData = function() {
clearTimeout(loadWebSeedsDataTimer);
loadWebSeedsData();
};
const wsTable = new webseedsDynTable();
wsTable.setup($('webseedsTable'));
return exports();
})();

View file

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

View file

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

View file

@ -23,7 +23,7 @@
<label for="autoTMM">QBT_TR(Torrent Management Mode:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
</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 value="true">Automatic</option>
</select>
@ -51,7 +51,7 @@
</td>
<td>
<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>
</select>
<input name="category" type="text" value="" />

View file

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

View file

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

View file

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

View file

@ -20,8 +20,8 @@
<div>
<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;">
<button id="newPluginCancel" onclick="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="newPluginCancel" onclick="qBittorrent.SearchPlugins.closeSearchWindow('installSearchPlugin');">QBT_TR(Cancel)QBT_TR[CONTEXT=PluginSourceDlg]</button>
<button id="newPluginOk" onclick="qBittorrent.InstallSearchPlugin.newPluginOk();">QBT_TR(Ok)QBT_TR[CONTEXT=PluginSourceDlg]</button>
</div>
</div>
</div>
@ -29,7 +29,18 @@
<script>
'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({
defaultEventType: 'keydown',
events: {
@ -41,7 +52,7 @@
if ((elem.id === "newPluginPath") || (elem.id === "newPluginOk"))
newPluginOk();
else if (elem.id === "newPluginCancel")
closeSearchWindow('installSearchPlugin');
window.qBittorrent.SearchPlugins.closeSearchWindow('installSearchPlugin');
}
}
}).activate();
@ -49,7 +60,7 @@
$('newPluginPath').select();
};
this.newPluginOk = function() {
const newPluginOk = function() {
const path = $("newPluginPath").get("value").trim();
if (path)
new Request({
@ -60,10 +71,13 @@
sources: path,
},
onRequest: function() {
closeSearchWindow('installSearchPlugin');
window.qBittorrent.SearchPlugins.closeSearchWindow('installSearchPlugin');
}
}).send();
};
initInstallSearchPlugin();
init();
return exports();
})();
</script>

View file

@ -85,7 +85,7 @@
</tr>
<tr>
<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>
</td>
<td>
@ -94,7 +94,7 @@
</tr>
<tr>
<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>
</td>
<td>
@ -103,7 +103,7 @@
</tr>
<tr>
<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>
</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;">
<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 value="default_folder">QBT_TR(Default save location)QBT_TR[CONTEXT=ScanFoldersModel]</option>
<option value="other">QBT_TR(Other...)QBT_TR[CONTEXT=HttpServer]</option>
</select>
<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>
</td>
</tr>
@ -144,7 +144,7 @@
<fieldset class="settings">
<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>
</legend>
<table>
@ -178,7 +178,7 @@
</div>
<fieldset class="settings">
<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>
</legend>
<table>
@ -204,7 +204,7 @@
<fieldset class="settings">
<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>
</legend>
<div class="formRow">
@ -242,14 +242,14 @@
<div class="formRow">
<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;" />
<button style="margin-left: 1em;" onclick="generateRandomPort();">Random</button>
<button style="margin-left: 1em;" onclick="qBittorrent.Preferences.generateRandomPort();">Random</button>
</div>
<div class="formRow">
<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>
</div>
<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>
</div>
</fieldset>
@ -259,28 +259,28 @@
<table>
<tr>
<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>
</td>
<td><input type="text" id="max_connec_value" style="width: 4em;" /></td>
</tr>
<tr>
<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>
</td>
<td><input type="text" id="max_connec_per_torrent_value" style="width: 4em;" /></td>
</tr>
<tr>
<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>
</td>
<td><input type="text" id="max_uploads_value" style="width: 4em;" /></td>
</tr>
<tr>
<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>
</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>
</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="socks4">QBT_TR(SOCKS4)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="socks5">QBT_TR(SOCKS5)QBT_TR[CONTEXT=OptionsDialog]</option>
@ -327,7 +327,7 @@
</div>
<fieldset class="settings">
<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>
</legend>
<table>
@ -356,7 +356,7 @@
<fieldset class="settings">
<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>
</legend>
<div class="formRow">
@ -414,7 +414,7 @@
<fieldset class="settings">
<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>
</legend>
<div class="formRow">
@ -488,7 +488,7 @@
<fieldset class="settings">
<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>
</legend>
<table>
@ -519,7 +519,7 @@
</table>
<fieldset class="settings">
<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>
</legend>
<table>
@ -556,7 +556,7 @@
<table>
<tr>
<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>
</td>
<td>
@ -564,7 +564,7 @@
</td>
<tr>
<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>
</td>
<td>
@ -588,7 +588,7 @@
<fieldset class="settings">
<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>
</legend>
<textarea id="add_trackers_textarea" rows="5" cols="70"></textarea>
@ -673,7 +673,7 @@
</div>
<fieldset class="settings">
<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>
</legend>
<table>
@ -722,7 +722,7 @@
<label for="bypass_local_auth_checkbox">QBT_TR(Bypass authentication for clients on localhost)QBT_TR[CONTEXT=OptionsDialog]</label>
</div>
<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>
</div>
<div class="formRow" style="padding-left: 30px; padding-top: 5px;">
@ -737,7 +737,7 @@
</fieldset>
<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>
<div class="formRow">
<label for="webui_files_location_textarea">QBT_TR(Files location:)QBT_TR[CONTEXT=OptionsDialog]</label>
@ -758,7 +758,7 @@
<fieldset class="settings">
<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>
</legend>
<table>
@ -777,14 +777,14 @@
<fieldset class="settings">
<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>
</legend>
<select id="dyndns_select">
<option value="0">DynDNS</option>
<option value="1">NO-IP</option>
</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;">
<tr>
<td>
@ -1079,20 +1079,60 @@
</fieldset>
</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>
'use strict';
// Downloads tab
this.WatchedFoldersTable = new HtmlTable($("watched_folders_tab"));
if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
this.updateTempDirEnabled = function() {
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
const WatchedFoldersTable = new HtmlTable($("watched_folders_tab"));
const updateTempDirEnabled = function() {
const isTempDirEnabled = $('temppath_checkbox').getProperty('checked');
$('temppath_text').setProperty('disabled', !isTempDirEnabled);
};
this.addWatchFolder = function() {
const addWatchFolder = function() {
const new_folder = $('new_watch_folder_txt').getProperty('value').trim();
if (new_folder.length <= 0) return;
@ -1112,7 +1152,7 @@
$('new_watch_folder_other_txt').setProperty('value', text);
};
this.changeWatchFolderSelect = function(item) {
const changeWatchFolderSelect = function(item) {
if (item.value == "other") {
item.nextElementSibling.hidden = false;
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 disableInput = (sel != "other");
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='default_folder'>QBT_TR(Default save location)QBT_TR[CONTEXT=ScanFoldersModel]</option>"
+ "<option value='other'>QBT_TR(Other...)QBT_TR[CONTEXT=HttpServer]</option>"
@ -1145,7 +1185,7 @@
$('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 folders = new Hash();
for (let i = 0; i < nb_folders; ++i) {
@ -1165,17 +1205,17 @@
return folders;
};
this.updateExportDirEnabled = function() {
const updateExportDirEnabled = function() {
const isExportDirEnabled = $('exportdir_checkbox').getProperty('checked');
$('exportdir_text').setProperty('disabled', !isExportDirEnabled);
};
this.updateExportDirFinEnabled = function() {
const updateExportDirFinEnabled = function() {
const isExportDirFinEnabled = $('exportdirfin_checkbox').getProperty('checked');
$('exportdirfin_text').setProperty('disabled', !isExportDirFinEnabled);
};
this.updateMailNotification = function() {
const updateMailNotification = function() {
const isMailNotificationEnabled = $('mail_notification_checkbox').getProperty('checked');
$('src_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');
$('mail_username_text').setProperty('disabled', !isMailAuthEnabled);
$('mail_password_text').setProperty('disabled', !isMailAuthEnabled);
};
this.updateAutoRun = function() {
const updateAutoRun = function() {
const isAutoRunEnabled = $('autorun_checkbox').getProperty('checked');
$('autorunProg_txt').setProperty('disabled', !isAutoRunEnabled);
};
// Connection tab
this.updatePortValueEnabled = function() {
const updatePortValueEnabled = function() {
const checked = $('random_port_checkbox').getProperty('checked');
$('port_value').setProperty('disabled', checked);
};
this.updateMaxConnecEnabled = function() {
const updateMaxConnecEnabled = function() {
const isMaxConnecEnabled = $('max_connec_checkbox').getProperty('checked');
$('max_connec_value').setProperty('disabled', !isMaxConnecEnabled);
};
this.updateMaxConnecPerTorrentEnabled = function() {
const updateMaxConnecPerTorrentEnabled = function() {
const isMaxConnecPerTorrentEnabled = $('max_connec_per_torrent_checkbox').getProperty('checked');
$('max_connec_per_torrent_value').setProperty('disabled', !isMaxConnecPerTorrentEnabled);
};
this.updateMaxUploadsEnabled = function() {
const updateMaxUploadsEnabled = function() {
const isMaxUploadsEnabled = $('max_uploads_checkbox').getProperty('checked');
$('max_uploads_value').setProperty('disabled', !isMaxUploadsEnabled);
};
this.updateMaxUploadsPerTorrentEnabled = function() {
const updateMaxUploadsPerTorrentEnabled = function() {
const isMaxUploadsPerTorrentEnabled = $('max_uploads_per_torrent_checkbox').getProperty('checked');
$('max_uploads_per_torrent_value').setProperty('disabled', !isMaxUploadsPerTorrentEnabled);
};
this.updatePeerProxySettings = function() {
const updatePeerProxySettings = function() {
const isPeerProxyTypeSelected = $('peer_proxy_type_select').getProperty('value') != "none";
$('peer_proxy_host_text').setProperty('disabled', !isPeerProxyTypeSelected);
$('peer_proxy_port_value').setProperty('disabled', !isPeerProxyTypeSelected);
@ -1249,13 +1289,13 @@
}
};
this.updatePeerProxyAuthSettings = function() {
const updatePeerProxyAuthSettings = function() {
const isPeerProxyAuthEnabled = $('peer_proxy_auth_checkbox').getProperty('checked');
$('peer_proxy_username_text').setProperty('disabled', !isPeerProxyAuthEnabled);
$('peer_proxy_password_text').setProperty('disabled', !isPeerProxyAuthEnabled);
};
this.updateFilterSettings = function() {
const updateFilterSettings = function() {
const isIPFilterEnabled = $('ipfilter_enabled_checkbox').getProperty('checked');
$('ipfilter_text').setProperty('disabled', !isIPFilterEnabled);
$('ipfilter_trackers_checkbox').setProperty('disabled', !isIPFilterEnabled);
@ -1263,7 +1303,7 @@
};
// Speed tab
this.updateSchedulingEnabled = function() {
const updateSchedulingEnabled = function() {
const isLimitSchedulingEnabled = $('limit_sheduling_checkbox').getProperty('checked');
$('schedule_from_hour').setProperty('disabled', !isLimitSchedulingEnabled);
$('schedule_from_min').setProperty('disabled', !isLimitSchedulingEnabled);
@ -1273,7 +1313,7 @@
};
// Bittorrent tab
this.updateQueueingSystem = function() {
const updateQueueingSystem = function() {
const isQueueingEnabled = $('queueing_checkbox').getProperty('checked');
$('max_active_dl_value').setProperty('disabled', !isQueueingEnabled);
$('max_active_up_value').setProperty('disabled', !isQueueingEnabled);
@ -1282,14 +1322,14 @@
updateSlowTorrentsSettings();
};
this.updateSlowTorrentsSettings = function() {
const updateSlowTorrentsSettings = function() {
const isDontCountSlowTorrentsEnabled = (!$('dont_count_slow_torrents_checkbox').getProperty('disabled')) && $('dont_count_slow_torrents_checkbox').getProperty('checked');
$('dl_rate_threshold').setProperty('disabled', !isDontCountSlowTorrentsEnabled);
$('ul_rate_threshold').setProperty('disabled', !isDontCountSlowTorrentsEnabled);
$('torrent_inactive_timer').setProperty('disabled', !isDontCountSlowTorrentsEnabled);
};
this.updateMaxRatioTimeEnabled = function() {
const updateMaxRatioTimeEnabled = function() {
const isMaxRatioEnabled = $('max_ratio_checkbox').getProperty('checked');
$('max_ratio_value').setProperty('disabled', !isMaxRatioEnabled);
@ -1299,34 +1339,34 @@
$('max_ratio_act').setProperty('disabled', !(isMaxRatioEnabled || isMaxSeedingTimeEnabled));
};
this.updateAddTrackersEnabled = function() {
const updateAddTrackersEnabled = function() {
const isAddTrackersEnabled = $('add_trackers_checkbox').getProperty('checked');
$('add_trackers_textarea').setProperty('disabled', !isAddTrackersEnabled);
};
// Web UI tab
this.updateHttpsSettings = function() {
const updateHttpsSettings = function() {
const isUseHttpsEnabled = $('use_https_checkbox').getProperty('checked');
$('ssl_cert_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');
$('bypass_auth_subnet_whitelist_textarea').setProperty('disabled', !isBypassAuthSubnetWhitelistEnabled);
};
this.updateAlternativeWebUISettings = function() {
const updateAlternativeWebUISettings = function() {
const isUseAlternativeWebUIEnabled = $('use_alt_webui_checkbox').getProperty('checked');
$('webui_files_location_textarea').setProperty('disabled', !isUseAlternativeWebUIEnabled);
};
this.updateHostHeaderValidationSettings = function() {
const updateHostHeaderValidationSettings = function() {
const isHostHeaderValidationEnabled = $('host_header_validation_checkbox').getProperty('checked');
$('webui_domain_textarea').setProperty('disabled', !isHostHeaderValidationEnabled);
};
this.updateDynDnsSettings = function() {
const updateDynDnsSettings = function() {
const isDynDnsEnabled = $('use_dyndns_checkbox').getProperty('checked');
$('dyndns_select').setProperty('disabled', !isDynDnsEnabled);
$('dyndns_domain_text').setProperty('disabled', !isDynDnsEnabled);
@ -1334,7 +1374,7 @@
$('dyndns_password_text').setProperty('disabled', !isDynDnsEnabled);
};
this.registerDynDns = function() {
const registerDynDns = function() {
if ($('dyndns_select').getProperty('value').toInt() == 1) {
window.open("http://www.no-ip.com/services/managed_dns/free_dynamic_dns.html", "NO-IP Registration");
}
@ -1343,14 +1383,14 @@
}
};
this.generateRandomPort = function() {
const generateRandomPort = function() {
const min = 1024;
const max = 65535;
const port = Math.floor(Math.random() * (max - min + 1) + min);
$('port_value').setProperty('value', port);
};
this.time_padding = function(val) {
const time_padding = function(val) {
let ret = val.toString();
if (ret.length == 1)
ret = '0' + ret;
@ -1358,7 +1398,7 @@
};
// Advanced Tab
this.updateNetworkInterfaces = function(default_iface) {
const updateNetworkInterfaces = function(default_iface) {
const url = 'api/v2/app/networkInterfaceList';
$('networkInterface').empty();
new Request.JSON({
@ -1380,7 +1420,7 @@
}).send();
};
this.updateInterfaceAddresses = function(iface, default_addr) {
const updateInterfaceAddresses = function(iface, default_addr) {
const url = 'api/v2/app/networkInterfaceAddressList';
$('optionalIPAddressToBind').empty();
new Request.JSON({
@ -1405,7 +1445,7 @@
}).send();
}
this.loadPreferences = function() {
const loadPreferences = function() {
const url = 'api/v2/app/preferences';
new Request.JSON({
url: url,
@ -1708,7 +1748,7 @@
}).send();
};
this.applyPreferences = function() {
const applyPreferences = function() {
const settings = new Hash();
// Validate form data
// Downloads tab
@ -2094,4 +2134,7 @@
});
loadPreferences();
return exports();
})();
</script>

View file

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

View file

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

View file

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

View file

@ -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 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;">
<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="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: 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="qBittorrent.SearchPlugins.checkForUpdates();">QBT_TR(Check for updates)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>
@ -79,12 +79,28 @@
<script>
'use strict';
this.searchPluginsTableContextMenu = undefined;
this.prevOffsetLeft = undefined;
this.prevOffsetTop = undefined;
if (window.qBittorrent === undefined) {
window.qBittorrent = {};
}
this.initSearchPlugins = function() {
searchPluginsTableContextMenu = new SearchPluginsTableContextMenu({
window.qBittorrent.SearchPlugins = (function() {
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',
menu: 'searchPluginsTableMenu',
actions: {
@ -94,14 +110,14 @@
offsets: calculateContextMenuOffsets()
});
searchPluginsTable.setup('searchPluginsTableDiv', 'searchPluginsTableFixedHeaderDiv', searchPluginsTableContextMenu);
updateSearchPluginsTable();
updateTable();
};
this.closeSearchWindow = function(id) {
const closeSearchWindow = function(id) {
window.parent.MochaUI.closeWindow(window.parent.$(id));
};
this.installPlugin = function(path) {
const installPlugin = function(path) {
new MochaUI.Window({
id: 'installSearchPlugin',
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 url = new URI('api/v2/search/uninstallPlugin');
new Request({
@ -130,11 +146,11 @@
}).send();
};
this.enablePlugin = function() {
const enablePlugin = function() {
const plugins = searchPluginsTable.selectedRowsIds();
let enable = true;
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');
new Request({
@ -148,7 +164,7 @@
}).send();
};
this.checkForUpdates = function() {
const checkForUpdates = function() {
const url = new URI('api/v2/search/updatePlugins');
new Request({
url: url,
@ -157,7 +173,7 @@
}).send();
};
this.calculateContextMenuOffsets = function() {
const calculateContextMenuOffsets = function() {
prevOffsetLeft = document.getElementById("searchPlugins").getBoundingClientRect().left;
prevOffsetTop = document.getElementById("searchPlugins").getBoundingClientRect().top;
@ -167,13 +183,13 @@
};
};
this.updateSearchPluginsTableContextMenuOffset = function() {
const updateSearchPluginsTableContextMenuOffset = function() {
// only re-calculate if window has moved
if ((prevOffsetLeft !== document.getElementById("searchPlugins").getBoundingClientRect().left) || (prevOffsetTop !== document.getElementById("searchPlugins").getBoundingClientRect().top))
searchPluginsTableContextMenu.options.offsets = calculateContextMenuOffsets();
};
this.setupSearchPluginTableEvents = function(enable) {
const setupSearchPluginTableEvents = function(enable) {
if (enable)
$$(".searchPluginsTableRow").each(function(target) {
target.addEventListener('dblclick', enablePlugin, false);
@ -186,7 +202,7 @@
});
};
this.updateSearchPluginsTable = function() {
const updateTable = function() {
// clear event listeners
setupSearchPluginTableEvents(false);
@ -194,8 +210,8 @@
// remove old rows from the table
for (let i = 0; i < oldPlugins.length; ++i) {
let found = false;
for (let j = 0; j < searchPlugins.length; ++j) {
if (searchPlugins[j].name === oldPlugins[i]) {
for (let j = 0; j < window.qBittorrent.Search.searchPlugins.length; ++j) {
if (window.qBittorrent.Search.searchPlugins[j].name === oldPlugins[i]) {
found = true;
break;
}
@ -204,9 +220,9 @@
searchPluginsTable.removeRow(oldPlugins[i]);
}
for (let i = 0; i < searchPlugins.length; ++i) {
searchPlugins[i].rowId = searchPlugins[i].name;
searchPluginsTable.updateRowData(searchPlugins[i]);
for (let i = 0; i < window.qBittorrent.Search.searchPlugins.length; ++i) {
window.qBittorrent.Search.searchPlugins[i].rowId = window.qBittorrent.Search.searchPlugins[i].name;
searchPluginsTable.updateRowData(window.qBittorrent.Search.searchPlugins[i]);
}
searchPluginsTable.updateTable();
@ -217,4 +233,7 @@
};
initSearchPlugins();
return exports();
})();
</script>

View file

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