Permalink
Browse files

New labeled_show_column for the default show

Sortable column includes the table name
Fix for paperclip file field
  • Loading branch information...
1 parent f4a13a9 commit 9c620b8701d6dc0d4a5df0eefeb216ab450cdf1e @quirkey committed Dec 4, 2009
@@ -17,9 +17,9 @@ def labeled_#{field}(method, options = {})
def paperclip_file_field(method, options = {})
html = %{<p>}
label_text = options.delete(:label) || method.to_s.humanize
+ html << label(method, label_text)
if object.send("#{method}?")
html << %{
- #{label(method, label_text)}
<em>View existing #{label_text}:</em>
<a href="#{object.send(method).url}" target="_blank">#{object.send("#{method}_file_name")}</a>
<br />
View
@@ -63,6 +63,7 @@ def sortable_column_header(attribute_name, text = nil, options = {})
query_param = options[:query_param] || :query
logger.debug 'params:' + self.params[query_param].inspect
logger.debug 'parser:' + query_parser.inspect
+ attribute_name = "#{qadmin_configuration.model_klass.table_name}.#{attribute_name}"
sorting_this = query_parser.sort(attribute_name)
logger.debug "sorting #{attribute_name}:" + sorting_this.inspect
link_text << " #{image_tag("qadmin/icon_#{sorting_this.direction.downcase}.gif")}" if sorting_this
@@ -209,5 +210,30 @@ def fieldset(legend = nil, options = {}, &block)
html
end)
end
+
+ def labeled_show_column(object, method, options = {})
+ html = %{<p>}
+ html << label(object, method, options[:label] || nil)
+ show_value = options.has_key?(:value) ? options[:value] : object.send(method)
+ show_value = '<em>blank</em>' if show_value.blank?
+ html << %{<span class="show_value">#{show_value}</span>}
+ html << %{</p>}
+ html
+ end
+
+ def labeled_show_paperclip_attachment(object, method, options = {})
+ value = if object.send("#{method}?")
+ # has attachment
+ if object.send("#{method}_content_type") =~ /image/
+ size = number_to_human_size(object.send("#{method}_file_size"))
+ image_tag(object.send(method).url, {:title => "Size: #{size}"}.merge(options[:img_options] || {}))
+ else
+ link_to(object.send("#{method}_file_name"), object.send(method).url)
+ end
+ else
+ nil
+ end
+ labeled_show_column(object, method, options.merge(:value => value))
+ end
end
end
@@ -1,8 +1,7 @@
<div id="<%= dom_id(instance) %>">
<div class="fields_group">
<% qadmin_configuration.on_show.model_column_names.each do |attribute| -%>
- <h5><%= attribute.to_s.humanize %>:</h5>
- <%= h instance.send(attribute) %>
- <% end -%>
+ <%= labeled_show_column(instance, attribute) %>
+ <% end %>
</div>
</div>
@@ -2,7 +2,15 @@
<%= admin_controls model_instance_name, :for => :index, :ports => qadmin_configuration.ports, :controls => qadmin_configuration.on_index.controls, :parent => instance_variable_get("@#{qadmin_configuration.on_index.parent}") %>
-<%= will_paginate(@model_collection) %>
+<!-- <div class="page_controls"> -->
+ <!-- <div class="page_controls per_page">
+ <% form_tag nil, :method => :get do %>
+ <%= select_tag "per_page", options_for_select([5, 10, 25, 50, 100]) %>
+ <%= submit_tag 'go', :name => nil %>
+ <% end %>
+ </div> -->
+ <%= will_paginate(@model_collection) %>
+<!-- </div> -->
<%= admin_table(@model_collection) %>
<%= will_paginate(@model_collection) %>
@@ -2,10 +2,12 @@
<%= admin_controls model_instance_name, :for => :show, :object => @model_instance, :controls => qadmin_configuration.on_show.controls, :parent => instance_variable_get("@#{qadmin_configuration.on_show.parent}") %>
-<%- if controller.send(:template_exists?, "_#{model_instance_name}") -%>
- <%= render :partial => model_instance_name, :object => @model_instance %>
-<%- else -%>
- <%= render :partial => 'default/instance', :object => @model_instance %>
-<%- end -%>
-
+ <%=
+ begin
+ render model_instance_name, :object => @model_instance
+ rescue ActionView::MissingTemplate => e
+ logger.warn e
+ render 'default/instance', :object => @model_instance
+ end
+ %>
<%= admin_controls model_instance_name, :for => :show, :object => @model_instance, :controls => qadmin_configuration.on_show.controls, :parent => instance_variable_get("@#{qadmin_configuration.on_show.parent}") %>

0 comments on commit 9c620b8

Please sign in to comment.