X-Git-Url: https://projects.mako.cc/source/selectricity/blobdiff_plain/3e545735b4784af19edec9bfcc8e25ff17cb7f12..131cab23209cb1dfa81930240b8cf722d2302131:/app/controllers/quickvote_controller.rb diff --git a/app/controllers/quickvote_controller.rb b/app/controllers/quickvote_controller.rb index 7ad1722..da2903d 100644 --- a/app/controllers/quickvote_controller.rb +++ b/app/controllers/quickvote_controller.rb @@ -12,17 +12,42 @@ class QuickvoteController < ApplicationController def create if params[:quickvote] @quickvote = QuickVote.new(params[:quickvote]) + + # check to see if any of the advanced options have been changed + new_qv = QuickVote.new + if @quickvote.election_method != new_qv.election_method \ + or @quickvote.enddate.day != new_qv.enddate.day \ + or @quickvote.viewable != new_qv.viewable \ + or @quickvote.notices != new_qv.notices + show_advanced = true + end + end + + show_advanced ||= false + + if params[:quickvote] + # store the candidate grabbed through ajax and stored in flash @quickvote.candidate_names = flash[:candidate_names] @quickvote.description=@quickvote.description + #record who created the quickvote so that person can monitor it easily @quickvote.quickuser = session.session_id + + #Give registered users additional QuickVote functionality + @quickvote.user_id = session[:user][:id] if session[:user] + # try to save, if it fails, show the page again (the flash should # still be intact if @quickvote.save @quickvote = @quickvote.reload + # blank sidebar and show the success page + @sidebar_content = '' render :action => 'success' else + # render the sidebar + @sidebar_content = render_to_string(:partial => 'create_sidebar', + :locals => {:show_advanced => show_advanced}) flash.keep(:candidate_names) end @@ -32,7 +57,10 @@ class QuickvoteController < ApplicationController # candidate_names list in the flash flash.delete(:candidate_names) if flash.has_key?(:candidate_names) @quickvote = QuickVote.new + @sidebar_content = render_to_string(:partial => 'create_sidebar', + :locals => {:show_advanced => show_advanced}) end + end def add_candidate @@ -132,16 +160,6 @@ class QuickvoteController < ApplicationController voter.destroy redirect_to quickvote_url( :ident => params[:ident] ) end - - def sort_candidates - @vote = Vote.find(params[:id]) - - @vote.rankings.each do |ranking| - ranking.rank = params['rankings-list'].index(ranking.candidate.id.to_s) + 1 - ranking.save - end - render :nothing => true - end def mapvoters @map = GMap.new("map_div_id") @@ -184,6 +202,8 @@ class QuickvoteController < ApplicationController @results = @election.results @candidates = {} @election.candidates.each {|c| @candidates[c.id] = c} + @names = @election.names_by_id + @sidebar_content = render_to_string :partial => 'results_sidebar' end def my_quickvotes