Application_Form/app/helpers/admin/application_forms_helper.rb

103 lines
4.2 KiB
Ruby
Raw Normal View History

2022-03-10 02:11:18 +00:00
module Admin::ApplicationFormsHelper
data = File.open(File.join(File.dirname(__FILE__), '../../../config', 'list.yml')).read
2022-03-10 02:11:18 +00:00
$application_form_list = YAML::load(ERB.new(data).result(binding)).symbolize_keys
2021-03-29 14:27:08 +00:00
def display_format_string(num, str_length)
return format("%0#{str_length}d", num % (10^str_length))
end
2022-03-10 02:11:18 +00:00
def page_for_application_form(application_form)
2016-06-29 06:57:45 +00:00
ann_page = nil
2022-03-10 02:11:18 +00:00
pages = Page.where(:module=>'application_form')
2016-06-29 06:57:45 +00:00
pages.each do |page|
if page.categories.count ==1
2022-03-10 06:14:52 +00:00
if (page.categories.include?(application_form.category.id.to_s) rescue false)
2016-06-29 06:57:45 +00:00
ann_page = page
end
end
break if !ann_page.nil?
end
if ann_page.nil?
pages.each do |page|
2022-03-10 06:14:52 +00:00
if (page.categories.include?(application_form.category.id.to_s) rescue false)
2016-06-29 06:57:45 +00:00
ann_page = page
end
break if !ann_page.nil?
end
end
ann_page = pages.first if ann_page.nil?
2022-03-10 02:11:18 +00:00
request.protocol+(request.host_with_port+ann_page.url+'/'+application_form.to_param).gsub('//','/') rescue "/"
2016-06-29 06:57:45 +00:00
end
2022-03-10 02:11:18 +00:00
def can_see_application_form_signup(application_form)
if can_edit_or_delete?(application_form)
return true
2022-03-10 02:11:18 +00:00
elsif (application_form.organizer_id == current_user.member_profile_id rescue false)
return true
else
2022-03-10 02:11:18 +00:00
return application_form.reviewer_ids.to_a.include?(current_user.member_profile_id.to_s)
end
end
2022-03-10 02:11:18 +00:00
def admin_for_application_form(application_form)
return can_edit_or_delete?(application_form) || (application_form.organizer_id == current_user.member_profile_id rescue false)
end
2022-03-10 02:11:18 +00:00
def page_for_application_form_url
if @application_form_main_url
return @application_form_main_url
2021-06-17 10:07:43 +00:00
else
2022-03-10 02:11:18 +00:00
page = Page.where(:module => 'application_form').first
2021-06-17 10:07:43 +00:00
return request.protocol+(request.host_with_port+"/#{I18n.locale}#{(page.get_url rescue page.url)}").gsub('//','/') rescue "/"
end
2022-03-10 02:11:18 +00:00
# return "/#{I18n.locale}#{page.url}/#{application_form.to_param}"
2016-06-29 06:57:45 +00:00
end
2020-06-26 03:56:02 +00:00
module MultiLang
extend self
extend ActionView::Helpers::FormTagHelper
extend ActionView::Helpers::FormOptionsHelper
extend ActionView::Helpers::DateHelper
extend ActionView::Helpers::TagHelper
extend ActionView::Helpers::RenderingHelper
extend ActionView::Context
extend OrbitBasis::RenderAnywhere
extend ActionView::Helpers::UrlHelper
extend OrbitFormHelper
extend Ckeditor::Helpers::FormHelper
def get_input_name()
2022-03-10 02:11:18 +00:00
'application_form_main'
2020-06-26 03:56:02 +00:00
end
def create_lang_panel(field)
tmp2 = content_tag(:div,:class => 'btn-group', :data=>{:toggle=>"buttons-radio"}) do
I18n.available_locales.collect do |key|
link_entry_ary = ["##{field}","_#{key}"]
link_entry = link_entry_ary.join
link_to(I18n.t(key),link_entry,:data=>{:toggle=>"tab"},:class=>"btn #{(key == I18n.locale ? "active" : nil)}",:for=>key)
end.join.html_safe
end
end
def multiple_lang_tag(index1,type_of_tag,field,value=nil,custom_options={},combine_element='',exteral_options={},panel_on_top=false)
content_tag(:div,{:class => "tab-content"}.merge(exteral_options)) do
if !index1.nil?
all_field = (get_input_name + "[#{index1}][#{field}][parant]").gsub(/\[/,'_').gsub(/\]/,'')
else
all_field = (get_input_name + "[#{field}][parant]").gsub(/\[/,'_').gsub(/\]/,'')
end
tmp = I18n.available_locales.collect do |locale|
active_flag = ((locale == I18n.locale) ? ' active in' : '')
content_tag(:div,:class => "tab-pane fade#{active_flag}",:id=>"#{all_field}_#{locale}") do
value_locale = value[locale.to_s] rescue nil
if !index1.nil?
self.__send__("#{type_of_tag}_tag","#{get_input_name}[#{index1}][#{field}][#{locale}]",value_locale,custom_options)
else
self.__send__("#{type_of_tag}_tag","#{get_input_name}[#{field}][#{locale}]",value_locale,custom_options)
end
end
end.join
if panel_on_top
create_lang_panel(all_field).html_safe + tmp.html_safe + combine_element
else
(tmp + create_lang_panel(all_field)).html_safe + combine_element
end
end
end
end
2016-06-29 06:57:45 +00:00
end