define(['loading', 'libraryMenu', 'globalize', 'cardStyle', 'emby-button', 'emby-checkbox', 'emby-select'], function (loading, libraryMenu, globalize) { 'use strict'; function reloadList(page) { loading.show(); var promise1 = ApiClient.getAvailablePlugins(); var promise2 = ApiClient.getInstalledPlugins(); Promise.all([promise1, promise2]).then(function (responses) { populateList({ catalogElement: page.querySelector('#pluginTiles'), noItemsElement: page.querySelector('#noPlugins'), availablePlugins: responses[0], installedPlugins: responses[1] }); }); } function getHeaderText(category) { category = category.replace(' ', ''); if ('Channel' === category) { category = 'Channels'; } else if ('Theme' === category) { category = 'Themes'; } else if ('LiveTV' === category) { category = 'HeaderLiveTV'; } else if ('ScreenSaver' === category) { category = 'HeaderScreenSavers'; } return globalize.translate(category); } function populateList(options) { var availablePlugins = options.availablePlugins; var installedPlugins = options.installedPlugins; var categories = []; availablePlugins.forEach(function (plugin, index, array) { plugin.category = plugin.category || 'General'; plugin.categoryDisplayName = getHeaderText(plugin.category); array[index] = plugin; }); availablePlugins.sort(function (a, b) { if (a.category > b.category) { return 1; } else if (b.category > a.category) { return -1; } if (a.name > b.name) { return 1; } else if (b.name > a.name) { return -1; } return 0; }); var currentCategory = null; var html = ''; for (var i = 0; i < availablePlugins.length; i++) { var plugin = availablePlugins[i]; var category = plugin.categoryDisplayName; if (category != currentCategory) { if (currentCategory) { html += ''; html += ''; } html += '
'; html += '

' + category + '

'; html += '
'; currentCategory = category; } html += getPluginHtml(plugin, options, installedPlugins); } html += '
'; html += '
'; if (!availablePlugins.length && options.noItemsElement) { options.noItemsElement.classList.remove('hide'); } options.catalogElement.innerHTML = html; loading.hide(); } function getPluginHtml(plugin, options, installedPlugins) { var html = ''; var href = plugin.externalUrl ? plugin.externalUrl : 'addplugin.html?name=' + encodeURIComponent(plugin.name) + '&guid=' + plugin.guid; if (options.context) { href += '&context=' + options.context; } var target = plugin.externalUrl ? ' target="_blank"' : ''; html += "
"; html += '
'; html += '
'; html += '
'; html += ''; html += ''; html += ''; html += '
'; html += '
'; html += "
"; html += plugin.name; html += '
'; var installedPlugin = installedPlugins.filter(function (ip) { return ip.Id == plugin.guid; })[0]; html += "
"; html += installedPlugin ? globalize.translate('LabelVersionInstalled', installedPlugin.Version) : ' '; html += '
'; html += '
'; html += '
'; return html += '
'; } function getTabs() { return [{ href: 'installedplugins.html', name: globalize.translate('TabMyPlugins') }, { href: 'availableplugins.html', name: globalize.translate('TabCatalog') }, { href: 'repositories.html', name: globalize.translate('TabRepositories') }]; } window.PluginCatalog = { renderCatalog: populateList }; return function (view, params) { view.addEventListener('viewshow', function () { libraryMenu.setTabs('plugins', 1, getTabs); reloadList(this); }); }; });