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
cee230a1
Commit
cee230a1
authored
Sep 14, 2012
by
Riyad Preukschas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update JS for adding and removing diff line notes
parent
653f7ec4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
8 deletions
+48
-8
app/assets/javascripts/note.js
app/assets/javascripts/note.js
+33
-4
app/views/notes/_create_line.js.haml
app/views/notes/_create_line.js.haml
+15
-4
No files found.
app/assets/javascripts/note.js
View file @
cee230a1
...
@@ -17,8 +17,9 @@ var NoteList = {
...
@@ -17,8 +17,9 @@ var NoteList = {
// get initial set of notes
// get initial set of notes
this
.
getContent
();
this
.
getContent
();
$
(
'
.delete-note
'
).
live
(
'
ajax:success
'
,
function
()
{
$
(
"
#notes-list, #new-notes-list
"
).
on
(
"
ajax:success
"
,
"
.delete-note
"
,
function
()
{
$
(
this
).
closest
(
'
li
'
).
fadeOut
();
});
$
(
this
).
closest
(
'
li
'
).
fadeOut
();
});
$
(
"
.note-form-holder
"
).
on
(
"
ajax:before
"
,
function
(){
$
(
"
.note-form-holder
"
).
on
(
"
ajax:before
"
,
function
(){
$
(
"
.submit_note
"
).
disable
()
$
(
"
.submit_note
"
).
disable
()
...
@@ -197,13 +198,41 @@ var NoteList = {
...
@@ -197,13 +198,41 @@ var NoteList = {
var
PerLineNotes
=
{
var
PerLineNotes
=
{
init
:
init
:
function
()
{
function
()
{
$
(
"
.line_note_link, .line_note_reply_link
"
).
on
(
"
click
"
,
function
(
e
)
{
/**
* Called when clicking on the "add note" or "reply" button for a diff line.
*
* Shows the note form below the line.
* Sets some hidden fields in the form.
*/
$
(
"
.diff_file_content
"
).
on
(
"
click
"
,
"
.line_note_link, .line_note_reply_link
"
,
function
(
e
)
{
var
form
=
$
(
"
.per_line_form
"
);
var
form
=
$
(
"
.per_line_form
"
);
$
(
this
).
closest
(
"
tr
"
).
after
(
form
);
$
(
this
).
closest
(
"
tr
"
).
after
(
form
);
form
.
find
(
"
#note_line_code
"
).
val
(
$
(
this
).
attr
(
"
line_c
ode
"
));
form
.
find
(
"
#note_line_code
"
).
val
(
$
(
this
).
data
(
"
lineC
ode
"
));
form
.
show
();
form
.
show
();
return
false
;
return
false
;
});
});
disableButtonIfEmptyField
(
"
.line-note-text
"
,
"
.submit_inline_note
"
);
disableButtonIfEmptyField
(
"
.line-note-text
"
,
"
.submit_inline_note
"
);
/**
* Called in response to successfully deleting a note on a diff line.
*
* Removes the actual note from view.
* Removes the reply button if the last note for that line has been removed.
*/
$
(
"
.diff_file_content
"
).
on
(
"
ajax:success
"
,
"
.delete-note
"
,
function
()
{
var
trNote
=
$
(
this
).
closest
(
"
tr
"
);
trNote
.
fadeOut
(
function
()
{
$
(
this
).
remove
();
});
// check if this is the last note for this line
// elements must really be removed for this to work reliably
var
trLine
=
trNote
.
prev
();
var
trRpl
=
trNote
.
next
();
if
(
trLine
.
hasClass
(
"
line_holder
"
)
&&
trRpl
.
hasClass
(
"
reply
"
))
{
trRpl
.
fadeOut
(
function
()
{
$
(
this
).
remove
();
});
}
});
}
}
}
}
app/views/notes/_create_line.js.haml
View file @
cee230a1
-
if
note
.
valid?
-
if
note
.
valid?
:plain
:plain
// hide and reset the form
$(".per_line_form").hide();
$(".per_line_form").hide();
$('.line-note-form-holder textarea').val("");
$('.line-note-form-holder textarea').val("");
$("a.line_note_reply_link[line_code='
#{
note
.
line_code
}
']").closest("tr").remove();
// find the reply button for this line
// (might not be there if this is the first note)
var trRpl = $("a.line_note_reply_link[data-line-code='
#{
note
.
line_code
}
']").closest("tr");
if (trRpl.size() == 0) {
// find the commented line ...
var trEl = $(".
#{
note
.
line_code
}
").parent();
var trEl = $(".
#{
note
.
line_code
}
").parent();
trEl.after("
#{
escape_javascript
(
render
partial:
"notes/per_line_show"
,
locals:
{
note:
note
})
}
");
// ... and insert the note and the reply button after it
trEl.after("
#{
escape_javascript
(
render
partial:
"notes/reply_button"
,
locals:
{
line_code:
note
.
line_code
})
}
");
trEl.after("
#{
escape_javascript
(
render
"notes/reply_button"
,
line_code:
note
.
line_code
)
}
");
trEl.after("
#{
escape_javascript
(
render
"notes/per_line_show"
,
note:
note
)
}
");
} else {
// instert new note before reply button
trRpl.before("
#{
escape_javascript
(
render
"notes/per_line_show"
,
note:
note
)
}
");
}
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