Merge branch 'master' of github.com:fatchan/jschan

merge-requests/208/head
fatchan 5 years ago
commit 9b0a2d492f
  1. 6
      gulp/res/js/forms.js
  2. 13
      models/forms/uploadbanners.js

@ -123,7 +123,7 @@ class formHandler {
} }
} }
this.form.reset(); this.form.reset();
this.messageBox.dispatchEvent(new Event('input')); this.updateMessageBox();
this.files = []; this.files = [];
this.updateFilesText(); this.updateFilesText();
const captcha = this.form.querySelector('img'); const captcha = this.form.querySelector('img');
@ -163,6 +163,10 @@ class formHandler {
xhr.send(postData); xhr.send(postData);
} }
updateMessageBox() {
this.messageBox && this.messageBox.dispatchEvent(new Event('input'));
}
//remove a single file, unused atm //remove a single file, unused atm
removeFile(index) { removeFile(index) {
const childNode = this.fileLabel.childNodes[index+1]; //+1 because first one is fileLabelText const childNode = this.fileLabel.childNodes[index+1]; //+1 because first one is fileLabelText

@ -71,10 +71,19 @@ module.exports = async (req, res, next) => {
deleteTempFiles(req).catch(e => console.error); deleteTempFiles(req).catch(e => console.error);
// no new banners
if (filenames.length === 0) {
return dynamicResponse(req, res, 400, 'message', {
'title': 'Bad request',
'message': `Banner${res.locals.numFiles > 1 ? 's' : ''} already exist${res.locals.numFiles > 1 ? '' : 's'}`,
'redirect': redirect
});
}
// add banners to the db // add banners to the db
await Boards.addBanners(req.params.board, filenames); await Boards.addBanners(req.params.board, filenames);
//add banners to board in memory // add banners to board in memory
res.locals.board.banners = res.locals.board.banners.concat(filenames); res.locals.board.banners = res.locals.board.banners.concat(filenames);
if (filenames.length > 0) { if (filenames.length > 0) {
@ -87,7 +96,7 @@ module.exports = async (req, res, next) => {
}); });
} }
return res.render('message', { return dynamicResponse(req, res, 200, 'message', {
'title': 'Success', 'title': 'Success',
'message': `Uploaded ${filenames.length} new banners.`, 'message': `Uploaded ${filenames.length} new banners.`,
'redirect': redirect 'redirect': redirect

Loading…
Cancel
Save