-
Notifications
You must be signed in to change notification settings - Fork 0
/
mim.js
120 lines (117 loc) · 3.35 KB
/
mim.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
console.log('tok: ' + tok);
function ajaxCaller(d) {
console.log('tok: ' + tok)
$.ajax({
// dataType: 'json',
type: 'POST',
url: admin_page_address,
data: {
dataArray: d,
tok: tok,
assertion: ass,
act: act
},
success: function(res, status, xhr) {
console.log('res: ' + res);
receivedAjax = jQuery.parseJSON(res);
console.log('receivedAjax: ' + receivedAjax);
tok = receivedAjax.tok;
isLogedIn = receivedAjax.logedIn;
cmd = receivedAjax.cmd;
},
error: function(xhr, status, err) {
console.log('ERR! ' + err)
navigator.id.logout();
alert("Login failure: " + err);
},
beforeSend: function() {
duringAjax(act);
//TODO: use this to make a little LED light that let the users know when AJAX is in action!
// console.log('AJAX call STARTED!');
},
complete: function() {
afterAjax(act);
//TODO: use this to make a little LED light that let the users know when AJAX is in action!
// console.log('AJAX call FINISHED!');
},
statusCode: {
404: function() {
console.log("page not found");
},
200: function() {
// console.log('status 200 !!!');
}
}
})
}
function duringAjax(act) {
if (act == 'killUser') {
navigator.id.logout();
// $("#page_loader_mask").fadeIn();
}
}
function afterAjax(act) {
if (act == 'auth' && isLogedIn == true) {
// isLogedIn ? : $("#page_loader_mask").fadeOut();
}
//the comand received from the server:
switch (cmd) {
case 'refresh':
// true is to force the reload to not use the cache:
location.reload(true);
break;
case 'BuildEditPage':
console.log('EDIT PAGE NEEDS TO BE BUILD!!! ====================================+');
$( ".container" ).replaceWith(receivedAjax.snip);
break;
default:
console.log('--------------- > CMD not recognised! < ---------------');
}
}
var receivedAjax;
var ass;
var act;
var isLogedIn;
var cmd;
// ================================================= PERSONA RELATED SH**! :P
var signinLink = document.getElementById('signin');
if (signinLink) {
signinLink.onclick = function() {
navigator.id.request({
siteName: 'mim CV',
returnTo: '/',
backgroundColor: '#f00',
oncancel: function() {
alert('Incomplete Login!')
}
});
};
}
var signoutLink = document.getElementById('signout');
if (signoutLink) {
signoutLink.onclick = function() {
navigator.id.logout();
act = 'killUser';
ass = null;
ajaxCaller();
};
}
function killUser(){
navigator.id.logout();
act = 'killUser';
ass = null;
ajaxCaller();
}
navigator.id.watch({
onlogin: function(assertion) {
act = 'auth';
ass = assertion;
ajaxCaller();
},
onlogout: function() {
act = 'auth';
ass = null;
//TODO: kill the session on server and destroy the UI (refresh the page on ajax success)!
ajaxCaller();
}
});