added reshare to mobile site

This commit is contained in:
danielgrippi 2011-10-03 17:02:11 -07:00
parent 56f5efc373
commit 1d818fdc23
8 changed files with 109 additions and 50 deletions

View file

@ -1,6 +1,6 @@
class ResharesController < ApplicationController class ResharesController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
respond_to :js respond_to :js, :json
def create def create
@reshare = current_user.build_post(:reshare, :root_guid => params[:root_guid]) @reshare = current_user.build_post(:reshare, :root_guid => params[:root_guid])

View file

@ -17,6 +17,17 @@
.bottom_bar .bottom_bar
.floater .floater
- if (post.public? || reshare?(post)) && post.author != current_user.person
- if reshare?(post)
- root = post.root
- else
- root = post
- reshare = Reshare.where(:author_id => current_user.person.id, :root_guid => root.guid).first ? "active" : "inactive"
= link_to '', reshares_path(:root_guid => root.guid), :title => t('reshares.reshare.reshare_confirmation', :author => root.author.name), :class => "image_link reshare_action #{reshare}"
= link_to '', new_post_comment_path(post), :class => "image_link comment_action inactive" = link_to '', new_post_comment_path(post), :class => "image_link comment_action inactive"
- if current_user && current_user.liked?(post) - if current_user && current_user.liked?(post)
@ -33,6 +44,10 @@
- if defined?(expanded_info) && expanded_info - if defined?(expanded_info) && expanded_info
.comment_container .comment_container
.post_stats .post_stats
- if @post.public?
%span.comment_count
= @post.reshares.size
%span.comment_count %span.comment_count
= @post.comments.size = @post.comments.size

View file

@ -0,0 +1,9 @@
class AddIndexForReshares < ActiveRecord::Migration
def self.up
add_index :posts, [:author_id, :root_guid], :unique => true
end
def self.down
remove_index :posts, :column => [:author_id, :root_guid]
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20111002013921) do ActiveRecord::Schema.define(:version => 20111003232053) do
create_table "aspect_memberships", :force => true do |t| create_table "aspect_memberships", :force => true do |t|
t.integer "aspect_id", :null => false t.integer "aspect_id", :null => false
@ -285,6 +285,7 @@ ActiveRecord::Schema.define(:version => 20111002013921) do
t.integer "comments_count", :default => 0 t.integer "comments_count", :default => 0
end end
add_index "posts", ["author_id", "root_guid"], :name => "index_posts_on_author_id_and_root_guid", :unique => true
add_index "posts", ["author_id"], :name => "index_posts_on_person_id" add_index "posts", ["author_id"], :name => "index_posts_on_person_id"
add_index "posts", ["guid"], :name => "index_posts_on_guid", :unique => true add_index "posts", ["guid"], :name => "index_posts_on_guid", :unique => true
add_index "posts", ["root_guid"], :name => "index_posts_on_root_guid" add_index "posts", ["root_guid"], :name => "index_posts_on_root_guid"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 764 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 761 B

View file

@ -1,5 +1,15 @@
$(document).ready(function(){ $(document).ready(function(){
var showLoader = function(link){
link.addClass('loading');
};
var removeLoader = function(link){
link.removeClass('loading')
.toggleClass('active')
.toggleClass('inactive');
};
/* Heart toggle */ /* Heart toggle */
$(".like_action", ".stream").bind("tap click", function(evt){ $(".like_action", ".stream").bind("tap click", function(evt){
evt.preventDefault(); evt.preventDefault();
@ -7,48 +17,68 @@ $(document).ready(function(){
likeCounter = $(this).closest(".stream_element").find("like_count"), likeCounter = $(this).closest(".stream_element").find("like_count"),
href = link.attr("href"); href = link.attr("href");
var showLoader = function(link){ if(!link.hasClass("loading")){
link.addClass('loading'); if(link.hasClass('inactive')) {
}; $.ajax({
url: href,
dataType: 'json',
type: 'POST',
beforeSend: showLoader(link),
success: function(data){
removeLoader(link);
link.attr("href", href + "/" + data["id"]);
var removeLoader = function(link){ if(likeCounter){
link.removeClass('loading') likeCounter.text(parseInt(likeCounter.text) + 1);
.toggleClass('active') }
.toggleClass('inactive');
};
if(!link.hasClass("loading") && link.hasClass('inactive')) {
$.ajax({
url: href,
dataType: 'json',
type: 'POST',
beforeSend: showLoader(link),
success: function(data){
removeLoader(link);
link.attr("href", href + "/" + data["id"]);
if(likeCounter){
likeCounter.text(parseInt(likeCounter.text) + 1);
} }
} });
}); }
else if(link.hasClass("active")){
$.ajax({
url: link.attr("href"),
dataType: 'json',
type: 'DELETE',
beforeSend: showLoader(link),
complete: function(data){
removeLoader(link);
link.attr("href", href.replace(/\/\d+$/, ''));
if(likeCounter){
likeCounter.text(parseInt(likeCounter.text) - 1);
}
}
});
}
} }
else if(!link.hasClass("loading") && link.hasClass("active")){ });
$.ajax({
url: link.attr("href"),
dataType: 'json',
type: 'DELETE',
beforeSend: showLoader(link),
complete: function(data){
removeLoader(link);
link.attr("href", href.replace(/\/\d+$/, ''));
if(likeCounter){ /* Reshare */
likeCounter.text(parseInt(likeCounter.text) - 1); $(".reshare_action", ".stream").bind("tap click", function(evt){
} evt.preventDefault();
var link = $(this),
href = link.attr("href"),
confirmText = link.attr('title');
if(!link.hasClass("loading")) {
if(link.hasClass('inactive')) {
if(confirm(confirmText)) {
$.ajax({
url: href + "&provider_display_name=mobile",
dataType: 'json',
type: 'POST',
beforeSend: showLoader(link),
success: function(data){
removeLoader(link);
},
error: function(data){
removeLoader(link);
alert("Failed to reshare!");
}
});
} }
}); }
} }
}); });

View file

@ -614,28 +614,32 @@ footer {
width: 24px; width: 24px;
padding: 5px; padding: 5px;
margin: { margin: {
left: 5px; }; } left: 5px; };
.like_action {
&.inactive{
background-image: url("/images/icons/heart_mobile_grey.png");
}
&.active {
background-image: url("/images/icons/heart_mobile_red.png");
}
&.loading { &.loading {
background-image: url("/images/mobile-spinner.gif"); background-image: url("/images/mobile-spinner.gif");
} }
} }
.reshare_action {
background-image: url("/images/icons/reshare_mobile.png");
&.active {
background-image: url("/images/icons/reshare_mobile_active.png");
}
}
.like_action {
background-image: url("/images/icons/heart_mobile_grey.png");
&.active {
background-image: url("/images/icons/heart_mobile_red.png");
}
}
.comment_action.image_link { .comment_action.image_link {
background-image: url("/images/icons/pencil_mobile_grey_active.png"); background-image: url("/images/icons/pencil_mobile_grey_active.png");
&.inactive { &.inactive {
background-image: url("/images/icons/pencil_mobile_grey.png"); background-image: url("/images/icons/pencil_mobile_grey.png");
} }
&.loading {
background-image: url("/images/mobile-spinner.gif");
}
} }
.compose_icon { .compose_icon {