Created
November 21, 2012 12:43
-
-
Save recurser/4124680 to your computer and use it in GitHub Desktop.
Review a widget, or load the next one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ManageWidgetModalView = Backbone.View.extend({ | |
el: '.modal', | |
events: { | |
'click .decide-later': 'loadNextWidget', | |
'submit form': 'submitWidgetForm' | |
}, | |
/** | |
* Submits the widget form via AJAX. | |
*/ | |
submitWidgetForm: function(event) { | |
var view = this; | |
var form = $(event.target); | |
var params = { | |
type: form.attr('method').toUpperCase(), | |
url: form.attr('action'), | |
data: form.serialize(), | |
success: function(response) { view.refreshView(response); view.refreshList(); }, | |
error: function(response) { view.errorCallback(response); } | |
}; | |
$.ajax(params); | |
event.preventDefault(); | |
}, | |
/** | |
* Loads the next widget via AJAX. | |
*/ | |
loadNextWidget: function(event) { | |
event.preventDefault(); | |
var view = this; | |
var params = { | |
url: $(event.target).attr('href'), | |
success: function(response) { view.refreshView(response); }, | |
error: function(response) { view.errorCallback(response); } | |
}; | |
$.ajax(params); | |
}, | |
/** | |
* Refreshes the widget list. | |
*/ | |
refreshList: function() { | |
var view = this; | |
var params = { | |
url: Application.parentWindowUrl(), | |
success: function(response) { view.refreshListCallback(response); }, | |
error: function(response) { view.errorCallback(response); } | |
}; | |
$.ajax(params); | |
}, | |
/** | |
* Callback to load AJAX content into the widget list. | |
*/ | |
refreshListCallback: function(response) { | |
$('#ajax-wrapper').html(response); | |
}, | |
/** | |
* Refreshes the modal window with the new content, or hides the modal if | |
* there is no content to show. | |
*/ | |
refreshView: function(content) { | |
$('.modal-body', this.el).html(content); | |
}, | |
/** | |
* Displays an error if something went wrong. | |
*/ | |
errorCallback: function(response) { | |
var msg = I18n.t('common.generic_error'); | |
$('.modal-body', this.el).html('').removeClass().displayError(msg); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment