In the middle of adding custom theme supports. Skin_pictures table added to store...
author<jlsharps@mit.edu> <>
Wed, 28 May 2008 17:24:40 +0000 (13:24 -0400)
committer<jlsharps@mit.edu> <>
Wed, 28 May 2008 17:24:40 +0000 (13:24 -0400)
.bzrignore
app/controllers/election_controller.rb
app/models/skin_picture.rb [new file with mode: 0644]
app/views/election/_themeupload.rhtml [new file with mode: 0644]
app/views/election/edit_general_information.rhtml
db/migrate/003_add_custom_widget_support.rb [new file with mode: 0644]
db/schema.rb
test/fixtures/skin_pictures.yml [new file with mode: 0644]
test/unit/skin_picture_test.rb [new file with mode: 0644]

index 5304d54136103c673695551947c79d3753d355c9..42f2b24ae1e026d9f320403cc576219156ff5d46 100644 (file)
@@ -8,3 +8,7 @@ public/engine_files
 .DS_Store
 vendor/plugins/sitealizer/lib/last_update
 public/pictures
+public/skin_pictures
+public/pictures
+help
+public/pictures/0000
index 571b93628e7e916f2dd4e2228e91c02729c5344d..becba6b161d7cc9781b6c2cc365ecfdd3adad2f9 100644 (file)
@@ -62,6 +62,11 @@ class ElectionController < ApplicationController
   
   def update_general_information
     @election = Election.find(params[:id])
+    
+    if params[:skin_picture]
+      add_theme
+    end
+    
     if @election.update_attributes(params[:election])
       flash[:notice] = 'Election was successfully updated.'
       redirect_to :action => 'show', :id => @election
@@ -69,7 +74,12 @@ class ElectionController < ApplicationController
       render :action => 'edit'
     end
   end
-
+  
+  def add_theme
+    debugger
+    skin_picture = SkinPicture.new(params[:skin_picture])
+    skin_picture.save
+  end
 
   def show
     @sidebar_content = render_to_string :partial => 'progress',
diff --git a/app/models/skin_picture.rb b/app/models/skin_picture.rb
new file mode 100644 (file)
index 0000000..c369eae
--- /dev/null
@@ -0,0 +1,9 @@
+class SkinPicture < ActiveRecord::Base
+  
+  has_attachment :storage => :file_system,
+                 :processor => :Rmagick
+                 
+  validates_as_attachment
+                 
+  
+end
diff --git a/app/views/election/_themeupload.rhtml b/app/views/election/_themeupload.rhtml
new file mode 100644 (file)
index 0000000..20d7e29
--- /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="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 c2f1cf5b5e24692462840d20604db7c6b6f21079..c3b0052c9df32e6bbac3fac726c2c953d1341d5a 100644 (file)
@@ -3,7 +3,9 @@
   <span class="subheader"></span>
 </div>
 
-<% form_tag(:action => 'update_general_information', :id => @election) do %>
+<% form_tag( {:action => 'update_general_information', :id => @election},
+                       :multipart => true ) do %>
   <%= render :partial => 'overview_form' %>
+  <%= render :partial => 'themeupload' %>
   <%= submit_tag 'Done' %>
 <% end %>
diff --git a/db/migrate/003_add_custom_widget_support.rb b/db/migrate/003_add_custom_widget_support.rb
new file mode 100644 (file)
index 0000000..07c69e0
--- /dev/null
@@ -0,0 +1,24 @@
+class AddCustomWidgetSupport < ActiveRecord::Migration
+  
+  def self.up
+    create_table :skin_pictures, :force => true do |t|
+      t.column :filename,     :string
+      t.column :content_type, :string
+      t.column :size,         :integer
+      t.column :width,        :integer
+      t.column :height,       :integer
+      t.column :created_at,   :datetime
+      t.column :user_id,      :integer
+    end
+    
+    add_column :elections, :embed_custom_string, :string, :default => nil
+    
+  end
+  
+  def self.down
+    drop_table :skin_pictures
+    
+    remove_column :elections, :embed_custom_string   
+  end
+  
+end
index aa46f6fa78c1033e26b97e4e0818175135db77a0..e3f8d16363eb0ecaacb2889a0cb90022b606c2d9 100644 (file)
@@ -2,7 +2,7 @@
 # migrations feature of ActiveRecord to incrementally modify your database, and
 # then regenerate this schema definition.
 
-ActiveRecord::Schema.define(:version => 2) do
+ActiveRecord::Schema.define(:version => 3) do
 
   create_table "candidates", :force => true do |t|
     t.column "election_id", :integer,                                :null => false
@@ -11,21 +11,22 @@ ActiveRecord::Schema.define(:version => 2) do
   end
 
   create_table "elections", :force => true do |t|
-    t.column "name",            :string,   :limit => 100, :default => "",    :null => false
-    t.column "description",     :text,                    :default => "",    :null => false
-    t.column "anonymous",       :integer,  :limit => 4,   :default => 1,     :null => false
-    t.column "startdate",       :datetime
-    t.column "enddate",         :datetime,                                   :null => false
-    t.column "active",          :integer,  :limit => 4,   :default => 0,     :null => false
-    t.column "viewable",        :integer,  :limit => 4,   :default => 1,     :null => false
-    t.column "notices",         :integer,  :limit => 4,   :default => 0,     :null => false
-    t.column "user_id",         :integer
-    t.column "quickuser",       :string
-    t.column "election_method", :string,   :limit => 100, :default => "ssd"
-    t.column "type",            :string,   :limit => 100, :default => "",    :null => false
-    t.column "embeddable",      :boolean,                 :default => false, :null => false
-    t.column "authenticated",   :boolean,                 :default => true,  :null => false
-    t.column "early_results",   :boolean,                 :default => false, :null => false
+    t.column "name",                :string,   :limit => 100, :default => "",    :null => false
+    t.column "description",         :text,                    :default => "",    :null => false
+    t.column "anonymous",           :integer,  :limit => 4,   :default => 1,     :null => false
+    t.column "startdate",           :datetime
+    t.column "enddate",             :datetime,                                   :null => false
+    t.column "active",              :integer,  :limit => 4,   :default => 0,     :null => false
+    t.column "viewable",            :integer,  :limit => 4,   :default => 1,     :null => false
+    t.column "notices",             :integer,  :limit => 4,   :default => 0,     :null => false
+    t.column "user_id",             :integer
+    t.column "quickuser",           :string
+    t.column "election_method",     :string,   :limit => 100, :default => "ssd"
+    t.column "type",                :string,   :limit => 100, :default => "",    :null => false
+    t.column "embeddable",          :boolean,                 :default => false, :null => false
+    t.column "authenticated",       :boolean,                 :default => true,  :null => false
+    t.column "early_results",       :boolean,                 :default => false, :null => false
+    t.column "embed_custom_string", :string
   end
 
   add_index "elections", ["user_id"], :name => "fk_user_election"
@@ -66,6 +67,16 @@ ActiveRecord::Schema.define(:version => 2) do
     t.column "created_on", :date
   end
 
+  create_table "skin_pictures", :force => true do |t|
+    t.column "filename",     :string
+    t.column "content_type", :string
+    t.column "size",         :integer
+    t.column "width",        :integer
+    t.column "height",       :integer
+    t.column "created_at",   :datetime
+    t.column "user_id",      :integer
+  end
+
   create_table "tokens", :force => true do |t|
     t.column "token",   :string,  :limit => 100, :default => "", :null => false
     t.column "vote_id", :integer,                                :null => false
diff --git a/test/fixtures/skin_pictures.yml b/test/fixtures/skin_pictures.yml
new file mode 100644 (file)
index 0000000..b49c4eb
--- /dev/null
@@ -0,0 +1,5 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+  id: 1
+two:
+  id: 2
diff --git a/test/unit/skin_picture_test.rb b/test/unit/skin_picture_test.rb
new file mode 100644 (file)
index 0000000..ec95ba4
--- /dev/null
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class SkinPictureTest < Test::Unit::TestCase
+  fixtures :skin_pictures
+
+  # Replace this with your real tests.
+  def test_truth
+    assert true
+  end
+end

Benjamin Mako Hill || Want to submit a patch?