Class: Kms::AssetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/kms/assets_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#set_csrf_cookie_for_ng

Instance Method Details

#ckeditorObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/kms/assets_controller.rb', line 19

def ckeditor
  @asset = Asset.new(file: params[:upload])
  if @asset.save
    render text: %Q"<script type='text/javascript'>
        window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, '#{@asset.file.url}');
      </script>"
  else
    render text: %Q"<script type='text/javascript'>
            window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, null, '#{@asset.errors.full_messages.first}');
          </script>"
  end
end

#createObject



10
11
12
13
14
15
16
17
# File 'app/controllers/kms/assets_controller.rb', line 10

def create
  @asset = Asset.new(asset_params)
  if @asset.save
    render json: {success: true, files: [@asset]}.to_json
  else
    render text: '', status: :unprocessable_entity
  end
end

#destroyObject



46
47
48
49
50
# File 'app/controllers/kms/assets_controller.rb', line 46

def destroy
  @asset = Asset.find(params[:id])
  @asset.destroy
  render json: @asset.to_json
end

#indexObject



6
7
8
# File 'app/controllers/kms/assets_controller.rb', line 6

def index
  render json: Asset.all.to_json(methods: [:filename, :url])
end

#showObject



39
40
41
42
43
44
# File 'app/controllers/kms/assets_controller.rb', line 39

def show
  @asset = Asset.find(params[:id])
  attrs = {}
  attrs.merge!(methods: [:filename, :text]) if @asset.stylesheet_or_javascript?
  render json: @asset.to_json(attrs)
end

#updateObject



32
33
34
35
36
37
# File 'app/controllers/kms/assets_controller.rb', line 32

def update
  @asset = Asset.find(params[:id])
  asset_params.merge!(text: params[:text], performing_plain_text: params[:performing_plain_text]) if params[:text]
  @asset.update_attributes(asset_params)
  render json: @asset.to_json
end