Skip to content
Browse files

add first round of adding new ask to campaign

  • Loading branch information...
1 parent 6cb986f commit e71e660da0c450e61bf6b0e67cdaab6773c00d10 Willa committed Nov 14, 2012
View
10 lib/crowdring/ask.rb
@@ -82,7 +82,7 @@ def handle?(type, ringer)
type == :voice
end
- def typesym
+ def self.typesym
:offline_ask
end
end
@@ -92,7 +92,7 @@ def handle?(type, ringer)
false
end
- def typesym
+ def self.typesym
:send_sms_ask
end
end
@@ -102,7 +102,7 @@ def handle?(type, ringer)
type == :voice && super(type, ringer)
end
- def typesym
+ def self.typesym
:join_ask
end
end
@@ -121,7 +121,7 @@ def text(ringer, text, sms_number)
respond(ringer, sms_number)
end
- def typesym
+ def self.typesym
:text_ask
end
end
@@ -141,7 +141,7 @@ def respond(ringer, sms_number)
[{cmd: :record, prompt: prompt, voicemail: voicemail}]
end
- def typesym
+ def self.typesym
:voicemail_ask
end
end
View
54 lib/crowdring/crowdring.rb
@@ -273,6 +273,48 @@ def process_request(service_name, request, response_type)
end
end
+ post '/campaign/:id/assigned_voice_number/destroy' do
+ campaign = Campaign.get(params[:id])
+ unless campaign.voice_numbers.count == 1
+ campaign.voice_numbers.first(id: params[:number_id]).destroy
+ flash[:notice] = "Voice number has been removed"
+ redirect to("/campaigns##{campaign.id}")
+ else
+ flash[:errors] = "Must have at least one voice number"
+ redirect to("/campaigns##{campaign.id}")
+ end
+ end
+
+ get '/campaign/:id/add_new_ask' do
+ @campaign = Campaign.get(params[:id])
+ @ask_type = Ask.descendants.reject {|a| [:offline_ask, :join_ask].include?(a.typesym)}
+
+ haml :campaign_add_new_ask
+ end
+
+ post '/campaign/:id/add_new_ask' do
+ campaign = Campaign.get(params[:id])
+ ask_type = params[:ask_type]
+ unless ask_type
+ flash[:errors] = "Ask type can not be empty"
+ redirect to("/campaign/#{campaign.id}/add_new_ask")
+ end
+ ask_name = Ask.descendants.find{|a| a.typesym == ask_type.to_sym}
+ trigger_by = params[:trigger_by]
+ message = params[:campaign][:message]
+ ask = Ask.create(type: ask_name, message: message)
+
+ campaign.asks.last.triggered_ask = ask
+ campaign.asks << ask
+ if campaign.save
+ flash[:notice] = "New Ask Add"
+ redirect to("/campaigns##{campaign.id}")
+ else
+ flash[:errors] = "Failed to add new ask"
+ redirect to("/campaign/#{campaign.id}/add_new_ask")
+ end
+ end
+
post '/campaign/:id/destroy' do
campaign = Campaign.get(params[:id])
if campaign.destroy
@@ -360,18 +402,6 @@ def process_request(service_name, request, response_type)
haml :tag_new
end
- post '/campaign/:id/assigned_voice_number/destroy' do
- campaign = Campaign.get(params[:id])
- unless campaign.voice_numbers.count == 1
- campaign.voice_numbers.first(id: params[:number_id]).destroy
- flash[:notice] = "Voice number has been removed"
- redirect to("/campaigns##{campaign.id}")
- else
- flash[:errors] = "Must have at least one voice number"
- redirect to("/campaigns##{campaign.id}")
- end
- end
-
post '/tags/create' do
tag = Tag.from_str(params[:type] + ':' + params[:value])
if tag.saved?
View
1 lib/views/asks/voicemail_ask.haml
@@ -3,7 +3,6 @@
=haml :price_estimate, locals: {price_estimate: ask.initial_price_estimate(@campaign.ringers, @campaign.sms_number.phone_number)}
="#{ask.respondents.count} recipients / #{ask.recipients.count} respondents"
=haml :message, locals: {message: ask.message}
-%h4="Prompt: #{ask.prompt}"
%h4 Voicemails:
-ask.voicemails.each do |vm|
%a{href: vm.filename}= vm.id
View
5 lib/views/campaign.haml
@@ -49,8 +49,9 @@
#asks
%h2= "ASKS"
-@campaign.asks.each do |ask|
- =haml :ask, locals: {ask: ask, type: ask.typesym}
-
+ =haml :ask, locals: {ask: ask, type: ask.class.typesym}
+ %form{action: "/campaign/#{@campaign.id}/add_new_ask", method: 'get'}
+ %button Add new ask
#broadcast.form-box
%h3 Broadcast
View
25 lib/views/campaign_add_new_ask.haml
@@ -0,0 +1,25 @@
+%h2 Add new asks
+%h3 What type of ask is this?
+%form{action: "/campaign/#{@campaign.id}/add_new_ask ", method: 'post'}
+ %select{name: "ask_type"}
+ %option{value:"", selected: 'selected', disabled:"disabled"} Select Ask Type
+ -@ask_type. each do |type|
+ -type_view = type.to_s.split(":").last.split("Ask").first
+ %option{value: "#{type.typesym}"}= "#{type_view}"
+ %h3 How to prompt this ask?
+ #filtered-messages
+ %button#new-filter-button{type: 'button', onclick: "window.addFilter();"} Add filtered message
+ .field
+ %label Default Message:
+ %textarea.msg-text-area{name: 'campaign[message][default_message]', placeholder: 'Thanks for supporting...'}
+ %h3 What triggers this ask?
+ %div
+ %input{type: 'radio', name:'[triggered_by]', id: 'user', value: 'user', checked: 'checked'}
+ %label{for: 'user'} The Campaigner (that's you!)
+ %div
+ %input{type: 'radio', name:'[triggered_by]', id: 'ask', value: 'previous'}
+ %label{for: 'ask'} The Previous Event
+ %button{type:'submit'} Add new ask
+
+ #original-filtered-message-template-container{style: 'display:none'}
+ =haml :filtered_message_template
View
25 spec/campaign_spec.rb
@@ -1,6 +1,12 @@
require File.dirname(__FILE__) + '/spec_helper'
describe Crowdring::Campaign do
+
+ def app
+ Crowdring::Server
+ end
+
+
describe 'campaign creation' do
before(:each) do
DataMapper.auto_migrate!
@@ -87,4 +93,23 @@
Crowdring::Ringer.all.count.should eq(1)
end
end
+ describe 'campaign and asks' do
+ include Rack::Test::Methods
+
+ before(:each) do
+ Crowdring::Server.service_handler.reset
+ DataMapper.auto_migrate!
+ @number1 = '+18001111111'
+ @number2 = '+18002222222'
+ @number3 = '+18003333333'
+ @c = Crowdring::Campaign.create(title: 'test', voice_numbers: [{phone_number: @number2, description: 'num1'}], sms_number: @number3)
+ end
+
+ it 'should be able to add new ask after campaign creation' do
+ params = {'ask_type' => 'text_ask', 'trigger_by' => 'user','campaign' => { 'message' => {'default_message' => 'hello'}}}
+ post "/campaign/#{@c.id}/add_new_ask" ,params
+
+ @c.asks.count.should eq(2)
+ end
+ end
end

0 comments on commit e71e660

Please sign in to comment.
Something went wrong with that request. Please try again.