Permalink
Browse files

Plugged in assign unsubscribe voice number

  • Loading branch information...
1 parent ec99204 commit 30837760b899f631f8f2c110ec3df5eada423a0e Willa committed Nov 7, 2012
View
@@ -110,10 +110,42 @@ def process_request(service_name, request, response_type)
get '/' do
@campaigns = Campaign.all
+ @unsubscribe_numbers = AssignedUnsubscribeVoiceNumber.all
+ @unsubscribed_count = Ringer.unsubscribed.count
haml :index
end
+
+ get '/unsubscribe_numbers/new' do
+ used_voice_numbers = AssignedVoiceNumber.all.map(&:phone_number)
+ @voice_numbers = Server.service_handler.voice_numbers - used_voice_numbers
+
+ haml :assign_unsubscribe_number
+ end
+
+ post '/unsubscribe_numbers/create' do
+ unsubscribe_number = AssignedUnsubscribeVoiceNumber.new(phone_number: params[:voice_number])
+ if unsubscribe_number.save
+ flash[:notice] = "Unsubscribe number assigned"
+ redirect to("/")
+ else
+ flash[:errors] = unsubscribe_number.errors.full_messages.join('|')
+ redirect to('/unsubscribe_numbers/new')
+ end
+ end
+
+ post '/unsubscribe_numbers/:phone_number/destroy' do
+ unsubscribe_number = AssignedUnsubscribeVoiceNumber.get(params[:phone_number])
+ if unsubscribe_number.destroy
+ flash[:notice] = "Unsubscribe number removed"
+ else
+ flash[:errors] = "Failed to remove number|" + unsubscribe_number.errors.full_messages.join('|')
+ end
+
+ redirect to('/')
+ end
+
get '/campaigns' do
@campaigns = Campaign.all
View
@@ -25,6 +25,10 @@ class Ringer
after :create, :add_tags
+ def self.unsubscribed
+ all(subscribed: false)
+ end
+
def phone_number=(number)
super Phoner::Phone.parse(number).to_s
end
@@ -0,0 +1,10 @@
+%h2 Assign unsubscribe voice number
+-if @voice_numbers.empty?
+ %h3 Sorry, no voice numbers currently available.
+-else
+ %form{action: '/unsubscribe_numbers/create', method: 'post'}
+ %select{name: 'voice_number'}
+ -@voice_numbers.each do |n|
+ %option #{n}
+ %button{type: 'submit'} Assign
+
View
@@ -8,3 +8,4 @@
%form{action: '/campaign/new', method: 'get'}
%button New Campaign
#campaign
+
View
@@ -1,6 +1,11 @@
#new-campaign
- %form{action: 'campaign/new', method: 'get'}
+ %form{action: '/campaign/new', method: 'get'}
%button New Campaign
-
+ %form{action: '/unsubscribe_numbers/new', method: 'get'}
+ %button Assign unsubscribe number
+ %h3 Unsubscribe numbers
+ -@unsubscribe_numbers.each do |n|
+ = haml :unsubscribe_number, locals: {number: n}
+ %h3= "Unsubscribe Count: #{@unsubscribed_count}"
-@campaigns.each do |campaign|
= haml :campaign_preview, locals: {campaign: campaign}
@@ -0,0 +1,4 @@
+%h4 #{number.pretty_phone_number}
+%form{action: "/unsubscribe_numbers/#{number.phone_number}/destroy", method: 'post'}
+ %button{type: 'submit'} Remove
+

0 comments on commit 3083776

Please sign in to comment.