Permalink
Browse files

Added acts as refineable, ajax loading of refined lists, javascript e…

…ffects and cleaned up js code.
  • Loading branch information...
Russell Branca
Russell Branca committed Feb 20, 2010
1 parent 255ce19 commit 8a61078b69a8610d5bc6defaba89f2abfaeed520
View
@@ -1,4 +1,4 @@
-Copyright (c) 2006-2009 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein
+Copyright (c) 2006-2010 Newscloud
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -4,6 +4,14 @@ class HomeController < ApplicationController
before_filter :set_current_tab
def index
+ if request.post?
+ respond_to do |format|
+ format.html
+ format.fbml
+ format.json { @stories = Content.refine(params) }
+ format.fbjs { @stories = Content.refine(params) }
+ end
+ end
#expires_in 1.minutes, :private => false, :public => true
@no_paginate = true
end
@@ -4,5 +4,11 @@ module FacebookHelper
def fb_mp3(src, options = {})
tag "fb:mp3", options.merge(:src => src)
end
+
+ def fb_jqjs_library
+ "<script>var _token = '#{form_authenticity_token}';var _hostname = '#{ActionController::Base.asset_host}'</script>"+
+ "#{javascript_include_tag 'Utility'}"+
+ "#{javascript_include_tag 'FBjqRY'}"
+ end
end
View
@@ -5,6 +5,7 @@ class Content < ActiveRecord::Base
acts_as_featured_item
acts_as_moderatable
acts_as_media_item
+ acts_as_refineable
belongs_to :user
belongs_to :article
@@ -13,7 +14,7 @@ class Content < ActiveRecord::Base
has_friendly_id :title, :use_slug => true
- named_scope :newest, lambda { |*args| { :order => ["created_at desc"], :limit => (args.first || 5)} }
+ named_scope :newest, lambda { |*args| { :order => ["created_at desc"], :limit => (args.first || 10)} }
named_scope :newest_stories, lambda { |*args| { :conditions => ["article_id IS NULL"], :order => ["created_at desc"], :limit => (args.first || 5)} }
named_scope :newest_articles, lambda { |*args| { :conditions => ["article_id IS NOT NULL"], :order => ["created_at desc"], :limit => (args.first || 5)} }
@@ -25,6 +26,14 @@ class Content < ActiveRecord::Base
validates_format_of :image_url, :with => /\Ahttp(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i, :allow_blank => true, :message => "should look like a URL"
validates_format_of :tags_string, :with => /^([-a-zA-Z0-9_ ]+,?)+$/, :allow_blank => true, :message => "Invalid tags. Tags can be alphanumeric characters or -_ or a blank space."
+ def self.top
+ self.tally({
+ :at_least => 1,
+ :limit => 10,
+ :order => "votes.count desc"
+ })
+ end
+
def is_article?
self.article.present?
end
@@ -0,0 +1 @@
+= render :partial => 'shared/stories', :locals => { :stories => (@stories || nil) }
@@ -0,0 +1 @@
+= render :partial => 'shared/stories'
@@ -1,13 +1,31 @@
%fb:fbml
- = fbjs_library
- %style
- = File.read('public/stylesheets/default.css')
+ = stylesheet_link_tag 'default', 'formtastic', 'formtastic_changes'
+
%style
- = File.read('public/stylesheets/formtastic.css')
- -#%script{:type => "text/javascript"}
+ :sass
+ .bar_link
+ position: relative
+ .refine-box
+ position: absolute
+ width: 150px
+ height: 200px
+ top: 15px
+ left: -65px
+ border: 1px solid black
+ background-color: #B3B3B3
+ z-index: 43
+ display: none
+
+ .refine-content
+ margin-left: 10px
+
+ form
+ margin-left: 10px
%script
== var SITE_URL = "#{APP_CONFIG['fb_ajax_url']}";
- = File.read('public/javascripts/application.fbjs.js')
+ = fb_jqjs_library
+ = javascript_include_tag 'application.fbjs'
+
= fb_connect_javascript_tag
= init_fb_connect "XFBML"
= render :partial => 'shared/header'
@@ -2,13 +2,33 @@
%html{:xmlns => "http://www.w3.org/1999/xhtml", "xmlns:fb" => "http://www.facebook.com/2008/fbml"}
%head
= stylesheet_link_tag 'default.css', 'formtastic.css', 'ui-lightness/jquery-ui-1.7.2.custom.css', 'jquery.jcarousel', 'jcarousel.skin', 'application'
- = javascript_include_tag 'jquery.min', 'jquery.ui.min', 'jquery.jcarousel.pack', 'jquery.application'
+ = javascript_include_tag 'jquery.min', 'jquery.ui.min', 'jquery.jcarousel.pack', 'jquery.quicksand.min', 'jquery.application'
+ = fb_connect_javascript_tag
+ = init_fb_connect "XFBML", :js => :jquery
= auto_discovery_link_tag(:atom, stories_path(:format => :atom))
%style
:sass
.body-wrapper
width: 760px
padding-left: 25px
+ .bar_link
+ position: relative
+ .refine-box
+ position: absolute
+ width: 150px
+ height: 200px
+ top: 15px
+ left: -65px
+ border: 1px solid black
+ background-color: #B3B3B3
+ z-index: 43
+ display: none
+
+ .refine-content
+ margin-left: 10px
+
+ form
+ margin-left: 10px
%body
.body-wrapper
@@ -0,0 +1,17 @@
+- stories ||= Content.paginate :page => params[:page], :per_page => 10, :order => "created_at desc"
+%ul
+ - stories.each do |content|
+ %li{'data-id' => content.cache_key}
+ .thumb
+ - if content.content_image.present?
+ %img{:alt => "story image", :src => content.content_image.url}
+ .storyBlockWrap
+ %p.storyHead= link_to content.title, story_path(content)
+ %p.storyCaption= linked_story_caption content
+ .profilePic= local_linked_profile_pic content.user
+ .storyBlockMeta
+ %p= t('.stories_posted_by', :fb_name => local_linked_profile_name(content.user), :date => time_ago_in_words(content.created_at))
+ %p
+ %span.btn_left== #{link_to t('.stories_like'), like_story_path(content.id), :class => "voteLink"} #{content.votes.size}
+ %span.btn_mid== #{link_to t('.stories_comments'), story_path(content, :anchor => "commentListTop")} #{content.comments_count}
+ %span.btn_right= t('.stories_share')
@@ -4,6 +4,9 @@
.panel_1
.panelBar.clearfix
%h2= t('.stories_title')
+ - if contents.first.refineable?
+ .bar_link
+ = render :partial => 'shared/forms/refine_dropdown'
.subtitle
%span= t('.stories_subtitle')
.storyList
@@ -4,13 +4,16 @@
.panel_1
.panelBar.clearfix
%h2= t('.stories_title')
+ - if contents.first.refineable?
+ .bar_link
+ = render :partial => 'shared/forms/refine_dropdown'
.subtitle
%span= t('.stories_subtitle')
.storyList
- .list_stories.clearfix
+ #front-stories.list_stories.clearfix
%ul
- contents.each do |content|
- %li
+ %li{'data-id' => content.cache_key}
.thumb
- if content.content_image.present?
%img{:alt => "story image", :src => content.content_image.url}
@@ -0,0 +1,17 @@
+- stories ||= Content.paginate :page => params[:page], :per_page => 10, :order => "created_at desc"
+%ul
+ - stories.each do |content|
+ %li{'data-id' => content.cache_key}
+ .thumb
+ - if content.content_image.present?
+ %img{:alt => "story image", :src => content.content_image.url}
+ .storyBlockWrap
+ %p.storyHead= link_to content.title, story_path(content)
+ %p.storyCaption= linked_story_caption content
+ .profilePic= local_linked_profile_pic content.user
+ .storyBlockMeta
+ %p= t('.stories_posted_by', :fb_name => local_linked_profile_name(content.user), :date => time_ago_in_words(content.created_at))
+ %p
+ %span.btn_left== #{link_to t('.stories_like'), like_story_path(content.id), :class => "voteLink"} #{content.votes.size}
+ %span.btn_mid== #{link_to t('.stories_comments'), story_path(content, :anchor => "commentListTop")} #{content.comments_count}
+ %span.btn_right= t('.stories_share')
@@ -0,0 +1,11 @@
+= link_to 'Refine Results', '#', :class => "refine-toggle"
+.refine-box{:style => "display: none"}
+ .refine-content
+ %p Refine Results
+ - form_tag nil, :class => "refine-form", :id => 'refine-form' do
+ = label_tag :sort_by, 'Sort By:'
+ %br
+ = select_tag :sort_by, options_for_select(['Newest', 'Top'].collect {|k| [k, k]})
+ %br
+ %br
+ = submit_tag "Go"
@@ -0,0 +1,11 @@
+= link_to 'Refine Results', '#', :class => "refine-toggle"
+.refine-box{:style => "display: none"}
+ .refine-content
+ %p Refine Results
+ - form_tag nil, :class => "refine-form", :id => 'refine-form' do
+ = label_tag :sort_by, 'Sort By:'
+ %br
+ = select_tag :sort_by, options_for_select(['Newest', 'Top'].collect {|k| [k, k]})
+ %br
+ %br
+ = submit_tag "Go"
@@ -13,3 +13,7 @@
# Load acts_as_moderatable mixin
require "#{RAILS_ROOT}/lib/acts_as_moderatable.rb"
ActiveRecord::Base.send :include, Newscloud::Acts::Moderatable
+
+# Load acts_as_refineable mixin
+require "#{RAILS_ROOT}/lib/acts_as_refineable.rb"
+ActiveRecord::Base.send :include, Newscloud::Acts::Refineable
View
@@ -15,7 +15,7 @@
map.resources :users, :collection => {:link_user_accounts => :get, :invite => [:get, :post]}
map.resource :session
- map.resources :home, :collection => { :app_tab => [:get, :post], :google_ads => [:get], :bookmarklet_panel => [:get], :about => :get, :faq => :get, :terms => :get, :contact_us => [:get, :post] }, :member => { :render_widget => [:get, :post] }
+ map.resources :home, :collection => { :index => [:get, :post], :app_tab => [:get, :post], :google_ads => [:get], :bookmarklet_panel => [:get], :about => :get, :faq => :get, :terms => :get, :contact_us => [:get, :post] }, :member => { :render_widget => [:get, :post] }
map.paged_stories_with_format '/stories/page/:page.:format', :controller => 'stories', :action => 'index'
map.paged_stories '/stories/page/:page', :controller => 'stories', :action => 'index'
@@ -11,6 +11,10 @@ def self.included(base)
module ClassMethods
+ def refineable?
+ false
+ end
+
end
module InstanceMethods
@@ -19,6 +23,14 @@ def moderatable?
false
end
+ def refineable?
+ false
+ end
+
+ def featured_item?
+ false
+ end
+
def media_item?
false
end
@@ -17,6 +17,10 @@ def acts_as_featured_item
end
module InstanceMethods
+ def featured_item?
+ true
+ end
+
def featured_url
# To use a custom path create a Model.featured_url function
# and return as hash like so:
View
@@ -0,0 +1,61 @@
+require 'active_record'
+
+module Newscloud
+ module Acts
+ module Refineable
+
+ def self.included(base)
+ base.extend ClassMethods
+ end
+
+ module ClassMethods
+ def acts_as_refineable
+
+ include Newscloud::Acts::Refineable::InstanceMethods
+ extend Newscloud::Acts::Refineable::RefineClassMethods
+ end
+ end
+
+ module RefineClassMethods
+
+ def refineable?
+ true
+ end
+
+ def refine(params)
+ refineable_params = ['sort_by', 'category', 'section']
+
+ chains = []
+ params.each do |key, value|
+ next unless refineable_params.index(key)
+ if key == 'sort_by'
+ value = value.downcase
+ case value.downcase
+ when 'newest'
+ chains << value if self.respond_to?(value)
+ when 'top'
+ chains << value if self.respond_to?(value)
+ else
+ end
+ elsif key == 'category'
+ elsif key == 'section'
+ end
+ end
+
+ result = chains.empty? ?
+ self.all(:limit => 10, :order => "created_at desc") :
+ chains.inject(self) { |chain, scope| chain.send(scope) }
+ end
+
+ end
+
+ module InstanceMethods
+
+ def refineable?
+ true
+ end
+
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 8a61078

Please sign in to comment.