Published on 03/10/2021
Published by Pratik Takle
Ticket Handler
- The ticket Handler module works as an intermediate module between the destination module and the route call
- For eg: route_ajax=“ticket-handler/<ticket_id>/submit”
- Here submit module is the destination module
- At first ticket-handler module will be executed and here session ticket will be verified.
- Use session_ticket.get to get session ticket data.
- Check details here – session_ticket-get
- Please consider the following example,
- Calling Code snippet in samples app:
-
12345678[templates.add main][session_ticket.create nonce=yes set=template.ticket_id /][session_ticket.set_activity {template.ticket_id} app='samples' module='test_2' /]<button type="button" name="singlebutton"class="btn btn-sm btn-primary js-submit-job"> Call Test </button><script type=spa/axn axn='route.run' bind='click' bind_selector='.js-submit-job'route_ajax='ticket-handler/[template.ticket_id /]' disable_selector='.js-submit-job'></script>[/templates.add]
- The session activity is configured with the attribute,
app="samples"
serving as a router within the application. - The designated destination module within the “samples” app is labelled as “test_2”.
- When the Call Test component receives a click event, it initiates a routing action to the “ticket-handler” module within the same “samples” app.
- Ticket handler code:
-
12345678[templates.add main][aw2.get qs.0 set=ticktt /][session_ticket.get main="{ticktt}" set=ticket_data /][if.not_empty ticket_data][aw2.get ticket_data.ticket_activity.json_decode set=route_details /]//** route as per requirement | route to module, service or template **//[/if.not_empty][/templates.add]
- In the given scenario,
qs.0
is designated asticket_id
due to the structure of the route call. - Utilizing the
ticket_id
, data associated with the ticket is retrieved, denoted asticket_data
. - If
ticket_data
is not empty, it signifies that the ticket is valid and contains relevant information. - Following validation, subsequent routing procedures can be executed based on session ticket activity.
- These routing actions may encompass services, modules, or templates, depending on the context.
- Calling Code snippet using service module as calling module:
-
123456789101112131415[templates.add main][session_ticket.create nonce=yes set=template.ticket_id /][session_ticket.set_activity {template.ticket_id} app='system'service='test_service.test_module' /]<button type="button" name="singlebutton"class="btn btn-sm btn-primary js-submit-job"> Call Test </button><script type=spa/axn axn='route.run' bind='click'bind_selector='.js-submit-job'route_ajax='t/[template.ticket_id /]'disable_selector='.js-submit-job'></script>[/templates.add]
- In this code, the session activity is configured with the app attribute set to “system,” serving as a bypassing mechanism. If the system app is not present, it needs to be created.
- Additionally, the destination module is specified as the service module located in “test_service,” identified as “test_module.”
- When the Call Test receives a click event, the routing will direct to the module “test_service.test_module.”
- So simple it is, try this in your app.
- Happy coding.
- Ps: Shortly, this will get updated as ticket-handler as service perhaps there will be a modification in routine too.