Grammalecte  Diff

Differences From Artifact [c815154404]:

To Artifact [f56336af44]:


27
28
29
30
31
32
33




34
35
36
37
38
39
40
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44







+
+
+
+







function showError (e) {
    console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}


document.getElementById("lexicon_button").addEventListener("click", () => { oPage.showPage("lexicon"); }, false);
document.getElementById("add_word_button").addEventListener("click", () => { oPage.showPage("lemma"); }, false);

document.getElementById("table").addEventListener("click", (xEvent) => { oPage.onTableClick(xEvent); }, false);
document.getElementById("save_button").addEventListener("click", () => { oLexicon.save(); }, false);

document.getElementById("editor").addEventListener("click", (xEvent) => { oPage.onSelectionClick(xEvent); }, false);
document.getElementById("lemma").addEventListener("keyup", () => { oPage.onWrite(); }, false);
document.getElementById("lemma2").addEventListener("keyup", () => { oPage.onWrite2(); }, false);
document.getElementById("verb_pattern").addEventListener("keyup", () => { oFlex.update(); }, false);
document.getElementById("flexion").addEventListener("keyup", () => { oFlex.update(); }, false);
document.getElementById("tags").addEventListener("keyup", () => { oFlex.update(); }, false);
document.getElementById("add_to_lexicon").addEventListener("click", () => { oFlex.addToLexicon(); }, false);
174
175
176
177
178
179
180




















































181
182
183
184
185
186
187
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








    showActions: function () {
        document.getElementById("actions").style.display = "block";
    },

    hideActions: function () {
        document.getElementById("actions").style.display = "none";
    },

    showSaveButton: function () {
        document.getElementById("save_button").style.display = "block";
    },

    hideSaveButton: function () {
        document.getElementById("save_button").style.display = "none";
    },

    createTableHeader: function () {
        let xRowNode = createNode("tr");
        xRowNode.appendChild(createNode("th", { textContent: "·" }));
        xRowNode.appendChild(createNode("th", { textContent: "#" }));
        xRowNode.appendChild(createNode("th", { textContent: "Forme fléchie" }));
        xRowNode.appendChild(createNode("th", { textContent: "Lemme" }));
        xRowNode.appendChild(createNode("th", { textContent: "Étiquettes" }));
        return xRowNode;
    },

    createRowNode: function (n, sFlexion, sLemma, sTags) {
        let xRowNode = createNode("tr", { id: "row_" + n });
        xRowNode.appendChild(createNode("td", { textContent: "×", className: "delete_entry", title: "Effacer cette entrée" }, { id_entry: n }));
        xRowNode.appendChild(createNode("td", { textContent: n }));
        xRowNode.appendChild(createNode("td", { textContent: sFlexion }));
        xRowNode.appendChild(createNode("td", { textContent: sLemma }));
        xRowNode.appendChild(createNode("td", { textContent: sTags }));
        return xRowNode;
    },

    clearTable: function () {
        let xTable = document.getElementById("table");
        while (xTable.firstChild) {
            xTable.removeChild(xTable.firstChild);
        }
    },

    onTableClick: function (xEvent) {
        try {
            let xElem = xEvent.target;
            if (xElem.className) {
                if (xElem.className == "delete_entry") {
                    let iEntry = xElem.dataset.id_entry
                    oLexicon.lFlexion[parseInt(iEntry)] = null;
                    document.getElementById("row_"+iEntry).style.display = "none";
                    this.showSaveButton();
                }
            }
        }
        catch (e) {
            showError(e);
        }
    }
}



const oFlex = {

396
397
398
399
400
401
402
403
404
405
406
407
408

409
410
411
412
413
414
415
452
453
454
455
456
457
458

459
460
461
462
463
464
465
466
467
468
469
470
471







-





+







            oPage.hideActions();
        }
    },

    addToLexicon: function () {
        try {
            oLexicon.addFlexions(this.lFlexion);
            oLexicon.save();
            document.getElementById("lemma").value = "";
            oPage.showSection("section_vide");
            oPage.hideEditor();
            oPage.hideActions();
            oPage.clear();
            oPage.showSaveButton();
            this.clear();
        }
        catch (e) {
            showError(e);
        }
    }
}
439
440
441
442
443
444
445
446

447
448
449
450

451
452

453
454
455
456
457
458
459
460
461


462
463
464
465
466

467
468
469


470
471
472
473
474
475
476
477

478
479
480
481
482


483
484

485
486



487
488
489
490
491
492
493
495
496
497
498
499
500
501

502
503
504
505

506
507

508
509
510
511
512
513
514
515


516
517





518



519
520








521





522
523


524


525
526
527
528
529
530
531
532
533
534







-
+



-
+

-
+







-
-
+
+
-
-
-
-
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
+
-
-
+
-
-
+
+
+







    _setList: function (dResult) {
        if (dResult.hasOwnProperty("lexicon_list")) {
            this.lFlexion = dResult.lexicon_list;
        }
    },

    display: function () {
        this.clearTable();
        oPage.clearTable();
        let xTable = document.getElementById("table");
        let n = 0;
        if (this.lFlexion.length > 0) {
            xTable.appendChild(this._createTableHeader());
            xTable.appendChild(oPage.createTableHeader());
            for (let [sFlexion, sLemma, sTags] of this.lFlexion) {
                xTable.appendChild(this._createRowNode(n, sFlexion, sLemma, sTags));
                xTable.appendChild(oPage.createRowNode(n, sFlexion, sLemma, sTags));
                n += 1;
            }
        } else {
            xTable.appendChild(createNode("tr", { textContent: "Aucun élément." }));
        }
    },

    _createTableHeader: function () {
        let xRowNode = createNode("tr");
    save: function () {
        console.log("u");
        xRowNode.appendChild(createNode("th", { textContent: "#" }));
        xRowNode.appendChild(createNode("th", { textContent: "Forme fléchie" }));
        xRowNode.appendChild(createNode("th", { textContent: "Lemme" }));
        xRowNode.appendChild(createNode("th", { textContent: "Étiquettes" }));
        return xRowNode;
        oPage.hideSaveButton();
    },

    _createRowNode: function (n, sFlexion, sLemma, sTags) {
        let lResult = [];
        for (let e of this.lFlexion) {
        let xRowNode = createNode("tr", { id: "row_"+n });
        xRowNode.appendChild(createNode("td", { textContent: n }));
        xRowNode.appendChild(createNode("td", { textContent: sFlexion }));
        xRowNode.appendChild(createNode("td", { textContent: sLemma }));
        xRowNode.appendChild(createNode("td", { textContent: sTags }));
        return xRowNode;
    },

            if (e !== null) {
    clearTable: function () {
        let xTable = document.getElementById("table");
        while (xTable.firstChild) {
            xTable.removeChild(xTable.firstChild);
        }
                lResult.push(e);
            }
    },

        }
    save: function () {
        browser.storage.local.set({ "lexicon_list": this.lFlexion });
        browser.storage.local.set({ "lexicon_list": lResult });
        this.lFlexion = lResult;
        this.display();
    },

    build: function () {
        return null;
    },

    export: function () {