# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
# Request from an iPhone or iPod touch? (Mobile Safari user agent)
def iphone_user_agent?
request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(Mobile\/.+Safari)/]
end
def time_ago_in_words_short(time)
time_ago = time_ago_in_words(time)
time_ago = time_ago.gsub(/about /, '')
time_ago = time_ago.gsub(/minutes/, 'mins')
time_ago = time_ago.gsub(/hours/, 'hrs')
time_ago = time_ago.gsub(/seconds/, 'secs')
end
def download_status(download)
case download.status
when "downloading"
"#{bytes_complete(download)}"
when "complete"
"Download Complete"
when "queued"
"#{bytes_complete(download)} - Queued"
when "paused"
"#{bytes_complete(download)} - Paused"
when "pausing"
"#{bytes_complete(download)} - Pausing"
when "unrar"
"#{bytes_complete(download)} - Unraring"
when "par_repair"
"#{bytes_complete(download)} - Repairing"
when "mp3_rename"
"#{bytes_complete(download)} - Retagging"
when "avimerge"
"#{bytes_complete(download)} - Merging video files"
when "error"
"#{bytes_complete(download)} - Error"
end
end
def time_remaining(download)
case download.status
when "downloading"
case @pyrot.speed_in_bytes
when 0
time_left = "Something is wrong"
else
time_left = "#{((download.bytes_left/@pyrot.speed_in_bytes)/(60)).to_i} mins remaining"
end
time_left
end
end
def download_buttons(download)
output = []
case download.status
when "downloading"
output << link_to_remote('pause', {:url => pause_download_path(download.title), :method => :get}, {:class => 'pause_button'})
output << link_to_remote('remove', {:url => remove_download_path(download.title), :method => :get}, {:class => 'remove_button'})
when "complete"
output << link_to_remote('remove', {:url => remove_download_path(download.title), :method => :get}, {:class => 'remove_button'})
when "error"
output << link_to_remote('remove', {:url => remove_download_path(download.title), :method => :get}, {:class => 'remove_button'})
when "paused"
output << link_to_remote('resume', {:url => resume_download_path(download.title), :method => :get}, {:class => 'resume_button'})
output << link_to_remote('remove', {:url => remove_download_path(download.title), :method => :get}, {:class => 'remove_button'})
when "queued"
output << link_to_remote('remove', {:url => remove_download_path(download.title), :method => :get}, {:class => 'remove_button'})
end
output.join
end
def bytes_complete(download)
"#{download.completed_bytes.to_mb} MB of #{download.total_bytes.to_mb} MB (#{download.percent_complete}%)"
end
def search_button
%{<a class="button" href="#" onclick="$('search_dialog').show(); return false;">Search</a>}
end
def content_for_iphone_title_bar(&block)
html = %{<div class="title_bar">}
html << capture(&block)
html << %{</div>}
concat(html, block)
end
def newzbin_format_options
options_for_select([["Format", "1073741824"],["x264", "131072"],["H.264", "2048"],["XviD", "16"],["iPod", "512"],["DVD", "2"],["PSP", "1024"],["DivX", "1"]])
end
def newzbin_format_select_tag
select_tag "ps_rb_video_format", newzbin_format_options
end
def newzbin_source_options
options_for_select([["Source", "1073741824"], ["HD-DVD", "512"], ["Blu-ray", "2048"], ["DVD", "64"], ["TV Cap", "256"], ["HDTV", "128"]])
end
def newzbin_source_select_tag
select_tag "ps_rb_source", newzbin_source_options
end
def newzbin_category_options
options_for_select([["Category", "-1"], ["Movies", "6"], ["TV", "8"]])
end
def newzbin_category_select_tag
select_tag "category", newzbin_category_options
end
def newzbin_genre_options
options_for_select([["Genre", "1073741824"], ["Action/Adv", "1"], ["Animation", "2"], ["Children", "131072"], ["Comedy", "4"], ["Documentary", "8"], ["Drama", "16"], ["Family", "8192"], ["Fantasy", "2048"], ["Horror", "512"], ["Musical", "16384"], ["SciFi", "32"], ["Sitcom", "64"], ["Sport", "128"], ["Reality", "256"], ["Romance", "1024"], ["Thriller", "4096"], ["War", "65536"], ["Western", "32768"]])
end
def newzbin_genre_select_tag
select_tag "ps_rb_video_genre", newzbin_genre_options
end
def pagination_links(page)
output = "<h2>"
output << link_to( "<= Previous", group_nzbs_path(@group, :page => page.to_i - 1)) if page && page.to_i > 1
output << link_to( "More =>", group_nzbs_path(@group, :page => page == nil ? 2 : page.to_i + 1))
output << "</h2>"
end
def decide_partial(category)
case category
when "movies"
"movies/movie"
when "tv"
"movies/episode"
end
end
def meta_decide_partial(category)
case category
when "movies"
"movies/big_movie"
when "tv"
"movies/big_episode"
end
end
def determine_season_pass_link(series)
season_passes = SeasonPass.find(:all)
found_pass = nil
season_passes.each do |pass|
found_pass = pass if pass.title =~ /#{series.title}/i
end
case found_pass
when nil
link_to 'Season Pass', new_season_pass_path(:title => series.title)
else
link_to 'Season Pass', edit_season_pass_path(found_pass)
end
end
end