assetable 0.1.3 → 0.1.6

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjZiYTU5Zjc1OTk0NTE2MzFhZWRlMjdlYzVmZmMyOTMzYWNmMzM1Mg==
4
+ MjllOWNiYzFhMzExZGIwYmQ2NGVhNjE1YWIyN2UzZThlYjZkZjE4Yg==
5
5
  data.tar.gz: !binary |-
6
- ZDIxMWU0MjMyYTdhZDQ5NTM2NzJmOTViY2ViYTdmMTNhM2E5NjExOQ==
6
+ NWQxY2FmNGM3Mzk4MDlhYjJhMzI2M2YwMTE0NjczYzZmNWYzNWE0OA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YmIwNWJjOGE2ZTNmMzhlMjdhNGU5ZmE0MTIyMjM1NzIwOTI2OGQ4YzIwZDhj
10
- ZmE3OTRmY2FjYmY2YjFhY2FhNjMyOGM2MzRhNzc1MWYzNzUyZGM4ZWY4YWRh
11
- NmJmMTU2NTliNDMyMWViMDE3YTgwMTYxMTU1MThjZGUxNmU4ODk=
9
+ ZmYyNjQ0YmQ2MDUwMmNlNWFiODcxMDM3YWZkZTE4OWVjNDljMDAwNWUzZTZi
10
+ YjIzYjZhYzBiNmNmM2RhMDNhZjJlZDFlNTFiMGJmYzVkNTk0NWNiMzczNGI5
11
+ MWFlNDIwZjE4N2E1OGVlYjVjN2Y4N2U1YWM2OTM1YzhiYWQyYTk=
12
12
  data.tar.gz: !binary |-
13
- OTAxYjQ3ZWUwMDA2MWE4ZmM2ZmRhZjUyOWYxNzY4NDcyZWQ5OTcyYmE3NzY2
14
- YjhjNTgwMTQ2NWM4MTA2YTJkNjc0NTEwZGVkZmRkOWM0YjU3NTYwNzkxMWNk
15
- MTAyNzMwZWFmNDU2MWY3MmIyZDZkOGUyNGVhN2JhYmZiNGZjYzA=
13
+ NDk4ZDYwNjZlMjEyOTlkMDI4MzRlZGEyYjlmNDJkYmU2OGQyYTljNjVhZTEw
14
+ YTY5ODYwZTczZDQ1MmVkZjQyYTdkZjA2OThjZmEzMjQ2YjRiMzUwODZmYmQ5
15
+ ZTdiOTdhODdkZjdkYzZhODJmZWUwNTZhOGQxOTNiNWNiY2EwODc=
@@ -9,6 +9,7 @@
9
9
  fieldname: null
10
10
  FileUploaded: options.onUploaded
11
11
  fileRemoved: options.fileRemoved
12
+ fileUpdated: options.fileUpdated
12
13
  gallery: false
13
14
  id: null
14
15
  max_file_size: "10mb"
@@ -133,6 +134,26 @@
133
134
  assetable_uploader.options.fileRemoved this, assetable_uploader
134
135
 
135
136
 
137
+ $(assetable_uploader).on "click", ".btn-uploader-edit-asset", (e)->
138
+ e.preventDefault()
139
+ $.ajax
140
+ url: $(this).attr('href')
141
+ data: {fieldname: assetable_uploader.options.fieldname}
142
+ type: 'GET'
143
+
144
+ success: (response)->
145
+ $response = $(response)
146
+ $response.modal()
147
+
148
+ $('form.form-edit-asset').on 'ajax:beforeSend', ()->
149
+ # console.log "form submitting..."
150
+
151
+ $('form.form-edit-asset').on 'ajax:success', (data, status, xhr)->
152
+ if status.success
153
+ $response.modal('hide').remove()
154
+ assetable_uploader.options.fileUpdated status
155
+
156
+
136
157
  $(assetable_uploader).on "click", ".btn-open-asset-gallery", (e)->
137
158
  e.preventDefault()
138
159
  $(assetable_uploader).asset_gallery({fieldname: assetable_uploader.options.fieldname})
@@ -173,11 +194,11 @@
173
194
  ) jQuery
174
195
 
175
196
 
176
- $(document).ready ->
177
197
 
198
+
199
+ bind_uploaders = ->
178
200
  # Bind the koh uploader and galleries to a page
179
201
  $(".uploader").each ->
180
-
181
202
  # Check that it's not already bound
182
203
  unless $(this).hasClass("uploadable")
183
204
  $(this).addClass "uploadable"
@@ -198,7 +219,14 @@ $(document).ready ->
198
219
  return false unless $(item).hasClass("uploader-has-asset")
199
220
  $('.uploader-preview', item).html('<input type="hidden" name="' + field + '" />')
200
221
  $(item).removeClass("uploader-has-asset")
222
+ fileUpdated: (resp) ->
223
+ $this.find('div.uploader-preview[data-asset-id="' + resp.id + '"]').replaceWith(resp.html)
201
224
  # openAssetGallery: (button, item) ->
202
225
 
203
-
204
226
 
227
+
228
+ window.Assetable.bind_uploaders = bind_uploaders
229
+
230
+ $(document).ready ->
231
+
232
+ window.Assetable.bind_uploaders()
@@ -1,8 +1,6 @@
1
- $(document).ready ->
2
-
1
+ bind_galleries = ->
3
2
  # Bind the koh uploader and galleries to a page
4
3
  $(".gallery-uploader").each ->
5
-
6
4
  # Check that it's not already bound
7
5
  unless $(this).hasClass("uploadable")
8
6
  $(this).addClass "uploadable"
@@ -18,11 +16,11 @@ $(document).ready ->
18
16
  fieldname: field
19
17
  authenticity_token: $("meta[name=\"csrf-token\"]").attr("content")
20
18
  onUploaded: (resp) ->
21
- $this.find('.uploadar-data-wrapper').append(resp.html)
19
+ $this.find('.uploader-data-wrapper').append(resp.html)
22
20
  fileRemoved: (button, item) ->
23
21
  $(button).closest('.uploader-preview').remove()
24
-
25
-
22
+ fileUpdated: (resp) ->
23
+ $this.find('div.uploader-preview[data-asset-id="' + resp.id + '"]').replaceWith(resp.html)
26
24
 
27
25
  # Make the gallery sortable
28
26
  $(this).sortable
@@ -31,3 +29,10 @@ $(document).ready ->
31
29
  tolerance: 'pointer'
32
30
  placeholder: 'uploader-sortable-placeholder'
33
31
 
32
+
33
+ window.Assetable.bind_galleries = bind_galleries
34
+
35
+ $(document).ready ->
36
+
37
+ window.Assetable.bind_galleries()
38
+
@@ -1,3 +1,5 @@
1
+ #= require_self
2
+
1
3
  #= require moxie
2
4
  #= require plupload.dev
3
5
  #= require plupload.settings
@@ -8,3 +10,5 @@
8
10
  #= require assetable/assetable_uploader
9
11
  #= require assetable/gallery
10
12
  #= require assetable/asset_gallery
13
+
14
+ window.Assetable = {}
@@ -148,7 +148,7 @@ div.uploader-preview
148
148
  width: 100%
149
149
 
150
150
 
151
- .gallery-uploader .uploadar-data-wrapper
151
+ .gallery-uploader .uploader-data-wrapper
152
152
  +clearfix
153
153
  text-align: left
154
154
 
@@ -13,9 +13,6 @@ class Assetable::AssetsController < ActionController::Base
13
13
  content_type = params[:file].content_type
14
14
  asset_params = {name: params[:file].original_filename, filename: params[:file]}
15
15
 
16
- puts "params:: #{params.inspect}"
17
- puts "content_type:: #{content_type}"
18
-
19
16
  # Create the appropriate model
20
17
  if content_type.split("/").first == "image"
21
18
  @asset = Image.new(asset_params)
@@ -25,8 +22,6 @@ class Assetable::AssetsController < ActionController::Base
25
22
  @asset = Document.new(asset_params)
26
23
  end
27
24
 
28
- puts "@asset:: #{@asset.inspect}"
29
-
30
25
  # Return
31
26
  if @asset.errors.empty? and @asset.save
32
27
  render json: { success: true, html: render_to_string(partial: "assetable/assets/asset", locals: { asset: @asset, fieldname: params[:fieldname]})}
@@ -35,4 +30,30 @@ class Assetable::AssetsController < ActionController::Base
35
30
  end
36
31
  end
37
32
 
33
+ def edit
34
+ @asset = Asset.find(params[:id])
35
+ end
36
+
37
+ def update
38
+ @asset = Asset.find(params[:id])
39
+ if @asset and @asset.errors.empty? and @asset.update_attributes(permitted_params)
40
+ render json: { success: true, id: @asset.id, html: render_to_string(partial: "assetable/assets/asset", locals: { asset: @asset, fieldname: params[:fieldname]})}
41
+ else
42
+ render json: { status: "error", errors: @external_service.errors.full_messages, html: render_to_string(:edit) }
43
+ end
44
+ end
45
+
46
+ # Permitted params for the model
47
+ def permitted_params
48
+ params.require(params[:asset_type].underscore.to_sym).permit(
49
+ :name,
50
+ :filename,
51
+ :body,
52
+ :content_type,
53
+ :width,
54
+ :height,
55
+ :asset_type
56
+ )
57
+ end
58
+
38
59
  end
data/app/models/asset.rb CHANGED
@@ -62,7 +62,7 @@ class Asset < ActiveRecord::Base
62
62
  self.content_type = self.filename.file.content_type
63
63
  self.file_size = self.filename.file.size
64
64
  self.width, self.height = `identify -format "%wx%h" #{self.filename.file.path}`.split(/x/) unless self.document?
65
- self.checksum = Digest::MD5.file(self.filename.file.path).to_s
65
+ # self.checksum = Digest::MD5.file(self.filename.to_s).to_s
66
66
  end
67
67
  end
68
68
 
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ class AssetUploader < CarrierWave::Uploader::Base
4
+
5
+ # Choose what kind of storage to use for this uploader:
6
+ storage Assetable.storage
7
+
8
+ # Set the MD5 hash
9
+ process :set_md5
10
+
11
+ # Override the directory where uploaded files will be stored.
12
+ # This is a sensible default for uploaders that are meant to be mounted:
13
+ def store_dir
14
+ if model.present?
15
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
16
+ else
17
+ "uploads/#{mounted_as}"
18
+ end
19
+ end
20
+
21
+ # Set an MD5 hash of the image
22
+ def set_md5
23
+ if model.present?
24
+ model.checksum = Digest::MD5.file(current_path).to_s
25
+ end
26
+ end
27
+
28
+ end
@@ -1,19 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- class DocumentUploader < CarrierWave::Uploader::Base
4
-
5
- # Choose what kind of storage to use for this uploader:
6
- storage Assetable.storage
7
-
8
- # Override the directory where uploaded files will be stored.
9
- # This is a sensible default for uploaders that are meant to be mounted:
10
- def store_dir
11
- if model.present?
12
- "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
13
- else
14
- "uploads/#{mounted_as}"
15
- end
16
- end
3
+ class DocumentUploader < AssetUploader
17
4
 
18
5
  # Provide a default URL as a default if there hasn't been a file uploaded:
19
6
  # def default_url
@@ -1,27 +1,14 @@
1
1
  # encoding: utf-8
2
2
 
3
- class ImageUploader < CarrierWave::Uploader::Base
3
+ class ImageUploader < AssetUploader
4
4
 
5
5
  include CarrierWave::MimeTypes
6
6
  # Include RMagick or MiniMagick support:
7
7
  include CarrierWave::RMagick
8
8
 
9
- # Choose what kind of storage to use for this uploader:
10
- storage Assetable.storage
11
-
12
9
  # More reliable content types
13
10
  process :set_content_type
14
11
 
15
- # Override the directory where uploaded files will be stored.
16
- # This is a sensible default for uploaders that are meant to be mounted:
17
- def store_dir
18
- if model.present?
19
- "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
20
- else
21
- "uploads/#{mounted_as}"
22
- end
23
- end
24
-
25
12
  # Add a white list of extensions which are allowed to be uploaded.
26
13
  # For images you might use something like this:
27
14
  def extension_white_list
@@ -1,16 +1,4 @@
1
1
  class VideoUploader < CarrierWave::Uploader::Base
2
-
3
- storage Assetable.storage
4
-
5
- # Override the directory where uploaded files will be stored.
6
- # This is a sensible default for uploaders that are meant to be mounted:
7
- def store_dir
8
- if model.present?
9
- "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
10
- else
11
- "uploads/#{mounted_as}"
12
- end
13
- end
14
2
 
15
3
  # Create an MP4 version
16
4
  # version :mp4 do
@@ -1,4 +1,4 @@
1
- .uploader-preview
1
+ .uploader-preview{:'data-asset-id' => asset.id}
2
2
 
3
3
  = link_to asset.filename.to_s, target: "_blank" do
4
4
  - if asset.image?
@@ -18,6 +18,6 @@
18
18
  %span.uploader-size= number_to_human_size(asset.file_size)
19
19
  .uploader-actions
20
20
  = link_to "delete", "#", class: "btn-uploader btn-uploader-remove-asset"
21
- = link_to "edit", "#", class: "btn-uploader btn-uploader-edit-asset"
21
+ = link_to "edit", edit_assetable_asset_path(asset), class: "btn-uploader btn-uploader-edit-asset"
22
22
 
23
23
  = hidden_field_tag(fieldname, asset.id)
@@ -0,0 +1,32 @@
1
+ .assetable-assets.assetable-modal.modal.fade
2
+ .modal-dialog
3
+ .modal-content
4
+ = form_for [:assetable, @asset], url: assetable_asset_path(@asset, asset_type: @asset.type), remote: true, html: {class: "form-edit-asset"} do |f|
5
+ .modal-header
6
+ %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", type: "button"} ×
7
+ %h4.modal-title Asset
8
+ .modal-body
9
+
10
+ = hidden_field_tag :fieldname, params[:fieldname]
11
+
12
+ .form-group
13
+ = f.label :name
14
+ = f.text_field :name, class: "form-control input-fluid", required: true
15
+ - unless f.object.filename.present?
16
+ .form-group
17
+ = f.label :filename
18
+ = f.text_field :filename, class: "form-control input-fluid"
19
+ .form-group
20
+ = f.label :body
21
+ = f.text_area :body, class: "form-control input-fluid"
22
+ .form-group.row
23
+ .col-xs-6
24
+ = f.label :width
25
+ = f.number_field :width, class: "form-control input-fluid"
26
+ .col-xs-6
27
+ = f.label :height
28
+ = f.number_field :height, class: "form-control input-fluid"
29
+
30
+ .modal-footer
31
+ = button_tag "Cancel", class: "btn btn-default", :'data-dismiss' => "modal", type: "button"
32
+ = f.submit "Save Asset", class: "btn btn-primary"
@@ -0,0 +1 @@
1
+ = render 'form'
@@ -0,0 +1,34 @@
1
+ .assetable-external-services.assetable-modal.modal.fade
2
+ .modal-dialog
3
+ .modal-content
4
+ = form_for [:assetable, @external_service], remote: true do |f|
5
+ .modal-header
6
+ %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", type: "button"} ×
7
+ %h4.modal-title Third Party Service
8
+ .modal-body
9
+
10
+ = hidden_field_tag :fieldname, params[:fieldname]
11
+
12
+ .form-group
13
+ = f.label :name
14
+ = f.text_field :name, class: "form-control input-fluid", required: true
15
+ .form-group
16
+ = f.label :content_type
17
+ = f.select :content_type, ExternalService.possible_content_types
18
+ .form-group
19
+ = f.label :filename
20
+ = f.text_field :filename, class: "form-control input-fluid"
21
+ .form-group
22
+ = f.label :body
23
+ = f.text_area :body, class: "form-control input-fluid", required: true
24
+ .form-group.row
25
+ .col-xs-6
26
+ = f.label :width
27
+ = f.number_field :width, class: "form-control input-fluid"
28
+ .col-xs-6
29
+ = f.label :height
30
+ = f.number_field :height, class: "form-control input-fluid"
31
+
32
+ .modal-footer
33
+ = button_tag "Cancel", class: "btn btn-default", :'data-dismiss' => "modal", type: "button"
34
+ = f.submit "Add Third Party Service", class: "btn btn-primary"
@@ -1,34 +1 @@
1
- .assetable-external-services.assetable-modal.modal.fade
2
- .modal-dialog
3
- .modal-content
4
- = form_for [:assetable, @external_service], remote: true do |f|
5
- .modal-header
6
- %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", type: "button"} ×
7
- %h4.modal-title Third Party Service
8
- .modal-body
9
-
10
- = hidden_field_tag :fieldname, params[:fieldname]
11
-
12
- .form-group
13
- = f.label :name
14
- = f.text_field :name, class: "form-control input-fluid", required: true
15
- .form-group
16
- = f.label :content_type
17
- = f.select :content_type, ExternalService.possible_content_types
18
- .form-group
19
- = f.label :filename
20
- = f.text_field :filename, class: "form-control input-fluid"
21
- .form-group
22
- = f.label :body
23
- = f.text_area :body, class: "form-control input-fluid", required: true
24
- .form-group.row
25
- .col-xs-6
26
- = f.label :width
27
- = f.number_field :width, class: "form-control input-fluid"
28
- .col-xs-6
29
- = f.label :height
30
- = f.number_field :height, class: "form-control input-fluid"
31
-
32
- .modal-footer
33
- = button_tag "Cancel", class: "btn btn-default", :'data-dismiss' => "modal", type: "button"
34
- = f.submit "Add Third Party Service", class: "btn btn-primary"
1
+ = render 'form'
@@ -27,7 +27,7 @@ class ActionView::Helpers::FormBuilder
27
27
  end
28
28
 
29
29
  # Uploader HTML with the asset previews and actions
30
- uploader_html = content_tag(:div, (asset_preview.html_safe), class: "uploadar-data-wrapper")
30
+ uploader_html = content_tag(:div, (asset_preview.html_safe), class: "uploader-data-wrapper")
31
31
 
32
32
  # Wrap the previews and uploader in a div
33
33
  uploader_wrapper = content_tag(:div, uploader_html, class: "gallery-uploader", id: options[:id], :'data-uploader-input-name' => fieldname)
@@ -38,9 +38,9 @@ class ActionView::Helpers::FormBuilder
38
38
  image_tag = asset_preview_image(asset)
39
39
  asset_name = content_tag(:span, asset.name.to_s, class: "uploader-name")
40
40
  asset_size = content_tag(:span, number_to_human_size(asset.file_size.to_s), class: "uploader-size")
41
- asset_size_and_actions = content_tag(:div, (asset_size + asset_actions), class: "uploader-size-and-actions")
41
+ asset_size_and_actions = content_tag(:div, (asset_size + asset_actions(asset)), class: "uploader-size-and-actions")
42
42
  field = hidden_field_tag(fieldname, (asset.id))
43
- return content_tag(:div, (image_tag + asset_name + asset_size_and_actions + field), class: "uploader-preview")
43
+ return content_tag(:div, (image_tag + asset_name + asset_size_and_actions + field), class: "uploader-preview", :'data-asset-id' => asset.id)
44
44
  end
45
45
 
46
46
  # Asset preview image or fallback to a content type image
@@ -63,9 +63,9 @@ class ActionView::Helpers::FormBuilder
63
63
  end
64
64
 
65
65
  # Asset actions, i.e.e remove and edit buttons
66
- def asset_actions
66
+ def asset_actions asset
67
67
  remove_btn = link_to "delete", "#", class: "btn-uploader btn-uploader-remove-asset"
68
- edit_btn = link_to "edit", "#", class: "btn-uploader btn-uploader-edit-asset"
68
+ edit_btn = link_to "edit", Rails.application.routes.url_helpers.edit_assetable_asset_path(asset), class: "btn-uploader btn-uploader-edit-asset", :'data-asset-id' => asset.id
69
69
  content_tag(:div, (remove_btn + edit_btn), class: "uploader-actions")
70
70
  end
71
71
 
@@ -1,3 +1,3 @@
1
1
  module Assetable
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assetable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Koht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-20 00:00:00.000000000 Z
11
+ date: 2013-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -306,11 +306,15 @@ files:
306
306
  - app/models/gallery.rb
307
307
  - app/models/image.rb
308
308
  - app/models/video.rb
309
+ - app/uploaders/asset_uploader.rb
309
310
  - app/uploaders/document_uploader.rb
310
311
  - app/uploaders/image_uploader.rb
311
312
  - app/uploaders/video_uploader.rb
312
313
  - app/views/assetable/assets/_asset.html.haml
314
+ - app/views/assetable/assets/_form.html.haml
313
315
  - app/views/assetable/assets/_gallery.html.haml
316
+ - app/views/assetable/assets/edit.html.haml
317
+ - app/views/assetable/external_services/_form.html.haml
314
318
  - app/views/assetable/external_services/new.html.haml
315
319
  - config/initializers/carrierwave.rb
316
320
  - config/initializers/gallery_input.rb