From 78cddb93ccab280b0dd5b0bd31c95825404093d7 Mon Sep 17 00:00:00 2001 From: hylom Date: Fri, 17 Mar 2017 20:25:22 +0900 Subject: [PATCH] js: fix comments.js to reduce vue.js warnings --- src/newslash_web/public/js/comments.js | 49 +++++++++++----------- .../templates/comment/comments.html.tt2 | 24 +++++------ 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/newslash_web/public/js/comments.js b/src/newslash_web/public/js/comments.js index fb8c25cb..0a1a1884 100644 --- a/src/newslash_web/public/js/comments.js +++ b/src/newslash_web/public/js/comments.js @@ -7,6 +7,7 @@ Vue.component('comment', { data: function () { return { moderateReason: 0, + moderateMessage: '', metamoderateMessage: '', displayModInfo: 0, loadingMods: 1, @@ -23,7 +24,7 @@ Vue.component('comment', { return typeof mod.m2val == 'undefined' ? 1 : 0; }, reasonToText: function (reason) { - return vm.modReasons[reason]; + return this.modReasons[reason]; }, showModInfo: function () { this.loadingMods = 1; @@ -32,7 +33,7 @@ Vue.component('comment', { return; } // get moderation data - this.$http.get(vm.urls.moderate + "?cid=" + this.comment.cid).then( + this.$http.get(this.urls.moderate + "?cid=" + this.comment.cid).then( (response) => { // success if (response.body.sec_token) { this.secToken = response.body.sec_token; @@ -61,12 +62,12 @@ Vue.component('comment', { moderate: function () { var data = { reason: Number(this.moderateReason), - discussion_id: Number(vm.discussion_id), + discussion_id: Number(this.discussion_id), cid: Number(this.comment.cid), action: 'moderate', }; this.loadingMods = 1; - this.$http.post(vm.urls.moderate, data).then( + this.$http.post(this.urls.moderate, data).then( (response) => { // success this.moderateMessage = "保存しました"; }, @@ -90,7 +91,7 @@ Vue.component('comment', { sec_token: this.secToken, }; mod.status = 'm2saving'; - this.$http.post(vm.urls.metamoderate, data).then( + this.$http.post(this.urls.metamoderate, data).then( (response) => { // success mod.status = 'm2saved'; mod.m2val = value; @@ -106,7 +107,7 @@ Vue.component('comment', { }, computed: { m2able: function () { - return vm.user.login; + return this.user.login; }, signedPoints: function () { if (this.comment.points < 0) { @@ -136,7 +137,7 @@ Vue.component('comment', { return 0; } // 子アイテムの少なくとも1つが表示なら -> 「1件の非表示コメント」表示 - const count = vm.countHiddenItems(this.comment); + const count = this.countHiddenItems(this.comment); if (count[0] != count [1]) { return 1; } @@ -148,7 +149,7 @@ Vue.component('comment', { return 0; } // 子アイテムの少なくとも1つが表示なら -> 「1件の非表示コメント」表示 - const count = vm.countHiddenItems(this.comment); + const count = this.countHiddenItems(this.comment); if (count[0] != count [1]) { return 1; } @@ -156,10 +157,10 @@ Vue.component('comment', { return count[0]; }, enableModerate: function () { - return vm.user.admin || (vm.user.moderator && !vm.archived); + return vm.user.admin || (this.user.moderator && !this.archived); }, enableReply: function () { - return !vm.archived; + return !this.archived; }, showSignature: function () { return !vm.userConfig.hide_signature; @@ -187,12 +188,12 @@ Vue.component('comment-form', { const data = { title: reply.rawTitle, comment: reply.rawComment, - discussion_id: vm.discussion_id, - stoid: vm.stoid, + discussion_id: this.discussion_id, + stoid: this.stoid, pid: reply.pid, action: 'preview', } - this.$http.post(vm.urls.commentPost, data).then( + this.$http.post(this.urls.commentPost, data).then( (response) => { // success reply.subject = response.body.title; reply.comment = response.body.comment; @@ -217,12 +218,12 @@ Vue.component('comment-form', { const data = { title: reply.rawTitle, comment: reply.rawComment, - discussion_id: vm.discussion_id, - stoid: vm.stoid, + discussion_id: this.discussion_id, + stoid: this.stoid, pid: reply.pid, action: 'post', } - this.$http.post(vm.urls.commentPost, data).then( + this.$http.post(this.urls.commentPost, data).then( (response) => { // success const newComment = response.body.new_comment; comments.initComment(newComment, this.reply.parent); @@ -232,7 +233,7 @@ Vue.component('comment-form', { if (children) { reply.parent.children.unshift(newComment); } else { - vm.comments.push(newComment); + this.comments.push(newComment); } }, (response) => { // fail @@ -266,7 +267,6 @@ comments.blankReply = function blankReply () { comments.initComment = function initComment (comment, params) { //comment.archived = params.archived; comment.children = []; - comment.reply = this.blankReply(); comment.reply.parent = comment; comment.reply.rawTitle = 'Re:' + comment.subject; @@ -322,11 +322,11 @@ comments.run = function run (params) { } var result = [1, 0]; for (var i = 0; i < comment.children.length; i++) { - var ret = vm.countHiddenItems(comment.children[i]); + var ret = this.countHiddenItems(comment.children[i]); result[0] += ret[0]; result[1] += ret[1]; } - if (comment.points < vm.userConfig.show_threshold) { + if (comment.points < this.userConfig.show_threshold) { result[1]++; } return result; @@ -334,19 +334,20 @@ comments.run = function run (params) { saveConfig: function saveConfig () { const data = { type: "config", - config: vm.$data.userConfig, + config: this.$data.userConfig, }; - this.$http.post(vm.urls.configSave, data).then( + this.$http.post(this.urls.configSave, data).then( (response) => { // success - vm.configMessage = "保存しました"; + this.configMessage = "保存しました"; }, (response) => { // fail - vm.configMessage = "エラー"; + this.configMessage = "エラー"; } ); }, }; const getUrl = "/api/v1/comment?discussion_id=" + data.discussion_id; + vm = new Vue({el: params.el, data: data, computed: computed, diff --git a/src/newslash_web/templates/comment/comments.html.tt2 b/src/newslash_web/templates/comment/comments.html.tt2 index 45651ed5..0eed0a4a 100644 --- a/src/newslash_web/templates/comment/comments.html.tt2 +++ b/src/newslash_web/templates/comment/comments.html.tt2 @@ -1,3 +1,14 @@ +
+ [%- INCLUDE comment/comment_header -%] +
    +
  1. + + +
  2. + +
+
+ @@ -18,19 +29,8 @@ -
- [%- INCLUDE comment/comment_header -%] -
    -
  1. - - -
  2. - -
- -
- +