diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index b4151a935..620fa8e40 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -4,11 +4,12 @@ class StatusMessagesController < ApplicationController before_filter :authenticate_user! - + before_filter :remove_getting_started, :only => [:create] - respond_to :html - respond_to :mobile + respond_to :html, + :mobile, + :json # Called when a user clicks "Mention" on a profile page # @param person_id [Integer] The id of the person to be mentioned @@ -40,8 +41,7 @@ class StatusMessagesController < ApplicationController end def create - params[:status_message][:aspect_ids] = params[:aspect_ids] - + params[:status_message][:aspect_ids] = [*params[:aspect_ids]] normalize_public_flag! @status_message = current_user.build_post(:status_message, params[:status_message]) @@ -69,9 +69,9 @@ class StatusMessagesController < ApplicationController end respond_to do |format| - format.js { render :create, :status => 201} format.html { redirect_to :back} format.mobile{ redirect_to multi_path} + format.json{ render :json => @status_message.as_api_response(:backbone), :status => 201 } end else unless photos.empty? diff --git a/app/views/shared/_publisher.html.haml b/app/views/shared/_publisher.html.haml index 3651113b9..c9c8bda0a 100644 --- a/app/views/shared/_publisher.html.haml +++ b/app/views/shared/_publisher.html.haml @@ -24,7 +24,7 @@ #publisher.closed{:class => ((aspect == :profile)? 'mention_popup' : nil )} .content_creation - = form_for(StatusMessage.new, :remote => remote?, :html => {"data-type" => "json"}) do |status| + = form_for(StatusMessage.new) do |status| = status.error_messages %p %params @@ -81,7 +81,7 @@ - for aspect in all_aspects = aspect_dropdown_list_item(aspect, !all_aspects_selected?(selected_aspects) && selected_aspects.include?(aspect) ) - = status.submit t('.share'), :disable_with => t('.posting'), :class => 'button creation', :tabindex => 2 + = status.submit t('.share'), :disabled => publisher_hidden_text.blank?, :disable_with => t('.posting'), :class => 'button creation', :tabindex => 2 .facebox_content #question_mark_pane diff --git a/public/javascripts/app/collections/stream.js b/public/javascripts/app/collections/stream.js index c0de92043..49148dfd2 100644 --- a/public/javascripts/app/collections/stream.js +++ b/public/javascripts/app/collections/stream.js @@ -1,6 +1,7 @@ app.collections.Stream = Backbone.Collection.extend({ url: function() { - var path = document.location.pathname + ".json"; + var path = document.location.pathname; + if(this.models.length) { path += "?max_time=" + _.last(this.models).createdAt(); } diff --git a/public/javascripts/app/models/post.js b/public/javascripts/app/models/post.js index 97f8e3528..6288503f2 100644 --- a/public/javascripts/app/models/post.js +++ b/public/javascripts/app/models/post.js @@ -8,7 +8,11 @@ app.models.Post = Backbone.Model.extend({ }, url: function(){ - return "/posts/" + this.id; + if(this.id) { + return "/posts/" + this.id; + } else { + return "/status_messages" + } }, createdAt: function(){ diff --git a/public/javascripts/app/views/post_view.js b/public/javascripts/app/views/post_view.js index 1dbece577..15479fb8e 100644 --- a/public/javascripts/app/views/post_view.js +++ b/public/javascripts/app/views/post_view.js @@ -24,7 +24,6 @@ app.views.Post = app.views.StreamObject.extend({ initialize : function() { this.feedbackView = new app.views.Feedback({model : this.model}); this.commentStreamView = new app.views.CommentStream({ model : this.model}); - return this; }, diff --git a/public/javascripts/app/views/publisher_view.js b/public/javascripts/app/views/publisher_view.js new file mode 100644 index 000000000..677128054 --- /dev/null +++ b/public/javascripts/app/views/publisher_view.js @@ -0,0 +1,82 @@ +app.views.Publisher = Backbone.View.extend({ + + el : "#publisher", + + events : { + "focus textarea" : "open", + "click #hide_publisher" : "close", + "submit form" : "createStatusMessage" + }, + + initialize : function(){ + this.collection = this.collection || new app.collections.Stream; + return this; + }, + + createStatusMessage : function(evt) { + if(evt){ evt.preventDefault(); } + + var serializedForm = $(evt.target).closest("form").serializeObject(); + + this.collection.create({ + "status_message" : { + "text" : serializedForm["status_message[text]"] + }, + "aspect_ids" : serializedForm["aspect_ids[]"] + }); + + // clear state + this.clear(); + }, + + clear : function() { + // remove form data + _.each(this.$('textarea'), function(element) { + $(element).removeClass("with_attachments") + .css("paddingBottom", "") + .val(""); + }); + + // remove photos + this.$("#photodropzone").find('li').remove(); + + // close publishing area (CSS) + this.close(); + + return this; + }, + + open : function() { + $(this.el).removeClass('closed'); + this.$("#publisher_textarea_wrapper").addClass('active'); + this.$("textarea.ac_input").css('min-height', '42px'); + + return this; + }, + + close : function() { + $(this.el).addClass("closed"); + this.$("#publisher_textarea_wrapper").removeClass("active"); + this.$("textarea.ac_input").css('min-height', ''); + + return this; + } +}); + +// jQuery helper for serializing a