added photos to status messages

This commit is contained in:
maxwell 2010-11-19 12:44:03 -08:00 committed by danielvincent
parent f6491816a3
commit fb0dc2db7e
7 changed files with 74 additions and 19 deletions

View file

@ -9,12 +9,22 @@ class StatusMessagesController < ApplicationController
respond_to :json, :only => :show respond_to :json, :only => :show
def create def create
puts params.inspect
@photos = Photo.all(:id.in => params[:photos])
puts @photos.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
status_message = current_user.build_post(:status_message, params[:status_message]) status_message = current_user.build_post(:status_message, params[:status_message])
status_message.photos += @photos
if status_message.save(:safe => true) if status_message.save(:safe => true)
raise 'MongoMapper failed to catch a failed save' unless status_message.id raise 'MongoMapper failed to catch a failed save' unless status_message.id
current_user.dispatch_post(status_message, :to => params[:status_message][:to]) current_user.dispatch_post(status_message, :to => params[:status_message][:to])

View file

@ -82,7 +82,7 @@ class Photo < Post
{ {
:photo => { :photo => {
:id => self.id, :id => self.id,
:url => self.url(:thumb_small) :url => self.url(:thumb_medium)
} }
} }
end end

View file

@ -9,6 +9,7 @@ class StatusMessage < Post
xml_accessor :message xml_accessor :message
key :message, String key :message, String
many :photos, :class => Photo
validates_presence_of :message validates_presence_of :message
attr_accessible :message attr_accessible :message

View file

@ -12,13 +12,17 @@
debug: true, debug: true,
button: document.getElementById('file-upload'), button: document.getElementById('file-upload'),
sizeLimit: 5000048, sizeLimit: 5000048,
onSubmit: function(id, fileName){
$('#file-upload').text("loading");
},
onComplete: function(id, fileName, responseJSON){ onComplete: function(id, fileName, responseJSON){
//var obj = jQuery.parseJSON(responseJSON.data); $('#file-upload').text("add photos");
alert(responseJSON.data.photo.url);
var id = responseJSON.data.photo.id; var id = responseJSON.data.photo.id;
alert($('#new_status_message').length); var url = responseJSON.data.photo.url;
$('#new_status_message').append("<input type='hidden' value='" + id + "' name='photos[]' />"); $('#new_status_message').append("<input type='hidden' value='" + id + "' name='photos[]' />");
$('#photodropzone').append("<li><img src='" + url +"' data-id='" + id + "' /></li>");
} }
}); });

View file

@ -15,25 +15,27 @@
// $("#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();
}); //});
#publisher #publisher
= owner_image_link = owner_image_link
= form_for StatusMessage.new, :html => {:multipart => true,}, :remote => true do |status| = form_for StatusMessage.new, :html => {:multipart => true,}, :remote => true do |status|
%ul#photodropzone
= status.error_messages = status.error_messages
%params #file-upload.button
= status.label :message, t('.post_a_message_to', :aspect => (aspect == :all ? "everyone" : aspect)) add photos
= status.text_area :message, :rows => 2, :value => params[:prefill]
%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) = 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
@ -54,5 +56,5 @@
.fancybox_content .fancybox_content
#question_mark_pane #question_mark_pane
= render 'shared/public_explain' = render 'shared/public_explain'
#publisher_photo_upload #publisher_photo_upload
= render 'photos/new_photo', :aspect_id => (aspect == :all ? aspect : aspect.id) = render 'photos/new_photo', :aspect_id => (aspect == :all ? aspect : aspect.id)

View file

@ -3,3 +3,7 @@
-# the COPYRIGHT file. -# the COPYRIGHT file.
= markdownify(post.message) = markdownify(post.message)
%br
- for photo in post.photos
/= render 'photos/photo', :post => photo
= image_tag photo.url(:thumb_medium)

View file

@ -29,6 +29,9 @@ a
h1, h2, h3, h4 h1, h2, h3, h4
:color #444 :color #444
ol, ul
:list-style none
.hidden .hidden
:display none :display none
@ -720,6 +723,30 @@ label
:text :text
:shadow 0 1px 1px #eee :shadow 0 1px 1px #eee
#file-upload
:z-index 5
:float right
:height 34px
:width 70px
:margin 0
:background
:color #107FC9
:-webkit-border-radius 0 5px 5px 0
:-moz-border-radius 0 5px 5px 0
:border-radius 0 5px 5px 0
:background -webkit-gradient( linear, left bottom, left top, color-stop(0, rgb(0,123,194)), color-stop(1, rgb(65,182,250)))
:background -moz-linear-gradient( center bottom, rgb(0,123,194) 0%, rgb(65,182,250) 100%)
:padding 9px
:font
:size 18px
:weight bold
:color #eee
:text-shadow 0 1px 0 #333
#publisher #publisher
:color #999 :color #999
:position relative :position relative
@ -747,13 +774,20 @@ label
:left 65px :left 65px
:top 0 :top 0
ul
>li
:display inline
:margin-right 2px
img
:border-radius 5px
textarea textarea
:height 42px :height 42px
:display block
input[type='text'], input[type='text'],
textarea textarea
:width 490px :width 400px
:margin 0 :margin 0
.options_and_submit .options_and_submit