(function ($)
{
$.widget("portal.membership",
{
lang:
{
submitting: "Submitting" || "Submitting",
resetting: "Resetting" || "Resetting",
confirming: "Confirming" || "Confirming",
sessionexpired: "Session Expired" || "Session Expired",
popuptitle: "Disclosure of Information & Data Protection" || "Disclaimer",
success: "We have sent you an email with instructions on how to change your password. If you do not receive anything in the next several minutes, please check your junk/spam folder." || "We have sent you an email with instructions on how to change your password. If you do not receive anything in the next several minutes, please check your junk/spam folder."
},
options:
{
parentpageref: null,
loginurl: "",
popdisclaimer: false,
customextrapropertiesfunction: null
},
_create: function ()
{
// bind relevant events
this.bind();
},
bind: function()
{
// reference this plugin
var $that = this;
// first check to see if we're not at the parent (browser level) node. if not, we need to redirect user back to the login page at the parent.
if ($("body.portal-private")[0])
{
$.colorbox(
{
href: "#popup_SessionExpired", inline: true, title: $that.lang.sessionexpired, overlayClose: false, width: 640, maxHeight: "90%", maxWidth: "90%", closeButton: false,
onComplete: function ()
{
$("#popup_SessionExpired .button_ok").on("click", function ()
{
var btn = $(this);
btn.closest(".portal-popup-content").find(".portal-popup-message").empty().html("Redirecting ...");
btn.addClass("hide");
location.href = $that.options.loginurl + "/SessionExpired";
})
}
});
}
// wire the login button
$that.options.parentpageref.find("form#env-login").submit(function ()
{
$(this).find("div.portal-login-status").html("" + $that.lang.submitting + "");
var $status = $(this).find("div.portal-login-status");
var $submit = $(this).find("button.button-login");
SwitchElementViews($status, $submit);
return $that.checkloginattempt(this);
});
// wire the reset password button
$that.options.parentpageref.find("form#env-resetpassword").submit(function ()
{
$(this).find("div.portal-resetpassword-status").html("" + $that.lang.resetting + "");
var $status = $(this).find("div.portal-resetpassword-status");
var $submit = $(this).find("div.portal-resetpassword-submit");
SwitchElementViews($status, $submit);
return $that.resetpassword(this);
});
// wire the complete invitation button
$that.options.parentpageref.find("form#env-completeinvitation").submit(function ()
{
$(this).find("div.portal-completeinvitation-status").html("" + $that.lang.confirming + "");
var $status = $(this).find("div.portal-completeinvitation-status");
var $submit = $(this).find("div.portal-completeinvitation-submit");
SwitchElementViews($status, $submit);
return $that.completeinvitationattempt(this);
});
// remove the sidemenu buttons for this page
//$that.options.parentpageref.find("#env-sidemenu-forgotpassword").remove();
// if we need to pop the disclaimer, do it here
if ($that.options.popdisclaimer)
{
$(document).ready(function ()
{
$that.showdisclaimer();
});
}
else
$("#env-completeinvitation").removeClass("hide");
},
checkloginattempt: function (form)
{
// validate login attempt
var $that = this;
$.ajax({
type: form.method,
url: "/Authentication/Membership/CheckLogin",
data: $(form).serialize(),
success: function (returndata)
{
if (returndata.ok)
{
// go to the dashboard
location.href = returndata.redirect;
}
else
{
$that.options.parentpageref.find("div.portal-login-status").html("" + returndata.message + "");
var $status = $that.options.parentpageref.find("div.portal-login-status");
var $submit = $that.options.parentpageref.find("button.button-login");
SwitchElementViews($status, null);
SwitchElementViews($submit, null);
}
},
error: function (data, errorThrown)
{
$that.options.parentpageref.find("div.portal-login-status").html("" + errorThrown + "");
var $status = $that.options.parentpageref.find("div.portal-login-status");
var $submit = $that.options.parentpageref.find("button.button-login");
SwitchElementViews($status, null);
SwitchElementViews($submit, null);
}
});
return false;
},
sendforgotpassword: function (form)
{
// send forgot password
var $that = this;
$.ajax({
type: form.method,
url: "/Authentication/Membership/SendForgotPassword",
data: $(form).serialize(),
success: function (returndata)
{
if (returndata.ok)
{
// indicate password change instructions
$that.options.parentpageref.find("div.portal-forgotpassword-container").addClass("hide");
$that.options.parentpageref.find("div.portal-forgotpassword-status").html("" + $that.lang.success + "");
}
else
{
$that.options.parentpageref.find("div.portal-forgotpassword-status").html("" + returndata.message + "");
var $status = $that.options.parentpageref.find("div.portal-forgotpassword-status");
var $submit = $that.options.parentpageref.find("div.portal-forgotpassword-submit");
SwitchElementViews($status, null);
SwitchElementViews($submit, null);
}
},
error: function (data, errorThrown)
{
$that.options.parentpageref.find("div.forgotpassword-status-message").html("" + errorThrown + "");
var $status = $that.options.parentpageref.find("div.portal-forgotpassword-status");
var $submit = $that.options.parentpageref.find("div.portal-forgotpassword-submit");
SwitchElementViews($status, null);
SwitchElementViews($submit, null);
}
});
return false;
},
resetpassword: function (form)
{
// reset password
var $that = this;
$.ajax({
type: form.method,
url: "/Authentication/Membership/ChangePassword",
data: $(form).serialize(),
success: function (returndata)
{
if (returndata.ok)
{
// hide the form and show the success screen
$that.options.parentpageref.find("div.portal-resetpassword-container").addClass("hide");
$that.options.parentpageref.find("div.portal-resetpassword-success").removeClass("hide");
}
else
{
$that.options.parentpageref.find("div.portal-resetpassword-status").html("" + returndata.message + "");
var $status = $that.options.parentpageref.find("div.portal-resetpassword-status");
var $submit = $that.options.parentpageref.find("div.portal-resetpassword-submit");
SwitchElementViews($status, null);
SwitchElementViews($submit, null);
}
},
error: function (data, errorThrown)
{
$that.options.parentpageref.find("div.portal-resetpassword-status").html("" + errorThrown + "");
var $status = $that.options.parentpageref.find("div.portal-resetpassword-status");
var $submit = $that.options.parentpageref.find("div.portal-resetpassword-submit");
SwitchElementViews($status, null);
SwitchElementViews($submit, null);
}
});
return false;
},
completeinvitationattempt: function (form)
{
// validate complete invitation attempt
var $that = this;
var $form = $(form);
var completefunction = function(form, msg)
{
if (msg == "")
{
$.ajax({
type: "POST",
url: "/Authentication/Membership/CompleteInvitation",
data: $(form).serialize(),
success: function (returndata)
{
if (returndata.ok)
{
// go to the dashboard
location.href = returndata.redirect + "/invitation";
}
else
{
$that.options.parentpageref.find("div.portal-completeinvitation-status").html("" + returndata.message + "");
var $status = $that.options.parentpageref.find("div.portal-completeinvitation-status");
var $submit = $that.options.parentpageref.find("div.portal-completeinvitation-submit");
SwitchElementViews($status, null);
SwitchElementViews($submit, null);
}
},
error: function (data, errorThrown)
{
$that.options.parentpageref.find("div.portal-completeinvitation-status").html("" + errorThrown + "");
var $status = $that.options.parentpageref.find("div.portal-completeinvitation-status");
var $submit = $that.options.parentpageref.find("div.portal-completeinvitation-submit");
SwitchElementViews($status, null);
SwitchElementViews($submit, null);
}
});
}
else
{
$that.options.parentpageref.find("div.portal-completeinvitation-status").html("" + msg + "");
var $status = $that.options.parentpageref.find("div.portal-completeinvitation-status");
var $submit = $that.options.parentpageref.find("div.portal-completeinvitation-submit");
SwitchElementViews($status, null);
SwitchElementViews($submit, null);
}
};
if ($that.options.customextrapropertiesfunction != null)
$that.options.customextrapropertiesfunction(form, completefunction);
else
completefunction(form, "");
return false;
},
showdisclaimer: function()
{
var $that = this;
$.colorbox(
{
href: "#popup_PortalDisclaimer", inline: true, title: $that.lang.popuptitle, overlayClose: false, width: 640, maxHeight: "90%", maxWidth: "90%", closeButton: false,
onComplete: function ()
{
$("#popup_PortalDisclaimer .button_ok").on("click", function () { $("#env-completeinvitation").removeClass("hide"); })
}
});
},
showforgotpasswordpanel: function(form)
{
// Get the submitting HTML code when the page first loads
var submitting_code = form.find("div.portal-forgotpassword-status").html();
// wire the forgot password button
var $that = this;
form.submit(function ()
{
$(this).find("div.portal-forgotpassword-status").html(submitting_code);
var $status = $(this).find("div.portal-forgotpassword-status");
var $submit = $(this).find("div.portal-forgotpassword-submit");
SwitchElementViews($status, $submit);
return $that.sendforgotpassword(this);
});
},
loadextraproperties: function (ctnr, encryptid)
{
$(ctnr).load("", { encryptid: encryptid }, function () { $("#env-footer").hide(); });
},
setextrapropertiescallback: function (callback)
{
this.options.customextrapropertiesfunction = callback;
},
destroy: function ()
{
this.element.removeData();
}
});
})(jQuery);