Skip to content

Commit

Permalink
fixes to invitations and contests controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Bornsztein committed Nov 13, 2008
1 parent c99a03b commit ae9c167
Show file tree
Hide file tree
Showing 19 changed files with 147 additions and 107 deletions.
9 changes: 9 additions & 0 deletions app/controllers/admin_controller.rb
@@ -1,6 +1,15 @@
class AdminController < BaseController
before_filter :admin_required

def contests
@contests = Contest.find(:all)

respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @contests.to_xml }
end
end

def messages
@user = current_user
@messages = Message.find(:all, :page => {:current => params[:page], :size => 50}, :order => 'created_at DESC')
Expand Down
38 changes: 12 additions & 26 deletions app/controllers/contests_controller.rb
@@ -1,42 +1,40 @@
class ContestsController < BaseController
before_filter :login_required, :except => [:show]
before_filter :admin_required, :except => [:show]
before_filter :login_required, :except => [:show, :current]
before_filter :admin_required, :except => [:show, :current, :index]

uses_tiny_mce(:options => AppConfig.default_mce_options, :only => [:new, :edit ])
# GET /contests
# GET /contests.xml

def current
@contest = Contest.current
redirect_to :action => "index" and return unless @contest
render :action => 'show'
end


def index
@contests = Contest.find(:all)

respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @contests.to_xml }
format.html
end
end

# GET /contests/1
# GET /contests/1.xml
def show
@contest = Contest.find(params[:id])

respond_to do |format|
format.html # show.rhtml
format.xml { render :xml => @contest.to_xml }
format.html
end
end

# GET /contests/new
def new
@contest = Contest.new
end

# GET /contests/1;edit
def edit
@contest = Contest.find(params[:id])
end

# POST /contests
# POST /contests.xml
def create
@contest = Contest.new(params[:contest])

Expand All @@ -45,42 +43,30 @@ def create
flash[:notice] = :contest_was_successfully_created.l

format.html { redirect_to contest_url(@contest) }
format.xml do
headers["Location"] = contest_url(@contest)
render :nothing => true, :status => "201 Created"
end
else
format.html { render :action => "new" }
format.xml { render :xml => @contest.errors.to_xml }
end
end
end

# PUT /contests/1
# PUT /contests/1.xml
def update
@contest = Contest.find(params[:id])

respond_to do |format|
if @contest.update_attributes(params[:contest])
format.html { redirect_to contest_url(@contest) }
format.xml { render :nothing => true }
else
format.html { render :action => "edit" }
format.xml { render :xml => @contest.errors.to_xml }
end
end
end

# DELETE /contests/1
# DELETE /contests/1.xml
def destroy
@contest = Contest.find(params[:id])
@contest.destroy

respond_to do |format|
format.html { redirect_to contests_url }
format.xml { render :nothing => true }
end
end
end
27 changes: 11 additions & 16 deletions app/controllers/invitations_controller.rb
@@ -1,43 +1,38 @@
class InvitationsController < BaseController
before_filter :require_current_user, :only => [:create, :edit, :update, :destroy, :index]
# GET /invitations
# GET /invitations.xml
before_filter :login_required

def index
@user = User.find(params[:user_id])
@user = current_user
@invitations = @user.invitations

respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @invitations.to_xml }
format.html
end
end

# GET /invitations/1
# GET /invitations/1.xml

def show
@invitation = Invitation.find(params[:id])

respond_to do |format|
format.html # show.rhtml
format.xml { render :xml => @invitation.to_xml }
format.html
end
end

# GET /invitations/new

def new
@user = User.find(params[:user_id])
@user = current_user
@invitation = Invitation.new
end

# GET /invitations/1;edit

def edit
@invitation = Invitation.find(params[:id])
end

# POST /invitations
# POST /invitations.xml

def create
@user = User.find(params[:user_id])
@user = current_user

@invitation = Invitation.new(params[:invitation])
@invitation.user = @user
Expand Down
27 changes: 26 additions & 1 deletion app/models/contest.rb
Expand Up @@ -4,9 +4,13 @@ class Contest < ActiveRecord::Base

validates_presence_of :begin, :end, :title, :banner_title, :banner_subtitle

named_scope :active, :conditions => ["begin < ? AND end > ?", Time.now, Time.now], :order => 'created_at desc'

def self.current
active.find(:first)
end

def transform_post
#self.post = Post.convert_to_html(self.raw_post, 'textile')
self.post = white_list(self.raw_post)
end

Expand All @@ -17,5 +21,26 @@ def self.get_active
def active?
(self.begin < Time.now ) and (self.end > Time.now )
end

def time_and_date
if spans_days?
string = "#{start_time.strftime("%B %d")} to #{end_time.strftime("%B %d %Y")}"
else
string = "#{start_time.strftime("%B %d, %Y")}, #{start_time.strftime("%I:%M %p")} - #{end_time.strftime("%I:%M %p")}"
end
end

def spans_days?
(end_time - start_time) >= 86400
end

def start_time
self.begin
end

def end_time
self.end
end


end
3 changes: 3 additions & 0 deletions app/models/invitation.rb
@@ -1,4 +1,6 @@
class Invitation < ActiveRecord::Base
acts_as_activity :user

belongs_to :user

after_save :send_invite
Expand All @@ -12,6 +14,7 @@ class Invitation < ActiveRecord::Base
invalid_emails = []
email_addresses = email_addresses || ''
emails = email_addresses.split(",").collect{|email| email.strip }.uniq

emails.each{ |email|
unless email =~ /[\w._%-]+@[\w.-]+.[a-zA-Z]{2,4}/
invalid_emails << email
Expand Down
3 changes: 3 additions & 0 deletions app/views/activities/_activity.html.haml
Expand Up @@ -28,6 +28,9 @@
- when 'Clipping'
=:added_a_clipping.l
= link_to image_tag( activity.item.image_uri(:thumb), :width => '50px'), user_clipping_path(activity.item.user, activity.item)
- when 'Invitation'
=:invited_friends.l

- else
- case activity.action
- when 'updated_profile'
Expand Down
31 changes: 31 additions & 0 deletions app/views/admin/contests.html.haml
@@ -0,0 +1,31 @@
.yui-b
= render :partial => 'shared/admin_nav' if current_user.admin?

#yui-main
.yui-b
.box
%h3= :contests.l
= link_to :new_contest.l, new_contest_path

%table{:width=>"100%"}
%tr
%th= :date.l
%th= :title.l
%th= :description.l
%th= :begin.l
%th= :end.l
%th= :actions.l

- for contest in @contests
%tr
%td=h contest.created_at.strftime("%m/%d/%y")
%td=h contest.title
%td=h truncate(contest.post, 250)
%td=h contest.begin.strftime("%m/%d/%y")
%td=h contest.end.strftime("%m/%d/%y")
%td
= link_to :show.l, contest_path(contest)
%br
= link_to :edit.l, edit_contest_path(contest)
%br
= link_to :destroy.l, contest_path(contest), :confirm => :are_you_sure.l, :method => :delete
31 changes: 6 additions & 25 deletions app/views/contests/index.html.haml
@@ -1,31 +1,12 @@
.yui-b
= render :partial => 'shared/admin_nav' if current_user.admin?


#yui-main
.yui-b
.box
%h3= :contests.l
= link_to :new_contest.l, new_contest_path

%table{:width=>"100%"}
%tr
%th= :date.l
%th= :title.l
%th= :description.l
%th= :begin.l
%th= :end.l
%th= :actions.l

- for contest in @contests
%tr
%td=h contest.created_at.strftime("%m/%d/%y")
%td=h contest.title
%td=h truncate(contest.post, 250)
%td=h contest.begin.strftime("%m/%d/%y")
%td=h contest.end.strftime("%m/%d/%y")
%td
= link_to :show.l, contest_path(contest)
%br
= link_to :edit.l, edit_contest_path(contest)
%br
= link_to :destroy.l, contest_path(contest), :confirm => :are_you_sure.l, :method => :delete
- @contests.each do |contest|
%h2
=link_to contest.title, contest
%small
%em=contest.time_and_date
2 changes: 1 addition & 1 deletion app/views/contests/show.rhtml
Expand Up @@ -27,7 +27,7 @@
<small><%= :for_detailed_contest_rules.l %> <a href="/rules.html"><%= :click_here.l %></a>.</small>
</div>
<% else %>
<h3><%= :his_contest_is_closed.l %></h3>
<h3><%= :this_contest_is_closed.l %></h3>
<% end %>
</div>

10 changes: 0 additions & 10 deletions app/views/invitations/edit.rhtml

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/invitations/index.rhtml
Expand Up @@ -7,9 +7,6 @@
<% for invitation in @invitations %>
<tr>
<td><%= invitation.email_addresses %></td>
<td><%= link_to :show.l, user_invitation_path(current_user, invitation) %></td>
<td><%= link_to :edit.l, edit_user_invitation_path(current_user, invitation) %></td>
<td><%= link_to :destroy.l, user_invitation_path(current_user, invitation), :confirm => :are_you_sure.l, :method => :delete %></td>
</tr>
<% end %>
</table>
Expand Down
35 changes: 35 additions & 0 deletions app/views/invitations/new.html.haml
@@ -0,0 +1,35 @@
%script{"type"=>"text/javascript", "src"=>"http://www.plaxo.com/css/m/js/util.js"}
%script{"type"=>"text/javascript", "src"=>"http://www.plaxo.com/css/m/js/basic.js"}
%script{"type"=>"text/javascript", "src"=>"http://www.plaxo.com/css/m/js/abc_launcher.js"}

.yui-b
.box.alt.first_alt
%h3=:spread_the_word.l
%p
=:the_more_people_you_invite_the_better.l
= AppConfig.community_name
=:becomes.l
%p
=:people_who_sign_up_using_your_invitation_will_automatically_be_added_as_your_friends_on.l
= AppConfig.community_name
\.

#yui-main
.yui-b
.box
%h3=:invite_your_friends_to_join.l
- form_for(:invitation, :url => user_invitations_path(:user_id => @user.id ), :html => {:class => "MainForm"} ) do |f|
.right
%a{"href"=>"#", "onclick"=>"showPlaxoABChooser('invitation_email_addresses', '/application/plaxo'); return false;"}
%img{"src"=>"http://www.plaxo.com/images/abc/buttons/add_button.gif", "alt"=>:add_from_my_address_book.l}/
%label{"for"=>"email_addresses"}
=:enter_e_mail_addresses.l
%em= :comma_separated.l
= f.text_area :email_addresses , :rows => "5"
%label{"for"=>"message"}= :write_a_message.l
= f.text_area :message, :rows => "5"

%p
= submit_tag :send_invitations.l
or
= link_to :cancel.l, user_path(@user)
15 changes: 0 additions & 15 deletions app/views/invitations/new.rhtml

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/invitations/show.rhtml

This file was deleted.

0 comments on commit ae9c167

Please sign in to comment.