jellyfin-web/dashboard-ui/scripts/pluginspage.js

249 lines
7.0 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
function deletePlugin(page, uniqueid, name) {
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
var msg = Globalize.translate('UninstallPluginConfirmation').replace("{0}", name);
2013-02-20 18:33:05 -07:00
2016-02-22 11:47:56 -07:00
require(['confirm'], function (confirm) {
confirm(msg, Globalize.translate('UninstallPluginHeader')).then(function () {
2015-01-09 22:53:35 -07:00
Dashboard.showLoadingMsg();
2013-02-20 18:33:05 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.uninstallPlugin(uniqueid).then(function () {
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
reloadList(page);
});
2016-02-22 11:47:56 -07:00
});
2013-02-20 18:33:05 -07:00
});
2015-01-09 22:53:35 -07:00
}
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
function showNoConfigurationMessage() {
2014-10-25 11:32:58 -07:00
Dashboard.alert({
message: Globalize.translate('NoPluginConfigurationMessage')
});
2015-01-09 22:53:35 -07:00
}
2014-10-25 11:32:58 -07:00
2015-01-09 22:53:35 -07:00
function showConnectMessage() {
2014-10-25 11:32:58 -07:00
Dashboard.alert({
message: Globalize.translate('MessagePluginConfigurationRequiresLocalAccess')
});
2015-01-09 22:53:35 -07:00
}
2014-10-25 11:32:58 -07:00
2015-07-22 22:25:55 -07:00
function getPluginCardHtml(plugin, pluginConfigurationPages) {
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
var configPage = $.grep(pluginConfigurationPages, function (pluginConfigurationPage) {
return pluginConfigurationPage.PluginId == plugin.Id;
})[0];
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
var html = '';
2013-02-20 18:33:05 -07:00
2015-01-31 19:41:35 -07:00
var isConnectMode = Dashboard.isConnectMode();
var configPageUrl = configPage ? Dashboard.getConfigurationPageUrl(configPage.Name) : null;
var href = configPage && !isConnectMode ?
configPageUrl :
2015-01-09 22:53:35 -07:00
null;
2015-10-15 10:21:18 -07:00
html += "<div data-id='" + plugin.Id + "' data-name='" + plugin.Name + "' class='card backdropCard bottomPaddedCard'>";
2015-01-09 22:53:35 -07:00
html += '<div class="cardBox visualCardBox">';
html += '<div class="cardScalable">';
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
html += '<div class="cardPadder"></div>';
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
if (href) {
html += '<a class="cardContent" href="' + href + '">';
2015-01-31 19:41:35 -07:00
}
else if (!configPageUrl) {
html += '<div class="cardContent noConfigPluginCard noHoverEffect">';
}
else if (isConnectMode) {
html += '<div class="cardContent connectModePluginCard">';
}
else {
2015-01-09 22:53:35 -07:00
html += '<div class="cardContent">';
}
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
if (plugin.ImageUrl) {
html += '<div class="cardImage" style="background-image:url(\'' + plugin.ImageUrl + '\');">';
} else {
html += '<div class="cardImage" style="background-image:url(\'css/images/items/list/collection.png\');">';
}
2014-03-31 14:04:22 -07:00
2015-01-09 22:53:35 -07:00
html += "</div>";
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
// cardContent
if (href) {
html += "</a>";
} else {
html += "</div>";
}
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
// cardScalable
html += "</div>";
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
html += '<div class="cardFooter">';
2013-02-20 18:33:05 -07:00
2015-06-23 21:38:46 -07:00
html += '<div class="cardText" style="text-align:right; float:right;padding-top:5px;">';
2016-05-07 23:31:08 -07:00
html += '<button type="button" is="paper-icon-button-light" class="btnCardMenu"><iron-icon icon="' + AppInfo.moreIcon + '"></iron-icon></button>';
2015-01-09 22:53:35 -07:00
html += "</div>";
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
html += "<div class='cardText'>";
html += plugin.Name;
html += "</div>";
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
html += "<div class='cardText'>";
html += plugin.Version;
html += "</div>";
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
// cardFooter
html += "</div>";
// cardBox
html += "</div>";
// card
html += "</div>";
return html;
}
2015-08-23 19:08:20 -07:00
function renderPlugins(page, plugins, showNoPluginsMessage) {
2015-03-08 10:58:45 -07:00
2016-03-17 23:36:58 -07:00
ApiClient.getJSON(ApiClient.getUrl("web/configurationpages") + "?pageType=PluginConfiguration").then(function (configPages) {
2015-03-08 10:58:45 -07:00
2015-08-23 19:08:20 -07:00
populateList(page, plugins, configPages, showNoPluginsMessage);
2015-03-08 10:58:45 -07:00
});
}
2015-08-23 19:08:20 -07:00
function populateList(page, plugins, pluginConfigurationPages, showNoPluginsMessage) {
2015-01-09 22:53:35 -07:00
plugins = plugins.sort(function (plugin1, plugin2) {
return (plugin1.Name) > (plugin2.Name) ? 1 : -1;
});
var html = plugins.map(function (p) {
2015-07-22 22:25:55 -07:00
return getPluginCardHtml(p, pluginConfigurationPages);
2015-01-09 22:53:35 -07:00
}).join('');
2013-04-06 09:59:18 -07:00
2014-03-31 14:04:22 -07:00
if (!plugins.length) {
2013-02-20 18:33:05 -07:00
2015-08-23 19:08:20 -07:00
if (showNoPluginsMessage) {
html += '<div style="padding:5px;">';
2016-02-07 14:16:02 -07:00
if (AppInfo.enableAppStorePolicy) {
html += '<p>' + Globalize.translate('MessageNoPluginsDueToAppStore') + '</p>';
} else {
html += '<p>' + Globalize.translate('MessageNoPluginsInstalled') + '</p>';
html += '<p><a href="plugincatalog.html">';
html += Globalize.translate('BrowsePluginCatalogMessage');
html += '</a></p>';
}
2015-08-23 19:08:20 -07:00
html += '</div>';
}
2014-03-31 14:04:22 -07:00
2016-03-06 11:09:20 -07:00
$('.installedPlugins', page).html(html);
2014-03-31 14:04:22 -07:00
} else {
2015-01-09 22:53:35 -07:00
2016-03-06 11:09:20 -07:00
var elem = $('.installedPlugins', page).html(html);
2015-01-09 22:53:35 -07:00
2015-01-31 19:41:35 -07:00
$('.noConfigPluginCard', elem).on('click', function () {
2015-01-09 22:53:35 -07:00
showNoConfigurationMessage();
});
2015-01-31 19:41:35 -07:00
$('.connectModePluginCard', elem).on('click', function () {
2015-01-09 22:53:35 -07:00
showConnectMessage();
});
$('.btnCardMenu', elem).on('click', function () {
showPluginMenu(page, this);
});
2014-03-31 14:04:22 -07:00
}
2013-02-20 18:33:05 -07:00
Dashboard.hideLoadingMsg();
2015-01-09 22:53:35 -07:00
}
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
function showPluginMenu(page, elem) {
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
var card = $(elem).parents('.card');
var id = card.attr('data-id');
var name = card.attr('data-name');
var configHref = $('.cardContent', card).attr('href');
2013-02-20 18:33:05 -07:00
2015-07-15 04:26:47 -07:00
var menuItems = [];
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
if (configHref) {
2015-07-15 04:26:47 -07:00
menuItems.push({
name: Globalize.translate('ButtonSettings'),
id: 'open',
ironIcon: 'mode-edit'
});
2015-01-09 22:53:35 -07:00
}
2013-02-20 18:33:05 -07:00
2015-07-15 04:26:47 -07:00
menuItems.push({
name: Globalize.translate('ButtonUninstall'),
id: 'delete',
ironIcon: 'delete'
2015-01-09 22:53:35 -07:00
});
2016-01-30 21:04:00 -07:00
require(['actionsheet'], function (actionsheet) {
2015-07-15 04:26:47 -07:00
2016-01-30 21:04:00 -07:00
actionsheet.show({
2015-07-15 04:26:47 -07:00
items: menuItems,
2015-07-20 21:22:46 -07:00
positionTo: elem,
2015-07-15 04:26:47 -07:00
callback: function (resultId) {
switch (resultId) {
case 'open':
Dashboard.navigate(configHref);
break;
case 'delete':
deletePlugin(page, id, name);
break;
default:
break;
}
}
});
2015-01-09 22:53:35 -07:00
2013-02-20 18:33:05 -07:00
});
2015-01-09 22:53:35 -07:00
}
function reloadList(page) {
Dashboard.showLoadingMsg();
2013-02-20 18:33:05 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.getInstalledPlugins().then(function (plugins) {
2015-01-09 22:53:35 -07:00
2015-08-23 19:08:20 -07:00
renderPlugins(page, plugins, true);
2015-01-09 22:53:35 -07:00
});
2013-02-20 18:33:05 -07:00
}
2016-04-12 23:02:07 -07:00
function getTabs() {
return [
{
href: 'plugins.html',
name: Globalize.translate('TabMyPlugins')
},
{
href: 'plugincatalog.html',
name: Globalize.translate('TabCatalog')
}];
}
2015-09-24 10:08:10 -07:00
$(document).on('pageshow', "#pluginsPage", function () {
2015-01-09 22:53:35 -07:00
2016-04-12 23:02:07 -07:00
LibraryMenu.setTabs('plugins', 0, getTabs);
2015-01-09 22:53:35 -07:00
reloadList(this);
});
2015-03-08 10:58:45 -07:00
window.PluginsPage = {
renderPlugins: renderPlugins
};
});