assetable 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +181 -0
  4. data/Rakefile +23 -0
  5. data/app/assets/images/assetable/icon-upload.png +0 -0
  6. data/app/assets/images/assetable/icons/icon-ai.png +0 -0
  7. data/app/assets/images/assetable/icons/icon-css.png +0 -0
  8. data/app/assets/images/assetable/icons/icon-desmos.png +0 -0
  9. data/app/assets/images/assetable/icons/icon-doc.png +0 -0
  10. data/app/assets/images/assetable/icons/icon-document.png +0 -0
  11. data/app/assets/images/assetable/icons/icon-docx.png +0 -0
  12. data/app/assets/images/assetable/icons/icon-eps.png +0 -0
  13. data/app/assets/images/assetable/icons/icon-flash.png +0 -0
  14. data/app/assets/images/assetable/icons/icon-html.png +0 -0
  15. data/app/assets/images/assetable/icons/icon-jpg.png +0 -0
  16. data/app/assets/images/assetable/icons/icon-js.png +0 -0
  17. data/app/assets/images/assetable/icons/icon-mov.png +0 -0
  18. data/app/assets/images/assetable/icons/icon-mp3.png +0 -0
  19. data/app/assets/images/assetable/icons/icon-mp4.png +0 -0
  20. data/app/assets/images/assetable/icons/icon-pdf.png +0 -0
  21. data/app/assets/images/assetable/icons/icon-php.png +0 -0
  22. data/app/assets/images/assetable/icons/icon-png.png +0 -0
  23. data/app/assets/images/assetable/icons/icon-ppt.png +0 -0
  24. data/app/assets/images/assetable/icons/icon-pptx.png +0 -0
  25. data/app/assets/images/assetable/icons/icon-txt.png +0 -0
  26. data/app/assets/images/assetable/icons/icon-xls.png +0 -0
  27. data/app/assets/images/assetable/icons/icon-xlsx.png +0 -0
  28. data/app/assets/images/assetable/icons/icon-xml.png +0 -0
  29. data/app/assets/javascripts/assetable/asset_gallery.js.coffee +74 -0
  30. data/app/assets/javascripts/assetable/assetable_uploader.js.coffee +204 -0
  31. data/app/assets/javascripts/assetable/gallery.js.coffee +33 -0
  32. data/app/assets/javascripts/assetable/uploader.js.coffee +10 -0
  33. data/app/assets/javascripts/vendor/bootstrap-modal.js +246 -0
  34. data/app/assets/javascripts/vendor/jquery-ui-1.10.3.custom.js +2252 -0
  35. data/app/assets/stylesheets/assetable/_assetable.css.sass +9 -0
  36. data/app/assets/stylesheets/assetable/_bootstrap.css.sass +5 -0
  37. data/app/assets/stylesheets/assetable/components/_buttons.css.sass +99 -0
  38. data/app/assets/stylesheets/assetable/components/_close.css.sass +28 -0
  39. data/app/assets/stylesheets/assetable/components/_forms.css.sass +219 -0
  40. data/app/assets/stylesheets/assetable/components/_gallery.css.sass +118 -0
  41. data/app/assets/stylesheets/assetable/components/_modals.css.sass +116 -0
  42. data/app/assets/stylesheets/assetable/components/_progress.css.sass +91 -0
  43. data/app/assets/stylesheets/assetable/components/_uploader.css.sass +175 -0
  44. data/app/assets/stylesheets/assetable/core/_mixins.css.sass +754 -0
  45. data/app/assets/stylesheets/assetable/core/_utilities.css.sass +5 -0
  46. data/app/assets/stylesheets/assetable/core/_variables.css.sass +165 -0
  47. data/app/controllers/assetable/assets_controller.rb +38 -0
  48. data/app/controllers/assetable/external_services_controller.rb +36 -0
  49. data/app/models/asset.rb +53 -0
  50. data/app/models/asset_attachment.rb +4 -0
  51. data/app/models/document.rb +5 -0
  52. data/app/models/external_service.rb +14 -0
  53. data/app/models/gallery.rb +7 -0
  54. data/app/models/image.rb +5 -0
  55. data/app/models/video.rb +5 -0
  56. data/app/uploaders/document_uploader.rb +50 -0
  57. data/app/uploaders/image_uploader.rb +67 -0
  58. data/app/uploaders/video_uploader.rb +40 -0
  59. data/app/views/assetable/assets/_asset.html.haml +20 -0
  60. data/app/views/assetable/assets/_gallery.html.haml +12 -0
  61. data/app/views/assetable/external_services/new.html.haml +31 -0
  62. data/config/initializers/carrierwave.rb +6 -0
  63. data/config/initializers/gallery_input.rb +37 -0
  64. data/config/initializers/uploader_input.rb +80 -0
  65. data/config/routes.rb +8 -0
  66. data/db/migrate/20131122232735_create_assets.rb +19 -0
  67. data/db/migrate/20131123172825_create_asset_attachments.rb +15 -0
  68. data/db/migrate/20131125200943_create_galleries.rb +14 -0
  69. data/lib/assetable.rb +18 -0
  70. data/lib/assetable/config.rb +23 -0
  71. data/lib/assetable/core.rb +41 -0
  72. data/lib/assetable/engine.rb +15 -0
  73. data/lib/assetable/version.rb +3 -0
  74. data/lib/tasks/assetable_tasks.rake +4 -0
  75. data/test/fixtures/asset_attachments.yml +11 -0
  76. data/test/fixtures/assets.yml +11 -0
  77. data/test/fixtures/images.yml +11 -0
  78. data/test/fixtures/videos.yml +11 -0
  79. data/test/models/asset_attachment_test.rb +7 -0
  80. data/test/models/asset_test.rb +7 -0
  81. data/test/models/image_test.rb +7 -0
  82. data/test/models/video_test.rb +7 -0
  83. metadata +371 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDE0MDczY2NjOGI4Njk3MTZjNDMxMjAwNzFjMDhjYmQxNDUxY2JjMQ==
5
+ data.tar.gz: !binary |-
6
+ ZWU0OTBhNzFkNTJjOTczNzEyN2I3OTMwYjkxNWU2MmNhNDNjYmI5YQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YWNlOGVmMzU3M2NiZjhmOGIxMzg4N2Y5ZjYwYjNmOWIyYWFjNWU5ZjBlMmVm
10
+ NzUwZTNlMzkzNjI4MTRkMTVlMjljOWQ3YTI5ODkwYjk3ZmVlZDk2ZDg0MmM5
11
+ OWRmNzJiMTFhYzI4NDRiNjFmZjc3MDkxYTFkMmM1MjNkODFmYjA=
12
+ data.tar.gz: !binary |-
13
+ ODc2NTJjNjM3YzczYjY4ZDQ3M2Y1YTkwODdkMjhmNDM4YjhhYjg3MjU3N2U3
14
+ Y2E1ZDgzNWFmYWM0NDJmMWM4ZTg1ZGNhNTM4YzBlMWE0YjQzZjY1ZWQ1Y2Jk
15
+ NGY4NWE3MmI1ZWJhYzM3OWZlNTk4Mjk0ZWUxOTdjNjBiZGYyODQ=
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,181 @@
1
+ = Assetable
2
+
3
+ Easily add Assets to your Active Record models, including images, videos and almost any kind of documents. Includes an uploader, media gallery and much more.
4
+
5
+ === Installation
6
+
7
+ ==== Add the Gem
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'bootstrap_sass_rails'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bootstrap_sass_rails
20
+
21
+
22
+ ==== Migrations
23
+ Run the migrations
24
+
25
+ $ rake db:migrate
26
+
27
+
28
+ ==== Assets for the uploader and UI
29
+
30
+ Add the Stylesheet and Javascripts to your project:
31
+
32
+ # Sass syntax
33
+ @import assetable
34
+
35
+ # Assetable uses some of bootstrap's UI. You can import the partial bootstrap
36
+ # library to add some extra styles to the uploader
37
+ # @import bootstrap
38
+
39
+ Javascript:
40
+
41
+ //= import uploader
42
+
43
+
44
+ ==== Configuration
45
+
46
+ If you want to use fog, you can easily add the two initializers:
47
+
48
+ # initializers/assetable.rb
49
+ Assetable.configure do |config|
50
+ config.storage = :fog
51
+ end
52
+
53
+ # initializers/carrierwave.rb
54
+ # Checkout carrierwave's documentation for more options and details
55
+ CarrierWave.configure do |config|
56
+ config.fog_credentials = {
57
+ :provider => 'AWS',
58
+ :aws_access_key_id => AWS_ACCESS_KEY_ID,
59
+ :aws_secret_access_key => AWS_SECRET_ACCESS_KEY,
60
+ :region => S3_REGION,
61
+ }
62
+ config.fog_directory = S3_NAMESPACE
63
+ config.fog_public = true
64
+ config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
65
+ config.asset_host = S3_CLOUDFRONT_DOMAIN
66
+ end
67
+
68
+ This is only required if you're using Fog. Otherwise, Assetable will default to uploading locally.
69
+
70
+
71
+ == Usage
72
+
73
+ Using assetable is incredibly easy.
74
+
75
+ === Asset Attachments
76
+
77
+ Assetable allows you to easily attach and asset to a resource. This creates a join between your record and an asset through an asset_attachment table. You can add as many as you would like to any given model.
78
+
79
+ ==== Single Asset Attachment
80
+
81
+ For a single image or asset, simply add: "assetable" to your model:
82
+
83
+ class User < ActiveRecord::Base
84
+ assetable :avatar
85
+ end
86
+
87
+ You can name the asset attachment whatever you would like, in this case I used "avatar" but you can replace that with whatever you want.
88
+
89
+ On the frontend, you can simple call @user.avatar to access the file. Note that @user.avatar will be a ActiveRecord object for Asset. The file itself will be accessible through @user.avatar.filename and since we're using carrierwave, you can access the different version as you normally would, e.g. @user.avatar.filename.thumbnail, etc.
90
+
91
+ ==== Multiple Asset Attachments
92
+
93
+ For multiple attachments, simple pass more attributes to assetable. In theory, you can pass unlimited attributes to assetable and this will create an attachment for each.
94
+
95
+ def User < ActiveRecord::Base
96
+ assetable :avatar, :background, :hero
97
+ end
98
+
99
+ This will create multiple attachments to the user model, you can easily call them by:
100
+
101
+ @user.avatar #=> Asset Object
102
+ @user.avatar.filename #=> "/path/to/filename.extension"
103
+ # note this is a carrierwave uploader object, so you can access all of your versions
104
+ @user.avatar.filename.thumbnail
105
+
106
+ @user.background
107
+ @user.hero
108
+
109
+
110
+ === Gallery Attachments
111
+ Assetable allows you to attach galleries to any object. A gallery is a collection of assets grouped together for a specific record.
112
+
113
+ ==== Single Gallery
114
+
115
+ You can easily add a gallery to your object:
116
+
117
+ class Project < ActiveRecord::Base
118
+ galleryable
119
+ end
120
+
121
+ That is all you need to do to attach a gallery to your object. On the front-end, you can easily access your gallery and the attached assets:
122
+
123
+ # in your view or controller
124
+ @project.gallery #=> Gallery Object
125
+ @project.gallery.assets #=> Collection of Assets
126
+
127
+
128
+ ==== Multiple Galleries
129
+
130
+ You can add numerous galleries to a single object. Just as we did with assets, you can declare as many galleries through the galleryable:
131
+
132
+ class Project < ActiveRecord::Base
133
+ galleryable :another_gallery, :one_more_gallery
134
+ end
135
+
136
+ By default, galleryable will create a default :gallery. So you don't have to every pass :gallery or any arguments if you only want one gallery. This is great for multiple gallery records.
137
+
138
+ You can easily call these galleries:
139
+
140
+ @project.another_gallery #=> Gallery object
141
+ @project.another_gallery.assets #=> Asset collection
142
+
143
+ @project.one_more_gallery
144
+ @project.one_more_gallery.assets
145
+
146
+
147
+ === Adding the Uploader
148
+
149
+ In order to start uploading assets, you'll need to add the uploader to your form. You can easily add an uploader or gallery using a simple form helper.
150
+
151
+ ==== Single Asset Uploader
152
+
153
+ = form_for @user do |f|
154
+ ...
155
+ = f.uploader :avatar
156
+ ...
157
+
158
+ # You can also pass typical params to the uploader
159
+ = form_for @user do |f|
160
+ = f.uploader :avatar, class: "classname", id: "something-else"
161
+
162
+ Make sure the assetable uploader javascript is added.
163
+
164
+
165
+ ==== Gallery Uploader
166
+
167
+ = form_for @user do |f|
168
+ ...
169
+ = f.gallery :gallery
170
+ ...
171
+
172
+ It's that easy!
173
+
174
+
175
+ === Contributing
176
+
177
+ 1. Fork it
178
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
179
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
180
+ 4. Push to the branch (`git push origin my-new-feature`)
181
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Assetable'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
@@ -0,0 +1,74 @@
1
+ (($) ->
2
+ $.fn.asset_gallery = (options) ->
3
+
4
+ # Defaults variables
5
+ defaults =
6
+ base_path: "/assetable/assets"
7
+ fieldname: null
8
+ gallery_open: false
9
+ gallery: null
10
+
11
+
12
+ asset_gallery = this
13
+
14
+ init = ->
15
+ console.log "init!!"
16
+ # merge the options with the defaults
17
+ asset_gallery.options = jQuery.extend({}, defaults, options)
18
+ asset_gallery.load_page(1)
19
+
20
+
21
+ template = (html)->
22
+ backdrop = '<div class="assetable-gallery-backdrop"></div>'
23
+ wrapper = '<div class="assetable-gallery-wrapper">' + html + '</div>'
24
+ asset_gallery.gallery = $(wrapper)
25
+ return backdrop + wrapper
26
+
27
+
28
+ asset_gallery.load_page = (page)->
29
+ console.log "page:: ", page
30
+ if page > 1 then path = (asset_gallery.options.base_path + "/page/" + path) else path = asset_gallery.options.base_path
31
+
32
+ $.get path, {fieldname: asset_gallery.options.fieldname}, (data) ->
33
+ console.log "data:: ", data
34
+ if page > 1
35
+ $('.assetable-gallery', asset_gallery).html(data.html)
36
+ else
37
+ $('body').append(template(data.html))
38
+
39
+ bind_pagination(asset_gallery.gallery)
40
+ asset_gallery.bind_close_button()
41
+
42
+
43
+ bind_pagination = (gallery)->
44
+ console.log "bind pagination!!...", gallery
45
+ console.log $('.assetable-gallery-paginate a', gallery)
46
+
47
+ $('.assetable-gallery-paginate a', gallery).on "ajax:beforeSend", (event, xhr, settings) ->
48
+ console.log "event:: ", event
49
+ console.log "before send!!"
50
+
51
+ $('.assetable-gallery-paginate a', gallery).on "ajax:success", (data, status, xhr) ->
52
+ console.log "ajax success!!"
53
+ console.log "data:: ", data
54
+ console.log "status:: ", status
55
+
56
+
57
+ asset_gallery.bind_close_button = ()->
58
+ console.log "bound close button::, ", $(asset_gallery.gallery)
59
+ $('.btn-close-assetable-gallery', $(asset_gallery.gallery)).remove()
60
+ $(asset_gallery.gallery).on "click", '.btn-close-assetable-gallery', (e) ->
61
+ alert "fuck!"
62
+ console.log "close button clicked!"
63
+ e.preventDefault()
64
+ asset_gallery.close()
65
+
66
+
67
+ asset_gallery.close = ()->
68
+ $(asset_gallery.gallery).fadeOut()
69
+
70
+
71
+
72
+ init()
73
+
74
+ ) jQuery
@@ -0,0 +1,204 @@
1
+ (($) ->
2
+ $.fn.assetable_uploader = (options) ->
3
+
4
+ # Defaults variables
5
+ defaults =
6
+ allow_select_mg: true
7
+ authenticity_token: null
8
+ drag_drop: true
9
+ fieldname: null
10
+ FileUploaded: options.onUploaded
11
+ fileRemoved: options.fileRemoved
12
+ gallery: false
13
+ id: null
14
+ max_file_size: "10mb"
15
+ multiple_queues: true
16
+ multi_selection: true
17
+ max_file_count: 0
18
+ unique_names: true
19
+ url: null
20
+
21
+ assetable_uploader = this
22
+
23
+ init = ->
24
+ # merge the options with the defaults
25
+ assetable_uploader.options = jQuery.extend({}, defaults, options)
26
+ assetable_uploader.id = assetable_uploader.attr('id')
27
+ bind_uploader()
28
+
29
+
30
+ bind_uploader = ->
31
+
32
+ # Create our extra HTML for the copy and queu
33
+ # upload_directions = '<div class="uploader-directions" id="' + assetable_uploader.id + '-drop-area"><div class="uploader-directions-image"></div><div class="uploader-directions-copy">Drag and drop files or <a href="#" class="browse-btn" id="' + assetable_uploader.id + '-browse-btn">add them manually</a></div></div>'
34
+ # upload_directions = '<div class="uploader-directions" id="' + assetable_uploader.id + '-drop-area"><div class="uploader-directions-image"></div><div class="uploader-directions-copy"><a href="#" class="browse-btn" id="' + assetable_uploader.id + '-browse-btn">select file</a> or <a href="#" class="btn-open-asset-gallery">open gallery</a></div></div>'
35
+ upload_directions = '<div class="uploader-directions" id="' + assetable_uploader.id + '-drop-area"><div class="uploader-directions-image"></div><div class="uploader-directions-copy"><a href="#" class="browse-btn" id="' + assetable_uploader.id + '-browse-btn">select file</a> or <a href="/assetable/external_services/new" class="btn-third-party-service">add third party service</a></div></div>'
36
+ upload_queue = '<ul class="upload-queue"></ul>'
37
+ # Add to the uploader
38
+ $(assetable_uploader).append(upload_directions)
39
+ $(assetable_uploader).append(upload_queue)
40
+
41
+
42
+ # Instantiate the uploader
43
+ uploader = new plupload.Uploader(
44
+ runtimes: "html5"
45
+ browse_button: "#{assetable_uploader.id}-browse-btn"
46
+ url: assetable_uploader.options.url
47
+ max_file_size: assetable_uploader.options.max_file_size
48
+ unique_names: assetable_uploader.options.unique_names
49
+ dragdrop: assetable_uploader.options.drag_drop
50
+ drop_element: assetable_uploader.id
51
+ multiple_queues: assetable_uploader.options.multiple_queues
52
+ multi_selection: assetable_uploader.options.multi_selection
53
+ max_file_count: assetable_uploader.options.max_file_count
54
+ multipart: true
55
+ multipart_params:
56
+ authenticity_token: assetable_uploader.options.authenticity_token
57
+ fieldname: assetable_uploader.options.fieldname
58
+
59
+ # Filter file types
60
+ # filter: [
61
+ # title: "Image files"
62
+ # extensions: "jpg,gif,png"
63
+ # ,
64
+ # title: "Video files"
65
+ # extensions: "mov,mp4,mpeg4"
66
+ # ]
67
+ )
68
+
69
+
70
+
71
+ # # Uploader Template
72
+ # template = "<div class=\"current_preview current_" + uploader_id + "\">" + content + "</div>" + "<div class=\"koh_pluploader\" id=\"" + uploader_id + "_drop_area\">" + "<a id=\"" + uploader_id + "_browse_btn\" href=\"#\"><span class=\"link_color\">Attach files by dragging & dropping them here</span> or add them manually</a>" + "<ul class=\"upload_queue\"></ul>" + "</div>" + ((if allow_select_mg then "<a href=\"#\" class=\"attach_image\" uid=\"" + uploader_id + "\" target=\"" + container + "\">select from media gallery</a>" else ""))
73
+
74
+ # # Initialize binding
75
+ # uploader.bind "Init", (up, params) ->
76
+ # $("#" + container).html template
77
+
78
+
79
+ # # Initiate the uploader
80
+ uploader.init()
81
+
82
+ # Bind to file added function
83
+ uploader.bind "FilesAdded", (up, files) ->
84
+ $.each files, (i, file) ->
85
+ $("ul.upload-queue", assetable_uploader).append '<li id="' + file.id + '"><span class="uploader-file-name">' + file.name + '</span><div class="progress progress"><div class="progress-bar progress-bar-success"></div></div></li>'
86
+
87
+
88
+ # Update the progress bars
89
+ uploader.bind "UploadProgress", (up, file) ->
90
+ $("li#" + file.id + " .progress .progress-bar", assetable_uploader).width file.percent + "%"
91
+
92
+
93
+ # Listen for upload complete
94
+ uploader.bind "FileUploaded", (up, file, info) ->
95
+ if assetable_uploader.options.FileUploaded
96
+ json = jQuery.parseJSON(info.response)
97
+ assetable_uploader.options.FileUploaded json
98
+ $("li#" + file.id, assetable_uploader).fadeOut().remove()
99
+
100
+
101
+ # Listen for queue changes
102
+ uploader.bind "QueueChanged", (up, files) ->
103
+ uploader.start()
104
+ up.refresh()
105
+ # # Listen for errors
106
+ # uploader.bind "Error", (up, err) ->
107
+ # $("#" + container).append "<div class=\"notice error\">" + "<span class=\"block\">Error: " + err.code + "</div>" + "<span class=\"block\">Message: " + err.message + "</div>" + ((if err.file then "<span clas=\"block\">" + err.file.name + "</span>" else "")) + "</div>"
108
+ # up.refresh() # Reposition Flash/Silverlight
109
+
110
+ draggable_selector = (if assetable_uploader.options.gallery then $('.uploader-directions', assetable_uploader) else $(assetable_uploader))
111
+
112
+ # Handle the drag over effect, adds a class to the container
113
+ $(draggable_selector).bind "dragover", ->
114
+ $(this).addClass "droppable" unless $(this).hasClass("droppable")
115
+
116
+ # Handles drag leave
117
+ $(draggable_selector).on "dragleave", ->
118
+ $(this).removeClass "droppable" if $(this).hasClass("droppable")
119
+
120
+ $(draggable_selector).on "dragend", ->
121
+ $(this).removeClass "droppable" if $(this).hasClass("droppable")
122
+
123
+ $(draggable_selector).on "drop", ->
124
+ $(this).removeClass "droppable" if $(this).hasClass("droppable")
125
+
126
+
127
+
128
+
129
+ # Remove asset link handler
130
+ $(assetable_uploader).on "click", ".btn-uploader-remove-asset", (e)->
131
+ e.preventDefault()
132
+ if assetable_uploader.options.fileRemoved
133
+ assetable_uploader.options.fileRemoved this, assetable_uploader
134
+
135
+
136
+ $(assetable_uploader).on "click", ".btn-open-asset-gallery", (e)->
137
+ e.preventDefault()
138
+ $(assetable_uploader).asset_gallery({fieldname: assetable_uploader.options.fieldname})
139
+ # if assetable_uploader.options.openAssetGallery
140
+ # assetable_uploader.options.openAssetGallery this, assetable_uploader
141
+
142
+ # $(assetable_uploader).on "click", ".btn-third-party-service", (e)->
143
+ # e.preventDefault()
144
+ # console.log "boom"
145
+
146
+
147
+ # Add a third party service
148
+ $(assetable_uploader).on "click", ".btn-third-party-service", (e)->
149
+ e.preventDefault()
150
+ $.ajax
151
+ url: $(this).attr('href')
152
+ data: {fieldname: assetable_uploader.options.fieldname}
153
+ type: 'GET'
154
+
155
+ success: (response)->
156
+ $response = $(response)
157
+ $response.modal()
158
+
159
+ $('form#new_external_service').on 'ajax:beforeSend', ()->
160
+ # console.log "form submitting..."
161
+
162
+ $('form#new_external_service').on 'ajax:success', (data, status, xhr)->
163
+ if status.success
164
+ $response.modal('hide').remove()
165
+ assetable_uploader.options.FileUploaded status
166
+
167
+
168
+
169
+
170
+
171
+ init()
172
+
173
+ ) jQuery
174
+
175
+
176
+ $(document).ready ->
177
+
178
+ # Bind the koh uploader and galleries to a page
179
+ $(".uploader").each ->
180
+
181
+ # Check that it's not already bound
182
+ unless $(this).hasClass("uploadable")
183
+ $(this).addClass "uploadable"
184
+ $this = $(this)
185
+ $this.removeClass "uploader"
186
+
187
+ field = $this.attr("data-uploader-input-name")
188
+
189
+ $this.assetable_uploader
190
+ multi_selection: false
191
+ url: "/assetable/assets"
192
+ fieldname: field
193
+ authenticity_token: $("meta[name=\"csrf-token\"]").attr("content")
194
+ onUploaded: (resp) ->
195
+ $this.find('.uploader-data-wrapper').html(resp.html)
196
+ $this.addClass("uploader-has-asset")
197
+ fileRemoved: (button, item) ->
198
+ return false unless $(item).hasClass("uploader-has-asset")
199
+ $('.uploader-preview', item).html('<input type="hidden" name="' + field + '" />')
200
+ $(item).removeClass("uploader-has-asset")
201
+ # openAssetGallery: (button, item) ->
202
+
203
+
204
+