Guest User

Untitled

a guest
Jun 22nd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. # Methods added to this helper will be available to all templates in
  2. the application.
  3. module ApplicationHelper
  4.  
  5. def listado( registros, otro )
  6. campos = otro[:cps]
  7. sizes = otro[:size]
  8. clase = otro[:cls]
  9. edit_path = otro[:edit_path].nil? ? "" : otro[:edit_path]
  10. new_title = otro[:new_title].nil? ? "Crear un registro" : otro[:new_title]
  11. edit_title = otro[:edit_title].nil? ? "Modifica este registro." :
  12. otro[:edit_title]
  13. if otro[:delete_path]
  14. delete_title = otro[:delete_title]
  15. delete_path = otro[:delete_path]
  16. end
  17. ad = []
  18. if otro[:adicional_mono]
  19. ad << {:mono => otro[:adicional_mono],
  20. :titulo => otro[:adicional_titulo],
  21. :path => otro[:adicional_path]}
  22. elsif otro[:adicional]
  23. if otro[:adicional].is_a?(Array)
  24. ad += otro[:adicional]
  25. elsif otro[:adicional].is_a?(Hash)
  26. ad << otro[:adicional]
  27. end
  28. end
  29. # encabezados especiales
  30. enc_ad1_path = otro[:enc_ad1_path]
  31. enc_ad1_titulo = otro[:enc_ad1_titulo]
  32. enc_ad1_mono = otro[:enc_ad1_mono]
  33. enc_ad2_path = otro[:enc_ad2_path]
  34. enc_ad2_titulo = otro[:enc_ad2_titulo]
  35. enc_ad2_mono = otro[:enc_ad2_mono]
  36. enc_ad3_path = otro[:enc_ad3_path]
  37. enc_ad3_titulo = otro[:enc_ad3_titulo]
  38. enc_ad3_mono = otro[:enc_ad3_mono]
  39. color_txt_fld = otro[:color]
  40. # Fin encabezados especiales
  41. s = %Q!<table
  42. class="detalle">\n<caption>#{otro[:ttl]}</caption>\n<tr
  43. class="titulos">!
  44. # Titulos
  45. campos.each {|cp| s += %Q!\n<td>#{
  46. clase.human_attribute_name(cp).gsub(/\./,"<br>")}</td>! }
  47. s += "<td>"
  48. s += %Q!#{ link_to image_tag('add.png'), otro[:new_path], :title
  49. => new_title }! if otro[:new_path]
  50. s += %Q!#{ link_to image_tag(enc_ad1_mono), enc_ad1_path, :title
  51. => enc_ad1_titulo}! if enc_ad1_path
  52. s += %Q!#{ link_to image_tag(enc_ad2_mono), enc_ad2_path, :title
  53. => enc_ad2_titulo}! if enc_ad2_path
  54. s += %Q!#{ link_to image_tag(enc_ad3_mono), enc_ad3_path, :title
  55. => enc_ad3_titulo}! if enc_ad3_path
  56. s += otro[:enc_link_esp] if otro[:enc_link_esp]
  57. s += %Q!</td></tr>\n!
  58.  
  59. otro[:save_path] = clase.name.pluralize.downcase if otro[:save_path].nil?
  60. otro[:save_path] = otro[:save_path][1..-1] if
  61. otro[:save_path][0,1] =="/"
  62.  
  63. s += %Q!<form action="/#{otro[:save_path]}" method="get">!
  64. s += %Q!<input name="authenticity_token" type="hidden"
  65. value="#{form_authenticity_token}" />!
  66. s += %Q!\n<tr class="txtsql">!
  67. campos.each_index do |ind|
  68. cp = campos[ind]
  69. if (not sizes.blank?) && (not sizes[ind].blank?)
  70. s += %Q!\n <td>#{ text_field "txtsql", cp, :size => sizes[ind] }</td>!
  71. else
  72. s += %Q!\n <td>#{ text_field "txtsql", cp}</td>!
  73. end
  74. end
  75. s += %Q!\n <td>#{submit_tag "Ok", :title => "Buscar"} </td>!
  76. s += %Q!\n</tr>\n!
  77.  
  78. registros.each do |registro|
  79. s += %Q!<tr class="#{ cycle('odd','par')}">!
  80. campos.each_index do |indice|
  81. cp = campos[indice]
  82. v = eval("registro."+cp)
  83. td = "\n<td>"
  84. txt = ""
  85. if color_txt_fld[indice]
  86. prcc = color_txt_fld[indice]
  87. txt += %Q!<font color="#{prcc.call(v, registro)}">!
  88. end if color_txt_fld
  89. if v.is_a?(String)
  90. txt += h(v)
  91. elsif cp =~ /folio/i # Los folios no llevan punto de
  92. separacion de miles
  93. td = %Q!\n<td align="right">!
  94. txt += v.to_s
  95. elsif cp =~ /pct/i
  96. td = %Q!\n<td align="right">!
  97. txt += number_to_currency(v*100.0, :unit => '%', :precision
  98. => 2, :delimiter => '')
  99. elsif v.is_a?(Float) || v.is_a?(BigDecimal)
  100. td = %Q!\n<td align="right">!
  101. txt += number_to_currency(v, :unit => '', :precision => 2,
  102. :delimiter => '.')
  103. elsif v.is_a?(Fixnum) || v.is_a?(Bignum)
  104. td = %Q!\n<td align="right">!
  105. txt += number_to_currency(v, :unit => '', :precision => 0,
  106. :delimiter => '.') <---------------------------ACA SE CAE
  107. elsif v.is_a?(Date)
  108. txt += v.to_s(:my_date)
  109. elsif v.is_a?(ActiveSupport::TimeWithZone)
  110. txt += v.to_s(:my_time)
  111. elsif v.is_a?(FalseClass)
  112. txt += check_box_tag(cp, value = "0", checked = false,
  113. options = {:disabled => true})
  114. elsif v.is_a?(TrueClass)
  115. txt += check_box_tag(cp, value = "1", checked = true,
  116. options = {:disabled => true})
  117. end
  118. txt += %Q!</font>! if color_txt_fld[indice] if color_txt_fld
  119. s += td + txt + "</td>"
  120. end
  121. s += "\n <td>"
  122.  
  123. s += link_to( image_tag('book_edit.png'),
  124. edit_path.call(registro), :title => edit_title) if
  125. edit_path.is_a?(Proc)
  126.  
  127. if delete_path
  128. if delete_path.is_a?(String)
  129. s += link_to( image_tag('delete.png'), registro, :confirm =>
  130. '¿ Esta ud seguro ?', :method => :delete, :title => delete_title)
  131. else
  132. s += link_to( image_tag('delete.png'),
  133. delete_path.call(registro), :confirm => '¿ Esta ud seguro ?', :method
  134. => :delete, :title => delete_title)
  135. end
  136. end
  137.  
  138. ad.each do |adic|
  139. s += link_to( image_tag(adic[:mono]),
  140. adic[:path].call(registro), :title => adic[:titulo])
  141. end
  142. s += "</td>\n</tr>"
  143. end
  144. s += "\n</table>"
  145. s
  146. end
Add Comment
Please, Sign In to add comment