Refactor publisher backbone view
This commit is contained in:
parent
9217df43cd
commit
b23debf0b6
2 changed files with 10 additions and 23 deletions
|
|
@ -22,7 +22,7 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
"focus textarea" : "open",
|
"focus textarea" : "open",
|
||||||
"submit form" : "createStatusMessage",
|
"submit form" : "createStatusMessage",
|
||||||
"click #submit" : "createStatusMessage",
|
"click #submit" : "createStatusMessage",
|
||||||
"textchange #status_message_text": "handleTextchange",
|
"textchange #status_message_text": "checkSubmitAvailability",
|
||||||
"click #locator" : "showLocation",
|
"click #locator" : "showLocation",
|
||||||
"click #poll_creator" : "togglePollCreator",
|
"click #poll_creator" : "togglePollCreator",
|
||||||
"click #hide_location" : "destroyLocation",
|
"click #hide_location" : "destroyLocation",
|
||||||
|
|
@ -154,7 +154,7 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
this.viewPollCreator.render();
|
this.viewPollCreator.render();
|
||||||
|
|
||||||
if (this.prefillMention) {
|
if (this.prefillMention) {
|
||||||
this.handleTextchange();
|
this.checkSubmitAvailability();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -170,7 +170,7 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
|
|
||||||
this.inputEl.trigger("input");
|
this.inputEl.trigger("input");
|
||||||
autosize.update(this.inputEl);
|
autosize.update(this.inputEl);
|
||||||
this.handleTextchange();
|
this.checkSubmitAvailability();
|
||||||
},
|
},
|
||||||
|
|
||||||
// show the "getting started" popups around the publisher
|
// show the "getting started" popups around the publisher
|
||||||
|
|
@ -242,7 +242,7 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
self.setButtonsEnabled(true);
|
self.setButtonsEnabled(true);
|
||||||
self.setInputEnabled(true);
|
self.setInputEnabled(true);
|
||||||
self.wrapperEl.removeClass("submitting");
|
self.wrapperEl.removeClass("submitting");
|
||||||
self.handleTextchange();
|
self.checkSubmitAvailability();
|
||||||
autosize.update(self.inputEl);
|
autosize.update(self.inputEl);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -318,9 +318,7 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
|
|
||||||
createPostPreview: function() {
|
createPostPreview: function() {
|
||||||
var serializedForm = $("#new_status_message").serializeObject();
|
var serializedForm = $("#new_status_message").serializeObject();
|
||||||
var text = serializedForm["status_message[text]"];
|
|
||||||
var photos = this.getUploadedPhotos();
|
var photos = this.getUploadedPhotos();
|
||||||
var mentionedPeople = this.mention.getMentionedPeople();
|
|
||||||
var poll = this.getPollData(serializedForm);
|
var poll = this.getPollData(serializedForm);
|
||||||
var locationCoords = serializedForm["location[coords]"];
|
var locationCoords = serializedForm["location[coords]"];
|
||||||
if(!locationCoords || locationCoords === "") {
|
if(!locationCoords || locationCoords === "") {
|
||||||
|
|
@ -336,12 +334,12 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
|
|
||||||
var previewMessage = {
|
var previewMessage = {
|
||||||
"id": 0,
|
"id": 0,
|
||||||
"text": text,
|
"text": serializedForm["status_message[text]"],
|
||||||
"public": serializedForm["aspect_ids[]"] === "public",
|
"public": serializedForm["aspect_ids[]"] === "public",
|
||||||
"created_at": new Date().toISOString(),
|
"created_at": new Date().toISOString(),
|
||||||
"interacted_at": new Date().toISOString(),
|
"interacted_at": new Date().toISOString(),
|
||||||
"author": app.currentUser ? app.currentUser.attributes : {},
|
"author": app.currentUser ? app.currentUser.attributes : {},
|
||||||
"mentioned_people": mentionedPeople,
|
"mentioned_people": this.mention.getMentionedPeople(),
|
||||||
"photos": photos,
|
"photos": photos,
|
||||||
"title": serializedForm["status_message[text]"],
|
"title": serializedForm["status_message[text]"],
|
||||||
"location": location,
|
"location": location,
|
||||||
|
|
@ -454,8 +452,7 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
setEnabled: function(bool) {
|
setEnabled: function(bool) {
|
||||||
this.setInputEnabled(bool);
|
this.setInputEnabled(bool);
|
||||||
this.disabled = !bool;
|
this.disabled = !bool;
|
||||||
|
this.checkSubmitAvailability();
|
||||||
this.handleTextchange();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setButtonsEnabled: function(bool) {
|
setButtonsEnabled: function(bool) {
|
||||||
|
|
@ -483,10 +480,6 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
return (!onlyWhitespaces || isPhotoAttached) && isValidPoll && !this.disabled;
|
return (!onlyWhitespaces || isPhotoAttached) && isValidPoll && !this.disabled;
|
||||||
},
|
},
|
||||||
|
|
||||||
handleTextchange: function() {
|
|
||||||
this.checkSubmitAvailability();
|
|
||||||
},
|
|
||||||
|
|
||||||
_beforeUnload: function(e) {
|
_beforeUnload: function(e) {
|
||||||
if(this._submittable() && this.inputEl.val() !== this.prefillText){
|
if(this._submittable() && this.inputEl.val() !== this.prefillText){
|
||||||
var confirmationMessage = Diaspora.I18n.t("confirm_unload");
|
var confirmationMessage = Diaspora.I18n.t("confirm_unload");
|
||||||
|
|
|
||||||
|
|
@ -43,17 +43,11 @@ describe("app.views.Publisher", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#initSubviews", function() {
|
describe("#initSubviews", function() {
|
||||||
it("calls handleTextchange if the publisher is prefilled with mentions", function() {
|
it("calls checkSubmitAvailability if the publisher is prefilled with mentions", function() {
|
||||||
spyOn(this.view, "handleTextchange");
|
spyOn(this.view, "checkSubmitAvailability");
|
||||||
this.view.prefillMention = "user@example.org";
|
this.view.prefillMention = "user@example.org";
|
||||||
this.view.initSubviews();
|
this.view.initSubviews();
|
||||||
expect(this.view.handleTextchange).toHaveBeenCalled();
|
expect(this.view.checkSubmitAvailability).toHaveBeenCalled();
|
||||||
});
|
|
||||||
|
|
||||||
it("doesn't call handleTextchange if there are no prefilled mentions", function() {
|
|
||||||
spyOn(this.view, "handleTextchange");
|
|
||||||
this.view.initSubviews();
|
|
||||||
expect(this.view.handleTextchange).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue