2009-01-06 11:49:19 +01:00
|
|
|
# Methods added to this helper will be available to all templates in the application.
|
|
|
|
module ApplicationHelper
|
|
|
|
|
|
|
|
def format_time(time = Time.now)
|
2009-01-12 18:26:09 +01:00
|
|
|
I18n.l(time, :format => "%d.%m.%Y %H:%M") unless time.nil?
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def format_date(time = Time.now)
|
2009-01-12 18:26:09 +01:00
|
|
|
I18n.l(time.to_date) unless time.nil?
|
2009-01-06 15:45:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def format_datetime(time = Time.now)
|
2009-01-12 18:26:09 +01:00
|
|
|
I18n.l(time) unless time.nil?
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2009-08-22 18:14:56 +02:00
|
|
|
|
|
|
|
def format_datetime_timespec(time, format)
|
|
|
|
I18n.l(time, :format => format) unless (time.nil? or format.nil?)
|
|
|
|
end
|
2009-01-06 11:49:19 +01:00
|
|
|
|
|
|
|
# Creates ajax-controlled-links for pagination
|
|
|
|
# see also the plugin "will_paginate"
|
2009-01-14 12:46:01 +01:00
|
|
|
def pagination_links_remote(collection, options = {})
|
|
|
|
per_page = options[:per_page] || @per_page
|
|
|
|
params = options[:params] || {}
|
|
|
|
update = options[:update] || nil
|
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# Translations
|
2009-03-23 10:47:42 +01:00
|
|
|
previous_label = '« ' + "Vorherige"
|
|
|
|
next_label = "Nächste" + ' »'
|
2009-01-06 11:49:19 +01:00
|
|
|
# Merge other url-options for will_paginate
|
|
|
|
params = params.merge({:per_page => per_page})
|
2009-01-14 12:46:01 +01:00
|
|
|
will_paginate collection, { :params => params, :remote => true, :update => update,
|
|
|
|
:previous_label => previous_label, :next_label => next_label, }
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# Link-collection for per_page-options when using the pagination-plugin
|
2009-01-14 12:46:01 +01:00
|
|
|
def items_per_page(options = {})
|
|
|
|
per_page_options = options[:per_page_options] || [20, 50, 100]
|
|
|
|
current = options[:current] || @per_page
|
|
|
|
action = options[:action] || controller.action_name
|
|
|
|
update = options[:update] || nil
|
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
links = []
|
|
|
|
per_page_options.each do |per_page|
|
|
|
|
unless per_page == current
|
2009-01-12 18:26:09 +01:00
|
|
|
links << link_to_remote(
|
|
|
|
per_page,
|
|
|
|
{ :url => { :action => action, :params => {:per_page => per_page}},
|
|
|
|
:before => "Element.show('loader')",
|
|
|
|
:success => "Element.hide('loader')",
|
2009-01-14 12:46:01 +01:00
|
|
|
:method => :get, :update => update } )
|
2009-01-06 11:49:19 +01:00
|
|
|
else
|
|
|
|
links << per_page
|
|
|
|
end
|
|
|
|
end
|
2009-03-23 10:47:42 +01:00
|
|
|
return "Pro Seite: " + links.join(" ")
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def sort_td_class_helper(param)
|
|
|
|
result = 'class="sortup"' if params[:sort] == param
|
|
|
|
result = 'class="sortdown"' if params[:sort] == param + "_reverse"
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2009-04-03 17:16:39 +02:00
|
|
|
def sort_link_helper(text, key, options = {})
|
|
|
|
per_page = options[:per_page] || 10
|
|
|
|
action = options[:action] || "list"
|
|
|
|
remote = options[:remote].nil? ? true : options[:remote]
|
|
|
|
key += "_reverse" if params[:sort] == key
|
|
|
|
|
|
|
|
link_options = {
|
2009-01-16 16:19:26 +01:00
|
|
|
:url => url_for(:params => params.merge({:sort => key, :page => nil, :per_page => per_page})),
|
2009-01-06 11:49:19 +01:00
|
|
|
:before => "Element.show('loader')",
|
2009-01-12 18:26:09 +01:00
|
|
|
:success => "Element.hide('loader')",
|
|
|
|
:method => :get
|
2009-01-06 11:49:19 +01:00
|
|
|
}
|
|
|
|
html_options = {
|
2009-04-01 00:50:59 +02:00
|
|
|
:title => _("Nach #{text} sortieren"),
|
2009-04-01 00:46:01 +02:00
|
|
|
:href => url_for(:action => action, :params => params.merge({:sort => key, :page => nil, :per_page => per_page}))
|
2009-01-06 11:49:19 +01:00
|
|
|
}
|
2009-04-03 17:16:39 +02:00
|
|
|
|
|
|
|
if remote
|
|
|
|
link_to_remote(text, link_options, html_options)
|
|
|
|
else
|
|
|
|
link_to(text, link_options[:url], html_options)
|
|
|
|
end
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# Generates a link to the top of the website
|
|
|
|
def link_to_top
|
|
|
|
link_to image_tag("arrow_up_red.png", :size => "16x16", :border => "0", :alt => "Nach oben"), "#"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Returns the weekday. 0 is sunday, 1 is monday and so on
|
|
|
|
def weekday(dayNumber)
|
|
|
|
weekdays = ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"]
|
|
|
|
return weekdays[dayNumber]
|
|
|
|
end
|
|
|
|
|
|
|
|
# highlights a phrase in given text
|
|
|
|
# based on the rails text-helper 'highlight'
|
|
|
|
def highlight_phrase(text, phrase, highlighter = '<strong class="highlight">\1</strong>')
|
|
|
|
unless phrase.blank? || text.nil?
|
|
|
|
phrase.split(' ').each {|keyword| text.gsub!(/(#{Regexp.escape(keyword)})/i, highlighter)}
|
|
|
|
end
|
|
|
|
return text
|
|
|
|
end
|
|
|
|
|
|
|
|
# to set a title for both the h1-tag and the title in the header
|
2009-08-12 18:41:25 +02:00
|
|
|
def title(page_title, show_title = true)
|
2011-05-11 13:38:46 +02:00
|
|
|
content_for(:title) { page_title.to_s }
|
2009-08-12 18:41:25 +02:00
|
|
|
@show_title = show_title
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_title?
|
|
|
|
@show_title
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2009-01-08 16:33:27 +01:00
|
|
|
|
|
|
|
def tab_is_active?(tab)
|
2010-03-22 01:58:37 +01:00
|
|
|
tab[:active].detect {|c| controller.controller_path.match(c) }
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|
2009-01-16 16:19:26 +01:00
|
|
|
|
|
|
|
def icon(name, options={})
|
|
|
|
icons = { :delete => { :file => 'b_drop.png', :alt => 'Löschen'},
|
|
|
|
:edit => { :file => 'b_edit.png', :alt => 'Bearbeiten'}}
|
2009-10-16 21:06:55 +02:00
|
|
|
options[:alt] ||= icons[name][:alt]
|
|
|
|
options[:title] ||= icons[name][:title]
|
2009-01-16 16:19:26 +01:00
|
|
|
options.merge!({:size => '16x16',:border => "0"})
|
|
|
|
|
|
|
|
image_tag icons[name][:file], options
|
|
|
|
end
|
2009-01-29 21:28:22 +01:00
|
|
|
|
|
|
|
# Remote links with default 'loader'.gif during request
|
|
|
|
def remote_link_to(text, options={})
|
2009-02-10 13:26:10 +01:00
|
|
|
remote_options = {
|
|
|
|
:before => "Element.show('loader')",
|
|
|
|
:success => "Element.hide('loader')",
|
|
|
|
:method => :get
|
|
|
|
}
|
2009-01-29 21:28:22 +01:00
|
|
|
link_to_remote(text, remote_options.merge(options))
|
|
|
|
end
|
2009-02-02 16:35:43 +01:00
|
|
|
|
|
|
|
def format_roles(record)
|
|
|
|
roles = []
|
|
|
|
roles << 'Admin' if record.role_admin?
|
|
|
|
roles << 'Finanzen' if record.role_finance?
|
|
|
|
roles << 'Lieferanten' if record.role_suppliers?
|
|
|
|
roles << 'Artikel' if record.role_article_meta?
|
|
|
|
roles << 'Bestellung' if record.role_orders?
|
|
|
|
roles.join(', ')
|
|
|
|
end
|
|
|
|
|
|
|
|
def link_to_gmaps(address)
|
|
|
|
link_to h(address), "http://maps.google.de/?q=#{h(address)}", :title => "Show it on google maps",
|
|
|
|
:target => "_blank"
|
|
|
|
end
|
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|