2012-02-22 09:11:35 -08:00
|
|
|
NEWSBLUR.ReaderSocialProfile = function(user_id, options) {
|
2012-02-21 10:06:12 -08:00
|
|
|
var defaults = {
|
|
|
|
width: 800
|
|
|
|
};
|
|
|
|
|
|
|
|
this.options = $.extend({}, defaults, options);
|
2012-05-17 18:40:46 -07:00
|
|
|
this.model = NEWSBLUR.assets;
|
2012-03-13 13:18:47 -07:00
|
|
|
this.profiles = new NEWSBLUR.Collections.Users();
|
2012-04-10 17:28:00 -07:00
|
|
|
user_id = parseInt(_.string.ltrim(user_id, 'social:'), 10);
|
2012-02-22 09:11:35 -08:00
|
|
|
this.runner(user_id);
|
2012-02-21 10:06:12 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
NEWSBLUR.ReaderSocialProfile.prototype = new NEWSBLUR.Modal;
|
|
|
|
|
|
|
|
_.extend(NEWSBLUR.ReaderSocialProfile.prototype, {
|
|
|
|
|
2012-02-22 09:11:35 -08:00
|
|
|
runner: function(user_id) {
|
2012-04-17 15:37:01 -07:00
|
|
|
if (!this.model.user_profiles.find(user_id)) {
|
|
|
|
this.model.add_user_profiles([{user_id: user_id}]);
|
|
|
|
}
|
2012-03-14 12:38:59 -07:00
|
|
|
this.profile = this.model.user_profiles.find(user_id).clone();
|
2012-02-21 10:06:12 -08:00
|
|
|
this.make_modal();
|
|
|
|
this.open_modal();
|
2012-02-22 09:11:35 -08:00
|
|
|
_.defer(_.bind(this.fetch_profile, this, user_id));
|
2012-04-21 16:14:53 -07:00
|
|
|
|
|
|
|
this.profile.bind('change', _.bind(this.populate_friends, this));
|
2012-02-21 10:06:12 -08:00
|
|
|
this.$modal.bind('click', $.rescope(this.handle_click, this));
|
|
|
|
},
|
|
|
|
|
|
|
|
make_modal: function() {
|
|
|
|
var self = this;
|
2012-03-13 16:58:50 -07:00
|
|
|
this.$profile = new NEWSBLUR.Views.SocialProfileBadge({
|
2012-03-07 18:35:17 -08:00
|
|
|
model: this.profile,
|
2012-03-12 18:11:13 -07:00
|
|
|
embiggen: true,
|
2012-07-28 19:53:38 -07:00
|
|
|
photo_size: 'large',
|
|
|
|
show_edit_button: true
|
2012-03-07 18:35:17 -08:00
|
|
|
});
|
|
|
|
|
2012-02-21 10:06:12 -08:00
|
|
|
this.$modal = $.make('div', { className: 'NB-modal NB-modal-profile' }, [
|
2012-03-08 09:15:33 -08:00
|
|
|
$.make('div', { className: 'NB-modal-loading' }),
|
2012-03-13 16:58:50 -07:00
|
|
|
$.make('div', { className: 'NB-profile-info-header' }, $(this.$profile)),
|
2013-04-11 16:54:21 -07:00
|
|
|
$.make('fieldset', { className: 'NB-profile-section NB-profile-section-activities' }, [
|
|
|
|
$.make('legend', 'Recent interactions'),
|
2012-04-19 19:09:31 -07:00
|
|
|
$.make('div', { className: 'NB-profile-activities' })
|
|
|
|
]),
|
2012-02-21 10:06:12 -08:00
|
|
|
$.make('div', { className: 'NB-profile-section' }, [
|
2012-03-13 16:58:50 -07:00
|
|
|
$.make('table', { className: 'NB-profile-followers' }, [
|
|
|
|
$.make('tr', [
|
|
|
|
$.make('td', { className: 'NB-profile-follow-count' }, [
|
2012-03-14 12:38:59 -07:00
|
|
|
$.make('div', { className: 'NB-profile-following-count' }, this.profile.get('following_count')),
|
|
|
|
$.make('h3', 'Following')
|
2012-03-13 16:58:50 -07:00
|
|
|
]),
|
|
|
|
$.make('td', [
|
|
|
|
$.make('fieldset', [
|
2012-06-27 17:10:44 -07:00
|
|
|
$.make('legend', 'People you know'),
|
2012-03-14 12:38:59 -07:00
|
|
|
$.make('div', { className: 'NB-modal-section NB-profile-following-youknow' })
|
2012-03-13 16:58:50 -07:00
|
|
|
]),
|
|
|
|
$.make('fieldset', [
|
|
|
|
$.make('legend', 'Everybody'),
|
2012-03-14 12:38:59 -07:00
|
|
|
$.make('div', { className: 'NB-modal-section NB-profile-following-everybody' })
|
2012-03-13 16:58:50 -07:00
|
|
|
])
|
|
|
|
])
|
|
|
|
])
|
2012-02-21 10:06:12 -08:00
|
|
|
])
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-profile-section' }, [
|
2012-03-13 16:58:50 -07:00
|
|
|
$.make('table', { className: 'NB-profile-followers' }, [
|
|
|
|
$.make('tr', [
|
|
|
|
$.make('td', { className: 'NB-profile-follow-count' }, [
|
2012-03-14 12:38:59 -07:00
|
|
|
$.make('div', { className: 'NB-profile-follower-count' }, this.profile.get('followers_count')),
|
|
|
|
$.make('h3', 'Followers')
|
2012-03-13 16:58:50 -07:00
|
|
|
]),
|
|
|
|
$.make('td', [
|
|
|
|
$.make('fieldset', [
|
2012-06-27 17:10:44 -07:00
|
|
|
$.make('legend', 'People you know'),
|
2012-03-14 12:38:59 -07:00
|
|
|
$.make('div', { className: 'NB-modal-section NB-profile-followers-youknow' })
|
2012-03-13 16:58:50 -07:00
|
|
|
]),
|
|
|
|
$.make('fieldset', [
|
|
|
|
$.make('legend', 'Everybody'),
|
2012-03-14 12:38:59 -07:00
|
|
|
$.make('div', { className: 'NB-modal-section NB-profile-followers-everybody' })
|
2012-03-13 16:58:50 -07:00
|
|
|
])
|
|
|
|
])
|
|
|
|
])
|
2012-02-21 10:06:12 -08:00
|
|
|
])
|
|
|
|
])
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
2012-02-22 09:11:35 -08:00
|
|
|
fetch_profile: function(user_id, callback) {
|
2012-02-21 10:06:12 -08:00
|
|
|
$('.NB-modal-loading', this.$modal).addClass('NB-active');
|
2012-03-13 13:18:47 -07:00
|
|
|
|
2012-02-22 09:11:35 -08:00
|
|
|
this.model.fetch_user_profile(user_id, _.bind(function(data) {
|
2012-03-08 09:15:33 -08:00
|
|
|
$('.NB-modal-loading', this.$modal).removeClass('NB-active');
|
2012-04-19 19:09:31 -07:00
|
|
|
this.profiles = data.profiles;
|
|
|
|
this.activities = data.activities;
|
|
|
|
this.data = data;
|
2012-08-31 14:46:56 -07:00
|
|
|
|
|
|
|
this.profile.set(data.user_profile);
|
|
|
|
// this.populate_friends(); # Bound to this.profile's change
|
2012-04-19 19:09:31 -07:00
|
|
|
this.populate_activities(data.activities_html);
|
2012-04-17 15:20:21 -07:00
|
|
|
this.load_images_and_resize();
|
2012-02-21 10:06:12 -08:00
|
|
|
callback && callback();
|
|
|
|
}, this));
|
|
|
|
},
|
|
|
|
|
2012-08-31 14:46:56 -07:00
|
|
|
populate_friends: function() {
|
|
|
|
// NEWSBLUR.log(["populate_friends", this.profile.get('followers_youknow')]);
|
2012-03-13 13:18:47 -07:00
|
|
|
_.each(['following_youknow', 'following_everybody', 'followers_youknow', 'followers_everybody'], _.bind(function(f) {
|
2012-04-21 16:14:53 -07:00
|
|
|
var user_ids = this.profile.get(f);
|
2012-03-13 13:18:47 -07:00
|
|
|
var $f = $('.NB-profile-'+f.replace('_', '-'), this.$modal);
|
2012-04-19 19:09:31 -07:00
|
|
|
$f.html(this.make_profile_badges(user_ids, this.profiles));
|
2012-03-13 13:18:47 -07:00
|
|
|
$f.closest('fieldset').toggle(!!user_ids.length);
|
|
|
|
}, this));
|
2012-04-21 16:14:53 -07:00
|
|
|
$('.NB-profile-follower-count', this.$modal).text(this.profile.get('follower_count'));
|
|
|
|
$('.NB-profile-following-count', this.$modal).text(this.profile.get('following_count'));
|
2012-04-21 16:42:59 -07:00
|
|
|
_.defer(_.bind(this.resize, this));
|
2012-02-21 10:06:12 -08:00
|
|
|
},
|
|
|
|
|
2012-04-19 19:09:31 -07:00
|
|
|
populate_activities: function(activities_html) {
|
|
|
|
var $activities = $('.NB-profile-activities', this.$modal).empty();
|
|
|
|
var $section = $(".NB-profile-section-activities", this.$modal);
|
|
|
|
|
|
|
|
if (!this.activities.length) {
|
|
|
|
$section.hide();
|
|
|
|
} else {
|
|
|
|
$section.show();
|
|
|
|
// Ugh, hate how this is in a Django template.
|
|
|
|
$activities.html(activities_html);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-17 15:20:21 -07:00
|
|
|
load_images_and_resize: function() {
|
|
|
|
var $images = $('img', this.$modal);
|
|
|
|
var image_count = $images.length;
|
2020-06-09 15:37:04 -04:00
|
|
|
$images.on('load', _.bind(function() {
|
2012-04-17 15:20:21 -07:00
|
|
|
if (image_count > 1) {
|
|
|
|
image_count -= 1;
|
|
|
|
} else {
|
|
|
|
this.resize();
|
|
|
|
}
|
|
|
|
}, this));
|
|
|
|
},
|
|
|
|
|
2012-03-13 13:18:47 -07:00
|
|
|
make_profile_badges: function(user_ids, profiles) {
|
2012-05-09 14:48:10 -07:00
|
|
|
$('.tipsy').remove();
|
2012-03-12 18:11:13 -07:00
|
|
|
var $badges = $.make('div', { className: 'NB-profile-links' }, _.map(user_ids, function(user_id) {
|
2012-03-13 13:18:47 -07:00
|
|
|
var user = new NEWSBLUR.Models.User(profiles[user_id]);
|
2012-03-12 18:11:13 -07:00
|
|
|
return $.make('div', { className: 'NB-profile-link', title: user.get('username') }, [
|
|
|
|
$.make('img', { src: user.get('photo_url') })
|
|
|
|
]).tipsy({
|
|
|
|
gravity: 's',
|
2012-06-27 17:10:44 -07:00
|
|
|
delayIn: 1,
|
2012-03-12 18:11:13 -07:00
|
|
|
offset: 3
|
|
|
|
}).data('user_id', user_id);
|
2012-02-22 09:11:35 -08:00
|
|
|
}));
|
2012-02-21 10:06:12 -08:00
|
|
|
return $badges;
|
|
|
|
},
|
2012-03-12 18:11:13 -07:00
|
|
|
|
|
|
|
// ===========
|
|
|
|
// = Actions =
|
|
|
|
// ===========
|
2012-02-21 10:06:12 -08:00
|
|
|
|
|
|
|
open_modal: function(callback) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.$modal.modal({
|
|
|
|
'minWidth': this.options.width,
|
|
|
|
'maxWidth': this.options.width,
|
|
|
|
'overlayClose': true,
|
|
|
|
'onOpen': function (dialog) {
|
|
|
|
dialog.overlay.fadeIn(200, function () {
|
|
|
|
dialog.container.fadeIn(200);
|
|
|
|
dialog.data.fadeIn(200, function() {
|
|
|
|
if (self.options.onOpen) {
|
|
|
|
self.options.onOpen();
|
|
|
|
}
|
2012-02-24 16:14:24 -08:00
|
|
|
self.resize();
|
2012-02-21 10:06:12 -08:00
|
|
|
});
|
2012-02-24 16:14:24 -08:00
|
|
|
self.resize();
|
2012-02-21 10:06:12 -08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
'onShow': function(dialog) {
|
|
|
|
$('#simplemodal-container').corner('6px');
|
|
|
|
if (self.options.onShow) {
|
|
|
|
self.options.onShow();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'onClose': function(dialog, callback) {
|
|
|
|
dialog.data.hide().empty().remove();
|
|
|
|
dialog.container.hide().empty().remove();
|
|
|
|
dialog.overlay.fadeOut(200, function() {
|
|
|
|
dialog.overlay.empty().remove();
|
|
|
|
$.modal.close(callback);
|
|
|
|
});
|
|
|
|
$('.NB-modal-holder').empty().remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// ===========
|
|
|
|
// = Actions =
|
|
|
|
// ===========
|
|
|
|
|
|
|
|
handle_click: function(elem, e) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$.targetIs(e, { tagSelector: '.NB-account-link' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
self.close_and_load_account();
|
|
|
|
});
|
2012-03-12 18:11:13 -07:00
|
|
|
$.targetIs(e, { tagSelector: '.NB-profile-link' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var user_id = $t.data('user_id');
|
|
|
|
$t.tipsy('hide').tipsy('disable');
|
|
|
|
self.fetch_profile(user_id);
|
|
|
|
});
|
2012-08-31 14:46:56 -07:00
|
|
|
$.targetIs(e, { tagSelector: '.NB-activity-follow' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
var user_id = $t.data('userId');
|
|
|
|
$t.tipsy('hide').tipsy('disable');
|
|
|
|
self.fetch_profile(user_id);
|
|
|
|
});
|
2012-08-27 14:10:34 -07:00
|
|
|
|
2012-02-21 10:06:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|