mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-05-31 00:41:20 +00:00
Purged git history and removed sensitive information.
This commit is contained in:
commit
6bcc8dc76b
862 changed files with 25312 additions and 0 deletions
133
app/helpers/application_helper.rb
Normal file
133
app/helpers/application_helper.rb
Normal file
|
@ -0,0 +1,133 @@
|
|||
module ApplicationHelper
|
||||
def namelink model, length = nil
|
||||
return if model.nil?
|
||||
model = case model.class.to_s
|
||||
when "DataFile"
|
||||
model.movie ? model.movie : model
|
||||
when "Comment"
|
||||
model.commentable
|
||||
when "Post"
|
||||
model.topic
|
||||
else
|
||||
model
|
||||
end
|
||||
str = model.to_s
|
||||
if length and str.length > length
|
||||
link_to raw(str.to_s[0, length] + "..."), model
|
||||
else
|
||||
link_to raw(str), model
|
||||
end
|
||||
end
|
||||
|
||||
def shorten str, length
|
||||
if length and str and str.to_s.length > length
|
||||
str = str.to_s[0, length] + "..."
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
def longtime time
|
||||
printtime time, "%d %B %y %H:%M"
|
||||
end
|
||||
|
||||
def shorttime time
|
||||
printtime time, "%d/%b/%y %H:%M"
|
||||
end
|
||||
|
||||
def shortdate time
|
||||
printtime time, "%d %b %y"
|
||||
end
|
||||
|
||||
def longdate time
|
||||
printtime time, "%d %B %Y"
|
||||
end
|
||||
|
||||
def printtime time, format
|
||||
return unless time
|
||||
out = ""
|
||||
out << '<span style="font-style: italic; ">'
|
||||
out << time.strftime(format)
|
||||
out << '</span>'
|
||||
raw out
|
||||
end
|
||||
|
||||
def cascade model, list
|
||||
out = ""
|
||||
|
||||
list.each do |element|
|
||||
name = key = element
|
||||
result = ""
|
||||
|
||||
if element.instance_of?(Array)
|
||||
name = element[0]
|
||||
key = element[1]
|
||||
end
|
||||
|
||||
if m = key.to_s.match(/^(.*)_b$/)
|
||||
name = m[1]
|
||||
key = m[1]
|
||||
end
|
||||
|
||||
str = eval("model.#{key}")
|
||||
next if str == "" or str.nil?
|
||||
|
||||
if model[key].instance_of?(Time)
|
||||
result << shorttime(str)
|
||||
elsif element.instance_of?(Symbol)
|
||||
result << namelink(str)
|
||||
elsif key.to_s.match(/^(.*)_b$/)
|
||||
result << str.bbcode_to_html
|
||||
else
|
||||
result << h(str)
|
||||
end
|
||||
|
||||
out << "<p>"
|
||||
out << "<b>#{name.to_s.capitalize.gsub(/_s/, '').gsub(/_/, ' ')}</b>: "
|
||||
out << result
|
||||
out << "</p>"
|
||||
end
|
||||
raw out
|
||||
end
|
||||
|
||||
def abslink text, url
|
||||
raw link_to text, url
|
||||
end
|
||||
|
||||
def flag country
|
||||
if country and country.to_s.length > 0
|
||||
image_tag "/images/flags/" + country.downcase + ".gif", :width => 18, :height => 12
|
||||
else
|
||||
image_tag "/images/flags/eu.gif"
|
||||
end
|
||||
end
|
||||
|
||||
def add_comments object
|
||||
@comment = Comment.new :commentable => object
|
||||
@comments = object.comments.ordered.with_userteam
|
||||
return_here
|
||||
render :partial => "comments/index"
|
||||
end
|
||||
|
||||
def bbcode
|
||||
link_to "(BBCode)", article_url(:id => 536)
|
||||
end
|
||||
|
||||
def sortable(column, title = nil)
|
||||
title ||= column.titleize
|
||||
css_class = (column == sort_column) ? "current #{sort_direction}" : nil
|
||||
direction = (column == sort_column && sort_direction == "asc") ? "desc" : "asc"
|
||||
link_to title, {:sort => column, :direction => direction}, {:class => css_class}
|
||||
end
|
||||
|
||||
def link_to_remove_fields(name, f)
|
||||
f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
|
||||
end
|
||||
|
||||
def link_to_add_fields(name, f, association)
|
||||
new_object = f.object.class.reflect_on_association(association).klass.new
|
||||
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
|
||||
render(association.to_s.singularize, :f => builder)
|
||||
end
|
||||
link_to_function(name, ("add_fields(this, '#{association}', '#{escape_javascript(fields)}')"))
|
||||
end
|
||||
end
|
18
app/helpers/gathers_helper.rb
Normal file
18
app/helpers/gathers_helper.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
module GathersHelper
|
||||
def render_gather
|
||||
if @gather.status == Gather::STATE_RUNNING
|
||||
headers["Gather"] = "running"
|
||||
render :partial => "running", :layout => false
|
||||
elsif @gather.status == Gather::STATE_VOTING
|
||||
if @gatherer and @gather.gatherer_votes.first(:conditions => {:user_id => cuser.id})
|
||||
headers["Gather"] = "voted"
|
||||
else
|
||||
headers["Gather"] = "voting"
|
||||
end
|
||||
render :partial => "voting", :layout => false
|
||||
elsif @gather.status == Gather::STATE_PICKING or @gather.status == Gather::STATE_FINISHED
|
||||
headers["Gather"] = "picking"
|
||||
render :partial => "picking", :layout => false
|
||||
end
|
||||
end
|
||||
end
|
11
app/helpers/polls_helper.rb
Normal file
11
app/helpers/polls_helper.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
module PollsHelper
|
||||
def add_option_link(name, form)
|
||||
link_to_function name do |page|
|
||||
option = render :partial => 'option', :locals => { :pf => form, :options => Option.new }
|
||||
page << %{
|
||||
this.counter = typeof this.counter == 'undefined' ? 0 : this.counter + 1;
|
||||
$('options').insert({ bottom: "#{ escape_javascript option }".replace(/\\[\\d+\\]/g, "[" + this.counter + "]") });
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
5
app/helpers/topics_helper.rb
Normal file
5
app/helpers/topics_helper.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
module TopicsHelper
|
||||
def lastpost topic
|
||||
topic_url(topic, :page => topic.last_page, :anchor => "post_#{topic.posts.last.id}")
|
||||
end
|
||||
end
|
21
app/helpers/users_helper.rb
Normal file
21
app/helpers/users_helper.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module UsersHelper
|
||||
def sort_link text, param
|
||||
key = param
|
||||
key += "_reverse" if params[:sort] == param
|
||||
|
||||
options = {
|
||||
:url => {:params => params.merge({:sort => key, :page => nil})},
|
||||
:with => "`_method=get`",
|
||||
:update => 'usersTable',
|
||||
:before => "Element.show('spinner')",
|
||||
:success => "Element.hide('spinner')",
|
||||
}
|
||||
|
||||
html_options = {
|
||||
:title => "Sort by this field",
|
||||
:href => url_for(:params => params.merge({:sort => key, :page => nil})),
|
||||
}
|
||||
|
||||
# link_to_remote text, options, html_options
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue