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

231 lines
6.4 KiB
JavaScript
Raw Normal View History

2015-01-09 22:53:35 -07:00
(function ($, window) {
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
2015-01-09 22:53:35 -07:00
Dashboard.confirm(msg, Globalize.translate('UninstallPluginHeader'), function (result) {
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
if (result) {
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);
});
}
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;">';
2015-07-14 09:39:34 -07:00
html += '<paper-icon-button icon="' + AppInfo.moreIcon + '" class="btnCardMenu"></paper-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
2015-12-14 08:43:03 -07:00
ApiClient.getJSON(ApiClient.getUrl("dashboard/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;">';
html += '<p>' + Globalize.translate('MessageNoPluginsInstalled') + '</p>';
html += '<p><a href="plugincatalog.html">';
html += Globalize.translate('BrowsePluginCatalogMessage');
html += '</a></p>';
html += '</div>';
}
2014-03-31 14:04:22 -07:00
2015-01-09 22:53:35 -07:00
$('.installedPlugins', page).html(html).trigger('create');
2014-03-31 14:04:22 -07:00
} else {
2015-01-09 22:53:35 -07:00
var elem = $('.installedPlugins', page).html(html).trigger('create');
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
}
2015-09-24 10:08:10 -07:00
$(document).on('pageshow', "#pluginsPage", function () {
2015-01-09 22:53:35 -07:00
reloadList(this);
});
2015-03-08 10:58:45 -07:00
window.PluginsPage = {
renderPlugins: renderPlugins
};
2015-01-09 22:53:35 -07:00
})(jQuery, window);