From d68c5bac092ba40f217a207155e6b6a498f2a09c Mon Sep 17 00:00:00 2001
From: Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
Date: Fri, 16 Jul 2021 17:45:08 +0200
Subject: [PATCH] WIP bootstrap 3 => 4

---
 src/UnicaenAuth/View/Helper/UserCurrent.php   | 12 +++----
 src/UnicaenAuth/View/Helper/UserProfile.php   |  2 +-
 .../View/Helper/UserProfileSelect.php         | 16 ++++-----
 .../View/Helper/UserUsurpationHelper.php      | 36 +++++++++++--------
 .../View/Helper/partial/connect.phtml         |  6 ++--
 .../user_current/logged-in-translated.phtml   |  6 ++--
 .../expected/user_current/logged-in.phtml     |  6 ++--
 .../user_current/logged-out-translated.phtml  |  6 ++--
 .../expected/user_current/logged-out.phtml    |  6 ++--
 view/unicaen-auth/auth/login-tabs.phtml       |  6 ++--
 view/unicaen-auth/auth/login.phtml            |  4 ++-
 .../auth/request-password-reset-form.phtml    |  2 +-
 .../droits/partial/tbl-link.phtml             |  4 +--
 view/unicaen-auth/droits/privileges.phtml     |  2 +-
 view/unicaen-auth/droits/roles.phtml          |  6 ++--
 15 files changed, 63 insertions(+), 57 deletions(-)

diff --git a/src/UnicaenAuth/View/Helper/UserCurrent.php b/src/UnicaenAuth/View/Helper/UserCurrent.php
index d086f7c..dfaf775 100644
--- a/src/UnicaenAuth/View/Helper/UserCurrent.php
+++ b/src/UnicaenAuth/View/Helper/UserCurrent.php
@@ -52,7 +52,7 @@ class UserCurrent extends UserAbstract
 		            $selectableRoles = $this->getUserContext()->getSelectableIdentityRoles();
                     $role = current($selectableRoles) ?: $this->getUserContext()->getIdentityRole('user');
                 }
-                $status .= sprintf(", <small class='role-libelle'>%s</small>", !method_exists($role, '__toString') ? $role->getRoleId() : $role);
+                $status .= sprintf("<br/><small class='role-libelle'>%s</small>", !method_exists($role, '__toString') ? $role->getRoleId() : $role);
             }
         
             $userProfileHelper = $this->getView()->plugin('userProfile'); /* @var $userProfileHelper UserProfile */
@@ -77,13 +77,13 @@ class UserCurrent extends UserAbstract
         }
 
         $out = <<<EOS
-<a class="navbar-link" 
+<a class="navbar-link dropdown-toggle" 
    id="$id" 
    title="$title" 
-   data-placement="bottom" 
-   data-toggle="popover" 
-   data-html="true" 
-   data-content="$content" 
+   data-bs-placement="bottom" 
+   data-bs-toggle="popover" 
+   data-bs-html="true" 
+   data-bs-content="$content" 
    href="#">$status<span class="caret"></span></a>
 EOS;
         $out .= PHP_EOL;
diff --git a/src/UnicaenAuth/View/Helper/UserProfile.php b/src/UnicaenAuth/View/Helper/UserProfile.php
index 56393d9..f0cb706 100644
--- a/src/UnicaenAuth/View/Helper/UserProfile.php
+++ b/src/UnicaenAuth/View/Helper/UserProfile.php
@@ -36,7 +36,7 @@ class UserProfile extends UserAbstract
      */
     public function render()
     {
-        $title   = _("Profil utilisateur");
+        $title   = _("Rôle utilisateur");
         $unknown = _("Inconnu");
         $none    = _("Aucun");
 
diff --git a/src/UnicaenAuth/View/Helper/UserProfileSelect.php b/src/UnicaenAuth/View/Helper/UserProfileSelect.php
index 136634e..c51c261 100644
--- a/src/UnicaenAuth/View/Helper/UserProfileSelect.php
+++ b/src/UnicaenAuth/View/Helper/UserProfileSelect.php
@@ -2,6 +2,7 @@
 namespace UnicaenAuth\View\Helper;
 
 use Zend\Permissions\Acl\Role\RoleInterface;
+use Zend\View\Helper\HeadScript;
 
 /**
  * Aide de vue permettant à l'utilisateur de sélectionner son profil courant parmi
@@ -79,18 +80,15 @@ class UserProfileSelect extends UserAbstract
         $url = $this->getView()->url('utilisateur/default', ['action' => 'selectionner-profil']);
         $redirectUrl = $this->getView()->url($this->redirectRoute ?: 'home');
 
-        $html .= <<<EOS
-<script>
-    $(function() {
-        $("input.$inputClass").change(function() { submitProfile(); }).tooltip({ delay: 500, placement: 'left' });
-    });
-    function submitProfile()
-    {
+        $js = <<<EOS
+$(function() {
+    $("body").on("change", "input.$inputClass", function() {
         $("body *").css('cursor', 'wait');
         $.post("$url", $(".$formClass").serializeArray(), function() { $(location).attr('href', "$redirectUrl"); });
-    }
-</script>
+    });
+});
 EOS;
+        $this->view->inlineScript(HeadScript::SCRIPT, $js);
 
         return $html;
     }
diff --git a/src/UnicaenAuth/View/Helper/UserUsurpationHelper.php b/src/UnicaenAuth/View/Helper/UserUsurpationHelper.php
index 1f2d763..44db267 100644
--- a/src/UnicaenAuth/View/Helper/UserUsurpationHelper.php
+++ b/src/UnicaenAuth/View/Helper/UserUsurpationHelper.php
@@ -11,6 +11,7 @@ use Zend\Form\Element\Text;
 use Zend\Form\Form;
 use Zend\Form\View\Helper\Form as FormHelper;
 use Zend\Form\View\Helper\FormElement;
+use Zend\View\Helper\HeadScript;
 use Zend\View\Renderer\PhpRenderer;
 
 /**
@@ -145,26 +146,30 @@ class UserUsurpationHelper extends UserAbstract
         $html = '';
         $html .= $formHelper->openTag($form);
         $html .= "<div><strong>Usurpation d'identité :</strong></div>";
-        $html .= $formControlGroupHelper->__invoke($identity);
-        $html .= $formControlGroupHelper->__invoke($submit);
+        $html .= '<div class="row">' . PHP_EOL;
+        $html .= '<div class="col-sm-9">' . $formControlGroupHelper->__invoke($identity) . '</div>' . PHP_EOL;
+        $html .= '<div class="col-sm-3">' . $formControlGroupHelper->__invoke($submit) . '</div>' . PHP_EOL;
+        $html .= '</div>' . PHP_EOL;
         $html .= $formHelper->closeTag();
 
         $formId = $form->getAttribute('id');
 
-        $html .= <<<EOS
-<script>
-    var form = $("#$formId").submit(function() {
-        $("body *").css('cursor', 'wait');
-    });
-    var input = form.find(".user-usurpation-input").on('input', function() {
-        updateUsurpationSubmit();
-    });
-    function updateUsurpationSubmit() {
-        form.find(".user-usurpation-submit").prop("disabled", input.val().length === 0);
-    }
-    updateUsurpationSubmit();
-</script>
+        $js = <<<EOS
+$(function() {
+    $("body")
+        .on("input", ".user-usurpation-input", function() {
+            const input = $(this);
+            const submit = $(".user-usurpation-submit");
+            input.val().length > 0 ? 
+                submit.prop("disabled", false) : 
+                submit.prop("disabled", true);
+        })
+        .on("submit", "#$formId", function() {
+            $("body *").css('cursor', 'wait');
+        });
+});
 EOS;
+        $this->view->inlineScript(HeadScript::SCRIPT, $js);
 
         return $html;
     }
@@ -209,6 +214,7 @@ EOS;
         $submit = new Submit('submit');
         $submit->setValue("Usurper");
         $submit->setAttributes([
+            'disabled' => true,
             'class' => 'user-usurpation-submit btn btn-danger',
         ]);
 
diff --git a/src/UnicaenAuth/View/Helper/partial/connect.phtml b/src/UnicaenAuth/View/Helper/partial/connect.phtml
index 95defbd..ba278fb 100644
--- a/src/UnicaenAuth/View/Helper/partial/connect.phtml
+++ b/src/UnicaenAuth/View/Helper/partial/connect.phtml
@@ -28,10 +28,10 @@ use Zend\Form\Form;
 
 <?php if ($messages = $this->flashMessenger('zfcuser-login-form')): ?>
 <?php foreach ($messages as $message): ?>
-<div class="messenger alert alert-danger ">
-    <button type="button" class="close" title="Fermer cette alerte" data-dismiss="alert">×</button>
-    <span class="glyphicon glyphicon-warning-sign"></span>
+<div class="messenger alert alert-danger alert-dismissible ">
+    <span class="icon icon-avertissement"></span>
         <?php echo $message ?> <br>
+    <button type="button" class="btn-close" title="Fermer cette alerte" data-bs-dismiss="alert"></button>
 </div>
 <?php endforeach ?>
 <?php endif ?>
diff --git a/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-in-translated.phtml b/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-in-translated.phtml
index 14ae2ef..c752fb5 100644
--- a/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-in-translated.phtml
+++ b/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-in-translated.phtml
@@ -1,7 +1,7 @@
 <a class="navbar-link" 
    id="user-current-info" 
    title="Auth user" 
-   data-placement="bottom" 
-   data-toggle="popover" 
-   data-content="User Profile Helper MarkupUser Info Helper Markup" 
+   data-bs-placement="bottom"
+   data-bs-toggle="popover"
+   data-bs-content="User Profile Helper MarkupUser Info Helper Markup"
    href="#">User Status Helper Markup</a>
diff --git a/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-in.phtml b/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-in.phtml
index 55a4990..f9f9342 100644
--- a/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-in.phtml
+++ b/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-in.phtml
@@ -1,7 +1,7 @@
 <a class="navbar-link" 
    id="user-current-info" 
    title="Utilisateur connecté à l'application" 
-   data-placement="bottom" 
-   data-toggle="popover" 
-   data-content="User Profile Helper MarkupUser Info Helper Markup" 
+   data-bs-placement="bottom"
+   data-bs-toggle="popover"
+   data-bs-content="User Profile Helper MarkupUser Info Helper Markup"
    href="#">User Status Helper Markup</a>
diff --git a/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-out-translated.phtml b/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-out-translated.phtml
index 09fd022..5df1c92 100644
--- a/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-out-translated.phtml
+++ b/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-out-translated.phtml
@@ -1,7 +1,7 @@
 <a class="navbar-link" 
    id="user-current-info" 
    title="Auth user" 
-   data-placement="bottom" 
-   data-toggle="popover" 
-   data-content="None" 
+   data-bs-placement="bottom"
+   data-bs-toggle="popover"
+   data-bs-content="None"
    href="#">User Status Helper Markup</a>
diff --git a/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-out.phtml b/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-out.phtml
index 8e5a62d..2a4258b 100644
--- a/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-out.phtml
+++ b/tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-out.phtml
@@ -1,7 +1,7 @@
 <a class="navbar-link" 
    id="user-current-info" 
    title="Utilisateur connecté à l'application" 
-   data-placement="bottom" 
-   data-toggle="popover" 
-   data-content="Aucun" 
+   data-bs-placement="bottom"
+   data-bs-toggle="popover"
+   data-bs-content="Aucun"
    href="#">User Status Helper Markup</a>
diff --git a/view/unicaen-auth/auth/login-tabs.phtml b/view/unicaen-auth/auth/login-tabs.phtml
index b22f9a9..dca5454 100644
--- a/view/unicaen-auth/auth/login-tabs.phtml
+++ b/view/unicaen-auth/auth/login-tabs.phtml
@@ -19,7 +19,7 @@ use Zend\Form\Form;
 
 $form->prepare();
 $form->setAttributes([
-    'class' => 'form-horizontal',
+    //'class' => 'form-horizontal', // .form-horizontal n'existe plus dans boostrap 4
     'role' => 'form',
 ]);
 
@@ -45,9 +45,9 @@ $activeHelper = null;
             $activeClass = '';
         }
         ?>
-        <li role="presentation" class="<?php echo $activeClass ?>">
+        <li role="presentation" class="nav-item">
             <?php $query = $redirect ? ['redirect' => $redirect] : [] ?>
-            <a href="<?php echo $this->url('zfcuser/login', ['type' => $key], ['query' => $query]) ?>"><?php echo $helper->getTitle() ?></a>
+            <a class="nav-link <?php echo $activeClass ?>" href="<?php echo $this->url('zfcuser/login', ['type' => $key], ['query' => $query]) ?>"><?php echo $helper->getTitle() ?></a>
         </li>
     <?php endforeach ?>
 </ul>
diff --git a/view/unicaen-auth/auth/login.phtml b/view/unicaen-auth/auth/login.phtml
index 1415243..0dc7974 100644
--- a/view/unicaen-auth/auth/login.phtml
+++ b/view/unicaen-auth/auth/login.phtml
@@ -31,8 +31,10 @@ $this->headTitle("Connexion") ?>
 
 <!-- Création d'un compte local (si autorisée) -->
 <?php if ($enableRegistration) : ?>
-<div id="div-connexion" class="panel panel-primary">
+<div id="div-connexion" class="card">
+    <div class="card-body">
     <?php echo $this->translate("Not registered?"); ?> <a href="<?php echo $this->url('zfcuser/register') . ($this->redirect ? '?redirect=' . $this->redirect : '') ?>"><?php echo $this->translate("Sign up!"); ?></a>
+    </div>
 </div>
 <?php endif; ?>
 
diff --git a/view/unicaen-auth/auth/request-password-reset-form.phtml b/view/unicaen-auth/auth/request-password-reset-form.phtml
index 61e8802..765abf3 100644
--- a/view/unicaen-auth/auth/request-password-reset-form.phtml
+++ b/view/unicaen-auth/auth/request-password-reset-form.phtml
@@ -30,7 +30,7 @@ use Zend\Form\Form;
         echo $this->formInput($email);
         echo $this->formElementErrors($email, ['class' => 'text-danger']);
         ?>
-        <span class="help-block">Un lien à cliquer vous sera envoyé à cette adresse électronique.</span>
+        <span class="form-text">Un lien à cliquer vous sera envoyé à cette adresse électronique.</span>
     </p>
 
     <?php echo $this->formInput($form->get('csrf')); ?>
diff --git a/view/unicaen-auth/droits/partial/tbl-link.phtml b/view/unicaen-auth/droits/partial/tbl-link.phtml
index 799d42e..08ff592 100644
--- a/view/unicaen-auth/droits/partial/tbl-link.phtml
+++ b/view/unicaen-auth/droits/partial/tbl-link.phtml
@@ -14,7 +14,7 @@ $canEdit = $this->isAllowed(Privileges::getResourceId(Privileges::DROIT_PRIVILEG
         <a href="javascript:void(0)" data-action="refuser"
         title="Privilège '<?php echo $privilege->getCategorie() ?> > '<?php echo $privilege ?>' accordé au rôle '<?php echo $role ?>'. Cliquez pour le retirer.">
     <?php endif; ?>
-    <span class="glyphicon glyphicon-ok text-success"></span>
+    <span class="icon iconly icon-oui text-success"></span>
     <?php if ($canEdit): ?>
         </a>
     <?php endif; ?>
@@ -25,7 +25,7 @@ $canEdit = $this->isAllowed(Privileges::getResourceId(Privileges::DROIT_PRIVILEG
         <a href="javascript:void(0)" data-action="accorder"
         title="Privilège '<?php echo $privilege->getCategorie() ?> > <?php echo $privilege ?>' refusé au rôle '<?php echo $role ?>'. Cliquez pour l'accorder.">
     <?php endif; ?>
-    <span class="glyphicon glyphicon-remove text-danger refuse"></span>
+    <span class="icon iconly icon-non text-danger refuse"></span>
     <?php if ($canEdit): ?>
         </a>
     <?php endif; ?>
diff --git a/view/unicaen-auth/droits/privileges.phtml b/view/unicaen-auth/droits/privileges.phtml
index 8ce8e3e..0db6305 100644
--- a/view/unicaen-auth/droits/privileges.phtml
+++ b/view/unicaen-auth/droits/privileges.phtml
@@ -6,7 +6,7 @@
 ?>
 <h1 class="page-header">Gestion des privilèges</h1>
 
-<table class="droits-tbl table table-hover table-bordered table-condensed table-extra-condensed table-header-rotated" data-modifier-url="<?php echo $this->url('droits/privileges/modifier'); ?>">
+<table class="droits-tbl table table-hover table-bordered table-sm table-extra-condensed table-header-rotated" data-modifier-url="<?php echo $this->url('droits/privileges/modifier'); ?>">
 <thead>
     <tr>
         <th class="separator"></th>
diff --git a/view/unicaen-auth/droits/roles.phtml b/view/unicaen-auth/droits/roles.phtml
index e511f9d..bc2d109 100644
--- a/view/unicaen-auth/droits/roles.phtml
+++ b/view/unicaen-auth/droits/roles.phtml
@@ -9,7 +9,7 @@ $canEdit = $this->isAllowed('privilege/'.Privileges::DROIT_ROLE_EDITION);
 $ajoutUrl = $this->url( 'droits/roles/edition' );
 
 ?>
-<table class="table table-condensed table-bordered">
+<table class="table table-sm table-bordered">
     <tr>
         <th>Nom</th>
         <th>Parent</th>
@@ -28,8 +28,8 @@ $ajoutUrl = $this->url( 'droits/roles/edition' );
         <td><?php echo $role->getAccessibleExterieur() ? 'Oui' : 'Non'; ?></td>
         <?php if ($canEdit): ?>
         <td style="width:1%;white-space: nowrap;text-align: center">
-            <a href="<?php echo $editionUrl; ?>" class="ajax-modal" data-event="role-edition"><span class="glyphicon glyphicon-edit"></span></a>
-            <a href="<?php echo $suppressionUrl; ?>" class="ajax-modal" data-event="role-suppression"><span class="glyphicon glyphicon-remove"></span></a>
+            <a href="<?php echo $editionUrl; ?>" class="ajax-modal" data-event="role-edition"><span class="icon iconly icon-modifier"></span></a>
+            <a href="<?php echo $suppressionUrl; ?>" class="ajax-modal" data-event="role-suppression"><span class="icon iconly icon-supprimer"></span></a>
         </td>
         <?php endif; ?>
     </tr>
-- 
GitLab