-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbbox-common.js
More file actions
168 lines (151 loc) · 5.2 KB
/
Copy pathbbox-common.js
File metadata and controls
168 lines (151 loc) · 5.2 KB
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
/*!
* @brief Common definitions and support for the UI
*
* Copyright (c) 2013, 2014 Bouygues Telecom
*
* The computer program contained herein contains proprietary
* information which is the property of Bouygues Telecom.
* The program may be used and/or copied only with the written
* permission of Bouygues Telecom or in accordance with the
* terms and conditions stipulated in the agreement/contract under
* which the programs have been supplied.
*
* @author Stephane Carrez <stcarrez@bouyguestelecom.fr>
*/
var Bbox = Bbox || {};
var header = $('header'),
headerHeight = header.height() + 25,
treshold = 0,
lastScroll = 0;
Bbox.PendingErrors = false;
Bbox.refresh_delay = {
default2: 10000,
devices: 10000,
wps_devices: 1000,
stats: 1000,
cpu_graph_delay: 10000,
temp_graph_delay: 10000,
xdsl_graph_delay: 60000
};
/**
* @brief Install the tooltip on a form.
*
* @param form the form where the tooltip must be activated.
*/
Bbox.tooltip = function(form) {
$(form).find('.help-focus').focusin(function() {
$(this).find('.help-bloc').show().css({visibility:'visible'});
$(this).find('.help-bloc.bottom:not(.dhcp-help)').css({visibility:'visible',width:'100%'});
}).focusout(function() {
$(this).find('.help-bloc:not(.bottom)').hide();
$(this).find('.help-bloc.bottom').css({visibility:'hidden'});
});
$(form).find('.help-focus').focusin(function() {
$(form).find('.help-bloc-small').show();
}).focusout(function() {
$(form).find('.help-bloc-small').hide();
});
};
/**
* @brief Get the message box or create it if necessary.
*
* @return the message box div.
*/
Bbox.createMessageBox = function() {
var div;
div = document.getElementById('message-box');
if (div) {
return div;
}
div = document.createElement('div');
div.id = 'message-box';
div.className = 'message-box message';
var block = document.createElement('div');
block.className = 'row';
div.appendChild(block);
var span = document.createElement('span');
span.className = 'close';
block.appendChild(span);
var header = document.createElement('div');
header.className = 'message-header';
block.appendChild(header);
var msg = document.createElement('p');
msg.className = 'message-content';
block.appendChild(msg);
document.body.appendChild(div);
return div;
};
Bbox.closeMessage = function() {
$('#message-box').fadeOut(800);
$('.margin-message-box').css( 'margin-top', 120 );
};
/**
* @brief Print a message on the top of the page.
*
* @param title the message title.
* @param message the message text.
*/
Bbox.printMessage = function(title, message,NoClose) {
var box = Bbox.createMessageBox();
$('.margin-message-box').css( 'margin-top', $('.message-box').height() + 120 );
$(box).find('.message-header').text(title);
$(box).find('.message-content').text(message);
$(box).find('.close').click(Bbox.closeMessage);
$('#message-box').fadeIn(100);
if(!NoClose) {
setTimeout(Bbox.closeMessage, 5000);
}
};
/**
* @brief Display the login popup modal when we detect that the user's session expired.
*/
Bbox.login = function() {
var login = document.getElementById('login-modal');
var bool = false;
if (login === null) {
login = document.createElement('div');
login.className = 'md-modal';
login.id = 'login-modal';
document.body.appendChild(login);
bool = true;
}
bool = (bool || $(login).css('visibility')==='hidden');
if(bool) {
Bbox.api.get(Bbox.api.server + '/forms/form-login.html', null, function(response) {
if (!response.error) {
$(login).html(response.data);
/**
* Build the login modal box.
*/
$(login).modal({
allow_close: false,
rules: {
password: { required: true }
},
messages: {
password: Bbox.Messages.password_required
},
/**
* @brief Action when submitting the form
* @param e event
* @return nothing
*/
submit: function(e) {
var passwd = $(login).find('.text-input').val();
var remember = $('#cbox-login').val();
Bbox.api.login(passwd, remember === 'on' ? true : false, function(response) {
if (!response.error) {
$(login).close();
Bbox.printMessage('Information', 'Vous êtes reconnecté...');
Bbox.api.operation.apply(Bbox.api,Bbox.api.lastError);
} else if (response.status === 401) {
$('#password-message').html(Bbox.Messages.invalid_password);
$('#password-message').show();
}
});
}
}).showModal();
}
});
}
};