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 Method Summary collapse

Methods included from AbAdmin::Controllers::Fv

#fv

Instance Method Details

#batchObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/controllers/admin/base_controller.rb', line 92

def batch
  raise 'No ids specified for batch action' unless params[:by_ids].present?
  batch_action = params[:batch_action].to_sym
  if allow_batch_action?(batch_action) && collection.all?{|item| can?(batch_action, item) }
    if batch_action.to_s.end_with?('_collection')
      count = collection.size
      resource_class.public_send(batch_action, collection, *[params[:batch_params]].compact)
      if settings[:history]
        if Object.const_defined?('ActiveRecord::Import') && Track.respond_to?(:import)
          tracks = collection.map { |item| track_action("batch_#{batch_action}", item) }
          Track.import_from_batch_collection_action(tracks)
        else
          collection.each { |item| track_action!("batch_#{batch_action}", item) }
        end
      end
    else
      count = collection.inject(0) { |c, item| apply_batch_action(item, batch_action, *[params[:batch_params]].compact) ? c + 1 : c }
    end
    batch_action_name = I18n.t("admin.actions.batch_#{batch_action}.title", default: batch_action.to_s.humanize)
    flash[:success] = I18n.t('admin.batch_actions.status', count: count, action: batch_action_name)
  else
    raise CanCan::AccessDenied
  end
  redirect_to_back_or_root
end

#createObject



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

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 }
  end
end

#destroyObject



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

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

#editObject



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

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

#indexObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/admin/base_controller.rb', line 28

def index
  super do |format|
    format.js { render layout: false }
    format.csv do
      authorize! :export, resource_class
      doc = AbAdmin::Utils::CsvDocument.new(collection, export_options)
      send_data(doc.render, 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, filename: doc.filename, type: Mime[:xlsx], disposition: 'attachment')
      end
    end
  end
end

#newObject



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

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

#showObject



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

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
# File 'app/controllers/admin/base_controller.rb', line 54

def update
  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 { head :unprocessable }
    end
  end
end