Module: Caseadilla::CaseadillaHelper

Included in:
CaseadillaController, ScaffoldGenerator
Defined in:
app/helpers/caseadilla/caseadilla_helper.rb

Instance Method Summary collapse

Instance Method Details

#caseadilla_check_box(form, obj, attribute, options = {}) ⇒ Object


132
133
134
135
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 132

def caseadilla_check_box form, obj, attribute, options = {}
  form_tag = "<div class='check-box'>#{form.check_box(attribute, strip_caseadilla_options(options))}</div>".html_safe
  caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
end

#caseadilla_check_box_group(form, obj, check_boxes = {}) ⇒ Object


137
138
139
140
141
142
143
144
145
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 137

def caseadilla_check_box_group form, obj, check_boxes = {}
  form_tags = ""

  for check_box in check_boxes
    form_tags += caseadilla_check_box form, obj, check_box[0], check_box[1]
  end

  caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options)
end

#caseadilla_collection_check_boxes(form, obj, attribute, collection, value_method, text_method, options = {}) ⇒ Object


179
180
181
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 179

def caseadilla_collection_check_boxes form, obj, attribute, collection, value_method, text_method, options = {}
  caseadilla_form_tag_wrapper(collection_check_boxes(obj.class.name.downcase.to_sym, attribute, collection, value_method, text_method, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
end

#caseadilla_collection_select(form, obj, attribute, collection, value_method, text_method, options = {}) ⇒ Object


175
176
177
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 175

def caseadilla_collection_select form, obj, attribute, collection, value_method, text_method, options = {}
  caseadilla_form_tag_wrapper(collection_select(obj.class.name.downcase.to_sym, attribute, collection, value_method, text_method, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
end

#caseadilla_color_field(form, obj, attribute, options = {}) ⇒ Object


214
215
216
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 214

def caseadilla_color_field form, obj, attribute, options = {}
    caseadilla_form_tag_wrapper(form.color_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_custom_field(form, obj, attribute, custom_contents, options = {}) ⇒ Object


210
211
212
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 210

def caseadilla_custom_field form, obj, attribute, custom_contents, options = {}
  caseadilla_form_tag_wrapper(custom_contents, form, obj, attribute, options).html_safe
end

#caseadilla_date_field(form, obj, attribute, options = {}) ⇒ Object


234
235
236
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 234

def caseadilla_date_field form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.date_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_date_select(form, obj, attribute, options = {}) ⇒ Object


183
184
185
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 183

def caseadilla_date_select form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper("<div class='caseadilla-date-select'>".html_safe + form.date_select(attribute, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
end

#caseadilla_datetime_field(form, obj, attribute, options = {}) ⇒ Object


238
239
240
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 238

def caseadilla_datetime_field form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.datetime_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_datetime_local_field(form, obj, attribute, options = {}) ⇒ Object


242
243
244
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 242

def caseadilla_datetime_local_field form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.datetime_local_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_datetime_select(form, obj, attribute, options = {}) ⇒ Object


191
192
193
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 191

def caseadilla_datetime_select form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper("<div class='caseadilla-datetime-select'>".html_safe + form.datetime_select(attribute, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
end

#caseadilla_email_field(form, obj, attribute, options = {}) ⇒ Object


230
231
232
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 230

def caseadilla_email_field form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.email_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_file_field(form, obj, object_name, attribute, options = {}) ⇒ Object


195
196
197
198
199
200
201
202
203
204
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 195

def caseadilla_file_field form, obj, object_name, attribute, options = {}
  class_hash = merged_class_hash(options, 'form-control')
  contents = "<div class='#{class_hash[:class]}'>" + file_field(object_name, attribute, strip_caseadilla_options(options)) + '</div>'

  if options.key? :caseadilla_contents_preview
    contents = options[:caseadilla_contents_preview].html_safe + contents.html_safe
  end

  caseadilla_form_tag_wrapper(contents, form, obj, attribute, options).html_safe
end

#caseadilla_format_date(date, format = "%b %d, %Y") ⇒ Object


74
75
76
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 74

def caseadilla_format_date date, format = "%b %d, %Y"
  date.strftime(format)
end

#caseadilla_format_datetime(datetime, format = "%b %d, %Y %H:%M") ⇒ Object


82
83
84
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 82

def caseadilla_format_datetime datetime, format = "%b %d, %Y %H:%M"
  datetime.strftime(format)
end

#caseadilla_format_time(time, format = "%H:%M") ⇒ Object


78
79
80
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 78

def caseadilla_format_time time, format = "%H:%M"
  time.strftime(format)
end

#caseadilla_generate_page_titleObject


20
21
22
23
24
25
26
27
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 20

def caseadilla_generate_page_title

  if @caseadilla_page_title.nil?
    return caseadilla_config_website_name
  end

  caseadilla_config_website_name + " > " + @caseadilla_page_title
end

#caseadilla_get_access_level_arrayObject


40
41
42
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 40

def caseadilla_get_access_level_array
  [["Administrator", $caseadilla_USER_ACCESS_LEVEL_ADMIN], ["User", $caseadilla_USER_ACCESS_LEVEL_USER]]
end

#caseadilla_get_access_level_text(level) ⇒ Object


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

def caseadilla_get_access_level_text level
  case level
    when $caseadilla_USER_ACCESS_LEVEL_ADMIN
      return "Administrator"
    when $caseadilla_USER_ACCESS_LEVEL_USER
      return "User"
    else
      return "Unknown"
  end
end

4
5
6
7
8
9
10
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 4

def caseadilla_get_footer_string include_version = false
  if include_version
    "Running on #{link_to 'Caseadilla', 'http://www.github.com/zeiv/caseadilla'} #{caseadilla_get_full_version_string}, an open-source project.".html_safe
  else
    "Running on #{link_to 'Caseadilla', 'http://www.github.com/zeiv/caseadilla'}, an open-source project.".html_safe
  end
end

#caseadilla_get_full_version_stringObject


12
13
14
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 12

def caseadilla_get_full_version_string
  Caseadilla::VERSION
end

#caseadilla_get_short_version_stringObject


16
17
18
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 16

def caseadilla_get_short_version_string
  Caseadilla::VERSION.slice(0..(str.index('.')))
end

#caseadilla_hidden_field(form, obj, attribute, options = {}) ⇒ Object


206
207
208
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 206

def caseadilla_hidden_field form, obj, attribute, options = {}
  form.hidden_field(attribute, strip_caseadilla_options(options)).html_safe
end

#caseadilla_month_field(form, obj, attribute, options = {}) ⇒ Object


246
247
248
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 246

def caseadilla_month_field form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.month_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_no_yes_label(value) ⇒ Object


105
106
107
108
109
110
111
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 105

def caseadilla_no_yes_label value
  if value
    return "<span class='label label-danger'>Yes</span>".html_safe
  else
    return "<span class='label label-success'>No</span>".html_safe
  end
end

#caseadilla_number_field(form, obj, attribute, options = {}) ⇒ Object


258
259
260
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 258

def caseadilla_number_field form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.number_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_pagination_details(objs) ⇒ Object


44
45
46
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 44

def caseadilla_pagination_details objs
  " <small class='pagination-details'>/ page #{objs.current_page} of #{objs.total_pages}</small>".html_safe if objs.current_page && objs.total_pages > 1
end

#caseadilla_password_field(form, obj, attribute, options = {}) ⇒ Object


119
120
121
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 119

def caseadilla_password_field form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.password_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_radio_button(form, obj, attribute, tag_value, options = {}) ⇒ Object


147
148
149
150
151
152
153
154
155
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 147

def caseadilla_radio_button form, obj, attribute, tag_value, options = {}
  form_tag = form.radio_button(obj, attribute, tag_value, strip_caseadilla_options(options))

  if options.key? :caseadilla_button_label
    form_tag = "<div>" + form_tag + "<span class=\"rcText\">#{options[:caseadilla_button_label]}</span></div>".html_safe
  end

  caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
end

#caseadilla_radio_button_group(form, obj, radio_buttons = {}) ⇒ Object


157
158
159
160
161
162
163
164
165
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 157

def caseadilla_radio_button_group form, obj, radio_buttons = {}
  form_tags = ""

  for radio_button in radio_buttons
    form_tags += caseadilla_radio_button form, obj, check_box[0], check_box[1], check_box[2]
  end

  caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
end

#caseadilla_range_field(form, obj, attribute, options = {}) ⇒ Object


262
263
264
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 262

def caseadilla_range_field form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.range_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_search_field(form, obj, attribute, options = {}) ⇒ Object


218
219
220
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 218

def caseadilla_search_field form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.search_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_select(form, obj, attribute, option_tags, options = {}) ⇒ Object


167
168
169
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 167

def caseadilla_select form, obj, attribute, option_tags, options = {}
  caseadilla_form_tag_wrapper(form.select(attribute, option_tags, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
end

#caseadilla_show_icon(icon_name) ⇒ Object


66
67
68
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 66

def caseadilla_show_icon icon_name
  "<div class='icon'><span class='glyphicon glyphicon-#{icon_name}'></span></div>".html_safe
end

#caseadilla_show_row_icon(icon_name) ⇒ Object


70
71
72
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 70

def caseadilla_show_row_icon icon_name
  "<div class='iconRow'><span class='glyphicon glyphicon-#{icon_name}'></span></div>".html_safe
end

86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 86

def caseadilla_sort_link title, column, options = {}
  condition = options[:unless] if options.has_key?(:unless)
  icon_to_show_html = "<div class='table-header-icon'>&nbsp;</div>".html_safe
  if params[:c].to_s == column.to_s
    icon_to_show = params[:d] == 'down' ? 'chevron-up' : 'chevron-down'
    icon_to_show_html = "<div class='table-header-icon glyphicon glyphicon-#{icon_to_show}'></div>".html_safe
  end
  sort_dir = params[:d] == 'down' ? 'up' : 'down'
  link_to_unless(condition, title, request.parameters.merge({:c => column, :d => sort_dir})) + icon_to_show_html
end

48
49
50
51
52
53
54
55
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 48

def caseadilla_table_cell_link contents, link, options = {}

  if options.key? :caseadilla_truncate
    contents = truncate(contents, :length => options[:caseadilla_truncate], :omission => "...")
  end

  link_to "#{contents}".html_safe, link, options
end

57
58
59
60
61
62
63
64
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 57

def caseadilla_table_cell_no_link contents, options = {}

  if options.key? :caseadilla_truncate
    contents = truncate(contents, :length => options[:caseadilla_truncate], :omission => "...")
  end

  "<div class='no-link'>#{contents}</div>".html_safe
end

#caseadilla_telephone_field(form, obj, attribute, options = {}) ⇒ Object


222
223
224
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 222

def caseadilla_telephone_field form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.telephone_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_text_area(form, obj, attribute, options = {}) ⇒ Object


123
124
125
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 123

def caseadilla_text_area form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.text_area(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_text_area_wysiwym(form, obj, attribute, options = {}) ⇒ Object


127
128
129
130
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 127

def caseadilla_text_area_wysiwym form, obj, attribute, options = {}
  options.reverse_merge!({style: "height: 250px;"})
  caseadilla_form_tag_wrapper(form.text_area(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control wysiwym'))), form, obj, attribute, options).html_safe
end

#caseadilla_text_field(form, obj, attribute, options = {}) ⇒ Object

Styled form tag helpers


115
116
117
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 115

def caseadilla_text_field form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.text_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_time_field(form, obj, attribute, options = {}) ⇒ Object


254
255
256
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 254

def caseadilla_time_field form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.time_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_time_select(form, obj, attribute, options = {}) ⇒ Object


187
188
189
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 187

def caseadilla_time_select form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper("<div class='caseadilla-time-select'>".html_safe + form.time_select(attribute, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
end

#caseadilla_time_zone_select(form, obj, attribute, option_tags, options = {}) ⇒ Object


171
172
173
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 171

def caseadilla_time_zone_select form, obj, attribute, option_tags, options = {}
  caseadilla_form_tag_wrapper(form.time_zone_select(attribute, option_tags, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
end

#caseadilla_url_field(form, obj, attribute, options = {}) ⇒ Object


226
227
228
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 226

def caseadilla_url_field form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.url_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_week_field(form, obj, attribute, options = {}) ⇒ Object


250
251
252
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 250

def caseadilla_week_field form, obj, attribute, options = {}
  caseadilla_form_tag_wrapper(form.week_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
end

#caseadilla_yes_no_label(value) ⇒ Object


97
98
99
100
101
102
103
# File 'app/helpers/caseadilla/caseadilla_helper.rb', line 97

def caseadilla_yes_no_label value
  if value
    return "<span class='label label-success'>Yes</span>".html_safe
  else
    return "<span class='label label-danger'>No</span>".html_safe
  end
end