From d1e8495890ed28d221595e3a60c2df8567b277c1 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 19 Dec 2013 20:11:01 +0200 Subject: [PATCH] Add validations to BroadcastMessage color and font Signed-off-by: Dmitriy Zaporozhets --- app/models/broadcast_message.rb | 3 +++ app/views/admin/broadcast_messages/index.html.haml | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/broadcast_message.rb b/app/models/broadcast_message.rb index 05b4dfc366e..bebe0da9c61 100644 --- a/app/models/broadcast_message.rb +++ b/app/models/broadcast_message.rb @@ -20,6 +20,9 @@ class BroadcastMessage < ActiveRecord::Base validates :starts_at, presence: true validates :ends_at, presence: true + validates :color, format: { with: /\A\#[0-9A-Fa-f]{6}+\Z/ }, allow_blank: true + validates :font, format: { with: /\A\#[0-9A-Fa-f]{6}+\Z/ }, allow_blank: true + def self.current where("ends_at > :now AND starts_at < :now", now: Time.zone.now).last end diff --git a/app/views/admin/broadcast_messages/index.html.haml b/app/views/admin/broadcast_messages/index.html.haml index 8a0d5e4d760..d7c78950b95 100644 --- a/app/views/admin/broadcast_messages/index.html.haml +++ b/app/views/admin/broadcast_messages/index.html.haml @@ -21,11 +21,13 @@ .control-group.js-toggle-colors-container.hide = f.label :color, "Background Color" .controls - = f.text_field :color + = f.text_field :color, placeholder: "#AA33EE" + .light Hex values as 3 double digit numbers, starting with a # sign. .control-group.js-toggle-colors-container.hide = f.label :font, "Font Color" .controls - = f.text_field :font + = f.text_field :font, placeholder: "#224466" + .light Hex values as 3 double digit numbers, starting with a # sign. .control-group = f.label :starts_at .controls.datetime-controls