Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5594 from Faldrian/4055-add_contacts_mobile
4055 add contacts mobile
- Loading branch information
Showing
12 changed files
with
174 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
$(document).ready(function(){ | ||
/* profile page: aspect-dropdown */ | ||
|
||
// renders the cover text for the dropdown | ||
function profileAspectDropdown_refresh($el) { | ||
var cover_text, num_selected = $el.find('option.selected').length; | ||
if(num_selected === 0) { | ||
$el.removeClass('has_connection'); | ||
cover_text = Diaspora.I18n.t('aspect_dropdown.add_to_aspect'); | ||
} else { | ||
$el.addClass('has_connection'); | ||
if(num_selected === 1) { | ||
cover_text = $el.find('option.selected').data('name'); | ||
} else { | ||
cover_text = Diaspora.I18n.t('aspect_dropdown.toggle', { 'count' : num_selected }); | ||
} | ||
} | ||
$el.find('option.list_cover').text(cover_text); | ||
} | ||
|
||
// onchange handler for aspect dropdown instances | ||
var profileAspectDropDown_onchange = function() { | ||
var $el = $(this), | ||
selected = $el.find('option:selected'); | ||
$el.find('option.list_cover').text(Diaspora.I18n.t('aspect_dropdown.updating')); | ||
$el.val('list_cover'); // switch back to cover | ||
|
||
if(selected.hasClass('selected')) { | ||
// remove from aspect | ||
var membership_id = selected.data('membership_id'); | ||
|
||
$.ajax({ | ||
url: Routes.aspect_membership_path(membership_id), | ||
type: 'DELETE', | ||
dataType: 'json', | ||
headers: { | ||
'Accept': "application/json, text/javascript, */*; q=0.01" | ||
} | ||
}).done(function() { | ||
selected.text("– " + Diaspora.I18n.t('aspect_dropdown.mobile_row_unchecked', {name: selected.data('name')})); | ||
selected.removeClass('selected'); | ||
profileAspectDropdown_refresh($el); | ||
}).fail(function() { | ||
alert(Diaspora.I18n.t('aspect_dropdown.error_remove')); | ||
profileAspectDropdown_refresh($el); | ||
}); | ||
|
||
} else { | ||
// add to aspect | ||
var person_id = $el.data('person-id'); | ||
|
||
$.ajax({ | ||
url: Routes.aspect_memberships_path(), | ||
data: JSON.stringify({ | ||
"person_id": person_id, | ||
"aspect_id": parseInt(selected.val(), 10) | ||
}), | ||
processData: false, | ||
type: 'POST', | ||
dataType: 'json', | ||
headers: { | ||
'Accept': "application/json, text/javascript, */*; q=0.01" | ||
}, | ||
contentType: "application/json; charset=UTF-8" | ||
}).done(function(data) { | ||
selected.data('membership_id', data.id); // remember membership-id | ||
selected.text("✓ " + Diaspora.I18n.t('aspect_dropdown.mobile_row_checked', {name: selected.data('name')})); | ||
selected.addClass('selected'); | ||
profileAspectDropdown_refresh($el); | ||
}).fail(function() { | ||
alert(Diaspora.I18n.t('aspect_dropdown.error')); | ||
profileAspectDropdown_refresh($el); | ||
}); | ||
|
||
} | ||
}; | ||
|
||
// initialize list_cover and register eventhandler for every user_aspect dropdown there is | ||
$('.user_aspects').each(function() { | ||
profileAspectDropdown_refresh($(this)); | ||
$(this).change(profileAspectDropDown_onchange); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
app/views/aspect_memberships/_aspect_membership_dropdown.mobile.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
%div | ||
%select{:name => 'user_aspects', :class => 'user_aspects', 'data-person-id' => @person.id} | ||
%option{:value => 'list_cover', :class => 'list_cover', :disabled => 'true', :selected => 'true'} | ||
= t("add_contact") | ||
- contact = current_user.contact_for(@person) | ||
- current_user.aspects.each do |aspect| | ||
- if contact.try(:in_aspect?, aspect) | ||
- membership_id = contact.aspect_memberships.where(:aspect_id => aspect.id).limit(1).pluck(:id).first | ||
%option{:value => aspect.id, 'data-name' => aspect.name, 'data-membership_id' => membership_id, :class => 'selected'} | ||
= "✓ #{t('shared.aspect_dropdown.mobile_row_checked', name: aspect.name)}" | ||
- else | ||
%option{:value => aspect.id, 'data-name' => aspect.name} | ||
= "– #{t('shared.aspect_dropdown.mobile_row_unchecked', name: aspect.name)}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@javascript | ||
Feature: adding and removing people from aspects | ||
In order to add people to my contacts | ||
As a mobile user | ||
I want to add and remove people from my contacts | ||
|
||
Background: | ||
Given following users exist: | ||
| username | | ||
| bob | | ||
| alice | | ||
And I toggle the mobile view | ||
And I sign in as "bob@bob.bob" on the mobile website | ||
|
||
Scenario: verify different states of the cover button | ||
When I am on "alice@alice.alice"'s page | ||
Then the aspect dropdown within "#author_info" should be labeled "Add contact" | ||
|
||
When I select "Unicorns" from "user_aspects" within "#author_info" | ||
Then the aspect dropdown within "#author_info" should be labeled "Unicorns" | ||
|
||
When I select "Besties" from "user_aspects" within "#author_info" | ||
Then the aspect dropdown within "#author_info" should be labeled "In 2 aspects" | ||
|
||
Scenario: add contact to aspect | ||
When I am on "alice@alice.alice"'s page | ||
And I select "Unicorns" from "user_aspects" within "#author_info" | ||
Then the aspect dropdown within "#author_info" should be labeled "Unicorns" | ||
Then I should have 1 contacts in "Unicorns" | ||
|
||
Scenario: remove contact to aspect | ||
When I am on "alice@alice.alice"'s page | ||
And I select "Unicorns" from "user_aspects" within "#author_info" | ||
Then the aspect dropdown within "#author_info" should be labeled "Unicorns" | ||
|
||
And I select "Besties" from "user_aspects" within "#author_info" | ||
Then the aspect dropdown within "#author_info" should be labeled "In 2 aspects" | ||
Then I should have 1 contacts in "Unicorns" | ||
|
||
When I am on "alice@alice.alice"'s page | ||
And I select "Unicorns" from "user_aspects" within "#author_info" | ||
Then the aspect dropdown within "#author_info" should be labeled "Besties" | ||
Then I should have 0 contacts in "Unicorns" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,3 @@ | |
find('.photo.loaded .thumbnail', :match => :first).hover | ||
find('.delete', :match => :first).click | ||
end | ||
|