Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions public/main/admin/configure_plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,19 @@

$em = Container::getEntityManager();

$content = '';
$currentUrl = api_get_self()."?plugin={$plugin->getTitle()}";
$currentUrl = api_get_self().'?plugin='.$plugin->getTitle();
$backUrl = api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins';

$headerHtml = '
<div class="mb-4 flex items-center justify-between">
<h2 class="text-2xl font-semibold text-gray-90">'.htmlspecialchars($pluginInfo['title'] ?? $plugin->getTitle(), ENT_QUOTES).'</h2>
<a href="'.$backUrl.'" class="btn btn--sm btn--plain" title="'.get_lang('Back').'">
<i class="mdi mdi-arrow-left"></i> '.get_lang('Back to plugins').'
</a>
</div>
';

$content = $headerHtml;

if (isset($pluginInfo['settings_form'])) {
/** @var FormValidator $form */
Expand All @@ -44,7 +55,6 @@
if (isset($pluginInfo['settings'])) {
$form->setDefaults($pluginInfo['settings']);
}
$content = Display::page_header($pluginInfo['title']);
$content .= $form->toHtml();
}
} else {
Expand Down Expand Up @@ -98,8 +108,8 @@
$objPlugin->uninstall_course_fields_in_all_courses();
}
} elseif ($newEnabled && $newDefaultVis !== $prevDefaultVis) {
$objPlugin->uninstall_course_fields_in_all_courses();
$objPlugin->install_course_fields_in_all_courses();
$objPlugin->uninstall_course_fields_in_all_courses();
$objPlugin->install_course_fields_in_all_courses();
}
}

Expand Down
108 changes: 88 additions & 20 deletions public/main/admin/settings.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ function handlePlugins()
: '<span class="badge badge--default">'.get_lang('Not installed').'</span>';

echo '<tr class="border-t border-gray-25 hover:bg-gray-15 transition duration-200">';
echo '<td class="p-3 font-medium">'.$plugin_info['title'].'</td>';
echo '<td class="p-3">'.$plugin_info['version'].'</td>';
echo '<td class="p-3 font-medium">'.htmlspecialchars($plugin_info['title'] ?? $pluginName, ENT_QUOTES).'</td>';
echo '<td class="p-3">'.htmlspecialchars($plugin_info['version'] ?? '0.0.0', ENT_QUOTES).'</td>';
echo '<td class="p-3">'.$statusBadge.'</td>';
echo '<td class="p-3 text-center">';

Expand All @@ -191,12 +191,12 @@ function handlePlugins()
$toggleIcon = $isEnabled ? 'mdi mdi-toggle-switch-off-outline' : 'mdi mdi-toggle-switch-outline';

echo '<button class="plugin-action btn btn--sm '.$toggleColor.'"
data-plugin="'.$pluginName.'" data-action="'.$toggleAction.'">
data-plugin="'.htmlspecialchars($pluginName, ENT_QUOTES).'" data-action="'.$toggleAction.'">
<i class="'.$toggleIcon.'"></i> '.$toggleText.'
</button>';

echo '<button class="plugin-action btn btn--sm btn--danger"
data-plugin="'.$pluginName.'" data-action="uninstall">
data-plugin="'.htmlspecialchars($pluginName, ENT_QUOTES).'" data-action="uninstall">
<i class="mdi mdi-trash-can-outline"></i> '.get_lang('Uninstall').'
</button>';

Expand All @@ -212,7 +212,7 @@ function handlePlugins()
);
} else {
echo '<button class="plugin-action btn btn--sm btn--success"
data-plugin="'.$pluginName.'" data-action="install">
data-plugin="'.htmlspecialchars($pluginName, ENT_QUOTES).'" data-action="install">
<i class="mdi mdi-download"></i> '.get_lang('Install').'
</button>';
}
Expand All @@ -224,23 +224,91 @@ function handlePlugins()

echo '</tbody></table>';

echo '<div id="page-loader" class="hidden fixed inset-0 bg-black/30 z-40">
<div class="absolute inset-0 flex items-center justify-center">
<div class="text-white text-sm text-center">
<i class="mdi mdi-loading mdi-spin text-3xl block mb-2"></i>
'.get_lang('Processing').'…
</div>
</div>
</div>';

echo '<script>
$(document).ready(function () {
$(".plugin-action").click(function () {
var pluginName = $(this).data("plugin");
var action = $(this).data("action");

$.post("'.api_get_path(WEB_AJAX_PATH).'plugin.ajax.php", { a: action, plugin: pluginName }, function(response) {
var data = JSON.parse(response);
if (data.success) {
location.reload();
} else {
alert("Error: " + data.error);
}
});
});
(function($){
function showToast(message, type) {
var bg = type === "success" ? "bg-green-600" : (type === "warning" ? "bg-yellow-600" : "bg-red-600");
var $toast = $("<div/>", {
class: "fixed top-4 right-4 z-50 text-white px-4 py-3 rounded shadow " + bg,
text: message
}).appendTo("body");
setTimeout(function(){ $toast.fadeOut(300, function(){ $(this).remove(); }); }, 3500);
}

function actionLabel(a) {
switch(a){
case "install": return "'.get_lang('Installing').'";
case "uninstall": return "'.get_lang('Uninstalling').'";
case "enable": return "'.get_lang('Enabling').'";
case "disable": return "'.get_lang('Disabling').'";
default: return "'.get_lang('Processing').'";
}
}

function showPageLoader(show){
$("#page-loader").toggleClass("hidden", !show);
}

$(document).ready(function () {
$(".plugin-action").on("click", function () {
var $btn = $(this);
if ($btn.data("busy")) return;

var pluginName = $btn.data("plugin");
var action = $btn.data("action");
var originalHtml = $btn.html();

$btn.data("busy", true)
.attr("aria-busy", "true")
.addClass("opacity-60 cursor-not-allowed")
.html(\'<i class="mdi mdi-loading mdi-spin"></i> \' + actionLabel(action) + "...");
$.ajax({
type: "POST",
url: "'.api_get_path(WEB_AJAX_PATH).'plugin.ajax.php",
data: { a: action, plugin: pluginName },
dataType: "json",
timeout: 120000,
beforeSend: function(){
showToast(actionLabel(action) + "…", "warning");
},
success: function(data){
if (data && data.success) {
showToast("'.get_lang('Done').': " + action.toUpperCase(), "success");
setTimeout(function(){ location.reload(); }, 500);
} else {
var msg = (data && (data.error || data.message)) ? (data.error || data.message) : "'.get_lang('Unknown error').'";
showToast("'.get_lang('Error').': " + msg, "error");
$btn.html(originalHtml);
}
},
error: function(xhr){
var msg = "'.get_lang('Request failed').'";
try {
var j = JSON.parse(xhr.responseText);
if (j && (j.error || j.message)) msg = j.error || j.message;
} catch(e) {}
showToast("'.get_lang('Error').': " + msg, "error");
$btn.html(originalHtml);
},
complete: function(){
$btn.data("busy", false)
.removeAttr("aria-busy")
.removeClass("opacity-60 cursor-not-allowed");
}
});
});
</script>';
});
})(jQuery);
</script>';
}

/**
Expand Down
4 changes: 0 additions & 4 deletions public/main/admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,6 @@
break;
case 'Plugins':
echo '<div class="tab_wrapper">';
echo '<ul class="nav nav-tabs" id="tabs" role="tablist">';
echo '<li class="nav-item"><a id="plugin-tab-1" class="nav-link active" href="#tab1" aria-controls="tab1" aria-selected="true">'.get_lang('Plugins').'</a></li>';
echo '</ul>';

echo '<div class="tab-content" id="tabs-content">';
echo '<div class="tab-pane fade show active" id="tab1" role="tabpanel" aria-labelledby="plugin-tab-1">';
handlePlugins();
Expand Down
Loading
Loading