(function ($, window) { function deletePlugin(page, uniqueid, name) { var msg = Globalize.translate('UninstallPluginConfirmation').replace("{0}", name); Dashboard.confirm(msg, Globalize.translate('UninstallPluginHeader'), function (result) { if (result) { Dashboard.showLoadingMsg(); ApiClient.uninstallPlugin(uniqueid).done(function () { reloadList(page); }); } }); } function showNoConfigurationMessage() { Dashboard.alert({ message: Globalize.translate('NoPluginConfigurationMessage') }); } function showConnectMessage() { Dashboard.alert({ message: Globalize.translate('MessagePluginConfigurationRequiresLocalAccess') }); } function getPluginCardHtml(plugin, pluginConfigurationPages) { var configPage = $.grep(pluginConfigurationPages, function (pluginConfigurationPage) { return pluginConfigurationPage.PluginId == plugin.Id; })[0]; var html = ''; var isConnectMode = Dashboard.isConnectMode(); var configPageUrl = configPage ? Dashboard.getConfigurationPageUrl(configPage.Name) : null; var href = configPage && !isConnectMode ? configPageUrl : null; html += "
"; html += '
'; html += '
'; html += '
'; if (href) { html += ''; } else if (!configPageUrl) { html += '
'; } else if (isConnectMode) { html += '
'; } else { html += '"; html += '
'; html += '
'; html += ''; html += "
"; html += "
"; html += plugin.Name; html += "
"; html += "
"; html += plugin.Version; html += "
"; // cardFooter html += "
"; // cardBox html += "
"; // card html += "
"; return html; } function renderPlugins(page, plugins) { ApiClient.getJSON(ApiClient.getUrl("dashboard/configurationpages") + "?pageType=PluginConfiguration").done(function (configPages) { populateList(page, plugins, configPages); }); } 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(''); if (!plugins.length) { html += '
'; html += '

' + Globalize.translate('MessageNoPluginsInstalled') + '

'; html += '

'; html += Globalize.translate('BrowsePluginCatalogMessage'); html += '

'; html += '
'; $('.installedPlugins', page).html(html).trigger('create'); } else { var elem = $('.installedPlugins', page).html(html).trigger('create'); $('.noConfigPluginCard', elem).on('click', function () { showNoConfigurationMessage(); }); $('.connectModePluginCard', elem).on('click', function () { showConnectMessage(); }); $('.btnCardMenu', elem).on('click', function () { showPluginMenu(page, this); }); } Dashboard.hideLoadingMsg(); } function showPluginMenu(page, elem) { var card = $(elem).parents('.card'); var id = card.attr('data-id'); var name = card.attr('data-name'); var configHref = $('.cardContent', card).attr('href'); $('.cardMenu', page).popup("close").remove(); var html = '
'; html += ''; html += '
'; $(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); }); } function reloadList(page) { Dashboard.showLoadingMsg(); ApiClient.getInstalledPlugins().done(function (plugins) { renderPlugins(page, plugins); }); } $(document).on('pageshow', "#pluginsPage", function () { reloadList(this); }); window.PluginsPage = { renderPlugins: renderPlugins }; })(jQuery, window);