Quellcode durchsuchen

Add customisations for confirm box.
Can change the text of the accept and reject buttons.
Now returns undefined if the user clicks off it

j433866 vor 6 Jahren
Ursprung
Commit
082d939f7d
1 geänderte Dateien mit 13 neuen und 4 gelöschten Zeilen
  1. 13 4
      src/web/App.mjs

+ 13 - 4
src/web/App.mjs

@@ -670,18 +670,22 @@ class App {
      *
      *
      * @param {string} title - The title of the box
      * @param {string} title - The title of the box
      * @param {string} body - The question (HTML supported)
      * @param {string} body - The question (HTML supported)
+     * @param {string} accept - The text of the accept button
+     * @param {string} reject - The text of the reject button
      * @param {function} callback - A function accepting one boolean argument which handles the
      * @param {function} callback - A function accepting one boolean argument which handles the
      *   response e.g. function(answer) {...}
      *   response e.g. function(answer) {...}
      * @param {Object} [scope=this] - The object to bind to the callback function
      * @param {Object} [scope=this] - The object to bind to the callback function
      *
      *
      * @example
      * @example
      * // Pops up a box asking if the user would like a cookie. Prints the answer to the console.
      * // Pops up a box asking if the user would like a cookie. Prints the answer to the console.
-     * this.confirm("Question", "Would you like a cookie?", function(answer) {console.log(answer);});
+     * this.confirm("Question", "Would you like a cookie?", "Yes", "No", function(answer) {console.log(answer);});
      */
      */
-    confirm(title, body, callback, scope) {
+    confirm(title, body, accept, reject, callback, scope) {
         scope = scope || this;
         scope = scope || this;
         document.getElementById("confirm-title").innerHTML = title;
         document.getElementById("confirm-title").innerHTML = title;
         document.getElementById("confirm-body").innerHTML = body;
         document.getElementById("confirm-body").innerHTML = body;
+        document.getElementById("confirm-yes").innerText = accept;
+        document.getElementById("confirm-no").innerText = reject;
         document.getElementById("confirm-modal").style.display = "block";
         document.getElementById("confirm-modal").style.display = "block";
 
 
         this.confirmClosed = false;
         this.confirmClosed = false;
@@ -694,9 +698,14 @@ class App {
                 callback.bind(scope)(true);
                 callback.bind(scope)(true);
                 $("#confirm-modal").modal("hide");
                 $("#confirm-modal").modal("hide");
             }.bind(this))
             }.bind(this))
+            .one("click", "#confirm-no", function() {
+                this.confirmClosed = true;
+                callback.bind(scope)(false);
+            }.bind(this))
             .one("hide.bs.modal", function(e) {
             .one("hide.bs.modal", function(e) {
-                if (!this.confirmClosed)
-                    callback.bind(scope)(false);
+                if (!this.confirmClosed) {
+                    callback.bind(scope)(undefined);
+                }
                 this.confirmClosed = true;
                 this.confirmClosed = true;
             }.bind(this));
             }.bind(this));
     }
     }