Sha256: 03dc1139023963c2661423274aeb752c0a8adcd7cebfa2a9451171191ca4a2ff
Contents?: true
Size: 1.48 KB
Versions: 9
Compression:
Stored size: 1.48 KB
Contents
module Ckeditor class AssetResponse attr_reader :asset, :params def initialize(asset, request) @asset = asset @request = request @params = request.params @asset.data = Ckeditor::Http.normalize_param(file, @request) end def json? params[:responseType] == 'json' end def ckeditor? !params[:CKEditor].blank? end def file !(ckeditor? || json?) ? params[:qqfile] : params[:upload] end def success(relative_url_root = nil) if json? { json: { "uploaded" => 1, "fileName" => asset.filename, "url" => asset.url }.to_json } elsif ckeditor? { text: %Q"<script type='text/javascript'> window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, '#{relative_url_root}#{Ckeditor::Utils.escape_single_quotes(asset.url_content)}'); </script>" } else { json: asset.to_json(only: [:id, :type]) } end end def errors if json? { json: { "uploaded" => 0, "error" => { "message" => "Upload failed"} }.to_json } elsif ckeditor? { text: %Q"<script type='text/javascript'> window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, null, '#{Ckeditor::Utils.escape_single_quotes(asset.errors.full_messages.first)}'); </script>" } else {nothing: true, format: :json} end end end end
Version data entries
9 entries across 9 versions & 3 rubygems