2017-12-28 13:05:36 -05:00
< style type = "text/css" >
#searchPluginsContainer {
height: calc(100% - 20px);
margin: 10px;
overflow: auto;
}
#searchPluginsContainer button {
padding: 2px;
}
#searchPluginsContainer span {
display: block;
margin-top: 10px;
}
#searchPluginsTable {
width: 100%;
height: calc(100% - 150px);
-moz-height: calc(100% - 150px);
-webkit-height: calc(100% - 150px);
}
#searchPluginsTable .dynamicTable {
width: 100%;
}
#searchPluginsTableDiv {
height: calc(100% - 26px);
-moz-height: calc(100% - 26px);
-webkit-height: calc(100% - 26px);
}
#dynamicTableFixedHeaderDiv {
height: 26px;
}
#searchPlugins_content {
height: 100%;
}
2018-12-12 12:23:56 +08:00
2017-12-28 13:05:36 -05:00
< / style >
< div id = "searchPluginsContainer" >
< h2 > QBT_TR(Installed search plugins:)QBT_TR[CONTEXT=PluginSelectDlg]< / h2 >
< div id = "searchPluginsTable" >
< div id = "searchPluginsTableFixedHeaderDiv" class = "dynamicTableFixedHeaderDiv" >
< table class = "dynamicTable unselectable" style = "position:relative;" >
< thead >
< tr class = "dynamicTableHeader" id = "searchPluginsTableFixedHeaderRow" > < / tr >
< / thead >
< / table >
< / div >
< div id = "searchPluginsTableDiv" class = "dynamicTableDiv" >
< table class = "dynamicTable unselectable" >
< thead >
< tr class = "dynamicTableHeader" > < / tr >
< / thead >
< tbody > < / tbody >
< / table >
< / div >
< / div >
< 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 >
< / div >
< / div >
< ul id = "searchPluginsTableMenu" class = "contextMenu" >
< li > < a href = "#Enabled" > < img src = "images/qbt-theme/checked.svg" alt = "QBT_TR(Enabled)QBT_TR[CONTEXT=PluginSelectDlg]" / > QBT_TR(Enabled)QBT_TR[CONTEXT=PluginSelectDlg]< / a > < / li >
< li class = "separator" > < a href = "#Uninstall" > < img src = "images/qbt-theme/list-remove.svg" alt = "QBT_TR(Uninstall)QBT_TR[CONTEXT=PluginSelectDlg]" / > QBT_TR(Uninstall)QBT_TR[CONTEXT=PluginSelectDlg]< / a > < / li >
< / ul >
< script >
'use strict';
2019-05-30 09:05:16 +03:00
this.searchPluginsTableContextMenu = undefined;
this.prevOffsetLeft = undefined;
this.prevOffsetTop = undefined;
2017-12-28 13:05:36 -05:00
2019-05-30 09:05:16 +03:00
this.initSearchPlugins = function() {
2017-12-28 13:05:36 -05:00
searchPluginsTableContextMenu = new SearchPluginsTableContextMenu({
targets: '.searchPluginsTableRow',
menu: 'searchPluginsTableMenu',
actions: {
Enabled: enablePlugin,
Uninstall: uninstallPlugin
},
2018-12-12 12:23:56 +08:00
offsets: calculateContextMenuOffsets()
2017-12-28 13:05:36 -05:00
});
searchPluginsTable.setup('searchPluginsTableDiv', 'searchPluginsTableFixedHeaderDiv', searchPluginsTableContextMenu);
updateSearchPluginsTable();
};
2019-05-30 09:05:16 +03:00
this.closeSearchWindow = function(id) {
2017-12-28 13:05:36 -05:00
window.parent.MochaUI.closeWindow(window.parent.$(id));
};
2019-05-30 09:05:16 +03:00
this.installPlugin = function(path) {
2017-12-28 13:05:36 -05:00
new MochaUI.Window({
id: 'installSearchPlugin',
title: "QBT_TR(Install plugin)QBT_TR[CONTEXT=PluginSourceDlg]",
loadMethod: 'xhr',
contentURL: 'installsearchplugin.html',
scrollbars: false,
resizable: false,
maximizable: false,
paddingVertical: 0,
paddingHorizontal: 0,
width: 500,
height: 120
});
};
2019-05-30 09:05:16 +03:00
this.uninstallPlugin = function() {
const plugins = searchPluginsTable.selectedRowsIds().join('|');
const url = new URI('api/v2/search/uninstallPlugin');
2017-12-28 13:05:36 -05:00
new Request({
url: url,
noCache: true,
method: 'post',
data: {
names: plugins,
}
}).send();
};
2019-05-30 09:05:16 +03:00
this.enablePlugin = function() {
const plugins = searchPluginsTable.selectedRowsIds();
let enable = true;
2017-12-28 13:05:36 -05:00
if (plugins & & plugins.length)
enable = !getPlugin(plugins[0]).enabled;
2019-05-30 09:05:16 +03:00
const url = new URI('api/v2/search/enablePlugin');
2017-12-28 13:05:36 -05:00
new Request({
url: url,
noCache: true,
method: 'post',
data: {
names: plugins.join('|'),
enable: enable
}
}).send();
};
2019-05-30 09:05:16 +03:00
this.checkForUpdates = function() {
const url = new URI('api/v2/search/updatePlugins');
2017-12-28 13:05:36 -05:00
new Request({
url: url,
noCache: true,
method: 'post'
}).send();
};
2019-05-30 09:05:16 +03:00
this.calculateContextMenuOffsets = function() {
2017-12-28 13:05:36 -05:00
prevOffsetLeft = document.getElementById("searchPlugins").getBoundingClientRect().left;
prevOffsetTop = document.getElementById("searchPlugins").getBoundingClientRect().top;
return {
x: -(prevOffsetLeft + 20),
y: -(prevOffsetTop + 2)
};
};
2019-05-30 09:05:16 +03:00
this.updateSearchPluginsTableContextMenuOffset = function() {
2017-12-28 13:05:36 -05:00
// only re-calculate if window has moved
if ((prevOffsetLeft !== document.getElementById("searchPlugins").getBoundingClientRect().left) || (prevOffsetTop !== document.getElementById("searchPlugins").getBoundingClientRect().top))
searchPluginsTableContextMenu.options.offsets = calculateContextMenuOffsets();
};
2019-05-30 09:05:16 +03:00
this.setupSearchPluginTableEvents = function(enable) {
2017-12-28 13:05:36 -05:00
if (enable)
$$(".searchPluginsTableRow").each(function(target) {
target.addEventListener('dblclick', enablePlugin, false);
target.addEventListener('contextmenu', updateSearchPluginsTableContextMenuOffset, true);
});
else
$$(".searchPluginsTableRow").each(function(target) {
target.removeEventListener('dblclick', enablePlugin, false);
target.removeEventListener('contextmenu', updateSearchPluginsTableContextMenuOffset, true);
});
};
2019-05-30 09:05:16 +03:00
this.updateSearchPluginsTable = function() {
2017-12-28 13:05:36 -05:00
// clear event listeners
setupSearchPluginTableEvents(false);
2019-05-30 09:05:16 +03:00
const oldPlugins = Object.keys(searchPluginsTable.rows);
2017-12-28 13:05:36 -05:00
// remove old rows from the table
2019-05-30 09:05:16 +03:00
for (let i = 0; i < oldPlugins.length ; + + i ) {
let found = false;
for (let j = 0; j < searchPlugins.length ; + + j ) {
2017-12-28 13:05:36 -05:00
if (searchPlugins[j].name === oldPlugins[i]) {
found = true;
break;
}
}
if (!found)
searchPluginsTable.removeRow(oldPlugins[i]);
}
2019-05-30 09:05:16 +03:00
for (let i = 0; i < searchPlugins.length ; + + i ) {
2017-12-28 13:05:36 -05:00
searchPlugins[i].rowId = searchPlugins[i].name;
searchPluginsTable.updateRowData(searchPlugins[i]);
}
searchPluginsTable.updateTable();
searchPluginsTable.altRow();
// add event listeners
setupSearchPluginTableEvents(true);
};
initSearchPlugins();
< / script >