108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
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
|
-
-
-
+
+
+
+
+
+
-
+
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
+
+
+
+
+
|
}
_addRow (lData) {
let xRowNode = createNode("tr", { id: this.sNodeId + "_row_" + this.iEntryIndex });
if (this.bDeleteButtons) {
xRowNode.appendChild(createNode("td", { textContent: "×", className: "delete_entry", title: "Effacer cette entrée" }, { id_entry: this.iEntryIndex }));
}
for (let data of lData) {
xRowNode.appendChild(createNode("td", { textContent: data }));
}
let [nDicId, sName, sOwner, nEntry, sDescription, ...data] = lData;
xRowNode.appendChild(createNode("td", { textContent: nDicId }));
xRowNode.appendChild(createNode("td", { textContent: sName }));
xRowNode.appendChild(createNode("td", { textContent: sOwner }));
xRowNode.appendChild(createNode("td", { textContent: nEntry }));
xRowNode.appendChild(createNode("td", { textContent: sDescription }));
if (this.bActionButtons) {
xRowNode.appendChild(createNode("td", { textContent: "+", className: "select_entry", title: "Sélectionner/Désélectionner cette entrée" }, { id_entry: this.iEntryIndex }));
xRowNode.appendChild(createNode("td", { textContent: "+", className: "select_entry", title: "Sélectionner/Désélectionner cette entrée" }, { id_entry: this.iEntryIndex, dict_name: sName }));
}
this.xTable.appendChild(xRowNode);
this.iEntryIndex += 1;
}
listen () {
if (this.bDeleteButtons || this.bActionButtons) {
this.xTable.addEventListener("click", (xEvent) => { this.onTableClick(xEvent); }, false);
}
}
onTableClick (xEvent) {
try {
let xElem = xEvent.target;
if (xElem.className) {
switch (xElem.className) {
case "delete_entry": this.deleteRow(xElem.dataset.id_entry); break;
case "select_entry": this.selectEntry(xElem.dataset.id_entry); break;
case "delete_entry": this.deleteRow(xElem.dataset.id_entry, xElem.dataset.dict_name); break;
case "select_entry": this.selectEntry(xElem.dataset.id_entry, xElem.dataset.dict_name); break;
}
}
}
catch (e) {
showError(e);
}
}
deleteRow (iEntry) {
this.lEntry[parseInt(iEntry)] = null;
if (document.getElementById(this.sNodeId + "_row_" + iEntry)) {
document.getElementById(this.sNodeId + "_row_" + iEntry).style.display = "none";
}
this.nEntry -= 1;
this.showEntryNumber();
if (this.sNodeId == "lexicon_table") {
showElement("save_button", "inline-block");
}
}
selectEntry (iEntry) {
let sRowId = this.sNodeId + "_row_" + iEntry;
document.getElementById(sRowId).style.backgroundColor = "hsl(120, 50%, 90%)";
}
getEntries () {
return this.lEntry.filter((e) => e !== null);
selectEntry (nEntryId, sDicName) {
let sRowId = this.sNodeId + "_row_" + nEntryId;
if (!this.aSelectedDict.has(sDicName)) {
this.aSelectedDict.set(sDicName, nEntryId);
document.getElementById(sRowId).style.backgroundColor = "hsl(120, 50%, 90%)";
}
else {
this.aSelectedDict.delete(sDicName);
document.getElementById(sRowId).style.backgroundColor = "";
}
this.showSelectedDict();
}
clearSelectedDict () {
let xDicList = document.getElementById("dictionaries_list");
while (xDicList.firstChild) {
xDicList.removeChild(xDicList.firstChild);
}
}
showSelectedDict () {
this.clearSelectedDict();
let xDicList = document.getElementById("dictionaries_list");
if (this.aSelectedDict.size === 0) {
xDicList.textContent = "[Aucun]";
return;
}
for (let [sName, nDicId] of this.aSelectedDict) {
xDicList.appendChild(this.createDictLabel(nDicId, sName));
}
}
createDictLabel (nDicId, sLabel) {
let xLabel = createNode("div", {className: "dic_button"});
let xCloseButton = createNode("div", {className: "dic_button_close", textContent: "×"}, {id_entry: nDicId});
xCloseButton.addEventListener("click", () => {
this.aSelectedDict.delete(sLabel);
document.getElementById(this.sNodeId+"_row_"+nDicId).style.backgroundColor = "";
xLabel.style.display = "none";
});
xLabel.appendChild(xCloseButton);
xLabel.appendChild(createNode("div", {className: "dic_button_label", textContent: sLabel}));
return xLabel;
}
}
const oDicTable = new Table("dictionaries_table", ["Nom", "Créé par", "Entrées", "Description"], "wait_progress", "", false, true);
const oDicTable = new Table("dictionaries_table", ["Id", "Nom", "par", "Entrées", "Description"], "wait_progress", "num_dic", false, true);
oDicTable.fill([
["Ambre", "Inconnu", "240", "Univers des Princes d’Ambre (de Roger Zelazny)"],
["Malaz", "Inconnu", "2340", "Univers du Livre des Martyrs (de Steven Erikson)"],
["Pudlard", "Inconnu", "1440", "Univers d’Harry Potter de XXXX"],
["Dune", "Inconnu", "2359", "Univers de Dune (de Frank Herbert)"],
["StarWars", "Inconnu", "4359", "Univers de Star Wars (de George Lucas)"]
[1, "Ambre", "Inconnu", "240", "Univers des Princes d’Ambre (de Roger Zelazny)"],
[2, "Malaz", "Inconnu", "2340", "Univers du Livre des Martyrs (de Steven Erikson)"],
[3, "Poudlard", "Inconnu", "1440", "Univers d’Harry Potter (de J. K. Rowlings)"],
[4, "Dune", "Inconnu", "2359", "Univers de Dune (de Frank Herbert)"],
[5, "StarWars", "Inconnu", "4359", "Univers de Star Wars (de George Lucas)"]
]);
|