announcement-test/app/views/announcements/show.html.erb

69 lines
2.4 KiB
Plaintext
Raw Normal View History

<%
require 'announcements_helper'
params = OrbitHelper.params
page = Page.where(url:params['url']).first
@show_back_and_next_flag = 0
if page.methods.include? 'select_option_items'.to_sym
ModuleApp.all.select{|tmp| tmp.key.to_s=='announcement'}.each do |modile_app|
@show_option_items = modile_app.show_option_items rescue nil
end
page.select_option_items.each do |select_option_item|
if !(@show_option_items.nil?) && select_option_item.field_name == @show_option_items.keys.first.to_s
value = YAML.load(select_option_item.value)
if value[I18n.locale] == t('announcement.not_show')
@show_back_and_next_flag = 0
elsif value[I18n.locale] == t('announcement.show_top')
@show_back_and_next_flag = 1
elsif value[I18n.locale] == t('announcement.show_bottom')
@show_back_and_next_flag = 2
end
end
end
end
if @show_back_and_next_flag != 0
uid = params['uid']
announcements,sorted = get_sorted_annc
now_index = sorted.to_enum.with_index.select{|v| v[0].uid==uid}[0][1]
if now_index != 0
prev_result = sorted[now_index-1]
prev_url = params['url'] + '/' + prev_result.to_param
prev_content = "<a href='#{prev_url}' title='#{t('announcement.prev')}' class='prev'><b>#{t('announcement.prev')}</b><p>#{prev_result['title'][I18n.locale]}</p></a>"
end
if now_index != sorted.length-1
next_result = sorted[now_index+1]
next_url = params['url'] + '/' + next_result.to_param
next_content = "<a href='#{next_url}' title='#{t('announcement.next')}' class='next'><b>#{t('announcement.next')}</b><p>#{next_result['title'][I18n.locale]}</p></a>"
end
content = "<div class='see_more_boxTitle'>#{prev_content}#{next_content}</div>".html_safe
end
%>
<% if @show_back_and_next_flag!=0 %>
<style type="text/css">
.see_more_boxTitle{
display: flex;
margin: 1em 0em;
padding: 1em;
border: 0.2em solid;
}
a.prev, a.next{
width: 50%;
border: 0.2em solid;
padding: 1em;
flex: 1;
}
a.next{
margin-left: 1em;
}
a.prev{
margin-right: 1em;
}
</style>
<% end %>
<% if @show_back_and_next_flag==1 %>
<%= content %>
<% end %>
<%= render_view %>
<% if @show_back_and_next_flag==2 %>
<%= content %>
<% end %>