Progression in styles + initiate translation process
[vchess.git] / public / javascripts / index.js
index e24995b..13004f0 100644 (file)
@@ -1,3 +1,4 @@
+// Javascript for index page: mostly counters updating
 new Vue({
        el: "#indexPage",
        data: {
@@ -7,7 +8,11 @@ new Vue({
        },
        computed: {
                sortedCounts: function () {
-                       const variantsCounts = variantArray.map( v => {
+                       const variantsCounts = variantArray
+                       .filter( v => {
+                               return v.name.startsWith(this.curPrefix);
+                       })
+                       .map( v => {
                                return {
                                        name: v.name,
                                        desc: v.description,
@@ -24,8 +29,7 @@ new Vue({
        },
        created: function() {
                const url = socketUrl;
-               // random enough (TODO: function)
-               const sid = (Date.now().toString(36) + Math.random().toString(36).substr(2, 7)).toUpperCase();
+               const sid = getRandString();
                this.conn = new WebSocket(url + "/?sid=" + sid + "&page=index");
                const socketMessageListener = msg => {
                        const data = JSON.parse(msg.data);
@@ -37,7 +41,6 @@ new Vue({
                                this.counts[data.vname]--;
                };
                const socketCloseListener = () => {
-                       console.log("Lost connection -- reconnect");
                        this.conn = new WebSocket(url + "/?sid=" + sid + "&page=index");
                        this.conn.addEventListener('message', socketMessageListener);
                        this.conn.addEventListener('close', socketCloseListener);
@@ -71,5 +74,23 @@ new Vue({
                        }
                        // ...ignore everything else
                };
+               // Show welcome dialog box if "first visit"
+               const visited = getCookie("visited");
+               if (!visited || visited !== "1")
+                       document.getElementById("modalB4welcome").checked = true;
+       },
+       methods: {
+               showWelcomeMsg: function() {
+                       document.getElementById("modalB4welcome").checked = false;
+                       document.getElementById("modalWelcome").checked = true;
+               },
+               markAsVisited: function() {
+                       setCookie('visited', '1');
+                       document.getElementById('modalWelcome').checked = false;
+               },
+               setLanguage: function(e) {
+                       setCookie("lang", e.target.value);
+                       location.reload(); //to include the right .pug file
+               },
        },
 });