disable publisher after successfully posting in standalone mode

This commit is contained in:
Florian Staudacher 2014-04-25 18:27:33 +02:00
parent 7680165b14
commit 9da3bc347b
3 changed files with 58 additions and 4 deletions

View file

@ -30,6 +30,7 @@ app.views.Publisher = Backbone.View.extend({
initialize : function(opts){ initialize : function(opts){
this.standalone = opts ? opts.standalone : false; this.standalone = opts ? opts.standalone : false;
this.disabled = false;
// init shortcut references to the various elements // init shortcut references to the various elements
this.el_input = this.$('#status_message_fake_text'); this.el_input = this.$('#status_message_fake_text');
@ -123,6 +124,7 @@ app.views.Publisher = Backbone.View.extend({
this.el_hiddenInput.val(txt); this.el_hiddenInput.val(txt);
this.el_input.trigger('input'); this.el_input.trigger('input');
this.handleTextchange();
}, },
// show the "getting started" popups around the publisher // show the "getting started" popups around the publisher
@ -164,12 +166,14 @@ app.views.Publisher = Backbone.View.extend({
app.publisher.$el.trigger('ajax:success'); app.publisher.$el.trigger('ajax:success');
app.publisher.trigger('publisher:sync'); app.publisher.trigger('publisher:sync');
} }
if(app.stream) {
app.stream.addNow(statusMessage.toJSON()); if(app.stream) app.stream.addNow(statusMessage.toJSON());
}
// clear state // clear state
self.clear(); self.clear();
// standalone means single-shot posting (until further notice)
if( self.standalone ) self.setEnabled(false);
}, },
error: function() { error: function() {
if( app.publisher ) app.publisher.trigger('publisher:error'); if( app.publisher ) app.publisher.trigger('publisher:error');
@ -368,6 +372,8 @@ app.views.Publisher = Backbone.View.extend({
}, },
open : function() { open : function() {
if( this.disabled ) return;
// visually 'open' the publisher // visually 'open' the publisher
this.$el.removeClass('closed'); this.$el.removeClass('closed');
this.el_wrapper.addClass('active'); this.el_wrapper.addClass('active');
@ -393,6 +399,13 @@ app.views.Publisher = Backbone.View.extend({
} }
}, },
setEnabled: function(bool) {
this.setInputEnabled(bool);
this.disabled = !bool;
this.handleTextchange();
},
setButtonsEnabled: function(bool) { setButtonsEnabled: function(bool) {
bool = !bool; bool = !bool;
this.el_submit.prop({disabled: bool}); this.el_submit.prop({disabled: bool});
@ -410,7 +423,7 @@ app.views.Publisher = Backbone.View.extend({
var onlyWhitespaces = ($.trim(this.el_input.val()) === ''), var onlyWhitespaces = ($.trim(this.el_input.val()) === ''),
isPhotoAttached = (this.el_photozone.children().length > 0); isPhotoAttached = (this.el_photozone.children().length > 0);
return (!onlyWhitespaces || isPhotoAttached); return (!onlyWhitespaces || isPhotoAttached) && !this.disabled;
}, },
handleTextchange: function() { handleTextchange: function() {

View file

@ -45,4 +45,18 @@ describe('app.views.Bookmarklet', function() {
expect(app.publisher.el_hiddenInput.val()).toMatch(/.+A$/); expect(app.publisher.el_hiddenInput.val()).toMatch(/.+A$/);
}); });
it('keeps the publisher disabled after successful post creation', function() {
jasmine.Ajax.useMock();
init_bookmarklet(test_data);
spec.content().find('form').submit();
mostRecentAjaxRequest().response({
status: 200, // success!
responseText: "{}"
});
expect(app.publisher.disabled).toBeTruthy();
});
}); });

View file

@ -39,6 +39,12 @@ describe("app.views.Publisher", function() {
this.view.open($.Event()); this.view.open($.Event());
expect($(this.view.el)).not.toHaveClass("closed"); expect($(this.view.el)).not.toHaveClass("closed");
}); });
it("won't open when disabled", function() {
this.view.disabled = true;
this.view.open($.Event());
expect($(this.view.el)).toHaveClass("closed");
});
}); });
describe("#close", function() { describe("#close", function() {
@ -133,6 +139,27 @@ describe("app.views.Publisher", function() {
}); });
}); });
describe('#setEnabled', function() {
it('disables the publisher', function() {
expect(this.view.disabled).toBeFalsy();
this.view.setEnabled(false);
expect(this.view.disabled).toBeTruthy();
expect(this.view.el_input.prop('disabled')).toBeTruthy();
expect(this.view.el_hiddenInput.prop('disabled')).toBeTruthy();
});
it("disables submitting", function() {
this.view.setText('TESTING');
expect(this.view.el_submit.prop('disabled')).toBeFalsy();
expect(this.view.el_preview.prop('disabled')).toBeFalsy();
this.view.setEnabled(false);
expect(this.view.el_submit.prop('disabled')).toBeTruthy();
expect(this.view.el_preview.prop('disabled')).toBeTruthy();
});
});
describe("publishing a post with keyboard", function(){ describe("publishing a post with keyboard", function(){
it("should submit the form when ctrl+enter is pressed", function(){ it("should submit the form when ctrl+enter is pressed", function(){
this.view.render(); this.view.render();