Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Generator now uses qadmin wherever admin was used before

Fix for forms where controller was in a namespace - use 'namespace' config option
  • Loading branch information...
commit ddad60512b5e5526aecd8b742c16d0ef157d8d17 1 parent 32a1076
@quirkey authored
View
7 lib/qadmin/actions/edit.erb
@@ -1,6 +1,13 @@
def edit
logger.debug 'Qadmin: Default /edit'
@model_instance = @<%= config.on_edit.model_instance_name %> = <%= config.on_edit.model_name %>.find(params[:id])
+ @form_instance = if qadmin_configuration.parent
+ [qadmin_configuration.parent, @model_instance]
+ elsif qadmin_configuration.namespace
+ [qadmin_configuration.namespace, @model_instance]
+ else
+ @model_instance
+ end
respond_to do |format|
format.html { render_template_for_section('edit.html') }
format.xml { redirect_to <%= config.on_edit.model_instance_name %>_path(@<%= config.on_edit.model_instance_name %>) }
View
7 lib/qadmin/actions/new.erb
@@ -1,6 +1,13 @@
def new
logger.debug 'Qadmin: Default /new'
@model_instance = @<%= config.on_new.model_instance_name %> = <%= config.on_new.model_name %>.new
+ @form_instance = if qadmin_configuration.parent
+ [qadmin_configuration.parent, @model_instance]
+ elsif qadmin_configuration.namespace
+ [qadmin_configuration.namespace, @model_instance]
+ else
+ @model_instance
+ end
respond_to do |format|
format.html { render_template_for_section('new.html') }
format.xml { render :xml => @<%= config.on_new.model_instance_name %> }
View
1  lib/qadmin/configuration.rb
@@ -31,6 +31,7 @@ def #{name}?
hash_accessor :model_instance_name
hash_accessor :model_collection_name
hash_accessor :model_human_name
+ hash_accessor :namespace, :default => nil
hash_accessor :parent, :default => false
hash_accessor :default_scope, :default => false
View
20 lib/qadmin/helper.rb
@@ -13,14 +13,14 @@ def admin_controls(name, options = {}, &block)
general_link_attributes = {:controller => controller}.merge(parent_link_attributes)
control_links = {
- :index => lambda { link_to(image_tag('admin/icon_list.png') + " Back to List", general_link_attributes.merge(:action => 'index')) },
- :new => lambda { link_to(image_tag('admin/icon_new.png') + " New", general_link_attributes.merge(:action => 'new')) },
- :edit => lambda { link_to(image_tag('admin/icon_edit.png') + " Edit", general_link_attributes.merge({:action => 'edit', :id => obj.id})) },
- :show => lambda { link_to(image_tag('admin/icon_show.png') + " View", general_link_attributes.merge({:action => 'show', :id => obj.id})) },
- :destroy => lambda { link_to(image_tag('admin/icon_destroy.png') + " Delete", general_link_attributes.merge({:action => 'destroy', :id => obj.id}), :confirm => 'Are you sure?', :method => :delete) },
- :ports => lambda { link_to(image_tag('admin/icon_export.png') + " Import/Export", general_link_attributes.merge(:action => 'ports')) },
- :export => lambda { link_to(image_tag('admin/icon_export.png') + " Export", general_link_attributes.merge(:action => 'export')) },
- :preview => lambda { link_to(image_tag('admin/icon_preview.png') + " Preview", general_link_attributes.merge({:action => 'preview', :id => obj.id})) }
+ :index => lambda { link_to(image_tag('qadmin/icon_list.png') + " Back to List", general_link_attributes.merge(:action => 'index')) },
+ :new => lambda { link_to(image_tag('qadmin/icon_new.png') + " New", general_link_attributes.merge(:action => 'new')) },
+ :edit => lambda { link_to(image_tag('qadmin/icon_edit.png') + " Edit", general_link_attributes.merge({:action => 'edit', :id => obj.id})) },
+ :show => lambda { link_to(image_tag('qadmin/icon_show.png') + " View", general_link_attributes.merge({:action => 'show', :id => obj.id})) },
+ :destroy => lambda { link_to(image_tag('qadmin/icon_destroy.png') + " Delete", general_link_attributes.merge({:action => 'destroy', :id => obj.id}), :confirm => 'Are you sure?', :method => :delete) },
+ :ports => lambda { link_to(image_tag('qadmin/icon_export.png') + " Import/Export", general_link_attributes.merge(:action => 'ports')) },
+ :export => lambda { link_to(image_tag('qadmin/icon_export.png') + " Export", general_link_attributes.merge(:action => 'export')) },
+ :preview => lambda { link_to(image_tag('qadmin/icon_preview.png') + " Preview", general_link_attributes.merge({:action => 'preview', :id => obj.id})) }
}
control_sets = {
@@ -60,7 +60,7 @@ def sortable_column_header(attribute_name, text = nil, options = {})
logger.debug 'parser:' + query_parser.inspect
sorting_this = query_parser.sort(attribute_name)
logger.debug "sorting #{attribute_name}:" + sorting_this.inspect
- link_text << " #{image_tag("admin/icon_#{sorting_this.direction.downcase}.gif")}" if sorting_this
+ link_text << " #{image_tag("qadmin/icon_#{sorting_this.direction.downcase}.gif")}" if sorting_this
query_parser.clear_default_sort!
query_parser.set_sort(attribute_name, sorting_this ? sorting_this.next_direction : 'desc')
link_to link_text, self.params.dup.merge(query_param => query_parser.to_query_hash, :anchor => (options[:id] || self.qadmin_configuration.model_collection_name)), :class => 'sortable_column_header'
@@ -137,7 +137,7 @@ def admin_table(collection, options = {})
end
row_actions.each do |action|
http_method = (action.to_sym == :destroy) ? :delete : :get
- html << %{<td>#{link_to(image_tag("admin/icon_#{action}.png"), {:controller => controller, :action => action, :id => instance.id}, :method => http_method)}</td>}
+ html << %{<td>#{link_to(image_tag("qadmin/icon_#{action}.png"), {:controller => controller, :action => action, :id => instance.id}, :method => http_method)}</td>}
end
html << '</tr>'
end
View
3  lib/qadmin/views/default/edit.html.erb
@@ -4,8 +4,7 @@
<%= error_messages_for model_instance_name %>
-<%- instance = qadmin_configuration.parent ? [qadmin_configuration.parent, @model_instance] : @model_instance -%>
-<% form_for(instance, :html => {:multipart => qadmin_configuration.multipart_forms}) do |f| %>
+<% form_for(@form_instance, :html => {:multipart => qadmin_configuration.multipart_forms}) do |f| %>
<%= render :partial => 'form', :locals => {:f => f, model_instance_name.to_sym => @model_instance} %>
<p><%= f.submit "Update" %></p>
<% end %>
View
3  lib/qadmin/views/default/new.html.erb
@@ -4,8 +4,7 @@
<%= error_messages_for model_instance_name %>
-<%- instance = qadmin_configuration.parent ? [qadmin_configuration.parent, @model_instance] : @model_instance -%>
-<% form_for(instance, :html => {:multipart => qadmin_configuration.multipart_forms}) do |f| %>
+<% form_for(@form_instance, :html => {:multipart => qadmin_configuration.multipart_forms}) do |f| %>
<%= render :partial => 'form', :locals => {:f => f, model_instance_name.to_sym => @model_instance} %>
<p><%= f.submit "Create" %></p>
<% end %>
View
8 rails_generators/qadmin/qadmin_generator.rb
@@ -38,7 +38,7 @@ def manifest
if !after_scaffold
m.directory(File.join('app','controllers', controller_class_path))
m.directory(File.join('app', 'helpers', controller_class_path))
- m.directory(File.join('public','images','admin'))
+ m.directory(File.join('public','images','qadmin'))
end
m.directory(File.join('app', 'views', controller_class_path, controller_file_name))
@@ -50,8 +50,8 @@ def manifest
if !after_scaffold
# Layout and stylesheet.
- m.template('layout.html.erb', File.join('app','views','layouts', "admin.html.erb"))
- m.template('style.css', 'public/stylesheets/admin.css')
+ m.template('layout.html.erb', File.join('app','views','layouts', "qadmin.html.erb"))
+ m.template('style.css', 'public/stylesheets/qadmin.css')
m.template('controller.rb', File.join('app','controllers', controller_class_path, "#{controller_file_name}_controller.rb"))
end
@@ -63,7 +63,7 @@ def manifest
# Copy Icons
Dir[File.join(File.dirname(__FILE__),'templates','images/*')].each do |image|
- m.file File.join('images',File.basename(image)), File.join('public','images','admin',File.basename(image))
+ m.file File.join('images',File.basename(image)), File.join('public','images','qadmin',File.basename(image))
end
end
View
2  rails_generators/qadmin/templates/controller.rb
@@ -1,6 +1,6 @@
class <%= controller_class_name %>Controller < ApplicationController
#before_filter :login_required
- layout 'admin'
+ layout 'qadmin'
qadmin
end
View
2  rails_generators/qadmin/templates/layout.html.erb
@@ -7,7 +7,7 @@
<title>Admin</title>
- <%%= stylesheet_link_tag 'admin' %>
+ <%%= stylesheet_link_tag 'qadmin' %>
<%%= javascript_include_tag :defaults %>
</head>
<body>

0 comments on commit ddad605

Please sign in to comment.
Something went wrong with that request. Please try again.