Refactor request for comments view

This commit is contained in:
Maximilian Grundke
2015-11-11 13:55:08 +01:00
parent be87f939c6
commit 3f0edeadf1

View File

@ -26,7 +26,6 @@ do not put a carriage return in the line below. it will be present in the presen
<% end %> <% end %>
<script type="text/javascript"> <script type="text/javascript">
//(function() {
var commentitor = $('.editor'); var commentitor = $('.editor');
var userid = commentitor.data('user-id'); var userid = commentitor.data('user-id');
@ -42,9 +41,9 @@ do not put a carriage return in the line below. it will be present in the presen
var inputHtml = '' var inputHtml = ''
inputHtml += '<div class="input-group">' inputHtml += '<div class="input-group">'
inputHtml += '<input type="text" class="form-control" id="commentInput' + fileid + '" ' inputHtml += '<input type="text" class="form-control" id="commentInput"'
inputHtml += 'placeholder="I\'d suggest a variable here" required>' inputHtml += 'placeholder="I\'d suggest a variable here" required>'
inputHtml += '<span class="input-group-btn"><button id="submitComment' + fileid + '" ' inputHtml += '<span class="input-group-btn"><button id="submitComment"'
inputHtml += 'class="btn btn-default"><%= t("exercises.implement.comment.addComment") %>!</button></span>' inputHtml += 'class="btn btn-default"><%= t("exercises.implement.comment.addComment") %>!</button></span>'
inputHtml += '</div>' inputHtml += '</div>'
@ -58,7 +57,6 @@ do not put a carriage return in the line below. it will be present in the presen
}); });
jqrequest.done(function(response){ jqrequest.done(function(response){
//data-container=".ui-front" on gutter cell
$.each(response, function(index, comment) { $.each(response, function(index, comment) {
comment.className = "code-ocean_comment" comment.className = "code-ocean_comment"
comment.text = comment.username + ": " + comment.text comment.text = comment.username + ": " + comment.text
@ -73,17 +71,18 @@ do not put a carriage return in the line below. it will be present in the presen
position: 'right', position: 'right',
trigger: 'focus click' trigger: 'focus click'
}).on('shown.bs.popover', function() { }).on('shown.bs.popover', function() {
$('#commentInput' + fileid).focus() var container = $(editor.container)
$('#submitComment' + fileid).click(_.partial(addComment, editor, fileid)); container.find('#commentInput').focus()
$('#commentInput' + fileid).data('line', $(this).text()) container.find('#submitComment').click(_.partial(addComment, editor, fileid));
container.find('#commentInput').data('line', $(this).text())
}) })
}) })
} }
function addComment(editor, fileid) { function addComment(editor, fileid) {
var commentInput = $('#commentInput' + fileid); var commentInput = $(editor.container).find('#commentInput');
var comment = commentInput.val() var comment = commentInput.val()
var line = $('#commentInput' + fileid).data('line') var line = commentInput.data('line')
if (line == '' || comment == '') { if (line == '' || comment == '') {
return return
@ -108,7 +107,6 @@ do not put a carriage return in the line below. it will be present in the presen
$('.ace_gutter-cell').popover('hide') $('.ace_gutter-cell').popover('hide')
} }
//})()
</script> </script>
<style> <style>
#commentitor, .ace_gutter, .ace_gutter-layer { overflow: visible } #commentitor, .ace_gutter, .ace_gutter-layer { overflow: visible }