diff --git a/web/app/static/js/modules/corpus_analysis/view/callbacks.js b/web/app/static/js/modules/corpus_analysis/view/callbacks.js
index 4ea124d0..610e1d5f 100644
--- a/web/app/static/js/modules/corpus_analysis/view/callbacks.js
+++ b/web/app/static/js/modules/corpus_analysis/view/callbacks.js
@@ -61,7 +61,7 @@ function clientFailedCallback(resultsList, detail) {
resultsList.analysisInitError.classList.toggle('hide');
resultsList.analysisInitError.textContent = detail.msg;
} else {
- nopaque.flash(detail.msg, 'error')
+ nopaque.appClient.flash(detail.msg, 'error')
}
}
@@ -241,4 +241,4 @@ export {
resultsDataRecievedCallback,
disableElementsGeneralCallback,
enableElementsGeneralCallback,
-};
\ No newline at end of file
+};
diff --git a/web/app/static/js/nopaque/RessourceDisplays/CorpusDisplay.js b/web/app/static/js/nopaque/RessourceDisplays/CorpusDisplay.js
index 8d3b93b3..72fbd734 100644
--- a/web/app/static/js/nopaque/RessourceDisplays/CorpusDisplay.js
+++ b/web/app/static/js/nopaque/RessourceDisplays/CorpusDisplay.js
@@ -36,12 +36,12 @@ class CorpusDisplay extends RessourceDisplay {
requestCorpusExport() {
nopaque.appClient.socket.emit('export_corpus', this.user.data.corpora[this.corpusId].id);
- nopaque.flash('Preparing your corpus export...', 'corpus');
+ nopaque.appClient.flash('Preparing your corpus export...', 'corpus');
for (let exportCorpusTriggerElement of this.displayElement.querySelectorAll('.export-corpus-trigger')) {exportCorpusTriggerElement.classList.toggle('disabled', true);}
}
downloadCorpus() {
- nopaque.flash('Corpus export is done. Your corpus download is ready!', 'corpus');
+ nopaque.appClient.flash('Corpus export is done. Your corpus download is ready!', 'corpus');
for (let exportCorpusTriggerElement of this.displayElement.querySelectorAll('.export-corpus-trigger')) {exportCorpusTriggerElement.classList.toggle('disabled', false);}
// Little trick to call the download view after ziping has finished
let fakeBtn = document.createElement('a');
diff --git a/web/app/static/js/nopaque/main.js b/web/app/static/js/nopaque/main.js
index 4a91bd31..48e65060 100644
--- a/web/app/static/js/nopaque/main.js
+++ b/web/app/static/js/nopaque/main.js
@@ -1,9 +1,37 @@
class AppClient {
constructor(currentUserId) {
- this.socket = io({transports: ['websocket']});
- this.users = {};
- this.users.self = this.loadUser(currentUserId);
- this.users.self.eventListeners.job.addEventListener((eventType, payload) => this.jobEventHandler(eventType, payload));
+ if (currentUserId) {
+ this.socket = io({transports: ['websocket']});
+ this.users = {};
+ this.users.self = this.loadUser(currentUserId);
+ this.users.self.eventListeners.job.addEventListener((eventType, payload) => this.jobEventHandler(eventType, payload));
+ }
+ }
+
+ flash(message, category) {
+ let toast;
+ let toastCloseActionElement;
+
+ switch (category) {
+ case "corpus":
+ message = `book${message}`;
+ break;
+ case "error":
+ message = `error${message}`;
+ break;
+ case "job":
+ message = `work${message}`;
+ break;
+ default:
+ message = `notifications${message}`;
+ }
+
+ toast = M.toast({html: `${message}
+ `});
+ toastCloseActionElement = toast.el.querySelector('.toast-action[data-action="close"]');
+ toastCloseActionElement.addEventListener('click', () => {toast.dismiss();});
}
jobEventHandler(eventType, payload) {
@@ -35,7 +63,7 @@ class AppClient {
for (let operation of jobStatusPatches) {
let [match, jobId] = operation.path.match(/^\/jobs\/(\d+)\/status$/);
if (this.users.self.data.settings.job_status_site_notifications === "end" && !['complete', 'failed'].includes(operation.value)) {continue;}
- nopaque.flash(`[${this.users.self.data.jobs[jobId].title}] New status: ${operation.value}`, 'job');
+ this.flash(`[${this.users.self.data.jobs[jobId].title}] New status: ${operation.value}`, 'job');
}
}
}
@@ -150,32 +178,6 @@ class User {
*/
var nopaque = {};
-nopaque.flash = function(message, category) {
- let toast;
- let toastActionElement;
-
- switch (category) {
- case "corpus":
- message = `book${message}`;
- break;
- case "error":
- message = `error${message}`;
- break;
- case "job":
- message = `work${message}`;
- break;
- default:
- message = `notifications${message}`;
- }
-
- toast = M.toast({html: `${message}
- `});
- toastActionElement = toast.el.querySelector('.toast-action[data-action="close"]');
- toastActionElement.addEventListener('click', () => {toast.dismiss();});
-};
-
nopaque.Forms = {};
nopaque.Forms.init = function() {
var abortRequestElement, parentElement, progressElement, progressModal,
diff --git a/web/app/templates/nopaque.html.j2 b/web/app/templates/nopaque.html.j2
index f53ad189..aabdfa99 100644
--- a/web/app/templates/nopaque.html.j2
+++ b/web/app/templates/nopaque.html.j2
@@ -277,11 +277,8 @@
M.AutoInit();
M.CharacterCounter.init(document.querySelectorAll('input[data-length][type="email"], input[data-length][type="password"], input[data-length][type="text"], textarea[data-length]'));
M.Dropdown.init(document.querySelectorAll('#nav-more-dropdown-trigger'), {alignment: 'right', constrainWidth: false, coverTrigger: false});
+ nopaque.appClient = new AppClient({% if current_user.is_authenticated %}{{ current_user.id }}{% endif %});
nopaque.Forms.init();
- for (let flashedMessage of {{ get_flashed_messages(with_categories=True)|tojson }}) {nopaque.flash(flashedMessage[1], flashedMessage[0]);}
-
- {% if current_user.is_authenticated %}
- nopaque.appClient = new AppClient({{ current_user.id }});
- {% endif %}
+ for (let flashedMessage of {{ get_flashed_messages(with_categories=True)|tojson }}) {nopaque.appClient.flash(flashedMessage[1], flashedMessage[0]);}
{% endblock scripts %}