glebtv-rails-uploader 0.0.8 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -10
- data/app/assets/javascripts/uploader/rails_admin.js +4 -4
- data/app/controllers/uploader/attachments_controller.rb +12 -3
- data/app/views/uploader/default/_container.html.erb +1 -0
- data/lib/file_size_validator.rb +1 -1
- data/lib/uploader/asset.rb +1 -1
- data/lib/uploader/fileuploads.rb +1 -1
- data/lib/uploader/helpers/field_tag.rb +1 -1
- data/lib/uploader/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -25,6 +25,9 @@ a little howto for mongoid / carrierwave:
|
|
25
25
|
# DO NOT add this!
|
26
26
|
# belongs_to :post
|
27
27
|
|
28
|
+
# optional built-in sorting for rails_admin
|
29
|
+
field :sort, type: Integer
|
30
|
+
|
28
31
|
# field name must be 'data'
|
29
32
|
mount_uploader :data, CoverUploader
|
30
33
|
|
@@ -50,6 +53,9 @@ a little howto for mongoid / carrierwave:
|
|
50
53
|
# models/post.rb
|
51
54
|
class Post
|
52
55
|
include Mongoid::Document
|
56
|
+
|
57
|
+
field :fileupload_guid, type: String
|
58
|
+
|
53
59
|
include Uploader::Fileuploads
|
54
60
|
has_one :cover, as: :assetable
|
55
61
|
fileuploads :cover
|
@@ -60,16 +66,6 @@ a little howto for mongoid / carrierwave:
|
|
60
66
|
|
61
67
|
```ruby
|
62
68
|
class Album
|
63
|
-
# optional built-in sorting for rails_admin
|
64
|
-
def sort_assets!(order)
|
65
|
-
pos = 0
|
66
|
-
order.each do |pic_id|
|
67
|
-
pic = self.pictures.find(pic_id)
|
68
|
-
pic.sort = (pos+=1)
|
69
|
-
pic.save!
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
69
|
has_many :pictures, as: :assetable, dependent: :destroy
|
74
70
|
fileuploads :pictures
|
75
71
|
|
@@ -78,6 +74,7 @@ class Album
|
|
78
74
|
rails_admin do
|
79
75
|
edit do
|
80
76
|
...
|
77
|
+
field :fileupload_guid, :hidden # this is needed or else rails_admin sanitizes it away
|
81
78
|
field :pictures, :rails_uploader
|
82
79
|
end
|
83
80
|
end
|
@@ -110,6 +107,7 @@ end
|
|
110
107
|
rails_admin do
|
111
108
|
edit do
|
112
109
|
...
|
110
|
+
field :fileupload_guid, :hidden # this is needed or else rails_admin sanitizes it away
|
113
111
|
field :pictures, :rails_uploader
|
114
112
|
end
|
115
113
|
end
|
@@ -5,9 +5,7 @@
|
|
5
5
|
//= require uploader/jquery.fileupload
|
6
6
|
//= require uploader/jquery.fileupload-ui
|
7
7
|
|
8
|
-
$('.
|
9
|
-
|
10
|
-
$('.uploader-files').each(function() {
|
8
|
+
$(document).off('init.sort').on('init.sort', '.uploader-files', function() {
|
11
9
|
var $t = $(this);
|
12
10
|
$t.sortable({
|
13
11
|
update: function(event, ui) {
|
@@ -22,4 +20,6 @@ $('.uploader-files').each(function() {
|
|
22
20
|
})
|
23
21
|
}
|
24
22
|
})
|
25
|
-
});
|
23
|
+
});
|
24
|
+
|
25
|
+
$('.uploader-dnd-area input[type=file]').trigger("init.uploader");
|
@@ -19,10 +19,19 @@ module Uploader
|
|
19
19
|
|
20
20
|
def sort
|
21
21
|
@model = params[:assetable_type].safe_constantize
|
22
|
-
@object = @model.find(params[:assetable_id])
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
sort = params[:sort].split('|')
|
24
|
+
if params[:assetable_id].blank?
|
25
|
+
@finder = @klass.where(guid: params[:guid])
|
26
|
+
else
|
27
|
+
@finder = @klass.where(assetable_id: params[:assetable_id])
|
28
|
+
end
|
29
|
+
|
30
|
+
@finder.each do |asset|
|
31
|
+
if asset.respond_to?(:sort=)
|
32
|
+
asset.sort = sort.index(asset.id.to_s)
|
33
|
+
asset.save!
|
34
|
+
end
|
26
35
|
end
|
27
36
|
|
28
37
|
self.status = 200
|
data/lib/file_size_validator.rb
CHANGED
data/lib/uploader/asset.rb
CHANGED
@@ -15,7 +15,7 @@ module Uploader
|
|
15
15
|
def uploader_create(params, request = nil)
|
16
16
|
self.guid = params[:guid]
|
17
17
|
self.assetable_type = params[:assetable_type]
|
18
|
-
if self.class.respond_to?(:collection)
|
18
|
+
if self.class.respond_to?(:collection) && !params[:assetable_id].blank?
|
19
19
|
self.assetable_id = Moped::BSON::ObjectId.from_string(params[:assetable_id])
|
20
20
|
else
|
21
21
|
self.assetable_id = params[:assetable_id]
|
data/lib/uploader/fileuploads.rb
CHANGED
@@ -27,7 +27,7 @@ module Uploader
|
|
27
27
|
unless self.is_a?(ClassMethods)
|
28
28
|
include InstanceMethods
|
29
29
|
extend ClassMethods
|
30
|
-
|
30
|
+
|
31
31
|
after_save :fileuploads_update, :if => :fileupload_changed?
|
32
32
|
|
33
33
|
fileuploads_columns.each { |asset| accepts_nested_attributes_for asset, :allow_destroy => true }
|
data/lib/uploader/version.rb
CHANGED