<link rel="stylesheet" type="text/css" href="static/style.css">
<link rel="stylesheet" type="text/css" href="static/nav-menu.css">
<script type="text/javascript">
+ //runBeforeLoad();
$(document).ready(function () {
//$("#menu-container").populateNavbar();
$("#login").submit(function () {
<link rel="stylesheet" type="text/css" href="static/style.css">
<link rel="stylesheet" type="text/css" href="static/nav-menu.css">
<script type="text/javascript">
+ runBeforeLoad(true);
+
$(document).ready(function () {
$("#login").submit(function () {
$("#login").login();
mctx.strain_gauges.ids = [0, 1, 2, 3];
mctx.strain_gauges.time_limit = 20;
+function debugLog (msg) {
+ if (typeof console === "undefined" || typeof console.log === "undefined") {
+ alert(msg);
+ } else {
+ console.log(msg);
+ }
+}
+
/**
* Writes the current date to wherever it's called.
*/
document.write((new Date()).toDateString());
}
+function runBeforeLoad(isLoginPage) {
+ $.ajax({
+ url : mctx.api + "identify"
+ }).done(function (data) {
+ if (data.logged_in && isLoginPage) {
+ window.location = mctx.location;
+ } else if (!data.logged_in && !isLoginPage) {
+ //Note: this only clears the nameless cookie
+ document.cookie = "";
+ window.location = mctx.location + "login.html";
+ } else {
+ mctx.friendlyName = data.friendly_name;
+ }
+ }).fail(function (jqHXR) {
+ if (!isLoginPage) {
+ window.location = mctx.location + "login.html";
+ } else {
+ debugLog("Failed to ident server. Is API running?")
+ }
+ });
+}
+
/**
* Populates a submenu of the navigation bar
* @param {string} header The header