Loading module/Application/src/Application/View/Renderer/PhpRenderer.php +1 −1 Original line number Diff line number Diff line Loading @@ -133,7 +133,7 @@ use UnicaenApp\View\Helper\AppInfos; * * @method \UnicaenAlerte\View\Helper\AlerteViewHelper alertes() * * @method \UnicaenIdref\View\Helper\IdrefPopupTriggerViewHelper idrefPopupTrigger(string $sourceElementId, ?string $destinationElementId = null) * @method \UnicaenIdref\View\Helper\IdrefPopupTriggerViewHelper idrefPopupTrigger(array $sourceElements, ?string $destinationElement = null) * * @method boolean isAllowed($resource, $privilege = null) * Loading module/Individu/view/individu/individu/modifier.phtml +7 −3 Original line number Diff line number Diff line <?php use Application\View\Renderer\PhpRenderer; use UnicaenIdref\Domain\Index1; /** * @var \Individu\Form\IndividuForm $form Loading @@ -24,7 +25,7 @@ $form->setAttribute('class', 'row')->prepare(); </div> <div class="row"> <div class="col-md-6"> <?php echo $this->formControlGroup($form->get('nomUsuel')) ?> <?php echo $this->formControlGroup($form->get('nomUsuel')->setAttribute('id', 'nomUsuel')) ?> </div> <div class="col-md-6"> <?php echo $this->formControlGroup($form->get('nomPatronymique')) ?> Loading @@ -32,7 +33,7 @@ $form->setAttribute('class', 'row')->prepare(); </div> <div class="row"> <div class="col-md-5"> <?php echo $this->formControlGroup($form->get('prenom1')) ?> <?php echo $this->formControlGroup($form->get('prenom1')->setAttribute('id', 'prenom1')) ?> </div> <div class="col-md-5"> <?php echo $this->formControlGroup($form->get('prenom2')) ?> Loading @@ -55,7 +56,10 @@ $form->setAttribute('class', 'row')->prepare(); <?php echo $this->formControlGroup($form->get('idRef')->setAttribute('id', 'idRef')) ?> </div> <div class="col-md-2"> <?php echo $this->idrefPopupTrigger('idRef') ?> <?php echo $this->idrefPopupTrigger([ ['Index1' => Index1::INDEX_Ppn, 'Index1Value' => ['idRef']], ['Index1' => Index1::INDEX_NomDePersonne, 'Index1Value' => ['nomUsuel', 'prenom1']], ], 'idRef') ?> </div> </div> <?php echo $this->formSubmit($form->get('submit')) ?> Loading module/UnicaenIdref/public/unicaen/idref/js/trigger.js +18 −27 Original line number Diff line number Diff line Loading @@ -7,10 +7,23 @@ const UnicaenIdRef = { */ initTrigger: function ($trigger, params) { $trigger.on('click', function (event) { const $sourceElement = UnicaenIdRef.getSourceElementFromTrigger($trigger); // prise en compte de la "valeur" éventuelle de l'élément source en tant que 'index1Value' var index1Value = UnicaenIdRef.getSourceElementValue($sourceElement); const sourceElements = $trigger.data(k = 'source-elements'); if (!sourceElements) { throw new Error("UnicaenIdRef : le trigger doit fournir l'id de l'élément source via l'attribut suivant : data-" + k); } var index1 = null; var index1Value = null; $(sourceElements).each(function(i, item) { if (index1Value) { return; // on s'arrête à la première valeur trouvée } index1 = item["Index1"]; index1Value = $(item["Index1Value"]).map(function(i, val) { var sel = '#' + val; return $(sel).is(":input") ? $(sel).val() : $(sel).text(); }).get().join(' ').trim(); }); params["index1"] = index1; if (index1Value) { params["index1Value"] = index1Value; } Loading Loading @@ -40,35 +53,13 @@ const UnicaenIdRef = { handleResult: function ($trigger, data) { if (data["g"] != null) { const idref = data['b']; const $sourceElement = UnicaenIdRef.getSourceElementFromTrigger($trigger); const $destinationElement = UnicaenIdRef.getDestinationElementFromTrigger($trigger); UnicaenIdRef.setDestinationElementValue($destinationElement, idref); //console.log('idrefTriggerHandleResult', $trigger, $sourceElement, idref); } }, getSourceElementFromTrigger: function ($trigger) { const sourceElementId = $trigger.data(k = 'source-element-id'); if (!sourceElementId) { throw new Error("UnicaenIdRef : le trigger doit fournir l'id de l'élément source via l'attribut suivant : data-" + k); } const $sourceElement = $('#' + sourceElementId); if (!$sourceElement.length) { throw new Error("UnicaenIdRef : élément source introuvable avec cet id : " + sourceElementId); } return $sourceElement; }, getSourceElementValue: function ($sourceElement) { if ($sourceElement.is(":input")) { return $sourceElement.val(); } else { return $sourceElement.text(); } }, getDestinationElementFromTrigger: function ($trigger) { const destinationElementId = $trigger.data(k = 'destination-element-id'); const destinationElementId = $trigger.data(k = 'destination-element'); if (!destinationElementId) { throw new Error("UnicaenIdRef : le trigger doit fournir l'id de l'élément source via l'attribut suivant : data-" + k); } Loading module/UnicaenIdref/src/UnicaenIdref/View/Helper/IdrefPopupTriggerViewHelper.php +25 −28 Original line number Diff line number Diff line Loading @@ -11,11 +11,8 @@ use UnicaenIdref\Params; * Aide de vue dessinant un bouton affichant l'interface web d'IdRef pour rechercher la notice d'une personne/structure * dont on veut "importer" l'identifiant PPN dans un formulaire. * * Ce bouton est associé a minima à un champ texte source, duquel est prélevé le texte à rechercher (PPN, nom de personne, etc.). * Il peut être associé à un 2e champ texte destination, dans lequel sera inscrit l'identifiant PPN de la notice sélectionnée. * Si aucun champ texte destination n'est spécifié, l'identifiant PPN de la notice sélectionnée sera inscrit dans le champ texte source. * * Par défaut, cette aide de vue est paramétrée pour que la recherche se fasse sur l'identifiant PPN. * Ce bouton est associé à plusieurs champs sources possibles, desquels est prélevé le texte à rechercher (PPN, nom de personne, etc.) * et à un champ texte destination dans lequel sera inscrit l'identifiant PPN de la notice sélectionnée. * * @see https://documentation.abes.fr/aideidrefdeveloppeur/index.html#InterconnecterBaseEtIdref * Loading @@ -28,42 +25,42 @@ class IdrefPopupTriggerViewHelper extends AbstractHelper protected Button $button; protected Params $params; private string $sourceElementId; private string $destinationElementId; private array $sourceElements; private string $destinationElement; public function __construct() { $this->button = new Button('button'); $this->button->setLabel(''); // par défaut, la recherche se fait sur le PPN $this->params = new Params(); $this->params->setIndex1((new Index1)->setPpn('')); $this->params->setIndex1((new Index1)->setNomDePersonne('')); // todo : encore utile ? } /** * Point d'entrée. * * @param string $sourceElementId Id HTML de l'élément source, duquel est prélevé le texte à rechercher * @param string|null $destinationElementId Id HTML de l'élément destination dans lequel sera inscrit le PPN de la notice sélectionnée */ public function __invoke(string $sourceElementId, ?string $destinationElementId = null): self { $this->sourceElementId = $sourceElementId; $this->destinationElementId = $destinationElementId ?: $sourceElementId; return $this; } /** * Spécifie les paramètres de recherche. * @param array $sourceElements Éléments sources possibles à partir desquels seront prélevés le texte à rechercher dans l'interface web d'IdRef. * Exemple de valeur : * <pre> * [ * ['Index1' => Index1::INDEX_Ppn, 'Index1Value' => ['#idRef']], * ['Index1' => Index1::INDEX_NomDePersonne, 'Index1Value' => ['#nomUsuel', '#prenom1']], * ] * </pre> * Signification : * Si l'élément HTML '#idRef' est renseigné, alors la recherche visera un "Identifiant IdRef (n°PPN)" (Index1::INDEX_Ppn) avec * comme texte recherché la valeur de cet élément. * Sinon, la recherche visera un "Nom de personne" (Index1::INDEX_NomDePersonne) avec comme texte recherché la concaténation * des valeurs éventuelles des éléments HTML '#nomUsuel' et '#prenom1'. * * @param Params $params Ex pour rechercher selon le PPN : `(new Params())->setIndex1((new Index1)->setPpn('123456789'));` * @return self * @param string $destinationElement Élément destination dans lequel sera inscrit le PPN de la notice sélectionnée. * Exemple : '#idRef'. */ public function setParams(Params $params): self public function __invoke(array $sourceElements, string $destinationElement): self { $this->params = $params; $this->sourceElements = $sourceElements; $this->destinationElement = $destinationElement; return $this; } Loading @@ -76,8 +73,8 @@ class IdrefPopupTriggerViewHelper extends AbstractHelper $this->button ->setAttribute('class', 'idref-popup-trigger ' . $this->button->getAttribute('class')) ->setAttribute('href', '#') ->setAttribute('data-source-element-id', $this->sourceElementId) ->setAttribute('data-destination-element-id', $this->destinationElementId); ->setAttribute('data-source-elements', json_encode($this->sourceElements)) ->setAttribute('data-destination-element', $this->destinationElement); return $this->view->partial($this->partial, [ 'button' => $this->button, Loading module/UnicaenIdref/view/unicaen-idref/index/index.phtml +8 −3 Original line number Diff line number Diff line Loading @@ -31,8 +31,10 @@ use UnicaenIdref\ParamsFactory; echo $this->formControlGroup($sourceElement); echo $this->formControlGroup($destinationElement); ?> <?php echo $this->idrefPopupTrigger($sourceElement->getAttribute('id'), $destinationElement->getAttribute('id')) ->setParams(ParamsFactory::new()->setIndex1((new Index1())->setNomDePersonne(''))) ?> <?php echo $this->idrefPopupTrigger( [['Index1' => Index1::INDEX_NomDePersonne, 'Index1Value' => [$sourceElement->getAttribute('id')]]], $destinationElement->getAttribute('id') ) ?> </div> </div> Loading @@ -52,6 +54,9 @@ use UnicaenIdref\ParamsFactory; ->setAttribute('id', 'source-element-2'); echo $this->formControlGroup($sourceElement); ?> <?php echo $this->idrefPopupTrigger($sourceElement->getAttribute('id')) ?> <?php echo $this->idrefPopupTrigger( [['Index1' => Index1::INDEX_Ppn, 'Index1Value' => [$sourceElement->getAttribute('id')]]], $sourceElement->getAttribute('id') ) ?> </div> </div> Loading
module/Application/src/Application/View/Renderer/PhpRenderer.php +1 −1 Original line number Diff line number Diff line Loading @@ -133,7 +133,7 @@ use UnicaenApp\View\Helper\AppInfos; * * @method \UnicaenAlerte\View\Helper\AlerteViewHelper alertes() * * @method \UnicaenIdref\View\Helper\IdrefPopupTriggerViewHelper idrefPopupTrigger(string $sourceElementId, ?string $destinationElementId = null) * @method \UnicaenIdref\View\Helper\IdrefPopupTriggerViewHelper idrefPopupTrigger(array $sourceElements, ?string $destinationElement = null) * * @method boolean isAllowed($resource, $privilege = null) * Loading
module/Individu/view/individu/individu/modifier.phtml +7 −3 Original line number Diff line number Diff line <?php use Application\View\Renderer\PhpRenderer; use UnicaenIdref\Domain\Index1; /** * @var \Individu\Form\IndividuForm $form Loading @@ -24,7 +25,7 @@ $form->setAttribute('class', 'row')->prepare(); </div> <div class="row"> <div class="col-md-6"> <?php echo $this->formControlGroup($form->get('nomUsuel')) ?> <?php echo $this->formControlGroup($form->get('nomUsuel')->setAttribute('id', 'nomUsuel')) ?> </div> <div class="col-md-6"> <?php echo $this->formControlGroup($form->get('nomPatronymique')) ?> Loading @@ -32,7 +33,7 @@ $form->setAttribute('class', 'row')->prepare(); </div> <div class="row"> <div class="col-md-5"> <?php echo $this->formControlGroup($form->get('prenom1')) ?> <?php echo $this->formControlGroup($form->get('prenom1')->setAttribute('id', 'prenom1')) ?> </div> <div class="col-md-5"> <?php echo $this->formControlGroup($form->get('prenom2')) ?> Loading @@ -55,7 +56,10 @@ $form->setAttribute('class', 'row')->prepare(); <?php echo $this->formControlGroup($form->get('idRef')->setAttribute('id', 'idRef')) ?> </div> <div class="col-md-2"> <?php echo $this->idrefPopupTrigger('idRef') ?> <?php echo $this->idrefPopupTrigger([ ['Index1' => Index1::INDEX_Ppn, 'Index1Value' => ['idRef']], ['Index1' => Index1::INDEX_NomDePersonne, 'Index1Value' => ['nomUsuel', 'prenom1']], ], 'idRef') ?> </div> </div> <?php echo $this->formSubmit($form->get('submit')) ?> Loading
module/UnicaenIdref/public/unicaen/idref/js/trigger.js +18 −27 Original line number Diff line number Diff line Loading @@ -7,10 +7,23 @@ const UnicaenIdRef = { */ initTrigger: function ($trigger, params) { $trigger.on('click', function (event) { const $sourceElement = UnicaenIdRef.getSourceElementFromTrigger($trigger); // prise en compte de la "valeur" éventuelle de l'élément source en tant que 'index1Value' var index1Value = UnicaenIdRef.getSourceElementValue($sourceElement); const sourceElements = $trigger.data(k = 'source-elements'); if (!sourceElements) { throw new Error("UnicaenIdRef : le trigger doit fournir l'id de l'élément source via l'attribut suivant : data-" + k); } var index1 = null; var index1Value = null; $(sourceElements).each(function(i, item) { if (index1Value) { return; // on s'arrête à la première valeur trouvée } index1 = item["Index1"]; index1Value = $(item["Index1Value"]).map(function(i, val) { var sel = '#' + val; return $(sel).is(":input") ? $(sel).val() : $(sel).text(); }).get().join(' ').trim(); }); params["index1"] = index1; if (index1Value) { params["index1Value"] = index1Value; } Loading Loading @@ -40,35 +53,13 @@ const UnicaenIdRef = { handleResult: function ($trigger, data) { if (data["g"] != null) { const idref = data['b']; const $sourceElement = UnicaenIdRef.getSourceElementFromTrigger($trigger); const $destinationElement = UnicaenIdRef.getDestinationElementFromTrigger($trigger); UnicaenIdRef.setDestinationElementValue($destinationElement, idref); //console.log('idrefTriggerHandleResult', $trigger, $sourceElement, idref); } }, getSourceElementFromTrigger: function ($trigger) { const sourceElementId = $trigger.data(k = 'source-element-id'); if (!sourceElementId) { throw new Error("UnicaenIdRef : le trigger doit fournir l'id de l'élément source via l'attribut suivant : data-" + k); } const $sourceElement = $('#' + sourceElementId); if (!$sourceElement.length) { throw new Error("UnicaenIdRef : élément source introuvable avec cet id : " + sourceElementId); } return $sourceElement; }, getSourceElementValue: function ($sourceElement) { if ($sourceElement.is(":input")) { return $sourceElement.val(); } else { return $sourceElement.text(); } }, getDestinationElementFromTrigger: function ($trigger) { const destinationElementId = $trigger.data(k = 'destination-element-id'); const destinationElementId = $trigger.data(k = 'destination-element'); if (!destinationElementId) { throw new Error("UnicaenIdRef : le trigger doit fournir l'id de l'élément source via l'attribut suivant : data-" + k); } Loading
module/UnicaenIdref/src/UnicaenIdref/View/Helper/IdrefPopupTriggerViewHelper.php +25 −28 Original line number Diff line number Diff line Loading @@ -11,11 +11,8 @@ use UnicaenIdref\Params; * Aide de vue dessinant un bouton affichant l'interface web d'IdRef pour rechercher la notice d'une personne/structure * dont on veut "importer" l'identifiant PPN dans un formulaire. * * Ce bouton est associé a minima à un champ texte source, duquel est prélevé le texte à rechercher (PPN, nom de personne, etc.). * Il peut être associé à un 2e champ texte destination, dans lequel sera inscrit l'identifiant PPN de la notice sélectionnée. * Si aucun champ texte destination n'est spécifié, l'identifiant PPN de la notice sélectionnée sera inscrit dans le champ texte source. * * Par défaut, cette aide de vue est paramétrée pour que la recherche se fasse sur l'identifiant PPN. * Ce bouton est associé à plusieurs champs sources possibles, desquels est prélevé le texte à rechercher (PPN, nom de personne, etc.) * et à un champ texte destination dans lequel sera inscrit l'identifiant PPN de la notice sélectionnée. * * @see https://documentation.abes.fr/aideidrefdeveloppeur/index.html#InterconnecterBaseEtIdref * Loading @@ -28,42 +25,42 @@ class IdrefPopupTriggerViewHelper extends AbstractHelper protected Button $button; protected Params $params; private string $sourceElementId; private string $destinationElementId; private array $sourceElements; private string $destinationElement; public function __construct() { $this->button = new Button('button'); $this->button->setLabel(''); // par défaut, la recherche se fait sur le PPN $this->params = new Params(); $this->params->setIndex1((new Index1)->setPpn('')); $this->params->setIndex1((new Index1)->setNomDePersonne('')); // todo : encore utile ? } /** * Point d'entrée. * * @param string $sourceElementId Id HTML de l'élément source, duquel est prélevé le texte à rechercher * @param string|null $destinationElementId Id HTML de l'élément destination dans lequel sera inscrit le PPN de la notice sélectionnée */ public function __invoke(string $sourceElementId, ?string $destinationElementId = null): self { $this->sourceElementId = $sourceElementId; $this->destinationElementId = $destinationElementId ?: $sourceElementId; return $this; } /** * Spécifie les paramètres de recherche. * @param array $sourceElements Éléments sources possibles à partir desquels seront prélevés le texte à rechercher dans l'interface web d'IdRef. * Exemple de valeur : * <pre> * [ * ['Index1' => Index1::INDEX_Ppn, 'Index1Value' => ['#idRef']], * ['Index1' => Index1::INDEX_NomDePersonne, 'Index1Value' => ['#nomUsuel', '#prenom1']], * ] * </pre> * Signification : * Si l'élément HTML '#idRef' est renseigné, alors la recherche visera un "Identifiant IdRef (n°PPN)" (Index1::INDEX_Ppn) avec * comme texte recherché la valeur de cet élément. * Sinon, la recherche visera un "Nom de personne" (Index1::INDEX_NomDePersonne) avec comme texte recherché la concaténation * des valeurs éventuelles des éléments HTML '#nomUsuel' et '#prenom1'. * * @param Params $params Ex pour rechercher selon le PPN : `(new Params())->setIndex1((new Index1)->setPpn('123456789'));` * @return self * @param string $destinationElement Élément destination dans lequel sera inscrit le PPN de la notice sélectionnée. * Exemple : '#idRef'. */ public function setParams(Params $params): self public function __invoke(array $sourceElements, string $destinationElement): self { $this->params = $params; $this->sourceElements = $sourceElements; $this->destinationElement = $destinationElement; return $this; } Loading @@ -76,8 +73,8 @@ class IdrefPopupTriggerViewHelper extends AbstractHelper $this->button ->setAttribute('class', 'idref-popup-trigger ' . $this->button->getAttribute('class')) ->setAttribute('href', '#') ->setAttribute('data-source-element-id', $this->sourceElementId) ->setAttribute('data-destination-element-id', $this->destinationElementId); ->setAttribute('data-source-elements', json_encode($this->sourceElements)) ->setAttribute('data-destination-element', $this->destinationElement); return $this->view->partial($this->partial, [ 'button' => $this->button, Loading
module/UnicaenIdref/view/unicaen-idref/index/index.phtml +8 −3 Original line number Diff line number Diff line Loading @@ -31,8 +31,10 @@ use UnicaenIdref\ParamsFactory; echo $this->formControlGroup($sourceElement); echo $this->formControlGroup($destinationElement); ?> <?php echo $this->idrefPopupTrigger($sourceElement->getAttribute('id'), $destinationElement->getAttribute('id')) ->setParams(ParamsFactory::new()->setIndex1((new Index1())->setNomDePersonne(''))) ?> <?php echo $this->idrefPopupTrigger( [['Index1' => Index1::INDEX_NomDePersonne, 'Index1Value' => [$sourceElement->getAttribute('id')]]], $destinationElement->getAttribute('id') ) ?> </div> </div> Loading @@ -52,6 +54,9 @@ use UnicaenIdref\ParamsFactory; ->setAttribute('id', 'source-element-2'); echo $this->formControlGroup($sourceElement); ?> <?php echo $this->idrefPopupTrigger($sourceElement->getAttribute('id')) ?> <?php echo $this->idrefPopupTrigger( [['Index1' => Index1::INDEX_Ppn, 'Index1Value' => [$sourceElement->getAttribute('id')]]], $sourceElement->getAttribute('id') ) ?> </div> </div>