Module: ArtfullyOseHelper
- Includes:
- ActionView::Helpers::NumberHelper, LinkHelper
- Included in:
- DailyDonationReport, DailyMembershipReport, DailyPassReport, DailyTicketReport, DiscountsReport, DonationsImport, DoorList, GatewayTransaction, MembershipType, Order, PassType, PassesReport, Store::OrdersController
- Defined in:
- app/helpers/artfully_ose_helper.rb
Instance Method Summary collapse
- #amount_and_nongift(item) ⇒ Object
- #bootstrapped_type(type) ⇒ Object
- #build_action_path(target, action) ⇒ Object
- #build_order_location(order) ⇒ Object
- #channel_checkbox(channel) ⇒ Object
- #channel_text(channel) ⇒ Object
- #check_mark(size = nil, alt = nil) ⇒ Object
- #clean_full_error_messages(errors) ⇒ Object
- #contextual_menu(&block) ⇒ Object
- #credit_card_message ⇒ Object
- #date_field_tag(name, value = nil, options = {}) ⇒ Object
- #datetime_field_tag(name, value = nil, options = {}) ⇒ Object
- #events_to_options(selected_event_id = nil) ⇒ Object
-
#fully_qualified_asset_path(asset) ⇒ Object
This is for the widget generator, DO NOT use anywhere else.
-
#get_selected_class(selected_object, menu_object) ⇒ Object
For use with the nav-pills to select an intem based on a current selection Will protect against nil by using try on the object.
-
#icon_link_to(text, href, icon, class_names, id, html_attributes = {}) ⇒ Object
For use with Font Awesome icon %i classes.
-
#icon_tag(img, options = {}) ⇒ Object
just name the image, this method will prepend the path and append the .png icon_tag(‘111-logo’).
- #link_to_add_fields(name, f, association, view_path = '', additional_javascript = nil) ⇒ Object
- #link_to_remove_fields(name, f) ⇒ Object
- #nav_dropdown(text, link = '#') ⇒ Object
- #number_as_cents(cents, options = {}) ⇒ Object
-
#number_to_dollars(cents) ⇒ Object
This method will not prepend the $.
- #pluralize_word(count, singular, plural = nil) ⇒ Object
- #refund_header(items) ⇒ Object
- #select_event_for_sales_search(events, event_id, default) ⇒ Object
- #select_membership_type_for_sales_search(membership_types, membership_type_id, default) ⇒ Object
- #select_pass_type_for_sales_search(pass_types, pass_type_id, default) ⇒ Object
- #select_show_for_sales_search(shows, show_id, default) ⇒ Object
- #sorted_us_state_abbreviations ⇒ Object
- #sorted_us_state_names ⇒ Object
- #thanks_message(person) ⇒ Object
- #ticket_seller_name(ticket) ⇒ Object
- #time_ago_sentence(t) ⇒ Object
- #time_zone_description(tz) ⇒ Object
- #us_states ⇒ Object
- #verb_for_save(record) ⇒ Object
- #widget_script(event, organization) ⇒ Object
- #with_kit(kit, organization = nil) ⇒ Object
Methods included from LinkHelper
#active?, #active_link_to, #active_section, #calendar_active_link_to, #in_section, #in_section?, #in_sub_section
Instance Method Details
#amount_and_nongift(item) ⇒ Object
130 131 132 133 134 |
# File 'app/helpers/artfully_ose_helper.rb', line 130 def amount_and_nongift(item) str = number_as_cents item.total_price str += " (#{number_as_cents item.nongift_amount} Non-deductible)" unless item.nongift_amount.nil? || item.nongift_amount == 0 str end |
#bootstrapped_type(type) ⇒ Object
269 270 271 272 273 274 275 276 |
# File 'app/helpers/artfully_ose_helper.rb', line 269 def bootstrapped_type(type) case type when :notice then "alert alert-info" when :success then "alert alert-success" when :error then "alert alert-error" when :alert then "alert alert-error" end end |
#build_action_path(target, action) ⇒ Object
48 49 50 51 |
# File 'app/helpers/artfully_ose_helper.rb', line 48 def build_action_path(target, action) action_path_name = action.new_record? ? "actions" : "actions" "#{target.class.name.downcase}_#{action_path_name}_path" end |
#build_order_location(order) ⇒ Object
29 30 31 |
# File 'app/helpers/artfully_ose_helper.rb', line 29 def build_order_location(order) order.location end |
#channel_checkbox(channel) ⇒ Object
33 34 35 |
# File 'app/helpers/artfully_ose_helper.rb', line 33 def channel_checkbox(channel) channel.to_s.eql?("storefront") ? "Storefront & Widgets" : channel.to_s.humanize end |
#channel_text(channel) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/artfully_ose_helper.rb', line 37 def channel_text(channel) case channel.to_s when "members" "to your members in your Storefront" when "storefront" "online Storefront and installed widgets" else channel.to_s.humanize end end |
#check_mark(size = nil, alt = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/artfully_ose_helper.rb', line 5 def check_mark(size=nil, alt=nil) case size when :huge icon_tag('117-todo@2x', {:alt => alt}) when :big icon_tag('117-todo', {:alt => alt}) else "✓".html_safe end end |
#clean_full_error_messages(errors) ⇒ Object
58 59 60 61 62 |
# File 'app/helpers/artfully_ose_helper.rb', line 58 def (errors) string = errors..collect {|m| m.downcase.gsub(/.*organization/, 'organization')}.to_sentence string = string.slice(0,1).capitalize + string.slice(1..-1) string = string + "." end |
#contextual_menu(&block) ⇒ Object
109 110 111 112 113 |
# File 'app/helpers/artfully_ose_helper.rb', line 109 def (&block) = ContextualMenu.new(self) block.call() . end |
#credit_card_message ⇒ Object
295 296 |
# File 'app/helpers/artfully_ose_helper.rb', line 295 def end |
#date_field_tag(name, value = nil, options = {}) ⇒ Object
298 299 300 |
# File 'app/helpers/artfully_ose_helper.rb', line 298 def date_field_tag(name, value = nil, = {}) text_field_tag(name, value, .stringify_keys.update("type" => "date")) end |
#datetime_field_tag(name, value = nil, options = {}) ⇒ Object
302 303 304 |
# File 'app/helpers/artfully_ose_helper.rb', line 302 def datetime_field_tag(name, value = nil, = {}) text_field_tag(name, value, .stringify_keys.update("type" => "datetime")) end |
#events_to_options(selected_event_id = nil) ⇒ Object
102 103 104 105 106 107 |
# File 'app/helpers/artfully_ose_helper.rb', line 102 def (selected_event_id = nil) @events = current_user.current_organization.events @events_array = @events.map { |event| [event.name, event.id] } @events_array.insert(0, ["", ""]) (@events_array, selected_event_id) end |
#fully_qualified_asset_path(asset) ⇒ Object
This is for the widget generator, DO NOT use anywhere else
98 99 100 |
# File 'app/helpers/artfully_ose_helper.rb', line 98 def fully_qualified_asset_path(asset) "#{asset_path(asset, :digest => false)}" end |
#get_selected_class(selected_object, menu_object) ⇒ Object
For use with the nav-pills to select an intem based on a current selection Will protect against nil by using try on the object
returns ‘active’ if selected_object.id = menu_object.id ‘unselected’ otherwise
71 72 73 |
# File 'app/helpers/artfully_ose_helper.rb', line 71 def get_selected_class(selected_object, ) selected_object.try(:id) == .id ? "active" : "unselected" end |
#icon_link_to(text, href, icon, class_names, id, html_attributes = {}) ⇒ Object
For use with Font Awesome icon %i classes
76 77 78 79 80 81 82 83 |
# File 'app/helpers/artfully_ose_helper.rb', line 76 def icon_link_to(text, href, icon, class_names, id, html_attributes={}) s = "<a href='#{href}' class='#{class_names}' id='#{id}' " html_attributes.each do |k,v| s = s + " #{k}=#{v} " end s = s + "><i class='fa #{icon}'></i> #{text}</a>" s.html_safe end |
#icon_tag(img, options = {}) ⇒ Object
just name the image, this method will prepend the path and append the .png icon_tag(‘111-logo’)
89 90 91 |
# File 'app/helpers/artfully_ose_helper.rb', line 89 def icon_tag(img, ={}) image_tag('glyphish/gray/' + img + '.png', ) end |
#link_to_add_fields(name, f, association, view_path = '', additional_javascript = nil) ⇒ Object
282 283 284 285 286 287 288 289 290 |
# File 'app/helpers/artfully_ose_helper.rb', line 282 def link_to_add_fields(name, f, association, view_path = '', additional_javascript=nil) new_object = f.object.class.reflect_on_association(association).klass.new fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| view_path = view_path + '/' unless view_path.blank? template_path = view_path + association.to_s.singularize + "_fields" render(template_path, :f => builder) end link_to name, "#", :onclick => "add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\"); #{additional_javascript} return false;" end |
#link_to_remove_fields(name, f) ⇒ Object
278 279 280 |
# File 'app/helpers/artfully_ose_helper.rb', line 278 def link_to_remove_fields(name, f) f.hidden_field(:_destroy) + link_to(name, "#", :onclick => "remove_fields(this); return false;") end |
#nav_dropdown(text, link = '#') ⇒ Object
265 266 267 |
# File 'app/helpers/artfully_ose_helper.rb', line 265 def nav_dropdown(text, link='#') link_to ERB::Util.html_escape(text) + ' <b class="caret"></b>'.html_safe, link, :class => 'dropdown-toggle', 'data-toggle' => 'dropdown' end |
#number_as_cents(cents, options = {}) ⇒ Object
141 142 143 144 145 |
# File 'app/helpers/artfully_ose_helper.rb', line 141 def number_as_cents(cents, = {}) result = number_to_currency(number_to_dollars(cents), ) result = result.split('.').first if result.split('.').last == '00' && [:cents_if_needed] == true result end |
#number_to_dollars(cents) ⇒ Object
This method will not prepend the $
137 138 139 |
# File 'app/helpers/artfully_ose_helper.rb', line 137 def number_to_dollars(cents) cents.to_i / 100.00 end |
#pluralize_word(count, singular, plural = nil) ⇒ Object
321 322 323 |
# File 'app/helpers/artfully_ose_helper.rb', line 321 def pluralize_word(count, singular, plural = nil) ((count == 1 || count == '1') ? singular : (plural || singular.pluralize)) end |
#refund_header(items) ⇒ Object
306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'app/helpers/artfully_ose_helper.rb', line 306 def refund_header(items) str = "" if items.select(&:ticket?).any? str = "Tickets" end if items.select(&:ticket?).any? && items.select(&:donation?).any? str += " & " end if items.select(&:donation?).any? str += "Donations" end end |
#select_event_for_sales_search(events, event_id, default) ⇒ Object
222 223 224 225 226 227 228 229 230 |
# File 'app/helpers/artfully_ose_helper.rb', line 222 def select_event_for_sales_search events, event_id, default = [ content_tag(:option, " --- All Events --- ", :value => ""), (events, :id, :name, default) ].join select_tag event_id, raw(), :class => "span2" end |
#select_membership_type_for_sales_search(membership_types, membership_type_id, default) ⇒ Object
245 246 247 248 249 250 251 252 253 |
# File 'app/helpers/artfully_ose_helper.rb', line 245 def select_membership_type_for_sales_search(membership_types, membership_type_id, default) = [ content_tag(:option, " --- All Membership Types --- ", :value => ""), (membership_types, :id, :name, default) ].join select_tag membership_type_id, raw(), :class => "span3" end |
#select_pass_type_for_sales_search(pass_types, pass_type_id, default) ⇒ Object
255 256 257 258 259 260 261 262 263 |
# File 'app/helpers/artfully_ose_helper.rb', line 255 def select_pass_type_for_sales_search(pass_types, pass_type_id, default) = [ content_tag(:option, " --- All Pass Types --- ", :value => ""), (pass_types, :id, :name, default) ].join select_tag pass_type_id, raw(), :class => "span3" end |
#select_show_for_sales_search(shows, show_id, default) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'app/helpers/artfully_ose_helper.rb', line 232 def select_show_for_sales_search shows, show_id, default = [ content_tag(:option, " --- All Shows --- ", :value => ""), shows.map do |show| selected = "selected" if show.id == default.to_i content_tag(:option, l(show.datetime_local_to_event), :value => show.id, :selected => selected) end.join ].join select_tag show_id, raw(), :class => "span3" end |
#sorted_us_state_abbreviations ⇒ Object
151 152 153 |
# File 'app/helpers/artfully_ose_helper.rb', line 151 def sorted_us_state_abbreviations @sorted_us_states ||= us_states.invert.keys.sort{|a, b| a <=> b} end |
#sorted_us_state_names ⇒ Object
147 148 149 |
# File 'app/helpers/artfully_ose_helper.rb', line 147 def sorted_us_state_names @sorted_us_state_names ||= us_states.keys.sort{|a, b| a <=> b} end |
#thanks_message(person) ⇒ Object
23 24 25 26 27 |
# File 'app/helpers/artfully_ose_helper.rb', line 23 def (person) = "Thanks" += ", #{person.first_name}" unless person.first_name.blank? += "!" end |
#ticket_seller_name(ticket) ⇒ Object
292 293 |
# File 'app/helpers/artfully_ose_helper.rb', line 292 def ticket_seller_name(ticket) end |
#time_ago_sentence(t) ⇒ Object
53 54 55 56 |
# File 'app/helpers/artfully_ose_helper.rb', line 53 def time_ago_sentence(t) qualifier = t > Time.now ? "from now" : "ago" "#{time_ago_in_words(t)} #{qualifier}" end |
#time_zone_description(tz) ⇒ Object
93 94 95 |
# File 'app/helpers/artfully_ose_helper.rb', line 93 def time_zone_description(tz) ActiveSupport::TimeZone.create(tz) end |
#us_states ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'app/helpers/artfully_ose_helper.rb', line 155 def us_states { "Alabama" =>"AL", "Alaska" =>"AK", "American Samoa" =>"AS", "Arizona" =>"AZ", "Arkansas" =>"AR", "California" =>"CA", "Colorado" =>"CO", "Connecticut" =>"CT", "Delaware" =>"DE", "District of Columbia" =>"DC", "Florida" =>"FL", "Georgia" =>"GA", "Guam" =>"GU", "Hawaii" =>"HI", "Idaho" =>"ID", "Illinois" =>"IL", "Indiana" =>"IN", "Iowa" =>"IA", "Kansas" =>"KS", "Kentucky" =>"KY", "Louisiana" =>"LA", "Maine" =>"ME", "Marshall Islands" =>"MH", "Maryland" =>"MD", "Massachusetts" =>"MA", "Michigan" =>"MI", "Micronesia" =>"FM", "Minnesota" =>"MN", "Mississippi" =>"MS", "Missouri" =>"MO", "Montana" =>"MT", "Nebraska" =>"NE", "Nevada" =>"NV", "New Hampshire" =>"NH", "New Jersey" =>"NJ", "New Mexico" =>"NM", "New York" =>"NY", "North Carolina" =>"NC", "North Dakota" =>"ND", "Ohio" =>"OH", "Oklahoma" =>"OK", "Oregon" =>"OR", "Palau" =>"PW", "Pennsylvania" =>"PA", "Rhode Island" =>"RI", "Puerto Rico" =>"PR", "South Carolina" =>"SC", "South Dakota" =>"SD", "Tennessee" =>"TN", "Texas" =>"TX", "Utah" =>"UT", "Vermont" =>"VT", "Virgin Islands" =>"VI", "Virginia" =>"VA", "Washington" =>"WA", "Wisconsin" =>"WI", "West Virginia" =>"WV", "Wyoming" =>"WY" } end |
#verb_for_save(record) ⇒ Object
218 219 220 |
# File 'app/helpers/artfully_ose_helper.rb', line 218 def verb_for_save(record) record.new_record? ? "Create" : "Update" end |
#widget_script(event, organization) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/helpers/artfully_ose_helper.rb', line 115 def (event, organization) return <<-EOF <script> $(document).ready(function(){ artfully.configure({ base_uri: '#{root_url}api/', store_uri: '#{root_url}store/' }); #{render :partial => "widgets/event", :locals => { :event => event } unless event.nil? } #{render :partial => "widgets/donation", :locals => { :organization => organization } unless organization.nil? } }); <script> EOF end |
#with_kit(kit, organization = nil) ⇒ Object
16 17 18 19 20 21 |
# File 'app/helpers/artfully_ose_helper.rb', line 16 def with_kit(kit, organization = nil) organization = organization || current_user.try(:current_organization) || @store_organization if organization.has_kit? kit yield end end |