Slightly refactoring profile to use new data.

This commit is contained in:
Samuel Clay 2012-03-13 13:18:47 -07:00
parent a2ee769895
commit 0ed8937262
3 changed files with 15 additions and 14 deletions

View file

@ -254,7 +254,7 @@ def profile(request):
'followers_everybody': followers_everybody, 'followers_everybody': followers_everybody,
'following_youknow': following_youknow, 'following_youknow': following_youknow,
'following_everybody': following_everybody, 'following_everybody': following_everybody,
'profiles': [p.to_json(compact=True) for p in profiles], 'profiles': dict([(p.user_id, p.to_json(compact=True)) for p in profiles]),
} }
return payload return payload

View file

@ -4490,7 +4490,7 @@
fade: true, fade: true,
offset: 3 offset: 3
}) })
]).data('user_id', user.get('id')); ]).data('user_id', user_id);
return $profile; return $profile;
}, },

View file

@ -5,7 +5,7 @@ NEWSBLUR.ReaderSocialProfile = function(user_id, options) {
this.options = $.extend({}, defaults, options); this.options = $.extend({}, defaults, options);
this.model = NEWSBLUR.AssetModel.reader(); this.model = NEWSBLUR.AssetModel.reader();
this.profiles = new NEWSBLUR.Collections.Users();
user_id = _.string.ltrim(user_id, 'social:'); user_id = _.string.ltrim(user_id, 'social:');
this.runner(user_id); this.runner(user_id);
}; };
@ -15,6 +15,7 @@ NEWSBLUR.ReaderSocialProfile.prototype = new NEWSBLUR.Modal;
_.extend(NEWSBLUR.ReaderSocialProfile.prototype, { _.extend(NEWSBLUR.ReaderSocialProfile.prototype, {
runner: function(user_id) { runner: function(user_id) {
console.log(["get profile", user_id, this.model.user_profiles.get(user_id)]);
this.profile = this.model.user_profiles.get(user_id); this.profile = this.model.user_profiles.get(user_id);
this.make_modal(); this.make_modal();
this.open_modal(); this.open_modal();
@ -61,29 +62,29 @@ _.extend(NEWSBLUR.ReaderSocialProfile.prototype, {
fetch_profile: function(user_id, callback) { fetch_profile: function(user_id, callback) {
$('.NB-modal-loading', this.$modal).addClass('NB-active'); $('.NB-modal-loading', this.$modal).addClass('NB-active');
this.model.fetch_user_profile(user_id, _.bind(function(data) { this.model.fetch_user_profile(user_id, _.bind(function(data) {
console.log(["profile", data]); console.log(["profile", data]);
$('.NB-modal-loading', this.$modal).removeClass('NB-active'); $('.NB-modal-loading', this.$modal).removeClass('NB-active');
this.profile.set(data.user_profile); this.profile = new NEWSBLUR.Models.User(data.user_profile);
this.populate_friends(data); this.populate_friends(data);
callback && callback(); callback && callback();
this.resize(); _.defer(_.bind(this.resize, this));
}, this)); }, this));
}, },
populate_friends: function(data) { populate_friends: function(data) {
this.profiles = new NEWSBLUR.Collections.Users(data.profiles); _.each(['following_youknow', 'following_everybody', 'followers_youknow', 'followers_everybody'], _.bind(function(f) {
$('.NB-profile-following-youknow', this.$modal).html(this.make_profile_badges(data.following_youknow)); var user_ids = data[f];
$('.NB-profile-following-everybody', this.$modal).html(this.make_profile_badges(data.following_everybody)); var $f = $('.NB-profile-'+f.replace('_', '-'), this.$modal);
$('.NB-profile-followers-youknow', this.$modal).html(this.make_profile_badges(data.followers_youknow)); $f.html(this.make_profile_badges(user_ids, data.profiles));
$('.NB-profile-followers-everybody', this.$modal).html(this.make_profile_badges(data.followers_everybody)); $f.closest('fieldset').toggle(!!user_ids.length);
}, this));
}, },
make_profile_badges: function(user_ids) { make_profile_badges: function(user_ids, profiles) {
var profiles = this.profiles;
var $badges = $.make('div', { className: 'NB-profile-links' }, _.map(user_ids, function(user_id) { var $badges = $.make('div', { className: 'NB-profile-links' }, _.map(user_ids, function(user_id) {
var user = profiles.get(user_id); var user = new NEWSBLUR.Models.User(profiles[user_id]);
return $.make('div', { className: 'NB-profile-link', title: user.get('username') }, [ return $.make('div', { className: 'NB-profile-link', title: user.get('username') }, [
$.make('img', { src: user.get('photo_url') }) $.make('img', { src: user.get('photo_url') })
]).tipsy({ ]).tipsy({