Bug 35062

Summary: Allow a framework plugin to add class to prevent submit during ajax call
Product: Koha Reporter: Marcel de Rooy <m.de.rooy>
Component: CatalogingAssignee: Marcel de Rooy <m.de.rooy>
Status: RESOLVED FIXED QA Contact: Kyle M Hall (khall) <kyle>
Severity: enhancement    
Priority: P5 - low CC: caroline.cyr-la-rose, fridolin.somers, kyle, m.de.rooy
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.05.00
Circulation function:
Bug Depends on:    
Bug Blocks: 34860    
Attachments: Bug 35062: Add class plugin-blocks-submit in addbiblio
Bug 35062: Add class plugin-blocks-submit in addbiblio
Bug 35062: Add class plugin-blocks-submit in addbiblio

Description Marcel de Rooy 2023-10-16 10:02:34 UTC
I have a plugin that does a REST API call wrapped in an ajax construct:
jQuery.ajax({ rest api stuff }).done(function() ...).fail(function() ...);

Rapidly clicking Save (while the ajax is triggered by the Change event) lets the plugin shortly show an error before the form submits. Which is obviously undesirable.

If we would replace this in addbiblio.tt:
         var onOption = function () {
-            return Check();
+            if ( $('.plugin-blocks-submit').length==0 ) return Check();
         }

We can conditionally and temporarily block submittal.
When the change event of the plugin fires, I add class plugin-no-submit to the html element involved. In the done and fail functions I remove the class again from the element.
This effectively works. While several other approaches in addbiblio failed. (Removing the event handler is just too late.)

This is a one-liner that will do the job. On bug 34860 I will still submit a ISBN/ISSN plugin using this class that will demonstrate its use. In the meantime this is a harmless check.
Comment 1 Marcel de Rooy 2023-10-16 13:25:09 UTC
Actually, is it better move the condition to function Check itself.
Comment 2 Marcel de Rooy 2023-10-17 11:39:10 UTC
Created attachment 157226 [details] [review]
Bug 35062: Add class plugin-blocks-submit in addbiblio

Adding this condition in Check() allows you to prevent form submittal
during e.g. an ajax call in a framework plugin.
The plugin adds and removes the class on the corresponding html
element during processing.

Test plan:
Since we do not have a plugin using this class yet, nothing changes now.
Verify that you can still click Save in addbiblio while using standard
plugins. In other words: no change in behavior.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 3 David Nind 2023-10-25 19:39:06 UTC
Created attachment 157873 [details] [review]
Bug 35062: Add class plugin-blocks-submit in addbiblio

Adding this condition in Check() allows you to prevent form submittal
during e.g. an ajax call in a framework plugin.
The plugin adds and removes the class on the corresponding html
element during processing.

Test plan:
Since we do not have a plugin using this class yet, nothing changes now.
Verify that you can still click Save in addbiblio while using standard
plugins. In other words: no change in behavior.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: David Nind <david@davidnind.com>
Comment 4 Marcel de Rooy 2023-10-26 06:02:29 UTC
(In reply to David Nind from comment #3)
> Signed-off-by: David Nind <david@davidnind.com>

Thanks!
Comment 5 Kyle M Hall (khall) 2024-01-12 11:43:01 UTC
Created attachment 160936 [details] [review]
Bug 35062: Add class plugin-blocks-submit in addbiblio

Adding this condition in Check() allows you to prevent form submittal
during e.g. an ajax call in a framework plugin.
The plugin adds and removes the class on the corresponding html
element during processing.

Test plan:
Since we do not have a plugin using this class yet, nothing changes now.
Verify that you can still click Save in addbiblio while using standard
plugins. In other words: no change in behavior.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 6 Katrin Fischer 2024-03-22 09:37:09 UTC
Pushed for 24.05!

Well done everyone, thank you!
Comment 7 Fridolin Somers 2024-05-22 14:05:07 UTC
Not backported to 23.11.x
Comment 8 Caroline Cyr La Rose 2024-07-04 18:44:37 UTC
Architecture change, nothing to add/edit in the Koha manual.