lol_multiple_uploads 1.0.2 → 1.1.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: 147ed1d1db98b9e8c1366699145c94a6d5aafbf8
4
- data.tar.gz: 4dc6e3beb64bcfaf53ff1dec7bad3154a6af58d4
3
+ metadata.gz: d1db9c8916de621822c30a27aafdbffa884c1d90
4
+ data.tar.gz: f7488684571f2310249f0d989194726164c19647
5
5
  SHA512:
6
- metadata.gz: 3c3a986d4a8b6844c66c3393aad32d87d03946484222bfb8eacf3308584ead9472f3f07fff98d6c356549ec933a8ac30d99c2c14161485cf7fe1bb55e3afd8a9
7
- data.tar.gz: 8742b3452937a90d5e53f48edfbcf9820f78f6147cbc01cb81dde6fafa809184227f054968af97349af0eeb11c334db43f03e0c6e90000e1310f43a5bebb6ec9
6
+ metadata.gz: 16b2d8802abf708d86fda857431e40ade70f77a6aed30594a5c624f8e193902f7755afcf6297bd6f7b3ad6c9f1e563cc06bfa26de953d7df24608c4b5774e107
7
+ data.tar.gz: 37fc9f119a1824a882ce9dbf0448b79c73a08cfcbcdbe9e486ee8ec4e16feb7744059a67cc781fddfbc5f7543ee62a6c6cfa93cf90298956276956ffe971b27e
@@ -6,18 +6,23 @@ $(document).ready(function() {
6
6
  new MultipleUpload($multipleUploadLink);
7
7
  }
8
8
 
9
- new MultipleUploadsPhotos();
9
+ new imageContainerManager();
10
10
  });
11
11
 
12
- var MultipleUploadsPhotos = function(){
12
+ var imageContainerManager = function(){
13
13
  var _this = this;
14
14
  this.$container = $('.lol-multiple-uploads.images-container');
15
+ this.hasCaption = Boolean(this.$container.data('has-caption'));
15
16
 
16
17
  this.startup = function(){
17
18
  this.$container.on('click', 'figure a', function(event) {
18
19
  _this.removeImage($(this));
19
20
  return false;
20
21
  });
22
+
23
+ if (this.hasCaption){
24
+ new imageCaptionManager(this.$container);
25
+ };
21
26
  },
22
27
 
23
28
  this.removeImage = function($link){
@@ -45,14 +50,48 @@ var MultipleUploadsPhotos = function(){
45
50
  this.startup();
46
51
  }
47
52
 
53
+ var imageCaptionManager = function($container){
54
+ var _this = this;
55
+ _this.$container = $container;
56
+
57
+ this.startup = function(){
58
+ this.$container.on('focusout', 'figure input:text', function(event) {
59
+ event.preventDefault();
60
+ var field = $(this);
61
+ _this.updateImageCaption(field.val(), field.closest('figure').data('id'));
62
+ });
63
+ },
64
+
65
+ this.updateImageCaption = function(text, image_id){
66
+ $.ajax({
67
+ url: '/update-image/'+image_id,
68
+ type: 'PUT',
69
+ dataType: 'json',
70
+ data: {photo: {caption: text}},
71
+ })
72
+ .done(function() {
73
+ console.log("success");
74
+ })
75
+ .fail(function() {
76
+ console.log("error");
77
+ })
78
+ .always(function() {
79
+ console.log("complete");
80
+ });
81
+
82
+ }
83
+
84
+ this.startup();
85
+ }
86
+
48
87
  var MultipleUpload = function(link){
49
88
  var that = this;
50
89
  this.link = link;
51
- this.model = this.link.attr('data-model');
52
- this.model_id = this.link.attr('data-model-id');
53
- this.storeImagePath = this.link.attr('data-store-path');
54
- this.filePickerKey = this.link.attr('data-file-picker-key');
55
- this.imageContainer = this.link.attr('data-image-container');
90
+ this.model = this.link.data('model');
91
+ this.model_id = this.link.data('model-id');
92
+ this.storeImagePath = this.link.data('store-path');
93
+ this.filePickerKey = this.link.data('file-picker-key');
94
+ this.imageContainer = this.link.data('image-container');
56
95
 
57
96
  this.startup = function(){
58
97
  this.link.on('click', function(event) {
@@ -75,7 +114,7 @@ var MultipleUpload = function(link){
75
114
  $.ajax({
76
115
  url: that.storeImagePath,
77
116
  type: 'POST',
78
- dataType: 'json',
117
+ dataType: 'html',
79
118
  data: {model: that.model, model_id: that.model_id, photo: val.url},
80
119
  beforeSend: function(xhr){
81
120
  that.showLoading();
@@ -93,12 +132,7 @@ var MultipleUpload = function(link){
93
132
  });
94
133
  },
95
134
 
96
- this.appendImage = function(obj){
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
-
135
+ this.appendImage = function(html){
102
136
  $(this.imageContainer).append(html);
103
137
  },
104
138
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  .lol-multiple-uploads.images-container figure{
8
8
  width: 120px;
9
- height: 120px;
9
+ min-height: 120px;
10
10
  float: left;
11
11
  padding: 0px;
12
12
  margin: 5px;
@@ -18,10 +18,15 @@
18
18
  cursor: move;
19
19
  }
20
20
 
21
+ .lol-multiple-uploads.images-container figure img{
22
+ height: 120px;
23
+ width: 120px;
24
+ }
25
+
21
26
  .lol-multiple-uploads.images-container figure a{
22
27
  position: absolute;
23
- bottom: -36px;
24
- left: 0px;
28
+ top: 94px;
29
+ left: -120px;
25
30
  width: 100%;
26
31
  padding: 5px 0;
27
32
  color: #fff;
@@ -38,7 +43,7 @@
38
43
  }
39
44
 
40
45
  .lol-multiple-uploads.images-container figure:hover a{
41
- bottom: 0px;
46
+ left: 0px;
42
47
  -webkit-transition: all 200ms ease-in-out;
43
48
  -moz-transition: all 200ms ease-in-out;
44
49
  -ms-transition: all 200ms ease-in-out;
@@ -49,3 +54,8 @@
49
54
  .lol-multiple-uploads.images-container img{
50
55
  max-width: 100%;
51
56
  }
57
+
58
+ .lol-multiple-uploads.images-container[data-has-caption="true"] figure input[type='text']{
59
+ border: 1px solid #cacaca;
60
+ width: 116px;
61
+ }
@@ -8,13 +8,26 @@ class PhotosController < ActionController::Base
8
8
  respond_with(@photo) do |format|
9
9
  if @photo.save
10
10
  format.json{ render json: @photo }
11
+ format.js { render partial: '/layouts/lol_multiple_uploads/photo', locals: { photo: @photo } }
11
12
  else
12
13
  format.json{ render nothing: true, status: :error }
13
14
  end
14
15
  end
15
16
  rescue Exception
16
17
  render nothing: true, status: :error
17
- end
18
+ end
19
+
20
+ def update
21
+ @photo = Photo.find params[:id]
22
+
23
+ respond_with(@photo) do |format|
24
+ if @photo.update_attributes(params[:photo])
25
+ format.json{ render json: @photo }
26
+ else
27
+ format.json{ render nothing: true, status: :error }
28
+ end
29
+ end
30
+ end
18
31
 
19
32
  def destroy
20
33
  @photo = Photo.find params[:id]
@@ -1,7 +1,7 @@
1
1
  module ImageHelper
2
2
 
3
3
  def list_photos(resource)
4
- content_tag(:div, class: 'lol-multiple-uploads images-container is-sortable', 'data-resource' => 'photo') do
4
+ content_tag(:div, class: 'lol-multiple-uploads images-container is-sortable', 'data-resource' => 'photo', 'data-has-caption' => resource.class.caption_status) do
5
5
  render partial: '/layouts/lol_multiple_uploads/photo', collection: resource.photos.prioritized
6
6
  end
7
7
  end
@@ -1,5 +1,5 @@
1
1
  module UploadHelper
2
2
  def upload_link(name='Upload File', object=nil, image_container='.images-container')
3
- link_to(name, 'javascript://', class: 'multiple_upload', 'data-model' => object.class, 'data-model-id' => object.id, 'data-store-path' => upload_image_path(format: 'json'), 'data-file-picker-key' => "#{PICKER_KEY}", 'data-image-container' => image_container) unless object.nil? || object.new_record?
3
+ link_to(name, 'javascript://', class: 'multiple_upload', 'data-model' => object.class, 'data-model-id' => object.id, 'data-store-path' => upload_image_path(format: 'js'), 'data-file-picker-key' => "#{PICKER_KEY}", 'data-image-container' => image_container) unless object.nil? || object.new_record?
4
4
  end
5
5
  end
data/app/models/photo.rb CHANGED
@@ -8,4 +8,12 @@ class Photo
8
8
  belongs_to :photable, polymorphic: true
9
9
 
10
10
  validates :photable, presence: true
11
+
12
+ field :caption
13
+
14
+ validates :caption, presence: true, if: :has_caption?, on: :update
15
+
16
+ def has_caption?
17
+ self.photable.present? && self.photable.caption_status
18
+ end
11
19
  end
@@ -0,0 +1,3 @@
1
+ <%= form_for photo, url: update_image_path(photo) do |f|%>
2
+ <%= f.text_field :caption, placeholder: 'pt-BR' %>
3
+ <% end %>
@@ -1,4 +1,5 @@
1
1
  <figure data-id="<%= photo.id %>">
2
2
  <%= image_tag(photo.image.url)%>
3
3
  <%= link_to "Remover", remove_image_path(photo, format: 'json'), method: :delete %>
4
+ <%= render partial: '/layouts/lol_multiple_uploads/photo-caption', locals: {photo: photo} if photo.has_caption? %>
4
5
  </figure>
data/config/routes.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  Rails.application.routes.draw do
2
-
3
2
  post '/upload-image' => 'photos#create' , as: :upload_image
3
+ put '/update-image/:id' => 'photos#update' , as: :update_image
4
4
  delete '/remove-image/:id' => 'photos#destroy', as: :remove_image
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module LolMultipleUploads
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,12 +1,35 @@
1
+ # module Mongoid
2
+ # module LolMultipleImages
3
+ # extend ActiveSupport::Concern
4
+
5
+ # included do
6
+ # cattr_accessor :caption_status
7
+
8
+ # has_many :photos, as: :photable
9
+ # end
10
+
11
+ # module ClassMethods
12
+ # def images_caption(option=false)
13
+ # self.caption_status = option
14
+ # end
15
+ # end
16
+ # end
17
+ # end
18
+
1
19
  module Mongoid
2
- module LolMultipleImages
3
- extend ActiveSupport::Concern
20
+ module LolMultipleImages
21
+ extend ActiveSupport::Concern
22
+
23
+ included do
24
+ cattr_accessor :caption_status
4
25
 
5
- included do
6
26
  has_many :photos, as: :photable
7
27
  end
8
-
9
- module ClassMethods
10
- end
11
- end
28
+
29
+ module ClassMethods
30
+ def multiple_uploads(option={})
31
+ self.caption_status = option[:caption] || false # config
32
+ end
33
+ end
34
+ end
12
35
  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: 1.0.2
4
+ version: 1.1.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-09-12 00:00:00.000000000 Z
11
+ date: 2013-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -96,6 +96,7 @@ files:
96
96
  - app/helpers/upload_helper.rb
97
97
  - app/models/photo.rb
98
98
  - app/uploaders/image_uploader.rb
99
+ - app/views/layouts/lol_multiple_uploads/_photo-caption.html.erb
99
100
  - app/views/layouts/lol_multiple_uploads/_photo.html.erb
100
101
  - config/initializers/init_lol_multiple_uploads.rb
101
102
  - config/routes.rb