diff --git a/admin/include/plugins.class.php b/admin/include/plugins.class.php index b06a6f114..56d810f35 100644 --- a/admin/include/plugins.class.php +++ b/admin/include/plugins.class.php @@ -238,7 +238,7 @@ DELETE FROM '. PLUGINS_TABLE .' { break; } - + include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); deltree(PHPWG_PLUGINS_PATH . $plugin_id, PHPWG_PLUGINS_PATH . 'trash'); break; } diff --git a/admin/plugins_installed.php b/admin/plugins_installed.php index 003d43490..204c7c0dc 100644 --- a/admin/plugins_installed.php +++ b/admin/plugins_installed.php @@ -206,7 +206,9 @@ function cmp($a, $b) else return $s[$a['STATE']] >= $s[$b['STATE']]; } -usort($tpl_plugins, 'cmp'); + +// Stoped plugin sorting for new plugin manager +// usort($tpl_plugins, 'cmp'); $template->assign( array( diff --git a/admin/themes/default/js/plugins_installated.js b/admin/themes/default/js/plugins_installated.js index 3daaf0a99..35067e720 100644 --- a/admin/themes/default/js/plugins_installated.js +++ b/admin/themes/default/js/plugins_installated.js @@ -1,4 +1,7 @@ -function setDisplayTile() { +function setDisplayClassic() { + console.log("DISPLAY CLASSIC"); + $(".pluginContainer").removeClass("line").removeClass("compact").addClass("classic"); + $(".pluginDesc").show(); $(".pluginDescCompact").hide(); $(".pluginActions").show(); @@ -10,6 +13,9 @@ function setDisplayTile() { } function setDisplayCompact() { + console.log("DISPLAY COMPACT"); + $(".pluginContainer").removeClass("line").addClass("compact").removeClass("classic"); + $(".pluginDesc").hide(); $(".pluginDescCompact").show(); $(".pluginActions").hide(); @@ -20,9 +26,20 @@ function setDisplayCompact() { reduceTitle() } +function setDisplayLine() { + console.log("DISPLAY LINE"); + $(".pluginContainer").addClass("line").removeClass("compact").removeClass("classic"); + + $(".pluginDesc").show(); + $(".pluginDescCompact").hide(); + $(".pluginActions").show(); + $(".pluginActionsSmallIcons").hide(); + normalTitle(); +} + function reduceTitle() { var x = document.getElementsByClassName("pluginMiniBoxNameCell"); - var length = 20; + var length = 22; for (const div of x) { var text = div.innerHTML.trim() @@ -44,27 +61,362 @@ function normalTitle() { } } +function activatePlugin(id) { + console.log("Plugin activated"); + console.log(id); + + $("#"+id+" .switch").attr("disabled", true); + + $.ajax({ + type: 'GET', + dataType: 'json', + url: 'ws.php', + data: { method: 'pwg.plugins.performAction', + action: 'activate', + plugin: id, + pwg_token: pwg_token, + format: 'json' }, + success: function (data) { + if (data.stat == 'ok') { + let pluginName = id; + $("#" + id + " .pluginNotif").stop(false, true); + $("#" + id + " .AddPluginSuccess label span:first").html(plugin_added_str.replace("%s", pluginName)); + $("#" + id + " .AddPluginSuccess").css("display", "flex"); + } + }, + error: function () { + console.log(e); + console.log("It didn't work"); + $("#" + id + " .pluginNotif").stop(false, true); + $("#" + id + " .PluginActionError label span:first").html(plugin_action_error); + $("#" + id + " .PluginActionError").css("display", "flex"); + $("#" + id + " .PluginActionError").delay(1500).fadeOut(2500); + } + }).done(function (data) { + console.log(data); + $("#"+id+" .switch").attr("disabled", false); + $("#" + id + " .AddPluginSuccess").fadeOut(2500); + }) +} + +function disactivatePlugin(id) { + console.log("Plugin disactivated"); + console.log(id); + $("#"+id+" .switch").attr("disabled", true); + + $.ajax({ + type: 'GET', + dataType: 'json', + url: 'ws.php', + data: { method: 'pwg.plugins.performAction', + action: 'deactivate', + plugin: id, + pwg_token: pwg_token, + format: 'json' }, + success: function (data) { + if (data.stat == 'ok') { + let pluginName = id; + $("#" + id + " .pluginNotif").stop(false, true); + $("#" + id + " .DeactivatePluginSuccess label span:first").html(plugin_deactivated_str.replace("%s", pluginName)); + $("#" + id + " .DeactivatePluginSuccess").css("display", "flex"); + } + }, + error: function () { + console.log(e); + console.log("It didn't work"); + $("#" + id + " .pluginNotif").stop(false, true); + $("#" + id + " .PluginActionError label span:first").html(plugin_action_error); + $("#" + id + " .PluginActionError").css("display", "flex"); + $("#" + id + " .PluginActionError").delay(1500).fadeOut(2500); + } + }).done(function (data) { + console.log(data); + $("#"+id+" .switch").attr("disabled", false); + $("#" + id + " .DeactivatePluginSuccess").fadeOut(2500); + }) +} + +function deletePlugin(id, name) { + console.log("Plugin deletetion"); + console.log(id); + console.log(pwg_token); + + $.alert({ + title : deleted_plugin_msg.replace("%s",name), + content: function() { + return $.ajax({ + type: 'GET', + dataType: 'json', + url: 'ws.php', + data: { method: 'pwg.plugins.performAction', + action: 'delete', + plugin: id, + pwg_token: pwg_token, + format: 'json' }, + success: function (data) { + if (data.stat === "ok") { + $("#"+id).remove(); + actualizeFilter(); + } + }, + error: function (e) { + console.log(e); + console.log("It didn't work"); + $("#" + id + " .pluginNotif").stop(false, true); + $("#" + id + " .PluginActionError label span:first").html(plugin_action_error); + $("#" + id + " .PluginActionError").css("display", "flex"); + $("#" + id + " .PluginActionError").delay(1500).fadeOut(2500); + } + }) + }, + ...jConfirm_alert_options + }); +} + +function restorePlugin(id) { + console.log("Plugin restoration"); + console.log(id); + console.log(pwg_token); + + $.ajax({ + type: 'GET', + dataType: 'json', + url: 'ws.php', + data: { method: 'pwg.plugins.performAction', + action: 'restore', + plugin: id, + pwg_token: pwg_token, + format: 'json' }, + success: function (data) { + if (data.stat == 'ok') { + let pluginName = id; + $("#" + id + " .pluginNotif").stop(false, true); + $("#" + id + " .RestorePluginSuccess label span:first").html(plugin_restored_str.replace("%s", pluginName)); + $("#" + id + " .RestorePluginSuccess").css("display", "flex"); + } + }, + error: function (e) { + console.log(e); + console.log("It didn't work"); + $("#" + id + " .pluginNotif").stop(false, true); + $("#" + id + " .PluginActionError label span:first").html(plugin_action_error); + $("#" + id + " .PluginActionError").css("display", "flex"); + $("#" + id + " .PluginActionError").delay(1500).fadeOut(2500); + } + }).done(function (data) { + $("#" + id + " .RestorePluginSuccess").fadeOut(2500); + }) +} + +function uninstallPlugin(id) { + console.log("Plugin uninstallated"); + console.log(id); + console.log(pwg_token); + + $.ajax({ + type: 'GET', + dataType: 'json', + url: 'ws.php', + data: { method: 'pwg.plugins.performAction', + action: 'uninstall', + plugin: id, + pwg_token: pwg_token, + format: 'json' }, + success: function (data) { + console.log(data); + console.log("it works (uninstallated)"); + }, + error: function (e) { + console.log(e); + console.log("It didn't work"); + } + }) +} + +function actualizeFilter() { + $(".filterLabel").hide(); + $(".pluginMiniBox").each(function () { + if ($(this).hasClass("plugin-active")) { + $("label[for='seeActive']").show(); + console.log("BLEU"); + } + if ($(this).hasClass("plugin-inactive")) { + $("label[for='seeInactive']").show(); + } + if (($(this).hasClass("plugin-merged")) || ($(this).hasClass("plugin-missing"))) { + $("label[for='seeOther']").show(); + } + }) +} + $(document).ready(function () { + actualizeFilter(); if (!$.cookie("pwg_plugin_manager_view")) { $.cookie("pwg_plugin_manager_view", "tile"); } - if ($("#displayTile").is(":checked")) { - setDisplayTile(); + if ($("#displayClassic").is(":checked")) { + setDisplayClassic(); }; if ($("#displayCompact").is(":checked")) { setDisplayCompact(); }; - $("#displayTile").change(function () { - setDisplayTile(); - $.cookie("pwg_plugin_manager_view", "tile"); + if ($("#displayLine").is(":checked")) { + setDisplayLine(); + }; + + $("#displayClassic").change(function () { + setDisplayClassic(); + $.cookie("pwg_plugin_manager_view", "classic"); }) $("#displayCompact").change(function () { setDisplayCompact(); $.cookie("pwg_plugin_manager_view", "compact"); }) + + $("#displayLine").change(function () { + setDisplayLine(); + $.cookie("pwg_plugin_manager_view", "line"); + }) + + /* Plugin Filters */ + + $("#seeAll").on("change", function () { + console.log("All"); + $(".pluginMiniBox").show(); + }) + + $("#seeActive").on("change", function () { + console.log("Active"); + $(".pluginMiniBox").show(); + $(".pluginMiniBox").each(function () { + if (!$(this).hasClass("plugin-active")) { + $(this).hide(); + } + }) + }) + + $("#seeInactive").on("change", function () { + console.log("Inactive"); + $(".pluginMiniBox").show(); + $(".pluginMiniBox").each(function () { + if (!$(this).hasClass("plugin-inactive")) { + $(this).hide(); + } + }) + }) + + $("#seeOther").on("change", function () { + console.log("Other"); + $(".pluginMiniBox").show(); + $(".pluginMiniBox").each(function () { + if (($(this).hasClass("plugin-active") || $(this).hasClass("plugin-inactive"))) { + $(this).hide(); + } + }) + }) + + + /* Plugin Actions */ + /** + * Activate / Deactivate + */ + $(".switch").change(function () { + if ($(this).find("#toggleSelectionMode").is(':checked')) { + activatePlugin($(this).parent().parent().attr("id")); + console.log("activatePlugin"); + + $(this).parent().parent().addClass("plugin-active").removeClass("plugin-inactive"); + if ($(this).parent().parent().find(".pluginUnavailableAction").attr("href")) { + $(this).parent().parent().find(".pluginUnavailableAction").removeClass("pluginUnavailableAction").addClass("pluginActionLevel1"); + } + } else { + disactivatePlugin($(this).parent().parent().attr("id")) + console.log("disactivatePlugin"); + + $(this).parent().parent().removeClass("plugin-active").addClass("plugin-inactive"); + $(this).parent().parent().find(".pluginActionLevel1").removeClass("pluginActionLevel1").addClass("pluginUnavailableAction"); + } + + actualizeFilter(); + }) + + /** + * Delete + */ + $(".pluginContent").find('.dropdown-option.delete-plugin-button').on('click', function () { + let plugin_name = $(this).closest(".pluginContent").find(".pluginMiniBoxNameCell").html().trim(); + let plugin_id = $(this).closest(".pluginContent").parent().attr("id"); + console.log($(this).closest(".pluginContent").parent().attr("id")); + $.confirm({ + title: delete_plugin_msg.replace("%s",plugin_name), + buttons: { + confirm: { + text: confirm_msg, + btnClass: 'btn-red', + action: function () { + deletePlugin(plugin_id, plugin_name); + }, + }, + cancel: { + text: cancel_msg + } + }, + ...jConfirm_confirm_options + }) + }) + + /** + * Restore + */ + $(".pluginContent").find('.dropdown-option.plugin-restore').on('click', function () { + let plugin_name = $(this).closest(".pluginContent").find(".pluginMiniBoxNameCell").html().trim(); + let plugin_id = $(this).closest(".pluginContent").parent().attr("id"); + console.log($(this).closest(".pluginContent").parent().attr("id")); + $.confirm({ + title: restore_plugin_msg.replace('%s', plugin_name), + buttons: { + confirm: { + text: confirm_msg, + btnClass: 'btn-red', + action: function () { + restorePlugin(plugin_id); + }, + }, + cancel: { + text: cancel_msg + } + }, + ...jConfirm_confirm_options + }) + }) + + /** + * Uninstall + */ + $(".pluginContent").find('.uninstall-plugin-button').on('click', function () { + let plugin_name = $(this).closest(".pluginContent").find(".pluginMiniBoxNameCell").html().trim(); + let plugin_id = $(this).closest(".pluginContent").parent().attr("id"); + console.log($(this).closest(".pluginContent").parent().attr("id")); + $.confirm({ + title: restore_plugin_msg.replace('%s', plugin_name), + buttons: { + confirm: { + text: confirm_msg, + btnClass: 'btn-red', + action: function () { + uninstallPlugin(plugin_id); + }, + }, + cancel: { + text: cancel_msg + } + }, + ...jConfirm_confirm_options + }) + }) }) \ No newline at end of file diff --git a/admin/themes/default/template/plugins_installed.tpl b/admin/themes/default/template/plugins_installed.tpl index 67b3d7ca7..f3aece91f 100644 --- a/admin/themes/default/template/plugins_installed.tpl +++ b/admin/themes/default/template/plugins_installed.tpl @@ -20,8 +20,13 @@ const are_you_sure_msg = '{'Are you sure?'|@translate|@escape:'javascript'}'; const confirm_msg = '{"Yes, I am sure"|@translate}'; const cancel_msg = "{"No, I have changed my mind"|@translate}"; let delete_plugin_msg = '{'Are you sure you want to delete the plugin "%s"?'|@translate|@escape:'javascript'}'; +let deleted_plugin_msg = '{'Plugin "%s" deleted!'|@translate|@escape:'javascript'}'; let restore_plugin_msg = '{'Are you sure you want to restore the plugin "%s"?'|@translate|@escape:'javascript'}'; const restore_tip_msg = "{'Restore default configuration. You will lose your plugin settings!'|@translate}"; +const plugin_added_str = '{'Activated!'|@translate}'; +const plugin_deactivated_str = '{'Deactivated!'|@translate}'; +const plugin_restored_str = '{'Restored!'|@translate}'; +const plugin_action_error = '{'an error happened'|@translate}'; {literal} var queuedManager = jQuery.manageAjax.create('queued', { queue: true, @@ -32,30 +37,6 @@ var done = 0; /* group action */ jQuery(document).ready(function() { - $(".delete-plugin-button").each(function() { - let plugin_name = $(this).closest(".pluginContent").find(".pluginMiniBoxNameCell").html().trim(); - $(this).pwg_jconfirm_follow_href({ - alert_title: delete_plugin_msg.replace('%s', plugin_name), - alert_confirm: confirm_msg, - alert_cancel: cancel_msg - }); - }); - $(".plugin-restore").each(function() { - let plugin_name = $(this).closest(".pluginContent").find(".pluginMiniBoxNameCell").html().trim(); - $(this).pwg_jconfirm_follow_href({ - alert_title: restore_plugin_msg.replace('%s', plugin_name), - alert_confirm: confirm_msg, - alert_cancel: cancel_msg, - alert_content: restore_tip_msg, - }); - }); - $(".uninstall-plugin-button").each(function() { - $(this).pwg_jconfirm_follow_href({ - alert_title: are_you_sure_msg, - alert_confirm: confirm_msg, - alert_cancel: cancel_msg - }); - }); jQuery('div.deactivate_all a').click(function() { $.confirm({ title: deactivate_all_msg, @@ -160,35 +141,37 @@ jQuery(document).ready(function() { jQuery(".pluginFilter input").on("input", function() { let text = jQuery(this).val().toLowerCase(); var searchNumber = 0; - jQuery('.pluginBoxes').each(function () { - let searchNumberInBox = 0; - let pluginBoxes = jQuery(this); - pluginBoxes.find(".pluginMiniBox").each(function() { + + $(".pluginMiniBox").each(function() { if (text == "") { - jQuery(this).fadeIn() - searchNumberInBox++; + jQuery(this).fadeIn(); + searchNumber++ } else { let name = jQuery(this).find(".pluginMiniBoxNameCell").text().toLowerCase(); let description = jQuery(this).find(".pluginDesc").text().toLowerCase(); if (name.search(text) != -1 || description.search(text) != -1){ - jQuery(this).fadeIn() - searchNumberInBox++; + searchNumber++; + + if ($("#seeAll").is(":checked")) { + jQuery(this).fadeIn(); + } + if ($("#seeActive").is(":checked") && jQuery(this).hasClass("plugin-active")) { + jQuery(this).fadeIn(); + } + if ($("#seeInactive").is(":checked") && jQuery(this).hasClass("plugin-inactive")) { + + jQuery(this).fadeIn(); + } + if ($("#seeOther").is(":checked") && (jQuery(this).hasClass("plugin-merged") || jQuery(this).hasClass("plugin-missing"))) { + jQuery(this).fadeIn(); + } + } else { - jQuery(this).fadeOut() + jQuery(this).fadeOut(); } } }) - if (searchNumberInBox == 0) { - pluginBoxes.fadeOut(); - } else { - if (pluginBoxes.hasClass("plugin-inactive")) { - showInactivePlugins() - } else { - pluginBoxes.fadeIn(); - } - } - searchNumber += searchNumberInBox; - }); + if (searchNumber == 0) { jQuery(".emptyResearch").fadeIn(); } else { @@ -237,6 +220,10 @@ jQuery(".pluginMiniBox").each(function(index){ {assign var='field_name' value='null'} {* *} {counter start=0 assign=i} {* *} +
- {if $plugin.STATE == 'active'} - {'Active Plugins'|@translate} - {elseif $plugin.STATE == 'inactive'} - {'Inactive Plugins'|@translate} - {elseif $plugin.STATE == 'missing'} - {'Missing Plugins'|@translate} - {elseif $plugin.STATE == 'merged'} - {'Obsolete Plugins'|@translate} - {/if} -
-