Class: Widget
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Widget
- Defined in:
- app/models/widget.rb
Overview
Schema Information
Table name: widgets
id :integer not null, primary key
title :string(255)
content :text
css_name :string(255)
active :boolean
created_at :datetime not null
updated_at :datetime not null
id_name :string(255)
sorter :integer
mobile_content :text
teaser :string(255)
default :boolean
description :text
offline_days :string(255)
offline_time_active :boolean
alternative_content :text
offline_date_start :date
offline_date_end :date
offline_time_week_start_end :text
Constant Summary collapse
- OfflineDays =
["Mo", 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']
- OfflineDaysEN =
['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su']
Instance Attribute Summary collapse
-
#offline_time_end_fr ⇒ Object
Returns the value of attribute offline_time_end_fr.
-
#offline_time_end_mo ⇒ Object
Returns the value of attribute offline_time_end_mo.
-
#offline_time_end_sa ⇒ Object
Returns the value of attribute offline_time_end_sa.
-
#offline_time_end_su ⇒ Object
Returns the value of attribute offline_time_end_su.
-
#offline_time_end_th ⇒ Object
Returns the value of attribute offline_time_end_th.
-
#offline_time_end_tu ⇒ Object
Returns the value of attribute offline_time_end_tu.
-
#offline_time_end_we ⇒ Object
Returns the value of attribute offline_time_end_we.
-
#offline_time_start_fr ⇒ Object
Returns the value of attribute offline_time_start_fr.
-
#offline_time_start_mo ⇒ Object
Returns the value of attribute offline_time_start_mo.
-
#offline_time_start_sa ⇒ Object
Returns the value of attribute offline_time_start_sa.
-
#offline_time_start_su ⇒ Object
Returns the value of attribute offline_time_start_su.
-
#offline_time_start_th ⇒ Object
Returns the value of attribute offline_time_start_th.
-
#offline_time_start_tu ⇒ Object
Returns the value of attribute offline_time_start_tu.
-
#offline_time_start_we ⇒ Object
Returns the value of attribute offline_time_start_we.
Instance Method Summary collapse
- #offline_date_end_display ⇒ Object
-
#offline_date_start_display ⇒ Object
def offline_time_end_display if self.offline_time_end.present? self.offline_time_end.strftime(“%H%M”) else “” end end.
- #offline_day ⇒ Object
- #offline_day=(wert) ⇒ Object
- #offline_time_week ⇒ Object
- #set_default_tag ⇒ Object
- #set_week_start_end_times ⇒ Object
- #validate_start_end_time ⇒ Object
Instance Attribute Details
#offline_time_end_fr ⇒ Object
Returns the value of attribute offline_time_end_fr.
36 37 38 |
# File 'app/models/widget.rb', line 36 def offline_time_end_fr @offline_time_end_fr end |
#offline_time_end_mo ⇒ Object
Returns the value of attribute offline_time_end_mo.
35 36 37 |
# File 'app/models/widget.rb', line 35 def offline_time_end_mo @offline_time_end_mo end |
#offline_time_end_sa ⇒ Object
Returns the value of attribute offline_time_end_sa.
36 37 38 |
# File 'app/models/widget.rb', line 36 def offline_time_end_sa @offline_time_end_sa end |
#offline_time_end_su ⇒ Object
Returns the value of attribute offline_time_end_su.
37 38 39 |
# File 'app/models/widget.rb', line 37 def offline_time_end_su @offline_time_end_su end |
#offline_time_end_th ⇒ Object
Returns the value of attribute offline_time_end_th.
36 37 38 |
# File 'app/models/widget.rb', line 36 def offline_time_end_th @offline_time_end_th end |
#offline_time_end_tu ⇒ Object
Returns the value of attribute offline_time_end_tu.
35 36 37 |
# File 'app/models/widget.rb', line 35 def offline_time_end_tu @offline_time_end_tu end |
#offline_time_end_we ⇒ Object
Returns the value of attribute offline_time_end_we.
35 36 37 |
# File 'app/models/widget.rb', line 35 def offline_time_end_we @offline_time_end_we end |
#offline_time_start_fr ⇒ Object
Returns the value of attribute offline_time_start_fr.
36 37 38 |
# File 'app/models/widget.rb', line 36 def offline_time_start_fr @offline_time_start_fr end |
#offline_time_start_mo ⇒ Object
Returns the value of attribute offline_time_start_mo.
35 36 37 |
# File 'app/models/widget.rb', line 35 def offline_time_start_mo @offline_time_start_mo end |
#offline_time_start_sa ⇒ Object
Returns the value of attribute offline_time_start_sa.
36 37 38 |
# File 'app/models/widget.rb', line 36 def offline_time_start_sa @offline_time_start_sa end |
#offline_time_start_su ⇒ Object
Returns the value of attribute offline_time_start_su.
37 38 39 |
# File 'app/models/widget.rb', line 37 def offline_time_start_su @offline_time_start_su end |
#offline_time_start_th ⇒ Object
Returns the value of attribute offline_time_start_th.
36 37 38 |
# File 'app/models/widget.rb', line 36 def offline_time_start_th @offline_time_start_th end |
#offline_time_start_tu ⇒ Object
Returns the value of attribute offline_time_start_tu.
35 36 37 |
# File 'app/models/widget.rb', line 35 def offline_time_start_tu @offline_time_start_tu end |
#offline_time_start_we ⇒ Object
Returns the value of attribute offline_time_start_we.
35 36 37 |
# File 'app/models/widget.rb', line 35 def offline_time_start_we @offline_time_start_we end |
Instance Method Details
#offline_date_end_display ⇒ Object
96 97 98 99 100 101 102 |
# File 'app/models/widget.rb', line 96 def offline_date_end_display if self.offline_date_end.present? self.offline_date_end.strftime("%Y%m%d") else "" end end |
#offline_date_start_display ⇒ Object
def offline_time_end_display
if self.offline_time_end.present?
self.offline_time_end.strftime("%H%M")
else
""
end
end
88 89 90 91 92 93 94 |
# File 'app/models/widget.rb', line 88 def offline_date_start_display if self.offline_date_start.present? self.offline_date_start.strftime("%Y%m%d") else "" end end |
#offline_day ⇒ Object
68 69 70 |
# File 'app/models/widget.rb', line 68 def offline_day self.offline_days.split(",").map{|tag| tag.strip} if self.offline_days.present? end |
#offline_day=(wert) ⇒ Object
64 65 66 |
# File 'app/models/widget.rb', line 64 def offline_day=(wert) self.offline_days = wert.flatten.uniq.compact.delete_if{|a|a==""}.join(",") end |
#offline_time_week ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'app/models/widget.rb', line 104 def offline_time_week result = Hash.new if self.offline_time_week_start_end.present? self.offline_time_week_start_end.each do |key,value| result["data-time-day-#{key}"] = value end end return result end |
#set_default_tag ⇒ Object
60 61 62 |
# File 'app/models/widget.rb', line 60 def set_default_tag self.tag_list = "sidebar" if self.tag_list.blank? end |
#set_week_start_end_times ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/models/widget.rb', line 129 def set_week_start_end_times self.offline_time_week_start_end = Hash.new OfflineDays.each_with_index do |day,index| if self.offline_day.present? && self.offline_day.include?(day) current_day = OfflineDaysEN[index] if current_day.present? start_time = eval("self.offline_time_start_#{current_day}").to_s.gsub(/\D/, "").strip end_time = eval("self.offline_time_end_#{current_day}").to_s.gsub(/\D/, "").strip start_time = "0001" if start_time.blank? end_time = "2359" if end_time.blank? self.offline_time_week_start_end[current_day] = "#{start_time}-#{end_time}" end end end end |
#validate_start_end_time ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'app/models/widget.rb', line 145 def validate_start_end_time if self.offline_time_active # if self.offline_time_start.present? && self.offline_time_end.present? # if self.offline_time_start > self.offline_time_end # errors.add(:offline_time_start, 'Startzeit muss VOR Endzeit liegen') # errors.add(:offline_time_end, 'Startzeit muss VOR Endzeit liegen') # end # else # errors.add(:offline_time_start, 'Zeit muss gesetzt werden') # errors.add(:offline_time_end, 'Zeit muss gesetzt werden') # end if self.offline_days.blank? errors.add(:offline_day, 'Mindestens ein Tag muss ausgewählt sein.') end end end |