-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
212 lines (172 loc) · 5.27 KB
/
main.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
function drawBalance(xml)
{
var rub;
{
var errorCode = $("errorCode", xml);
if (errorCode.length)
{
error = parseInt(errorCode[0].text);
if (error == 1)
throw new Error(strings.inputError);
else if (error == 2)
throw new Error(strings.innerError);
else if (error == 3)
throw new Error(strings.methodNotFoundError);
}
var balance = $("balance", xml);
if (balance.length)
{
rub = parseFloat(balance[0].text).toFixed(2);
$('#balance').text(rub+' ð.');
$('#balance_docked').text(rub+' ð.');
}
var debetBound = $("debetBound", xml);
if (debetBound.length)
{
$('#debetBound').text(debetBound[0].text+ ' ð.');
}
var days2BlockStr = $("days2BlockStr", xml);
if (days2BlockStr.length)
{
$('#days2BlockStr').text(days2BlockStr[0].text);
$('#days2BlockStr_docked').text(days2BlockStr[0].text);
}
var contractId = $("contractId", xml);
if (contractId.length)
{
$('#contractId').text(contractId[0].text);
}
/*var promisedPayment = $("promisedPayment", xml);
if (promisedPayment.length)
{
var isOpen = promisedPayment.find("isOpen");
if (isOpen.length && isOpen[0].text == "1")
$('#debet').get(0).style.display = '';
else
$('#debet').get(0).style.display = 'none';
}*/
var name = $("name", xml);
if (name.length)
{
var reg = /(\D+)\s(\D+)\s(\D+)/;
var arr = reg.exec(name[0].text);
var text = $('#first_name')[0].childNodes;
text[0].nodeValue = arr[1];
text[2].nodeValue = arr[2];
text[4].nodeValue = arr[3];
}
}
if (rub)
{
var date = new Date();
var strDate = date.getDate() + "."+ (date.getMonth()+1) + "." + date.getFullYear() +
" " + date.getHours() + ":" + date.getMinutes();
$('#date').text(strDate);
return true;
}
return false;
}
function draw()
{
var xmlhttp = new XMLHttpRequest();
var login = xor(System.Gadget.Settings.readString('login'));
var password = System.Gadget.Settings.readString('password');
try
{
xmlhttp.open('GET', 'https://api.novotelecom.ru/billing/?method=userInfo&login='+login+'&passwordHash=' + password+ "&clientVersion=2", true);
xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(null);
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
try
{
if (!drawBalance(xmlhttp.responseXML)){
$('#gadgetContent').get(0).style.display = 'none';
$('#message').get(0).style.display = '';
$('#message').text(strings.connectError);
}
else{
$('#gadgetContent').get(0).style.display = '';
$('#message').get(0).style.display = 'none';
}
}
catch (err)
{
$('#gadgetContent').get(0).style.display = 'none';
$('#message').get(0).style.display = '';
$('#message').text(err.message);
}
}
}
catch (exception_var)
{
}
}
function onSettingsClosed(event) {
if (event.closeAction == event.Action.commit) {
initSettings();
}
}
function initSettings() {
System.Gadget.settingsUI = 'settings.html';
System.Gadget.onSettingsClosed = onSettingsClosed;
//System.Gadget.Settings.write("PrivateSetting_GadgetOpacity", 40);
// óñòàíàâëèâàåì çíà÷åíèÿ ïî óìîë÷àíèþ ïðè ïåðâîì çàïóñêå ãàäæåòà
var login = System.Gadget.Settings.readString('login');
var password = System.Gadget.Settings.readString('password');
if(login == '' || password == '') {
$('#gadgetContent').get(0).style.display = 'none';
$('#message').text(strings.inputLogin);
$('#message').get(0).style.display = 'inline-block';
}
else{
$('#gadgetContent').get(0).style.display = 'none';
$('#message').text(strings.connecting);
$('#message').get(0).style.display = '';
draw();
}
}
function main()
{
System.Gadget.onDock = dockStateChanged;
System.Gadget.onUndock = dockStateChanged;
initSettings();
/*{
// Äëÿ òåñòîâ
$('#balance').text(194.41+' ð.');
$('#balance_docked').text(194.41+' ð.');
$('#debetBound').text(-300+ ' ð.');
$('#days2BlockStr').text("Õâàòèò ïðèìåðíî íà 9 äíåé");
$('#gadgetContent').get(0).style.display = '';
$('#message').get(0).style.display = 'none';
}*/
window.setInterval(draw , 1000*60*60)
}
function dockStateChanged() {
if (System.Gadget.docked) {
var width = '100px';
var height = '85px';
$('#background').css('width', width)
.css('height', height)
.attr('src', 'images/dockedBg.png');
$(document.body).css('width', width)
.css('height', height);
$('#docked').get(0).style.display = '';
$('#undocked').get(0).style.display = 'none';
} else {
var width = '220px'
var height = '176px'
$('#background').css('width', width)
.css('height', height)
.attr('src', 'images/dockedBg.png');
$(document.body).css('width', width)
.css('height', height);
$('#docked').get(0).style.display = 'none';
$('#undocked').get(0).style.display = '';
}
// Äîáàâëÿåì òåíü
//$('#background').get(0).addShadow("black", 20, 80, 5, 5);
}
$(document).ready(main);