Skip to content

Commit caccb63

Browse files
author
kas70
committed
show 'stop ignoring' button in hovercards
1 parent 1b5ba68 commit caccb63

File tree

3 files changed

+72
-28
lines changed

3 files changed

+72
-28
lines changed

app/assets/javascripts/app/views/aspect_membership_view.js

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,64 @@ app.views.AspectMembership = app.views.Base.extend({
1919
"click ul.aspect_membership.dropdown-menu > li.aspect_selector"
2020
: "_clickHandler",
2121
"keypress ul.aspect_membership.dropdown-menu > li.aspect_selector"
22-
: "_clickHandler"
22+
: "_clickHandler",
23+
"click #unblock_user_button": function() {
24+
this.unblockPerson();
25+
this.reload();
26+
},
2327
},
2428

29+
2530
initialize: function(opts) {
2631
_.extend(this, opts);
2732
this.list_item = null;
2833
this.dropdown = null;
2934
},
3035

3136
presenter: function() {
32-
var aspectMembershipsLength = this.person.contact ? this.person.contact.aspectMemberships.length : 0;
33-
3437
return _.extend(this.defaultPresenter(), {
3538
aspects: this.aspectsPresenter(),
3639
dropdownMayCreateNewAspect: this.dropdownMayCreateNewAspect
37-
}, aspectMembershipsLength === 0 ? {
38-
extraButtonClass: "btn-default",
39-
noAspectIsSelected: true
40-
} : { // this.contact.aspectMemberships.length > 0
41-
aspectMembershipsLength: aspectMembershipsLength,
42-
allAspectsAreSelected: aspectMembershipsLength === app.aspects.length,
43-
onlyOneAspectIsSelected: aspectMembershipsLength === 1,
44-
firstMembershipName: this.person.contact.aspectMemberships.at(0).get("aspect").name,
45-
extraButtonClass: "btn-success"
40+
}, this.dropdownContext(this.person));
41+
},
42+
43+
reload: function() {
44+
this.person.set("block", null);
45+
this.render();
46+
return false;
47+
},
48+
49+
dropdownContext: function f(person) {
50+
var aspectMembershipsLength = this.person.contact ? this.person.contact.aspectMemberships.length : 0;
51+
var contactBlocked = this.person.get("block");
52+
53+
if (contactBlocked) {
54+
return {
55+
extraButtonClass: "btn-danger",
56+
contactBlocked: true,
57+
}
58+
} else if (aspectMembershipsLength === 0) {
59+
return {
60+
extraButtonClass: "btn-default",
61+
noAspectIsSelected: true,
62+
}
63+
} else {
64+
return {
65+
aspectMembershipsLength: aspectMembershipsLength,
66+
allAspectsAreSelected: aspectMembershipsLength === app.aspects.length,
67+
onlyOneAspectIsSelected: aspectMembershipsLength === 1,
68+
firstMembershipName: this.person.contact.aspectMemberships.at(0).get("aspect").name,
69+
extraButtonClass: "btn-success"
70+
}
71+
}
72+
},
73+
74+
unblockPerson: function() {
75+
var block = this.person.unblock();
76+
block.fail(function() {
77+
app.flashMessages.error(Diaspora.I18.t("unblock_failed"));
4678
});
79+
return false;
4780
},
4881

4982
aspectsPresenter: function() {

app/assets/templates/aspect_membership_dropdown_tpl.jst.hbs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
<button class="btn dropdown-toggle {{extraButtonClass}}" data-toggle="dropdown" tabindex="0">
2-
<span class="text">
3-
{{#if allAspectsAreSelected }}
4-
{{ t "aspect_dropdown.all_aspects" }}
5-
{{else if onlyOneAspectIsSelected}}
6-
{{ firstMembershipName }}
7-
{{else if noAspectIsSelected}}
8-
{{ t "aspect_dropdown.add_to_aspect"}}
9-
{{else}}
10-
{{ t "aspect_dropdown.toggle" count=aspectMembershipsLength }}
11-
{{/if}}
12-
</span>
13-
<span class="caret" />
14-
</button>
1+
{{#if contactBlocked}}
2+
<button id="unblock_user_button" class="btn btn-danger">
3+
<span class="text">{{ t "people.stop_ignoring" }}</span>
4+
</button>
5+
6+
{{else}}
7+
<button class="btn dropdown-toggle {{extraButtonClass}}" data-toggle="dropdown" tabindex="0">
8+
<span class="text">
9+
{{#if allAspectsAreSelected }}
10+
{{ t "aspect_dropdown.all_aspects" }}
11+
{{else if onlyOneAspectIsSelected}}
12+
{{ firstMembershipName }}
13+
{{else if noAspectIsSelected}}
14+
{{ t "aspect_dropdown.add_to_aspect"}}
15+
{{else}}
16+
{{ t "aspect_dropdown.toggle" count=aspectMembershipsLength }}
17+
{{/if}}
18+
</span>
19+
<span class="caret" />
20+
</button>
21+
{{/if}}
1522

1623
<ul class="dropdown-menu aspect_membership pull-right" unselectable="on">
1724
{{#each aspects}}

app/presenters/person_presenter.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def base_hash
1313
def full_hash
1414
base_hash_with_contact.merge(
1515
relationship: relationship,
16-
block: is_blocked? ? BlockPresenter.new(current_user_person_block).base_hash : false,
16+
block: block_details,
1717
is_own_profile: own_profile?,
1818
show_profile_info: public_details? || own_profile? || person_is_following_current_user
1919
)
@@ -24,7 +24,7 @@ def as_json(_options={})
2424
end
2525

2626
def hovercard
27-
base_hash_with_contact.merge(profile: ProfilePresenter.new(profile).for_hovercard)
27+
base_hash_with_contact.merge(block: block_details, profile: ProfilePresenter.new(profile).for_hovercard)
2828
end
2929

3030
def metas_attributes
@@ -109,6 +109,10 @@ def is_blocked?
109109
current_user_person_block.present?
110110
end
111111

112+
def block_details
113+
is_blocked? ? BlockPresenter.new(current_user_person_block).base_hash : false
114+
end
115+
112116
def title
113117
name
114118
end

0 commit comments

Comments
 (0)