diff --git a/Gemfile.lock b/Gemfile.lock
index 1ecfdd7..98f6e70 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -126,10 +126,10 @@ GEM
ntlm-http (~> 0.1, >= 0.1.1)
webrobots (~> 0.0, >= 0.0.9)
meta_programming (0.2.2)
- metaclass (0.0.1)
+ metaclass (0.0.4)
method_source (0.8.1)
mime-types (1.21)
- mocha (0.10.0)
+ mocha (1.0.0)
metaclass (~> 0.0.1)
multi_json (1.6.0)
mysql2 (0.3.11)
@@ -180,7 +180,7 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
- rake (10.0.3)
+ rake (10.1.1)
rcov (0.9.10)
rdoc (3.12.1)
json (~> 1.4)
diff --git a/app/assets/javascripts/polls.coffee b/app/assets/javascripts/polls.coffee
index ba57fc8..2767447 100644
--- a/app/assets/javascripts/polls.coffee
+++ b/app/assets/javascripts/polls.coffee
@@ -19,6 +19,15 @@ $ ->
$('#poll_form_url').focus()
false
+ checkForceSubscription()
+ $('#poll_force_subscription_false').change checkForceSubscription
+ $('#poll_force_subscription_true').change checkForceSubscription
+
+checkForceSubscription = ->
+ readonly = $('#poll_force_subscription_true').is(':checked')
+ $('#poll_welcome_message').attr('readonly', readonly)
+ $('#poll_confirmation_word').attr('readonly', readonly)
+
setupValidation = () ->
jQuery.validator.addMethod(
"hasChildren"
diff --git a/app/models/poll.rb b/app/models/poll.rb
index 67bb46d..aeaed99 100644
--- a/app/models/poll.rb
+++ b/app/models/poll.rb
@@ -1,17 +1,17 @@
# Copyright (C) 2011-2012, InSTEDD
-#
+#
# This file is part of Pollit.
-#
+#
# Pollit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# Pollit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with Pollit. If not, see .
@@ -27,18 +27,18 @@ class Poll < ActiveRecord::Base
validates :title, :presence => true, :length => {:maximum => 64}, :uniqueness => {:scope => :owner_id}
validates :owner, :presence => true
validates :form_url, :presence => true
- validates :welcome_message, :presence => true, :length => {:maximum => 140}
+ validates :welcome_message, :presence => true, :length => {:maximum => 140}, :unless => :force_subscription
validates :post_url, :presence => true
- validates :confirmation_word, :presence => true
+ validates :confirmation_word, :presence => true, :unless => :force_subscription
validates :goodbye_message, :presence => true, :length => {:maximum => 140}
validates :questions, :presence => true
accepts_nested_attributes_for :questions
-
+
after_initialize :default_values
enum_attr :status, %w(^configuring started paused)
-
+
include Parser
include AcceptAnswers
@@ -57,7 +57,7 @@ def start
raise Exception.new("Cannot start poll #{self.id}") unless can_be_started?
invite respondents
-
+
self.status = :started
save
end
@@ -78,13 +78,13 @@ def pause
def resume
raise Exception.new("Cannot resume unpaused poll #{self.id}") unless self.status_paused?
-
+
messages = []
-
+
# Invite respondents that were added while the poll was paused
respondents_to_invite = self.respondents.where(:current_question_sent => false).where(:confirmed => false)
invite respondents_to_invite
-
+
# Sends next questions to users with a current question and without the current_question_sent mark
respondents_to_send_next_question = self.respondents.where(:current_question_sent => false).where('current_question_id IS NOT NULL')
respondents_to_send_next_question.each do |r|
@@ -99,7 +99,7 @@ def resume
send_messages messages
- [respondents_to_send_next_question, respondents_to_goodbye].each do |rs|
+ [respondents_to_send_next_question, respondents_to_goodbye].each do |rs|
rs.update_all :current_question_sent => true
end
@@ -140,28 +140,28 @@ def google_form_key
query = URI.parse(form_url || post_url).query
CGI::parse(query)['formkey'][0]
end
-
+
def on_respondents_added
invite_new_respondents if status_started?
end
-
+
def invite_new_respondents
respondents_to_invite = self.respondents.where(:current_question_sent => false).where(:confirmed => false)
invite respondents_to_invite
end
private
-
+
def invite(respondents)
messages = []
-
+
respondents.each do |respondent|
messages << message_to(respondent, welcome_message)
end
# mark respondents as invited
respondents.update_all :current_question_sent => true
-
+
send_messages messages
end
diff --git a/app/views/polls/_form.haml b/app/views/polls/_form.haml
index 51beeae..da22d97 100644
--- a/app/views/polls/_form.haml
+++ b/app/views/polls/_form.haml
@@ -12,15 +12,18 @@
.field
= f.label :title
= f.text_field :title, :class => 'required w60'
-
+
.field
= f.label :description
%p This is an internal description of the Poll, it will not be sent to your users
= f.text_area :description, :class => 'w60', :rows => 5
-
.field
- = f.label :welcome_message
+ = f.label :force_subscription, "#{f.radio_button(:force_subscription, true)} Force subscription".html_safe, value: true
+ %p Select this options only if you have explicit permission from the respondents to participate in your poll with their mobile phones.
+
+ .field
+ = f.label :force_subscription, "#{f.radio_button(:force_subscription, false)} Welcome message".html_safe, value: false
%p This message will be sent to all respondents asking them if they agree to participate in the poll
= f.text_area :welcome_message, :size => "28x5", :maxlength => 140, :class => 'required ux-wajbar w60', :readonly => !@poll.editable?
.field
@@ -31,7 +34,7 @@
= f.label :goodbye_message
%p This message will be sent to respondents when they complete the poll
= f.text_area :goodbye_message, :size => "28x5", :maxlength => 140, :class => 'ux-wajbar w60'
-
+
%hr
= render :partial => 'form_questions', :locals => {f:f}
@@ -45,4 +48,4 @@
= grey_button _("Next")
- else
= grey_button _("Save")
- = white_link_to _("Cancel"), back_path
\ No newline at end of file
+ = white_link_to _("Cancel"), back_path
diff --git a/db/migrate/20140313123128_add_force_subscription_to_polls.rb b/db/migrate/20140313123128_add_force_subscription_to_polls.rb
new file mode 100644
index 0000000..30c75da
--- /dev/null
+++ b/db/migrate/20140313123128_add_force_subscription_to_polls.rb
@@ -0,0 +1,5 @@
+class AddForceSubscriptionToPolls < ActiveRecord::Migration
+ def change
+ add_column :polls, :force_subscription, :boolean, default: false
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index e46ac43..d579845 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111213154341) do
+ActiveRecord::Schema.define(:version => 20140313123128) do
create_table "answers", :force => true do |t|
t.integer "respondent_id"
@@ -37,11 +37,12 @@
t.string "form_url"
t.datetime "created_at"
t.datetime "updated_at"
- t.string "welcome_message", :default => "YES"
+ t.string "welcome_message", :default => "YES"
t.string "status"
t.string "post_url"
t.string "confirmation_word"
t.string "goodbye_message"
+ t.boolean "force_subscription", :default => false
end
create_table "questions", :force => true do |t|
diff --git a/spec/models/poll_spec.rb b/spec/models/poll_spec.rb
index 562c590..5446c13 100644
--- a/spec/models/poll_spec.rb
+++ b/spec/models/poll_spec.rb
@@ -1,18 +1,18 @@
# encoding: UTF-8
# Copyright (C) 2011-2012, InSTEDD
-#
+#
# This file is part of Pollit.
-#
+#
# Pollit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# Pollit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with Pollit. If not, see .
@@ -39,6 +39,22 @@
it "must require questions if specified" do
Poll.make_unsaved(:questions => []).should be_invalid
end
+
+ it "must require welcome message" do
+ Poll.make_unsaved(welcome_message: nil).should be_invalid
+ end
+
+ it "must require confirmation word" do
+ Poll.make_unsaved(confirmation_word: nil).should be_invalid
+ end
+
+ it "can have welcome message empty if force subscription" do
+ Poll.make_unsaved(welcome_message: nil, force_subscription: true).should be_valid
+ end
+
+ it "can have confirmation word empty if force subscription" do
+ Poll.make_unsaved(confirmation_word: nil, force_subscription: true).should be_valid
+ end
end
context "parsing google form" do
@@ -375,4 +391,4 @@ def messages
end
end
-end
\ No newline at end of file
+end