June 6, 2016♦
EVR.Account.Form.Error.Errors = function(form)
{
this.form = form;
this.container = form.element;
this.errors = [];
this.element = document.createElement("div");
this.set_attributes();
this.attached = false;
}
EVR.Account.Form.Error.Errors.prototype.set_attributes = function()
{
this.element.style.marginTop = FORM_ERROR_DISPLAY_MARGIN;
}
EVR.Account.Form.Error.Errors.prototype.append = function()
{
this.container.appendChild(this.element);
// var container = this.container;
// container.insertBefore(this.element, container.firstChild.nextSibling);
this.attached = true;
}
EVR.Account.Form.Error.Errors.prototype.add_error = function(message, affected)
{
this.errors.push(new EVR.Account.Form.Error(this, message, affected));
}
EVR.Account.Form.Error.Errors.prototype.display = function()
{
var error, errors = this.errors;
var selected = false;
for (var ii = 0; ii < errors.length; ii++)
{
error = errors[ii];
error.append();
selected = error.restyle_affected(selected);
}
this.append();
}
EVR.Account.Form.Error.Errors.prototype.clear = function()
{
var error;
while (error = this.errors.pop())
{
error.remove();
}
if (this.attached)
{
this.remove();
}
}
EVR.Account.Form.Error.Errors.prototype.remove = function()
{
this.container.removeChild(this.element);
this.attached = false;
}
EVR.include("account/form/error/Errors.js");
EVR.Account.Form.Error = function(errors, message, affected)
{
this.errors = errors;
this.container = errors.element;
this.message = message;
this.affected = affected || [];
this.element = document.createElement("li");
this.set_attributes();
}
EVR.Account.Form.Error.prototype.set_attributes = function()
{
var element = this.element;
element.innerHTML = this.message;
element.style.color = FORM_ERROR_TEXT_COLOR;
}
EVR.Account.Form.Error.prototype.append = function()
{
this.container.appendChild(this.element);
}
EVR.Account.Form.Error.prototype.restyle_affected = function(selected)
{
var affected = this.affected;
var input, inputs = this.errors.form.inputs;
for (var ii = 0; ii < affected.length; ii++)
{
input = inputs[affected[ii]];
input.set_background(FORM_ERROR_COLOR);
if (!selected)
{
input.select();
selected = true;
}
}
return selected;
}
EVR.Account.Form.Error.prototype.remove = function()
{
this.container.removeChild(this.element);
}
EVR.include("account/form/forms/Login_Form.js");
EVR.include("account/form/forms/Registration_Form.js");
EVR.include("account/form/forms/Forgot_Password_Form.js");
EVR.include("account/form/forms/Change_Password_Form.js");
EVR.Account.Form.Forms = function(account)
{
this.account = account;
this.container = account.element;
this.element = document.createElement("div");
this.add_forms();
}
EVR.Account.Form.Forms.prototype.add_forms = function()
{
var forms = [];
var element = this.element;
forms.push(new EVR.Account.Form.Forms.Login_Form(this));
forms.push(new EVR.Account.Form.Forms.Registration_Form(this));
forms.push(new EVR.Account.Form.Forms.Forgot_Password_Form(this));
forms.push(new EVR.Account.Form.Forms.Change_Password_Form(this));
for (var ii = 0; ii < forms.length; ii++)
{
forms[ii].append();
}
this.forms = forms;
}
EVR.Account.Form.Forms.prototype.reset = function()
{
var forms = this.forms;
for (var ii = 0; ii < forms.length; ii++)
{
forms[ii].reset();
}
}
EVR.Account.Form.Forms.prototype.append = function()
{
this.container.appendChild(this.element);
}
EVR.Account.Form.Forms.Change_Password_Form = function(forms)
{
EVR.Account.Form.call(this, forms.element, "Change Password");
this.forms = forms;
this.initialize();
this.add_inputs();
}
EVR.Account.Form.Forms.Change_Password_Form.prototype = new EVR.Account.Form;
EVR.Account.Form.Forms.Change_Password_Form.prototype.add_inputs = function()
{
this.add_input("name", "username");
this.add_input("old_pass", "old password", "password");
this.add_input("new_pass", "new password", "password");
this.add_input("new_pass_confirmation", "confirm new password", "password");
}
EVR.Account.Form.Forms.Change_Password_Form.prototype.respond = function()
{
var response = this.submit()
if (response[0] == "")
{
this.clear_errors();
this.forms.account.evr.log_in();
}
else
{
var current = this;
window.setTimeout(
function()
{
current.clear_errors();
current.handle_errors(response);
current.display_errors();
}, FORM_RESULTS_DELAY);
}
}
EVR.Account.Form.Forms.Change_Password_Form.prototype.submit = function()
{
var script = SOURCE_PATH + "account/submit_change_password_request.php";
var query = this.build_query();
return new EVR.Requester(script, query, true).execute().split("\n");
}
EVR.Account.Form.Forms.Change_Password_Form.prototype.handle_errors =
function(errors)
{
var error, erroneous, found, display_response = false;
for (var ii = 0; ii < errors.length; ii++)
{
error = errors[ii];
erroneous = [];
found = false;
switch (error)
{
case "username not found (note: usernames are case-sensitive)":
erroneous.push("name");
found = true;
}
switch (error)
{
case "password doesn't match username":
erroneous.push("old_pass");
found = true;
}
switch (error)
{
case "submitted passwords don't match":
case "password too short":
case "password too long":
erroneous.push("new_pass");
erroneous.push("new_pass_confirmation");
found = true;
}
if (!found)
{
display_response = true;
}
else
{
this.add_error(error, erroneous);
}
}
if (display_response)
{
alert(errors);
}
}