rails_admin_multiple_file_upload 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/rails_admin/rails_admin_multiple_file_upload.coffee +1 -0
- data/app/views/rails_admin/main/multiple_file_upload.html.slim +21 -21
- data/config/locales/ru.rails_admin_multiple_file_upload.yml +2 -1
- data/lib/rails_admin_multiple_file_upload/action.rb +12 -11
- data/lib/rails_admin_multiple_file_upload/helper.rb +25 -12
- data/lib/rails_admin_multiple_file_upload/model.rb +1 -1
- data/lib/rails_admin_multiple_file_upload/version.rb +1 -1
- data/lib/rails_admin_multiple_file_upload.rb +0 -4
- data/rails_admin_multiple_file_upload.gemspec +2 -2
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87a6f6401edd7c55d0aa347839beb7ba6106993a
|
4
|
+
data.tar.gz: 58cadda3b992b35a2da0328d48f499b595a6ce71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e49b2e00464091644fd9d07d7b480272c2d3784e76a05e1af58e66f9dcb2c3cf35b5f57d5f7d65f9c12a4eab80ce2832c22624a28d88034e6ff79226df22a5a
|
7
|
+
data.tar.gz: 86a63f89a84bfd88b29ecfdc74a73167f217aac362399becfb3eec43527ba14f031842405b6c0ce81386ed6b6ddfb4fd3e9811afb04c1185bdde48f35187851e
|
@@ -9,14 +9,14 @@
|
|
9
9
|
ruby:
|
10
10
|
if f.is_a?(Hash)
|
11
11
|
next if f.empty?
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
child_field = f.keys.first
|
13
|
+
child_model_upload_field = f.values.first
|
14
|
+
child_model_upload_field = child_model_upload_field.last if child_model_upload_field.is_a?(Array)
|
15
15
|
|
16
|
-
i18n_path = "rails_admin.multiple_file_upload.#{@object.class.name.tableize}.#{
|
17
|
-
i18n_path_default = "rails_admin.multiple_file_upload.#{@object.class.name.tableize}.#{
|
16
|
+
i18n_path = "rails_admin.multiple_file_upload.#{@object.class.name.tableize}.#{child_field}.#{child_model_upload_field}"
|
17
|
+
i18n_path_default = "rails_admin.multiple_file_upload.#{@object.class.name.tableize}.#{child_field}"
|
18
18
|
|
19
|
-
link = "#multiple_file_upload_#{
|
19
|
+
link = "#multiple_file_upload_#{child_field}_#{child_model_upload_field}"
|
20
20
|
title = I18n.t(i18n_path, default: I18n.t(i18n_path_default))
|
21
21
|
|
22
22
|
else
|
@@ -33,31 +33,31 @@
|
|
33
33
|
- multiple_file_upload_fields.each do |f|
|
34
34
|
- if f.is_a?(Hash)
|
35
35
|
- next if f.empty?
|
36
|
-
-
|
37
|
-
-
|
36
|
+
- child_field = f.keys.first
|
37
|
+
- child_model_upload_field = f.values.first
|
38
38
|
- else
|
39
|
-
-
|
40
|
-
-
|
39
|
+
- child_field = f
|
40
|
+
- child_model_upload_field = "image"
|
41
41
|
|
42
|
-
-
|
43
|
-
-
|
44
|
-
- if
|
45
|
-
-
|
42
|
+
- child_objects = @object.send(child_field)
|
43
|
+
- child_model_ordered_scope = ""
|
44
|
+
- if child_objects.respond_to?("sorted")
|
45
|
+
- child_model_ordered_scope = "sorted"
|
46
46
|
|
47
|
-
- if
|
48
|
-
-
|
47
|
+
- if child_objects.respond_to?("ordered") and child_model_ordered_scope.blank?
|
48
|
+
- child_model_ordered_scope = "ordered"
|
49
49
|
|
50
|
-
.tab-pane{id="multiple_file_upload_#{
|
50
|
+
.tab-pane{id="multiple_file_upload_#{child_field}_#{child_model_upload_field}"}
|
51
51
|
.row-fluid
|
52
|
-
- block_id = "rails_admin_multiple_upload_#{
|
53
|
-
- button_id = "rails_admin_multiple_upload_#{
|
52
|
+
- block_id = "rails_admin_multiple_upload_#{child_field}_#{child_model_upload_field}"
|
53
|
+
- button_id = "rails_admin_multiple_upload_#{child_field}_#{child_model_upload_field}_button"
|
54
54
|
.span12.rails_admin_multiple_upload{id="#{block_id}"}
|
55
|
-
= rails_admin_multiple_file_upload
|
55
|
+
= rails_admin_multiple_file_upload child_objects.send(child_model_ordered_scope).to_a, {child_field: child_field, child_model_upload_field: child_model_upload_field}
|
56
56
|
|
57
57
|
= button_tag "Загрузить", id: button_id
|
58
58
|
javascript:
|
59
59
|
$("##{block_id} .dropzone").dropzone({
|
60
|
-
paramName: "#{
|
60
|
+
paramName: "#{child_field}[#{child_model_upload_field}]",
|
61
61
|
autoProcessQueue: false,
|
62
62
|
addRemoveLinks: true
|
63
63
|
});
|
@@ -34,24 +34,25 @@ module RailsAdmin
|
|
34
34
|
|
35
35
|
elsif request.post?
|
36
36
|
begin
|
37
|
-
|
38
|
-
|
37
|
+
child_model = params[:child_model].to_s
|
38
|
+
child_field = params[:child_field].to_s
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
child_model_upload_field = params[:child_model_upload_field].to_s
|
41
|
+
child_model_upload_field = "image" if child_model_upload_field.blank?
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
_file = params[child_field][child_model_upload_field]
|
44
|
+
if ["undefined", "blob", '', nil].include?(_file.original_filename)
|
45
|
+
ext = _file.content_type.split("/").last
|
46
|
+
_file.original_filename = "#{(Time.new.to_f*1_000_000).to_i}.#{ext}"
|
46
47
|
end
|
47
48
|
|
48
49
|
main_obj = @object
|
49
|
-
|
50
|
-
|
51
|
-
if
|
50
|
+
child = main_obj.send(child_field).new
|
51
|
+
child.send(child_model_upload_field + "=", params[child_field][child_model_upload_field])
|
52
|
+
if child.save
|
52
53
|
message = "<strong>#{I18n.t('admin.actions.multiple_file_upload.success')}!</strong>"
|
53
54
|
else
|
54
|
-
message = "<strong>#{I18n.t('admin.actions.multiple_file_upload.
|
55
|
+
message = "<strong>#{I18n.t('admin.actions.multiple_file_upload.save_error')}</strong>: #{child.errors.full_messages}"
|
55
56
|
end
|
56
57
|
|
57
58
|
rescue Exception => e
|
@@ -1,13 +1,26 @@
|
|
1
1
|
module RailsAdminMultipleFileUpload
|
2
2
|
module Helper
|
3
3
|
def rails_admin_multiple_file_upload(files, opts= {})
|
4
|
-
|
4
|
+
# backward compatibility
|
5
|
+
opts[:child_field] ||= opts[:embedded_field]
|
6
|
+
opts[:child_model_order_field] ||= opts[:embedded_model_order_field]
|
7
|
+
opts[:child_model_upload_field] ||= opts[:embedded_model_upload_field]
|
8
|
+
|
9
|
+
files = files.to_a.sort_by do |m|
|
10
|
+
_meth = opts[:child_model_order_field]
|
11
|
+
_meth = "order" if _meth.blank?
|
12
|
+
_meth = "sort" unless m.respond_to?(_meth)
|
13
|
+
_meth = "lft" unless m.respond_to?(_meth)
|
14
|
+
if _meth and m.respond_to?(_meth)
|
15
|
+
m.send(_meth).to_i
|
16
|
+
end
|
17
|
+
end
|
5
18
|
id = "ns_#{rand(100_000_000..999_999_999)}"
|
6
19
|
config = {
|
7
20
|
update_url: multiple_file_upload_path(model_name: @abstract_model),
|
8
|
-
|
9
|
-
|
10
|
-
|
21
|
+
child_field: opts[:child_field],
|
22
|
+
child_model_upload_field: opts[:child_model_upload_field] || "image",
|
23
|
+
child_model: @abstract_model.model.new.send(opts[:child_field]).new.class.name
|
11
24
|
}
|
12
25
|
content_tag(:div, rails_admin_multiple_file_upload_builder(files, config), id: id, class: 'rails_admin_multiple_file_upload')
|
13
26
|
end
|
@@ -15,17 +28,17 @@ module RailsAdminMultipleFileUpload
|
|
15
28
|
def rails_admin_multiple_file_upload_builder(files, config)
|
16
29
|
ret = []
|
17
30
|
_ret = []
|
18
|
-
@object.send(config[:
|
31
|
+
@object.send(config[:child_field]).sorted.each do |ef|
|
19
32
|
if multiple_file_upload_paperclip?
|
20
|
-
if ef.send(config[:
|
21
|
-
file_url = ef.send(config[:
|
33
|
+
if ef.send(config[:child_model_upload_field] + "_content_type") =~ /\Aimage/
|
34
|
+
file_url = ef.send(config[:child_model_upload_field]).url(multiple_file_upload_thumbnail_size)
|
22
35
|
_ret << content_tag(:span, image_tag(file_url), class: "file_block_load_already")
|
23
36
|
|
24
37
|
else
|
25
38
|
if ef.respond_to?(:name)
|
26
39
|
file_name = ef.name
|
27
40
|
else
|
28
|
-
file_name = ef.send(config[:
|
41
|
+
file_name = ef.send(config[:child_model_upload_field] + "_file_name")
|
29
42
|
end
|
30
43
|
_ret << content_tag(:span, link_to(ef.name), class: "file_block_load_already")
|
31
44
|
end
|
@@ -35,11 +48,11 @@ module RailsAdminMultipleFileUpload
|
|
35
48
|
ret << content_tag(:div, "", class: "clearfix")
|
36
49
|
ret << rails_admin_form_for(@object, url: config[:update_url], html: {method: :post, multipart: true, class: "form-horizontal denser dropzone"})do |f|
|
37
50
|
_ret = []
|
38
|
-
_ret << hidden_field_tag(:
|
39
|
-
_ret << hidden_field_tag(:
|
51
|
+
_ret << hidden_field_tag(:child_field, config[:child_field])
|
52
|
+
_ret << hidden_field_tag(:child_model_upload_field, config[:child_model_upload_field])
|
40
53
|
_ret.join.html_safe
|
41
|
-
# f.fields_for config[:
|
42
|
-
# @object.send(config[:
|
54
|
+
# f.fields_for config[:child_field] do |ef|
|
55
|
+
# @object.send(config[:child_field]).each do |field|
|
43
56
|
# ef.input_for field
|
44
57
|
# end
|
45
58
|
# end
|
@@ -20,6 +20,6 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.add_development_dependency "bundler", "~> 1.10"
|
21
21
|
gem.add_development_dependency "rake", "~> 10.0"
|
22
22
|
|
23
|
-
gem.add_dependency "rails_admin"
|
24
|
-
gem.add_dependency 'dropzonejs-rails'
|
23
|
+
gem.add_dependency "rails_admin", "~> 0.8.1"
|
24
|
+
gem.add_dependency 'dropzonejs-rails', "~> 0.7.3"
|
25
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_admin_multiple_file_upload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kiseliev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,30 +42,30 @@ dependencies:
|
|
42
42
|
name: rails_admin
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.8.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.8.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: dropzonejs-rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.7.3
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.7.3
|
69
69
|
description: Rails admin multiple file upload with AJAX and DnD
|
70
70
|
email:
|
71
71
|
- i43ack@gmail.com
|