Disable button while running

Now using withDisabledElement to prevent multiple event handling. I've
attempted to write this as a common function in view_utils, so that this
approach can be used more generally, wherever needed. Includes a unit test.

Thanks to Christina and Andy for all their help on this one.
This commit is contained in:
Eric Fischer
2015-09-17 14:14:59 -04:00
parent decdb11710
commit 02b72abccb
3 changed files with 52 additions and 9 deletions

View File

@@ -6,16 +6,17 @@
'gettext',
'js/views/fields',
'teams/js/models/team',
'common/js/components/utils/view_utils',
'text!teams/templates/edit-team.underscore'],
function (Backbone, _, gettext, FieldViews, TeamModel, editTeamTemplate) {
function (Backbone, _, gettext, FieldViews, TeamModel, ViewUtils, editTeamTemplate) {
return Backbone.View.extend({
maxTeamNameLength: 255,
maxTeamDescriptionLength: 300,
events: {
'click .action-primary': 'createOrUpdateTeam',
'submit form': 'createOrUpdateTeam',
'click .action-primary': ViewUtils.withDisabledElement('createOrUpdateTeam'),
'submit form': ViewUtils.withDisabledElement('createOrUpdateTeam'),
'click .action-cancel': 'cancelAndGoBack'
},
@@ -124,10 +125,9 @@
var validationResult = this.validateTeamData(data);
if (validationResult.status === false) {
this.showMessage(validationResult.message, validationResult.srMessage);
return;
return $().promise();
}
this.teamModel.save(data, saveOptions)
return view.teamModel.save(data, saveOptions)
.done(function(result) {
view.teamEvents.trigger('teams:update', {
action: view.action,