Class: Carnival::BaseAdminController
- Inherits:
-
InheritedResources::Base
- Object
- InheritedResources::Base
- Carnival::BaseAdminController
- Defined in:
- app/controllers/carnival/base_admin_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #edit ⇒ Object
- #home ⇒ Object
- #index ⇒ Object
- #load_dependent_select_options ⇒ Object
- #load_select_options ⇒ Object
- #new ⇒ Object
- #presenter_name(field) ⇒ Object
- #render_inner_form ⇒ Object
- #show ⇒ Object
- #table_items ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
69 70 71 72 73 74 |
# File 'app/controllers/carnival/base_admin_controller.rb', line 69 def create create! do |success, failure| success.html { redirect_to back_or_model_path, :notice => I18n.t("messages.created") } failure.html { instantiate_model and render 'new' } end end |
#edit ⇒ Object
63 64 65 66 67 |
# File 'app/controllers/carnival/base_admin_controller.rb', line 63 def edit edit! do instantiate_model end end |
#home ⇒ Object
8 9 |
# File 'app/controllers/carnival/base_admin_controller.rb', line 8 def home end |
#index ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/carnival/base_admin_controller.rb', line 27 def index @query_form = Carnival::QueryFormCreator.create(@presenter, params) @model = @presenter.model_class @query_service = Carnival::QueryService.new(table_items || @model, @presenter, @query_form) respond_to do |format| format.html do @records = @query_service.get_query last_page = (@query_service.total_records / @presenter.items_per_page.to_f).ceil @paginator = Carnival::Paginator.new @query_form.page, last_page @thead_renderer = Carnival::TheadRenderer.new @presenter.fields_for_action(:index), @query_form.sort_column, @query_form.sort_direction end format.csv do @records = @query_service.records_without_pagination render :csv => @model.model_name.human end format.pdf do @records = @query_service.records_without_pagination @thead_renderer = Carnival::TheadRenderer.new @presenter.fields_for_action(:index), @query_form.sort_column, @query_form.sort_direction render :pdf => t("activerecord.attributes.#{@presenter.full_model_name}.pdf_name") , :template => 'carnival/base_admin/index.pdf.haml', :show_as_html => params[:debug].present? end end end |
#load_dependent_select_options ⇒ Object
83 84 85 86 87 88 |
# File 'app/controllers/carnival/base_admin_controller.rb', line 83 def presenter = params[:presenter].constantize.send(:new, :controller => self) model = presenter.relation_model(params[:field].gsub("_id", "").to_sym) @options = model.list_for_select(add_empty_option: true, query: ["#{params[:dependency_field]} = ?", params[:dependency_value]]) render layout: nil end |
#load_select_options ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/controllers/carnival/base_admin_controller.rb', line 90 def model_name = params[:model_name] search_field = params[:search_field] presenter = params[:presenter_name].constantize.send(:new, :controller => self) model = presenter.relation_model(model_name.to_sym) list = [] model.where("#{search_field} like '%#{params[:q]}%'").each do |elem| list << {id: elem.id, text: elem.send(search_field.to_sym)} end render :json => list end |
#new ⇒ Object
57 58 59 60 61 |
# File 'app/controllers/carnival/base_admin_controller.rb', line 57 def new new! do instantiate_model end end |
#presenter_name(field) ⇒ Object
21 22 23 24 25 |
# File 'app/controllers/carnival/base_admin_controller.rb', line 21 def presenter_name field field_name = field.split('/').last carnival_mount = Carnival::Config.mount_at "#{carnival_mount}/#{field_name.singularize}_presenter".classify.constantize end |
#render_inner_form ⇒ Object
15 16 17 18 19 |
# File 'app/controllers/carnival/base_admin_controller.rb', line 15 def render_inner_form @presenter = presenter_name(params[:field]).new controller: self model_class = params[:field].classify.constantize @model_object = model_class.find(params[:id]) end |
#show ⇒ Object
51 52 53 54 55 |
# File 'app/controllers/carnival/base_admin_controller.rb', line 51 def show show! do instantiate_model end end |
#table_items ⇒ Object
11 12 13 |
# File 'app/controllers/carnival/base_admin_controller.rb', line 11 def table_items nil end |
#update ⇒ Object
76 77 78 79 80 81 |
# File 'app/controllers/carnival/base_admin_controller.rb', line 76 def update update! do |success, failure| success.html { redirect_to back_or_model_path, :notice => I18n.t("messages.updated") } failure.html { instantiate_model and render 'edit' } end end |