class Utils { static elementFromString(string) { let tmpElement = document.createElement('div'); tmpElement.innerHTML = string.trim(); return tmpElement.firstChild; } static buildCorpusRequest(userId, corpusId) { return new Promise((resolve, reject) => { let corpus = app.data.users[userId].corpora[corpusId]; fetch(`/corpora/${corpus.id}/build`, {method: 'POST', headers: {Accept: 'application/json'}}) .then( (response) => { app.flash(`Corpus "${corpus.title}" marked for building`, 'corpus'); resolve(response); }, (response) => { if (response.status === 403) {app.flash('Forbidden', 'error');} if (response.status === 404) {app.flash('Not Found', 'error');} if (response.status === 409) {app.flash('Conflict', 'error');} reject(response); } ); }); } static deleteCorpusRequest(userId, corpusId) { return new Promise((resolve, reject) => { let corpus = app.data.users[userId].corpora[corpusId]; let modalElement = Utils.elementFromString( `