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) => { if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);} if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);} if (response.status === 409) {app.flash('Conflict', 'error'); reject(response);} app.flash(`Corpus "${corpus.title}" marked for building`, 'corpus'); resolve(response); }, (response) => { app.flash('Something went wrong', 'error'); reject(response); } ); }); } static deleteCorpusRequest(userId, corpusId) { return new Promise((resolve, reject) => { let corpus = app.data.users[userId].corpora[corpusId]; let modalElement = Utils.elementFromString( `