Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
6aebb76b
Commit
6aebb76b
authored
Sep 15, 2012
by
Riyad Preukschas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update votes when creating or refreshing notes
parent
b8113334
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
3 deletions
+40
-3
app/assets/javascripts/notes.js
app/assets/javascripts/notes.js
+40
-3
No files found.
app/assets/javascripts/notes.js
View file @
6aebb76b
...
@@ -21,15 +21,18 @@ var NoteList = {
...
@@ -21,15 +21,18 @@ var NoteList = {
this
.
getContent
();
this
.
getContent
();
$
(
"
#notes-list, #new-notes-list
"
).
on
(
"
ajax:success
"
,
"
.delete-note
"
,
function
()
{
$
(
"
#notes-list, #new-notes-list
"
).
on
(
"
ajax:success
"
,
"
.delete-note
"
,
function
()
{
$
(
this
).
closest
(
'
li
'
).
fadeOut
();
$
(
this
).
closest
(
'
li
'
).
fadeOut
(
function
()
{
$
(
this
).
remove
();
NoteList
.
updateVotes
();
});
});
});
$
(
"
.note-form-holder
"
).
on
(
"
ajax:before
"
,
function
(){
$
(
"
.note-form-holder
"
).
on
(
"
ajax:before
"
,
function
(){
$
(
"
.submit_note
"
).
disable
()
$
(
"
.submit_note
"
).
disable
()
;
})
})
$
(
"
.note-form-holder
"
).
on
(
"
ajax:complete
"
,
function
(){
$
(
"
.note-form-holder
"
).
on
(
"
ajax:complete
"
,
function
(){
$
(
"
.submit_note
"
).
enable
()
$
(
"
.submit_note
"
).
enable
()
;
})
})
disableButtonIfEmptyField
(
"
.note-text
"
,
"
.submit_note
"
);
disableButtonIfEmptyField
(
"
.note-text
"
,
"
.submit_note
"
);
...
@@ -154,6 +157,8 @@ var NoteList = {
...
@@ -154,6 +157,8 @@ var NoteList = {
if
(
!
this
.
reversed
)
{
if
(
!
this
.
reversed
)
{
this
.
initRefreshNew
();
this
.
initRefreshNew
();
}
}
// make sure we are up to date
this
.
updateVotes
();
},
},
...
@@ -193,6 +198,7 @@ var NoteList = {
...
@@ -193,6 +198,7 @@ var NoteList = {
replaceNewNotes
:
replaceNewNotes
:
function
(
html
)
{
function
(
html
)
{
$
(
"
#new-notes-list
"
).
html
(
html
);
$
(
"
#new-notes-list
"
).
html
(
html
);
this
.
updateVotes
();
},
},
/**
/**
...
@@ -205,6 +211,37 @@ var NoteList = {
...
@@ -205,6 +211,37 @@ var NoteList = {
}
else
{
}
else
{
$
(
"
#new-notes-list
"
).
append
(
html
);
$
(
"
#new-notes-list
"
).
append
(
html
);
}
}
this
.
updateVotes
();
},
/**
* Recalculates the votes and updates them (if they are displayed at all).
*
* Assumes all relevant notes are displayed (i.e. there are no more notes to
* load via getMore()).
* Might produce inaccurate results when not all notes have been loaded and a
* recalculation is triggered (e.g. when deleting a note).
*/
updateVotes
:
function
()
{
var
votes
=
$
(
"
#votes .votes
"
);
var
notes
=
$
(
"
#notes-list, #new-notes-list
"
).
find
(
"
.note.vote
"
);
// only update if there is a vote display
if
(
votes
.
size
())
{
var
upvotes
=
notes
.
filter
(
"
.upvote
"
).
size
();
var
downvotes
=
notes
.
filter
(
"
.downvote
"
).
size
();
var
votesCount
=
upvotes
+
downvotes
;
var
upvotesPercent
=
votesCount
?
(
100.0
/
votesCount
*
upvotes
)
:
0
;
var
downvotesPercent
=
votesCount
?
(
100.0
-
upvotesPercent
)
:
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
));
}
}
}
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment