]> projects.mako.cc - selectricity-live/commitdiff
Custom embeddable code works for png's except for top_bar
author<jlsharps@mit.edu> <>
Fri, 30 May 2008 02:42:46 +0000 (22:42 -0400)
committer<jlsharps@mit.edu> <>
Fri, 30 May 2008 02:42:46 +0000 (22:42 -0400)
app/controllers/election_controller.rb
app/controllers/voter_controller.rb
app/views/embed/_backdrop.rhtml
app/views/embed/full_vote.rhtml

index 2fe5e4bbc8d17f6df259b19175bc73df39eab0fb..072d4397a10247c2bd3929f2224d06a1317e1152 100644 (file)
@@ -89,27 +89,27 @@ class ElectionController < ApplicationController
   def add_theme(prefix)
     unless params[:top_bar][:uploaded_data].to_s.empty?
       top_bar = SkinPicture.new(params[:top_bar])
   def add_theme(prefix)
     unless params[:top_bar][:uploaded_data].to_s.empty?
       top_bar = SkinPicture.new(params[:top_bar])
-      top_bar.filename = prefix + "top_bar"
+      top_bar.filename = prefix + "top_bar." + params[:top_bar][:uploaded_data].content_type[6..-2]
       top_bar.save
     end
     unless params[:default_image][:uploaded_data].to_s.empty?
       default_image = SkinPicture.new(params[:default_image])
       top_bar.save
     end
     unless params[:default_image][:uploaded_data].to_s.empty?
       default_image = SkinPicture.new(params[:default_image])
-      default_image.filename = prefix + "default_image"
+      default_image.filename = prefix + "default_image." + params[:default_image][:uploaded_data].content_type[6..-2]
       default_image.save
     end
     unless params[:bg1][:uploaded_data].to_s.empty?
       default_image.save
     end
     unless params[:bg1][:uploaded_data].to_s.empty?
-      bg1 = SkinPicture.new(params[:bg1])
-      bg1.filename = prefix + "bg1"
+      bg1 = SkinPicture.new(params[:bg1])  
+      bg1.filename = prefix + "bg1." + params[:bg1][:uploaded_data].content_type[6..-2]
       bg1.save
     end
     unless params[:bg2][:uploaded_data].to_s.empty?
       bg1.save
     end
     unless params[:bg2][:uploaded_data].to_s.empty?
-      bg2 = SkinPicture.new(params[:bg2])
-      bg2.filename = prefix + "bg2"
+      bg2 = SkinPicture.new(params[:bg2]) 
+      bg2.filename = prefix + "bg2." + params[:bg2][:uploaded_data].content_type[6..-2]
       bg2.save
     end
     unless params[:bottom_bar][:uploaded_data].to_s.empty?
       bottom_bar = SkinPicture.new(params[:bottom_bar])
       bg2.save
     end
     unless params[:bottom_bar][:uploaded_data].to_s.empty?
       bottom_bar = SkinPicture.new(params[:bottom_bar])
-      bottom_bar.filename = prefix + "bottom_bar"
+      bottom_bar.filename = prefix + "bottom_bar." + params[:bottom_bar][:uploaded_data].content_type[6..-2]
       bottom_bar.save
     end
         
       bottom_bar.save
     end
         
index cdc045da05c3e680d425918a7c0670685590eff5..9e88e9e282b048cfe1b0e9177081fc1300424873 100644 (file)
@@ -61,6 +61,19 @@ class VoterController < ApplicationController
       else
         @sidebar_content = render_to_string(:partial => 'vote_sidebar')
         if @election.embeddable? and params[:embed] == "true"
       else
         @sidebar_content = render_to_string(:partial => 'vote_sidebar')
         if @election.embeddable? and params[:embed] == "true"
+          #look for custom theme, and assign to instance variabels for widget use
+          if @election.embed_custom_string
+            @top_bar = SkinPicture.find(:first,
+            :conditions => ["filename = ?", @election.embed_custom_string + "top_bar.png"])
+            @default_image = SkinPicture.find(:first,
+            :conditions => ["filename = ?", @election.embed_custom_string + "default_image.png"])
+            @bg1 = SkinPicture.find(:first,
+            :conditions => ["filename = ?", @election.embed_custom_string + "bg1.png"])
+            @bg2 = SkinPicture.find(:first,
+            :conditions => ["filename = ?", @election.embed_custom_string + "bg2.png"])
+            @bottom_bar = SkinPicture.find(:first,
+            :conditions => ["filename = ?", @election.embed_custom_string + "bottom_bar.png"])
+          end
           render :template => 'embed/full_vote', :layout => 'embed'
         else
           render :action => 'full_vote'
           render :template => 'embed/full_vote', :layout => 'embed'
         else
           render :action => 'full_vote'
@@ -151,6 +164,19 @@ class VoterController < ApplicationController
       @names = @election.names_by_id
         
       @sidebar_content = render_to_string(:partial => 'results_sidebar')
       @names = @election.names_by_id
         
       @sidebar_content = render_to_string(:partial => 'results_sidebar')
+      #look for custom theme, and assign to instance variabels for widget use
+      if @election.embed_custom_string
+        @top_bar = SkinPicture.find(:first,
+        :conditions => ["filename = ?", @election.embed_custom_string + "top_bar.png"])
+        @default_image = SkinPicture.find(:first,
+        :conditions => ["filename = ?", @election.embed_custom_string + "default_image.png"])
+        @bg1 = SkinPicture.find(:first,
+        :conditions => ["filename = ?", @election.embed_custom_string + "bg1.png"])
+        @bg2 = SkinPicture.find(:first,
+        :conditions => ["filename = ?", @election.embed_custom_string + "bg2.png"])
+        @bottom_bar = SkinPicture.find(:first,
+        :conditions => ["filename = ?", @election.embed_custom_string + "bottom_bar.png"])
+      end
       if @election.embeddable? and params[:embed] == "true"
         render :template => 'embed/results', :layout => 'embed'
       else
       if @election.embeddable? and params[:embed] == "true"
         render :template => 'embed/results', :layout => 'embed'
       else
index 847f9a3e3ce5c2b6ee18440c2af474f407e991bf..bee6fdf5f074c16fed478f90ba519e4e4ee6001c 100644 (file)
@@ -1,10 +1,17 @@
 <%@election.candidates.length.times do |count|-%>
        <% if (count%2)==0-%>
 <%@election.candidates.length.times do |count|-%>
        <% if (count%2)==0-%>
-               <img src="/images/widget_dark.png" 
-               style="position:absolute;top:<%=(count+1)*53%>px;">
-               <% else -%>
-               <img src="/images/widget_light.png" 
-               style="position:absolute;top:<%=(count+1)*53%>px">
+               <img src=" <% if @bg1 -%>
+                       <%= url_for @bg1.public_filename %>
+               <% else %>
+                       /images/widget_dark.png 
+               <% end -%> " style="position:absolute;top:<%=(count+1)*53%>px"/> 
+       <% else -%>
+               <img src=" <% if @bg2 -%>
+                       <%=url_for @bg2.public_filename %>
+               <% else %>
+                       /images/widget_light.png
+               <% end -%>" 
+                       style="position:absolute;top:<%=(count+1)*53%>px">
        <% end -%>
        <p class="position" style="top:<%=(10+(count+1)*53)%>px;left:10px">
        <%=count+1 -%>
        <% end -%>
        <p class="position" style="top:<%=(10+(count+1)*53)%>px;left:10px">
        <%=count+1 -%>
index 56715eb064203e78f174e8627b9521e0b3f77f2e..4eca8c4f4320e598f6b00573ff820e7fc9218c79 100644 (file)
@@ -1,3 +1,13 @@
+<head>
+<%javascript_include_tag :defaults %>
+<%if @top_bar %>
+<script type="text/javascript">
+
+document.getElementById("header").style.backgroundImage="<%=url_for @top_bar.public_filename%>"
+
+</script>
+<% end %>
+</head>
 <div id="header">
 <%= link_to '<img id="header_icon" src="/images/embed_header_icon.png" />',
             {:controller => 'front'}, {:target => "_parent"} %><h2>Vote Now</h2>
 <div id="header">
 <%= link_to '<img id="header_icon" src="/images/embed_header_icon.png" />',
             {:controller => 'front'}, {:target => "_parent"} %><h2>Vote Now</h2>
 <div id="voting-box" height="<%=(@election.candidates.length + 2)*53 %>px">
        
        <%= render :partial => '/embed/backdrop' %>
 <div id="voting-box" height="<%=(@election.candidates.length + 2)*53 %>px">
        
        <%= render :partial => '/embed/backdrop' %>
-       
        <ul id="rankings-list">
       <% @voter.vote.rankings.each do |ranking| %>
                <li class="ranking" id="ranking_<%= ranking.candidate.id %>">
                        <img alt="<%= white_list ranking.candidate.name %>"
                  src="<% if ranking.candidate.picture -%>
                       <%= url_for ranking.candidate.picture.public_filename(:thumb) -%>
        <ul id="rankings-list">
       <% @voter.vote.rankings.each do |ranking| %>
                <li class="ranking" id="ranking_<%= ranking.candidate.id %>">
                        <img alt="<%= white_list ranking.candidate.name %>"
                  src="<% if ranking.candidate.picture -%>
                       <%= url_for ranking.candidate.picture.public_filename(:thumb) -%>
-                     <%- else -%>
+                                         <% elsif @default_image %>
+                                         <%= url_for @default_image.public_filename %>
+                      <%- else -%>
                      /images/default_icon.png
                      <%- end %>" />
                        <p class="ranking-info">
                      /images/default_icon.png
                      <%- end %>" />
                        <p class="ranking-info">
@@ -26,7 +37,9 @@
        <div style="clear:both;"></div>
        
        <div id="voting-bottom" style="
        <div style="clear:both;"></div>
        
        <div id="voting-bottom" style="
-       <% if @election.candidates.length%2 == 0 %>
+       <% if @bottom_bar %>
+       background-image:url(<%= url_for @bottom_bar.public_filename %>)
+       <% elsif @election.candidates.length%2 == 0 %>
        background-image:url(/images/bottom_dark.png)
        <%else%>
        background-image:url(/images/bottom_light.png)
        background-image:url(/images/bottom_dark.png)
        <%else%>
        background-image:url(/images/bottom_light.png)

Benjamin Mako Hill || Want to submit a patch?