2020-05-04 12:44:12 +02:00
|
|
|
define(['loading', 'libraryMenu', 'dom', 'globalize', 'cardStyle', 'emby-button'], function (loading, libraryMenu, dom, globalize) {
|
|
|
|
'use strict';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function deletePlugin(page, uniqueid, name) {
|
2020-05-04 12:44:12 +02:00
|
|
|
var msg = globalize.translate('UninstallPluginConfirmation', name);
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
require(['confirm'], function (confirm) {
|
2018-10-23 01:05:09 +03:00
|
|
|
confirm({
|
2020-05-04 12:44:12 +02:00
|
|
|
title: globalize.translate('UninstallPluginHeader'),
|
2018-10-23 01:05:09 +03:00
|
|
|
text: msg,
|
2020-05-04 12:44:12 +02:00
|
|
|
primary: 'delete',
|
|
|
|
confirmText: globalize.translate('UninstallPluginHeader')
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(function () {
|
2019-04-02 15:16:51 -07:00
|
|
|
loading.show();
|
2019-11-06 13:43:39 +03:00
|
|
|
ApiClient.uninstallPlugin(uniqueid).then(function () {
|
2019-04-02 15:16:51 -07:00
|
|
|
reloadList(page);
|
|
|
|
});
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showNoConfigurationMessage() {
|
|
|
|
Dashboard.alert({
|
2020-05-04 12:44:12 +02:00
|
|
|
message: globalize.translate('NoPluginConfigurationMessage')
|
2019-04-02 15:16:51 -07:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showConnectMessage() {
|
|
|
|
Dashboard.alert({
|
2020-05-04 12:44:12 +02:00
|
|
|
message: globalize.translate('MessagePluginConfigurationRequiresLocalAccess')
|
2019-04-02 15:16:51 -07:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPluginCardHtml(plugin, pluginConfigurationPages) {
|
2019-11-06 13:43:39 +03:00
|
|
|
var configPage = pluginConfigurationPages.filter(function (pluginConfigurationPage) {
|
|
|
|
return pluginConfigurationPage.PluginId == plugin.Id;
|
2019-02-26 02:39:58 +09:00
|
|
|
})[0];
|
|
|
|
var configPageUrl = configPage ? Dashboard.getConfigurationPageUrl(configPage.Name) : null;
|
2020-05-04 12:44:12 +02:00
|
|
|
var html = '';
|
2019-02-26 02:39:58 +09:00
|
|
|
html += "<div data-id='" + plugin.Id + "' data-name='" + plugin.Name + "' class='card backdropCard'>";
|
|
|
|
html += '<div class="cardBox visualCardBox">';
|
|
|
|
html += '<div class="cardScalable">';
|
|
|
|
html += '<div class="cardPadder cardPadder-backdrop"></div>';
|
2019-02-26 02:56:18 +09:00
|
|
|
html += configPageUrl ? '<a class="cardContent cardImageContainer" is="emby-linkbutton" href="' + configPageUrl + '">' : '<div class="cardContent noConfigPluginCard noHoverEffect cardImageContainer">';
|
2020-04-28 16:55:33 +03:00
|
|
|
html += '<span class="cardImageIcon material-icons folder"></span>';
|
2020-05-04 12:44:12 +02:00
|
|
|
html += configPageUrl ? '</a>' : '</div>';
|
|
|
|
html += '</div>';
|
2019-02-26 02:39:58 +09:00
|
|
|
html += '<div class="cardFooter">';
|
|
|
|
html += '<div style="text-align:right; float:right;padding-top:5px;">';
|
2020-05-16 18:07:20 +02:00
|
|
|
html += '<button type="button" is="paper-icon-button-light" class="btnCardMenu autoSize"><span class="material-icons more_vert"></span></button>';
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</div>';
|
2019-02-26 02:39:58 +09:00
|
|
|
html += "<div class='cardText'>";
|
2020-06-06 16:09:25 -06:00
|
|
|
html += configPage && configPage.DisplayName ? configPage.DisplayName : plugin.Name;
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</div>';
|
2019-02-26 02:39:58 +09:00
|
|
|
html += "<div class='cardText cardText-secondary'>";
|
|
|
|
html += plugin.Version;
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</div>';
|
|
|
|
html += '</div>';
|
|
|
|
html += '</div>';
|
|
|
|
html += '</div>';
|
2019-02-26 02:39:58 +09:00
|
|
|
return html;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2019-04-02 15:16:51 -07:00
|
|
|
function renderPlugins(page, plugins) {
|
2020-05-04 12:44:12 +02:00
|
|
|
ApiClient.getJSON(ApiClient.getUrl('web/configurationpages') + '?pageType=PluginConfiguration').then(function (configPages) {
|
2019-04-02 15:16:51 -07:00
|
|
|
populateList(page, plugins, configPages);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2019-04-02 15:16:51 -07:00
|
|
|
function populateList(page, plugins, pluginConfigurationPages) {
|
2019-11-06 13:43:39 +03:00
|
|
|
plugins = plugins.sort(function (plugin1, plugin2) {
|
|
|
|
if (plugin1.Name > plugin2.Name) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|
2020-02-14 03:17:39 +09:00
|
|
|
|
2019-11-06 13:43:39 +03:00
|
|
|
var html = plugins.map(function (p) {
|
|
|
|
return getPluginCardHtml(p, pluginConfigurationPages);
|
2020-05-04 12:44:12 +02:00
|
|
|
}).join('');
|
2020-02-14 03:17:39 +09:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
var installedPluginsElement = page.querySelector('.installedPlugins');
|
|
|
|
installedPluginsElement.removeEventListener('click', onInstalledPluginsClick);
|
|
|
|
installedPluginsElement.addEventListener('click', onInstalledPluginsClick);
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2019-04-02 15:16:51 -07:00
|
|
|
if (plugins.length) {
|
2020-05-04 12:44:12 +02:00
|
|
|
installedPluginsElement.classList.add('itemsContainer');
|
|
|
|
installedPluginsElement.classList.add('vertical-wrap');
|
2019-04-02 15:16:51 -07:00
|
|
|
} else {
|
2020-02-14 03:17:39 +09:00
|
|
|
html += '<div class="centerMessage">';
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '<h1>' + globalize.translate('MessageNoPluginsInstalled') + '</h1>';
|
2019-04-02 16:11:55 -07:00
|
|
|
html += '<p><a is="emby-linkbutton" class="button-link" href="availableplugins.html">';
|
2020-05-04 12:44:12 +02:00
|
|
|
html += globalize.translate('BrowsePluginCatalogMessage');
|
|
|
|
html += '</a></p>';
|
|
|
|
html += '</div>';
|
2019-04-02 15:16:51 -07:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2019-04-02 15:16:51 -07:00
|
|
|
installedPluginsElement.innerHTML = html;
|
|
|
|
loading.hide();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showPluginMenu(page, elem) {
|
2020-05-04 12:44:12 +02:00
|
|
|
var card = dom.parentWithClass(elem, 'card');
|
|
|
|
var id = card.getAttribute('data-id');
|
|
|
|
var name = card.getAttribute('data-name');
|
|
|
|
var configHref = card.querySelector('.cardContent').getAttribute('href');
|
2019-04-02 15:16:51 -07:00
|
|
|
var menuItems = [];
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2019-04-02 15:16:51 -07:00
|
|
|
if (configHref) {
|
|
|
|
menuItems.push({
|
2020-05-04 12:44:12 +02:00
|
|
|
name: globalize.translate('ButtonSettings'),
|
|
|
|
id: 'open',
|
|
|
|
icon: 'mode_edit'
|
2019-04-02 15:16:51 -07:00
|
|
|
});
|
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2019-04-02 15:16:51 -07:00
|
|
|
menuItems.push({
|
2020-05-04 12:44:12 +02:00
|
|
|
name: globalize.translate('ButtonUninstall'),
|
|
|
|
id: 'delete',
|
|
|
|
icon: 'delete'
|
2019-04-02 15:16:51 -07:00
|
|
|
});
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
require(['actionsheet'], function (actionsheet) {
|
2018-10-23 01:05:09 +03:00
|
|
|
actionsheet.show({
|
|
|
|
items: menuItems,
|
|
|
|
positionTo: elem,
|
2019-11-06 13:43:39 +03:00
|
|
|
callback: function (resultId) {
|
2018-10-23 01:05:09 +03:00
|
|
|
switch (resultId) {
|
2020-05-04 12:44:12 +02:00
|
|
|
case 'open':
|
2018-10-23 01:05:09 +03:00
|
|
|
Dashboard.navigate(configHref);
|
|
|
|
break;
|
2020-05-04 12:44:12 +02:00
|
|
|
case 'delete':
|
2019-11-06 13:43:39 +03:00
|
|
|
deletePlugin(page, id, name);
|
2020-02-14 03:17:39 +09:00
|
|
|
break;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2019-04-02 15:16:51 -07:00
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function reloadList(page) {
|
2019-04-02 15:16:51 -07:00
|
|
|
loading.show();
|
2019-11-06 13:43:39 +03:00
|
|
|
ApiClient.getInstalledPlugins().then(function (plugins) {
|
2019-04-02 15:16:51 -07:00
|
|
|
renderPlugins(page, plugins);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getTabs() {
|
|
|
|
return [{
|
2020-05-04 12:44:12 +02:00
|
|
|
href: 'installedplugins.html',
|
|
|
|
name: globalize.translate('TabMyPlugins')
|
2018-10-23 01:05:09 +03:00
|
|
|
}, {
|
2020-05-04 12:44:12 +02:00
|
|
|
href: 'availableplugins.html',
|
|
|
|
name: globalize.translate('TabCatalog')
|
2019-11-06 13:43:39 +03:00
|
|
|
}];
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onInstalledPluginsClick(e) {
|
2020-05-04 12:44:12 +02:00
|
|
|
if (dom.parentWithClass(e.target, 'noConfigPluginCard')) {
|
2019-04-02 15:16:51 -07:00
|
|
|
showNoConfigurationMessage();
|
2020-05-04 12:44:12 +02:00
|
|
|
} else if (dom.parentWithClass(e.target, 'connectModePluginCard')) {
|
2019-04-02 15:16:51 -07:00
|
|
|
showConnectMessage();
|
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
var btnCardMenu = dom.parentWithClass(e.target, 'btnCardMenu');
|
2019-11-06 13:43:39 +03:00
|
|
|
if (btnCardMenu) {
|
2020-05-04 12:44:12 +02:00
|
|
|
showPluginMenu(dom.parentWithClass(btnCardMenu, 'page'), btnCardMenu);
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2019-04-02 15:16:51 -07:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
pageIdOn('pageshow', 'pluginsPage', function () {
|
|
|
|
libraryMenu.setTabs('plugins', 0, getTabs);
|
2019-04-02 15:16:51 -07:00
|
|
|
reloadList(this);
|
|
|
|
});
|
2020-02-14 03:17:39 +09:00
|
|
|
|
2019-04-02 15:16:51 -07:00
|
|
|
window.PluginsPage = {
|
2018-10-23 01:05:09 +03:00
|
|
|
renderPlugins: renderPlugins
|
2019-11-06 13:43:39 +03:00
|
|
|
};
|
2019-02-26 21:12:58 +00:00
|
|
|
});
|