Class: Caboose::SubscriptionsController
Instance Method Summary
collapse
#add_ga_event, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#admin_add ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/controllers/caboose/subscriptions_controller.rb', line 59
def admin_add
return unless user_is_allowed('subscriptions', 'add')
resp = Caboose::StdClass.new
name = params[:name]
if name.nil? || name.strip.length == 0
resp.error = "A name is required."
elsif Subscription.where(:site_id => @site.id, :name => params[:name]).exists?
resp.error = "A subscription with that name already exists."
else
s = Subscription.create(
:site_id => @site.id,
:name => params[:name].strip,
:interval => Subscription::INTERVAL_MONTHLY,
:prorate => false,
:start_on_day => false
)
resp.redirect = "/admin/subscriptions/#{s.id}"
resp.success = true
end
render :json => resp
end
|
#admin_delete ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
|
# File 'app/controllers/caboose/subscriptions_controller.rb', line 111
def admin_delete
return unless user_is_allowed('subscriptions', 'delete')
model_ids = params[:id] == 'bulk' ? params[:model_ids] : [params[:id]]
model_ids.each do |model_id|
UserSubscription.where(:subscription_id => model_id).destroy_all
Subscription.where(:id => model_id).destroy_all
end
render :json => { :sucess => true }
end
|
#admin_edit ⇒ Object
45
46
47
48
49
|
# File 'app/controllers/caboose/subscriptions_controller.rb', line 45
def admin_edit
return if !user_is_allowed('subscriptions', 'edit')
@subscription = Subscription.find(params[:id])
render :layout => 'caboose/admin'
end
|
#admin_index ⇒ Object
10
11
12
13
|
# File 'app/controllers/caboose/subscriptions_controller.rb', line 10
def admin_index
return if !user_is_allowed('subscriptions', 'view')
render :layout => 'caboose/admin'
end
|
#admin_json ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'app/controllers/caboose/subscriptions_controller.rb', line 16
def admin_json
return if !user_is_allowed('subscriptions', 'view')
= PageBarGenerator.new(params, {
'site_id' => @site.id,
'name_like' => '',
'description_like' => '',
'variant_id' => '',
'interval' => '',
'prorate' => '',
'prorate_method' => '',
'prorate_flat_amount' => '',
'start_on_day' => '',
'start_day' => '',
'start_month' => ''
},{
'model' => 'Caboose::Subscription',
'sort' => 'name',
'desc' => false,
'base_url' => "/admin/subscriptions",
'use_url_params' => false
})
render :json => {
:pager => ,
:models => .items
}
end
|
#admin_json_single ⇒ Object
52
53
54
55
56
|
# File 'app/controllers/caboose/subscriptions_controller.rb', line 52
def admin_json_single
return if !user_is_allowed('subscriptions', 'view')
s = Subscription.find(params[:id])
render :json => s
end
|
#admin_options ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'app/controllers/caboose/subscriptions_controller.rb', line 125
def admin_options
if !user_is_allowed('subscriptions', 'edit')
render :json => false
return
end
options = []
case params[:field]
when 'interval'
options = [
{ 'value' => Subscription::INTERVAL_MONTHLY , 'text' => 'Monthly' },
{ 'value' => Subscription::INTERVAL_YEARLY , 'text' => 'Yearly' }
]
when 'prorate-method'
options = [
{ 'value' => Subscription::PRORATE_METHOD_FLAT , 'text' => 'Flat Amount' },
{ 'value' => Subscription::PRORATE_METHOD_PERCENTAGE , 'text' => 'Percentage of Interval' },
{ 'value' => Subscription::PRORATE_METHOD_CUSTOM , 'text' => 'Custom' }
]
when 'start-day'
options = (1..31).collect{ |i| { 'value' => i, 'text' => i }}
when 'start-month'
options = (1..12).collect{ |i| { 'value' => i, 'text' => Date.new(2000, i, 1).strftime('%B') }}
end
render :json => options
end
|
#admin_update ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'app/controllers/caboose/subscriptions_controller.rb', line 84
def admin_update
return unless user_is_allowed('subscriptions', 'edit')
resp = StdClass.new
models = params[:id] == 'bulk' ? params[:model_ids].collect{ |model_id| Subscription.find(model_id) } : [Subscription.find(params[:id])]
params.each do |k, v|
case k
when 'name' then models.each{ |s| s.name = v }
when 'description' then models.each{ |s| s.description = v }
when 'variant_id' then models.each{ |s| s.variant_id = v }
when 'interval' then models.each{ |s| s.interval = v }
when 'prorate' then models.each{ |s| s.prorate = v }
when 'prorate_method' then models.each{ |s| s.prorate_method = v }
when 'prorate_flat_amount' then models.each{ |s| s.prorate_flat_amount = v }
when 'prorate_function' then models.each{ |s| s.prorate_function = v }
when 'start_on_day' then models.each{ |s| s.start_on_day = v }
when 'start_day' then models.each{ |s| s.start_day = v }
when 'start_month' then models.each{ |s| s.start_month = v }
end
end
models.each{ |s| s.save }
resp.success = true
render :json => resp
end
|