diff --git a/controllers/forms/makepost.js b/controllers/forms/makepost.js index 43e80716..2188dbf3 100644 --- a/controllers/forms/makepost.js +++ b/controllers/forms/makepost.js @@ -21,7 +21,7 @@ module.exports = async (req, res, next) => { const errors = []; // even if force file and message are off, the post must contain one of either. - if (!req.body.message && res.locals.numFiles === 0) { + if ((!req.body.message || req.body.message.length === 0) && res.locals.numFiles === 0) { errors.push('Posts must include a message or file'); } diff --git a/gulp/res/js/captcha.js b/gulp/res/js/captcha.js index 463807c3..ae1c62a4 100644 --- a/gulp/res/js/captcha.js +++ b/gulp/res/js/captcha.js @@ -1,3 +1,4 @@ + window.addEventListener('DOMContentLoaded', (event) => { const captchaFields = document.getElementsByClassName('captchafield'); @@ -16,7 +17,7 @@ window.addEventListener('DOMContentLoaded', (event) => { } xhr.open('GET', '/captcha', true); xhr.send(null); - } + }; const loadCaptcha = function(e) { const captchaDiv = this.previousSibling; diff --git a/gulp/res/js/live.js b/gulp/res/js/live.js index f305b0ac..4f1500b8 100644 --- a/gulp/res/js/live.js +++ b/gulp/res/js/live.js @@ -19,7 +19,7 @@ window.addEventListener('DOMContentLoaded', (event) => { console.log('got new post'); const postData = data; //create a new post - const postHtml = post({post: postData}); + const postHtml = post({ post: postData }); //add it to the end of the thread thread.insertAdjacentHTML('beforeend', postHtml); for (let j = 0; j < postData.quotes.length; j++) { diff --git a/gulp/res/js/modal.js b/gulp/res/js/modal.js index 96034cab..7657b5fb 100644 --- a/gulp/res/js/modal.js +++ b/gulp/res/js/modal.js @@ -1,17 +1,17 @@ function pug_escape(e){var a=""+e,t=pug_match_html.exec(a);if(!t)return e;var r,c,n,s="";for(r=t.index,c=0;r]/;function modal(locals) {var pug_html = "", pug_mixins = {}, pug_interp;;var locals_for_with = (locals || {});(function (error, errors, message, messages, title) {pug_html = pug_html + "\u003Cdiv class=\"modal-bg\"\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"modal\"\u003E\u003Cdiv class=\"row\"\u003E\u003Cp class=\"bold\"\u003E" + (pug_escape(null == (pug_interp = title) ? "" : pug_interp)) + "\u003C\u002Fp\u003E\u003Ca class=\"close postform-style\" id=\"modalclose\"\u003EX\u003C\u002Fa\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cul class=\"nomarks\"\u003E"; -if (message) { -pug_html = pug_html + "\u003Cli\u003E" + (pug_escape(null == (pug_interp = message) ? "" : pug_interp)) + "\u003C\u002Fli\u003E"; +var pug_match_html=/["&<>]/;function modal(locals) {var pug_html = "", pug_mixins = {}, pug_interp;;var locals_for_with = (locals || {});(function (errors, messages, modal) {pug_mixins["modal"] = pug_interp = function(data){ +var block = (this && this.block), attributes = (this && this.attributes) || {}; +pug_html = pug_html + "\u003Cdiv class=\"modal-bg\"\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"modal\"\u003E\u003Cdiv class=\"row\"\u003E\u003Cp class=\"bold\"\u003E" + (pug_escape(null == (pug_interp = data.title) ? "" : pug_interp)) + "\u003C\u002Fp\u003E\u003Ca class=\"close postform-style\" id=\"modalclose\"\u003EX\u003C\u002Fa\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cul class=\"nomarks\"\u003E"; +if (data.message) { +pug_html = pug_html + "\u003Cli\u003E" + (pug_escape(null == (pug_interp = data.message) ? "" : pug_interp)) + "\u003C\u002Fli\u003E"; } -else -if (error) { -pug_html = pug_html + "\u003Cli\u003E" + (pug_escape(null == (pug_interp = error) ? "" : pug_interp)) + "\u003C\u002Fli\u003E"; +if (data.error) { +pug_html = pug_html + "\u003Cli\u003E" + (pug_escape(null == (pug_interp = data.error) ? "" : pug_interp)) + "\u003C\u002Fli\u003E"; } -else if (messages) { -// iterate messages +// iterate data.messages ;(function(){ - var $$obj = messages; + var $$obj = data.messages; if ('number' == typeof $$obj.length) { for (var pug_index0 = 0, $$l = $$obj.length; pug_index0 < $$l; pug_index0++) { var msg = $$obj[pug_index0]; @@ -28,25 +28,26 @@ pug_html = pug_html + "\u003Cli\u003E" + (pug_escape(null == (pug_interp = msg) }).call(this); } -else if (errors) { -// iterate errors +// iterate data.errors ;(function(){ - var $$obj = errors; + var $$obj = data.errors; if ('number' == typeof $$obj.length) { for (var pug_index1 = 0, $$l = $$obj.length; pug_index1 < $$l; pug_index1++) { - var err = $$obj[pug_index1]; -pug_html = pug_html + "\u003Cli\u003E" + (pug_escape(null == (pug_interp = err) ? "" : pug_interp)) + "\u003C\u002Fli\u003E"; + var error = $$obj[pug_index1]; +pug_html = pug_html + "\u003Cli\u003E" + (pug_escape(null == (pug_interp = error) ? "" : pug_interp)) + "\u003C\u002Fli\u003E"; } } else { var $$l = 0; for (var pug_index1 in $$obj) { $$l++; - var err = $$obj[pug_index1]; -pug_html = pug_html + "\u003Cli\u003E" + (pug_escape(null == (pug_interp = err) ? "" : pug_interp)) + "\u003C\u002Fli\u003E"; + var error = $$obj[pug_index1]; +pug_html = pug_html + "\u003Cli\u003E" + (pug_escape(null == (pug_interp = error) ? "" : pug_interp)) + "\u003C\u002Fli\u003E"; } } }).call(this); } -pug_html = pug_html + "\u003C\u002Ful\u003E\u003C\u002Fdiv\u003E\u003C\u002Fdiv\u003E";}.call(this,"error" in locals_for_with?locals_for_with.error:typeof error!=="undefined"?error:undefined,"errors" in locals_for_with?locals_for_with.errors:typeof errors!=="undefined"?errors:undefined,"message" in locals_for_with?locals_for_with.message:typeof message!=="undefined"?message:undefined,"messages" in locals_for_with?locals_for_with.messages:typeof messages!=="undefined"?messages:undefined,"title" in locals_for_with?locals_for_with.title:typeof title!=="undefined"?title:undefined));;return pug_html;} \ No newline at end of file +pug_html = pug_html + "\u003C\u002Ful\u003E\u003C\u002Fdiv\u003E\u003C\u002Fdiv\u003E"; +}; +pug_mixins["modal"](modal);}.call(this,"errors" in locals_for_with?locals_for_with.errors:typeof errors!=="undefined"?errors:undefined,"messages" in locals_for_with?locals_for_with.messages:typeof messages!=="undefined"?messages:undefined,"modal" in locals_for_with?locals_for_with.modal:typeof modal!=="undefined"?modal:undefined));;return pug_html;} \ No newline at end of file diff --git a/gulp/res/js/progress.js b/gulp/res/js/progress.js index 9906b95b..79a0eddf 100644 --- a/gulp/res/js/progress.js +++ b/gulp/res/js/progress.js @@ -39,11 +39,15 @@ window.addEventListener('DOMContentLoaded', () => { window.location.hash = json.postId; } form.reset(); //reset form on success + if (form.getElementsByTagName('img').length > 0) { + //TODO: refresh captcha here + } } else { //not 200 status, so some error/failed post, wrong captcha, etc if (json) { + console.log(json); //show modal when possible - const modalHtml = modal(json); + const modalHtml = modal({ modal: json }); document.body.insertAdjacentHTML('afterbegin', modalHtml); document.getElementById('modalclose').onclick = () => { document.getElementsByClassName('modal')[0].remove(); diff --git a/gulpfile.js b/gulpfile.js index f3723ef3..db2d76d1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -148,7 +148,7 @@ function scripts() { } gulp.src(`${paths.scripts.src}/*.js`) .pipe(concat('all.js')) -// .pipe(uglify()) + .pipe(uglify()) .pipe(gulp.dest(paths.scripts.dest)); return gulp.src(`${paths.scripts.src}/*.js`) .pipe(uglify()) diff --git a/helpers/dynamic.js b/helpers/dynamic.js index f43d0d65..dfaddd5b 100644 --- a/helpers/dynamic.js +++ b/helpers/dynamic.js @@ -3,6 +3,12 @@ module.exports = (req, res, code, page, data) => { res.status(code); if (req.headers['x-using-xhr'] != null) { + if (data.messages) { + data.message = data.messages.join('\n'); + } + if (data.errors) { + data.message = data.errors.join('\n'); + } return res.json(data); } else { return res.render(page, data); diff --git a/views/includes/modal.pug b/views/includes/modal.pug index 94cc333a..7d0c16f9 100644 --- a/views/includes/modal.pug +++ b/views/includes/modal.pug @@ -1,17 +1,2 @@ -.modal-bg -.modal - .row - p.bold #{title} - a.close.postform-style#modalclose X - .row - ul.nomarks - if message - li #{message} - else if error - li #{error} - else if messages - each msg in messages - li #{msg} - else if errors - each err in errors - li #{err} +include ../mixins/modal.pug ++modal(modal) diff --git a/views/mixins/modal.pug b/views/mixins/modal.pug new file mode 100644 index 00000000..0b08ed8c --- /dev/null +++ b/views/mixins/modal.pug @@ -0,0 +1,19 @@ +mixin modal(data) + .modal-bg + .modal + .row + p.bold #{data.title} + a.close.postform-style#modalclose X + .row + ul.nomarks + if data.message + li #{data.message} + if data.error + li #{data.error} + if messages + each msg in data.messages + li #{msg} + if errors + each error in data.errors + li #{error} +