Assigns a random color to conference, track and difficulty level

This commit is contained in:
Chrisbr 2014-06-02 12:31:44 +02:00
parent fa129de063
commit b9d01220ad
4 changed files with 50 additions and 4 deletions

View file

@ -95,8 +95,32 @@ $(function() {
$(this).find('span:nth-child(2)').toggleClass("glyphicon-chevron-down glyphicon-chevron-right");
}
});
$('a:contains("Add track")').click(function () {
setTimeout(function () {
$("div.nested-fields:last div:nth-of-type(2) input").val(get_color());
},
5)
});
$('a:contains("Add difficulty_level")').click(function () {
setTimeout(function () {
$("div.nested-fields:last div:nth-of-type(3) input").val(get_color());
},
5)
});
});
function get_color() {
var colors = ['#000000', '#0000FF', '#00FF00', '#FF0000', '#FFFF00', '#9900CC',
'#CC0066', '#00FFFF', '#FF00FF', '#C0C0C0', '#00008B', '#FFD700',
'#FFA500', '#FF1493', '#FF00FF', '#F0FFFF', '#EE82EE', '#D2691E',
'#C0C0C0', '#A52A2A', '#9ACD32', '#9400D3', '#8B008B', '#8B0000',
'#87CEEB', '#808080', '#800080', '#008B8B', '#006400'
];
return colors[Math.floor(Math.random() * colors.length)];
}
function word_count(text, divId, maxcount) {
var r = 0;
var input = text.value.replace(/\s/g,' ');

View file

@ -64,6 +64,7 @@ class Conference < ActiveRecord::Base
before_create :generate_guid
before_create :create_venue
before_create :create_email_settings
before_create :add_color
def self.media_types
media_types = {:youtube => 'YouTube', :slideshare => 'SlideShare', :flickr => 'Flickr', :vimeo => 'Vimeo', :speakerdeck => 'Speakerdeck', :instagram => 'Instagram'}
@ -189,4 +190,18 @@ class Conference < ActiveRecord::Base
self.guid = guid
end
##
# Adds a random color to the conference
#
def add_color
if !color
self.color = %w(
#000000 #0000FF #00FF00 #FF0000 #FFFF00 #9900CC
#CC0066 #00FFFF #FF00FF #C0C0C0 #00008B #FFD700
#FFA500 #FF1493 #FF00FF #F0FFFF #EE82EE #D2691E
#C0C0C0 #A52A2A #9ACD32 #9400D3 #8B008B #8B0000
#87CEEB #808080 #800080 #008B8B #006400
).sample
end
end
end

View file

@ -0,0 +1,7 @@
class RemoveColorDefaults < ActiveRecord::Migration
def change
change_column_default(:tracks, :color, nil)
change_column_default(:conferences, :color, nil)
change_column_default(:difficulty_levels, :color, nil)
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140529133339) do
ActiveRecord::Schema.define(version: 20140530082708) do
create_table "answers", force: true do |t|
t.string "title"
@ -78,7 +78,7 @@ ActiveRecord::Schema.define(version: 20140529133339) do
t.boolean "use_volunteers"
t.string "media_id"
t.string "media_type"
t.string "color", default: "#000000"
t.string "color"
t.text "description"
t.text "registration_description"
t.text "ticket_description"
@ -100,7 +100,7 @@ ActiveRecord::Schema.define(version: 20140529133339) do
t.integer "conference_id"
t.string "title"
t.text "description"
t.string "color", default: "#ffffff"
t.string "color"
t.datetime "created_at"
t.datetime "updated_at"
end
@ -313,7 +313,7 @@ ActiveRecord::Schema.define(version: 20140529133339) do
t.integer "conference_id"
t.string "name", null: false
t.text "description"
t.string "color", default: "#ffffff"
t.string "color"
t.datetime "created_at"
t.datetime "updated_at"
end