diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index 704ff8d83..ebf14d94b 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -62,6 +62,10 @@ module Budgets def vote @investment.register_selection(current_user) load_investment_votes(@investment) + respond_to do |format| + format.html { redirect_to budget_investments_path(heading_id: @investment.heading.id) } + format.js + end end private diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb index e790312d6..025b6301d 100644 --- a/app/controllers/management/budgets/investments_controller.rb +++ b/app/controllers/management/budgets/investments_controller.rb @@ -34,6 +34,10 @@ class Management::Budgets::InvestmentsController < Management::BaseController def vote @investment.register_selection(managed_user) load_investment_votes(@investment) + respond_to do |format| + format.html { redirect_to management_budget_investments_path(heading_id: @investment.heading.id) } + format.js + end end def print diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 4c8816abc..100433707 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -155,6 +155,7 @@ class Budget def reason_for_not_being_selectable_by(user) return permission_problem(user) if permission_problem?(user) + return :different_heading_assigned unless valid_heading?(user) return :no_selecting_allowed unless budget.selecting? end @@ -182,6 +183,24 @@ class Budget reason_for_not_being_selectable_by(user).blank? end + def valid_heading?(user) + !different_heading_assigned?(user) + end + + def different_heading_assigned?(user) + other_heading_ids = group.heading_ids - [heading.id] + voted_in?(other_heading_ids, user) + end + + def voted_in?(heading_ids, user) + heading_ids.include? heading_voted_by_user?(user) + end + + def heading_voted_by_user?(user) + user.votes.for_budget_investments(budget.investments.where(group: group)). + votables.map(&:heading_id).first + end + def ballotable_by?(user) reason_for_not_being_ballotable_by(user).blank? end @@ -204,13 +223,19 @@ class Budget end def should_show_aside? - (budget.selecting? && !unfeasible?) || (budget.balloting? && feasible?) || budget.on_hold? + (budget.selecting? && !unfeasible?) || + (budget.balloting? && feasible?) || + (budget.valuating? && feasible?) end def should_show_votes? budget.selecting? end + def should_show_vote_count? + budget.valuating? + end + def should_show_ballots? budget.balloting? end diff --git a/app/models/user.rb b/app/models/user.rb index 881f5700d..f8991d676 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -103,6 +103,10 @@ class User < ActiveRecord::Base comment_flags.each_with_object({}){ |f, h| h[f.flaggable_id] = true } end + def voted_in_group?(group) + votes.for_budget_investments(Budget::Investment.where(group: group)).exists? + end + def administrator? administrator.present? end diff --git a/app/views/budgets/investments/_feasibility_link.html.erb b/app/views/budgets/investments/_feasibility_link.html.erb new file mode 100644 index 000000000..118a02e7f --- /dev/null +++ b/app/views/budgets/investments/_feasibility_link.html.erb @@ -0,0 +1,11 @@ +
+