activeadmin_jfu_upload 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,12 @@
1
+ body.active_admin form
2
+ .jfu_upload_wrapper
3
+ border: 1px dashed #aaa
4
+ display: inline-block
5
+ width: calc(80% - 22px)
6
+ ul
7
+ padding: 0 10px
8
+ li
9
+ padding-bottom: 5px
10
+ .jfu_upload_input
11
+ padding: 10px
12
+ width: 100%
@@ -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,5 @@
1
+ module ActiveAdmin
2
+ module JfuUpload
3
+ VERSION = '0.1.1'
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'activeadmin/jfu_upload'
2
+
3
+ require 'formtastic/inputs/jfu_upload_input'
@@ -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.0
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