From 902cca66f3062d6c8c93b4bb357d0522d7937d73 Mon Sep 17 00:00:00 2001 From: Hunternif Date: Fri, 12 Apr 2019 06:06:18 +0700 Subject: Add tag input control to upload page. Fix some issues with tag input. --- client/js/controllers/post_upload_controller.js | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'client/js/controllers/post_upload_controller.js') diff --git a/client/js/controllers/post_upload_controller.js b/client/js/controllers/post_upload_controller.js index 4868042..7bdce9c 100644 --- a/client/js/controllers/post_upload_controller.js +++ b/client/js/controllers/post_upload_controller.js @@ -55,17 +55,44 @@ class PostUploadController { _evtSubmit(e) { this._view.disableForm(); this._view.clearMessages(); + const tagErrors = []; // to be displayed after all uploads e.detail.uploadables.reduce( (promise, uploadable) => promise.then(() => this._uploadSinglePost( uploadable, e.detail.skipDuplicates, e.detail.copyTagsToOriginals)), Promise.resolve()) + .then(() => { + // now save the new tags with categories + //TODO: re-use this code in post_main_controller.js + if (!e.detail.newTags) { + return Promise.resolve(); + } + let tagPromises = []; + for (let newTag of e.detail.newTags) { + // load the tag that was created during updating the post + tagPromises.push( + Tag.get(newTag.names[0]).then(tag => { + tag.category = newTag.category; + return tag.save(); + } + ).then(() => { + e.detail.newTags.removeByName(newTag.names[0]); + }, error => { + tagErrors.push(error.message); + }) + ); + } + return Promise.all(tagPromises); + }) .then(() => { this._view.clearMessages(); misc.disableExitConfirmation(); const ctx = router.show(uri.formatClientLink('posts')); ctx.controller.showSuccess('Posts uploaded.'); + for (let tagError of tagErrors) { + ctx.controller.showError(tagError); + } }, error => { if (error.uploadable) { if (error.similarPosts) { -- cgit v1.3