]> git.agnieray.net Git - galette.git/commitdiff
Fix contribution filtering from transactions
authorJohan Cwiklinski <johan@x-tnd.be>
Mon, 6 Nov 2023 07:06:58 +0000 (08:06 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Tue, 7 Nov 2023 03:46:56 +0000 (04:46 +0100)
Fix date selector

closes #1739

Co-authored-by: Guillaume AGNIERAY <107203963+gagnieray@users.noreply.github.com>
galette/lib/Galette/Controllers/Crud/ContributionsController.php
galette/lib/Galette/Filters/ContributionsList.php
galette/templates/default/pages/contributions_list.html.twig
galette/templates/default/pages/transaction_form.html.twig

index 0c9c9cce697b5e47a74ec787e43cfde76ae0d1b1..e130be8646c29377d983359d4a4208013e18fc28 100644 (file)
@@ -401,14 +401,6 @@ class ContributionsController extends CrudController
         $ajax = false;
         $get = $request->getQueryParams();
 
-        if (
-            ($request->getHeaderLine('X-Requested-With') === 'XMLHttpRequest')
-            || isset($get['ajax'])
-            && $get['ajax'] == 'true'
-        ) {
-            $ajax = true;
-        }
-
         switch ($type) {
             case 'transactions':
                 $raw_type = 'transactions';
@@ -430,6 +422,14 @@ class ContributionsController extends CrudController
         }
 
         $filter_name = 'filter_' . $raw_type;
+        if (
+            ($request->getHeaderLine('X-Requested-With') === 'XMLHttpRequest')
+            || isset($get['ajax'])
+            && $get['ajax'] == 'true'
+        ) {
+            $ajax = true;
+            $filter_name .= '_ajax';
+        }
 
         if (isset($this->session->$filter_name)) {
             $filters = $this->session->$filter_name;
@@ -444,7 +444,6 @@ class ContributionsController extends CrudController
         }
 
         if ($type === 'contributions') {
-            $filters->filtre_transactions = false;
             if (isset($request->getQueryParams()['max_amount'])) {
                 $filters->filtre_transactions = true;
                 $filters->max_amount = (int)$request->getQueryParams()['max_amount'];
@@ -602,7 +601,13 @@ class ContributionsController extends CrudController
      */
     public function filter(Request $request, Response $response, string $type = null): Response
     {
+        $ajax = false;
         $filter_name = 'filter_' . $type;
+        if ($request->getHeaderLine('X-Requested-With') === 'XMLHttpRequest') {
+            $ajax = true;
+            $filter_name .= '_ajax';
+        }
+
         $post = $request->getParsedBody();
         $error_detected = [];
 
@@ -614,9 +619,9 @@ class ContributionsController extends CrudController
         }
 
         if (isset($post['clear_filter'])) {
-            $filters->reinit();
+            $filters->reinit($ajax);
         } else {
-            if (isset($post['max_amount'])) {
+            if (!isset($post['max_amount'])) {
                 $filters->max_amount = null;
             }
 
index 7825cdb25988cc1901dc0d6d9a223e2683f49892..4be166191bbd5d93e0d8ac476b49fcfd8125ae34 100644 (file)
@@ -135,21 +135,26 @@ class ContributionsList extends Pagination
     /**
      * Reinit default parameters
      *
+     * @param boolean $ajax Called form an ajax query
+     *
      * @return void
      */
-    public function reinit()
+    public function reinit($ajax = false)
     {
         parent::reinit();
         $this->date_field = self::DATE_BEGIN;
         $this->start_date_filter = null;
         $this->end_date_filter = null;
         $this->payment_type_filter = null;
-        $this->filtre_transactions = false;
         $this->filtre_cotis_adh = null;
         $this->filtre_cotis_children = false;
         $this->from_transaction = false;
-        $this->max_amount = null;
         $this->selected = [];
+
+        if ($ajax === false) {
+            $this->max_amount = null;
+            $this->filtre_transactions = false;
+        }
     }
 
     /**
index 2a5ae3d7763ec556103b6fb337753dcf1a74e3af..40537db44f6cf0a87ffa13b8adc19e901a0d7f12 100644 (file)
     {% if mode == 'ajax'%}
         <input type="hidden" name="ajax" value="true"/>
         <input type="hidden" name="max_amount" value="{{ filters.max_amount }}"/>
+        <input type="hidden" name="filtre_transactions" value="{{ filters.filtre_transactions }}"/>
     {% else %}
         {% include "components/forms/csrf.html.twig" %}
     {% endif %}
index 9703d703a7790b87f945a3556f14b0ea851d99ab..3462d08a32ba79d4298f1b00f891e57710b2b63b 100644 (file)
                 $('.contributions-selection .contribution_row input[type=checkbox]').hide();
 
                 //Initialize Fomantic components
-                $('.contributions-selection .dropdown').dropdown()
-                $('[id$="rangestart"], [id$="rangeend"]').calendar();
+                $('.contributions-selection .dropdown').dropdown();
+                {% include "elements/js/calendar.js.twig" %}
 
                 //Deactivate contributions list links
                 $('.contributions-selection tbody a').click(function(){