Class: Ckeditor::AssetResponse
- Inherits:
-
Object
- Object
- Ckeditor::AssetResponse
- Defined in:
- lib/ckeditor/asset_response.rb
Instance Attribute Summary collapse
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #ckeditor? ⇒ Boolean
- #errors ⇒ Object
- #file ⇒ Object
-
#initialize(asset, request) ⇒ AssetResponse
constructor
A new instance of AssetResponse.
- #json? ⇒ Boolean
- #success(relative_url_root = nil) ⇒ Object
Constructor Details
#initialize(asset, request) ⇒ AssetResponse
Returns a new instance of AssetResponse.
5 6 7 8 9 10 11 |
# File 'lib/ckeditor/asset_response.rb', line 5 def initialize(asset, request) @asset = asset @request = request @params = request.params @asset.data = Ckeditor::Http.normalize_param(file, @request) end |
Instance Attribute Details
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
3 4 5 |
# File 'lib/ckeditor/asset_response.rb', line 3 def asset @asset end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/ckeditor/asset_response.rb', line 3 def params @params end |
Instance Method Details
#ckeditor? ⇒ Boolean
17 18 19 |
# File 'lib/ckeditor/asset_response.rb', line 17 def ckeditor? !params[:CKEditor].blank? end |
#errors ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ckeditor/asset_response.rb', line 43 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..first)}'); </script>" } else {nothing: true, format: :json} end end |
#file ⇒ Object
21 22 23 |
# File 'lib/ckeditor/asset_response.rb', line 21 def file !(ckeditor? || json?) ? params[:qqfile] : params[:upload] end |
#json? ⇒ Boolean
13 14 15 |
# File 'lib/ckeditor/asset_response.rb', line 13 def json? params[:responseType] == 'json' end |
#success(relative_url_root = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ckeditor/asset_response.rb', line 25 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 |