From: Date: Thu, 29 May 2008 17:06:52 +0000 (-0400) Subject: File upload system for custom skins almost complete. X-Git-Url: https://projects.mako.cc/source/selectricity/commitdiff_plain/50d95cd1569a8452323d565cf2f34fc63672cff7?ds=sidebyside;hp=947bdc28cd01bc025ffde2af3472b38e5d30f9d1 File upload system for custom skins almost complete. --- diff --git a/app/controllers/election_controller.rb b/app/controllers/election_controller.rb index becba6b..6cd12bc 100644 --- a/app/controllers/election_controller.rb +++ b/app/controllers/election_controller.rb @@ -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' } diff --git a/app/models/skin_picture.rb b/app/models/skin_picture.rb index c369eae..304fb8e 100644 --- a/app/models/skin_picture.rb +++ b/app/models/skin_picture.rb @@ -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 index 0000000..7c29c21 --- /dev/null +++ b/app/views/election/_theme_upload.rhtml @@ -0,0 +1,25 @@ +<%= error_messages_for("skin_picture") %> + +

If you want a custom theme upload it if here!
+ +
+ <%=file_field :top_bar, :uploaded_data %>
+
+ <%=file_field :default_image, :uploaded_data %>
+
+ <%=file_field :bg1, :uploaded_data %>
+
+ <%=file_field :bg2, :uploaded_data %>
+
+ <%=file_field :bottom_bar, :uploaded_data %>
+

+ +

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.
+ Top Bar/ Bottom Bar/ Alternating Backgrounds: 330px wide 53px tall +
+ Default Image: 70px wide 53px tall +

\ No newline at end of file diff --git a/app/views/election/_themeupload.rhtml b/app/views/election/_themeupload.rhtml deleted file mode 100644 index 20d7e29..0000000 --- a/app/views/election/_themeupload.rhtml +++ /dev/null @@ -1,25 +0,0 @@ -<%= error_messages_for("skin_picture") %> - -

If you want a custom theme upload it if here!
- -
- <%=file_field :skin_picture, :uploaded_data %>
-
- <%=file_field :skin_picture, :uploaded_data %>
-
- <%=file_field :skin_picture, :uploaded_data %>
-
- <%=file_field :skin_picture, :uploaded_data %>
-
- <%=file_field :skin_picture, :uploaded_data %>
-

- -

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.
- Top Bar/ Bottom Bar/ Alternating Backgrounds: 330px wide 53px tall -
- Default Image: 70px wide 53px tall -

\ No newline at end of file diff --git a/app/views/election/edit_general_information.rhtml b/app/views/election/edit_general_information.rhtml index c3b0052..17ec324 100644 --- a/app/views/election/edit_general_information.rhtml +++ b/app/views/election/edit_general_information.rhtml @@ -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 %> + + diff --git a/app/views/election/general_information.rhtml b/app/views/election/general_information.rhtml index 1eae59f..feed407 100644 --- a/app/views/election/general_information.rhtml +++ b/app/views/election/general_information.rhtml @@ -3,8 +3,8 @@ -<% 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 %> -