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

115 lines
3.4 KiB
JavaScript
Raw Normal View History

2013-02-20 18:33:05 -07:00
var PluginsPage = {
onPageShow: function () {
2013-12-27 09:18:42 -07:00
PluginsPage.reloadList(this);
2013-02-20 18:33:05 -07:00
},
2013-12-27 09:18:42 -07:00
reloadList: function (page) {
2013-02-20 18:33:05 -07:00
Dashboard.showLoadingMsg();
var promise1 = ApiClient.getInstalledPlugins();
2014-10-26 20:06:01 -07:00
var promise2 = ApiClient.getJSON(ApiClient.getUrl("dashboard/configurationpages") + "?pageType=PluginConfiguration");
2013-02-20 18:33:05 -07:00
2014-03-31 14:04:22 -07:00
$.when(promise1, promise2).done(function (response1, response2) {
2013-02-20 18:33:05 -07:00
2013-12-27 09:18:42 -07:00
PluginsPage.populateList(page, response1[0], response2[0]);
2013-02-20 18:33:05 -07:00
});
},
2014-10-25 11:32:58 -07:00
showNoConfigurationMessage: function() {
Dashboard.alert({
message: Globalize.translate('NoPluginConfigurationMessage')
});
},
showConnectMessage: function () {
Dashboard.alert({
message: Globalize.translate('MessagePluginConfigurationRequiresLocalAccess')
});
},
2013-12-27 09:18:42 -07:00
populateList: function (page, plugins, pluginConfigurationPages) {
2013-02-20 18:33:05 -07:00
plugins = plugins.sort(function (plugin1, plugin2) {
2013-03-04 21:29:43 -07:00
return (plugin1.Name) > (plugin2.Name) ? 1 : -1;
2013-02-20 18:33:05 -07:00
});
var html = "";
for (var i = 0, length = plugins.length; i < length; i++) {
var plugin = plugins[i];
2014-03-31 14:04:22 -07:00
2013-02-20 18:33:05 -07:00
var configPage = $.grep(pluginConfigurationPages, function (pluginConfigurationPage) {
return pluginConfigurationPage.PluginId == plugin.Id;
2013-02-20 18:33:05 -07:00
})[0];
html += "<li>";
2014-10-25 11:32:58 -07:00
if (Dashboard.isConnectMode()) {
html += "<a onclick='PluginsPage.showConnectMessage();' href='#'>";
}
else if (configPage) {
html += "<a href='" + Dashboard.getConfigurationPageUrl(configPage.Name) + "'>";
2014-10-25 11:32:58 -07:00
}
else {
html += "<a onclick='PluginsPage.showNoConfigurationMessage();' href='#'>";
}
2013-02-20 18:33:05 -07:00
html += "<h3>" + plugin.Name + "</h3>";
2013-12-01 19:24:14 -07:00
html += "<p>" + plugin.Version + "</p>";
2013-02-20 18:33:05 -07:00
html += "</a>";
2014-05-30 12:23:56 -07:00
html += "<a data-id='" + plugin.Id + "' data-pluginname='" + plugin.Name + "' onclick='PluginsPage.deletePlugin(this);' href='#'>" + Globalize.translate('Delete') + "</a>";
2013-02-20 18:33:05 -07:00
html += "</li>";
}
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
2014-03-31 14:04:22 -07:00
html += '<li 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>';
html += '</li>';
$('#ulInstalledPlugins', page).html(html);
} else {
$('#ulInstalledPlugins', page).html(html).listview('refresh');
}
2013-02-20 18:33:05 -07:00
Dashboard.hideLoadingMsg();
},
deletePlugin: function (link) {
2013-12-27 09:18:42 -07:00
var page = $(link).parents('.page');
2013-02-20 18:33:05 -07:00
var name = link.getAttribute('data-pluginname');
2013-02-21 23:28:57 -07:00
var uniqueid = link.getAttribute('data-id');
2013-02-20 18:33:05 -07:00
2014-05-30 12:23:56 -07:00
var msg = Globalize.translate('UninstallPluginConfirmation').replace("{0}", name);
2013-02-20 18:33:05 -07:00
2014-05-30 12:23:56 -07:00
Dashboard.confirm(msg, Globalize.translate('UninstallPluginHeader'), function (result) {
2013-02-20 18:33:05 -07:00
if (result) {
Dashboard.showLoadingMsg();
ApiClient.uninstallPlugin(uniqueid).done(function () {
2013-12-27 09:18:42 -07:00
PluginsPage.reloadList(page);
2013-02-20 18:33:05 -07:00
});
}
});
}
};
$(document).on('pageshow', "#pluginsPage", PluginsPage.onPageShow);