LP 1694058: Add confirmation dialog for multiple title holds.
authorJason Stephenson <jason@sigio.com>
Sat, 30 Sep 2017 19:30:22 +0000 (15:30 -0400)
committerKathy Lussier <klussier@masslnc.org>
Wed, 21 Feb 2018 21:56:11 +0000 (16:56 -0500)
Add a dialog to confirm that the user really wants to place the
requested number of title or metarecord holds to the
validateHoldForm() function.

Along the way, we add a format() function to the JS String prototype
in the i18n_strings.tt2 so that we can have translated strings with
placeholders in JavaScript.

Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>

Open-ILS/src/templates/opac/i18n_strings.tt2
Open-ILS/web/js/ui/default/opac/holds-validation.js

index d92c2b5..1617e29 100644 (file)
@@ -3,7 +3,21 @@ This file allows us to bring TT2 i18n'ized strings
 to js source files, via js blob.
 -->
 <script>
+    // Add a boost-style format function to JavaScript string.
+    // Implementation stolen from StackOverflow:
+    // https://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format
+    String.prototype.format = function() {
+        var args = arguments;
+        return this.replace(/{(\d+)}/g, function(match, number) {
+        return typeof args[number] != 'undefined'
+            ? args[number]
+            : match;
+        });
+    };
+
     var eg_opac_i18n = {};
 
     eg_opac_i18n.EG_MISSING_REQUIRED_INPUT = "[% l('Please fill out all required fields') %]";
+    // For multiple holds placement confirmation dialog. {0} is replaced by number of copies requested.
+    eg_opac_i18n.EG_MULTIHOLD_MESSAGE = "[% l('Do you really want to place {0} holds for this title?') %]";
 </script>
index ef3c4cd..7345e3f 100644 (file)
@@ -60,11 +60,22 @@ function validateMethodSelections (alertMethodCboxes) {
     return { isValid: isFormOK, culpritNames : culprits };
 }
 
+function confirmMultipleHolds() {
+    var result = true;
+    var numSelect = document.getElementById("num_copies");
+    if (numSelect) {
+        var num = parseInt(numSelect.value);
+        if (num > 1) {
+            result = window.confirm(eg_opac_i18n.EG_MULTIHOLD_MESSAGE.format(num));
+        }
+    }
+    return result;
+}
+
 function validateHoldForm() {
     var res = validateMethodSelections(document.getElementsByClassName("hold-alert-method"));
-    if (res.isValid)
-    {
-        return true;
+    if (res.isValid) {
+        return confirmMultipleHolds();
     } else {
         alert(eg_opac_i18n.EG_MISSING_REQUIRED_INPUT);
         res.culpritNames.forEach(function(n){