Completing migration of shares and comments.

This commit is contained in:
Samuel Clay 2012-06-06 20:37:20 -07:00
parent d642688744
commit 213262be8d
8 changed files with 85 additions and 89 deletions

View file

@ -223,9 +223,9 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
if (data.user_profiles) {
this.add_user_profiles(data.user_profiles);
}
callback(data);
var story = this.get_story(story_id);
if (story) story.set('shared_comments', comments);
story.set(data.story);
callback(data);
}, this);
if (NEWSBLUR.Globals.is_authenticated) {

View file

@ -1,6 +1,11 @@
NEWSBLUR.Models.Story = Backbone.Model.extend({
initialize: function() {
this.bind('change:comments', this.populate_comments);
this.populate_comments();
},
populate_comments: function() {
if (this.get('comments')) {
this.comments = new NEWSBLUR.Collections.Comments(this.get('comments'));
}

View file

@ -3728,13 +3728,9 @@
]),
$.make('li', { className: 'NB-menu-manage-story NB-menu-manage-confirm NB-menu-manage-story-share-confirm NB-modal-submit' }, [
$.make('div', { className: 'NB-menu-manage-confirm-position' }, [
$.make('div', { className: 'NB-sideoption-share'}, [
$.make('div', { className: 'NB-sideoption-share-wordcount' }),
$.make('div', { className: 'NB-sideoption-share-optional' }, 'Optional'),
$.make('div', { className: 'NB-sideoption-share-title' }, 'Comments:'),
$.make('textarea', { className: 'NB-sideoption-share-comments' }, story.get('shared_comments')),
$.make('div', { className: 'NB-menu-manage-story-share-save NB-modal-submit-green NB-modal-submit-button' }, 'Share')
])
new NEWSBLUR.Views.StoryShareView({
model: this.model
}).render().el
])
]),
$.make('li', { className: 'NB-menu-separator' }),
@ -5547,12 +5543,6 @@
self.show_confirm_story_share_menu_item();
}
});
$.targetIs(e, { tagSelector: '.NB-menu-manage-story-share-save' }, function($t, $p){
e.preventDefault();
e.stopPropagation();
var story_id = $t.closest('.NB-menu-manage').data('story_id');
self.mark_story_as_shared(story_id, {'source': 'menu'});
});
$.targetIs(e, { tagSelector: '.NB-menu-manage-story-share-confirm' }, function($t, $p){
e.preventDefault();
e.stopPropagation();
@ -6166,11 +6156,6 @@
handle_keyup: function(elem, e) {
var self = this;
$.targetIs(e, { tagSelector: '.NB-sideoption-share-comments' }, function($t, $p) {
e.preventDefault();
self.update_share_button_label($t);
});
},
handle_keystrokes: function() {

View file

@ -34,13 +34,6 @@ NEWSBLUR.Views.ProfileThumb = Backbone.View.extend({
create: function(user_id, options) {
var user = NEWSBLUR.assets.user_profiles.find(user_id);
if (user && user.profile_thumb_view) {
return user.profile_thumb_view;
}
if (!user) {
console.log(["User not found", NEWSBLUR.assets.user_profiles, user_id]);
}
return new NEWSBLUR.Views.ProfileThumb(_.extend({}, {model: user}, options));
}

View file

@ -11,7 +11,6 @@ NEWSBLUR.Views.StoryComment = Backbone.View.extend({
},
initialize: function(options) {
console.log(["init comment", this.model, this]);
this.user = NEWSBLUR.assets.user_profiles.find(this.model.get('user_id'));
},
@ -131,7 +130,6 @@ NEWSBLUR.Views.StoryComment = Backbone.View.extend({
comment_user_id, comment_reply,
original_message,
_.bind(function(data) {
console.log(["save comment", data, this.model]);
this.model.set(data.comment);
this.render();
// this.fetch_story_locations_in_feed_view();

View file

@ -73,10 +73,15 @@ NEWSBLUR.Views.StoryCommentsView = Backbone.View.extend({
<%= Inflector.pluralize("person", story.get("share_count")) %>\
</div>\
<% if (story.get("share_count_public")) { %>\
<div class="NB-story-share-profiles NB-story-share-profiles-public"><div>\
<div class="NB-story-share-profiles NB-story-share-profiles-public"></div>\
<% } %>\
<% } %>\
<% if (story.get("share_count")) { %>\
<% if (story.get("share_count_friends")) { %>\
<div class="NB-story-share-label">Shared by: </div>\
<% } %>\
<% if (story.get("share_count_friends")) { %>\
<div class="NB-story-share-profiles NB-story-share-profiles-friends"><div>\
<div class="NB-story-share-profiles NB-story-share-profiles-friends"></div>\
<% } %>\
<% } %>\
</div>\
@ -90,17 +95,16 @@ NEWSBLUR.Views.StoryCommentsView = Backbone.View.extend({
load_public_story_comments: function() {
var following_user_ids = NEWSBLUR.assets.user_profile.get('following_user_ids');
NEWSBLUR.assets.load_public_story_comments(this.model.id, this.model.get('story_feed_id'), _.bind(function(comments) {
console.log(["comments", comments]);
var $comments = $.make('div', { className: 'NB-story-comments-public' });
var public_comments = comments.select(_.bind(function(comment) {
return !_.contains(following_user_ids, comment.get('user_id'));
}, this));
console.log(["public_comments", public_comments]);
var $header = $.make('div', {
className: 'NB-story-comments-public-header-wrapper'
}, $.make('div', {
className: 'NB-story-comments-public-header'
}, Inflector.pluralize(' public comment', public_comments.length, true))).prependTo($comments);
_.each(public_comments, _.bind(function(comment) {
var $comment = new NEWSBLUR.Views.StoryComment({model: comment, story: this.model}).render().el;
$comments.append($comment);

View file

@ -1,5 +1,31 @@
NEWSBLUR.Views.StoryShareView = Backbone.View.extend({
events: {
"click .NB-feed-story-share" : "toggle_feed_story_share_dialog",
"click .NB-sideoption-share-save" : "mark_story_as_shared",
"keyup .NB-sideoption-share-comments" : "update_share_button_label"
},
render: function() {
this.$el.html(this.template({
story: this.model
}));
return this;
},
template: _.template('\
<div class="NB-sideoption-share-wrapper">\
<div class="NB-sideoption-share">\
<div class="NB-sideoption-share-wordcount"></div>\
<div class="NB-sideoption-share-optional">Optional</div>\
<div class="NB-sideoption-share-title">Comments:</div>\
<textarea class="NB-sideoption-share-comments"><%= story.get("shared_comments") %></textarea>\
<div class="NB-menu-manage-story-share-save NB-modal-submit-green NB-sideoption-share-save NB-modal-submit-button">Share</div>\
</div>\
</div>\
'),
toggle_feed_story_share_dialog: function(options) {
options = options || {};
var feed_id = this.model.get('story_feed_id');
@ -18,9 +44,9 @@ NEWSBLUR.Views.StoryShareView = Backbone.View.extend({
'duration': 300,
'easing': 'easeInOutQuint',
'queue': false,
'complete': function() {
'complete': _.bind(function() {
this.$('.NB-error').remove();
}
}, this)
});
$sideoption.removeClass('NB-active');
if ($story_content.data('original_height')) {
@ -57,7 +83,7 @@ NEWSBLUR.Views.StoryShareView = Backbone.View.extend({
var sideoptions_height = this.$('.NB-feed-story-sideoptions-container').innerHeight() + 12;
var content_height = $story_content.innerHeight() + $story_comments.innerHeight();
// console.log(["heights", full_height + sideoptions_height, content_height]);
if (sideoptions_height + full_height > content_height) {
// this.$s.$feed_stories.scrollTo(this.$s.$feed_stories.scrollTop() + sideoptions_height, {
// 'duration': 350,
@ -87,40 +113,39 @@ NEWSBLUR.Views.StoryShareView = Backbone.View.extend({
mark_story_as_shared: function(options) {
options = options || {};
var $story_title = this.find_story_in_story_titles(this.model.id);
var $feed_story = this.find_story_in_feed_view(this.model.id);
var $share_star = $('.NB-storytitles-share', $story_title);
var $share_button = $('.NB-sideoption-share-save', $feed_story);
var $share_star = this.model.story_title_view.$('.NB-storytitles-share');
var $share_button = this.$('.NB-sideoption-share-save');
var $share_button_menu = $('.NB-menu-manage-story-share-save');
var $share_menu = $share_button_menu.closest('.NB-sideoption-share');
var $share_sideoption = $('.NB-feed-story-share .NB-sideoption-title', $feed_story);
var $comments_sideoptions = $('.NB-sideoption-share-comments', $feed_story);
var $share_sideoption = this.model.story_view.$('.NB-feed-story-share .NB-sideoption-title');
var $comments_sideoptions = this.$('.NB-sideoption-share-comments');
var $comments_menu = $('.NB-sideoption-share-comments', $share_menu);
var comments = _.string.trim((options.source == 'menu' ? $comments_menu : $comments_sideoptions).val());
var feed = NEWSBLUR.reader.model.get_feed(NEWSBLUR.reader.active_feed);
var source_user_id = feed && feed.get('user_id');
$story_title.addClass('NB-story-shared');
this.model.set("shared", true);
$share_button.addClass('NB-saving').addClass('NB-disabled').text('Sharing...');
$share_button_menu.addClass('NB-saving').addClass('NB-disabled').text('Sharing...');
this.model.mark_story_as_shared(story.get('story_feed_id'), comments, source_user_id, _.bind(function(data) {
NEWSBLUR.assets.mark_story_as_shared(this.model.id, this.model.get('story_feed_id'), comments, source_user_id, _.bind(function(data) {
this.toggle_feed_story_share_dialog({'close': true});
this.hide_confirm_story_share_menu_item(true);
NEWSBLUR.reader.hide_confirm_story_share_menu_item(true);
$share_button.removeClass('NB-saving').removeClass('NB-disabled').text('Share');
$share_sideoption.text('Shared').closest('.NB-sideoption');
$feed_story.addClass('NB-story-shared');
this.model.story_view.$el.addClass('NB-story-shared');
$comments_menu.val(comments);
$comments_sideoptions.val(comments);
var $new_comments = $.make('div', { className: 'NB-feed-story-comments' }, new NEWSBLUR.Views.StoryComment({
model: comment,
story: this.model
}).el);
var $old_comments = $('.NB-feed-story-comments', $feed_story);
if (!$old_comments.length) {
$old_comments = $.make('div', { className: 'NB-feed-story-comments' });
$('.NB-feed-story-content', $feed_story).after($old_comments);
}
$old_comments.replaceWith($new_comments);
this.model.story_view.render_comments();
// var $new_comments = $.make('div', { className: 'NB-feed-story-comments' }, new NEWSBLUR.Views.StoryComment({
// model: comment,
// story: this.model
// }).el);
// var $old_comments = this.model.story_view.$('.NB-feed-story-comments');
// if (!$old_comments.length) {
// $old_comments = $.make('div', { className: 'NB-feed-story-comments' });
// this.model.story_view.$('.NB-feed-story-content').after($old_comments);
// }
// $old_comments.replaceWith($new_comments);
$share_star.attr({'title': 'Shared!'});
$share_star.tipsy({
@ -156,21 +181,20 @@ NEWSBLUR.Views.StoryShareView = Backbone.View.extend({
$share_button.siblings('.NB-error').remove();
$share_button.after($error);
if ($share_button_menu.length) {
$share_button_text.removeClass('NB-disabled').text('Share');
$share_button_text.siblings('.NB-error').remove();
$share_button_text.after($error.clone());
$share_button_menu.removeClass('NB-disabled').text('Share');
$share_button_menu.siblings('.NB-error').remove();
$share_button_menu.after($error.clone());
}
this.toggle_feed_story_share_dialog({'resize_open': true});
}, this));
this.blur_to_page();
NEWSBLUR.reader.blur_to_page();
},
update_share_button_label: function($t) {
if (!$t) $t = $('.NB-menu-manage-story-share-save');
var $share = $t.closest('.NB-sideoption-share');
var $comment_input = $('.NB-sideoption-share-comments', $share);
var $share_button = $('.NB-sideoption-share-save,.NB-menu-manage-story-share-save', $share);
update_share_button_label: function() {
var $share = this.$('.NB-sideoption-share');
var $comment_input = this.$('.NB-sideoption-share-comments');
var $share_button = this.$('.NB-sideoption-share-save,.NB-menu-manage-story-share-save');
if (!_.string.isBlank($comment_input.val())) {
$share_button.text('Share with comment');

View file

@ -11,14 +11,12 @@ NEWSBLUR.Views.StoryView = Backbone.View.extend({
"mouseleave .NB-feed-story-manage-icon" : "mouseleave_manage_icon",
"contextmenu .NB-feed-story-header" : "show_manage_menu",
"click .NB-feed-story-manage-icon" : "show_manage_menu",
"click .NB-sideoption-share-save" : "mark_story_as_shared",
"click .NB-feed-story-hide-changes" : "hide_story_changes",
"click .NB-feed-story-header-title" : "open_feed",
"click .NB-feed-story-tag" : "save_classifier",
"click .NB-feed-story-author" : "save_classifier",
"click .NB-feed-story-train" : "open_story_trainer",
"click .NB-feed-story-save" : "star_story",
"click .NB-feed-story-share" : "toggle_feed_story_share_dialog"
"click .NB-feed-story-save" : "star_story"
},
initialize: function() {
@ -34,10 +32,6 @@ NEWSBLUR.Views.StoryView = Backbone.View.extend({
this.$el.bind('mouseleave', this.mouseleave);
this.model.story_view = this;
this.story_share_view = new NEWSBLUR.Views.StoryShareView({
model: this.model,
el: this.el
});
},
// =============
@ -55,7 +49,13 @@ NEWSBLUR.Views.StoryView = Backbone.View.extend({
title : this.make_story_title(),
authors_score : this.classifiers.authors[this.model.get('story_authors')],
tags_score : this.classifiers.tags,
options : this.options
options : this.options,
story_share_view : new NEWSBLUR.Views.StoryShareView({
model: this.model,
el: this.el
}).template({
story: this.model
})
}));
this.toggle_classes();
this.toggle_read_status();
@ -127,15 +127,7 @@ NEWSBLUR.Views.StoryView = Backbone.View.extend({
<div class="NB-sideoption-icon">&nbsp;</div>\
<div class="NB-sideoption-title"><%= story.get("shared") ? "Shared" : "Share this story" %></div>\
</div>\
<div class="NB-sideoption-share-wrapper">\
<div class="NB-sideoption-share">\
<div class="NB-sideoption-share-wordcount"></div>\
<div class="NB-sideoption-share-optional">Optional</div>\
<div class="NB-sideoption-share-title">Comments:</div>\
<textarea class="NB-sideoption-share-comments"><%= story.get("shared_comments") %></textarea>\
<div class="NB-sideoption-share-save NB-modal-submit-button">Share</div>\
</div>\
</div>\
<%= story_share_view %>\
</div>\
'),
@ -168,7 +160,7 @@ NEWSBLUR.Views.StoryView = Backbone.View.extend({
render_comments: function() {
if (this.model.get("comment_count") || this.model.get("share_count")) {
var $comments = new NEWSBLUR.Views.StoryCommentsView({model: this.model}).render().el;
this.$('.NB-feed-story-share-container').replaceWith($comments);
this.$('.NB-feed-story-share-container,.NB-feed-story-comments').replaceWith($comments);
}
},
@ -319,7 +311,6 @@ NEWSBLUR.Views.StoryView = Backbone.View.extend({
show_manage_menu: function(e) {
e.preventDefault();
e.stopPropagation();
// console.log(["showing manage menu", this.model.is_social() ? 'socialfeed' : 'feed', $(this.el), this]);
NEWSBLUR.reader.show_manage_menu('story', this.$el, {
story_id: this.model.id,
feed_id: this.model.get('story_feed_id')
@ -375,11 +366,7 @@ NEWSBLUR.Views.StoryView = Backbone.View.extend({
open_story_in_new_tab: function() {
window.open(this.model.get('story_permalink'), '_blank');
window.focus();
},
toggle_feed_story_share_dialog: function() {
// Check story_share_view.js
}
});