diff --git a/app/assets/javascripts/osem.js b/app/assets/javascripts/osem.js index d96fd091..c543d914 100644 --- a/app/assets/javascripts/osem.js +++ b/app/assets/javascripts/osem.js @@ -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,' '); diff --git a/app/models/conference.rb b/app/models/conference.rb index 2bee4eec..64561606 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -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 diff --git a/db/migrate/20140530082708_remove_color_defaults.rb b/db/migrate/20140530082708_remove_color_defaults.rb new file mode 100644 index 00000000..4292ecca --- /dev/null +++ b/db/migrate/20140530082708_remove_color_defaults.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 2950e7e3..9d4be48c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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