Class: PushType::Admin::AssetsController

Inherits:
PushType::AdminController show all
Includes:
PushType::AssetsHelper
Defined in:
app/controllers/push_type/admin/assets_controller.rb

Instance Method Summary collapse

Methods included from PushType::AssetsHelper

#asset_back_link, #asset_hash, #asset_icon, #asset_preview_thumb_url, #assets_array

Methods inherited from PushType::AdminController

#info

Instance Method Details

#createObject



30
31
32
33
34
35
36
37
# File 'app/controllers/push_type/admin/assets_controller.rb', line 30

def create
  if @asset.save
    flash[:notice] = 'File successfully uploaded.'
    redirect_to push_type_admin.assets_path
  else
    render 'new'
  end
end

#destroyObject



65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/push_type/admin/assets_controller.rb', line 65

def destroy
  if @asset.trashed?
    @asset.destroy
    flash[:notice] = 'Media permanently deleted.'
    redirect_to push_type_admin.trash_assets_path
  else
    @asset.trash!
    flash[:notice] = 'Media trashed.'
    redirect_to push_type_admin.assets_path
  end
end

#editObject



53
54
# File 'app/controllers/push_type/admin/assets_controller.rb', line 53

def edit
end

#emptyObject



83
84
85
86
87
# File 'app/controllers/push_type/admin/assets_controller.rb', line 83

def empty
  PushType::Asset.trashed.destroy_all
  flash[:notice] = 'Trash successfully emptied.'
  redirect_to push_type_admin.assets_path
end

#indexObject



11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/push_type/admin/assets_controller.rb', line 11

def index
  respond_to do |format|
    format.html do
      @assets = PushType::Asset.not_trash.page(params[:page]).per(20)
    end
    format.json do
      @assets = PushType::Asset.not_trash.page(params[:page]).per(12)
      render json: { assets: assets_array(@assets).as_json, meta: { current_page: @assets.current_page, total_pages: @assets.total_pages } }
    end
  end
end

#newObject



27
28
# File 'app/controllers/push_type/admin/assets_controller.rb', line 27

def new
end

#restoreObject



77
78
79
80
81
# File 'app/controllers/push_type/admin/assets_controller.rb', line 77

def restore
  @asset.restore!
  flash[:notice] = 'Media successfully restored.'
  redirect_to push_type_admin.assets_path
end

#trashObject



23
24
25
# File 'app/controllers/push_type/admin/assets_controller.rb', line 23

def trash
  @assets = PushType::Asset.trashed.page(params[:page]).per(20)
end

#updateObject



56
57
58
59
60
61
62
63
# File 'app/controllers/push_type/admin/assets_controller.rb', line 56

def update
  if @asset.update_attributes asset_params
    flash[:notice] = 'Media successfully updated.'
    redirect_to push_type_admin.assets_path
  else
    render 'edit'
  end
end

#uploadObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/push_type/admin/assets_controller.rb', line 39

def upload
  respond_to do |format|
    format.json do
      if @asset.save
        hash = params[:froala] ? { link: media_path(@asset) } : { asset: asset_hash(@asset).as_json }
        render json: hash, status: :created
      else
        hash = params[:froala] ? { error: @asset.errors.full_messages.first } : { errors: @asset.errors.as_json }
        render json: hash, status: :unprocessable_entity
      end
    end
  end
end