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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 338e2b3e26b23d7481e436f48478f05b4b257307
4
- data.tar.gz: 509e356566d12ed77242b056edb3ff4036174617
3
+ metadata.gz: 87a6f6401edd7c55d0aa347839beb7ba6106993a
4
+ data.tar.gz: 58cadda3b992b35a2da0328d48f499b595a6ce71
5
5
  SHA512:
6
- metadata.gz: 644cb48ae756bd9a60f7769541d5754f58ef38ef76c75edac8b965c0749b30c56ad59ca7cf3b36e1f55be01bf659aec777f79ce505a9903a53b704ef13345163
7
- data.tar.gz: 2b64d8c73880b83cc632876762883dad9483b347ce983b0185d284e632ba9d7fe0ee5d6a0c70946222f7807555471d099d6b0edbb08f81994a585cf6292000bd
6
+ metadata.gz: 1e49b2e00464091644fd9d07d7b480272c2d3784e76a05e1af58e66f9dcb2c3cf35b5f57d5f7d65f9c12a4eab80ce2832c22624a28d88034e6ff79226df22a5a
7
+ data.tar.gz: 86a63f89a84bfd88b29ecfdc74a73167f217aac362399becfb3eec43527ba14f031842405b6c0ce81386ed6b6ddfb4fd3e9811afb04c1185bdde48f35187851e
@@ -42,6 +42,7 @@ if window.FileReader
42
42
  xhr.responseType = "blob"
43
43
  xhr.onload = ()->
44
44
  _blob = xhr.response
45
+ alert(_blob)
45
46
  if _blob != null
46
47
  dropzone.addFile(_blob)
47
48
  xhr.send()
@@ -9,14 +9,14 @@
9
9
  ruby:
10
10
  if f.is_a?(Hash)
11
11
  next if f.empty?
12
- embedded_field = f.keys.first
13
- embedded_model_upload_field = f.values.first
14
- embedded_model_upload_field = embedded_model_upload_field.last if embedded_model_upload_field.is_a?(Array)
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}.#{embedded_field}.#{embedded_model_upload_field}"
17
- i18n_path_default = "rails_admin.multiple_file_upload.#{@object.class.name.tableize}.#{embedded_field}"
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_#{embedded_field}_#{embedded_model_upload_field}"
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
- - embedded_field = f.keys.first
37
- - embedded_model_upload_field = f.values.first
36
+ - child_field = f.keys.first
37
+ - child_model_upload_field = f.values.first
38
38
  - else
39
- - embedded_field = f
40
- - embedded_model_upload_field = "image"
39
+ - child_field = f
40
+ - child_model_upload_field = "image"
41
41
 
42
- - embedded_objects = @object.send(embedded_field)
43
- - embedded_model_ordered_scope = ""
44
- - if embedded_objects.respond_to?("sorted")
45
- - embedded_model_ordered_scope = "sorted"
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 embedded_objects.respond_to?("ordered") and embedded_model_ordered_scope.blank?
48
- - embedded_model_ordered_scope = "ordered"
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_#{embedded_field}_#{embedded_model_upload_field}"}
50
+ .tab-pane{id="multiple_file_upload_#{child_field}_#{child_model_upload_field}"}
51
51
  .row-fluid
52
- - block_id = "rails_admin_multiple_upload_#{embedded_field}_#{embedded_model_upload_field}"
53
- - button_id = "rails_admin_multiple_upload_#{embedded_field}_#{embedded_model_upload_field}_button"
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 embedded_objects.send(embedded_model_ordered_scope).to_a, {embedded_field: embedded_field, embedded_model_upload_field: embedded_model_upload_field}
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: "#{embedded_field}[#{embedded_model_upload_field}]",
60
+ paramName: "#{child_field}[#{child_model_upload_field}]",
61
61
  autoProcessQueue: false,
62
62
  addRemoveLinks: true
63
63
  });
@@ -5,5 +5,6 @@ ru:
5
5
  menu: "Загрузка файлов"
6
6
  breadcrumb: "Загрузка файлов"
7
7
  error: "Ошибка"
8
+ save_error: "Ошибка при сохранении"
8
9
  success: "Успешно"
9
- title: "Загрузка файлов"
10
+ title: "Загрузка файлов"
@@ -34,24 +34,25 @@ module RailsAdmin
34
34
 
35
35
  elsif request.post?
36
36
  begin
37
- embedded_model = params[:embedded_model].to_s
38
- embedded_field = params[:embedded_field].to_s
37
+ child_model = params[:child_model].to_s
38
+ child_field = params[:child_field].to_s
39
39
 
40
- embedded_model_upload_field = params[:embedded_model_upload_field].to_s
41
- embedded_model_upload_field = "image" if embedded_model_upload_field.blank?
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
- if params[embedded_field][embedded_model_upload_field].original_filename == "undefined"
44
- ext = params[embedded_field][embedded_model_upload_field].content_type.split("/").last
45
- params[embedded_field][embedded_model_upload_field].original_filename = "#{Time.new.to_f*1_000_000}.#{ext}"
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
- embedded = main_obj.send(embedded_field).new
50
- embedded.send(embedded_model_upload_field + "=", params[embedded_field][embedded_model_upload_field])
51
- if embedded.save
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.error')}</strong>: #{embedded.errors.full_messages}"
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
- files = files.to_a.sort_by { |m| m.send(opts[:embedded_model_order_field] || "order").to_i }
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
- embedded_field: opts[:embedded_field],
9
- embedded_model_upload_field: opts[:embedded_model_upload_field] || "image",
10
- embedded_model: @abstract_model.model.new.send(opts[:embedded_field]).new.class.to_s
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[:embedded_field]).sorted.each do |ef|
31
+ @object.send(config[:child_field]).sorted.each do |ef|
19
32
  if multiple_file_upload_paperclip?
20
- if ef.send(config[:embedded_model_upload_field] + "_content_type") =~ /\Aimage/
21
- file_url = ef.send(config[:embedded_model_upload_field]).url(multiple_file_upload_thumbnail_size)
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[:embedded_model_upload_field] + "_file_name")
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(:embedded_field, config[:embedded_field])
39
- _ret << hidden_field_tag(:embedded_model_upload_field, config[:embedded_model_upload_field])
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[:embedded_field] do |ef|
42
- # @object.send(config[:embedded_field]).each do |field|
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
@@ -2,7 +2,7 @@ module RailsAdmin
2
2
  module Config
3
3
  class Model
4
4
  register_instance_option :multiple_file_upload do
5
- nil
5
+ {}
6
6
  end
7
7
  end
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module RailsAdminMultipleFileUpload
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,7 +1,3 @@
1
- module RailsAdminMultipleFileUpload
2
-
3
- end
4
-
5
1
  require "rails_admin_multiple_file_upload/version"
6
2
  require 'rails_admin_multiple_file_upload/engine'
7
3
 
@@ -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.3.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-03-01 00:00:00.000000000 Z
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: '0'
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: '0'
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: '0'
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: '0'
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