Skip to content

Instantly share code, notes, and snippets.

@brianjmiller
Last active December 25, 2015 21:29
Show Gist options
  • Save brianjmiller/7042658 to your computer and use it in GitHub Desktop.
Save brianjmiller/7042658 to your computer and use it in GitHub Desktop.
Backbone .save handlers
user.save(
userSaveData,
{
success: _.bind(this._registerSuccess, this),
error: _.bind(this._registerError, this)
}
);
_registerSuccess: function () {
console.log("views/signUp::_registerSuccess");
var prop;
for (prop in this._nodes) {
if (prop !== "indicator" && prop !== "failureReason") {
this._nodes[prop].val("");
}
}
this._nodes.indicator.removeClass("error").addClass("success");
},
_registerError: function (model, xhr) {
console.log("views/signUp::_registerError");
var msg = "";
if (xhr.status === 409) {
msg = "account already exists";
}
else {
msg = xhr.responseText + " (" + xhr.status + ")";
}
this._registerFailure(msg);
},
_registerFailure: function (reason) {
console.log("views/signUp::_registerFailure");
this._nodes.indicator.removeClass("success").addClass("error");
this._nodes.failureReason.html(reason);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment