diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-07-20 20:45:16 +0200 |
---|---|---|
committer | Petteri Räty <petsku@petteriraty.eu> | 2011-08-03 12:51:57 +0300 |
commit | 33abbf833236f957ff49d46951ee0dad294c677e (patch) | |
tree | 27f53754b62c7de3045af7a917cf425f7143c5ee /site/app/models | |
parent | Make some more actions available only to council members (diff) | |
download | council-webapp-33abbf833236f957ff49d46951ee0dad294c677e.tar.gz council-webapp-33abbf833236f957ff49d46951ee0dad294c677e.tar.bz2 council-webapp-33abbf833236f957ff49d46951ee0dad294c677e.zip |
Custom doodle-like feature
Diffstat (limited to 'site/app/models')
-rw-r--r-- | site/app/models/agenda.rb | 19 | ||||
-rw-r--r-- | site/app/models/agenda_item.rb | 2 | ||||
-rw-r--r-- | site/app/models/vote.rb | 14 |
3 files changed, 33 insertions, 2 deletions
diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb index bae34c3..b25b0b1 100644 --- a/site/app/models/agenda.rb +++ b/site/app/models/agenda.rb @@ -21,7 +21,7 @@ class Agenda < ActiveRecord::Base meeting_time :datetime email_reminder_sent :boolean meeting_log :text - summary :text + summary :text, :null => true timestamps end @@ -77,6 +77,21 @@ class Agenda < ActiveRecord::Base agenda.meeting_time ||= Time.now end + after_create do |agenda| + day_poll = AgendaItem.create! :poll => true, :title => 'Meeting day poll', :agenda => agenda + hour_poll = AgendaItem.create! :poll => true, :title => 'Meeting hour poll', :agenda => agenda + min_date = CustomConfig['CouncilTerm']['min_days_between_meetings'].days.from_now + + (0..CustomConfig['CouncilTerm']['days_for_meeting']).each do |days_from_min| + description = (min_date + days_from_min.days).strftime '%Y.%m.%d %A' + VotingOption.create! :agenda_item => day_poll, :description => description + end + + (0..24).each do |hour| + VotingOption.create! :agenda_item => hour_poll, :description => "#{hour}:00 - #{hour + 1}:00" + end + end + def self.current result = Agenda.state_is_not(:old).first result = Agenda.create! unless result @@ -136,7 +151,7 @@ class Agenda < ActiveRecord::Base end def time_for_reminders(type) - offset = CustomConfig['Reminders']["hours_before_meeting_to_send_#{type}_reminders"].hours + offset = CustomConfig['Reminders']["hours_before_meeting_to_send_#{type.to_s}_reminders"].hours meeting_time - offset end diff --git a/site/app/models/agenda_item.rb b/site/app/models/agenda_item.rb index 1f30599..db5e0ae 100644 --- a/site/app/models/agenda_item.rb +++ b/site/app/models/agenda_item.rb @@ -22,6 +22,7 @@ class AgendaItem < ActiveRecord::Base discussion :string body :markdown rejected :boolean, :default => false + poll :boolean, :default => false timelimits :text discussion_time :string timestamps @@ -33,6 +34,7 @@ class AgendaItem < ActiveRecord::Base validate :timelimits_entered_properly + attr_readonly :poll # --- Permissions --- # def create_permitted? return false if acting_user.guest? diff --git a/site/app/models/vote.rb b/site/app/models/vote.rb index 7aea160..a8b63f0 100644 --- a/site/app/models/vote.rb +++ b/site/app/models/vote.rb @@ -68,11 +68,25 @@ class Vote < ActiveRecord::Base end end + def self.update_user_poll_votes(new_choice, user, item) + old_choice = Vote.user_is(user).for_item(item).*.voting_option_id + (old_choice - new_choice).each do |choice_id| + vote = Vote.user_is(user).voting_option_is(choice_id).first + next if vote.nil? + vote.destroy + end + + (new_choice - old_choice).each do |choice_id| + next unless VotingOption.find(choice_id).agenda_item_is?(item) + Vote.create! :user => user, :voting_option_id => choice_id + end + end protected def user_voted_only_once return if user.nil? return if voting_option.nil? return if voting_option.agenda_item.nil? + return if voting_option.agenda_item.poll other_votes = Vote.for_item(voting_option.agenda_item_id).user_id_is(user_id) other_votes = other_votes.id_is_not(id) unless new_record? if other_votes.count > 0 |