Skip to content

Instantly share code, notes, and snippets.

@mdellavo
Created May 14, 2013 15:43
Show Gist options
  • Save mdellavo/5576969 to your computer and use it in GitHub Desktop.
Save mdellavo/5576969 to your computer and use it in GitHub Desktop.
var ModalView = Backbone.View.extend({
el: '#modal',
events: {
'click a.close': 'onClose',
'click a.submit': 'onSubmit',
'shown': 'onShown'
},
onClose: function() {
this.hide();
this.$el.removeData('modal');
},
onSubmit: function() {
this.$el.find('form').submit();
},
ajaxify: function() {
var this_ = this;
this.$el.find('form').ajaxify({
complete: function(form, xhr, status) {
var status = xhr.status / 100;
switch(status) {
case 2:
$('#modal').modal('hide');
window.location = '';
break;
case 4:
$('#modal .modal-body').html(xhr.responseText);
this_.onShown();
break;
}
}
});
},
onShown: function() {
this.ajaxify();
},
show: function(title, remote) {
this.$el.find('#modal-title').text(title);
this.$el.modal({'remote': remote});
},
hide: function() {
this.$el.modal('hide');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment