From 1d818fdc23343b90f0506bc0c4b53170255bc961 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Mon, 3 Oct 2011 17:02:11 -0700 Subject: [PATCH] added reshare to mobile site --- app/controllers/reshares_controller.rb | 2 +- app/views/shared/_stream_element.mobile.haml | 15 +++ .../20111003232053_add_index_for_reshares.rb | 9 ++ db/schema.rb | 3 +- public/images/icons/reshare_mobile.png | Bin 1712 -> 764 bytes public/images/icons/reshare_mobile_active.png | Bin 0 -> 761 bytes public/javascripts/mobile.js | 104 +++++++++++------- public/stylesheets/sass/mobile.scss | 26 +++-- 8 files changed, 109 insertions(+), 50 deletions(-) create mode 100644 db/migrate/20111003232053_add_index_for_reshares.rb create mode 100644 public/images/icons/reshare_mobile_active.png diff --git a/app/controllers/reshares_controller.rb b/app/controllers/reshares_controller.rb index 856426ef7..3e5d5a73b 100644 --- a/app/controllers/reshares_controller.rb +++ b/app/controllers/reshares_controller.rb @@ -1,6 +1,6 @@ class ResharesController < ApplicationController before_filter :authenticate_user! - respond_to :js + respond_to :js, :json def create @reshare = current_user.build_post(:reshare, :root_guid => params[:root_guid]) diff --git a/app/views/shared/_stream_element.mobile.haml b/app/views/shared/_stream_element.mobile.haml index e7066cb79..1a4b9c853 100644 --- a/app/views/shared/_stream_element.mobile.haml +++ b/app/views/shared/_stream_element.mobile.haml @@ -17,6 +17,17 @@ .bottom_bar .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" - if current_user && current_user.liked?(post) @@ -33,6 +44,10 @@ - if defined?(expanded_info) && expanded_info .comment_container .post_stats + - if @post.public? + %span.comment_count + = @post.reshares.size + %span.comment_count = @post.comments.size diff --git a/db/migrate/20111003232053_add_index_for_reshares.rb b/db/migrate/20111003232053_add_index_for_reshares.rb new file mode 100644 index 000000000..d99694fd9 --- /dev/null +++ b/db/migrate/20111003232053_add_index_for_reshares.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 87defb4b6..57297a4e7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # 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| t.integer "aspect_id", :null => false @@ -285,6 +285,7 @@ ActiveRecord::Schema.define(:version => 20111002013921) do t.integer "comments_count", :default => 0 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", ["guid"], :name => "index_posts_on_guid", :unique => true add_index "posts", ["root_guid"], :name => "index_posts_on_root_guid" diff --git a/public/images/icons/reshare_mobile.png b/public/images/icons/reshare_mobile.png index 7b53165ec4b0abdb4fe454c97b14f58f524b751a..91883ea03128cc87f3b14068551e6fdf52c09b93 100644 GIT binary patch delta 716 zcmV;-0yF)v4g3X=83+Ra002ikWoD5fCw~AlP)t-s-{0TR(9rw)`^3b=$jHd^^YicT z@6^=P>+9>x%*^BCMLNDsSfxGGYj=oi`*3vi9x#Mg{>_+RlcN z4S{Is(;38NGrU0tVqWreit)CeOmVOP9D@4D`KfJm`J*{ zu#lm9(h-xb!j>9?gcxmSwA2_3#1sw^mKp<&nDXIHL#`d}uEfA1dW?WX^cdY>fruVs z*+g)N9%K6X$1tQ2<8?d%A*~w2_3N$zLG&-5@IGZB5dHJ|9Rq{tF?@2yx_^)8F?I)& z`^Z@g7IOSnEhA0%P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13c8a9ba0 100644 --- a/public/javascripts/mobile.js +++ b/public/javascripts/mobile.js @@ -1,5 +1,15 @@ $(document).ready(function(){ + var showLoader = function(link){ + link.addClass('loading'); + }; + + var removeLoader = function(link){ + link.removeClass('loading') + .toggleClass('active') + .toggleClass('inactive'); + }; + /* Heart toggle */ $(".like_action", ".stream").bind("tap click", function(evt){ evt.preventDefault(); @@ -7,48 +17,68 @@ $(document).ready(function(){ likeCounter = $(this).closest(".stream_element").find("like_count"), href = link.attr("href"); - var showLoader = function(link){ - link.addClass('loading'); - }; + if(!link.hasClass("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){ - link.removeClass('loading') - .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); + 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){ - likeCounter.text(parseInt(likeCounter.text) - 1); - } + /* Reshare */ + $(".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!"); + } + }); } - }); + } } }); diff --git a/public/stylesheets/sass/mobile.scss b/public/stylesheets/sass/mobile.scss index 37f99c911..4538f6814 100644 --- a/public/stylesheets/sass/mobile.scss +++ b/public/stylesheets/sass/mobile.scss @@ -614,28 +614,32 @@ footer { width: 24px; padding: 5px; 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 { 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 { background-image: url("/images/icons/pencil_mobile_grey_active.png"); &.inactive { background-image: url("/images/icons/pencil_mobile_grey.png"); } - &.loading { - background-image: url("/images/mobile-spinner.gif"); - } } .compose_icon {