Loading config/merged/template.config.php +6 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace UnicaenRenderer; use Laminas\Router\Http\Literal; use Laminas\Router\Http\Segment; use UnicaenRenderer\View\Helper\TemplateInsertViewHelper; use UnicaenPrivilege\Guard\PrivilegeController; use UnicaenRenderer\Controller\TemplateController; use UnicaenRenderer\Controller\TemplateControllerFactory; Loading Loading @@ -153,4 +154,9 @@ return [ TemplateController::class => TemplateControllerFactory::class, ] ], 'view_helpers' => [ 'invokables' => [ 'templateInsert' => TemplateInsertViewHelper::class, ], ], ]; public/unicaen/renderer/css/unicaen-renderer.css +21 −1 Original line number Diff line number Diff line Loading @@ -14,8 +14,28 @@ } .macro-select { width: 30rem; width: 15rem; } .macro-selection-placeholder{ display: none; } #template-insert-widget-content{ display: none; } .template-popover{ display: none; } .template-insert-widget { position: relative; top: 32px; left: -5px; margin-left: 15px; } .template-select { width: 15rem; } .template-selection-placeholder{ display: none; } No newline at end of file public/unicaen/renderer/js/unicaen-renderer.js +83 −0 Original line number Diff line number Diff line Loading @@ -92,3 +92,86 @@ function installMacrosWidgets(macros) }); }); } /** * Parcours des textareas "template compatibles" pour y installer le widget de recherche/insertion de template. * @param templates array */ function installTemplatesWidgets(templates) { $(".template-compatible").each(function (index, element) { const $textarea = $(element); // Pour éviter un chevauchement éventuelle d'input ayant la croix permettant de les vider $textarea.parent().find(".form-control-clear").detach(); $textarea.parent().removeClass('has-clear'); const id = 'template-insert-widget-' + index; const $widget = $($("#template-insert-widget-content").html()).attr('id', id); // insertion du widget $(this).before($widget); // installation du popover sur le bouton const $popoverContent = $widget.find(".template-popover-content").attr('id', 'template-popover-content-' + index); const $popoverBtn = $widget.find(".template-btn").popover({ html: true, sanitize: false, content: $popoverContent, }); // installation du select2 dans le popover let $templateSelect2; const escapeHTML = function(html) { return document.createElement('div').appendChild(document.createTextNode(html)).parentNode.innerHTML; }; const templateSelectTemplate = function (template) { if (!template) return "Aucun template sélectionné."; return '<strong class="template-id">' + template.text + '</strong> : ' + '<code class="template-value">' + escapeHTML(template.value) + '</code><br>' + '<div class="template-description text-secondary">' + template.description + '</div>'; } try { $templateSelect2 = $widget.find(".template-select").select2({ data: templates, dropdownParent: $popoverContent, placeholder: "Sélectionnez un template...", search: true, templateResult: template => $(templateSelectTemplate(template)) }); } catch (e) { alert("Impossible d'activer Select2 ! : " + e); console.error(e); } // bouton déclenchant l'insertion de template sélectionné dans le textarea const $templateInsertBtn = $popoverContent.find(".template-insert-btn").on("click", function () { // debugger; const template = $templateSelect2.select2('data')[0]; if (!template) { return; } if (tinyMCE && ($ed = tinyMCE.get($textarea.prop('id')))) { $ed.selection.setContent(template.value); } else { const caretPos = $textarea.prop('selectionStart'); if (caretPos === undefined) { $textarea.val($textarea.val() + ' ' + template.value); } else { $textarea.val($textarea.val().substring(0, caretPos) + template.value + $textarea.val().substring(caretPos)); } } }); // bouton de fermeture du popover const $templateCancelBtn = $popoverContent.find(".template-close-btn").on("click", function () { $popoverBtn.popover('hide'); }); // lorsqu'une template est sélectionnée dans le select, affichage de ses détails $templateSelect2.on("select2:select", function (e) { const template = e.params.data; $popoverContent.find(".template-selection-placeholder").html(templateSelectTemplate(template)).show(); $templateInsertBtn.removeAttr("disabled"); }); }); } No newline at end of file src/UnicaenRenderer/Controller/TemplateController.php +2 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ class TemplateController extends AbstractActionController 'form' => $form, 'template' => $template, 'macrosJsonValue' => $this->getMacroService()->generateMacrosJsonValueForTemplate($template), 'templatesJsonValue' => $this->getTemplateService()->generateTemplatesJsonValues($template), ]); return $vm; Loading Loading @@ -107,6 +108,7 @@ class TemplateController extends AbstractActionController 'form' => $form, 'template' => $template, 'macrosJsonValue' => $this->getMacroService()->generateMacrosJsonValueForTemplate($template), 'templatesJsonValue' => $this->getTemplateService()->generateTemplatesJsonValues($template), ]); } Loading src/UnicaenRenderer/Form/Template/TemplateForm.php +1 −1 Original line number Diff line number Diff line Loading @@ -128,7 +128,7 @@ class TemplateForm extends Form ], 'attributes' => [ 'id' => 'corps', 'class' => 'form-control corps macro-compatible', 'class' => 'form-control corps macro-compatible template-compatible', 'rows' => 10, ] ]); Loading Loading
config/merged/template.config.php +6 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace UnicaenRenderer; use Laminas\Router\Http\Literal; use Laminas\Router\Http\Segment; use UnicaenRenderer\View\Helper\TemplateInsertViewHelper; use UnicaenPrivilege\Guard\PrivilegeController; use UnicaenRenderer\Controller\TemplateController; use UnicaenRenderer\Controller\TemplateControllerFactory; Loading Loading @@ -153,4 +154,9 @@ return [ TemplateController::class => TemplateControllerFactory::class, ] ], 'view_helpers' => [ 'invokables' => [ 'templateInsert' => TemplateInsertViewHelper::class, ], ], ];
public/unicaen/renderer/css/unicaen-renderer.css +21 −1 Original line number Diff line number Diff line Loading @@ -14,8 +14,28 @@ } .macro-select { width: 30rem; width: 15rem; } .macro-selection-placeholder{ display: none; } #template-insert-widget-content{ display: none; } .template-popover{ display: none; } .template-insert-widget { position: relative; top: 32px; left: -5px; margin-left: 15px; } .template-select { width: 15rem; } .template-selection-placeholder{ display: none; } No newline at end of file
public/unicaen/renderer/js/unicaen-renderer.js +83 −0 Original line number Diff line number Diff line Loading @@ -92,3 +92,86 @@ function installMacrosWidgets(macros) }); }); } /** * Parcours des textareas "template compatibles" pour y installer le widget de recherche/insertion de template. * @param templates array */ function installTemplatesWidgets(templates) { $(".template-compatible").each(function (index, element) { const $textarea = $(element); // Pour éviter un chevauchement éventuelle d'input ayant la croix permettant de les vider $textarea.parent().find(".form-control-clear").detach(); $textarea.parent().removeClass('has-clear'); const id = 'template-insert-widget-' + index; const $widget = $($("#template-insert-widget-content").html()).attr('id', id); // insertion du widget $(this).before($widget); // installation du popover sur le bouton const $popoverContent = $widget.find(".template-popover-content").attr('id', 'template-popover-content-' + index); const $popoverBtn = $widget.find(".template-btn").popover({ html: true, sanitize: false, content: $popoverContent, }); // installation du select2 dans le popover let $templateSelect2; const escapeHTML = function(html) { return document.createElement('div').appendChild(document.createTextNode(html)).parentNode.innerHTML; }; const templateSelectTemplate = function (template) { if (!template) return "Aucun template sélectionné."; return '<strong class="template-id">' + template.text + '</strong> : ' + '<code class="template-value">' + escapeHTML(template.value) + '</code><br>' + '<div class="template-description text-secondary">' + template.description + '</div>'; } try { $templateSelect2 = $widget.find(".template-select").select2({ data: templates, dropdownParent: $popoverContent, placeholder: "Sélectionnez un template...", search: true, templateResult: template => $(templateSelectTemplate(template)) }); } catch (e) { alert("Impossible d'activer Select2 ! : " + e); console.error(e); } // bouton déclenchant l'insertion de template sélectionné dans le textarea const $templateInsertBtn = $popoverContent.find(".template-insert-btn").on("click", function () { // debugger; const template = $templateSelect2.select2('data')[0]; if (!template) { return; } if (tinyMCE && ($ed = tinyMCE.get($textarea.prop('id')))) { $ed.selection.setContent(template.value); } else { const caretPos = $textarea.prop('selectionStart'); if (caretPos === undefined) { $textarea.val($textarea.val() + ' ' + template.value); } else { $textarea.val($textarea.val().substring(0, caretPos) + template.value + $textarea.val().substring(caretPos)); } } }); // bouton de fermeture du popover const $templateCancelBtn = $popoverContent.find(".template-close-btn").on("click", function () { $popoverBtn.popover('hide'); }); // lorsqu'une template est sélectionnée dans le select, affichage de ses détails $templateSelect2.on("select2:select", function (e) { const template = e.params.data; $popoverContent.find(".template-selection-placeholder").html(templateSelectTemplate(template)).show(); $templateInsertBtn.removeAttr("disabled"); }); }); } No newline at end of file
src/UnicaenRenderer/Controller/TemplateController.php +2 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ class TemplateController extends AbstractActionController 'form' => $form, 'template' => $template, 'macrosJsonValue' => $this->getMacroService()->generateMacrosJsonValueForTemplate($template), 'templatesJsonValue' => $this->getTemplateService()->generateTemplatesJsonValues($template), ]); return $vm; Loading Loading @@ -107,6 +108,7 @@ class TemplateController extends AbstractActionController 'form' => $form, 'template' => $template, 'macrosJsonValue' => $this->getMacroService()->generateMacrosJsonValueForTemplate($template), 'templatesJsonValue' => $this->getTemplateService()->generateTemplatesJsonValues($template), ]); } Loading
src/UnicaenRenderer/Form/Template/TemplateForm.php +1 −1 Original line number Diff line number Diff line Loading @@ -128,7 +128,7 @@ class TemplateForm extends Form ], 'attributes' => [ 'id' => 'corps', 'class' => 'form-control corps macro-compatible', 'class' => 'form-control corps macro-compatible template-compatible', 'rows' => 10, ] ]); Loading