]> git.agnieray.net Git - galette.git/commitdiff
Flexible redirect after member creation.
authorJohan Cwiklinski <jcwiklinski@teclib.com>
Mon, 15 Jan 2018 07:04:36 +0000 (08:04 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Sat, 2 Mar 2019 12:34:29 +0000 (13:34 +0100)
Closes #1136

galette/includes/routes/members.routes.php
galette/lib/Galette/Entity/Adherent.php
galette/templates/default/ajouter_contribution.tpl
galette/templates/default/member.tpl

index 0184b5deb7fa6f0e91bdb23470aed303be45247d..bfeb33acb1190ecfdcb13a468ab9e7d57daedca2 100644 (file)
@@ -1268,29 +1268,44 @@ $app->post(
             }
 
             if (count($error_detected) == 0) {
-                if (!isset($post['id_adh']) && !$member->isDueFree() && !isset($args['self'])) {
-                    return $response
-                        ->withStatus(301)
-                        ->withHeader(
-                            'Location',
-                            $this->router->pathFor(
-                                'contribution',
-                                [
-                                    'type'      => 'fee',
-                                    'action'    => 'add',
-                                ]
-                            ) . '?id_adh=' . $member->id
-                        );
-                } else {
-                    if (isset($args['self'])) {
-                        $redirect_url = $this->router->pathFor('login');
-                    } else {
-                        $redirect_url = $this->router->pathFor('member', ['id' => $member->id]);
+                $redirect_url = null;
+                if (isset($args['self'])) {
+                    $redirect_url = $this->router->pathFor('login');
+                } elseif (isset($post['redirect_on_create'])
+                    && $post['redirect_on_create'] > Adherent::AFTER_ADD_DEFAULT
+                ) {
+                    switch ($post['redirect_on_create']) {
+                        case Adherent::AFTER_ADD_TRANS:
+                            $redirect_url = $this->router->pathFor('transaction', ['action' => 'add']);
+                            break;
+                        case Adherent::AFTER_ADD_NEW:
+                            $redirect_url = $this->router->pathFor('editmember', ['action' => 'add']);
+                            break;
+                        case Adherent::AFTER_ADD_SHOW:
+                            $redirect_url = $this->router->pathFor('member', ['id' => $member->id]);
+                            break;
+                        case Adherent::AFTER_ADD_LIST:
+                            $redirect_url = $this->router->pathFor('members');
+                            break;
+                        case Adherent::AFTER_ADD_HOME:
+                            $redirect_url = $this->router->pathFor('slash');
+                            break;
                     }
-                    return $response
-                        ->withStatus(301)
-                        ->withHeader('Location', $redirect_url);
+                } elseif (!isset($post['id_adh']) && !$member->isDueFree()) {
+                    $redirect_url = $this->router->pathFor(
+                        'contribution',
+                        [
+                            'type'      => 'fee',
+                            'action'    => 'add',
+                        ]
+                    ) . '?id_adh=' . $member->id;
+                } else {
+                    $redirect_url = $this->router->pathFor('member', ['id' => $member->id]);
                 }
+
+                return $response
+                    ->withStatus(301)
+                    ->withHeader('Location', $redirect_url);
             } else {
                 //store entity in session
                 $this->session->member = $member;
index e564ad01ce0f3ee65470376d23d3875f1e30814c..2a054a8e94100d9cd37fea4df925895df66ff73a 100644 (file)
@@ -71,6 +71,13 @@ class Adherent
     const MAN = 1;
     const WOMAN = 2;
 
+    const AFTER_ADD_DEFAULT = 0;
+    const AFTER_ADD_TRANS = 1;
+    const AFTER_ADD_NEW = 2;
+    const AFTER_ADD_SHOW = 3;
+    const AFTER_ADD_LIST = 4;
+    const AFTER_ADD_HOME = 5;
+
     private $_id;
     //Identity
     private $_title;
index de1c11baaa37c04389a5a3a8446fcfffdb08ef22..d2b554e0f8824e2377c296c7aeb9e7b5b9465794 100644 (file)
     {/if}
             <p>{_T string="NB : The mandatory fields are in"} <span class="required">{_T string="red"}</span></p>
             <fieldset class="cssform">
-                <legend class="ui-state-active ui-corner-top">{if $type eq "fee"}{_T string="Select contributor and membership fee type"}{else}{_T string="Select contributor and donation type"}{/if}</legend>
+                <legend class="ui-state-active ui-corner-top">
+    {if $type eq {_T string="fee" domain="routes"}}
+                    {_T string="Select contributor and membership fee type"}
+                    <a href="{path_for name="contribution" data=["type" => {_T string="fee" domain="routes"}, "action" => {_T string="add" domain="routes"}]}?trans_id={$transaction->id}" class="button notext fright" id="btnadd" title="{_T string="Create a new fee that will be attached to the current transaction"}">{_T string="New attached fee"}</a>
+    {else}
+        {_T string="Select contributor and donation type"}
+
+                    <a href="{path_for name="contribution" data=["type" => {_T string="donation" domain="routes"}, "action" => {_T string="add" domain="routes"}]}?trans_id={$transaction->id}" class="button notext fright" id="btnadddon" title="{_T string="Create a new donation that will be attached to the current transaction"}">{_T string="New attached donation"}</a>
+    {/if}
+
+</legend>
+                <p>
+                     {_T string="Create a new %type instead" pattern="/%type/ replace=$type"}
+                </p>
                 <p>
                     <label for="id_adh" class="bline">{_T string="Contributor:"}</label>
                     <select name="id_adh" id="id_adh" class="nochosen"{if isset($disabled.id_adh)} {$disabled.id_adh}{/if}>
index 5f35470c50f62caa1ba5e376de3eb1c5f2d221db..d3b808d0c689ce3ba88b18b730e995f245529809 100644 (file)
     {/if}
         </div>
         <div class="button-container">
+            {if !$member->id && !$self_adh }
+               <label for="redirect_on_create">{_T string="After member creation:"}</label>
+               <select name="redirect_on_create" id="redirect_on_create">
+                  <option value="{constant('Galette\Entity\Adherent::AFTER_ADD_DEFAULT')}">{_T string="execute default action"}</option>
+                  <option value="{constant('Galette\Entity\Adherent::AFTER_ADD_TRANS')}">{_T string="create a new transaction"}</option>
+                  <option value="{constant('Galette\Entity\Adherent::AFTER_ADD_NEW')}">{_T string="create another new member"}</option>
+                  <option value="{constant('Galette\Entity\Adherent::AFTER_ADD_SHOW')}">{_T string="show member"}</option>
+                  <option value="{constant('Galette\Entity\Adherent::AFTER_ADD_LIST')}">{_T string="go to members list"}</option>
+                  <option value="{constant('Galette\Entity\Adherent::AFTER_ADD_HOME')}">{_T string="go to main page"}</option>
+               </select>
+               <br/>
+            {/if}
             <button type="submit" name="valid" class="action">
                 <i class="fas fa-save fa-fw"></i> {_T string="Save"}
             </button>
 
+
             {foreach item=entry from=$hidden_elements}
                 {if $entry->field_id neq 'mdp_adh'}
                     {assign var="title" value=null}
                     {/if}
                 {/if}
             {/foreach}
+
             <a href="#" id="back2top">{_T string="Back to top"}</a>
         </div>
         </form>