Module: EventCalendar::ApplicationHelper

Defined in:
app/helpers/event_calendar/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#div_for_record(record, options = {}, &block) ⇒ Object



2
3
4
# File 'app/helpers/event_calendar/application_helper.rb', line 2

def div_for_record(record, options={}, &block)
  div_for(record, options){ yield }
end

#event_calendar_asset_prefixObject



220
221
222
# File 'app/helpers/event_calendar/application_helper.rb', line 220

def event_calendar_asset_prefix
  'event_calendar/'
end

#event_calendar_javascript_includesObject



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'app/helpers/event_calendar/application_helper.rb', line 224

def event_calendar_javascript_includes
  list = [
    "#{event_calendar_asset_prefix}jquery.tablesorter.min.js",
    "#{event_calendar_asset_prefix}jquery-ui-1.8.16.custom.min.js",
    "#{event_calendar_asset_prefix}jquery.string.1.0-min.js",
    "#{event_calendar_asset_prefix}jquery.clonePosition.js",
    "#{event_calendar_asset_prefix}lowpro.jquery.js",
    "#{event_calendar_asset_prefix}fullcalendar.js",
    "#{event_calendar_asset_prefix}jquery.qtip-1.0.0-rc3.js",
    "#{event_calendar_asset_prefix}rails",
    "#{event_calendar_asset_prefix}event_calendar_behaviors.js",
    "#{event_calendar_asset_prefix}event_calendar.js"
  ]
  unless Rails.env == 'production'
    list.unshift("#{event_calendar_asset_prefix}jquery")
  else
    list.unshift("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js")
  end
end

#event_times(event) ⇒ Object



60
61
62
63
64
65
66
67
# File 'app/helpers/event_calendar/application_helper.rb', line 60

def event_times(event)
  t = []
  event_times = times_with_zones(event)
  event_times.first.each_with_index do |z_t, i|
    t << "#{z_t.last} - #{event_times.last[i].last} " + (:em, z_t.first)
  end
  t.join(" / ").html_safe
end

#form_for_browse_event_revisions(event) ⇒ Object



199
200
201
202
203
204
# File 'app/helpers/event_calendar/application_helper.rb', line 199

def form_for_browse_event_revisions(event)
  return unless has_authorization?(:update, event)
  render :partial => 'events/browse_event_revisions', :locals => {
    :event => event
  }
end

#hour_optionsObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/helpers/event_calendar/application_helper.rb', line 76

def hour_options
  [
    ['6 AM','6'],
    ['7 AM','7'],
    ['8 AM','8'],
    ['9 AM','9'],
    ['10 AM','10'],
    ['11 AM','11'],
    ['12 PM','12'],
    ['1 PM','13'],
    ['2 PM','14'],
    ['3 PM','15'],
    ['4 PM','16'],
    ['5 PM','17'],
    ['6 PM','18'],
    ['7 PM','19'],
    ['8 PM','20']
  ]
end


132
133
134
135
136
137
# File 'app/helpers/event_calendar/application_helper.rb', line 132

def link_to_add_event_attendees(event, wrapper_options={})
  return unless has_authorization?(:add_attendees, event)
  link_wrapper(new_event_attendee_path(event), wrapper_options, {
    :link_text => "Add <em>#{h(event.name)}</em> Attendees".html_safe
  })
end


174
175
176
177
178
179
180
181
182
183
# File 'app/helpers/event_calendar/application_helper.rb', line 174

def link_to_delete_event(event, wrapper_options={}, link_options={})
  return unless has_authorization?(:delete, event)
  link_wrapper(event_path(event), {
    :highlight => false
  }.merge!(wrapper_options), {
    :link_text => "Delete <em>#{event.name}</em>".html_safe,
    :confirm => "Are you sure you want to permanently delete the #{event.name} #{event.event_type}?",
    :method => "delete"
  }.merge!(link_options))
end


163
164
165
166
167
168
169
170
171
172
# File 'app/helpers/event_calendar/application_helper.rb', line 163

def link_to_delete_link(event, link, wrapper_options={}, link_options={})
  return unless has_authorization?(:delete, link)
  link_wrapper(event_link_path(event, link), {
    :no_wrapper => true
  }.merge!(wrapper_options), {
    :link_text => 'delete',
    :confirm => "Are you sure you want to permanently delete the #{link.name} link?",
    :method => "delete"
  }.merge!(link_options))
end


125
126
127
128
129
130
# File 'app/helpers/event_calendar/application_helper.rb', line 125

def link_to_deleted_events(wrapper_options={})
  return unless has_authorization?(:update, Event.new)
  link_wrapper(event_revisions_path, wrapper_options, {
    :link_text => "Browse Deleted Events (#{EventRevision.deleted.count})"
  })
end


139
140
141
142
143
144
# File 'app/helpers/event_calendar/application_helper.rb', line 139

def link_to_edit_event(event, wrapper_options={}, link_options={})
  return unless has_authorization?(:update, event)
  link_wrapper(edit_event_path(event), wrapper_options, {
    :link_text => "Edit <em>#{h(event.name)}</em>".html_safe
  }.merge!(link_options))
end


154
155
156
157
158
159
160
161
# File 'app/helpers/event_calendar/application_helper.rb', line 154

def link_to_edit_link(event, link, wrapper_options={}, link_options={})
  return unless has_authorization?(:update, link)
  link_wrapper(edit_event_link_path(event, link), {
    :no_wrapper => true
  }.merge!(wrapper_options), {
    :link_text => "update"
  }.merge!(link_options))
end


107
108
109
110
111
112
113
114
# File 'app/helpers/event_calendar/application_helper.rb', line 107

def link_to_event_revisions(wrapper_options={}, link_options={})
  return unless has_authorization?(:read, EventRevision.new)
  link_wrapper(event_revisions_path, {
    :no_wrapper => true
  }.merge!(wrapper_options), {
    :link_text => 'Browse Event Revisions'
  }.merge!(link_options))
end


100
101
102
103
104
105
# File 'app/helpers/event_calendar/application_helper.rb', line 100

def link_to_events(wrapper_options={}, link_options={})
  return unless has_authorization?(:read, Event.new)
  link_wrapper(events_path, wrapper_options, link_options.reverse_merge!({
    :link_text => 'Event Calendar'
  }))
end


116
117
118
119
120
121
122
123
# File 'app/helpers/event_calendar/application_helper.rb', line 116

def link_to_new_event(wrapper_options={}, link_options={})
  return unless has_authorization?(:create, Event.new)
  link_wrapper(new_event_path, {
    :no_wrapper => true
  }.merge!(wrapper_options), {
    :link_text => "Create New Event"
  }.merge!(link_options))
end


146
147
148
149
150
151
152
# File 'app/helpers/event_calendar/application_helper.rb', line 146

def link_to_new_link(event, wrapper_options={}, link_options={})
  return unless has_authorization?(:create, Link.new)
  link_wrapper(new_event_link_path(event), wrapper_options, {
    :link_text => 'Add a new link to this event',
    :class => 'fake_button'
  }.merge!(link_options))
end


9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/event_calendar/application_helper.rb', line 9

def link_wrapper(path, wrapper_options={}, link_options={})
  tag       = wrapper_options.delete(:tag) || :p
  link_text = link_options.delete(:link_text) || path

  unless wrapper_options.delete(:no_wrapper)
    return (tag, wrapper_options) do
      link_to(link_text, path, link_options)
    end
  else
    return link_to(link_text, path, link_options)
  end
end


185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'app/helpers/event_calendar/application_helper.rb', line 185

def links_to_edit_and_delete_event(event, wrapper_options={}, link_options={})
  return unless has_authorization?(:delete, event) || has_authorization?(:update, event)
  link_to_edit_event(event, {
    :no_wrapper => true
  }.merge!(wrapper_options), {
    :link_text => 'update'
  }.merge!(link_options)) + " " +
  link_to_delete_event(event, {
    :no_wrapper => true
  }.merge!(wrapper_options), {
    :link_text => 'delete'
  }.merge!(link_options))
end

#minute_optionsObject



96
97
98
# File 'app/helpers/event_calendar/application_helper.rb', line 96

def minute_options
  ['00', '15', '30', '45']
end

#open_if_current_month(month, closed_or_open) ⇒ Object



22
23
24
25
26
27
# File 'app/helpers/event_calendar/application_helper.rb', line 22

def open_if_current_month(month, closed_or_open)
  # setting closed_or_open='closed' in args does not seem to work when a
  # nil val is passed as the closed_or_open arg
  closed_or_open = closed_or_open.blank? ? 'closed' : closed_or_open
  Date.current.strftime("%B") == month ? 'open' : closed_or_open
end

#render_event_main_menuObject



212
213
214
# File 'app/helpers/event_calendar/application_helper.rb', line 212

def render_event_main_menu
  render :partial => 'event-calendar-shared/main_menu'
end

#render_event_navigation(event = nil) ⇒ Object



206
207
208
209
210
# File 'app/helpers/event_calendar/application_helper.rb', line 206

def render_event_navigation(event=nil)
  render :partial => 'event-calendar-shared/navigation', :locals => {
    :event => event
  }
end

#render_flashObject



216
217
218
# File 'app/helpers/event_calendar/application_helper.rb', line 216

def render_flash
  render :partial => 'event-calendar-shared/flash', :object => flash
end

#tag_for_record(tag, record, *args, &block) ⇒ Object



5
6
7
# File 'app/helpers/event_calendar/application_helper.rb', line 5

def tag_for_record(tag, record, *args, &block)
  (tag, record, *args){ yield }
end

#time_with_zones(time = Time.now) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/event_calendar/application_helper.rb', line 29

def time_with_zones(time=Time.now)
  out = []
  ActiveSupport::TimeZone.us_zones.map(&:name).each do |us_zone|
    next unless us_zone =~ /Pacific|Mountain|Central|Eastern/
    key = time.in_time_zone(us_zone).strftime("%Z")
    key = timezone_in_words(key.strip)
    # out[key] = time.in_time_zone(us_zone).strftime(format)
    out << [key, time.in_time_zone(us_zone).strftime(TIME_BASE)]
  end
  out.reverse
end

#times_with_zones(event) ⇒ Object



69
70
71
72
73
74
# File 'app/helpers/event_calendar/application_helper.rb', line 69

def times_with_zones(event)
  [
    time_with_zones(event.start_time),
    time_with_zones(event.end_time)
  ]
end

#timezone_in_words(zone) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/helpers/event_calendar/application_helper.rb', line 41

def timezone_in_words(zone)
  pac_regex = /^P(S|D)T$/
  mnt_regex = /^M(S|D)T$/
  ctr_regex = /^C(S|D)T$/
  est_regex = /^E(S|D)T$/
  case zone
  when pac_regex
    zone.gsub(pac_regex, 'Pacific')
  when mnt_regex
    zone.gsub(mnt_regex, 'Mountain')
  when ctr_regex
    zone.gsub(ctr_regex, 'Central')
  when est_regex
    zone.gsub(est_regex, 'Eastern')
  else
    zone
  end
end