diff --git a/app/assets/javascripts/app/views/contacts_view.js b/app/assets/javascripts/app/views/contacts_view.js index 1c85a3599d7546fa18fa21ece1d602c9454c642f..770e03ab598c91d043719f351e04308ff67f5219 100644 --- a/app/assets/javascripts/app/views/contacts_view.js +++ b/app/assets/javascripts/app/views/contacts_view.js @@ -4,13 +4,17 @@ app.views.Contacts = Backbone.View.extend({ events: { "click #contacts_visibility_toggle" : "toggleContactVisibility", - "click #change_aspect_name" : "showAspectNameForm" + "click #change_aspect_name" : "showAspectNameForm", + "click .contact_remove-from-aspect" : "removeContactFromAspect", + "click .contact_add-to-aspect" : "addContactToAspect", + "keyup #contact_list_search" : "searchContactList" }, initialize: function() { this.visibility_toggle = $("#contacts_visibility_toggle .entypo"); $("#people_stream.contacts .header .entypo").tooltip({ 'placement': 'bottom'}); $(".contact_remove-from-aspect").tooltip(); + $(".contact_add-to-aspect").tooltip(); $(document).on('ajax:success', 'form.edit_aspect', this.updateAspectName); }, @@ -20,16 +24,16 @@ app.views.Contacts = Backbone.View.extend({ .addClass("lock") .tooltip("destroy") .removeAttr("data-original-title") - .attr("title", Diaspora.I18n.t("aspects.edit.aspect_list_is_not_visible")) - .tooltip(); + .attr("title", Diaspora.I18n.t("contacts.aspect_list_is_not_visible")) + .tooltip({'placement': 'bottom'}); } else { this.visibility_toggle.removeClass("lock") .addClass("lock-open") .tooltip("destroy") .removeAttr("data-original-title") - .attr("title", Diaspora.I18n.t("aspects.edit.aspect_list_is_visible")) - .tooltip(); + .attr("title", Diaspora.I18n.t("contacts.aspect_list_is_visible")) + .tooltip({'placement': 'bottom'}); } }, @@ -43,5 +47,64 @@ app.views.Contacts = Backbone.View.extend({ $("#aspect_nav [data-aspect-id='"+data['id']+"'] .name").text(data['name']); $(".header > #aspect_name_form").hide(); $(".header > h3").show(); + }, + + addContactToAspect: function(e){ + var contact = $(e.currentTarget); + var aspect_membership = new app.models.AspectMembership({ + 'person_id': contact.data('person_id'), + 'aspect_id': contact.data('aspect_id') + }); + + aspect_membership.save({ + success: function(model,response){ + contact.attr('data-membership_id',model.id) + .tooltip('destroy') + .removeAttr('data-original-title') + .removeClass("contact_add-to_aspect").removeClass("circled-plus") + .addClass("contact_remove-from_aspect").addClass("circled-cross") + .attr('title', Diaspora.I18n.t('contacts.add_contact')) + .tooltip() + .closest('.stream_element').removeClass('not_in_aspect'); + }, + error: function(model,response){ + alert("SAVE ERROR " + JSON.stringify(model)); + } + }); + }, + + removeContactFromAspect: function(e){ + var contact = $(e.currentTarget); + var aspect_membership = new app.models.AspectMembership({ + 'id': contact.data('membership_id') + }); + + aspect_membership.destroy({ + success: function(model,response){ + contact.removeAttr('data-membership_id') + .tooltip('destroy') + .removeAttr('data-original-title') + .removeClass("contact_remove-from_aspect").removeClass("circled-cross") + .addClass("contact_add-to_aspect").addClass("circled-plus") + .attr('title', Diaspora.I18n.t('contacts.add_contact')) + .tooltip() + .closest('.stream_element').addClass('not_in_aspect'); + }, + error: function(model,response){ + alert("DESTROY ERROR " + JSON.stringify(model)); + } + }); + }, + + searchContactList: function(e) { + var query = new RegExp($(e.target).val(),'i'); + + $("#people_stream.stream.contacts .stream_element").each(function(){ + if($(this).find(".name").text().match(query)){ + $(this).show(); + } else { + $(this).hide(); + } + }); } }); diff --git a/app/assets/javascripts/aspect-edit-pane.js b/app/assets/javascripts/aspect-edit-pane.js deleted file mode 100644 index 27dc0f07dff68dfcad000a92fcb894fef0870cd5..0000000000000000000000000000000000000000 --- a/app/assets/javascripts/aspect-edit-pane.js +++ /dev/null @@ -1,89 +0,0 @@ -/** - * TEMPORARY SOLUTION - * TODO remove me, when the contacts section is done with Backbone.js ... - * (this is about as much covered by tests as the old code ... not at all) - * - * see also 'contact-edit.js' - */ - -app.tmp || (app.tmp = {}); - -// on the contacts page, viewing the facebox for single aspect -app.tmp.ContactAspectsBox = function() { - $('body').on('click', '#aspect_edit_pane a.add.btn', _.bind(this.addToAspect, this)); - $('body').on('click', '#aspect_edit_pane a.added.btn', _.bind(this.removeFromAspect, this)); -}; -_.extend(app.tmp.ContactAspectsBox.prototype, { - addToAspect: function(evt) { - var el = $(evt.currentTarget); - var aspect_membership = new app.models.AspectMembership({ - 'person_id': el.data('person_id'), - 'aspect_id': el.data('aspect_id') - }); - - aspect_membership.on('sync', this._successSaveCb, this); - aspect_membership.on('error', function() { - this._displayError('aspect_dropdown.error', el); - }, this); - - aspect_membership.save(); - - return false; - }, - - _successSaveCb: function(aspect_membership) { - var membership_id = aspect_membership.get('id'); - var person_id = aspect_membership.get('person_id'); - var el = $('li.contact').find('a.add[data-person_id="'+person_id+'"]'); - - el.removeClass('add') - .addClass('added') - .attr('data-membership_id', membership_id) // just to be sure... - .data('membership_id', membership_id); - - el.find('div').removeClass('icons-monotone_plus_add_round') - .addClass('icons-monotone_check_yes'); - }, - - removeFromAspect: function(evt) { - var el = $(evt.currentTarget); - - var aspect_membership = new app.models.AspectMembership({ - 'id': el.data('membership_id') - }); - aspect_membership.on('sync', this._successDestroyCb, this); - aspect_membership.on('error', function(aspect_membership) { - this._displayError('aspect_dropdown.error_remove', el); - }, this); - - aspect_membership.destroy(); - - return false; - }, - - _successDestroyCb: function(aspect_membership) { - var membership_id = aspect_membership.get('id'); - var el = $('li.contact').find('a.added[data-membership_id="'+membership_id+'"]'); - - el.removeClass('added') - .addClass('add') - .removeAttr('data-membership_id') - .removeData('membership_id'); - - el.find('div').removeClass('icons-monotone_check_yes') - .addClass('icons-monotone_plus_add_round'); - }, - - _displayError: function(msg_id, contact_el) { - var name = $('li.contact') - .has(contact_el) - .find('h4.name') - .text(); - var msg = Diaspora.I18n.t(msg_id, { 'name': name }); - Diaspora.page.flashMessages.render({ 'success':false, 'notice':msg }); - } -}); - -$(function() { - var contact_aspects_box = new app.tmp.ContactAspectsBox(); -}); diff --git a/app/assets/javascripts/contact-edit.js b/app/assets/javascripts/contact-edit.js deleted file mode 100644 index 99647bfb3393553a57e5c6264165590a209780b1..0000000000000000000000000000000000000000 --- a/app/assets/javascripts/contact-edit.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2010-2011, Diaspora Inc. This file is -// licensed under the Affero General Public License version 3 or later. See -// the COPYRIGHT file. - -/** - * TEMPORARY SOLUTION - * TODO remove me, when the contacts section is done with Backbone.js ... - * (this is about as much covered by tests as the old code ... not at all) - * - * see also 'aspect-edit-pane.js' - */ - -app.tmp || (app.tmp = {}); - -// on the contacts page, viewing the list of people in a single aspect -app.tmp.ContactAspects = function() { - $('#people_stream').on('click', '.contact_remove-from-aspect', _.bind(this.removeFromAspect, this)); -}; -_.extend(app.tmp.ContactAspects.prototype, { - removeFromAspect: function(evt) { - evt.stopImmediatePropagation(); - evt.preventDefault(); - - var el = $(evt.currentTarget); - var id = el.data('membership_id'); - - var aspect_membership = new app.models.AspectMembership({'id':id}); - aspect_membership.on('sync', this._successDestroyCb, this); - aspect_membership.on('error', function(aspect_membership) { - this._displayError('aspect_dropdown.error_remove', aspect_membership.get('id')); - }, this); - - aspect_membership.destroy(); - - return false; - }, - - _successDestroyCb: function(aspect_membership) { - var membership_id = aspect_membership.get('id'); - - $('.stream_element').has('[data-membership_id="'+membership_id+'"]') - .fadeOut(300, function() { $(this).remove() }); - }, - - _displayError: function(msg_id, membership_id) { - var name = $('.stream_element') - .has('[data-membership_id="'+membership_id+'"]') - .find('div.bd > a') - .text(); - var msg = Diaspora.I18n.t(msg_id, { 'name': name }); - Diaspora.page.flashMessages.render({ 'success':false, 'notice':msg }); - } -}); - - -$(function() { - var contact_aspects = new app.tmp.ContactAspects(); -}); diff --git a/app/assets/javascripts/contact-list.js b/app/assets/javascripts/contact-list.js index 5d8785a6e07b87b590d80d8876f9af34f45123d1..e4caeabd6e4a990d81c79faca57ad337f585cd71 100644 --- a/app/assets/javascripts/contact-list.js +++ b/app/assets/javascripts/contact-list.js @@ -4,37 +4,6 @@ */ var List = { - initialize: function() { - $(document).on("keyup", ".contact_list_search", function(e) { - var search = $(this); - var list = $(".contacts", ".searchable"); - var query = new RegExp(search.val(),'i'); - - $("> .contact", list).each( function(idx, element) { - element = $(element); - if( !element.find(".name").text().match(query) ) { - element.addClass('hidden'); - } else { - element.removeClass('hidden'); - } - }); - }); - }, - - disconnectUser: function(contact_id){ - $.ajax({ - url: "/contacts/" + contact_id, - type: "DELETE", - success: function(){ - if( $('.searchable').length == 1){ - $('.searchable .contact[data-contact_id='+contact_id+']').fadeOut(200); - } else if($('#aspects_list').length == 1) { - $.facebox.close(); - }; - } - }); - }, - runDelayedSearch: function( searchTerm ) { $.getJSON('/people/refresh_search', { q: searchTerm }, @@ -77,6 +46,4 @@ $(document).ready(function() { $this.removeClass("remove"); $this.children("img").attr("src","/images/icons/monotone_check_yes.png"); }); - - List.initialize(); }); diff --git a/app/assets/javascripts/home.js b/app/assets/javascripts/home.js index 2d14f604547d4e1cf02837dcb43e4a012066b864..f8a196cf05b53c98c0fa6d115cc5792ec4121dda 100644 --- a/app/assets/javascripts/home.js +++ b/app/assets/javascripts/home.js @@ -3,5 +3,4 @@ * the COPYRIGHT file. */ -//= require aspect-edit-pane //= require fileuploader-custom diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index 389e824af89a08ba29569dae4c28ffd69ec10149..483ee493c4858bbfdec7c84e8238a7a12ede90bc 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -32,8 +32,6 @@ //= require_tree ./widgets //= require view //= require aspects-dropdown -//= require contact-edit -//= require contact-list //= require mentions //= require bootstrap-tooltip //= require bootstrap-popover diff --git a/app/assets/javascripts/people.js b/app/assets/javascripts/people.js index d204d481c00e75cb027a3549cc930b175e46b606..78f1e519ef95105a236940a9c42ec1d3a6b3aa6c 100644 --- a/app/assets/javascripts/people.js +++ b/app/assets/javascripts/people.js @@ -2,7 +2,6 @@ * licensed under the Affero General Public License version 3 or later. See * the COPYRIGHT file. */ -//= require aspect-edit-pane //= require fileuploader-custom //= require jquery.autoSuggest.custom diff --git a/app/assets/stylesheets/contacts.css.scss b/app/assets/stylesheets/contacts.css.scss index 337660435bbeb354969bc0a21682a8489c49394b..5c565b355a256d451005713e8d18b8fe2618a2c8 100644 --- a/app/assets/stylesheets/contacts.css.scss +++ b/app/assets/stylesheets/contacts.css.scss @@ -14,6 +14,10 @@ } .btn { margin-top: 10px; } } + #contact_list_search { + margin: 6px 30px 0 0; + width: 150px; + } & > a, #aspect_controls > a { text-decoration: none; margin-right: 25px; @@ -27,15 +31,18 @@ #suggest_member.btn { margin-top: 8px; } } - .contact_remove-from-aspect, .contact_add-to-aspect { - text-decoration: none; - .entypo { + .stream_element { + .contact_remove-from-aspect, .contact_add-to-aspect { + text-decoration: none; + cursor: pointer; font-size: 20px; line-height: 50px; margin: 10px; color: lighten($black,75%); &:hover { color: $black; } } + + &.not_in_aspect { background-color: $background-grey; } } .no_contacts { diff --git a/app/assets/stylesheets/new_styles/_forms.scss b/app/assets/stylesheets/new_styles/_forms.scss index c85da9ec0ad93af91e3aabe45936643a702e4420..a6ecf1569e64b758cb6d4f6727571a04a0497774 100644 --- a/app/assets/stylesheets/new_styles/_forms.scss +++ b/app/assets/stylesheets/new_styles/_forms.scss @@ -86,7 +86,7 @@ form.block-form { } } -textarea, input[type=text], input[type=password] { +textarea, input[type=text], input[type=password], input[type=search] { &:focus, &:invalid:focus { border: 1px solid $border-dark-grey; outline: none; diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 18c3548265274421503996d6ef400c19e9ca6c53..becffae3b8dd9df423e33d016eb6386a102407f9 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -67,28 +67,6 @@ class AspectsController < ApplicationController end end - def edit - @aspect = current_user.aspects.where(:id => params[:id]).includes(:contacts => {:person => :profile}).first - - @contacts_in_aspect = @aspect.contacts.includes(:aspect_memberships, :person => :profile).to_a.sort_by { |c| c.person.name } - c = Contact.arel_table - if @contacts_in_aspect.empty? - @contacts_not_in_aspect = current_user.contacts.includes(:aspect_memberships, :person => :profile).to_a.sort_by { |c| c.person.name } - else - @contacts_not_in_aspect = current_user.contacts.where(c[:id].not_in(@contacts_in_aspect.map(&:id))).includes(:aspect_memberships, :person => :profile).to_a.sort_by { |c| c.person.name } - end - - @contacts = @contacts_not_in_aspect - - unless @aspect - render :file => Rails.root.join('public', '404.html').to_s, :layout => false, :status => 404 - else - @aspect_ids = [@aspect.id] - @aspect_contacts_count = @aspect.contacts.size - render :layout => false - end - end - def update @aspect = current_user.aspects.where(:id => params[:id]).first diff --git a/app/helpers/contacts_helper.rb b/app/helpers/contacts_helper.rb index edd4bc56f2941bafaadf0a698ff2aedb41aa3501..a197bb4e8e53eeac4590e061b144006433f87b98 100644 --- a/app/helpers/contacts_helper.rb +++ b/app/helpers/contacts_helper.rb @@ -3,16 +3,11 @@ module ContactsHelper membership = contact.aspect_memberships.where(:aspect_id => @aspect.id).first unless @aspect.nil? if membership - link_to(content_tag(:i, nil, :class => 'entypo circled-cross'), - { :controller => "aspect_memberships", - :action => 'destroy', - :id => membership.id - }, - :title => t('contacts.index.remove_person_from_aspect', :person_name => contact.person_first_name, :aspect_name => @aspect.name), - :class => 'contact_remove-from-aspect', - :method => 'delete', - 'data-membership_id' => membership.id - ) + content_tag(:i, nil, :class => 'entypo circled-cross contact_remove-from-aspect', + :title => t('contacts.index.remove_person_from_aspect', :person_name => contact.person_first_name, :aspect_name => @aspect.name), + 'data-aspect_id' => @aspect.id, + 'data-person_id' => contact.person_id, + 'data-membership_id' => membership.id ) elsif @aspect.nil? render :partial => 'people/relationship_action', @@ -20,18 +15,10 @@ module ContactsHelper :contact => contact, :current_user => current_user } else - link_to(content_tag(:i, nil, :class => 'entypo circled-plus'), - { :controller => "aspect_memberships", - :action => 'create', - :person_id => contact.person_id, - :aspect_id => @aspect.id - }, - :title => t('people.person.add_contact'), - :class => 'contact_add-to-aspect', - :method => 'create', - 'data-aspect_id' => @aspect.id, - 'data-person_id' => contact.person_id - ) + content_tag(:i, nil, :class => 'entypo circled-plus contact_add-to-aspect', + :title => t('people.person.add_contact'), + 'data-aspect_id' => @aspect.id, + 'data-person_id' => contact.person_id ) end end diff --git a/app/views/aspects/edit.html.haml b/app/views/aspects/edit.html.haml deleted file mode 100644 index 0ee1d00baba0e7d1c3818643296ea33eff48ed9b..0000000000000000000000000000000000000000 --- a/app/views/aspects/edit.html.haml +++ /dev/null @@ -1,13 +0,0 @@ -#people_stream.stream.contacts - - @contacts.each do |contact| - .media.stream_element{:id => contact.person_id} - .pull-right.contact_add-to-aspect - %i.entypo.circled-plus{:title => t('people.person.add_contact')} - .media-object.pull-left - = person_image_link(contact.person, :size => :thumb_small) - .media-body - = person_link(contact.person) - .info.diaspora_handle - = contact.person_diaspora_handle - .info.tags - = Diaspora::Taggable.format_tags(contact.person.profile.tag_string) diff --git a/app/views/contacts/_contact.html.haml b/app/views/contacts/_contact.html.haml index 2a005f457c083ebfbd32c494a5ae79b1e986eb23..ed484a85d5946b50864154263bc9679eecefef88 100644 --- a/app/views/contacts/_contact.html.haml +++ b/app/views/contacts/_contact.html.haml @@ -1,10 +1,11 @@ -.media.stream_element{:id => contact.person_id} +- membership = contact.aspect_memberships.where(:aspect_id => @aspect.id).first unless @aspect.nil? +.media.stream_element{:id => contact.person_id, :class => ("not_in_aspect" unless membership)} .pull-right = contact_aspect_dropdown(contact) .media-object.pull-left = person_image_link(contact.person, :size => :thumb_small) .media-body - = person_link(contact.person) + = person_link(contact.person, :class => 'name') .info.diaspora_handle = contact.person_diaspora_handle .info.tags diff --git a/app/views/contacts/_header.html.haml b/app/views/contacts/_header.html.haml index 5732ee081d56dfca2ef1d7982fdb3d3e6a5dbd2e..bedae3a8dd47336deb517f1b71872258a092099e 100644 --- a/app/views/contacts/_header.html.haml +++ b/app/views/contacts/_header.html.haml @@ -12,7 +12,8 @@ = link_to @aspect, method: "delete", data: { confirm: t('aspects.edit.confirm_remove_aspect') }, class: 'delete' do %i.entypo.trash.contacts-header-icon{:title => t('delete')} - + .pull-right + = search_field_tag :contact_search, "", id: "contact_list_search", placeholder: t('contacts.index.user_search') %h3 %span#aspect_name = @aspect.name @@ -21,7 +22,7 @@ #aspect_name_form = form_for @aspect, :remote => true do |aspect| = aspect.text_field :name, :maxlength => 20 - = aspect.submit t('aspects.edit.update'), 'data-disable-with' => t('aspects.edit.updating'), :class => "btn green" + = aspect.submit t('aspects.edit.update'), 'data-disable-with' => t('aspects.edit.updating'), :class => "btn" - else %h3 diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index a6db18f67e050de20723cfe3a237b064a5ecbad1..6aab979c4a737fc3f8a10eef6a45cf382f57977d 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -345,6 +345,7 @@ en: only_sharing_with_me: "Only sharing with me" remove_person_from_aspect: "Remove %{person_name} from \"%{aspect_name}\"" many_people_are_you_sure: "Are you sure you want to start a private conversation with more than %{suggested_limit} contacts? Posting to this aspect may be a better way to contact them." + user_search: "User Search" spotlight: community_spotlight: "Community Spotlight" suggest_member: "Suggest a member" diff --git a/config/locales/javascript/javascript.en.yml b/config/locales/javascript/javascript.en.yml index f99a08d90f229277c90f12a72afc9fbfd483a888..dd25785d129f017e9b5988ece04df4fd73a82cd9 100644 --- a/config/locales/javascript/javascript.en.yml +++ b/config/locales/javascript/javascript.en.yml @@ -38,6 +38,13 @@ en: years: "%d years" wordSeparator: " " + contacts: + add_contact: "Add contact" + aspect_list_is_visible: "Contacts in this aspect are able to see each other." + aspect_list_is_not_visible: "Contacts in this aspect are not able to see each other." + remove_contact: "Remove contact" + + my_activity: "My Activity" my_stream: "Stream" my_aspects: "My Aspects"