# addEventListenerToButton

**URL:** <https://www.ruby-forum.com/t/addeventlistenertobutton/128011>\
**Category:** Rails\
**Created:** [February 4, 2008, 7:48am UTC](https://www.ruby-forum.com/t/addeventlistenertobutton/128011 "2008-02-04T07:48:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@casid](https://www.ruby-forum.com/u/casid)\
**Post date:** [February 4, 2008, 7:48am UTC](https://www.ruby-forum.com/t/addeventlistenertobutton/128011/1 "2008-02-04T07:48:47Z")

</div>

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 csv

and 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…
