]> projects.mako.cc - selectricity/commitdiff
File upload system for custom skins almost complete.
author<jlsharps@mit.edu> <>
Thu, 29 May 2008 17:06:52 +0000 (13:06 -0400)
committer<jlsharps@mit.edu> <>
Thu, 29 May 2008 17:06:52 +0000 (13:06 -0400)
app/controllers/election_controller.rb
app/models/skin_picture.rb
app/views/election/_theme_upload.rhtml [new file with mode: 0644]
app/views/election/_themeupload.rhtml [deleted file]
app/views/election/edit_general_information.rhtml
app/views/election/general_information.rhtml

index becba6b161d7cc9781b6c2cc365ecfdd3adad2f9..6cd12bcb6154be9b7198257570883a7f98e1ec9d 100644 (file)
@@ -45,7 +45,13 @@ class ElectionController < ApplicationController
     @election.user = session[:user]
     @election.anonymous = 1
     @election.startdate = Time.now
-
+    
+    unless params[:top_bar][:uploaded_data].to_s.empty?
+      token_generator = UniqueTokenGenerator.new( 16 )
+      @election.embed_custom_string = token_generator.token
+      add_theme(@election.embed_custom_string)
+    end
+    
     if @election.save
       flash[:notice] = 'Election was successfully created.'
       redirect_to :action => 'edit_candidates', :id => @election.id
@@ -63,8 +69,8 @@ class ElectionController < ApplicationController
   def update_general_information
     @election = Election.find(params[:id])
     
-    if params[:skin_picture]
-      add_theme
+    unless params[:top_bar][:uploaded_data].to_s.empty?
+      add_theme(@election.embed_custom_string)
     end
     
     if @election.update_attributes(params[:election])
@@ -75,12 +81,35 @@ class ElectionController < ApplicationController
     end
   end
   
-  def add_theme
-    debugger
-    skin_picture = SkinPicture.new(params[:skin_picture])
-    skin_picture.save
+  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.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.save!
+    end
+    unless params[:bg1][:uploaded_data].to_s.empty?
+      bg1 = SkinPicture.new(params[:bg1])
+      bg1.filename = prefix + "bg1"
+      bg1.save!
+    end
+    unless params[:bg2][:uploaded_data].to_s.empty?
+      bg2 = SkinPicture.new(params[:bg2])
+      bg2.filename = prefix + "bg2"
+      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.save!
+    end
+        
   end
-
+  
   def show
     @sidebar_content = render_to_string :partial => 'progress',
                                         :locals => { :page => 'review' }
index c369eae2ff03772566c5191bf93a4b41697683b4..304fb8e5d5963015daa2caf0c96ce102bffa0434 100644 (file)
@@ -1,9 +1,9 @@
 class SkinPicture < ActiveRecord::Base
   
   has_attachment :storage => :file_system,
-                 :processor => :Rmagick
+                 :processor => :Rmagick,
+                 :content_type => :image
                  
   validates_as_attachment
-                 
-  
+    
 end
diff --git a/app/views/election/_theme_upload.rhtml b/app/views/election/_theme_upload.rhtml
new file mode 100644 (file)
index 0000000..7c29c21
--- /dev/null
@@ -0,0 +1,25 @@
+<%= error_messages_for("skin_picture") %>
+
+<p>If you want a custom theme upload it if here!<br />
+
+<span><label for="top_bar_uploaded_data">Top Bar</span><br />
+       <%=file_field :top_bar, :uploaded_data %><br />
+<span><label for="default_image_uploaded_data">Corner Image</span><br />
+       <%=file_field :default_image, :uploaded_data %><br />
+<span><label for="bg1_uploaded_data">Background One</span><br />
+       <%=file_field :bg1, :uploaded_data %><br />
+<span><label for="bg2_uploaded_data">Background Two</span><br />
+       <%=file_field :bg2, :uploaded_data %><br />
+<span><label for="bottom_bar_uploaded_data">Bottom Bar</span><br />
+       <%=file_field :bottom_bar, :uploaded_data %><br />
+</p>
+       
+<p>Detailed Information:
+       Every embeddable widget uses five different picture files to create 
+               it's color scheme and default image. If you have images you'd like to
+               use in your widget. Please make sure they fit the
+               specified dimensions.<br />
+               Top Bar/ Bottom Bar/ Alternating Backgrounds: 330px wide 53px tall
+               <br />
+               Default Image: 70px wide 53px tall
+</p>
\ No newline at end of file
diff --git a/app/views/election/_themeupload.rhtml b/app/views/election/_themeupload.rhtml
deleted file mode 100644 (file)
index 20d7e29..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<%= error_messages_for("skin_picture") %>
-
-<p>If you want a custom theme upload it if here!<br />
-
-<span><label for="skin_picture_topbar">Top Bar</span><br />
-       <%=file_field :skin_picture, :uploaded_data %><br />
-<span><label for="skin_picture_default_image">Corner Image</span><br />
-       <%=file_field :skin_picture, :uploaded_data %><br />
-<span><label for="skin_picture_vote_bg1">Background One</span><br />
-       <%=file_field :skin_picture, :uploaded_data %><br />
-<span><label for="skin_picture_vote_bg2">Background Two</span><br />
-       <%=file_field :skin_picture, :uploaded_data %><br />
-<span><label for="skin_picture_bottombar">Bottom Bar</span><br />
-       <%=file_field :skin_picture, :uploaded_data %><br />
-</p>
-       
-<p>Detailed Information:
-       Every embeddable widget uses five different picture files to create 
-               it's color scheme and default image. If you have images you'd like to
-               use in your widget. Please make sure they fit the
-               specified dimensions.<br />
-               Top Bar/ Bottom Bar/ Alternating Backgrounds: 330px wide 53px tall
-               <br />
-               Default Image: 70px wide 53px tall
-</p>
\ No newline at end of file
index c3b0052c9df32e6bbac3fac726c2c953d1341d5a..17ec3247f003e1a9a000b9f7abcfc84ca84cf2fd 100644 (file)
@@ -6,6 +6,8 @@
 <% form_tag( {:action => 'update_general_information', :id => @election},
                        :multipart => true ) do %>
   <%= render :partial => 'overview_form' %>
-  <%= render :partial => 'themeupload' %>
+  <%= render :partial => 'theme_upload' %>
   <%= submit_tag 'Done' %>
 <% end %>
+
+
index 1eae59feeaa25dd78f7d0cd745f33303796d7311..feed407dd23bc7ed4ae5548354c0c2e7679b15bf 100644 (file)
@@ -3,8 +3,8 @@
   <span class="subheader"></span>
 </div>
 
-<% form_tag (:action => 'create_election') do %>
+<% form_tag( {:action => 'create_election'}, :multipart => true ) do %>
   <%= render :partial => 'overview_form' %>
+  <%= render :partial => 'theme_upload' %>
   <%= submit_tag "Proceed to Next Step" %>
 <% end %>
-

Benjamin Mako Hill || Want to submit a patch?