diff --git a/app/assets/javascripts/angularjs/comments/comments_controller.js.coffee b/app/assets/javascripts/angularjs/comments/comments_controller.js.coffee index 2cce12bb0..d5fb3380d 100644 --- a/app/assets/javascripts/angularjs/comments/comments_controller.js.coffee +++ b/app/assets/javascripts/angularjs/comments/comments_controller.js.coffee @@ -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) diff --git a/app/controllers/projects/comments_controller.rb b/app/controllers/projects/comments_controller.rb index 851ddf7d9..54c4f9773 100644 --- a/app/controllers/projects/comments_controller.rb +++ b/app/controllers/projects/comments_controller.rb @@ -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 diff --git a/app/views/projects/comments/_add.html.slim b/app/views/projects/comments/_add.html.slim index 6c75e40d0..54dd8d5a8 100644 --- a/app/views/projects/comments/_add.html.slim +++ b/app/views/projects/comments/_add.html.slim @@ -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') diff --git a/app/views/projects/comments/create.json.jbuilder b/app/views/projects/comments/create.json.jbuilder index 9360e4013..92866965b 100644 --- a/app/views/projects/comments/create.json.jbuilder +++ b/app/views/projects/comments/create.json.jbuilder @@ -1,2 +1,3 @@ json.id @comment.id json.html render partial: 'projects/comments/line_comment.html.slim' +json.message t('flash.comment.saved') diff --git a/config/locales/models/comment.en.yml b/config/locales/models/comment.en.yml index ed1f6f504..e4045a103 100644 --- a/config/locales/models/comment.en.yml +++ b/config/locales/models/comment.en.yml @@ -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: diff --git a/config/locales/models/comment.ru.yml b/config/locales/models/comment.ru.yml index 0b8c199a4..f7fb6c92b 100644 --- a/config/locales/models/comment.ru.yml +++ b/config/locales/models/comment.ru.yml @@ -43,9 +43,12 @@ ru: flash: comment: - saved: Комментарий успешно сохранен + saved: Комментарий сохранен save_error: Ошибка сохранения комментария destroyed: Комментарий удален + error_in_deleting: Ошибка при удалении комментария + updated: Комментарий обновлен + error_in_updating: Ошибка при обновлении комментария activerecord: attributes: