diff options
| author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-12-27 14:25:03 +0200 |
|---|---|---|
| committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-12-27 14:25:03 +0200 |
| commit | 00056c82f20ce900cec9b9fd17e3950e80fbb693 (patch) | |
| tree | 06cde60ca5273a1e9a72bf01d9ad3848517abd15 /app/assets/javascripts | |
| parent | 32c7310f4a2ba8b408f0dd0cc17eba9b92159817 (diff) | |
| download | gitlab-ce-00056c82f20ce900cec9b9fd17e3950e80fbb693.tar.gz | |
Update votes ferom comments dynamically
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/assets/javascripts')
| -rw-r--r-- | app/assets/javascripts/notes.js.coffee | 4 | ||||
| -rw-r--r-- | app/assets/javascripts/notes_votes.js.coffee | 22 |
2 files changed, 26 insertions, 0 deletions
diff --git a/app/assets/javascripts/notes.js.coffee b/app/assets/javascripts/notes.js.coffee index d13fc439fa4..6501cf38a89 100644 --- a/app/assets/javascripts/notes.js.coffee +++ b/app/assets/javascripts/notes.js.coffee @@ -232,6 +232,7 @@ class Notes ### addNote: (xhr, note, status) => @renderNote(note) + @updateVotes() ### Called in response to the new note form being submitted @@ -425,4 +426,7 @@ class Notes form = $(e.target).closest(".js-discussion-note-form") @removeDiscussionNoteForm(form) + updateVotes: -> + (new NotesVotes).updateVotes() + @Notes = Notes diff --git a/app/assets/javascripts/notes_votes.js.coffee b/app/assets/javascripts/notes_votes.js.coffee new file mode 100644 index 00000000000..b31eb9ac9de --- /dev/null +++ b/app/assets/javascripts/notes_votes.js.coffee @@ -0,0 +1,22 @@ +class NotesVotes + updateVotes: -> + votes = $("#votes .votes") + notes = $("#notes-list .note .vote") + + # only update if there is a vote display + if votes.size() + upvotes = notes.filter(".upvote").size() + downvotes = notes.filter(".downvote").size() + votesCount = upvotes + downvotes + upvotesPercent = (if votesCount then (100.0 / votesCount * upvotes) else 0) + downvotesPercent = (if votesCount then (100.0 - upvotesPercent) else 0) + + # change vote bar lengths + votes.find(".bar-success").css "width", upvotesPercent + "%" + votes.find(".bar-danger").css "width", downvotesPercent + "%" + + # replace vote numbers + votes.find(".upvotes").text votes.find(".upvotes").text().replace(/\d+/, upvotes) + votes.find(".downvotes").text votes.find(".downvotes").text().replace(/\d+/, downvotes) + +@NotesVotes = NotesVotes |
