diaspora/public/javascripts/app/views/publisher_view.js
danielgrippi b583a7a444 Put dennis's changes back in
Revert "Revert "refactoring backbone urls""

This reverts commit 838da1fd52.

Revert "revert 9b1d64bb76 as it is causing inf. scroll to break (stream model now has a post collection)"

This reverts commit 2a69c0ebd4.
2012-01-19 17:05:30 -08:00

96 lines
2.3 KiB
JavaScript

//this file is the scary no-no-zone bad-touch of our backbone code.
//after re-writing/eliminating the existing Publisher let's re-write
//this with PANACHE!
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.Posts;
return this;
},
createStatusMessage : function(evt) {
if(evt){ evt.preventDefault(); }
var serializedForm = $(evt.target).closest("form").serializeObject();
// save status message
var statusMessage = new app.models.StatusMessage();
statusMessage.save({
"status_message" : {
"text" : serializedForm["status_message[text]"]
},
"aspect_ids" : serializedForm["aspect_ids[]"],
"photos" : serializedForm["photos[]"],
"services" : serializedForm["services[]"]
}, {
url : "/status_messages",
success : function() {
app.stream.posts.add(statusMessage.toJSON());
}
});
// clear state
this.clear();
},
clear : function() {
this.$('textarea')
.removeClass("with_attachments")
.css("paddingBottom", "")
.val("");
// remove photos
this.$("#photodropzone").find('li').remove();
this.$("input[name='photos[]']").remove();
// close publishing area (CSS)
this.close();
// clear mentions (TO BE REMOVED!!)
Publisher.autocompletion.mentionList.clear()
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 <form> into JSON
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};