Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Methods added to this helper will be available to all templates in
- the application.
- module ApplicationHelper
- def listado( registros, otro )
- campos = otro[:cps]
- sizes = otro[:size]
- clase = otro[:cls]
- edit_path = otro[:edit_path].nil? ? "" : otro[:edit_path]
- new_title = otro[:new_title].nil? ? "Crear un registro" : otro[:new_title]
- edit_title = otro[:edit_title].nil? ? "Modifica este registro." :
- otro[:edit_title]
- if otro[:delete_path]
- delete_title = otro[:delete_title]
- delete_path = otro[:delete_path]
- end
- ad = []
- if otro[:adicional_mono]
- ad << {:mono => otro[:adicional_mono],
- :titulo => otro[:adicional_titulo],
- :path => otro[:adicional_path]}
- elsif otro[:adicional]
- if otro[:adicional].is_a?(Array)
- ad += otro[:adicional]
- elsif otro[:adicional].is_a?(Hash)
- ad << otro[:adicional]
- end
- end
- # encabezados especiales
- enc_ad1_path = otro[:enc_ad1_path]
- enc_ad1_titulo = otro[:enc_ad1_titulo]
- enc_ad1_mono = otro[:enc_ad1_mono]
- enc_ad2_path = otro[:enc_ad2_path]
- enc_ad2_titulo = otro[:enc_ad2_titulo]
- enc_ad2_mono = otro[:enc_ad2_mono]
- enc_ad3_path = otro[:enc_ad3_path]
- enc_ad3_titulo = otro[:enc_ad3_titulo]
- enc_ad3_mono = otro[:enc_ad3_mono]
- color_txt_fld = otro[:color]
- # Fin encabezados especiales
- s = %Q!<table
- class="detalle">\n<caption>#{otro[:ttl]}</caption>\n<tr
- class="titulos">!
- # Titulos
- campos.each {|cp| s += %Q!\n<td>#{
- clase.human_attribute_name(cp).gsub(/\./,"<br>")}</td>! }
- s += "<td>"
- s += %Q!#{ link_to image_tag('add.png'), otro[:new_path], :title
- => new_title }! if otro[:new_path]
- s += %Q!#{ link_to image_tag(enc_ad1_mono), enc_ad1_path, :title
- => enc_ad1_titulo}! if enc_ad1_path
- s += %Q!#{ link_to image_tag(enc_ad2_mono), enc_ad2_path, :title
- => enc_ad2_titulo}! if enc_ad2_path
- s += %Q!#{ link_to image_tag(enc_ad3_mono), enc_ad3_path, :title
- => enc_ad3_titulo}! if enc_ad3_path
- s += otro[:enc_link_esp] if otro[:enc_link_esp]
- s += %Q!</td></tr>\n!
- otro[:save_path] = clase.name.pluralize.downcase if otro[:save_path].nil?
- otro[:save_path] = otro[:save_path][1..-1] if
- otro[:save_path][0,1] =="/"
- s += %Q!<form action="/#{otro[:save_path]}" method="get">!
- s += %Q!<input name="authenticity_token" type="hidden"
- value="#{form_authenticity_token}" />!
- s += %Q!\n<tr class="txtsql">!
- campos.each_index do |ind|
- cp = campos[ind]
- if (not sizes.blank?) && (not sizes[ind].blank?)
- s += %Q!\n <td>#{ text_field "txtsql", cp, :size => sizes[ind] }</td>!
- else
- s += %Q!\n <td>#{ text_field "txtsql", cp}</td>!
- end
- end
- s += %Q!\n <td>#{submit_tag "Ok", :title => "Buscar"} </td>!
- s += %Q!\n</tr>\n!
- registros.each do |registro|
- s += %Q!<tr class="#{ cycle('odd','par')}">!
- campos.each_index do |indice|
- cp = campos[indice]
- v = eval("registro."+cp)
- td = "\n<td>"
- txt = ""
- if color_txt_fld[indice]
- prcc = color_txt_fld[indice]
- txt += %Q!<font color="#{prcc.call(v, registro)}">!
- end if color_txt_fld
- if v.is_a?(String)
- txt += h(v)
- elsif cp =~ /folio/i # Los folios no llevan punto de
- separacion de miles
- td = %Q!\n<td align="right">!
- txt += v.to_s
- elsif cp =~ /pct/i
- td = %Q!\n<td align="right">!
- txt += number_to_currency(v*100.0, :unit => '%', :precision
- => 2, :delimiter => '')
- elsif v.is_a?(Float) || v.is_a?(BigDecimal)
- td = %Q!\n<td align="right">!
- txt += number_to_currency(v, :unit => '', :precision => 2,
- :delimiter => '.')
- elsif v.is_a?(Fixnum) || v.is_a?(Bignum)
- td = %Q!\n<td align="right">!
- txt += number_to_currency(v, :unit => '', :precision => 0,
- :delimiter => '.') <---------------------------ACA SE CAE
- elsif v.is_a?(Date)
- txt += v.to_s(:my_date)
- elsif v.is_a?(ActiveSupport::TimeWithZone)
- txt += v.to_s(:my_time)
- elsif v.is_a?(FalseClass)
- txt += check_box_tag(cp, value = "0", checked = false,
- options = {:disabled => true})
- elsif v.is_a?(TrueClass)
- txt += check_box_tag(cp, value = "1", checked = true,
- options = {:disabled => true})
- end
- txt += %Q!</font>! if color_txt_fld[indice] if color_txt_fld
- s += td + txt + "</td>"
- end
- s += "\n <td>"
- s += link_to( image_tag('book_edit.png'),
- edit_path.call(registro), :title => edit_title) if
- edit_path.is_a?(Proc)
- if delete_path
- if delete_path.is_a?(String)
- s += link_to( image_tag('delete.png'), registro, :confirm =>
- '¿ Esta ud seguro ?', :method => :delete, :title => delete_title)
- else
- s += link_to( image_tag('delete.png'),
- delete_path.call(registro), :confirm => '¿ Esta ud seguro ?', :method
- => :delete, :title => delete_title)
- end
- end
- ad.each do |adic|
- s += link_to( image_tag(adic[:mono]),
- adic[:path].call(registro), :title => adic[:titulo])
- end
- s += "</td>\n</tr>"
- end
- s += "\n</table>"
- s
- end
Add Comment
Please, Sign In to add comment