some refinements on the auto counting feature
authorRaphaël Jakse <raphael.trivabble@jakse.fr>
Sun, 22 Nov 2020 10:11:59 +0000 (11:11 +0100)
committerRaphaël Jakse <raphael.trivabble@jakse.fr>
Sun, 22 Nov 2020 11:28:42 +0000 (12:28 +0100)
l10n/po/fr/trivabble.po
l10n/pot/trivabble.pot
public/alert.css
public/alert.js
public/trivabble.js

index 816cb17dc1251edf9b523fa74ff7b071756de02d..571bc21434215ba5da38ea18c8cb3ae23b556bdb 100644 (file)
@@ -196,8 +196,11 @@ 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"
-msgstr "{0} points vont être ajouté au joueur"
+msgid  "{0} points will be added to:"
+msgstr "{0} points vont être ajoutés à:"
+
+msgid "There are no points to add."
+msgstr "Il n’y a pas de point à ajouter."
 
 msgid  "Settings"
 msgstr "Paramètres"
@@ -236,4 +239,4 @@ msgid "Spell checking is not available for this language."
 msgstr "La vérification orthographique n'est pas disponible dans cette langue."
 
 msgid "Score new words"
-msgstr "Evaluer les points des mots nouveaux"
+msgstr "Compter les points"
index 03f04facdb8db18ed371cae5834875eefc75027c..7b042715756339b966d0d393414240b1d945e8b1 100644 (file)
@@ -196,9 +196,12 @@ msgstr ""
 msgid  "Spell checking is based on:"
 msgstr ""
 
-msgid  "{0} points will be added to the following player"
+msgid  "{0} points will be added to:"
 msgstr ""
 
+msgid "There are no points to add."
+msgstr: ""
+
 msgid  "Settings"
 msgstr ""
 
index 656de4501c72c360748bf1b768535b881dd35366..c2e8962c963fd4ec07a1367ed76085cb9d44e0b5 100644 (file)
@@ -40,8 +40,8 @@
     margin-top:1em;
 }
 
-.alert-content {
-    padding:1ex
+.alert-content-and-input {
+    padding:1ex;
 }
 
 .alert input[type=text], .alert input[type=number], .alert input[type=password] {
     border-radius:3px
 }
 
+.alert-prompt-buttons {
+    display: none;
+}
+
+.alert.choice .alert-prompt-buttons {
+    display: block;
+}
+
+.alert.choice.choice-inline .alert-content, .choice.choice-inline .alert-prompt {
+    display:inline-block;
+}
+
+.alert.choice.choice-inline .alert-prompt {
+    padding-left: 1ex;
+}
index 1a85bf37b5ae90fa7e56163a45cf5a6d517f6143..b83146567663a071e8cde9bba7656578177596c5 100644 (file)
 
         divAlertInput.appendChild(alertSelect);
 
-        divAlertInput.appendChild(document.createElement("div"));
-        divAlertInput.lastChild.className = "alert-prompt-buttons";
-        divAlertInput.lastChild.appendChild(document.createElement("button"));
-        divAlertInput.lastChild.lastChild.textContent = _("OK");
-        divAlertInput.lastChild.lastChild.onclick = promptOK;
-        divAlertInput.lastChild.appendChild(document.createElement("button"));
-        divAlertInput.lastChild.lastChild.textContent = _("Annuler");
-        divAlertInput.lastChild.lastChild.onclick = promptCancel;
+        const divAlertContentAndInput = document.createElement("div");
+        divAlertContentAndInput.className = "alert-content-and-input";
+        divAlertContentAndInput.appendChild(divAlertContent);
+        divAlertContentAndInput.appendChild(divAlertInput);
+
+        const divAlerPromptButton = document.createElement("div");
+        divAlerPromptButton.className = "alert-prompt-buttons";
+        divAlerPromptButton.appendChild(document.createElement("button"));
+        divAlerPromptButton.lastChild.textContent = _("OK");
+        divAlerPromptButton.lastChild.onclick = promptOK;
+        divAlerPromptButton.appendChild(document.createElement("button"));
+        divAlerPromptButton.lastChild.textContent = _("Annuler");
+        divAlerPromptButton.lastChild.onclick = promptCancel;
 
         divAlertConfirm = document.createElement("div");
         divAlertConfirm.className = _("alert-confirm");
 
         const divAlertOuter = document.createElement("div");
         divAlertOuter.className = "alert-outer";
-        divAlertOuter.appendChild(divAlertContent);
-        divAlertOuter.appendChild(divAlertInput);
+        divAlertOuter.appendChild(divAlertContentAndInput);
+        divAlertOuter.appendChild(divAlerPromptButton);
         divAlertOuter.appendChild(divAlertConfirm);
         divAlertOuter.appendChild(divAlertButton);
         divAlert.appendChild(divAlertOuter);
         }
 
         divAlert.classList.remove("prompt");
+        divAlert.classList.remove('choice');
+        divAlert.classList.remove('choice-inline');
 
         divAlertContent.textContent = msg;
         divAlertInput.style.display = "none";
         }
 
         divAlert.classList.add("prompt");
+        divAlert.classList.remove('choice');
+        divAlert.classList.remove('choice-inline');
 
         divAlertContent.textContent = msg;
         divAlertInput.style.display = "";
         }
 
         divAlert.classList.remove("prompt");
+        divAlert.classList.remove('choice');
+        divAlert.classList.remove('choice-inline');
 
         divAlertContent.textContent = msg;
         divAlertInput.style.display = "none";
         }
 
         divAlert.classList.remove("prompt");
+        divAlert.classList.add('choice');
+
+        if (options.dispositionInline) {
+            divAlert.classList.add('choice-inline');
+        } else {
+            divAlert.classList.remove('choice-inline');
+        }
 
         alertSelect.options.length = 0;
-        for (let i = 0; i < options.length; i++) {
-            alertSelect.options[i] = new Option(options[i], options[i]);
+        for (const key of options.choices) {
+            [].push.call(alertSelect.options, new Option(key, key));
         }
         alertSelect.value = defaultValue;
 
index a66696bf49a09ad38b921f1a9ef1b4034590f044..62a9d52686c63a9a156c0924fbf0e78d2c5980c1 100644 (file)
         refreshCurrentPlayer();
     }
 
+    function getScoreCell(playerName) {
+        return tablePlayers[playerName].childNodes[2].childNodes[0];
+    }
+
     function setPlayers(players) {
         if (participantPlaceholder) {
             participantPlaceholder.parentNode.removeChild(participantPlaceholder);
             }
 
             if (Object.prototype.hasOwnProperty.call(player, "score")) {
-                const scoreCell = tablePlayers[playerName].childNodes[2].childNodes[0];
+                const scoreCell = getScoreCell(playerName);
                 scoreCell.textContent = player.score;
                 blink(scoreCell);
             }
             totalScore += wordScore * wordFactor;
         }
 
-        /* Check for trivabble */
+        if (!totalScore) {
+            myAlert(_("There are no points to add."));
+            return;
+        }
+
+        /* Check for trivabble (the premium score) */
         if (Object.keys(currentTilePlayed).length === 7) {
             totalScore += getSetting("PREMIUM_SEVEN_TILES");
         }
 
-        /* Confirm score */
-        if ((currentPlayer === "") || (currentPlayer === null)) {
-            setCurrentPlayer(getSetting("PlayerName"));
-        }
         myChoice(
-            format(_("{0} points will be added to the following player '{1}'"), totalScore, currentPlayer),
-            Object.getOwnPropertyNames(tablePlayers),
+            format(_("{0} points will be added to:"), totalScore), {
+                choices: Object.keys(tablePlayers),
+                dispositionInline: true
+            },
             function (name) {
-                if ((currentPlayer === "") || (currentPlayer === null)) {
+                if (!name) {
                     return;
                 }
-                if (currentPlayer !== name) {
-                    setCurrentPlayer(name);
-                }
-                const scoreCell = tablePlayers[currentPlayer].childNodes[2].childNodes[0];
+
                 sendCmds([{
                     cmd: "score",
                     player: currentPlayer,
-                    score: parseInt(scoreCell.textContent) + totalScore
+                    score: parseInt(getScoreCell(name).textContent) + totalScore
                 }]);
             },
-            currentPlayer);
+            currentPlayer || getSetting("PlayerName")
+        );
     }
 
     function triggerFlashLight(cell) {