2012-03-07 17:34:22 -08:00
|
|
|
NEWSBLUR.Views.SocialProfileBadge = Backbone.View.extend({
|
|
|
|
|
|
|
|
events: {
|
|
|
|
"click .NB-profile-badge-action-follow": "follow_user",
|
2012-03-14 12:38:59 -07:00
|
|
|
"click .NB-profile-badge-action-unfollow": "unfollow_user",
|
|
|
|
"click .NB-profile-badge-action-preview": "preview_user"
|
2012-03-07 17:34:22 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
constructor : function(options) {
|
|
|
|
Backbone.View.call(this, options);
|
|
|
|
this.render();
|
|
|
|
|
|
|
|
return this.el;
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
_.bindAll(this, 'render');
|
|
|
|
this.model.bind('change', this.render);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var profile = this.model;
|
2012-03-14 12:38:59 -07:00
|
|
|
this.$el.html($.make('table', {
|
|
|
|
className: "NB-profile-badge " + (this.options.embiggen ? "NB-profile-badge-embiggen" : "")
|
|
|
|
}, [
|
2012-03-07 18:35:17 -08:00
|
|
|
$.make('tr', [
|
|
|
|
$.make('td', [
|
|
|
|
$.make('div', { className: 'NB-profile-badge-photo' }, [
|
2012-03-12 18:11:13 -07:00
|
|
|
$.make('img', { src: profile.photo_url({'size': this.options.photo_size}) })
|
2012-03-07 18:35:17 -08:00
|
|
|
])
|
|
|
|
]),
|
|
|
|
$.make('td', { className: 'NB-profile-badge-info' }, [
|
|
|
|
$.make('div', { className: 'NB-profile-badge-actions' }),
|
|
|
|
$.make('div', { className: 'NB-profile-badge-username' }, profile.get('username')),
|
|
|
|
$.make('div', { className: 'NB-profile-badge-location' }, profile.get('location')),
|
|
|
|
(profile.get('website') && $.make('a', {
|
|
|
|
href: profile.get('website'),
|
|
|
|
target: '_blank',
|
|
|
|
rel: 'nofollow',
|
|
|
|
className: 'NB-profile-badge-website NB-splash-link'
|
|
|
|
}, profile.get('website').replace('http://', ''))),
|
|
|
|
$.make('div', { className: 'NB-profile-badge-bio' }, profile.get('bio')),
|
2012-03-14 12:38:59 -07:00
|
|
|
(_.isNumber(profile.get('shared_stories_count')) &&
|
|
|
|
$.make('div', { className: 'NB-profile-badge-stats' }, [
|
2012-03-07 18:35:17 -08:00
|
|
|
$.make('span', { className: 'NB-count' }, profile.get('shared_stories_count')),
|
|
|
|
'shared ',
|
|
|
|
Inflector.pluralize('story', profile.get('shared_stories_count')),
|
|
|
|
' · ',
|
|
|
|
$.make('span', { className: 'NB-count' }, profile.get('follower_count')),
|
|
|
|
Inflector.pluralize('follower', profile.get('follower_count'))
|
2012-03-08 09:15:33 -08:00
|
|
|
]))
|
2012-03-07 18:35:17 -08:00
|
|
|
])
|
2012-03-07 17:34:22 -08:00
|
|
|
])
|
|
|
|
]));
|
|
|
|
|
|
|
|
var $actions;
|
2012-03-07 18:35:17 -08:00
|
|
|
if (NEWSBLUR.reader.model.user_profile.get('user_id') == profile.get('user_id')) {
|
2012-03-07 17:34:22 -08:00
|
|
|
$actions = $.make('div', { className: 'NB-profile-badge-action-self NB-modal-submit-button' }, 'You');
|
2012-03-07 18:35:17 -08:00
|
|
|
} else if (_.contains(NEWSBLUR.reader.model.user_profile.get('following_user_ids'), profile.get('user_id'))) {
|
2012-03-07 17:34:22 -08:00
|
|
|
$actions = $.make('div', {
|
|
|
|
className: 'NB-profile-badge-action-unfollow NB-modal-submit-button NB-modal-submit-close'
|
|
|
|
}, 'Following');
|
|
|
|
} else {
|
2012-03-14 12:38:59 -07:00
|
|
|
$actions = $.make('div', [
|
|
|
|
$.make('div', {
|
|
|
|
className: 'NB-profile-badge-action-follow NB-modal-submit-button NB-modal-submit-green'
|
|
|
|
}, 'Follow'),
|
|
|
|
$.make('div', {
|
|
|
|
className: 'NB-profile-badge-action-preview NB-modal-submit-button NB-modal-submit-grey'
|
|
|
|
}, 'Preview')
|
|
|
|
]);
|
2012-03-07 17:34:22 -08:00
|
|
|
}
|
|
|
|
this.$('.NB-profile-badge-actions').append($actions);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
follow_user: function() {
|
|
|
|
NEWSBLUR.reader.model.follow_user(this.model.get('user_id'), _.bind(function(data, follow_user) {
|
|
|
|
// this.make_profile_section();
|
|
|
|
this.model.set(follow_user);
|
|
|
|
|
2012-03-14 12:38:59 -07:00
|
|
|
var $button = this.$('.NB-profile-badge-action-follow');
|
2012-03-07 17:34:22 -08:00
|
|
|
$button.text('Following');
|
|
|
|
$button.removeClass('NB-modal-submit-green')
|
|
|
|
.removeClass('NB-modal-submit-red')
|
|
|
|
.addClass('NB-modal-submit-close');
|
|
|
|
$button.removeClass('NB-profile-badge-action-follow')
|
|
|
|
.addClass('NB-profile-badge-action-unfollow');
|
|
|
|
|
|
|
|
NEWSBLUR.reader.make_social_feeds();
|
|
|
|
}, this));
|
|
|
|
},
|
|
|
|
|
|
|
|
unfollow_user: function() {
|
|
|
|
NEWSBLUR.reader.model.unfollow_user(this.model.get('user_id'), _.bind(function(data, unfollow_user) {
|
|
|
|
// this.make_profile_section();
|
|
|
|
this.model.set(unfollow_user);
|
|
|
|
|
2012-03-14 12:38:59 -07:00
|
|
|
var $button = this.$('.NB-profile-badge-action-follow');
|
2012-03-07 17:34:22 -08:00
|
|
|
$button.text('Unfollowed');
|
|
|
|
$button.removeClass('NB-modal-submit-close')
|
|
|
|
.addClass('NB-modal-submit-red');
|
|
|
|
$button.removeClass('NB-profile-badge-action-unfollow')
|
|
|
|
.addClass('NB-profile-badge-action-follow');
|
|
|
|
|
|
|
|
NEWSBLUR.reader.make_social_feeds();
|
|
|
|
}, this));
|
2012-03-14 12:38:59 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
preview_user: function() {
|
|
|
|
$.modal.close(_.bind(function() {
|
2012-03-14 17:48:28 -07:00
|
|
|
window.ss = this.model;
|
|
|
|
var socialsub = NEWSBLUR.reader.model.add_social_feed(this.model);
|
|
|
|
NEWSBLUR.reader.load_social_feed_in_tryfeed_view(socialsub);
|
2012-03-14 12:38:59 -07:00
|
|
|
}, this));
|
2012-03-07 17:34:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|