Module: Kryptonite::KryptoniteHelper

Included in:
KryptoniteController, ScaffoldGenerator
Defined in:
app/helpers/kryptonite/kryptonite_helper.rb

Instance Method Summary collapse

Instance Method Details

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

Styled form tag helpers



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 80

def kryptonite_assets_field form, obj, attribute, options = {}
 content_key = eval("obj.#{attribute}")
 content_key = "#{obj.class.name.demodulize.downcase}_#{attribute}_#{rand(36**8).to_s(36)}" if !content_key
 path = upload_kryptonite_asset_path(content_key)
  content = "<p><label>Dateiupload</label></p><p><div id=\"uploader\"></div></p>"
  content += javascript_tag("var uploader = new qq.FileUploader({
                      	        element: $('#uploader')[0],
                      	        action: \"#{path}\",
                      	        multiple: #{options[:multiple] ? options[:multiple] : "false"},
                      			allowedExtensions: [#{options[:extenstions] ? options[:extenstions] : "'jpg', 'jpeg', 'png'"}],
                      			onSubmit: function(id, fileName) {uploader.setParams({ffmultiple: #{options[:multiple] ? options[:multiple] : "false"}, ffsize: '#{options[:size] ? options[:size] : "200x200#"}', authenticity_token: $('meta[name=\"csrf-token\"]').attr('content')}); },
                      			onComplete: function(id, fileName, responseJSON) { }
                      	    });")
  content += "<ul id=\"assets\">"
  Asset.find_all_by_content_key(content_key).each do |asset|
    content += "<li>"
    content += link_to(asset.file_file_name, asset.file.url(:normal), :target=>"_blank")
    content += link_to(kryptonite_show_row_icon("delete"), kryptonite_asset_path(asset), :method => :delete, :remote=>true, :onclick=>"$(this).parent().remove()", :class=>"delete") if @session_user.is_user? || @session_user.is_admin?
    content += "</li>"
  end
  content += "</ul>"
  content += hidden_field_tag("#{obj.class.name.demodulize.downcase}[#{attribute.to_s}]", content_key).html_safe
  content.html_safe
end

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



121
122
123
124
125
126
127
128
129
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 121

def kryptonite_check_box form, obj, attribute, options = {}
  form_tag = form.check_box(attribute, strip_kryptonite_options(options))

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

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

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



131
132
133
134
135
136
137
138
139
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 131

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

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

  kryptonite_form_tag_wrapper form_tag, form, obj, attribute, options
end

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



169
170
171
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 169

def kryptonite_collection_select form, obj, object, attribute, collection, value_method, text_method, options = {}
	kryptonite_form_tag_wrapper(collection_select(object, attribute, collection, value_method, text_method, strip_kryptonite_options(options), merged_class_hash(options, 'kryptoniteSelect')), form, obj, attribute, options).html_safe
end

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



173
174
175
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 173

def kryptonite_date_select form, obj, attribute, options = {}
  kryptonite_form_tag_wrapper(form.date_select(attribute, strip_kryptonite_options(options), merged_class_hash(options, 'kryptoniteDateTimeSelect')), form, obj, attribute, options).html_safe
end

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



181
182
183
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 181

def kryptonite_datetime_select form, obj, attribute, options = {}
  kryptonite_form_tag_wrapper(form.datetime_select(attribute, strip_kryptonite_options(options), merged_class_hash(options, 'kryptoniteDateTimeSelect')), form, obj, attribute, options).html_safe
end

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



185
186
187
188
189
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 185

def kryptonite_file_field form, obj, object_name, attribute, options = {}
  class_hash = merged_class_hash(options, 'kryptoniteFileFieldContainer')
  contents = "<div class='#{class_hash[:class]}'>" + file_field(object_name, attribute, strip_kryptonite_options(options)) + '</div>'
  kryptonite_form_tag_wrapper(contents, form, obj, attribute, options).html_safe
end

#kryptonite_generate_page_titleObject



18
19
20
21
22
23
24
25
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 18

def kryptonite_generate_page_title
		
	if @kryptonite_page_title.nil?
		return kryptonite_config_website_name
	end
		
	@kryptonite_page_title + " > " + kryptonite_config_website_name
end

#kryptonite_get_access_level_arrayObject



40
41
42
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 40

def kryptonite_get_access_level_array
  [["Administrator", $KRYPTONITE_USER_ACCESS_LEVEL_ADMIN], ["User", $KRYPTONITE_USER_ACCESS_LEVEL_USER], ["Frontend User", $KRYPTONITE_USER_ACCESS_LEVEL_FE_USER]]
end

#kryptonite_get_access_level_text(level) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 27

def kryptonite_get_access_level_text level
  case level
     when $KRYPTONITE_USER_ACCESS_LEVEL_ADMIN
       return "Administrator"
     when $KRYPTONITE_USER_ACCESS_LEVEL_USER
      return "User"
    when $KRYPTONITE_USER_ACCESS_LEVEL_FE_USER
      return "Frontend User"
    else
      return "Unknown"
  end
end

#kryptonite_get_full_version_stringObject



8
9
10
11
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 8

def kryptonite_get_full_version_string
  version_info = kryptonite_get_version_info
  "v.#{version_info['major']}.#{version_info['minor']}.#{version_info['patch']}"
end

#kryptonite_get_language_arrayObject



44
45
46
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 44

def kryptonite_get_language_array
  [['English', 'en'], ['Deutsch', 'de']]
end

#kryptonite_get_short_version_stringObject



13
14
15
16
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 13

def kryptonite_get_short_version_string
  version_info = kryptonite_get_version_info
  "v.#{version_info['major']}"
end

#kryptonite_get_version_infoObject



4
5
6
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 4

def kryptonite_get_version_info  
  YAML::load_file File.join(File.dirname(__FILE__), '..', '..', '..', 'PUBLIC_VERSION.yml')
end

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



191
192
193
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 191

def kryptonite_hidden_field form, obj, attribute, options = {}
  form.hidden_field(attribute, strip_kryptonite_options(options)).html_safe
end

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



109
110
111
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 109

def kryptonite_password_field form, obj, attribute, options = {}
	kryptonite_form_tag_wrapper(form.password_field(attribute, strip_kryptonite_options(options_hash_with_merged_classes(options, 'kryptoniteTextField'))), form, obj, attribute, options).html_safe
end

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



141
142
143
144
145
146
147
148
149
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 141

def kryptonite_radio_button form, obj, attribute, tag_value, options = {}
  form_tag = form.radio_button(obj, attribute, tag_value, strip_kryptonite_options(options))

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

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

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



151
152
153
154
155
156
157
158
159
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 151

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

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

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

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



161
162
163
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 161

def kryptonite_select form, obj, attribute, option_tags, options = {}
	kryptonite_form_tag_wrapper(form.select(attribute, option_tags, strip_kryptonite_options(options), merged_class_hash(options, 'kryptoniteSelect')), form, obj, attribute, options).html_safe
end

#kryptonite_show_icon(icon_name) ⇒ Object



70
71
72
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 70

def kryptonite_show_icon icon_name
	"<div class='icon'><img src='/assets/kryptonite/icons/#{icon_name}.png' alt='' /></div>".html_safe
end

#kryptonite_show_row_icon(icon_name) ⇒ Object



74
75
76
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 74

def kryptonite_show_row_icon icon_name
	"<div class='iconRow'><img src='/assets/kryptonite/icons/#{icon_name}.png' alt='' /></div>".html_safe
end


48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 48

def kryptonite_table_cell_link contents, link, options = {}
 
 contents = strip_tags(contents.to_s)
	  
 if options.key? :kryptonite_truncate
   contents = truncate(contents, :length => options[:kryptonite_truncate], :omission => "...")
 end
	  
	link_to "#{contents}".html_safe, link, options
end


59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 59

def kryptonite_table_cell_no_link contents, options = {}
	  
 contents = strip_tags(contents.to_s)
	  
 if options.key? :kryptonite_truncate
   contents = truncate(contents, :length => options[:kryptonite_truncate], :omission => "...")
 end
	  
	"<div class='noLink'>#{contents}</div>".html_safe
end

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



113
114
115
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 113

def kryptonite_text_area form, obj, attribute, options = {}
  kryptonite_form_tag_wrapper(form.text_area(attribute, strip_kryptonite_options(options_hash_with_merged_classes(options, 'kryptoniteTextArea'))), form, obj, attribute, options).html_safe
end

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



117
118
119
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 117

def kryptonite_text_area_big form, obj, attribute, options = {}
 kryptonite_form_tag_wrapper(form.text_area(attribute, strip_kryptonite_options(options_hash_with_merged_classes(options, 'kryptoniteTextAreaBig'))), form, obj, attribute, options).html_safe
end

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



105
106
107
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 105

def kryptonite_text_field form, obj, attribute, options = {}
  kryptonite_form_tag_wrapper(form.text_field(attribute, strip_kryptonite_options(options_hash_with_merged_classes(options, 'kryptoniteTextField'))), form, obj, attribute, options).html_safe
end

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



177
178
179
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 177

def kryptonite_time_select form, obj, attribute, options = {}
  kryptonite_form_tag_wrapper(form.time_select(attribute, strip_kryptonite_options(options), merged_class_hash(options, 'kryptoniteDateTimeSelect')), form, obj, attribute, options).html_safe
end

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



165
166
167
# File 'app/helpers/kryptonite/kryptonite_helper.rb', line 165

def kryptonite_time_zone_select form, obj, attribute, option_tags, options = {}
  kryptonite_form_tag_wrapper(form.time_zone_select(attribute, option_tags, strip_kryptonite_options(options), merged_class_hash(options, 'kryptoniteSelect')), form, obj, attribute, options).html_safe
end