Skip to content

Instantly share code, notes, and snippets.

@ireneyiu
Last active August 29, 2015 14:04
Show Gist options
  • Save ireneyiu/2d3e5de3782282ade362 to your computer and use it in GitHub Desktop.
Save ireneyiu/2d3e5de3782282ade362 to your computer and use it in GitHub Desktop.
wfApp.settings.PasswordView = function(opts) {
this.model = opts.model; // pass in our Password object
this.$el = $(opts.el);
this.$inputCurrent = this.$el.find(opts.inputCurrent);
this.$inputNew = this.$el.find(opts.inputNew);
this.submitUrl = this.$el.attr('action');
};
wfApp.settings.PasswordView.prototype.submit = function(e) {
e.preventDefault();
var params = this.$el.serializeArray();
this.model = $.extend(this.model, params);
var validationResult = this.model.validate(); // get the validation result from Password
if (!validationResult.valid) {
this.$inputNew.val("").first().focus();
this.showSubmitMessage(this.$el, validationResult.errors, "failure", 3000);
} else {
this.$el.find("input").attr("disabled", true);
this.showSubmitMessage(this.$el, "Saving...");
$.post(this.submitUrl, params)
.then(this.processResponse.bind(this))
.done(this.submitSuccess.bind(this))
.fail(this.submitFail.bind(this));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment