Permalink
Browse files

issue based contact congress form

  • Loading branch information...
1 parent cdf71da commit ddebdb6b8d12507a94efc07bae1fb789f091700b @aross aross committed Mar 29, 2012
@@ -2,9 +2,9 @@ class Admin::TalkingPointsController < Admin::IndexController
# GET /talking_points
# GET /talking_points.xml
def index
- @bill = Bill.find_by_ident(params[:bill_id])
+ @talking_pointable = Object.const_get(params[:talking_pointable_type]).find_by_id(params[:talking_pointable_id])
- @talking_points = @bill.talking_points
+ @talking_points = @talking_pointable.talking_points
respond_to do |format|
format.html # index.html.erb
@@ -28,8 +28,8 @@ def show
def new
@talking_point = TalkingPoint.new
- @bill = Bill.find_by_ident(params[:bill_id])
- @talking_point.talking_pointable = @bill
+ @talking_pointable = Object.const_get(params[:talking_pointable_type]).find_by_id(params[:talking_pointable_id])
+ @talking_point.talking_pointable = @talking_pointable
respond_to do |format|
format.html # new.html.erb
@@ -49,7 +49,7 @@ def create
respond_to do |format|
if @talking_point.save
- format.html { redirect_to(:action => 'index', :bill_id => @talking_point.talking_pointable.ident, :notice => 'Talking point was successfully created.') }
+ format.html { redirect_to(:action => 'index', :talking_pointable_type => @talking_point.talking_pointable.class.name, :talking_pointable_id => @talking_point.talking_pointable.id, :notice => 'Talking point was successfully created.') }
format.xml { render :xml => @talking_point, :status => :created, :location => @talking_point }
else
format.html { render :action => "new" }
@@ -65,7 +65,7 @@ def update
respond_to do |format|
if @talking_point.update_attributes(params[:talking_point])
- format.html { redirect_to(:action => 'index', :bill_id => @talking_point.talking_pointable.ident, :notice => 'Talking point was successfully updated.') }
+ format.html { redirect_to(:action => 'index', :talking_pointable_type => @talking_point.talking_pointable.class.name, :talking_pointable_id => @talking_point.talking_pointable.id, :notice => 'Talking point was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
@@ -79,12 +79,12 @@ def update
def destroy
@talking_point = TalkingPoint.find(params[:id])
- @bill = @talking_point.talking_pointable
+ @talking_pointable = @talking_point.talking_pointable
@talking_point.destroy
respond_to do |format|
- format.html { redirect_to(:action => 'index', :bill_id => @bill.ident) }
+ format.html { redirect_to(:action => 'index', :talking_pointable_type => @talking_pointable.class.name, :talking_pointable_id => @talking_pointable.id) }
format.xml { head :ok }
end
end
@@ -5,9 +5,14 @@ class ContactCongressLettersController < ApplicationController
def new
@page_title = "Contact Congress"
- @bill = Bill.find_by_ident(params[:bill])
-
-
+
+ if !params[:bill].blank?
+ @bill = Bill.find_by_ident(params[:bill])
+ elsif !params[:issue].blank?
+ @issue = Subject.find_by_id(params[:issue])
+ end
+
+
if logged_in?
@sens = current_user.my_sens
@reps = current_user.my_reps
@@ -20,7 +25,7 @@ def new
@sens = @reps = []
end
- if params[:position].nil?
+ if @bill and params[:position].nil?
render 'select_position'
return
end
@@ -29,25 +34,40 @@ def new
### loop through recipients and see if formageddon is configured
- @position = params[:position]
+ if @bill
+ @position = params[:position]
- case @position
- when 'support'
- message_start = "I support #{@bill.typenumber} - #{@bill.title_common}, and am tracking it using OpenCongress.org, the free public resource website for government transparency and accountability."
- when 'oppose'
- message_start = "I oppose #{@bill.typenumber} - #{@bill.title_common}, and am tracking it using OpenCongress.org, the free public resource website for government transparency and accountability."
- else
- message_start = "I'm tracking #{@bill.typenumber} - #{@bill.title_common} using OpenCongress.org, the free public resource website for government transparency and accountability."
+ case @position
+ when 'support'
+ message_start = "I support #{@bill.typenumber} - #{@bill.title_common}, and am tracking it using OpenCongress.org, the free public resource website for government transparency and accountability."
+ when 'oppose'
+ message_start = "I oppose #{@bill.typenumber} - #{@bill.title_common}, and am tracking it using OpenCongress.org, the free public resource website for government transparency and accountability."
+ else
+ message_start = "I'm tracking #{@bill.typenumber} - #{@bill.title_common} using OpenCongress.org, the free public resource website for government transparency and accountability."
+ end
+
+ @subject = "#{@bill.typenumber} #{@bill.title_common}"
+ @contactable_query = "contactable_type=Bill&contactable_id=#{@bill.id}"
+ elsif @issue
+ message_start = "I am tracking legislation in the issue area of #{@issue.term} using OpenCongress.org, the free public resource website for government transparency and accountability."
+ @subject = @issue.term
+ @contactable_query = "contactable_type=Subject&contactable_id=#{@issue.id}"
end
+
@formageddon_thread = Formageddon::FormageddonThread.new
- @formageddon_thread.prepare(:user => current_user, :subject => "#{@bill.typenumber} #{@bill.title_common}", :message => message_start)
+ @formageddon_thread.prepare(:user => current_user, :subject => @subject, :message => message_start)
end
def get_recipients
- @bill = Bill.find_by_ident(params[:bill])
+ if !params[:bill].blank?
+ @bill = Bill.find_by_ident(params[:bill])
+ elsif !params[:issue].blank?
+ @issue = Subject.find_by_id(params[:issue])
+ end
+
unless params[:zip4].blank?
@sens, @reps = Person.find_current_congresspeople_by_zipcode(params[:zip5], params[:zip4])
else
@@ -92,7 +112,14 @@ def show
@additional_letters.flatten!.sort!{|a,b| a.created_at <=> b.created_at } unless @additional_letters.empty?
@page_title = "My Letter to Congress: #{@contact_congress_letter.formageddon_threads.first.formageddon_letters.first.subject}"
- @meta_description = "This is a letter to Congress sent using OpenCongress.org by user #{@contact_congress_letter.user.login} regarding #{@contact_congress_letter.bill.typenumber} #{@contact_congress_letter.bill.title_common}. OpenCongress is a free and open-source public resource website for tracking and contacting the U.S. Congress."
+
+ if @contact_congress_letter.contactable_type == 'Bill'
+ regarding = "#{@contact_congress_letter.contactable.typenumber} #{@contact_congress_letter.contactable.title_common}"
+ elsif @contact_congress_letter.contactable_type == 'Subject'
+ regarding = @contact_congress_letter.contactable.term
+ end
+
+ @meta_description = "This is a letter to Congress sent using OpenCongress.org by user #{@contact_congress_letter.user.login} regarding #{regarding}. OpenCongress is a free and open-source public resource website for tracking and contacting the U.S. Congress."
if params[:print_version] == 'true'
render :partial => 'contact_congress_letters/print',
@@ -111,16 +138,15 @@ def create_from_formageddon
@letters = Formageddon::FormageddonLetter.find(letter_ids)
end
-
- bill = Bill.find_by_ident(params[:bill])
+ contactable = Object.const_get(params[:contactable_type]).find_by_id(params[:contactable_id])
@letters.each do |l|
cclft = ContactCongressLettersFormageddonThread.find_by_formageddon_thread_id(l.formageddon_thread.id)
if cclft.nil?
if @contact_congress_letter.nil?
@contact_congress_letter = ContactCongressLetter.new
@contact_congress_letter.disposition = params[:disposition]
- @contact_congress_letter.bill = bill unless bill.nil?
+ @contact_congress_letter.contactable = contactable unless contactable.nil?
@contact_congress_letter.save
end
@@ -156,7 +182,7 @@ def create_from_formageddon
@group = Group.find_by_id(params[:group_id])
if @group
# make sure this group is tracking this bill and user is a member
- if @group.bills.include?(@contact_congress_letter.bill) and
+ if @group.bills.include?(@contact_congress_letter.contactable) and
(@group.is_member?(@contact_congress_letter.user) or @group.is_owner?(@contact_congress_letter.user))
notebook = PoliticalNotebook.find_or_create_from_group(@group)
@@ -1,13 +1,21 @@
module ContactCongressLettersHelper
def personal_share_message_for_letter(letter, url)
- u("Wrote my members of #Congress on @opencongress to let them know " +
- "#{letter.disposition == 'tracking' ? "I'm tracking" : "I " + letter.disposition} #USbill #" +
- letter.bill.typenumber.downcase.gsub(/\./, '') + " " + url)
+ if letter.contactable_type == 'Bill'
+ u("Wrote my members of #Congress on @opencongress to let them know " +
+ "#{letter.disposition == 'tracking' ? "I'm tracking" : "I " + letter.disposition} #USbill #" +
+ letter.contactable.typenumber.downcase.gsub(/\./, '') + " " + url)
+ elsif letter.contactable_type == 'Subject'
+ u("Wrote my members of #Congress on @opencongress about #{letter.contactable.term}" + url)
+ end
end
def generic_share_message_for_letter(letter, url)
- u("A letter to #Congress on @opencongress #{position_clause(letter.disposition)} #USbill #" +
- letter.bill.typenumber.downcase.gsub(/\./, '') + " " + url)
+ if letter.contactable_type == 'Bill'
+ u("A letter to #Congress on @opencongress #{position_clause(letter.disposition)} #USbill #" +
+ letter.contactable.typenumber.downcase.gsub(/\./, '') + " " + url)
+ elsif letter.contactable_type == 'Subject'
+ u("A letter to #Congress on @opencongress regarding #{letter.contactable.term}" + url)
+ end
end
def sponsor_tag(bill, person)
View
@@ -65,7 +65,7 @@ class Bill < ActiveRecord::Base
has_one :wiki_link, :as => "wikiable"
- has_many :contact_congress_letters
+ has_many :contact_congress_letters, :as => :contactable
alias :blog :blogs
@@ -4,7 +4,7 @@ class ContactCongressLetter < ActiveRecord::Base
has_many :formageddon_threads, :through => :contact_congress_letters_formageddon_threads, :class_name => 'Formageddon::FormageddonThread'
has_many :contact_congress_letters_formageddon_threads
- belongs_to :bill
+ belongs_to :contactable, :polymorphic => true
belongs_to :user
has_many :comments, :as => :commentable
View
@@ -8,6 +8,7 @@ class Subject < ActiveRecord::Base
has_many :recently_introduced_bills, :class_name => "Bill", :through => :bill_subjects, :source => "bill", :order => "bills.introduced DESC", :limit => 20
has_many :comments, :as => :commentable
+ has_many :talking_points, :as => :talking_pointable
has_one :issue_stats
@@ -1,5 +1,5 @@
.padding
- %h1 PPF Talking Points for #{@bill.typenumber}
+ %h1 PPF Talking Points for #{@talking_pointable}
%table
%tr
@@ -15,7 +15,10 @@
%br
- = link_to 'New Talking Point', {:action => 'new', :bill_id => @bill.ident }, :class => "silver button small"
+ = link_to 'New Talking Point', {:action => 'new', :talking_pointable_type => @talking_pointable.class.name, :talking_pointable_id => @talking_pointable.id }, :class => "silver button small"
%br
%br
- = link_to "Return to #{@bill.typenumber}", bill_path(@bill)
+ - if @talking_pointable.class.name == 'Bill'
+ = link_to "Return to #{@talking_pointable.typenumber}", bill_path(@talking_pointable)
+ - elsif @talking_pointable.class.name == 'Subject'
+ = link_to "Return to #{@talking_pointable.term}", :controller => "/issue", :action => 'show', :id => @talking_pointable
@@ -1,5 +1,5 @@
.padding
- %h1 New Talking Point for #{@bill.typenumber}
+ %h1 New Talking Point for #{@talking_pointable}
= render 'form'
@@ -46,7 +46,7 @@
<%= link_to "Select Default Title", { :controller => 'admin/bill_summaries', :action => 'defaulttitle', :id => @bill.ident }, :class => 'silver floatleft margin-right button small margin-bottom' %>
<%= link_to "Add Related Bill (Different Session)", { :controller => 'admin/bill_summaries', :action => 'session_relations', :bill_id => @bill.ident }, :class => 'silver floatleft margin-right button small margin-bottom' %>
<%= link_to "New news/blog article", { :controller => 'admin/commentary', :action => 'new', :commentariable_type => 'Bill', :commentariable_id => @bill.id }, :class => 'silver floatleft margin-right button small margin-bottom' %>
- <%= link_to "Manage Talking Points", { :controller => 'admin/talking_points', :action => 'index', :bill_id => @bill.ident }, :class => 'silver floatleft margin-right button small margin-bottom' %>
+ <%= link_to "Manage Talking Points", { :controller => 'admin/talking_points', :action => 'index', :talking_pointable_type => 'Bill', :talking_pointable_id => @bill.id }, :class => 'silver floatleft margin-right button small margin-bottom' %>
<%= link_to "Check pending news/blog articles", { :controller => 'admin/commentary', :action => 'pending', :commentariable_type => 'Bill', :commentariable_id => @bill.id }, :class => 'silver floatleft margin-right button small margin-bottom' %>
<%= link_to @bill.is_frontpage_hot? ? "Remove from frontpage" : "Add to frontpage", { :controller => 'admin/bill_summaries', :action => 'toggle_frontpage_hot', :bill_id => @bill.ident }, :class => 'silver floatleft margin-right button small margin-bottom' %>
@@ -9,8 +9,8 @@
= check_box_tag "formageddon[formageddon_multi_recipients[#{s.id}]]", 'Person', true
= image_tag(s.photo_path(:thumb), :class =>"photo", :alt => 'photo')
= link_to s.name, person_path(s)
- = sponsor_tag(@bill, s)
- if @bill
+ = sponsor_tag(@bill, s)
%span
= "Vote on Passage of #{@bill.typenumber}: "
%strong= "#{@bill.vote_on_passage(s)}"
@@ -21,8 +21,8 @@
= check_box_tag "formageddon[formageddon_multi_recipients[#{@reps.first.id}]]", 'Person', true
= image_tag(@reps.first.photo_path(:thumb), :class =>"photo", :alt => 'photo')
= link_to @reps.first.name, person_path(@reps.first)
- = sponsor_tag(@bill, p)
- if @bill
+ = sponsor_tag(@bill, p)
%span
= "Vote on Passage of #{@bill.typenumber}: "
%strong= "#{@bill.vote_on_passage(@reps.first)}"
@@ -0,0 +1,28 @@
+- trigger_js ||= false
+
+.contribution_data
+ %p.behave
+ Using all publicly-available data, the campaign contributions shown here are the ones OpenCongress automatically determines most-likely to be relevant to this issue.
+
+ %table
+ %thead
+ %tr
+ %th.topleft
+ - (@sens + @reps).each do |p|
+ %th= p.lastname
+ %tbody
+ - @issue.pvs_categories.each do |pvs|
+ - pvs.crp_industries.each do |ind|
+ %tr
+ %th.group_column= ind.name
+ - (@sens + @reps).each do |p|
+ - contribution_amount = ind.contrib_for_person(p)
+ %td
+ %span.message_builder_clickable
+ = "$#{number_with_delimiter(contribution_amount)}"
+ = render 'will_add_text_box', :text => "#{p.title} #{p.lastname}, campaign contribution data shows that you received $#{number_with_delimiter(contribution_amount)} in the #{Settings.current_opensecrets_cycle} election cycle from the #{ind.name.downcase} industry, which is relevant to this issue area."
+
+- if trigger_js
+ :javascript
+ $j(".contribution_data .message_builder_clickable").hover(function(){ mbHoverIn(this) }, function(){ mbHoverOut(this) });
+ $j(".contribution_data .message_builder_clickable").click(function(){ mbAddText(this) });
@@ -2,13 +2,19 @@
$j('#contact_recipients_container').html("<div class='none'>We could not find your representatives with the info you provided. Please try again.");
<% else %>
$j('#contact_recipients_container').html("<%= escape_javascript(render :partial => 'contact_congress_letters/contact_recipients', :locals => { :show_checkboxes => true }) %>");
- <% if @bill.bill_interest_groups.any? %>
- $j('#contribution_data_container').html("<%= escape_javascript(render :partial => 'contact_congress_letters/message_builder_intgroup_contribution_data', :locals => { :trigger_js => true}) %>");
- <% else %>
- $j('#contribution_data_container').html("<%= escape_javascript(render :partial => 'contact_congress_letters/message_builder_industry_contribution_data', :locals => { :trigger_js => true}) %>");
+ <% unless @bill.nil? %>
+ <% if @bill.bill_interest_groups.any? %>
+ $j('#contribution_data_container').html("<%= escape_javascript(render :partial => 'contact_congress_letters/message_builder_intgroup_contribution_data', :locals => { :trigger_js => true}) %>");
+ <% else %>
+ $j('#contribution_data_container').html("<%= escape_javascript(render :partial => 'contact_congress_letters/message_builder_industry_contribution_data', :locals => { :trigger_js => true}) %>");
+ <% end %>
<% end %>
-
- <% unless @bill.roll_calls.first.nil? %>
+
+ <% unless @issue.nil? %>
+ $j('#contribution_data_container').html("<%= escape_javascript(render :partial => 'contact_congress_letters/message_builder_issue_contribution_data', :locals => { :trigger_js => true}) %>");
+ <% end %>
+
+ <% unless @bill.nil? or @bill.roll_calls.first.nil? %>
$j('#roll_call_container').html("<%= escape_javascript(render :partial => 'contact_congress_letters/message_builder_roll_call', :locals => { :roll_call => @bill.roll_calls.first }) %>");
<% end %>
$j('.contact_recipients').css('background', 'rgba(101,101,101, .2)');
Oops, something went wrong.

0 comments on commit ddebdb6

Please sign in to comment.