Skip to content

Commit

Permalink
show 'stop ignoring' button in hovercards
Browse files Browse the repository at this point in the history
  • Loading branch information
kas70 committed Mar 25, 2018
1 parent 1b5ba68 commit caccb63
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 28 deletions.
57 changes: 45 additions & 12 deletions app/assets/javascripts/app/views/aspect_membership_view.js
Expand Up @@ -19,31 +19,64 @@ app.views.AspectMembership = app.views.Base.extend({
"click ul.aspect_membership.dropdown-menu > li.aspect_selector"
: "_clickHandler",
"keypress ul.aspect_membership.dropdown-menu > li.aspect_selector"
: "_clickHandler"
: "_clickHandler",
"click #unblock_user_button": function() {
this.unblockPerson();
this.reload();
},
},


initialize: function(opts) {
_.extend(this, opts);
this.list_item = null;
this.dropdown = null;
},

presenter: function() {
var aspectMembershipsLength = this.person.contact ? this.person.contact.aspectMemberships.length : 0;

return _.extend(this.defaultPresenter(), {
aspects: this.aspectsPresenter(),
dropdownMayCreateNewAspect: this.dropdownMayCreateNewAspect
}, aspectMembershipsLength === 0 ? {
extraButtonClass: "btn-default",
noAspectIsSelected: true
} : { // this.contact.aspectMemberships.length > 0
aspectMembershipsLength: aspectMembershipsLength,
allAspectsAreSelected: aspectMembershipsLength === app.aspects.length,
onlyOneAspectIsSelected: aspectMembershipsLength === 1,
firstMembershipName: this.person.contact.aspectMemberships.at(0).get("aspect").name,
extraButtonClass: "btn-success"
}, this.dropdownContext(this.person));
},

reload: function() {
this.person.set("block", null);
this.render();
return false;
},

dropdownContext: function f(person) {
var aspectMembershipsLength = this.person.contact ? this.person.contact.aspectMemberships.length : 0;
var contactBlocked = this.person.get("block");

if (contactBlocked) {
return {
extraButtonClass: "btn-danger",
contactBlocked: true,
}
} else if (aspectMembershipsLength === 0) {
return {
extraButtonClass: "btn-default",
noAspectIsSelected: true,
}
} else {
return {
aspectMembershipsLength: aspectMembershipsLength,
allAspectsAreSelected: aspectMembershipsLength === app.aspects.length,
onlyOneAspectIsSelected: aspectMembershipsLength === 1,
firstMembershipName: this.person.contact.aspectMemberships.at(0).get("aspect").name,
extraButtonClass: "btn-success"
}
}
},

unblockPerson: function() {
var block = this.person.unblock();
block.fail(function() {
app.flashMessages.error(Diaspora.I18.t("unblock_failed"));
});
return false;
},

aspectsPresenter: function() {
Expand Down
35 changes: 21 additions & 14 deletions app/assets/templates/aspect_membership_dropdown_tpl.jst.hbs
@@ -1,17 +1,24 @@
<button class="btn dropdown-toggle {{extraButtonClass}}" data-toggle="dropdown" tabindex="0">
<span class="text">
{{#if allAspectsAreSelected }}
{{ t "aspect_dropdown.all_aspects" }}
{{else if onlyOneAspectIsSelected}}
{{ firstMembershipName }}
{{else if noAspectIsSelected}}
{{ t "aspect_dropdown.add_to_aspect"}}
{{else}}
{{ t "aspect_dropdown.toggle" count=aspectMembershipsLength }}
{{/if}}
</span>
<span class="caret" />
</button>
{{#if contactBlocked}}
<button id="unblock_user_button" class="btn btn-danger">
<span class="text">{{ t "people.stop_ignoring" }}</span>
</button>

{{else}}
<button class="btn dropdown-toggle {{extraButtonClass}}" data-toggle="dropdown" tabindex="0">
<span class="text">
{{#if allAspectsAreSelected }}
{{ t "aspect_dropdown.all_aspects" }}
{{else if onlyOneAspectIsSelected}}
{{ firstMembershipName }}
{{else if noAspectIsSelected}}
{{ t "aspect_dropdown.add_to_aspect"}}
{{else}}
{{ t "aspect_dropdown.toggle" count=aspectMembershipsLength }}
{{/if}}
</span>
<span class="caret" />
</button>
{{/if}}

<ul class="dropdown-menu aspect_membership pull-right" unselectable="on">
{{#each aspects}}
Expand Down
8 changes: 6 additions & 2 deletions app/presenters/person_presenter.rb
Expand Up @@ -13,7 +13,7 @@ def base_hash
def full_hash
base_hash_with_contact.merge(
relationship: relationship,
block: is_blocked? ? BlockPresenter.new(current_user_person_block).base_hash : false,
block: block_details,
is_own_profile: own_profile?,
show_profile_info: public_details? || own_profile? || person_is_following_current_user
)
Expand All @@ -24,7 +24,7 @@ def as_json(_options={})
end

def hovercard
base_hash_with_contact.merge(profile: ProfilePresenter.new(profile).for_hovercard)
base_hash_with_contact.merge(block: block_details, profile: ProfilePresenter.new(profile).for_hovercard)
end

def metas_attributes
Expand Down Expand Up @@ -109,6 +109,10 @@ def is_blocked?
current_user_person_block.present?
end

def block_details
is_blocked? ? BlockPresenter.new(current_user_person_block).base_hash : false
end

def title
name
end
Expand Down

0 comments on commit caccb63

Please sign in to comment.