add a selector to choice player
authorLaurent Mazet <mazet@softndesign.org>
Tue, 17 Nov 2020 21:50:57 +0000 (22:50 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Tue, 17 Nov 2020 21:50:57 +0000 (22:50 +0100)
l10n/po/fr/trivabble.po
l10n/pot/trivabble.pot
public/alert.js
public/trivabble.js

index 33efba29a22aed42cedfe74f7e8e20aba8a7859a..816cb17dc1251edf9b523fa74ff7b071756de02d 100644 (file)
@@ -196,8 +196,8 @@ msgstr "La vérification orthographique nécessite que Trivabble télécharge un
 msgid  "Spell checking is based on:"
 msgstr "La vérification orthographique est basée sur :"
 
-msgid  "{0} points will be added to the following player '{1}'"
-msgstr "{0} points vont être ajouté au joueur '{1}'"
+msgid  "{0} points will be added to the following player"
+msgstr "{0} points vont être ajouté au joueur"
 
 msgid  "Settings"
 msgstr "Paramètres"
index adb996fff877fed3bf7b200376915e7188de947a..03f04facdb8db18ed371cae5834875eefc75027c 100644 (file)
@@ -196,7 +196,7 @@ msgstr ""
 msgid  "Spell checking is based on:"
 msgstr ""
 
-msgid  "{0} points will be added to the following player '{1}'"
+msgid  "{0} points will be added to the following player"
 msgstr ""
 
 msgid  "Settings"
index b0d5995b73fa349622d1322b07a4a66245a89929..1a85bf37b5ae90fa7e56163a45cf5a6d517f6143 100644 (file)
@@ -12,6 +12,7 @@
     let divAlertCallbackYes;
     let divAlertCallbackNo;
     let alertInput;
+    let alertSelect;
     let divAlertContent;
 
     const _ = (window.libD && libD.l10n) ? libD.l10n() : function (s) {
 
         divAlertInput.appendChild(alertInput);
 
+        alertSelect = document.createElement("select");
+        alertSelect.onchange = function () {
+            alertInput.value = alertSelect.value;
+        };
+
+        divAlertInput.appendChild(alertSelect);
+
         divAlertInput.appendChild(document.createElement("div"));
         divAlertInput.lastChild.className = "alert-prompt-buttons";
         divAlertInput.lastChild.appendChild(document.createElement("button"));
 
         divAlertContent.textContent = msg;
         divAlertInput.style.display = "";
+        alertInput.style.display = "";
         alertInput.value = defaultText || "";
         alertInput.type = (options && options.type) || "text";
+        alertSelect.style.display = "none";
         divAlertConfirm.style.display = "none";
         divAlertButton.style.display = "none";
         divAlertCallback = callback;
         divAlert.style.display = "";
         divAlertConfirm.getElementsByTagName("button")[0].focus();
     };
+
+    global.myChoice = function (msg, options, callback, defaultValue) {
+        if (!divAlert) {
+            prepare();
+        }
+
+        divAlert.classList.remove("prompt");
+
+        alertSelect.options.length = 0;
+        for (let i = 0; i < options.length; i++) {
+            alertSelect.options[i] = new Option(options[i], options[i]);
+        }
+        alertSelect.value = defaultValue;
+
+        divAlertContent.textContent = msg;
+        divAlertInput.style.display = "";
+        alertInput.style.display = "none";
+        alertSelect.style.display = "";
+        divAlertConfirm.style.display = "none";
+        divAlertButton.style.display = "none";
+        divAlertCallback = callback;
+        divAlert.style.display = "";
+        divAlertConfirm.getElementsByTagName("button")[0].focus();
+    };
 }(this));
index b2b9f5b2258b4f360de9e0ae8793f6704d0b83dc..54099414b023bc746627c2d5408d5dd0ecf45775 100644 (file)
@@ -22,7 +22,7 @@
  * @source: https://gitlab.com/raphj/trivabble/
  */
 
-/*global libD, myConfirm, myAlert, myPrompt*/
+/*global libD, myConfirm, myAlert, myPrompt, myChoice*/
 
 (function () {
     "use strict";
         }
 
         /* Confirm score */
-        if (currentPlayer === "") {
-            setCurrentPlayer( getSetting("PlayerName"));
+        if ((currentPlayer === "") || (currentPlayer === null)) {
+            setCurrentPlayer(getSetting("PlayerName"));
         }
-        myConfirm(
+        myChoice(
             format(_("{0} points will be added to the following player '{1}'"), totalScore, currentPlayer),
-            function () {
+            Object.getOwnPropertyNames(tablePlayers),
+            function (name) {
+                if (currentPlayer === "") {
+                    return;
+                }
+                if (currentPlayer !== name) {
+                    setCurrentPlayer(name);
+                }
                 const scoreCell = tablePlayers[currentPlayer].childNodes[2].childNodes[0];
                 sendCmds([{
                     cmd: "score",
                     player: currentPlayer,
                     score: parseInt(scoreCell.textContent) + totalScore
                 }]);
-            }
-        );
+            },
+            currentPlayer);
     }
 
     function triggerFlashLight(cell) {