@@ -105,37 +105,34 @@ def build_typus_table(model, fields, items, link_options = {}, association = nil
105
105
106
106
end
107
107
108
- # OPTIMIZE: Move html code to partial.
109
108
def typus_table_header ( model , fields )
110
- returning ( String . new ) do |html |
111
- headers = [ ]
112
- fields . each do |key , value |
113
-
114
- content = key . end_with? ( '_id' ) ? key : model . human_attribute_name ( key )
115
-
116
- if ( model . model_fields . map ( &:first ) . collect { |i | i . to_s } . include? ( key ) || model . reflect_on_all_associations ( :belongs_to ) . map ( &:name ) . include? ( key . to_sym ) ) && params [ :action ] == 'index'
117
- sort_order = case params [ :sort_order ]
118
- when 'asc' then [ 'desc' , '↓' ]
119
- when 'desc' then [ 'asc' , '↑' ]
120
- else
121
- [ nil , nil ]
122
- end
123
- order_by = model . reflect_on_association ( key . to_sym ) . primary_key_name rescue key
124
- switch = sort_order . last if params [ :order_by ] . eql? ( order_by )
125
- options = { :order_by => order_by , :sort_order => sort_order . first }
126
- content = link_to "#{ content } #{ switch } " , params . merge ( options )
127
- end
128
109
129
- headers << "<th>#{ content } </th>"
110
+ headers = fields . map do |key , value |
111
+
112
+ content = key . end_with? ( '_id' ) ? key : model . human_attribute_name ( key )
113
+
114
+ if ( model . model_fields . map ( &:first ) . collect { |i | i . to_s } . include? ( key ) || model . reflect_on_all_associations ( :belongs_to ) . map ( &:name ) . include? ( key . to_sym ) ) && params [ :action ] == 'index'
115
+ sort_order = case params [ :sort_order ]
116
+ when 'asc' then [ 'desc' , '↓' ]
117
+ when 'desc' then [ 'asc' , '↑' ]
118
+ else
119
+ [ nil , nil ]
120
+ end
121
+ order_by = model . reflect_on_association ( key . to_sym ) . primary_key_name rescue key
122
+ switch = sort_order . last if params [ :order_by ] . eql? ( order_by )
123
+ options = { :order_by => order_by , :sort_order => sort_order . first }
124
+ content = link_to "#{ content } #{ switch } " , params . merge ( options )
125
+ end
126
+
127
+ content
128
+
129
+ end
130
+
131
+ headers << " " if @current_user . can? ( 'delete' , model )
132
+
133
+ render "admin/helpers/table_header" ,
134
+ :headers => headers
130
135
131
- end
132
- headers << "<th> </th>" if @current_user . can? ( 'delete' , model )
133
- html << <<-HTML
134
- < tr >
135
- #{ headers . join ( "\n " ) }
136
- </ tr>
137
- HTML
138
- end
139
136
end
140
137
141
138
# OPTIMIZE: Refactor (Remove rescue)
@@ -255,4 +252,4 @@ def typus_table_boolean_field(attribute, item)
255
252
256
253
end
257
254
258
- end
255
+ end
0 commit comments