diff options
Diffstat (limited to 'site/app')
-rw-r--r-- | site/app/controllers/agenda_items_controller.rb | 9 | ||||
-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 | ||||
-rw-r--r-- | site/app/views/agenda_items/show.dryml | 43 |
5 files changed, 85 insertions, 2 deletions
diff --git a/site/app/controllers/agenda_items_controller.rb b/site/app/controllers/agenda_items_controller.rb index c2944dc..d202cd0 100644 --- a/site/app/controllers/agenda_items_controller.rb +++ b/site/app/controllers/agenda_items_controller.rb @@ -20,6 +20,15 @@ class AgendaItemsController < ApplicationController auto_actions :all, :except => :index before_filter :login, :except => :show + def update_poll_answers + new_choice = params[:choice].keys.collect { |txt| txt.to_i } + item = AgendaItem.find(params[:agenda_item_id]) + + Vote.update_user_poll_votes(new_choice, current_user, item) + + redirect_to agenda_item_path(item) + end + protected def login redirect_to user_login_path unless current_user.signed_up? 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 diff --git a/site/app/views/agenda_items/show.dryml b/site/app/views/agenda_items/show.dryml index b0b425d..3f0507f 100644 --- a/site/app/views/agenda_items/show.dryml +++ b/site/app/views/agenda_items/show.dryml @@ -16,6 +16,49 @@ </form> </span> </div> + + <table if="¤t_user.signed_up?"> + <tr> + <repeat:voting_options> + <th> + <name/> + </th> + </repeat> + </tr> + <repeat with="&User.council_member_is(true)"> + <tr> + <% user = this %> + <repeat with="&@this.voting_options"> + <td if="& not(user.id == current_user.id)"> + <unless with="&Vote.user_is(user).voting_option_is(this).count.zero?"> + + + </unless> + </td> + </repeat> + </tr> + </repeat> + <form if="¤t_user.council_member?" action="&update_poll_answers_path"> + <tr> + <repeat with="&@this.voting_options"> + <td> + <% name = "choice[#{this.id}]" + id = this.id %> + <if with="&Vote.user_is(current_user).voting_option_is(this).count.zero?"> + <input type="checkbox" name="&name" value="&id"/> + </if> + <else> + <input type="checkbox" name="&name" value="&this.id" checked/> + </else> + </td> + </repeat> + <td> + <after-submit stay-here/> + <input type="hidden" name="agenda_item_id" value="&this.id"/> + <submit label="Update choice"/> + </td> + </tr> + </form> + </table> </append-content-body:> <after-collection:> |