content.mjs 14.2 KB
Newer Older
ransome1's avatar
ransome1 committed
1
"use strict";
2
import { modal, userData, appData, setUserData, translations, handleError, setTheme, getConfirmation } from "../render.js";
3
import { _paq } from "./matomo.mjs";
4
import { createModalJail } from "../configs/modal.config.mjs";
ransome1's avatar
ransome1 committed
5
6
7
8
9
10
11
12
13
14
15
16
17

const reviewSourceforge = document.getElementById("reviewSourceforge");
const reviewWindowsStore = document.getElementById("reviewWindowsStore");
const shareFacebook = document.getElementById("shareFacebook");
const shareLinkedin = document.getElementById("shareLinkedin");
const shareTwitter = document.getElementById("shareTwitter");
const submitIssuesOnGithub = document.getElementById("submitIssuesOnGithub");
const contentTabs = document.querySelectorAll('.modal.content ul li');
const contentTabsCards = document.querySelectorAll('.modal.content section');
const helpTab1Title = document.getElementById("helpTab1Title");
const helpTab2Title = document.getElementById("helpTab2Title");
const helpTab3Title = document.getElementById("helpTab3Title");
const helpTab4Title = document.getElementById("helpTab4Title");
18
const helpTab5Title = document.getElementById("helpTab5Title");
ransome1's avatar
ransome1 committed
19
20
const helpTabContextsProjectsBody = document.getElementById("helpTabContextsProjectsBody");
const helpTabContextsProjectsTitle = document.getElementById("helpTabContextsProjectsTitle");
21
22
23
24
25
26
const helpTabDatesBody1 = document.getElementById("helpTabDatesBody1");
const helpTabDatesBody2 = document.getElementById("helpTabDatesBody2");
const helpTabRecurrencesBody1 = document.getElementById("helpTabRecurrencesBody1");
const helpTabDatesTitle1 = document.getElementById("helpTabDatesTitle1");
const helpTabDatesTitle2 = document.getElementById("helpTabDatesTitle2");
const helpTabRecurrencesTitle1 = document.getElementById("helpTabRecurrencesTitle1");
ransome1's avatar
ransome1 committed
27
28
29
30
31
32
33
34
35
36
37
const helpTabKeyboardTitle = document.getElementById("helpTabKeyboardTitle");
const helpTabKeyboardTR1TD1 = document.getElementById("helpTabKeyboardTR1TD1");
const helpTabKeyboardTR1TH1 = document.getElementById("helpTabKeyboardTR1TH1");
const helpTabKeyboardTR2TD1 = document.getElementById("helpTabKeyboardTR2TD1");
const helpTabKeyboardTR3TD1 = document.getElementById("helpTabKeyboardTR3TD1");
const helpTabKeyboardTR4TD1 = document.getElementById("helpTabKeyboardTR4TD1");
const helpTabKeyboardTR5TD1 = document.getElementById("helpTabKeyboardTR5TD1");
const helpTabKeyboardTR6TD1 = document.getElementById("helpTabKeyboardTR6TD1");
const helpTabKeyboardTR7TD1 = document.getElementById("helpTabKeyboardTR7TD1");
const helpTabKeyboardTR8TD1 = document.getElementById("helpTabKeyboardTR8TD1");
const helpTabKeyboardTR9TD1 = document.getElementById("helpTabKeyboardTR9TD1");
ransome1's avatar
ransome1 committed
38
39
40
const helpTabKeyboardTR10TD1 = document.getElementById("helpTabKeyboardTR10TD1");
const helpTabKeyboardTR11TD1 = document.getElementById("helpTabKeyboardTR11TD1");
const helpTabKeyboardTR12TD1 = document.getElementById("helpTabKeyboardTR12TD1");
ransome1's avatar
ransome1 committed
41
42
43
44
45
46
47
48
49
50
51
52
const helpTabPrioritiesBody = document.getElementById("helpTabPrioritiesBody");
const helpTabPrioritiesTitle = document.getElementById("helpTabPrioritiesTitle");
const settingsLanguage = document.getElementById("settingsLanguage");
const settingsTabAbout = document.getElementById("settingsTabAbout");
const settingsTabAboutContribute = document.getElementById("settingsTabAboutContribute");
const settingsTabAboutCopyrightLicense = document.getElementById("settingsTabAboutCopyrightLicense");
const settingsTabAboutCopyrightLicenseBody = document.getElementById("settingsTabAboutCopyrightLicenseBody");
const settingsTabAboutExternalLibraries = document.getElementById("settingsTabAboutExternalLibraries");
const settingsTabAboutHeadline = document.getElementById("settingsTabAboutHeadline");
const settingsTabAboutPrivacy = document.getElementById("settingsTabAboutPrivacy");
const settingsTabAboutPrivacyBody = document.getElementById("settingsTabAboutPrivacyBody");
const settingsTabSettings = document.getElementById("settingsTabSettings");
ransome1's avatar
ransome1 committed
53
54
55
//const settingsTabSettingsArchive = document.getElementById("settingsTabSettingsArchive");
//const settingsTabSettingsArchiveBody = document.getElementById("settingsTabSettingsArchiveBody");
//const settingsTabSettingsArchiveButton = document.getElementById("settingsTabSettingsArchiveButton");
ransome1's avatar
ransome1 committed
56
const settingsTabSettingsDarkmode = document.getElementById("settingsTabSettingsDarkmode");
ransome1's avatar
ransome1 committed
57
//const settingsTabSettingsDarkmodeBody = document.getElementById("settingsTabSettingsDarkmodeBody");
ransome1's avatar
ransome1 committed
58
59
60
61
62
63
64
65
66
const settingsTabSettingsHeadline = document.getElementById("settingsTabSettingsHeadline");
const settingsTabSettingsLanguage = document.getElementById("settingsTabSettingsLanguage");
const settingsTabSettingsLanguageBody = document.getElementById("settingsTabSettingsLanguageBody");
const settingsTabSettingsLogging = document.getElementById("settingsTabSettingsLogging");
const settingsTabSettingsLoggingBody = document.getElementById("settingsTabSettingsLoggingBody");
const settingsTabSettingsNotifications = document.getElementById("settingsTabSettingsNotifications");
const settingsTabSettingsNotificationsBody = document.getElementById("settingsTabSettingsNotificationsBody");
const settingsTabSettingsTray = document.getElementById("settingsTabSettingsTray");
const settingsTabSettingsTrayBody = document.getElementById("settingsTabSettingsTrayBody");
67
68
69
70
71
72
const helpTabKeyboardSubtitle = document.getElementById("helpTabKeyboardSubtitle");
const helpTabKeyboardTR13TD1 = document.getElementById("helpTabKeyboardTR13TD1");
const helpTabKeyboardTR14TD1 = document.getElementById("helpTabKeyboardTR14TD1");
const helpTabKeyboardTR15TD1 = document.getElementById("helpTabKeyboardTR15TD1");
const helpTabKeyboardTR16TD1 = document.getElementById("helpTabKeyboardTR16TD1");
const helpTabKeyboardTR17TD1 = document.getElementById("helpTabKeyboardTR17TD1");
73
74
75
76
const toggleDarkmode = document.getElementById("toggleDarkmode");
const toggleNotifications = document.getElementById("toggleNotifications");
const toggleTray = document.getElementById("toggleTray");

77
78
79
80
81
82
helpTabKeyboardSubtitle.innerHTML = translations.helpTabKeyboardSubtitle;
helpTabKeyboardTR13TD1.innerHTML = translations.helpTabKeyboardTR13TD1;
helpTabKeyboardTR14TD1.innerHTML = translations.helpTabKeyboardTR14TD1;
helpTabKeyboardTR15TD1.innerHTML = translations.helpTabKeyboardTR15TD1;
helpTabKeyboardTR16TD1.innerHTML = translations.helpTabKeyboardTR16TD1;
helpTabKeyboardTR17TD1.innerHTML = translations.helpTabKeyboardTR17TD1;
ransome1's avatar
ransome1 committed
83
84
85
86
helpTab1Title.innerHTML = translations.shortcuts;
helpTab2Title.innerHTML = translations.priorities;
helpTab3Title.innerHTML = translations.helpTab3Title;
helpTab4Title.innerHTML = translations.helpTab4Title;
87
helpTab5Title.innerHTML = translations.helpTab5Title;
ransome1's avatar
ransome1 committed
88
89
helpTabContextsProjectsBody.innerHTML = translations.helpTabContextsProjectsBody;
helpTabContextsProjectsTitle.innerHTML = translations.helpTabContextsProjectsTitle;
90
91
92
93
94
95
helpTabDatesBody1.innerHTML = translations.helpTabDatesBody1;
helpTabDatesBody2.innerHTML = translations.helpTabDatesBody2;
helpTabRecurrencesBody1.innerHTML = translations.helpTabRecurrencesBody1;
helpTabDatesTitle1.innerHTML = translations.helpTabDatesTitle1;
helpTabDatesTitle2.innerHTML = translations.helpTabDatesTitle2;
helpTabRecurrencesTitle1.innerHTML = translations.helpTabRecurrencesTitle1;
ransome1's avatar
ransome1 committed
96
97
98
99
100
101
102
103
104
105
106
107
helpTabKeyboardTitle.innerHTML = translations.shortcuts;
helpTabKeyboardTR10TD1.innerHTML = translations.helpTabKeyboardTR10TD1;
helpTabKeyboardTR1TD1.innerHTML = translations.addTodo;
helpTabKeyboardTR1TH1.innerHTML = translations.function;
helpTabKeyboardTR2TD1.innerHTML = translations.find;
helpTabKeyboardTR3TD1.innerHTML = translations.toggleCompletedTodos;
helpTabKeyboardTR4TD1.innerHTML = translations.toggleDarkMode;
helpTabKeyboardTR5TD1.innerHTML = translations.openFile;
helpTabKeyboardTR6TD1.innerHTML = translations.settings;
helpTabKeyboardTR7TD1.innerHTML = translations.helpTabKeyboardTR7TD1;
helpTabKeyboardTR8TD1.innerHTML = translations.toggleFilter;
helpTabKeyboardTR9TD1.innerHTML = translations.resetFilters;
ransome1's avatar
ransome1 committed
108
109
helpTabKeyboardTR11TD1.innerHTML = translations.createFile;
helpTabKeyboardTR12TD1.innerHTML = translations.reload;
ransome1's avatar
ransome1 committed
110
111
112
113
114
115
116
117
118
119
120
helpTabPrioritiesBody.innerHTML = translations.helpTabPrioritiesBody;
helpTabPrioritiesTitle.innerHTML = translations.helpTabPrioritiesTitle;
settingsTabAbout.innerHTML = translations.about;
settingsTabAboutContribute.innerHTML = translations.settingsTabAboutContribute;
settingsTabAboutCopyrightLicense.innerHTML = translations.settingsTabAboutCopyrightLicense;
settingsTabAboutCopyrightLicenseBody.innerHTML = translations.settingsTabAboutCopyrightLicenseBody;
settingsTabAboutExternalLibraries.innerHTML = translations.settingsTabAboutExternalLibraries;
settingsTabAboutHeadline.innerHTML = translations.about;
settingsTabAboutPrivacy.innerHTML = translations.settingsTabAboutPrivacy;
settingsTabAboutPrivacyBody.innerHTML = translations.settingsTabAboutPrivacyBody;
settingsTabSettings.innerHTML = translations.settings;
ransome1's avatar
ransome1 committed
121
122
//settingsTabSettingsArchive.innerHTML = translations.settingsTabSettingsArchive;
//settingsTabSettingsArchiveButton.innerHTML = translations.archive;
ransome1's avatar
ransome1 committed
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
settingsTabSettingsDarkmode.innerHTML = translations.darkmode;
settingsTabSettingsHeadline.innerHTML = translations.settings;
settingsTabSettingsLanguage.innerHTML = translations.language;
settingsTabSettingsLanguageBody.innerHTML = translations.settingsTabSettingsLanguageBody;
settingsTabSettingsLogging.innerHTML = translations.errorEventLogging;
settingsTabSettingsLoggingBody.innerHTML = translations.settingsTabSettingsLoggingBody;
settingsTabSettingsNotifications.innerHTML = translations.notifications;
settingsTabSettingsNotificationsBody.innerHTML = translations.settingsTabSettingsNotificationsBody;
settingsTabSettingsTray.innerHTML = translations.settingsTabSettingsTray;
settingsTabSettingsTrayBody.innerHTML = translations.settingsTabSettingsTrayBody;
shareFacebook.innerHTML = translations.shareFacebook;
shareLinkedin.innerHTML = translations.shareLinkedin;
shareTwitter.innerHTML = translations.shareTwitter;
reviewSourceforge.innerHTML = translations.reviewSourceforge;
reviewWindowsStore.innerHTML = translations.reviewWindowsStore;
submitIssuesOnGithub.innerHTML = translations.submitIssuesOnGithub;

contentTabs.forEach(tab => tab.addEventListener("click", function() {
  contentTabs.forEach(function(tab) {
    tab.classList.remove("is-active");
  });
  this.classList.add("is-active");
  showTab(this.classList[0]);
  // trigger matomo event
  if(userData.matomoEvents) _paq.push(["trackEvent", "Content", "Click on " + this.firstElementChild.innerHTML, this.classList[0]]);
}));
149

ransome1's avatar
ransome1 committed
150
settingsLanguage.onchange = function() {
151
  getConfirmation(setLanguage, translations.restartPrompt, this.value);
152
153
}
toggleNotifications.onclick = function() {
154
  setUserData("notifications", this.checked);
155
156
157
158
159
160
161
162
  // trigger matomo event
  if(userData.matomoEvents) _paq.push(["trackEvent", "Setting", "Click on Notifications", this.checked])
}
toggleDarkmode.onclick = function() {
  setTheme(true);
  // trigger matomo event
  if(userData.matomoEvents) _paq.push(["trackEvent", "Setting", "Click on Dark mode", this.checked])
}
163
164
165
toggleTray.onclick = function(event) {
  event.preventDefault();
  getConfirmation(setTray, translations.restartPrompt, this.checked);
166
167
168
169
}

toggleNotifications.checked = userData.notifications;

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
function setTray(setting) {
  setUserData("tray", setting);
  // trigger matomo event
  if(userData.matomoEvents) _paq.push(["trackEvent", "Settings", "Tray changed to: " + setting]);
  window.api.send("restart");
  return Promise.resolve("Info: Tray changed to: " + setting);
}
function setLanguage(language) {
  if(appData.environment==="testing") return false;
  userData.language = language;
  window.api.send("userData", ["language", userData.language]);
  window.api.send("changeLanguage", language);
  // trigger matomo event
  if(userData.matomoEvents) _paq.push(["trackEvent", "Settings", "Language changed to: " + language]);
}
ransome1's avatar
ransome1 committed
185
186
187
188
189
190
function showTab(tab) {
  contentTabsCards.forEach(function(el) {
    el.classList.remove("is-active");
  });
  document.getElementById(tab).classList.add("is-active");
}
191
function showContent(id) {
ransome1's avatar
ransome1 committed
192
  try {
193
    const section = document.getElementById(id);
ransome1's avatar
ransome1 committed
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
    // in case a content window was open, it will be closed
    modal.forEach(function(el) {
      el.classList.remove("is-active");
    });
    contentTabs.forEach(function(el) {
      el.classList.remove("is-active");
    });
    contentTabsCards.forEach(function(el) {
      el.classList.remove("is-active");
    });
    let firstTab = section.querySelector(".tabs");
    firstTab.firstElementChild.firstElementChild.classList.add("is-active");
    let firstSection = section.querySelector("section");
    firstSection.classList.add("is-active");
    section.classList.add("is-active");
    section.focus();
210
211
    // create the modal jail, so tabbing won't leave modal
    createModalJail(section);
ransome1's avatar
ransome1 committed
212
213
214
215
216
217
    return Promise.resolve("Info: Content is shown");
  } catch(error) {
    error.functionName = showContent.name;
    return Promise.reject(error);
  }
}
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
function setFriendlyLanguageNames() {
  try {
    appData.languages.forEach((language) => {
      // generate user friendly entries for language selection menu
      let friendlyLanguageName;
      switch (language) {
        case "de":
        friendlyLanguageName = "Deutsch"
        break;
        case "en":
        friendlyLanguageName = "English"
        break;
        case "it":
        friendlyLanguageName = "Italiano"
        break;
        case "es":
        friendlyLanguageName = "Español"
        break;
        case "fr":
        friendlyLanguageName = "Français"
        break;
        case "zh":
240
241
242
243
        friendlyLanguageName = "简体中文"
        break;
        case "pt":
        friendlyLanguageName = "Português do Brasil"
244
        break;
ransome1's avatar
ransome1 committed
245
        case "jp":
246
        friendlyLanguageName = "日本語"
ransome1's avatar
ransome1 committed
247
        break;
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
        default:
        return;
      }
      var option = document.createElement("option");
      option.text = friendlyLanguageName;
      option.value = language;
      if(language===userData.language) option.selected = true;
      settingsLanguage.add(option);
    });
    return Promise.resolve("Success: Friendly language names added to select field in settings");
  } catch(error) {
    error.functionName = setFriendlyLanguageNames.name;
    return Promise.reject(error);
  }
}

setFriendlyLanguageNames().then(function(response) {
  console.info(response);
}).catch(function(error) {
  handleError(error);
});

ransome1's avatar
ransome1 committed
270
export { showContent };