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

225 lines
6.5 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-01-09 22:53:35 -07:00
ApiClient.uninstallPlugin(uniqueid).done(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-01-09 22:53:35 -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;
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 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-01-09 22:53:35 -07:00
html += '<div class="cardText" style="text-align:right; float:right;">';
html += '<button class="btnCardMenu" type="button" data-inline="true" data-iconpos="notext" data-icon="ellipsis-v" style="margin: 2px 0 0;"></button>';
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-03-08 10:58:45 -07:00
function renderPlugins(page, plugins) {
ApiClient.getJSON(ApiClient.getUrl("dashboard/configurationpages") + "?pageType=PluginConfiguration").done(function (configPages) {
populateList(page, plugins, configPages);
});
}
2015-01-09 22:53:35 -07:00
function populateList(page, plugins, pluginConfigurationPages) {
plugins = plugins.sort(function (plugin1, plugin2) {
return (plugin1.Name) > (plugin2.Name) ? 1 : -1;
});
var html = plugins.map(function (p) {
return getPluginCardHtml(p, pluginConfigurationPages);
}).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-01-09 22:53:35 -07:00
html += '<div style="padding:5px;">';
2014-05-30 12:23:56 -07:00
html += '<p>' + Globalize.translate('MessageNoPluginsInstalled') + '</p>';
2014-03-31 14:04:22 -07:00
html += '<p><a href="plugincatalog.html">';
2014-05-30 12:23:56 -07:00
html += Globalize.translate('BrowsePluginCatalogMessage');
2014-03-31 14:04:22 -07:00
html += '</a></p>';
2015-01-09 22:53:35 -07:00
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-01-09 22:53:35 -07:00
$('.cardMenu', page).popup("close").remove();
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
var html = '<div data-role="popup" class="cardMenu tapHoldMenu" data-theme="a">';
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
html += '<ul data-role="listview" style="min-width: 180px;">';
html += '<li data-role="list-divider">' + Globalize.translate('HeaderMenu') + '</li>';
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
if (configHref) {
html += '<li><a href="' + configHref + '">' + Globalize.translate('ButtonSettings') + '</a></li>';
}
2013-02-20 18:33:05 -07:00
2015-01-09 22:53:35 -07:00
html += '<li><a href="#" class="btnDeletePlugin">' + Globalize.translate('ButtonUninstall') + '</a></li>';
html += '</ul>';
html += '</div>';
$(page).append(html);
var flyout = $('.cardMenu', page).popup({ positionTo: elem || "window" }).trigger('create').popup("open").on("popupafterclose", function () {
$(this).off("popupafterclose").remove();
});
$('.btnDeletePlugin', flyout).on('click', function () {
$('.cardMenu', page).popup('close');
// jqm won't show a popup while another is in the act of closing
setTimeout(function () {
deletePlugin(page, id, name);
}, 300);
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-03-08 10:58:45 -07:00
ApiClient.getInstalledPlugins().done(function (plugins) {
2015-01-09 22:53:35 -07:00
2015-03-08 10:58:45 -07:00
renderPlugins(page, plugins);
2015-01-09 22:53:35 -07:00
});
2013-02-20 18:33:05 -07:00
}
2015-01-09 22:53:35 -07:00
$(document).on('pageshow', "#pluginsPage", function () {
reloadList(this);
});
2015-03-08 10:58:45 -07:00
window.PluginsPage = {
renderPlugins: renderPlugins
};
2015-01-09 22:53:35 -07:00
})(jQuery, window);