rails-uploader 0.5.4 → 0.5.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 566c841fcb9d098a1b256c3aff94e01950cdbb0ace03d1c657e8d9fa3c114314
4
- data.tar.gz: 4ac9416e87c31176a81392e1a958fc90e65f3cc5c70d7faf72e37fdadcb21053
3
+ metadata.gz: 12397692cb77791fc651ff6ee848e3e9a376327eb531187a0bccb14d3208f18f
4
+ data.tar.gz: 013dd49aaca77295f886e66c1b8fc5e2d3ed86af4b0c027a2d645532c8e9dae4
5
5
  SHA512:
6
- metadata.gz: d535a4a9a2c9e40d24826c586f6ebf006934f3194f4600390e783659eadbe37955474b8430a1843ed8db6841afc13998cbaf46e2b935a88bc651fccf8806f33c
7
- data.tar.gz: 1ddd6948b2fd9c202b1a1bfeb9ce491964823bd7a3b861a33f2ad34b7c7e09fd6b452c1b5da312344ccdc9f9de1c6b8f8e42c45a2bcd40489f872f4fedf2e322
6
+ metadata.gz: c3f7ff5f6530a221a1d91dc55fd231d6d78baa63d3b6511ec2ef5c5aff46c10b9e1ef5d4068d4d314bd422ae6919f209a54bb48c7d6eeca1186333ed9a293058
7
+ data.tar.gz: f1d41d67e22055e0b6fe8cbb13fa86c9eabc4326c93b8ac53b86f03d88a9c6b62547d50813f3080280af66182708f68d5602a8bae2281856d8385e57dce4f753
@@ -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
@@ -1,14 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support/concern'
4
- require_relative 'json_rendering'
5
4
 
6
5
  module Uploader
7
6
  module Authorization
8
7
  extend ActiveSupport::Concern
9
8
 
10
9
  included do
11
- include JsonRendering
10
+ include Uploader::JsonRendering
12
11
  include ActionController::Rescue
13
12
 
14
13
  rescue_from Uploader::AccessDenied, with: :dispatch_uploader_access_denied
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uploader
4
- VERSION = '0.5.4'
4
+ VERSION = '0.5.7'
5
5
  end
data/lib/uploader.rb CHANGED
@@ -13,6 +13,7 @@ module Uploader
13
13
  autoload :UploadRequest, 'uploader/upload_request'
14
14
  autoload :FilePart, 'uploader/file_part'
15
15
  autoload :FileuploadGlue, 'uploader/fileupload_glue'
16
+ autoload :JsonRendering, 'uploader/json_rendering'
16
17
 
17
18
  # Just Rails helpers
18
19
  module Helpers
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.4
4
+ version: 0.5.7
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: 2022-01-19 00:00:00.000000000 Z
12
+ date: 2022-03-28 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)