Skip to content

Instantly share code, notes, and snippets.

@justintoth
Created February 19, 2014 19:15
Show Gist options
  • Save justintoth/9099422 to your computer and use it in GitHub Desktop.
Save justintoth/9099422 to your computer and use it in GitHub Desktop.
function baseFormViewModel(entityName, list) {
var self = this;
this.baseInit = function () {
//set default values.
self.clear();
ko.applyBindings(self, $('#' + entityName + '-form-container')[0]);
//setup ajax form.
utils.setupForm(function (e) {
if (e.success) {
//update list.
list.get();
//hide form.
self.hide();
}
else {
utils.showError(e.error || e.message || e);
}
}, entityName + '-form');
//setup event listeners.
$('#add-' + entityName).click(function () {
self.clear();
self.show();
});
$('#cancel-' + entityName + '-form').click(self.hide);
};
this.show = function () {
$('#' + entityName + '-form-container')
.show()
.scrollTop(0)
.animate({ opacity: .9 }, 500);
};
this.hide = function () {
$('#' + entityName + '-form-container').animate({ opacity: 0 }, 500, function () { $('#' + entityName + '-form-container').hide(); });
};
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment