From 7293906c91f2e92c50149cdf9f8cd7f545d3bcf5 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Sat, 26 Sep 2026 21:16:01 +0200 Subject: [PATCH 1/3] Move vehicle form script to a plugin file, share the history modal, show history to the owner --- templates/default/history_modal.js.twig | 34 +++++ .../default/public_vehicles_list.html.twig | 25 +--- templates/default/scripts.html.twig | 10 ++ templates/default/vehicles.html.twig | 139 ++++++------------ .../Controllers/tests/units/Controller.php | 20 ++- webroot/auto.js | 46 ++++++ 6 files changed, 157 insertions(+), 117 deletions(-) create mode 100644 templates/default/history_modal.js.twig create mode 100644 templates/default/scripts.html.twig create mode 100644 webroot/auto.js diff --git a/templates/default/history_modal.js.twig b/templates/default/history_modal.js.twig new file mode 100644 index 00000000..929462c4 --- /dev/null +++ b/templates/default/history_modal.js.twig @@ -0,0 +1,34 @@ +{# + # This file is part of Galette Auto plugin (https://galette.eu). + # SPDX-FileCopyrightText: Copyright © 2009-2026 The Galette Team + # SPDX-License-Identifier: GPL-3.0-or-later + #} + +{# Open vehicle history in a modal from any `.vehicle-history` button #} + $(function() { + $('.vehicle-history').on('click', function() { + $.ajax({ + url: $(this).data('url'), + success: function(res) { + {% include "elements/js/modal.js.twig" with { + modal_title_twig: _T("Car's history", "auto")|e("js"), + modal_content: "res", + modal_class: "large", + modal_content_class: "scrolling", + modal_deny_only: true, + modal_cancel_text: _T("Close")|e("js") + } %} + }, + error: function() { + {% include "elements/js/modal.js.twig" with { + modal_title_twig: _T("An error occurred displaying history :(", "auto")|e("js"), + modal_without_content: true, + modal_class: "mini", + modal_deny_only: true, + modal_cancel_text: _T("Close")|e("js"), + modal_classname: "redalert", + } %} + } + }); + }); + }); diff --git a/templates/default/public_vehicles_list.html.twig b/templates/default/public_vehicles_list.html.twig index e2db6643..90435d49 100644 --- a/templates/default/public_vehicles_list.html.twig +++ b/templates/default/public_vehicles_list.html.twig @@ -93,29 +93,6 @@ {% block javascripts %} {{ parent() }} {% endblock %} diff --git a/templates/default/scripts.html.twig b/templates/default/scripts.html.twig new file mode 100644 index 00000000..46095f90 --- /dev/null +++ b/templates/default/scripts.html.twig @@ -0,0 +1,10 @@ +{# + # This file is part of Galette Auto plugin (https://galette.eu). + # SPDX-FileCopyrightText: Copyright © 2009-2026 The Galette Team + # SPDX-License-Identifier: GPL-3.0-or-later + #} + +{# vehicle form only #} +{% if cur_route in ['vehicleAdd', 'vehicleEdit', 'doVehicleAdd', 'doVehicleEdit'] %} + +{% endif %} diff --git a/templates/default/vehicles.html.twig b/templates/default/vehicles.html.twig index 0b62afa4..bc6c7d9d 100644 --- a/templates/default/vehicles.html.twig +++ b/templates/default/vehicles.html.twig @@ -6,16 +6,26 @@ {% extends 'page.html.twig' %} +{% set can_change_owner = login.isAdmin() or login.isStaff() or login.isGroupManager() %} + {% block content %} {% if mode == 'new' %} {% set action = url_for("doVehicleAdd") %} {% else %} {% set action = url_for("doVehicleEdit", {"id": car.getId()}) %} {% endif %} -
+
- + {{ _T("Car's base informations", "auto") }}
@@ -85,7 +95,7 @@
- + {{ _T("Car's photo", "auto") }}
@@ -101,7 +111,7 @@
@@ -110,49 +120,46 @@
- + {{ _T("Current car's state informations", "auto") }}
-
{% if car.getId() %} - -

- +

+ +

{{ car.getOwner().sfullname }} - {% if login.isAdmin() or login.isStaff() or login.isGroupManager() %} - {# Does car's history should be visible by the actual owner? #} - - -

- - -
- {% endif %} - -

+ +

+ {% if can_change_owner %} +
+ + +
+ {% endif %} +
{% else %} - + {% endif %} - {% if login.isAdmin() or login.isStaff() or login.isGroupManager() %} - {% set cclass = 'field' %} - {% if car.getId() %}{% set cclass = cclass ~ ' displaynone' %}{% endif %} + {% if can_change_owner %} {% include 'components/forms/member_dropdown.html.twig' with { 'required': true, 'component_id': 'owner_id_elt', 'id': 'owner_id', 'label': _T("Owner", "auto"), 'value': car.getOwnerId(), - 'component_class': cclass + 'component_class': car.getId() ? 'field displaynone' : 'field' } %} -
- {% else %} - - {{ members.list[car.getOwnerId()] }} + {% elseif not car.getId() %} + {# simple members only own their vehicles #} +
+ +

{{ login.loggedInAs(true) }}

+
{% endif %} {% set color_list_values = {(-1): _T("Choose a color", "auto")} %} @@ -193,7 +200,7 @@
- + {{ _T("Car's technical informations", "auto") }}
@@ -274,7 +281,7 @@
- + {{ _T("Comment", "auto") }}
@@ -289,7 +296,7 @@
@@ -298,60 +305,12 @@ {% endblock %} {% block javascripts %} - + {% endblock %} diff --git a/tests/GaletteAuto/Controllers/tests/units/Controller.php b/tests/GaletteAuto/Controllers/tests/units/Controller.php index b566e3ae..fa67c153 100644 --- a/tests/GaletteAuto/Controllers/tests/units/Controller.php +++ b/tests/GaletteAuto/Controllers/tests/units/Controller.php @@ -855,7 +855,7 @@ public function testPublicListHistory(): void } /** - * Vehicle form opens history with a button + * Vehicle form opens history with a button, for the owner too */ public function testFormHistoryButton(): void { @@ -863,10 +863,24 @@ public function testFormHistoryButton(): void $this->logSuperAdmin(); $test_response = $this->app->handle($this->createRequest('vehicleEdit', ['id' => (string)$car_id])); $this->expectOK($test_response); + $body = (string)$test_response->getBody(); $this->assertMatchesRegularExpression( - '# {% if mode != "new" %} diff --git a/templates/default/object.html.twig b/templates/default/object.html.twig index 5a4a107e..e5f06017 100644 --- a/templates/default/object.html.twig +++ b/templates/default/object.html.twig @@ -13,7 +13,7 @@
- + {{ page_title }}
@@ -30,7 +30,7 @@
diff --git a/templates/default/object_show.html.twig b/templates/default/object_show.html.twig index 3f2e8d8e..99858c97 100644 --- a/templates/default/object_show.html.twig +++ b/templates/default/object_show.html.twig @@ -24,18 +24,17 @@ {{ _T("Registered models for the brand '%s'", "auto")|replace({'%s': obj.getValue()}) }}
-
+
+ {% else %}

{{ _T("The brand '%s' does not have any registered model at this time.", "auto")|replace({'%s': obj.getValue()}) }}