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