disable publisher after successfully posting in standalone mode
This commit is contained in:
parent
7680165b14
commit
9da3bc347b
3 changed files with 58 additions and 4 deletions
|
|
@ -30,6 +30,7 @@ app.views.Publisher = Backbone.View.extend({
|
|||
|
||||
initialize : function(opts){
|
||||
this.standalone = opts ? opts.standalone : false;
|
||||
this.disabled = false;
|
||||
|
||||
// init shortcut references to the various elements
|
||||
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_input.trigger('input');
|
||||
this.handleTextchange();
|
||||
},
|
||||
|
||||
// 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.trigger('publisher:sync');
|
||||
}
|
||||
if(app.stream) {
|
||||
app.stream.addNow(statusMessage.toJSON());
|
||||
}
|
||||
|
||||
if(app.stream) app.stream.addNow(statusMessage.toJSON());
|
||||
|
||||
// clear state
|
||||
self.clear();
|
||||
|
||||
// standalone means single-shot posting (until further notice)
|
||||
if( self.standalone ) self.setEnabled(false);
|
||||
},
|
||||
error: function() {
|
||||
if( app.publisher ) app.publisher.trigger('publisher:error');
|
||||
|
|
@ -368,6 +372,8 @@ app.views.Publisher = Backbone.View.extend({
|
|||
},
|
||||
|
||||
open : function() {
|
||||
if( this.disabled ) return;
|
||||
|
||||
// visually 'open' the publisher
|
||||
this.$el.removeClass('closed');
|
||||
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) {
|
||||
bool = !bool;
|
||||
this.el_submit.prop({disabled: bool});
|
||||
|
|
@ -410,7 +423,7 @@ app.views.Publisher = Backbone.View.extend({
|
|||
var onlyWhitespaces = ($.trim(this.el_input.val()) === ''),
|
||||
isPhotoAttached = (this.el_photozone.children().length > 0);
|
||||
|
||||
return (!onlyWhitespaces || isPhotoAttached);
|
||||
return (!onlyWhitespaces || isPhotoAttached) && !this.disabled;
|
||||
},
|
||||
|
||||
handleTextchange: function() {
|
||||
|
|
|
|||
|
|
@ -45,4 +45,18 @@ describe('app.views.Bookmarklet', function() {
|
|||
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -39,6 +39,12 @@ describe("app.views.Publisher", function() {
|
|||
this.view.open($.Event());
|
||||
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() {
|
||||
|
|
@ -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(){
|
||||
it("should submit the form when ctrl+enter is pressed", function(){
|
||||
this.view.render();
|
||||
|
|
|
|||
Loading…
Reference in a new issue