Skip to content
Extraits de code Groupes Projets
Valider 7fb751b0 rédigé par maxwell's avatar maxwell Validation de danielvincent
Parcourir les fichiers

making photo uploader work better

parent 242d0ab9
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -9,7 +9,7 @@ class AspectsController < ApplicationController ...@@ -9,7 +9,7 @@ class AspectsController < ApplicationController
respond_to :json, :only => :show respond_to :json, :only => :show
def index def index
@posts = current_user.visible_posts(:by_members_of => :all).paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC' @posts = current_user.visible_posts(:by_members_of => :all, :pending => false).paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC'
@aspect = :all @aspect = :all
if current_user.getting_started == true if current_user.getting_started == true
......
...@@ -34,7 +34,6 @@ class PhotosController < ApplicationController ...@@ -34,7 +34,6 @@ class PhotosController < ApplicationController
end end
def create def create
begin begin
params[:photo][:user_file] = file_handler(params) params[:photo][:user_file] = file_handler(params)
...@@ -43,9 +42,9 @@ class PhotosController < ApplicationController ...@@ -43,9 +42,9 @@ class PhotosController < ApplicationController
if @photo.save if @photo.save
raise 'MongoMapper failed to catch a failed save' unless @photo.id raise 'MongoMapper failed to catch a failed save' unless @photo.id
current_user.dispatch_post(@photo, :to => params[:photo][:to]) current_user.dispatch_post(@photo, :to => params[:photo][:to]) unless @photo.pending
respond_to do |format| respond_to do |format|
format.json{render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )} format.json{ render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
end end
else else
respond_with :location => photos_path, :error => message respond_with :location => photos_path, :error => message
......
...@@ -9,6 +9,7 @@ class StatusMessagesController < ApplicationController ...@@ -9,6 +9,7 @@ class StatusMessagesController < ApplicationController
respond_to :json, :only => :show respond_to :json, :only => :show
def create def create
puts params.inspect
public_flag = params[:status_message][:public] public_flag = params[:status_message][:public]
public_flag.to_s.match(/(true)/) ? public_flag = true : public_flag = false public_flag.to_s.match(/(true)/) ? public_flag = true : public_flag = false
params[:status_message][:public] = public_flag params[:status_message][:public] = public_flag
......
...@@ -14,6 +14,7 @@ class Photo < Post ...@@ -14,6 +14,7 @@ class Photo < Post
key :remote_photo_path key :remote_photo_path
key :remote_photo_name key :remote_photo_name
key :random_string key :random_string
timestamps! timestamps!
...@@ -76,5 +77,15 @@ class Photo < Post ...@@ -76,5 +77,15 @@ class Photo < Post
1.upto(len) { |i| string << chars[rand(chars.size-1)] } 1.upto(len) { |i| string << chars[rand(chars.size-1)] }
return string return string
end end
def as_json(opts={})
{
:photo => {
:id => self.id,
:url => self.url(:thumb_small)
}
}
end
end end
...@@ -20,6 +20,7 @@ class Post ...@@ -20,6 +20,7 @@ class Post
key :diaspora_handle, String key :diaspora_handle, String
key :user_refs, Integer, :default => 0 key :user_refs, Integer, :default => 0
key :pending, Boolean, :default => false
many :comments, :class_name => 'Comment', :foreign_key => :post_id, :order => 'created_at ASC' many :comments, :class_name => 'Comment', :foreign_key => :post_id, :order => 'created_at ASC'
belongs_to :person, :class_name => 'Person' belongs_to :person, :class_name => 'Person'
...@@ -33,10 +34,12 @@ class Post ...@@ -33,10 +34,12 @@ class Post
after_destroy :destroy_comments after_destroy :destroy_comments
attr_accessible :user_refs attr_accessible :user_refs
def self.instantiate params def self.instantiate params
new_post = self.new params.to_hash new_post = self.new params.to_hash
new_post.person = params[:person] new_post.person = params[:person]
new_post.public = params[:public] new_post.public = params[:public]
new_post.pending = params[:pending]
new_post.diaspora_handle = new_post.person.diaspora_handle new_post.diaspora_handle = new_post.person.diaspora_handle
new_post new_post
end end
......
...@@ -3,31 +3,24 @@ ...@@ -3,31 +3,24 @@
-# the COPYRIGHT file. -# the COPYRIGHT file.
:javascript :javascript
function createUploader(){ function createUploader(){
var uploader = new qq.FileUploader({ var uploader = new qq.FileUploaderBasic({
element: document.getElementById('file-upload'), element: document.getElementById('file-upload'),
params: {'photo' : { 'to' : "#{aspect_id}"}, 'set_profile_image' : "#{set_profile_image if defined?(set_profile_image)}"}, params: {'photo' : {'pending' : 'true', 'to' : "#{aspect_id}"}, 'set_profile_image' : "#{set_profile_image if defined?(set_profile_image)}"},
allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'], allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
action: "#{photos_path}", action: "#{photos_path}",
template: '<div class="qq-uploader">' + debug: true,
'<div class="qq-upload-drop-area"><span>#{t('.drop')}</span></div>' + button: document.getElementById('file-upload'),
'<div class="qq-upload-button">#{t('.upload')}</div>' + sizeLimit: 5000048,
'<ul class="qq-upload-list"></ul>' + onComplete: function(id, fileName, responseJSON){
'</div>', //var obj = jQuery.parseJSON(responseJSON.data);
fileTemplate: '<li>' + alert(responseJSON.data.photo.url);
'<span class="qq-upload-file"></span>' + var id = responseJSON.data.photo.id;
'<span class="qq-upload-spinner"></span>' + alert($('#new_status_message').length);
'<span class="qq-upload-size"></span>' + $('#new_status_message').append("<input type='hidden' value='" + id + "' name='photos[]' />");
'<a class="qq-upload-cancel" href="#">#{t('cancel')}</a>' +
'<span class="qq-upload-failed-text">#{t('.failed')}</span>' + }
'</li>',
messages: { });
typeError: "#{t('.invalid_ext')}", }
sizeError: "#{t('.size_error')}", window.onload = createUploader;
emptyError: "#{t('.empty')}"
}
});
}
window.onload = createUploader;
#file-upload
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
}; };
}); });
$("#publisher textarea, #publisher input").live("focus", function(evt){ //$("#publisher textarea, #publisher input").live("focus", function(evt){
$("#publisher .options_and_submit").fadeIn(50); // $("#publisher .options_and_submit").fadeIn(50);
}); //});
$("#publisher form").live("submit", function(evt){ $("#publisher form").live("submit", function(evt){
$("#publisher .options_and_submit").hide(); $("#publisher .options_and_submit").hide();
...@@ -22,15 +22,18 @@ ...@@ -22,15 +22,18 @@
#publisher #publisher
= owner_image_link = owner_image_link
= form_for StatusMessage.new, :remote => true do |status| = form_for StatusMessage.new, :html => {:multipart => true,}, :remote => true do |status|
= status.error_messages = status.error_messages
%p %params
= status.label :message, t('.post_a_message_to', :aspect => (aspect == :all ? "everyone" : aspect)) = status.label :message, t('.post_a_message_to', :aspect => (aspect == :all ? "everyone" : aspect))
= status.text_area :message, :rows => 2, :value => params[:prefill] = status.text_area :message, :rows => 2, :value => params[:prefill]
= status.hidden_field :to, :value => (aspect == :all ? aspect : aspect.id) = status.hidden_field :to, :value => (aspect == :all ? aspect : aspect.id)
.options_and_submit .options_and_submit
#file-upload.button
drag a photo to upload
- if aspect == :all - if aspect == :all
= status.submit t('.share'), :title => t('.share_with_all'), :disable_with => t('.posting') = status.submit t('.share'), :title => t('.share_with_all'), :disable_with => t('.posting')
- else - else
...@@ -51,9 +54,3 @@ ...@@ -51,9 +54,3 @@
.fancybox_content .fancybox_content
#question_mark_pane #question_mark_pane
= render 'shared/public_explain' = render 'shared/public_explain'
/#publisher_photo_upload
/= t('or')
/= render 'photos/new_photo', :aspect_id => (aspect == :all ? aspect : aspect.id)
Ce diff est replié.
...@@ -762,7 +762,6 @@ label ...@@ -762,7 +762,6 @@ label
.options_and_submit .options_and_submit
:min-height 21px :min-height 21px
:position relative :position relative
:display none
:padding :padding
:top 8px :top 8px
:margin :margin
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter