uploaded photos show in the publisher textarea instead of outside and above. fixed comment textarea on show pages.

This commit is contained in:
danielvincent 2010-12-18 22:39:56 -08:00
parent 4425c3df83
commit bb0375d2f8
5 changed files with 49 additions and 21 deletions

View file

@ -17,7 +17,7 @@ class Photo < Post
key :random_string key :random_string
key :status_message_id, ObjectId key :status_message_id, ObjectId
timestamps! timestamps!
belongs_to :status_message belongs_to :status_message
@ -30,8 +30,8 @@ class Photo < Post
#before_destroy :delete_parent_if_no_photos_or_message #before_destroy :delete_parent_if_no_photos_or_message
def ownership_of_status_message def ownership_of_status_message
message = StatusMessage.find_by_id(self.status_message_id) message = StatusMessage.find_by_id(self.status_message_id)
if status_message_id && message if status_message_id && message
self.diaspora_handle == message.diaspora_handle self.diaspora_handle == message.diaspora_handle
else else
true true
end end
@ -85,7 +85,7 @@ class Photo < Post
pod_url.chop! if APP_CONFIG[:pod_url][-1,1] == '/' pod_url.chop! if APP_CONFIG[:pod_url][-1,1] == '/'
"#{pod_url}#{url(*args)}" "#{pod_url}#{url(*args)}"
end end
def self.gen_random_string(len) def self.gen_random_string(len)
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
string = "" string = ""
@ -98,11 +98,12 @@ class Photo < Post
:photo => { :photo => {
:id => self.id, :id => self.id,
:url => self.url(:thumb_medium), :url => self.url(:thumb_medium),
:thumb_small => self.url(:thumb_small),
:caption => self.caption :caption => self.caption
} }
} }
end end
def self.hash_from_post_ids post_ids def self.hash_from_post_ids post_ids
hash = {} hash = {}
photos = self.on_statuses(post_ids) photos = self.on_statuses(post_ids)
@ -115,7 +116,7 @@ class Photo < Post
hash.each_value {|photos| photos.sort!{|p1, p2| p1.created_at <=> p2.created_at }} hash.each_value {|photos| photos.sort!{|p1, p2| p1.created_at <=> p2.created_at }}
hash hash
end end
scope :on_statuses, lambda { |post_ids| scope :on_statuses, lambda { |post_ids|
where(:status_message_id.in => post_ids) where(:status_message_id.in => post_ids)
} }

View file

@ -13,7 +13,6 @@
button: document.getElementById('file-upload'), button: document.getElementById('file-upload'),
sizeLimit: 4194304, sizeLimit: 4194304,
onProgress: function(id, fileName, loaded, total){ onProgress: function(id, fileName, loaded, total){
var progress = Math.round(loaded / total * 100 ); var progress = Math.round(loaded / total * 100 );
$('#fileInfo').text(fileName + ' ' + progress + '%'); $('#fileInfo').text(fileName + ' ' + progress + '%');
@ -37,7 +36,10 @@
$("#publisher_spinner").fadeOut(100); $("#publisher_spinner").fadeOut(100);
$('#file-upload').removeClass("loading"); $('#file-upload').removeClass("loading");
var id = responseJSON.data.photo.id; var id = responseJSON.data.photo.id;
var url = responseJSON.data.photo.url; var url = responseJSON.data.photo.thumb_small;
$("#publisher textarea").addClass("with_attachments");
$('#new_status_message').append("<input type='hidden' value='" + id + "' name='photos[]' />"); $('#new_status_message').append("<input type='hidden' value='" + id + "' name='photos[]' />");
$('#photodropzone').append( $('#photodropzone').append(
"<li style='position:relative;'>" + "<li style='position:relative;'>" +

View file

@ -39,7 +39,6 @@
.content_creation .content_creation
= form_for(StatusMessage.new, :remote => true) do |status| = form_for(StatusMessage.new, :remote => true) do |status|
%ul#photodropzone
= status.error_messages = status.error_messages
#file-upload #file-upload
= image_tag 'icons/photos.png' = image_tag 'icons/photos.png'
@ -48,7 +47,9 @@
%p %p
%params %params
= status.text_area :message, :rows => 2, :value => params[:prefill] #publisher_textarea_wrapper
%ul#photodropzone
= status.text_area :message, :rows => 2, :value => params[:prefill]
= status.hidden_field :aspect_ids, :value => (aspect == :all ? aspect : aspect.id) = status.hidden_field :aspect_ids, :value => (aspect == :all ? aspect : aspect.id)

View file

@ -27,6 +27,8 @@ var Stream = {
$stream.delegate("textarea.comment_box", "focus", function(evt) { $stream.delegate("textarea.comment_box", "focus", function(evt) {
var commentBox = $(this); var commentBox = $(this);
commentBox commentBox
.attr('rows',2)
.addClass('force_open')
.closest("li").find(".submit_instructions").removeClass('hidden'); .closest("li").find(".submit_instructions").removeClass('hidden');
}); });
@ -34,8 +36,9 @@ var Stream = {
var commentBox = $(this); var commentBox = $(this);
if (!commentBox.val()) { if (!commentBox.val()) {
commentBox commentBox
.attr('rows',2) .attr('rows',1)
.css('height','2.4em') .removeClass('force_open')
.css('height','1.4em')
.closest("li").find(".submit_instructions").addClass('hidden'); .closest("li").find(".submit_instructions").addClass('hidden');
} }
}); });
@ -92,12 +95,18 @@ var Stream = {
}); });
}); });
$(".new_status_message").bind('ajax:loading', function(data, json, xhr) {
$("#photodropzone").find('li').remove();
$("#publisher textarea").removeClass("with_attachments");
});
$(".new_status_message").bind('ajax:success', function(data, json, xhr) { $(".new_status_message").bind('ajax:success', function(data, json, xhr) {
json = $.parseJSON(json); json = $.parseJSON(json);
WebSocketReceiver.addPostToStream(json['post_id'], json['html']); WebSocketReceiver.addPostToStream(json['post_id'], json['html']);
//collapse publisher //collapse publisher
$("#publisher").addClass("closed"); $("#publisher").addClass("closed");
$("#photodropzone").find('li').remove(); $("#photodropzone").find('li').remove();
$("#publisher textarea").removeClass("with_attachments");
}); });
$(".new_status_message").bind('ajax:failure', function(data, html, xhr) { $(".new_status_message").bind('ajax:failure', function(data, html, xhr) {
alert('failed to post message!'); alert('failed to post message!');

View file

@ -40,7 +40,6 @@ form
:font :font
:size auto :size auto
.hidden .hidden
:display none :display none
@ -376,7 +375,7 @@ li.message
:right 5px :right 5px
&:hover &:hover
div.info, .time, .from div.info, .time, .from h4
a a
:color #107FC9 :color #107FC9
&:hover &:hover
@ -508,19 +507,17 @@ li.message
:background none :background none
:border none :border none
ul.comments
textarea
:width 324px
.stream ul.comments .stream ul.comments
.avatar .avatar
:width 30px :width 30px
:height 30px :height 30px
form
:margin
:right 12px
input.comment_submit input.comment_submit
:display none :display none
:margin
:right -10px
ul.comments ul.comments
:margin 0 :margin 0
@ -531,7 +528,10 @@ ul.comments
textarea textarea
:width 100% :width 100%
:height 2.4em :height 1.4em
.force_open
:min-height 2.4em
li.comment li.comment
:list :list
@ -910,6 +910,21 @@ label
&.loading &.loading
:opacity 0.5 :opacity 0.5
#publisher_textarea_wrapper
:position relative
textarea
:z-index 2
&.with_attachments
:padding
:bottom 70px
#photodropzone
:z-index 3
:position absolute
:bottom 0
:left 5px
.field_with_submit .field_with_submit
input[type='text'] input[type='text']
:width 82% :width 82%