Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* cleanup people_controller#show, add people_controller#stream for json
* introduce new presenters and extend the functionality of the BasePresenter * add a handlebars template for the profile sidebar, render it everytime we need to update * introduce a 'aspect_membership:update' global event
- Loading branch information
Showing
19 changed files
with
332 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
app.models.Person = Backbone.Model.extend({ | ||
urlRoot: '/people', | ||
|
||
url: function() { | ||
return this.urlRoot + '/' + this.get('guid'); | ||
}, | ||
|
||
initialize: function() { | ||
if( this.get('profile') ) | ||
this.profile = new app.models.Profile(this.get('profile')); | ||
}, | ||
|
||
isSharing: function() { | ||
var rel = this.get('relationship'); | ||
return (rel == 'mutual' || rel == 'sharing'); | ||
}, | ||
|
||
isReceiving: function() { | ||
var rel = this.get('relationship'); | ||
return (rel == 'mutual' || rel == 'receiving'); | ||
}, | ||
|
||
isMutual: function() { | ||
return (this.get('relationship') == 'mutual'); | ||
}, | ||
|
||
isBlocked: function() { | ||
return (this.get('relationship') == 'blocked'); | ||
}, | ||
|
||
block: function() { | ||
var self = this; | ||
var block = new app.models.Block({block: {person_id: this.id}}); | ||
|
||
// return the jqXHR with Promise interface | ||
return block.save() | ||
.done(function() { app.events.trigger('person:block:'+self.id); }); | ||
} | ||
}); |
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 |
---|---|---|
@@ -1,44 +1,47 @@ | ||
|
||
// TODO: this view should be model-driven an re-render when it was updated, | ||
// instead of changing classes/attributes on elements. | ||
app.pages.Profile = Backbone.View.extend({ | ||
// 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' | ||
}, | ||
|
||
subviews: { | ||
'#profile .badge': 'sidebarView' | ||
}, | ||
|
||
tooltipSelector: '.profile_button div, .sharing_message_container', | ||
|
||
initialize: function(opts) { | ||
// cache element references | ||
this.el_profile_btns = this.$('#profile_buttons'); | ||
this.el_sharing_msg = this.$('#sharing_message'); | ||
if( app.hasPreload('person') ) | ||
this.model = new app.models.Person(app.parsePreload('person')); | ||
|
||
// init tooltips | ||
this.el_profile_btns.find('.profile_button div, .sharin_message_container') | ||
.tooltip({placement: 'bottom'}); | ||
this.model.on('change', this.render, this); | ||
|
||
// respond to global events | ||
var person_id = this.$('#profile .avatar:first').data('person_id'); | ||
app.events.on('person:block:'+person_id, this._markBlocked, this); | ||
// bind to global events | ||
var id = this.model.get('id'); | ||
app.events.on('person:block:'+id, this.reload, this); | ||
app.events.on('aspect_membership:update', this.reload, this); | ||
}, | ||
|
||
sidebarView: function() { | ||
return new app.views.ProfileSidebar({model: this.model}); | ||
}, | ||
|
||
blockPerson: function(evt) { | ||
if( !confirm(Diaspora.I18n.t('ignore_user')) ) return; | ||
|
||
var person_id = $(evt.target).data('person-id'); | ||
var block = new app.models.Block({block: {person_id: person_id}}); | ||
block.save() | ||
.done(function() { app.events.trigger('person:block:'+person_id); }) | ||
.fail(function() { Diaspora.page.flashMessages.render({ | ||
var block = this.model.block(); | ||
block.fail(function() { | ||
Diaspora.page.flashMessages.render({ | ||
success: false, | ||
notice: Diaspora.I18n.t('ignore_failed') | ||
}); }); | ||
}); | ||
}); | ||
|
||
return false; | ||
}, | ||
|
||
_markBlocked: function() { | ||
this.el_profile_btns.attr('class', 'blocked'); | ||
this.el_sharing_msg.attr('class', 'icons-circle'); | ||
|
||
this.el_profile_btns.find('.profile_button, .white_bar').remove(); | ||
reload: function() { | ||
this.model.fetch(); | ||
} | ||
}); |
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
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,18 @@ | ||
|
||
app.views.ProfileSidebar = app.views.Base.extend({ | ||
templateName: 'profile_sidebar', | ||
|
||
presenter: function() { | ||
return _.extend({}, this.defaultPresenter(), { | ||
do_profile_btns: this._shouldDoProfileBtns(), | ||
is_sharing: this.model.isSharing(), | ||
is_receiving: this.model.isReceiving(), | ||
is_mutual: this.model.isMutual(), | ||
is_not_blocked: !this.model.isBlocked() | ||
}); | ||
}, | ||
|
||
_shouldDoProfileBtns: function() { | ||
return (app.currentUser.authenticated() && !this.model.get('is_own_profile')); | ||
}, | ||
}); |
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,36 @@ | ||
|
||
<div class="profile_photo"> | ||
{{#linkToPerson this}} | ||
{{{personImage this "l"}}} | ||
{{/linkToPerson}} | ||
</div> | ||
|
||
{{#if do_profile_btns}} | ||
<div id="profile_buttons" class="{{relationship}}"> | ||
{{{sharingBadge this}}} | ||
|
||
{{#if is_receiving}} | ||
<div class="profile_button"> | ||
<a href="" rel="facebox"> | ||
<div id="mention_button" class="icons-mention" title="{{t 'people.mention'}}" data-placement="bottom"></div> | ||
</a> | ||
</div> | ||
{{/if}} | ||
|
||
{{#if is_mutual}} | ||
<div class="profile_button"> | ||
<a href="" rel="facebox"> | ||
<div id="message_button" class="icons-message" title="{{t 'people.message'}}" data-placement="bottom"></div> | ||
</a> | ||
</div> | ||
{{/if}} | ||
|
||
{{#if is_not_blocked}} | ||
<div class="profile_button"> | ||
<a href="#" rel="nofollow"> | ||
<div id="block_user_button" class="icons-ignoreuser block_user" title="{{t 'ignore'}}" data-placement="bottom"></div> | ||
</a> | ||
</div> | ||
{{/if}} | ||
</div> | ||
{{/if}} |
Oops, something went wrong.