activeadmin_jfu_upload 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +69 -0
- data/Rakefile +3 -0
- data/activeadmin_jfu_upload.gemspec +19 -0
- data/app/assets/javascripts/activeadmin/jfu_upload/jquery.fileupload.js +1486 -0
- data/app/assets/javascripts/activeadmin/jfu_upload_input.js +14 -0
- data/app/assets/stylesheets/activeadmin/_jfu_upload_input.sass +12 -0
- data/lib/activeadmin/jfu_upload.rb +1 -0
- data/lib/activeadmin/jfu_upload/engine.rb +37 -0
- data/lib/activeadmin/jfu_upload/version.rb +5 -0
- data/lib/activeadmin_jfu_upload.rb +3 -0
- data/lib/formtastic/inputs/jfu_upload_input.rb +19 -0
- metadata +16 -2
@@ -0,0 +1,14 @@
|
|
1
|
+
$(document).ready( function() {
|
2
|
+
$('.jfu_upload_input').each(function () {
|
3
|
+
var options = {
|
4
|
+
dataType: 'json',
|
5
|
+
done: function (e, data) {
|
6
|
+
if( data.result.result == 1 ) {
|
7
|
+
$(e.target).next().html('<li class="jfu_file">' + data.result.file_name + '</li>');
|
8
|
+
}
|
9
|
+
}
|
10
|
+
};
|
11
|
+
options = $.extend({}, options, $(this).data('options'));
|
12
|
+
$(this).fileupload(options);
|
13
|
+
});
|
14
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'activeadmin/jfu_upload/engine'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'active_admin'
|
2
|
+
|
3
|
+
module ActiveAdmin
|
4
|
+
module JfuUpload
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
engine_name 'activeadmin_jfu_upload'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def upload_file( request, param, resource, field )
|
10
|
+
response = { result: 0 }
|
11
|
+
if !param.blank?
|
12
|
+
if request.headers['CONTENT-RANGE'].blank?
|
13
|
+
resource.update field => param
|
14
|
+
response = { result: 1, file_name: resource.try( field ).try( :url ) }
|
15
|
+
else
|
16
|
+
m = request.headers['CONTENT-RANGE'].match( /[^\s]+\s(\d+)-(\d+)\/(\d+)/ )
|
17
|
+
if m
|
18
|
+
pos = m[1].to_i
|
19
|
+
if pos == 0
|
20
|
+
resource.update field => param
|
21
|
+
else
|
22
|
+
File.open( resource.try( field ).try( :path ), 'ab' ) { |f| f.write( param.read ) }
|
23
|
+
end
|
24
|
+
if ( m[2].to_i + 1 ) == m[3].to_i
|
25
|
+
response = { result: 1, pos: m[3].to_i, file_name: resource.try( field ).try( :url ) }
|
26
|
+
else
|
27
|
+
response = { result: 2, position: pos }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
response
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Inputs
|
3
|
+
class JfuUploadInput < Formtastic::Inputs::FileInput
|
4
|
+
def input_html_options
|
5
|
+
super.merge( class: 'jfu_upload_input' )
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_html
|
9
|
+
input_wrapping do
|
10
|
+
label_html <<
|
11
|
+
template.content_tag( :div, { class: 'jfu_upload_wrapper' } ) do
|
12
|
+
builder.file_field( method, input_html_options ) <<
|
13
|
+
template.content_tag( :ul )
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_jfu_upload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
@@ -29,7 +29,21 @@ email: mat@blocknot.es
|
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
|
-
files:
|
32
|
+
files:
|
33
|
+
- ".gitignore"
|
34
|
+
- Gemfile
|
35
|
+
- LICENSE.txt
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- activeadmin_jfu_upload.gemspec
|
39
|
+
- app/assets/javascripts/activeadmin/jfu_upload/jquery.fileupload.js
|
40
|
+
- app/assets/javascripts/activeadmin/jfu_upload_input.js
|
41
|
+
- app/assets/stylesheets/activeadmin/_jfu_upload_input.sass
|
42
|
+
- lib/activeadmin/jfu_upload.rb
|
43
|
+
- lib/activeadmin/jfu_upload/engine.rb
|
44
|
+
- lib/activeadmin/jfu_upload/version.rb
|
45
|
+
- lib/activeadmin_jfu_upload.rb
|
46
|
+
- lib/formtastic/inputs/jfu_upload_input.rb
|
33
47
|
homepage: https://github.com/blocknotes/activeadmin_jfu_upload
|
34
48
|
licenses:
|
35
49
|
- MIT
|