Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 390
- Log:
Initial import of Canvass, a donations-based poll application.
- Author:
- rool
- Date:
- Mon Mar 21 14:58:04 +0000 2011
- Size:
- 2674 Bytes
1 | ######################################################################## |
2 | # File:: donations_controller.rb |
3 | # (C):: Hipposoft 2011 |
4 | # |
5 | # Purpose:: Handle creating and displaying donations. |
6 | # ---------------------------------------------------------------------- |
7 | # 30-Jan-2011 (ADH): Created. |
8 | ######################################################################## |
9 | |
10 | class DonationsController < ApplicationController |
11 | |
12 | uses_prototype() |
13 | uses_leightbox( :only => :index ) |
14 | |
15 | @@hubssolib_permissions = HubSsoLib::Permissions.new( { |
16 | :index => [ :admin, :webmaster, :privileged, :normal ], |
17 | :show => [ :admin, :webmaster, :privileged, :normal ], |
18 | :new => [ :admin, :webmaster, :privileged, :normal ], |
19 | :create => [ :admin, :webmaster, :privileged, :normal ] |
20 | } ) |
21 | |
22 | def self.hubssolib_permissions |
23 | @@hubssolib_permissions |
24 | end |
25 | |
26 | def skip_main_heading? |
27 | action_name.to_sym == :index |
28 | end |
29 | |
30 | # GET /donations |
31 | # GET /users/<n>/donations |
32 | def index |
33 | |
34 | # The Donation model takes care of permissions for users trying to view |
35 | # the donations of other users and so-forth within its "conditions_for" |
36 | # class method. If the user hacks around with URLs they might get an odd |
37 | # title such as "All Donations", but the list will only contain things |
38 | # they're allowed to see (e.g. for non-admins, only their donations). |
39 | |
40 | appctrl_search_sort_and_paginate( |
41 | Donation, |
42 | :default_sorting => Donation.default_sort_hash(), |
43 | :extra_conditions => Donation.conditions_for( params, current_user ) |
44 | ) |
45 | end |
46 | |
47 | # GET /donations/<n> |
48 | # GET /users/<u>/donations/<n> |
49 | def show |
50 | @donation = Donation.find_by_id( |
51 | params[ :id ], |
52 | :conditions => Donation.conditions_for( params, current_user ) |
53 | ) |
54 | |
55 | redirect_to polls_path and return if @donation.nil? |
56 | end |
57 | |
58 | # GET /polls/<n>/donations/new |
59 | def new |
60 | @poll = Poll.find_by_id( params[ :poll_id ] ) |
61 | @donation = Donation.generate_for( @poll, current_user, '0', '0' ) |
62 | end |
63 | |
64 | # POST /polls/<n>/donations |
65 | def create |
66 | begin |
67 | @poll = Poll.find_by_id( params[ :poll_id ] ) |
68 | @donation = Donation.generate_for( |
69 | @poll, |
70 | current_user, |
71 | params[ :donation ][ :amount_integer ], |
72 | params[ :donation ][ :amount_fraction ] |
73 | ) |
74 | rescue => error |
75 | appctrl_report_error( error ) |
76 | redirect_to root_path |
77 | end |
78 | |
79 | if @donation.save |
80 | if ( params[ :payment_method ] == 'onsite' ) |
81 | redirect_to new_poll_payment_gateway_onsite_path( @poll ) |
82 | else |
83 | redirect_to new_poll_payment_gateway_offsite_path( @poll ) |
84 | end |
85 | else |
86 | render :action => 'new' |
87 | end |
88 | end |
89 | end |