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

144 lines
4.3 KiB
JavaScript
Raw Normal View History

2013-04-03 20:56:02 -07:00
(function ($, document) {
2013-02-20 18:33:05 -07:00
// The base query options
var query = {
2013-04-25 16:28:01 -07:00
TargetSystems: 'Server,MBTheater,MBClassic'
};
2013-02-20 18:33:05 -07:00
function reloadList(page) {
2013-02-20 18:33:05 -07:00
Dashboard.showLoadingMsg();
2013-02-20 18:33:05 -07:00
var promise1 = ApiClient.getAvailablePlugins(query);
var promise2 = ApiClient.getInstalledPlugins();
2013-02-20 18:33:05 -07:00
$.when(promise1, promise2).done(function (response1, response2) {
populateList(page, response1[0], response2[0]);
});
2013-02-20 18:33:05 -07:00
Dashboard.hideLoadingMsg();
}
2013-02-20 18:33:05 -07:00
function populateList(page, availablePlugins, installedPlugins) {
2013-02-20 18:33:05 -07:00
2013-04-25 16:28:01 -07:00
Dashboard.showLoadingMsg();
2013-04-11 17:58:30 -07:00
availablePlugins = availablePlugins.filter(function (p) {
return p.type == "UserInstalled";
}).sort(function (a, b) {
return a.name > b.name ? 1 : -1;
});
2013-02-20 18:33:05 -07:00
2013-04-11 17:58:30 -07:00
var serverhtml = '';
2013-04-25 16:28:01 -07:00
var theatrehtml = '';
var classichtml = "";
2013-02-20 18:33:05 -07:00
for (var i = 0, length = availablePlugins.length; i < length; i++) {
2013-04-25 16:28:01 -07:00
var html = '';
var plugin = availablePlugins[i];
2013-02-20 18:33:05 -07:00
2013-04-28 10:39:16 -07:00
html += "<a class='posterItem backdropPosterItem transparentPosterItem' href='addPlugin.html?name=" + encodeURIComponent(plugin.name) + "'>";
2013-02-20 18:33:05 -07:00
if (plugin.thumbImage) {
2013-04-25 16:28:01 -07:00
html += '<div class="posterItemImage" style="background-image:url(\'' + plugin.thumbImage + '\');"></div>';
} else {
2013-04-25 16:28:01 -07:00
html += '<div class="posterItemImage defaultPosterItemImage" style="background-image:url(\'css/images/items/list/collection.png\');"></div>';
}
if (plugin.isPremium) {
if (plugin.price > 0) {
html += "<div class='premiumBanner'><img src='css/images/supporter/premiumflag.png' /></div>";
} else {
html += "<div class='premiumBanner'><img src='css/images/supporter/supporterflag.png' /></div>";
}
}
var color = plugin.tileColor || LibraryBrowser.getMetroColor(plugin.name);
2013-02-20 18:33:05 -07:00
2013-04-25 17:52:55 -07:00
html += "<div class='posterItemText posterItemTextCentered' style='background:" + color + "'>";
2013-02-20 18:33:05 -07:00
var installedPlugin = installedPlugins.filter(function (ip) {
return ip.Name == plugin.name;
})[0];
2013-02-20 18:33:05 -07:00
if (installedPlugin) {
html += plugin.name + " (Installed)";
} else {
html += plugin.name;
}
2013-02-20 18:33:05 -07:00
html += "</div>";
2013-02-20 18:33:05 -07:00
2013-04-25 16:28:01 -07:00
html += "</a>";
2013-02-20 18:33:05 -07:00
2013-04-25 16:28:01 -07:00
if (plugin.targetSystem == "Server") {
serverhtml += html;
} else if (plugin.targetSystem == "MBTheater") {
theatrehtml += html;
} else if (plugin.targetSystem == "MBClassic") {
classichtml += html;
}
2013-04-11 17:58:30 -07:00
}
2013-04-25 16:28:01 -07:00
if (!availablePlugins.length) {
$("#noPlugins", page).hide();
}
2013-04-08 18:38:18 -07:00
2013-04-25 16:28:01 -07:00
$('#pluginServerTiles', page).html(serverhtml);
$('#pluginTheatreTiles', page).html(theatrehtml);
$('#pluginClassicTiles', page).html(classichtml);
2013-02-20 18:33:05 -07:00
2013-04-25 16:28:01 -07:00
if (serverhtml) {
2013-04-11 17:58:30 -07:00
$('#pluginServerCollapsible', page).show();
2013-04-25 16:28:01 -07:00
} else {
$('#pluginServerCollapsible', page).hide();
}
if (theatrehtml) {
$('#pluginTheatreCollapsible', page).show();
} else {
$('#pluginTheatreCollapsible', page).hide();
}
if (classichtml) {
$('#pluginClassicCollapsible', page).show();
} else {
$('#pluginClassicCollapsible', page).hide();
}
2013-04-11 17:58:30 -07:00
Dashboard.hideLoadingMsg();
}
2013-04-03 20:56:02 -07:00
2013-04-08 18:38:18 -07:00
$(document).on('pageinit', "#pluginCatalogPage", function () {
2013-04-03 20:56:02 -07:00
2013-04-08 18:38:18 -07:00
var page = this;
2013-04-03 20:56:02 -07:00
2013-04-25 16:28:01 -07:00
reloadList(page);
2013-04-11 17:58:30 -07:00
2013-04-11 09:11:04 -07:00
$('.chkPremiumFilter', page).on('change', function () {
2013-04-03 20:56:02 -07:00
if (this.checked) {
query.IsPremium = true;
} else {
2013-04-03 21:46:14 -07:00
query.IsPremium = null;
}
2013-04-11 09:11:04 -07:00
reloadList(page);
});
2013-04-03 20:56:02 -07:00
2013-04-08 18:38:18 -07:00
}).on('pageshow', "#pluginCatalogPage", function () {
2013-04-25 16:28:01 -07:00
2013-04-11 09:11:04 -07:00
var page = this;
// Reset form values using the last used query
2013-04-11 09:11:04 -07:00
$('.chkPremiumFilter', page).each(function () {
2013-04-03 20:56:02 -07:00
var filters = query.IsPremium || false;
2013-04-03 20:56:02 -07:00
this.checked = filters;
2013-04-03 20:56:02 -07:00
}).checkboxradio('refresh');
});
2013-04-03 20:56:02 -07:00
})(jQuery, document);