Module: Kryptonite::KryptoniteHelper
- Included in:
- KryptoniteController, ScaffoldGenerator
- Defined in:
- app/helpers/kryptonite/kryptonite_helper.rb
Instance Method Summary collapse
-
#kryptonite_assets_field(form, obj, attribute, options = {}) ⇒ Object
Styled form tag helpers.
- #kryptonite_check_box(form, obj, attribute, options = {}) ⇒ Object
- #kryptonite_check_box_group(form, obj, check_boxes = {}) ⇒ Object
- #kryptonite_collection_select(form, obj, object, attribute, collection, value_method, text_method, options = {}) ⇒ Object
- #kryptonite_date_select(form, obj, attribute, options = {}) ⇒ Object
- #kryptonite_datetime_select(form, obj, attribute, options = {}) ⇒ Object
- #kryptonite_file_field(form, obj, object_name, attribute, options = {}) ⇒ Object
- #kryptonite_generate_page_title ⇒ Object
- #kryptonite_get_access_level_array ⇒ Object
- #kryptonite_get_access_level_text(level) ⇒ Object
- #kryptonite_get_full_version_string ⇒ Object
- #kryptonite_get_language_array ⇒ Object
- #kryptonite_get_short_version_string ⇒ Object
- #kryptonite_get_version_info ⇒ Object
- #kryptonite_hidden_field(form, obj, attribute, options = {}) ⇒ Object
- #kryptonite_password_field(form, obj, attribute, options = {}) ⇒ Object
- #kryptonite_radio_button(form, obj, attribute, tag_value, options = {}) ⇒ Object
- #kryptonite_radio_button_group(form, obj, radio_buttons = {}) ⇒ Object
- #kryptonite_select(form, obj, attribute, option_tags, options = {}) ⇒ Object
- #kryptonite_show_icon(icon_name) ⇒ Object
- #kryptonite_show_row_icon(icon_name) ⇒ Object
- #kryptonite_table_cell_link(contents, link, options = {}) ⇒ Object
- #kryptonite_table_cell_no_link(contents, options = {}) ⇒ Object
- #kryptonite_text_area(form, obj, attribute, options = {}) ⇒ Object
- #kryptonite_text_area_big(form, obj, attribute, options = {}) ⇒ Object
- #kryptonite_text_field(form, obj, attribute, options = {}) ⇒ Object
- #kryptonite_time_select(form, obj, attribute, options = {}) ⇒ Object
- #kryptonite_time_zone_select(form, obj, attribute, option_tags, options = {}) ⇒ Object
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, = {} 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: #{[:multiple] ? [:multiple] : "false"}, allowedExtensions: [#{[:extenstions] ? [:extenstions] : "'jpg', 'jpeg', 'png'"}], onSubmit: function(id, fileName) {uploader.setParams({ffmultiple: #{[:multiple] ? [:multiple] : "false"}, ffsize: '#{[:size] ? [: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, = {} form_tag = form.check_box(attribute, ()) if .key? :kryptonite_box_label form_tag = "<div>" + form_tag + "<span class=\"rcText\">#{[:kryptonite_box_label]}</span></div>".html_safe end kryptonite_form_tag_wrapper(form_tag, form, obj, attribute, ).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 = {} = "" for check_box in check_boxes += kryptonite_check_box form, obj, check_box[0], check_box[1] end kryptonite_form_tag_wrapper form_tag, form, obj, attribute, 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, = {} kryptonite_form_tag_wrapper(collection_select(object, attribute, collection, value_method, text_method, (), merged_class_hash(, 'kryptoniteSelect')), form, obj, attribute, ).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, = {} kryptonite_form_tag_wrapper(form.date_select(attribute, (), merged_class_hash(, 'kryptoniteDateTimeSelect')), form, obj, attribute, ).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, = {} kryptonite_form_tag_wrapper(form.datetime_select(attribute, (), merged_class_hash(, 'kryptoniteDateTimeSelect')), form, obj, attribute, ).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, = {} class_hash = merged_class_hash(, 'kryptoniteFileFieldContainer') contents = "<div class='#{class_hash[:class]}'>" + file_field(object_name, attribute, ()) + '</div>' kryptonite_form_tag_wrapper(contents, form, obj, attribute, ).html_safe end |
#kryptonite_generate_page_title ⇒ Object
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_array ⇒ Object
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_string ⇒ Object
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_array ⇒ Object
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_string ⇒ Object
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_info ⇒ Object
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, = {} form.hidden_field(attribute, ()).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, = {} kryptonite_form_tag_wrapper(form.password_field(attribute, ((, 'kryptoniteTextField'))), form, obj, attribute, ).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 form, obj, attribute, tag_value, = {} form_tag = form.(obj, attribute, tag_value, ()) if .key? :kryptonite_button_label form_tag = "<div>" + form_tag + "<span class=\"rcText\">#{[:kryptonite_button_label]}</span></div>".html_safe end kryptonite_form_tag_wrapper(form_tag, form, obj, attribute, ).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 form, obj, = {} = "" for in += form, obj, check_box[0], check_box[1], check_box[2] end kryptonite_form_tag_wrapper(form_tag, form, obj, attribute, ).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, , = {} kryptonite_form_tag_wrapper(form.select(attribute, , (), merged_class_hash(, 'kryptoniteSelect')), form, obj, attribute, ).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 |
#kryptonite_table_cell_link(contents, link, options = {}) ⇒ Object
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, = {} contents = (contents.to_s) if .key? :kryptonite_truncate contents = truncate(contents, :length => [:kryptonite_truncate], :omission => "...") end link_to "#{contents}".html_safe, link, end |
#kryptonite_table_cell_no_link(contents, options = {}) ⇒ Object
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, = {} contents = (contents.to_s) if .key? :kryptonite_truncate contents = truncate(contents, :length => [: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, = {} kryptonite_form_tag_wrapper(form.text_area(attribute, ((, 'kryptoniteTextArea'))), form, obj, attribute, ).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, = {} kryptonite_form_tag_wrapper(form.text_area(attribute, ((, 'kryptoniteTextAreaBig'))), form, obj, attribute, ).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, = {} kryptonite_form_tag_wrapper(form.text_field(attribute, ((, 'kryptoniteTextField'))), form, obj, attribute, ).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, = {} kryptonite_form_tag_wrapper(form.time_select(attribute, (), merged_class_hash(, 'kryptoniteDateTimeSelect')), form, obj, attribute, ).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, , = {} kryptonite_form_tag_wrapper(form.time_zone_select(attribute, , (), merged_class_hash(, 'kryptoniteSelect')), form, obj, attribute, ).html_safe end |