making photo uploader work better
This commit is contained in:
parent
242d0ab9c5
commit
7fb751b00c
9 changed files with 800 additions and 617 deletions
|
|
@ -9,7 +9,7 @@ class AspectsController < ApplicationController
|
|||
respond_to :json, :only => :show
|
||||
|
||||
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
|
||||
|
||||
if current_user.getting_started == true
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ class PhotosController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
|
||||
begin
|
||||
params[:photo][:user_file] = file_handler(params)
|
||||
|
||||
|
|
@ -43,9 +42,9 @@ class PhotosController < ApplicationController
|
|||
if @photo.save
|
||||
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|
|
||||
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
|
||||
else
|
||||
respond_with :location => photos_path, :error => message
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ class StatusMessagesController < ApplicationController
|
|||
respond_to :json, :only => :show
|
||||
|
||||
def create
|
||||
puts params.inspect
|
||||
public_flag = params[:status_message][:public]
|
||||
public_flag.to_s.match(/(true)/) ? public_flag = true : public_flag = false
|
||||
params[:status_message][:public] = public_flag
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class Photo < Post
|
|||
key :remote_photo_path
|
||||
key :remote_photo_name
|
||||
key :random_string
|
||||
|
||||
|
||||
timestamps!
|
||||
|
||||
|
|
@ -76,5 +77,15 @@ class Photo < Post
|
|||
1.upto(len) { |i| string << chars[rand(chars.size-1)] }
|
||||
return string
|
||||
end
|
||||
|
||||
def as_json(opts={})
|
||||
{
|
||||
:photo => {
|
||||
:id => self.id,
|
||||
:url => self.url(:thumb_small)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class Post
|
|||
|
||||
key :diaspora_handle, String
|
||||
key :user_refs, Integer, :default => 0
|
||||
key :pending, Boolean, :default => false
|
||||
|
||||
many :comments, :class_name => 'Comment', :foreign_key => :post_id, :order => 'created_at ASC'
|
||||
belongs_to :person, :class_name => 'Person'
|
||||
|
|
@ -33,10 +34,12 @@ class Post
|
|||
after_destroy :destroy_comments
|
||||
|
||||
attr_accessible :user_refs
|
||||
|
||||
def self.instantiate params
|
||||
new_post = self.new params.to_hash
|
||||
new_post.person = params[:person]
|
||||
new_post.public = params[:public]
|
||||
new_post.pending = params[:pending]
|
||||
new_post.diaspora_handle = new_post.person.diaspora_handle
|
||||
new_post
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,31 +3,24 @@
|
|||
-# the COPYRIGHT file.
|
||||
|
||||
:javascript
|
||||
function createUploader(){
|
||||
var uploader = new qq.FileUploader({
|
||||
element: document.getElementById('file-upload'),
|
||||
params: {'photo' : { 'to' : "#{aspect_id}"}, 'set_profile_image' : "#{set_profile_image if defined?(set_profile_image)}"},
|
||||
allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
|
||||
action: "#{photos_path}",
|
||||
template: '<div class="qq-uploader">' +
|
||||
'<div class="qq-upload-drop-area"><span>#{t('.drop')}</span></div>' +
|
||||
'<div class="qq-upload-button">#{t('.upload')}</div>' +
|
||||
'<ul class="qq-upload-list"></ul>' +
|
||||
'</div>',
|
||||
fileTemplate: '<li>' +
|
||||
'<span class="qq-upload-file"></span>' +
|
||||
'<span class="qq-upload-spinner"></span>' +
|
||||
'<span class="qq-upload-size"></span>' +
|
||||
'<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')}",
|
||||
emptyError: "#{t('.empty')}"
|
||||
}
|
||||
});
|
||||
}
|
||||
window.onload = createUploader;
|
||||
|
||||
#file-upload
|
||||
function createUploader(){
|
||||
var uploader = new qq.FileUploaderBasic({
|
||||
element: document.getElementById('file-upload'),
|
||||
params: {'photo' : {'pending' : 'true', 'to' : "#{aspect_id}"}, 'set_profile_image' : "#{set_profile_image if defined?(set_profile_image)}"},
|
||||
allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
|
||||
action: "#{photos_path}",
|
||||
debug: true,
|
||||
button: document.getElementById('file-upload'),
|
||||
sizeLimit: 5000048,
|
||||
onComplete: function(id, fileName, responseJSON){
|
||||
//var obj = jQuery.parseJSON(responseJSON.data);
|
||||
alert(responseJSON.data.photo.url);
|
||||
var id = responseJSON.data.photo.id;
|
||||
alert($('#new_status_message').length);
|
||||
$('#new_status_message').append("<input type='hidden' value='" + id + "' name='photos[]' />");
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
window.onload = createUploader;
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
};
|
||||
});
|
||||
|
||||
$("#publisher textarea, #publisher input").live("focus", function(evt){
|
||||
$("#publisher .options_and_submit").fadeIn(50);
|
||||
});
|
||||
//$("#publisher textarea, #publisher input").live("focus", function(evt){
|
||||
// $("#publisher .options_and_submit").fadeIn(50);
|
||||
//});
|
||||
|
||||
$("#publisher form").live("submit", function(evt){
|
||||
$("#publisher .options_and_submit").hide();
|
||||
|
|
@ -22,15 +22,18 @@
|
|||
#publisher
|
||||
= 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
|
||||
%p
|
||||
%params
|
||||
= status.label :message, t('.post_a_message_to', :aspect => (aspect == :all ? "everyone" : aspect))
|
||||
= status.text_area :message, :rows => 2, :value => params[:prefill]
|
||||
|
||||
= status.hidden_field :to, :value => (aspect == :all ? aspect : aspect.id)
|
||||
|
||||
.options_and_submit
|
||||
#file-upload.button
|
||||
drag a photo to upload
|
||||
- if aspect == :all
|
||||
= status.submit t('.share'), :title => t('.share_with_all'), :disable_with => t('.posting')
|
||||
- else
|
||||
|
|
@ -51,9 +54,3 @@
|
|||
.fancybox_content
|
||||
#question_mark_pane
|
||||
= render 'shared/public_explain'
|
||||
|
||||
|
||||
/#publisher_photo_upload
|
||||
/= t('or')
|
||||
/= render 'photos/new_photo', :aspect_id => (aspect == :all ? aspect : aspect.id)
|
||||
|
||||
|
|
|
|||
1326
public/javascripts/vendor/fileuploader.js
vendored
1326
public/javascripts/vendor/fileuploader.js
vendored
File diff suppressed because it is too large
Load diff
|
|
@ -762,7 +762,6 @@ label
|
|||
.options_and_submit
|
||||
:min-height 21px
|
||||
:position relative
|
||||
:display none
|
||||
:padding
|
||||
:top 8px
|
||||
:margin
|
||||
|
|
|
|||
Loading…
Reference in a new issue