Created
February 19, 2014 19:15
-
-
Save justintoth/9099422 to your computer and use it in GitHub Desktop.
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
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