Commit 0092c9c4 authored by Florian Staudacher's avatar Florian Staudacher

* create a handlebars view for the profile header

* unblock the user via ajax
parent fba3092c
......@@ -35,5 +35,17 @@ app.models.Person = Backbone.Model.extend({
// return the jqXHR with Promise interface
return block.save()
.done(function() { app.events.trigger('person:block:'+self.id); });
},
unblock: function() {
var self = this;
if( !this.get('block') ) {
var def = $.Deferred();
return def.reject();
}
var block = new app.models.Block({id: this.get('block').id});
return block.destroy()
.done(function() { app.events.trigger('person:unblock:'+self.id); });
}
});
......@@ -2,11 +2,13 @@
// TODO: update the aspect_membership dropdown, too, every time we render the view...
app.pages.Profile = app.views.Base.extend({
events: {
'click #block_user_button': 'blockPerson'
'click #block_user_button': 'blockPerson',
'click #unblock_user_button': 'unblockPerson'
},
subviews: {
'#profile .badge': 'sidebarView'
'#profile .badge': 'sidebarView',
'.stream_container': 'streamView'
},
tooltipSelector: '.profile_button div, .sharing_message_container',
......@@ -20,6 +22,7 @@ app.pages.Profile = app.views.Base.extend({
// bind to global events
var id = this.model.get('id');
app.events.on('person:block:'+id, this.reload, this);
app.events.on('person:unblock:'+id, this.reload, this);
app.events.on('aspect_membership:update', this.reload, this);
},
......@@ -27,6 +30,10 @@ app.pages.Profile = app.views.Base.extend({
return new app.views.ProfileSidebar({model: this.model});
},
streamView: function() {
return new app.views.ProfileStream({model: this.model});
},
blockPerson: function(evt) {
if( !confirm(Diaspora.I18n.t('ignore_user')) ) return;
......@@ -41,6 +48,17 @@ app.pages.Profile = app.views.Base.extend({
return false;
},
unblockPerson: function(evt) {
var block = this.model.unblock();
block.fail(function() {
Diaspora.page.flashMessages.render({
success: false,
notice: Diaspora.I18.t('unblock_failed')
});
});
return false;
},
reload: function() {
this.model.fetch();
}
......
app.views.ProfileStream = app.views.Base.extend({
templateName: 'profile_stream',
presenter: function() {
return _.extend({}, this.defaultPresenter(), {
is_blocked: this.model.isBlocked()
});
}
});
......@@ -11,7 +11,7 @@
{{#if is_receiving}}
<div class="profile_button">
<a href="" rel="facebox">
<a href="TODO" rel="facebox">
<div id="mention_button" class="icons-mention" title="{{t 'people.mention'}}" data-placement="bottom"></div>
</a>
</div>
......@@ -19,7 +19,7 @@
{{#if is_mutual}}
<div class="profile_button">
<a href="" rel="facebox">
<a href="TODO" rel="facebox">
<div id="message_button" class="icons-message" title="{{t 'people.message'}}" data-placement="bottom"></div>
</a>
</div>
......
<div id="author_info">
<div class="right">
{{#if loggedIn}}
{{#if is_own_profile}}
{{!-- can't block myself, so don't check it here --}}
<a href="TODO" class="button creation">{{t 'people.edit_my_profile'}}</a>
{{/if}}
{{#if is_blocked}}
<a href="#" id="unblock_user_button" class="button">{{t 'people.stop_ignoring'}}</a>
{{else}}
<div class="placeholder aspect_membership_dropdown"></div>
{{/if}}
{{/if}}
</div>
<h2>{{name}}</h2>
<span class="diaspora_handle">{{diaspora_id}}</span>
<div class="description">
</div>
</div>
class BlockPresenter < BasePresenter
def base_hash
{ id: id }
end
end
......@@ -10,6 +10,7 @@ class PersonPresenter < BasePresenter
def full_hash
base_hash.merge({
relationship: relationship,
block: is_blocked? ? BlockPresenter.new(current_user_person_block).base_hash : false,
is_own_profile: own_profile?
})
end
......@@ -45,12 +46,11 @@ class PersonPresenter < BasePresenter
def relationship
contact = current_user.contact_for(@presentable)
is_blocked = current_user.blocks.where(person_id: id).limit(1).any?
is_mutual = contact ? contact.mutual? : false
is_sharing = contact ? contact.sharing? : false
is_receiving = contact ? contact.receiving? : false
if is_blocked then :blocked
if is_blocked? then :blocked
elsif is_mutual then :mutual
elsif is_sharing then :sharing
elsif is_receiving then :receiving
......@@ -59,6 +59,16 @@ class PersonPresenter < BasePresenter
end
def person_is_following_current_user
@presentable.shares_with(@current_user)
@presentable.shares_with(current_user)
end
private
def current_user_person_block
@block ||= current_user.blocks.where(person_id: id).limit(1).first
end
def is_blocked?
current_user_person_block.present?
end
end
......@@ -6,7 +6,18 @@
%h3#aspect_stream_header.stream_title
= stream.title
= render 'publisher/publisher', :selected_aspects => stream.aspects, :aspect_ids => stream.aspect_ids, :aspect => stream.aspect
- aspects = current_user.aspects
- aspect = aspects.first
- aspect_ids = aspects.map { |a| a.id }
- if stream
- aspects = stream.aspects
- aspect = stream.aspect
- aspect_ids = stream.aspect_ids
= render 'publisher/publisher',
selected_aspects: aspects,
aspect_ids: aspect_ids,
aspect: aspect
= render 'aspects/no_posts_message'
#gs-shim{:title => popover_with_close_html("3. #{t('.stay_updated')}"), 'data-content' => t('.stay_updated_explanation')}
......
......@@ -17,6 +17,7 @@ en:
exists: "The report already exists"
ignore_user: "Ignore this user?"
ignore_failed: "Unable to ignore this user"
unblock_failed: "Unblocking this user has failed"
and: "and"
comma: ","
edit: "Edit"
......@@ -117,6 +118,8 @@ en:
not_found: "and no one was found..."
mention: "Mention"
message: "Message"
edit_my_profile: "Edit my profile"
stop_ignoring: "Stop ignoring"
helper:
is_sharing: "<%= name %> is sharing with you"
is_not_sharing: "<%= name %> is not sharing with you"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment