Class: Admin::BaseController

Inherits:
InheritedResources::Base
  • Object
show all
Includes:
AbAdmin::Controllers::Callbacks, AbAdmin::Controllers::Fv
Defined in:
app/controllers/admin/base_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AbAdmin::Controllers::Fv

#fv

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



6
7
8
# File 'app/controllers/admin/base_controller.rb', line 6

def settings
  @settings
end

Instance Method Details

#batchObject



93
94
95
96
97
98
# File 'app/controllers/admin/base_controller.rb', line 93

def batch
  batch_action = batch_actions.detect{|a| a.name == params[:batch_action].to_sym }
  count = collection.inject(0) { |c, item| apply_batch_action(item, batch_action, *params[:batch_params].presence) ? c + 1 : c }
  flash[:success] = I18n.t('admin.batch_actions.status', count: count, action: batch_action.title)
  redirect_to_back_or_root
end

#createObject



42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/admin/base_controller.rb', line 42

def create
  create! do |success, failure|
    success.html { redirect_to redirect_to_on_success }
    success.js { render layout: false }
    failure.js { render :new, layout: false }
    unless respond_to_format?(:json)
      success.json { head :no_content }
      failure.json { render json: {errors: resource.errors}, status: :unprocessable_entity }
    end
  end
end

#destroyObject



68
69
70
71
72
73
# File 'app/controllers/admin/base_controller.rb', line 68

def destroy
  destroy! do
    track_action! if @settings[:history]
    redirect_to_on_success
  end
end

#editObject



81
82
83
84
85
# File 'app/controllers/admin/base_controller.rb', line 81

def edit
  edit! do |format|
    format.js { render layout: false }
  end
end

#indexObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/admin/base_controller.rb', line 22

def index
  super do |format|
    format.js { render layout: false }
    if settings[:export]
      format.csv do
        authorize! :export, resource_class
        doc = AbAdmin::Utils::CsvDocument.new(collection, export_options)
        send_data(doc.render(self, locale: params[:locale]), filename: doc.filename, type: Mime[:csv], disposition: 'attachment')
      end
      if Mime[:xlsx]
        format.xlsx do
          authorize! :export, resource_class
          doc = AbAdmin::Utils::XlsDocument.new(collection, export_options)
          send_data(doc.render(self, locale: params[:locale]), filename: doc.filename, type: Mime[:xlsx], disposition: 'attachment')
        end
      end
    end
  end
end

#newObject



87
88
89
90
91
# File 'app/controllers/admin/base_controller.rb', line 87

def new
  new! do |format|
    format.js { render layout: false }
  end
end

#showObject



75
76
77
78
79
# File 'app/controllers/admin/base_controller.rb', line 75

def show
  show! do |format|
    format.js { render layout: false }
  end
end

#updateObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/admin/base_controller.rb', line 54

def update
  resource.last_updated_timestamp = params[:last_updated_timestamp].to_i if settings[:safe_save] && !params[:_force_save] && params[:last_updated_timestamp]
  update! do |success, failure|
    success.html { redirect_to redirect_to_on_success }
    failure.html { render :edit }
    success.js { render layout: false }
    failure.js { render :edit, layout: false }
    unless respond_to_format?(:json)
      success.json { head :no_content }
      failure.json { render json: {errors: resource.errors}, status: :unprocessable_entity }
    end
  end
end