From ac98b7d8e62d00d29ca457ba450ea640f0c77440 Mon Sep 17 00:00:00 2001 From: rr- Date: Tue, 3 Jan 2017 22:04:01 +0100 Subject: [PATCH] client/posts: fix merge could be used only once --- .../js/controllers/post_detail_controller.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/client/js/controllers/post_detail_controller.js b/client/js/controllers/post_detail_controller.js index 8b64aee1..9ad422e6 100644 --- a/client/js/controllers/post_detail_controller.js +++ b/client/js/controllers/post_detail_controller.js @@ -18,14 +18,7 @@ class PostDetailController extends BasePostController { this._id = ctx.parameters.id; post.addEventListener('change', e => this._evtSaved(e, section)); - this._view = new PostDetailView({ - post: post, - section: section, - canMerge: api.hasPrivilege('posts:merge'), - }); - - this._view.addEventListener('select', e => this._evtSelect(e)); - this._view.addEventListener('merge', e => this._evtMerge(e)); + this._installView(post, section); }, errorMessage => { this._view = new EmptyView(); this._view.showError(errorMessage); @@ -36,6 +29,17 @@ class PostDetailController extends BasePostController { this._view.showSuccess(message); } + _installView(post, section) { + this._view = new PostDetailView({ + post: post, + section: section, + canMerge: api.hasPrivilege('posts:merge'), + }); + + this._view.addEventListener('select', e => this._evtSelect(e)); + this._view.addEventListener('merge', e => this._evtMerge(e)); + } + _evtSelect(e) { this._view.clearMessages(); this._view.disableForm(); @@ -61,11 +65,7 @@ class PostDetailController extends BasePostController { this._view.disableForm(); e.detail.post.merge(e.detail.targetPost.id, e.detail.useOldContent) .then(() => { - this._view = new PostDetailView({ - post: e.detail.targetPost, - section: 'merge', - canMerge: api.hasPrivilege('posts:merge'), - }); + this._installView(e.detail.post, 'merge'); this._view.showSuccess('Post merged.'); router.replace( '/post/' + e.detail.targetPost.id + '/merge', null, false);