1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/scripts/pluginspage.js

231 lines
6.4 KiB
JavaScript
Raw Normal View History

2015-01-10 00:53:35 -05:00
(function ($, window) {
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
function deletePlugin(page, uniqueid, name) {
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
var msg = Globalize.translate('UninstallPluginConfirmation').replace("{0}", name);
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
Dashboard.confirm(msg, Globalize.translate('UninstallPluginHeader'), function (result) {
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
if (result) {
Dashboard.showLoadingMsg();
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
ApiClient.uninstallPlugin(uniqueid).done(function () {
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
reloadList(page);
});
}
2013-02-20 20:33:05 -05:00
});
2015-01-10 00:53:35 -05:00
}
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
function showNoConfigurationMessage() {
2014-10-25 14:32:58 -04:00
Dashboard.alert({
message: Globalize.translate('NoPluginConfigurationMessage')
});
2015-01-10 00:53:35 -05:00
}
2014-10-25 14:32:58 -04:00
2015-01-10 00:53:35 -05:00
function showConnectMessage() {
2014-10-25 14:32:58 -04:00
Dashboard.alert({
message: Globalize.translate('MessagePluginConfigurationRequiresLocalAccess')
});
2015-01-10 00:53:35 -05:00
}
2014-10-25 14:32:58 -04:00
2015-07-23 01:25:55 -04:00
function getPluginCardHtml(plugin, pluginConfigurationPages) {
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
var configPage = $.grep(pluginConfigurationPages, function (pluginConfigurationPage) {
return pluginConfigurationPage.PluginId == plugin.Id;
})[0];
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
var html = '';
2013-02-20 20:33:05 -05:00
2015-01-31 21:41:35 -05:00
var isConnectMode = Dashboard.isConnectMode();
var configPageUrl = configPage ? Dashboard.getConfigurationPageUrl(configPage.Name) : null;
var href = configPage && !isConnectMode ?
configPageUrl :
2015-01-10 00:53:35 -05:00
null;
html += "<div data-id='" + plugin.Id + "' data-name='" + plugin.Name + "' class='card backdropCard alternateHover bottomPaddedCard'>";
html += '<div class="cardBox visualCardBox">';
html += '<div class="cardScalable">';
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
html += '<div class="cardPadder"></div>';
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
if (href) {
html += '<a class="cardContent" href="' + href + '">';
2015-01-31 21:41:35 -05:00
}
else if (!configPageUrl) {
html += '<div class="cardContent noConfigPluginCard noHoverEffect">';
}
else if (isConnectMode) {
html += '<div class="cardContent connectModePluginCard">';
}
else {
2015-01-10 00:53:35 -05:00
html += '<div class="cardContent">';
}
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05: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 17:04:22 -04:00
2015-01-10 00:53:35 -05:00
html += "</div>";
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
// cardContent
if (href) {
html += "</a>";
} else {
html += "</div>";
}
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
// cardScalable
html += "</div>";
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
html += '<div class="cardFooter">';
2013-02-20 20:33:05 -05:00
2015-06-24 00:38:46 -04:00
html += '<div class="cardText" style="text-align:right; float:right;padding-top:5px;">';
2015-07-14 12:39:34 -04:00
html += '<paper-icon-button icon="' + AppInfo.moreIcon + '" class="btnCardMenu"></paper-icon-button>';
2015-01-10 00:53:35 -05:00
html += "</div>";
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
html += "<div class='cardText'>";
html += plugin.Name;
html += "</div>";
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
html += "<div class='cardText'>";
html += plugin.Version;
html += "</div>";
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
// cardFooter
html += "</div>";
// cardBox
html += "</div>";
// card
html += "</div>";
return html;
}
2015-08-23 22:08:20 -04:00
function renderPlugins(page, plugins, showNoPluginsMessage) {
2015-03-08 13:58:45 -04:00
ApiClient.getJSON(ApiClient.getUrl("dashboard/configurationpages") + "?pageType=PluginConfiguration").done(function (configPages) {
2015-08-23 22:08:20 -04:00
populateList(page, plugins, configPages, showNoPluginsMessage);
2015-03-08 13:58:45 -04:00
});
}
2015-08-23 22:08:20 -04:00
function populateList(page, plugins, pluginConfigurationPages, showNoPluginsMessage) {
2015-01-10 00:53:35 -05:00
plugins = plugins.sort(function (plugin1, plugin2) {
return (plugin1.Name) > (plugin2.Name) ? 1 : -1;
});
var html = plugins.map(function (p) {
2015-07-23 01:25:55 -04:00
return getPluginCardHtml(p, pluginConfigurationPages);
2015-01-10 00:53:35 -05:00
}).join('');
2013-04-06 09:59:18 -07:00
2014-03-31 17:04:22 -04:00
if (!plugins.length) {
2013-02-20 20:33:05 -05:00
2015-08-23 22:08:20 -04:00
if (showNoPluginsMessage) {
html += '<div style="padding:5px;">';
html += '<p>' + Globalize.translate('MessageNoPluginsInstalled') + '</p>';
html += '<p><a href="plugincatalog.html">';
html += Globalize.translate('BrowsePluginCatalogMessage');
html += '</a></p>';
html += '</div>';
}
2014-03-31 17:04:22 -04:00
2015-01-10 00:53:35 -05:00
$('.installedPlugins', page).html(html).trigger('create');
2014-03-31 17:04:22 -04:00
} else {
2015-01-10 00:53:35 -05:00
var elem = $('.installedPlugins', page).html(html).trigger('create');
2015-01-31 21:41:35 -05:00
$('.noConfigPluginCard', elem).on('click', function () {
2015-01-10 00:53:35 -05:00
showNoConfigurationMessage();
});
2015-01-31 21:41:35 -05:00
$('.connectModePluginCard', elem).on('click', function () {
2015-01-10 00:53:35 -05:00
showConnectMessage();
});
$('.btnCardMenu', elem).on('click', function () {
showPluginMenu(page, this);
});
2014-03-31 17:04:22 -04:00
}
2013-02-20 20:33:05 -05:00
Dashboard.hideLoadingMsg();
2015-01-10 00:53:35 -05:00
}
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
function showPluginMenu(page, elem) {
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05: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 20:33:05 -05:00
2015-07-15 07:26:47 -04:00
var menuItems = [];
2013-02-20 20:33:05 -05:00
2015-01-10 00:53:35 -05:00
if (configHref) {
2015-07-15 07:26:47 -04:00
menuItems.push({
name: Globalize.translate('ButtonSettings'),
id: 'open',
ironIcon: 'mode-edit'
});
2015-01-10 00:53:35 -05:00
}
2013-02-20 20:33:05 -05:00
2015-07-15 07:26:47 -04:00
menuItems.push({
name: Globalize.translate('ButtonUninstall'),
id: 'delete',
ironIcon: 'delete'
2015-01-10 00:53:35 -05:00
});
2015-07-15 07:26:47 -04:00
require(['actionsheet'], function () {
ActionSheetElement.show({
items: menuItems,
2015-07-21 00:22:46 -04:00
positionTo: elem,
2015-07-15 07:26:47 -04:00
callback: function (resultId) {
switch (resultId) {
case 'open':
Dashboard.navigate(configHref);
break;
case 'delete':
deletePlugin(page, id, name);
break;
default:
break;
}
}
});
2015-01-10 00:53:35 -05:00
2013-02-20 20:33:05 -05:00
});
2015-01-10 00:53:35 -05:00
}
function reloadList(page) {
Dashboard.showLoadingMsg();
2013-02-20 20:33:05 -05:00
2015-03-08 13:58:45 -04:00
ApiClient.getInstalledPlugins().done(function (plugins) {
2015-01-10 00:53:35 -05:00
2015-08-23 22:08:20 -04:00
renderPlugins(page, plugins, true);
2015-01-10 00:53:35 -05:00
});
2013-02-20 20:33:05 -05:00
}
2015-09-24 13:08:10 -04:00
$(document).on('pageshow', "#pluginsPage", function () {
2015-01-10 00:53:35 -05:00
reloadList(this);
});
2015-03-08 13:58:45 -04:00
window.PluginsPage = {
renderPlugins: renderPlugins
};
2015-01-10 00:53:35 -05:00
})(jQuery, window);