diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 597891c76..79f2a8ab5 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -6,7 +6,7 @@ class AspectsController < ApplicationController before_filter :authenticate_user! respond_to :html - respond_to :json, :only => :show + respond_to :json, :only => [:show, :move_contact] respond_to :js def index @@ -113,16 +113,21 @@ class AspectsController < ApplicationController @from_aspect = current_user.aspects.where(:id => params[:from]).first @to_aspect = current_user.aspects.where(:id => params[:to][:to]).first + response = { } + unless current_user.move_contact( @person, @to_aspect, @from_aspect) flash[:error] = I18n.t 'aspects.move_contact.error',:inspect => params.inspect end if aspect = current_user.aspects.where(:id => params[:to][:to]).first - flash[:notice] = I18n.t 'aspects.move_contact.success' - render :nothing => true + response[:notice] = I18n.t 'aspects.move_contact.success' + response[:success] = true else - flash[:notice] = I18n.t 'aspects.move_contact.failure' - render aspects_manage_path + response[:notice] = I18n.t 'aspects.move_contact.failure' + response[:success] = false end + + + respond_with response end def add_to_aspect diff --git a/public/javascripts/aspect-edit.js b/public/javascripts/aspect-edit.js index 1edba3310..5be180513 100644 --- a/public/javascripts/aspect-edit.js +++ b/public/javascripts/aspect-edit.js @@ -62,7 +62,7 @@ var AspectEdit = { if (person.attr('data-aspect_id') != undefined && // a request doesn't have a data-aspect_id, but an existing contact does dropzone.attr('data-aspect_id') != person.attr('data-aspect_id')) { $.ajax({ - url: "/aspects/move_contact/", + url: "/aspects/move_contact.json", data: { "person_id": person.attr('data-guid'), "from": person.attr('data-aspect_id'), @@ -70,8 +70,8 @@ var AspectEdit = { "to": dropzone.attr('data-aspect_id') } }, - success: function() { - AspectEdit.onMovePersonSuccess(person, dropzone); + success: function(data) { + AspectEdit.onMovePersonSuccess(person, dropzone, data); } }); } @@ -85,7 +85,8 @@ var AspectEdit = { person.removeAttr('data-person_id'); }, - onMovePersonSuccess: function(person, dropzone) { + onMovePersonSuccess: function(person, dropzone, data) { + View.flashes.render(data); person.attr('data-aspect_id', dropzone.attr('data-aspect_id')); }, diff --git a/public/javascripts/view.js b/public/javascripts/view.js index c0f62c9a6..228101a87 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -81,6 +81,13 @@ var View = { top: -100 }, $this.remove) }, + render: function(result) { + $("
") + .attr("id", (result.success) ? "flash_notice" : "flash_error") + .prependTo(document.body) + .html(result.notice); + View.flashes.animate(); + }, selector: "#flash_notice, #flash_error, #flash_alert" },