From e2412d2e43f355d5040531eb1afba3257a4539f2 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 16 Nov 2010 18:00:55 -0800 Subject: [PATCH] Add error messages for friending from aspect-manage --- app/controllers/people_controller.rb | 2 +- app/views/js/_websocket_js.haml | 16 +++++++++------- app/views/requests/_manage_aspect_contacts.haml | 5 +++-- public/javascripts/view.js | 4 ++++ public/stylesheets/sass/application.sass | 2 ++ 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 8abb47d6f..2e5bcd4a2 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -109,7 +109,7 @@ class PeopleController < ApplicationController response.socket_to_uid(current_user.id, opts) else require File.join(Rails.root,'lib/diaspora/websocket') - Diaspora::WebSocket.queue_to_user(current_user.id, {:class => 'person', :query => account, :response => response}) + Diaspora::WebSocket.queue_to_user(current_user.id, {:class => 'people', :status => 'fail', :query => account, :response => response}.to_json) end rescue RuntimeError => e puts e.message diff --git a/app/views/js/_websocket_js.haml b/app/views/js/_websocket_js.haml index 39302a97c..e27090a83 100644 --- a/app/views/js/_websocket_js.haml +++ b/app/views/js/_websocket_js.haml @@ -17,8 +17,13 @@ processNotification(obj['notice']); }else if (obj['class'] == 'people'){ + $('#loader').hide(); debug("got a " + obj['class']); - processPerson(obj['html']); + if(obj['status'] == 'fail'){ + $('#request_result li:first').text(obj['response']).show(); + }else{ + processPerson(obj['html']); + } }else{ debug("got a " + obj['class'] + " for aspects " + obj['aspect_ids']); @@ -34,22 +39,20 @@ processPost(obj['class'], obj['html'], obj['aspect_ids']) } } - }; ws.onclose = function() { debug("socket closed"); }; ws.onopen = function() { ws.send(location.pathname); debug("connected..."); }; - }); function processPerson(html){ $('.people#stream').prepend(html).slideDown('slow', function(){}); - var rr = $('#request_result'); - rr.prepend(html).hide(); + var rr = $('#request_result li:first'); + rr.after(html); $("#request_result [name='into']").val(rr.attr('aspect_id')); - rr.slideDown('fast', function(){}); + $('#request_result :nth-child(2)').slideDown('fast', function(){}); } function processNotification(html){ @@ -82,7 +85,6 @@ if( !opts['mine?'] && opts['my_post?']) { processNotification(opts['notification']); } - } function processPost(className, html, aspectIds){ diff --git a/app/views/requests/_manage_aspect_contacts.haml b/app/views/requests/_manage_aspect_contacts.haml index 4fba6a143..7a691b0bc 100644 --- a/app/views/requests/_manage_aspect_contacts.haml +++ b/app/views/requests/_manage_aspect_contacts.haml @@ -13,7 +13,7 @@ .span-7.last %h3 Add a new contact - = form_tag(person_by_handle_path, :id => "new_request_to_#{aspect.id}", :remote => true) do + = form_tag(person_by_handle_path, :id => "new_request_to_#{aspect.id}", :class => "webfinger_form", :remote => true) do =t('.enter_a_diaspora_username') %br %i= t '.your_diaspora_username_is', :diaspora_handle => current_user.diaspora_handle @@ -30,5 +30,6 @@ = submit_tag t('.create_request') %br + #loader.hidden= image_tag 'ajax-loader.gif' %ul#request_result{:aspect_id => aspect.id} - + %li.error.hidden diff --git a/public/javascripts/view.js b/public/javascripts/view.js index ce93e500f..a77602c83 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -72,6 +72,10 @@ $(document).ready(function(){ $(".person img", ".dropzone").tipsy({live:true}); $(".avatar", ".aspects").tipsy({live:true}); + $('.webfinger_form').submit(function(){ + $('#loader').show(); + $('#request_result li:first').hide(); + }); });//end document ready diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index d436b3754..c79d46523 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -31,6 +31,8 @@ h1, h2, h3, h4 h3 :font :size 18px +.hidden + :display none .avatar :width 50px