lol_multiple_uploads 0.0.2 → 1.0.0

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
  SHA1:
3
- metadata.gz: a6548accf5a47d041b92ce662e1becd80d3e8b16
4
- data.tar.gz: 3b2559aa35f7e3794e1df826539d8b1d041076bd
3
+ metadata.gz: 86d948f983e19f849009a7fd2322101bcbebc11d
4
+ data.tar.gz: a1a7a58af4e1f3a5eb1c7792f8e4143c06444c10
5
5
  SHA512:
6
- metadata.gz: b57e6ca95070c88dfbdfc0d3c023cc1428c844dd2f4ac785da7b45c0105b3faaeaef0de3f955a188aa06731c05f6e3c079aa92c680a7e2b7642a5f69c61f982b
7
- data.tar.gz: 5ac2403f0743ef3bbe0c4e37cf5cf26e87b02d8e40115f0e1ca257e9c9848cbfea54ff3886a0501351d656e327b1c74949ccc2815c2f77f69092bb5be4f3729c
6
+ metadata.gz: f6270075d06347ba790ece4cfb47c0c98e41eb47b2ad440a7856c5355d958000090f4ec1e28811b7fa22e3e9142ef7923d0c3637802aa9b17fecbebe295c43cd
7
+ data.tar.gz: dd97cda144696b35f57a5b22faba8f845e3102adba88b7589f0d2322707c19cb893f72860bc0531d3e6e27d9968e483aa728d92fb120e684754b666158cc91d1
@@ -5,8 +5,45 @@ $(document).ready(function() {
5
5
  if($multipleUploadLink[0]){
6
6
  new MultipleUpload($multipleUploadLink);
7
7
  }
8
+
9
+ new MultipleUploadsPhotos();
8
10
  });
9
11
 
12
+ var MultipleUploadsPhotos = function(){
13
+ var _this = this;
14
+ this.$container = $('.lol-multiple-uploads.images-container');
15
+
16
+ this.startup = function(){
17
+ this.$container.on('click', 'figure a', function(event) {
18
+ _this.removeImage($(this));
19
+ return false;
20
+ });
21
+ },
22
+
23
+ this.removeImage = function($link){
24
+ if(window.confirm("Você tem certeza?")){
25
+ $.ajax({
26
+ url: $link.attr('href'),
27
+ type: 'DELETE',
28
+ dataType: 'json'
29
+ })
30
+ .done(function() {
31
+ console.log("success");
32
+ $link.parent().fadeOut('400', function() {
33
+ $(this).remove();
34
+ });
35
+ })
36
+ .fail(function() {
37
+ console.log("error");
38
+ })
39
+ .always(function() {
40
+ console.log("complete");
41
+ });
42
+ }
43
+ },
44
+
45
+ this.startup();
46
+ }
10
47
 
11
48
  var MultipleUpload = function(link){
12
49
  var that = this;
@@ -26,7 +63,7 @@ var MultipleUpload = function(link){
26
63
  },
27
64
 
28
65
  this.filePicker = function(){
29
- filepicker.setKey(that.filePickerKey); // -> 'AW4LKXceQXaH71hWtVTdlz'
66
+ filepicker.setKey(that.filePickerKey);
30
67
 
31
68
  filepicker.pickMultiple(function(json){
32
69
  that.storeImages(json);
@@ -57,20 +94,26 @@ var MultipleUpload = function(link){
57
94
  },
58
95
 
59
96
  this.appendImage = function(obj){
60
- $(this.imageContainer).append("<img src='"+obj.image.url+"' data-id="+obj._id+">");
97
+ var html = "<figure data-id="+obj._id+">"
98
+ html += "<img src='"+obj.image.url+"' >"
99
+ html += "<a rel=nofollow' data-method='delete' href='/remove-image/"+obj._id+".json'>Remover</a>"
100
+ html += "</figure>"
101
+
102
+ $(this.imageContainer).append(html);
61
103
  },
62
104
 
63
105
  this.showLoading = function(){
64
106
  jQuery('<img/>', {
65
107
  src: '/assets/lol_multiple_uploads/loading.gif',
66
108
  style: 'position: fixed; bottom: 5px; right: 5px; z-index: 400;',
67
- class: 'lol-multiple-uploads'
109
+ class: 'lol-multiple-uploads loading'
68
110
  }).appendTo('body');
69
111
  },
70
112
 
71
113
  this.hideLoading = function(){
72
- $('.lol-multiple-uploads:first').remove();
114
+ $('.lol-multiple-uploads.loading:first').remove();
73
115
  }
74
116
 
75
117
  this.startup();
76
- }
118
+ }
119
+
@@ -0,0 +1,51 @@
1
+ .lol-multiple-uploads.images-container{
2
+ width: 100%;
3
+ float: left;
4
+ overflow: hidden;
5
+ }
6
+
7
+ .lol-multiple-uploads.images-container figure{
8
+ width: 120px;
9
+ height: 120px;
10
+ float: left;
11
+ padding: 0px;
12
+ margin: 5px;
13
+ position: relative;
14
+ overflow: hidden;
15
+ }
16
+
17
+ .lol-multiple-uploads.is-sortable figure{
18
+ cursor: move;
19
+ }
20
+
21
+ .lol-multiple-uploads.images-container figure a{
22
+ position: absolute;
23
+ bottom: -26px;
24
+ left: 0px;
25
+ width: 100%;
26
+ padding: 5px 0;
27
+ color: #fff;
28
+ font-family: Helvetica, Arial, sans-serif;
29
+ font-size: 14px;
30
+ text-align: center;
31
+ background-color: rgba(0, 0, 0, 0.7);
32
+ background: rgba(0, 0, 0, 0.7);
33
+ -webkit-transition: all 200ms ease-in-out;
34
+ -moz-transition: all 200ms ease-in-out;
35
+ -ms-transition: all 200ms ease-in-out;
36
+ -o-transition: all 200ms ease-in-out;
37
+ transition: all 200ms ease-in-out;
38
+ }
39
+
40
+ .lol-multiple-uploads.images-container figure:hover a{
41
+ bottom: 0px;
42
+ -webkit-transition: all 200ms ease-in-out;
43
+ -moz-transition: all 200ms ease-in-out;
44
+ -ms-transition: all 200ms ease-in-out;
45
+ -o-transition: all 200ms ease-in-out;
46
+ transition: all 200ms ease-in-out;
47
+ }
48
+
49
+ .lol-multiple-uploads.images-container img{
50
+ max-width: 100%;
51
+ }
@@ -3,17 +3,28 @@ class PhotosController < ActionController::Base
3
3
 
4
4
  def create
5
5
  @resource = params[:model].classify.constantize.find params[:model_id]
6
- @photo = @resource.photos.build
7
- @photo.image.store!(open(params[:photo]))
8
-
6
+ @photo = @resource.photos.build(remote_image_url: params[:photo])
7
+
9
8
  respond_with(@photo) do |format|
10
9
  if @photo.save
11
- format.json{ render json: @photo}
10
+ format.json{ render json: @photo }
12
11
  else
13
- format.json{ render nothing: true, status: :error}
12
+ format.json{ render nothing: true, status: :error }
14
13
  end
15
14
  end
16
15
  rescue Exception
17
16
  render nothing: true, status: :error
18
17
  end
18
+
19
+ def destroy
20
+ @photo = Photo.find params[:id]
21
+
22
+ respond_with(@photo) do |format|
23
+ if @photo.destroy
24
+ format.json{ render json: @photo }
25
+ else
26
+ format.json{ render nothing: true, status: :error }
27
+ end
28
+ end
29
+ end
19
30
  end
@@ -0,0 +1,9 @@
1
+ module ImageHelper
2
+
3
+ def list_photos(resource)
4
+ content_tag(:div, class: 'lol-multiple-uploads images-container is-sortable', 'data-resource' => 'photo') do
5
+ render partial: '/layouts/lol_multiple_uploads/photo', collection: resource.photos.prioritized
6
+ end
7
+ end
8
+
9
+ end
@@ -16,12 +16,9 @@ class ImageUploader < CarrierWave::Uploader::Base
16
16
  end
17
17
 
18
18
  # Provide a default URL as a default if there hasn't been a file uploaded:
19
- # def default_url
20
- # # For Rails 3.1+ asset pipeline compatibility:
21
- # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
22
- #
23
- # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
24
- # end
19
+ def default_url
20
+ "/assets/fallback/no-image.jpg"
21
+ end
25
22
 
26
23
  # Process files as they are uploaded:
27
24
  # process :scale => [200, 300]
@@ -0,0 +1,4 @@
1
+ <figure data-id="<%= photo.id %>">
2
+ <%= image_tag(photo.image.url)%>
3
+ <%= link_to "Remover", remove_image_path(photo, format: 'json'), method: :delete %>
4
+ </figure>
data/config/routes.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
- post '/upload-image' => 'photos#create', as: :upload_image
4
-
3
+ post '/upload-image' => 'photos#create' , as: :upload_image
4
+ delete '/remove-image/:id' => 'photos#destroy', as: :remove_image
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module LolMultipleUploads
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lol_multiple_uploads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Zaghi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-27 00:00:00.000000000 Z
11
+ date: 2013-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -90,10 +90,13 @@ extra_rdoc_files: []
90
90
  files:
91
91
  - app/assets/images/lol_multiple_uploads/loading.gif
92
92
  - app/assets/javascripts/lol_multiple_uploads/upload.js
93
+ - app/assets/stylesheets/lol_multiple_uploads/base.css
93
94
  - app/controllers/photos_controller.rb
95
+ - app/helpers/image_helper.rb
94
96
  - app/helpers/upload_helper.rb
95
97
  - app/models/photo.rb
96
98
  - app/uploaders/image_uploader.rb
99
+ - app/views/layouts/lol_multiple_uploads/_photo.html.erb
97
100
  - config/initializers/init_lol_multiple_uploads.rb
98
101
  - config/routes.rb
99
102
  - lib/generators/lol_multiple_uploads/install_generator.rb