rails-uploader 0.5.3 → 0.5.6

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
  SHA256:
3
- metadata.gz: e05f5c580e91d0d0b2702ad285f746f97afeffefd8c114088b96136bde737f8d
4
- data.tar.gz: 9b7f11b41d7dc7ec839e570a1889e140f09b0866231fc8a5d4dfe545b1e5ed54
3
+ metadata.gz: 34cf4f5470bf2a9ab6e3758b81ece72f0197deb58beabc92bbffe5145bfa3b93
4
+ data.tar.gz: f0a17d1ee3751d67a1359b3078e468e4c213612d3cd17babfb274b3aaeb3717d
5
5
  SHA512:
6
- metadata.gz: 9c0f890979f7ae8a766d6a2957a86c390ffa65413e90aaa5d996399728eab61e8398ccab92303010442154c2da261f6123571847f2e7688e110c3c5d657ea5d3
7
- data.tar.gz: 3ee71e85c530ca477922d7d591ce5e2bad65c864b3fbd9535acf069d092ccb06c7ee109fa25583f72bebb26e8acd269bd62ea69dd49298f50f6e9216306dc54d
6
+ metadata.gz: 7aa4ad3a15cde45c9e7221bc458fb36a190b42ba23be7baab13b180e62ae2fe015590ec1eae5b0cb2f91ddf546a3fdae59b1a434b31870570005de2aa1d5868a
7
+ data.tar.gz: 9300908ab201f4763f13843cd3ed4508ebd6caac99156ee68fd38ece251cbd0c120e59d40657ec0e6ecfb1db7b5dbdf259d7541591512d6cabcd1b095904b06d
@@ -0,0 +1,87 @@
1
+ (function() {
2
+ var $, UploaderWidget;
3
+
4
+ $ = jQuery;
5
+
6
+ $.fn.uploaderWidget = function(options) {
7
+ if (options == null) {
8
+ options = {};
9
+ }
10
+ return this.each(function() {
11
+ var $this, data;
12
+ $this = $(this);
13
+ data = $this.data('uploaderWidget');
14
+ if (!data) {
15
+ $this.data('uploaderWidget', new UploaderWidget(this, options));
16
+ }
17
+ if (typeof options === 'string') {
18
+ return data[options]();
19
+ }
20
+ });
21
+ };
22
+
23
+ UploaderWidget = (function() {
24
+ function UploaderWidget(dom_id, options) {
25
+ var defaults;
26
+ this.dom_id = dom_id;
27
+ if (options == null) {
28
+ options = {};
29
+ }
30
+ defaults = {
31
+ dataType: 'json',
32
+ autoUpload: true,
33
+ paramName: 'asset[data]',
34
+ formData: function(form) {
35
+ return [];
36
+ },
37
+ namespace: 'uploader',
38
+ uploadTemplateId: 'template-upload-',
39
+ downloadTemplateId: 'template-download-'
40
+ };
41
+ this.options = $.extend(defaults, options);
42
+ this._setup();
43
+ }
44
+
45
+ UploaderWidget.prototype._setup = function() {
46
+ this.element = $(this.dom_id);
47
+ this.container = this.element.find('.uploader-files');
48
+ this.template = this.element.data('tpml');
49
+ this.input = this.element.find('input[type="file"]:eq(0)');
50
+ this.options['dropZone'] = this.element;
51
+ this.options['filesContainer'] = this.container;
52
+ this.options['uploadTemplateId'] += this.template;
53
+ this.options['downloadTemplateId'] += this.template;
54
+ this.options.singular = !this.input.prop('multiple');
55
+ return this._initFileupload();
56
+ };
57
+
58
+ UploaderWidget.prototype._initFileupload = function() {
59
+ this.input.fileupload(this.options);
60
+ this.uploader = this.input.data('blueimp-fileupload') || this.input.data('fileupload');
61
+ if (this.element.data('exists')) {
62
+ return this._load();
63
+ }
64
+ };
65
+
66
+ UploaderWidget.prototype._load = function() {
67
+ return $.ajax({
68
+ url: this.input.data('url'),
69
+ dataType: 'json',
70
+ method: 'GET',
71
+ success: (function(_this) {
72
+ return function(data) {
73
+ if (data['files'] != null) {
74
+ return _this.render(data['files']);
75
+ }
76
+ };
77
+ })(this)
78
+ });
79
+ };
80
+
81
+ UploaderWidget.prototype.render = function(files) {
82
+ return this.uploader._renderDownload(files).appendTo(this.container);
83
+ };
84
+
85
+ return UploaderWidget;
86
+ })();
87
+ }).call(this);
@@ -51,7 +51,7 @@ module Uploader
51
51
  #
52
52
  def fileupload_create(params, _request = nil)
53
53
  self[Uploader.guid_column] = params[:guid]
54
- return false unless update_attributes(self.class.fileupload_assetable_options(params))
54
+ return false unless update(self.class.fileupload_assetable_options(params))
55
55
 
56
56
  if fileupload_destroy_other_on_singular?(params)
57
57
  self.class.fileupload_find_assets(params).where.not(id: id).destroy_all
@@ -76,7 +76,7 @@ module Uploader
76
76
  @input_html ||= { multiple: multiple?, class: 'uploader' }.merge(input_html_options)
77
77
  @input_html[:data] ||= {}
78
78
  @input_html[:data][:url] ||= attachments_path(singular: !multiple?)
79
- @input_html[:accept] ||= extension_whitelist
79
+ @input_html[:accept] ||= extract_extension_whitelist
80
80
  @input_html
81
81
  end
82
82
 
@@ -84,7 +84,8 @@ module Uploader
84
84
  @options.reject { |key, _value| RESERVED_OPTIONS_KEYS.include?(key.to_s) }
85
85
  end
86
86
 
87
- def extension_whitelist
87
+ def extract_extension_whitelist
88
+ return unless klass.respond_to?(:uploaders)
88
89
  return unless klass.uploaders[:data].try(:const_defined?, :EXTENSION_WHITELIST)
89
90
 
90
91
  exts = klass.uploaders[:data]::EXTENSION_WHITELIST
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uploader
4
- VERSION = '0.5.3'
4
+ VERSION = '0.5.6'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-uploader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Galeta
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-04-09 00:00:00.000000000 Z
12
+ date: 2022-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: carrierwave
@@ -64,7 +64,7 @@ files:
64
64
  - README.md
65
65
  - Rakefile
66
66
  - app/assets/javascripts/uploader/application.js
67
- - app/assets/javascripts/uploader/jquery.uploader.js.coffee
67
+ - app/assets/javascripts/uploader/jquery.uploader.js
68
68
  - app/assets/stylesheets/uploader/application.css
69
69
  - app/controllers/uploader/attachments_controller.rb
70
70
  - app/views/uploader/default/_container.html.erb
@@ -1,59 +0,0 @@
1
- $ = jQuery
2
-
3
- $.fn.uploaderWidget = (options = {}) ->
4
- @each ->
5
- $this = $(this)
6
- data = $this.data('uploaderWidget')
7
- if (!data)
8
- $this.data('uploaderWidget', new UploaderWidget(this, options))
9
- if (typeof options is 'string')
10
- data[options]()
11
-
12
- class UploaderWidget
13
- constructor: (@dom_id, options = {}) ->
14
- defaults =
15
- dataType: 'json'
16
- autoUpload: true
17
- paramName: 'asset[data]'
18
- formData: (form) -> return []
19
- namespace: 'uploader'
20
- uploadTemplateId: 'template-upload-'
21
- downloadTemplateId: 'template-download-'
22
-
23
- @options = $.extend defaults, options
24
-
25
- this._setup()
26
-
27
- _setup: ->
28
- @element = $(@dom_id)
29
- @container = @element.find('.uploader-files')
30
- @template = @element.data('tpml')
31
- @input = @element.find('input[type="file"]:eq(0)')
32
-
33
- @options['dropZone'] = @element
34
- @options['filesContainer'] = @container
35
- @options['uploadTemplateId'] += @template
36
- @options['downloadTemplateId'] += @template
37
- @options.singular = !@input.prop('multiple')
38
-
39
- this._initFileupload()
40
-
41
- _initFileupload: ->
42
- @input.fileupload(@options)
43
-
44
- @uploader = (@input.data('blueimp-fileupload') || @input.data('fileupload'))
45
-
46
- this._load() if @element.data('exists')
47
-
48
- _load: ->
49
- $.ajax(
50
- url: @input.data('url')
51
- dataType: 'json'
52
- method: 'GET'
53
- success: (data) =>
54
- if data['files']?
55
- this.render(data['files'])
56
- )
57
-
58
- render: (files) ->
59
- @uploader._renderDownload(files).appendTo(@container)