/
common.js
145 lines (100 loc) · 2.53 KB
/
common.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* loadermabobs */
var login={};
if (localmode) {
var uri='http://'+localmode_ip+'/alldone.io/api/';
var homeuri='http://'+localmode_ip+'/alldone.io/';
} else {
var uri='http://www.alldone.io/api/';
var homeuri='http://www.alldone.io/';
}
var update_notify_count=0;
var runtime='none';
function alldone_login(user,pswd) {
var obj={'request':'login',
'user':user,
'pswd':pswd};
$('#updating').show();
var jqxhr = $.post( uri, obj)
.done(function( data ) {
app_login_complete(jQuery.parseJSON(data));
$('#updating').hide();
})
.fail(function(xhr, textStatus, errorThrown) {
$('#updating').hide();
alert(xhr.responseText);
alert(textStatus);
});
}
function alldone_grab(slashid) {
// accepts username/blah
var obj={'request':'grab',
'session':login.session,
'uid':login.uid,
'list':slashid};
$('#updating').show();
var jqxhr = $.post( uri, obj)
.done(function( data ) {
app_grab_complete(jQuery.parseJSON(data));
$('#updating').hide();
})
.fail(function() {
$('#updating').hide();
alert( "error" );
});
}
function alldone_update_notify() {
// We don't want to hammer the server, so wait some seconds
// and restart the counter if we are notified again!
if (!public_use) {
update_notify_count++;
var check = update_notify_count;
$('#updating').show();
setTimeout(function(){
if (update_notify_count===check) {
alldone_update();
}
}, 1000);
}
}
function alldone_update() {
update_notify_count=0;
var prep_data={todo_list:todo_list,
colourscheme:user_options.colourscheme,
mode:user_options.mode};
var obj={'request':'update',
'session':login.session,
'uid':login.uid,
'owner':todo_owner,
'uri':todo_title,
'data':JSON.stringify(prep_data)};
var jqxhr = $.post( uri, obj)
.done(function( data ) {
$('#updating').hide();
var json=jQuery.parseJSON(data);
if (json.result===0) {
if (json.error==='login') {
if (runtime==='app') {
login={};
app_boot();
} else {
alert('please login again!');
}
} // reset
}
})
.fail(function() {
dialog({type:'error',title:'Error saving', text:'Error saving data.'});
$('#updating').hide();
});
}
// session-ma-bobs
function load_session() {
if (localStorage.getItem("alldone_session") === null) {
login={};
} else {
login=jQuery.parseJSON(localStorage.alldone_session);
}
}
function update_session() {
localStorage.alldone_session = JSON.stringify(login);
}