Hi Rails Developers
I want to create addEventListener to button. I have two method like
def work_sheet_csv
summary = [
“site_name=#{current_project.site.name}”,
“site_code=#{current_project.site.m_site_config.site_code}”,
“year=#{current_project.index_code_year}”,
‘%s=%s’ % [current_project.week? ? ‘week’ : ‘month’,
current_project.index_code_suffix],
“day_count=#{current_project.days}”,
“staff_count=#{current_project.t_project_staffs.length}”,
]
header = %w(
number staff_last_name staff_first_name staff_code year month day
shift_name kyuka from_jikoku to_jikoku jitsudo_minutes
location_name
)
io = StringIO.new
CSV::Writer.generate(io) do |csv|
csv << summary << header
cells =
TProjectWorkSheetCell.structured_data(current_project.work_sheet.id,
current_project)
XProjectShiftXLocation.append_to(current_project.t_project_shifts,
current_project.t_project_locations)
shifts_hash = current_project.t_project_shifts.inject({}) {|h, r|
h[r.id] = r; h }
number = 0
current_project.t_project_staffs.sort.each do |t_project_staff|
current_project.days.times do |date_index|
date = current_project.date_by_date_index(date_index)
shift = nil
shift_name =
if cell = cells[date_index][t_project_staff.id]
if cell.fixed?
shift = shifts_hash[cell.shift_ids.first]
shift && shift.display_name
elsif cell.only?
_('Only-Shift')
elsif cell.except?
_('Except-Shift')
else
nil
end
else
nil
end
csv << [
number += 1,
t_project_staff.last_name,
t_project_staff.first_name,
t_project_staff.staff_code,
date.year,
date.month,
date.day,
shift_name,
shift && shift.kyuka ? 1 : 0,
shift && shift.formatted_from_jikoku,
shift && shift.formatted_to_jikoku,
shift && shift.jitsudo_minutes,
shift && shift.location && shift.location.name,
]
end
end
end
io.rewind
send_data NKF.nkf('-Ws', io.read), :filename => NKF.nkf('-Ws',
work_sheet_csv_filename)
end
and
def index
@plugin_root = get_plugin_root
@templates_array = get_templates
“#{get_plugin_root}/public/converter/templates/”
end
def generate_excel
template_path =
“#{get_plugin_root}/public/converter/templates/#{params[:template]}”
output_path =
“#{RAILS_ROOT}/public/converter/output/#{params[:output]}.xml”
puts "==========="
puts template_path
puts output_path
#converter_generate(sheet_id, from_date, output_path=OUTPUT_PATH,
template_path=TEMPLATE_PATH)
converter_generate(params[:sheet_id], params[:date], output_path,
template_path)
end
def get_templates(templates_path)
dir = Dir.new(templates_path)
templates = Array.new
dir.each do |d|
templates << File.basename(d.gsub(/\/, ‘/’), ‘.xml’) unless
(d=~/^./) #except hidden files
templates.sort!
end
templates
end
second method gets parameters from select_tag, and add it to
converter_generate
I want to create select_tag like
temp1
temp2 temp3 temp4 csvand when I select template I want to run converter_generate with that
template but when I select csv want to run work_sheet_csv.
thanks for any help…