-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
81 lines (76 loc) · 2.13 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
let idleTime = 0;
$(document).ready(function() {
let retrievedProfile
$(logDate).datepicker({ dateFormat: 'yy/mm/dd' })
let WorkoutLog = (function($, undefined) {
let API_BASE = "https://exertrackweb.herokuapp.com/api/"
// let API_BASE = "http://localhost:3000/api/"
let userDefinitions= []
//private, gonna stay in the expression.
let setAuthHeader = function(sessionToken) {
window.localStorage.setItem("sessionToken", sessionToken)
//set the auth header
//this can be done on individual calls
//here we showcase ajaxsetup as a global tool
$.ajaxSetup({
"headers": {
"Authorization": sessionToken
}
})
}
// public. this will be exposed to the rest of the world
return {
API_BASE: API_BASE,
setAuthHeader: setAuthHeader
}
})(jQuery)
$(".nav-tabs a[data-toggle=tab]").on("click", function(e) {
let token = window.localStorage.getItem('sessionToken')
if ($(this).hasClass("disabled") && !token) {
e.preventDefault()
return false
}
if (!token && $(this).attr('id') != "loginout") {
alert("You must login first")
}
})
//bind ab change events
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
let target = $(e.target).attr("href")
if (target === '#log') { ///when checking for equality, ids must be '#id'
WorkoutLog.log.setDefinitions()
}
if (target === '#updateLog') {
WorkoutLog.log.setDefinitions()
}
if (target === '#history') {
WorkoutLog.log.getChart()
}
})
//bind enter key
$(document).on('keypress', function(e) {
if (e.which === 13) {
if ($(signupModal).is(':visible')) {
$(signup).trigger('click')
}
if ($(loginModal).is(':visible')) {
$(login).trigger('click')
}
}
})
//set header
let token = window.localStorage.getItem("sessionToken")
if (token) {
WorkoutLog.setAuthHeader(token)
$(homeNav).click()
// $(loginPage).hide()
} else {
$(loginout).click()
}
//expose this to the other workoutlog modules
window.WorkoutLog = WorkoutLog
// if(!window.localStorage.getItem('sessionToken')) {
// WorkoutLog.loginout()
// }
})
// this file gets the info from api/test. it works because onready it runs let test and gets