Fix creating a comment in Firefox; add flash-messages

This commit is contained in:
Alexander Machehin 2015-04-10 16:50:14 +05:00
parent f89e73ea0e
commit 22cec1be6e
6 changed files with 51 additions and 22 deletions

View File

@ -75,15 +75,22 @@ CommentsController = (Comment, Preview, confirmMessage, $scope, compileHTML, $ro
else
false
vm.add = ->
vm.add = ($event)->
$event.preventDefault()
$event.stopPropagation()
vm.processing = true
promise = Comment.add(vm.project, vm.commentable, vm.new_body)
promise.then (response) ->
element = compileHTML.run($scope, response.data.html)
Comment.add(vm.project, vm.commentable, vm.new_body)
.success (data) ->
element = compileHTML.run($scope, data.html)
list.append(element)
vm.new_body = ''
location.hash = "#comment" + response.data.id;
location.hash = "#comment" + data.id;
vm.processing = false
$.notify(data.message, 'success')
.error (data) ->
$.notify(data.message, 'error')
vm.processing = false
false
@ -91,8 +98,8 @@ CommentsController = (Comment, Preview, confirmMessage, $scope, compileHTML, $ro
vm.remove = (id) ->
return false unless confirmMessage.show()
vm.processing = true
promise = Comment.remove(vm.project, vm.commentable, id)
promise.then () ->
Comment.remove(vm.project, vm.commentable, id)
.success (data)->
parent = $('#comment'+id+',#diff-comment'+id).parents('tr.line-comments')
if parent.find('.line-comment').length is 1
# there is only one line comment, remove all line
@ -100,16 +107,21 @@ CommentsController = (Comment, Preview, confirmMessage, $scope, compileHTML, $ro
else
$('#comment'+id+',#diff-comment'+id+',#update-comment'+id).remove()
$.notify(data.message, 'success')
vm.processing = false
.error (data)->
$.notify(data.message, 'error')
vm.processing = false
false
vm.update = (id) ->
vm.processing = true
promise = Comment.update(vm.project, vm.commentable, id)
promise.then (response) ->
form = $('#comment'+id+ ' .md_and_cm.cm-s-default').html(response.data.body)
Comment.update(vm.project, vm.commentable, id)
.success (data) ->
form = $('#comment'+id+ ' .md_and_cm.cm-s-default').html(data.body)
$.notify(data.message, 'success')
vm.processing = false
form = $('.open-comment.comment-'+id)
if form.length is 1
@ -117,6 +129,9 @@ CommentsController = (Comment, Preview, confirmMessage, $scope, compileHTML, $ro
return true
else
return false
.error (data) ->
$.notify(data.message, 'error')
vm.processing = false
vm.showInlineForm = ($event, params = {}) ->
line_comments = findInlineComments($event, params)

View File

@ -12,14 +12,14 @@ class Projects::CommentsController < Projects::BaseController
if !@comment.set_additional_data params
format.json {
render json: {
error: I18n.t("flash.comment.save_error"),
message: @comment.errors.full_messages
message: I18n.t("flash.comment.save_error"),
error: @comment.errors.full_messages
}
}
elsif @comment.save
format.json {}
else
format.json { render json: { error: I18n.t("flash.comment.save_error") }, status: 422 }
format.json { render json: { message: I18n.t("flash.comment.save_error") }, status: 422 }
end
end
end
@ -28,17 +28,24 @@ class Projects::CommentsController < Projects::BaseController
end
def update
status, message = if @comment.update_attributes(params[:comment])
[200, view_context.markdown(@comment.body)]
else
[422, 'error']
respond_to do |format|
if @comment.update_attributes(params[:comment])
format.json { render json: {message:t('flash.comment.updated'), body: view_context.markdown(@comment.body)} }
else
format.json { render json: {message:t('flash.comment.error_in_updating')}, status: 422 }
end
end
render json: {body: message}, status: status
end
def destroy
@comment.destroy
render json: nil
respond_to do |format|
if @comment.present? && @comment.destroy
format.json { render json: {message: I18n.t('flash.comment.destroyed')} }
else
format.json {
render json: {message: t('flash.comment.error_in_deleting')}, status: 422 }
end
end
end
protected

View File

@ -13,7 +13,7 @@ h3
ang_model: 'new_body'
hr
button.btn.btn-primary[ ng-disabled = 'commentsCtrl.isDisabledNewCommentButton()'
ng-click = 'commentsCtrl.add()' ]
ng-click = 'commentsCtrl.add($event)' ]
= t('layout.create')
.panel-footer
=> t('layout.comments.notifications_are')

View File

@ -1,2 +1,3 @@
json.id @comment.id
json.html render partial: 'projects/comments/line_comment.html.slim'
json.message t('flash.comment.saved')

View File

@ -47,6 +47,9 @@ en:
saved: Comment saved
save_error: Error while saving comment
destroyed: Comment deleted
error_in_deleting: Error deleting comment
updated: Comment updated
error_in_updating: Error updating comment
activerecord:
attributes:

View File

@ -43,9 +43,12 @@ ru:
flash:
comment:
saved: Комментарий успешно сохранен
saved: Комментарий сохранен
save_error: Ошибка сохранения комментария
destroyed: Комментарий удален
error_in_deleting: Ошибка при удалении комментария
updated: Комментарий обновлен
error_in_updating: Ошибка при обновлении комментария
activerecord:
attributes: