11
11
function addNewRow(url, table, fields, directory)
13
13
var pars = 'action=add&tablename=' + table + '&directory=' + directory + '&';
16
pars += '&filter=' + inputValue(table + '_filter');
17
pars += '&pageSize=' + inputValue(table + '_pageSize');
17
21
for (var i = 0; i < fields.length; i++) {
18
22
var field = fields[i];
19
var value = $F(table + '_' + field);
23
//var value = $F(table + '_' + field);
24
var value = inputValue(table + '_' + field);
21
26
if (pars.length != 0) {
40
45
stripe('dataTable', '#ecf5da', '#ffffff');
42
47
onFailure: function(t) {
43
restoreHidden('buttons');
48
restoreHidden('buttons_' + table, table);
47
setLoading('buttons', true);
52
setLoading('buttons_' + table, table, true);
51
function changeRow(url, table, fields, directory, id)
56
function changeRow(url, table, fields, directory, id, page, force)
53
var pars = 'action=edit&tablename=' + table + '&directory=' + directory + '&id=' + id + '&';
58
var pars = 'action=edit&tablename=' + table + '&directory='
59
+ directory + '&id=' + id + '&';
60
if ( page != undefined ) {
61
pars += '&page=' + page;
63
if ( page != undefined ) {
64
pars += '&page=' + page;
66
pars += '&filter=' + inputValue(table + '_filter');
67
pars += '&pageSize=' + inputValue(table + '_pageSize');
69
// If force parameter is ready, show it
58
76
for (var i = 0; i < fields.length; i++) {
59
77
var field = fields[i];
60
var value = $F(table + '_' + field);
78
var value = inputValue(table + '_' + field);
62
80
if (pars.length != 0) {
82
100
stripe('dataTable', '#ecf5da', '#ffffff');
84
102
onFailure: function(t) {
85
restoreHidden('buttons');
103
restoreHidden('buttons_' + table, table );
89
setLoading('buttons', true);
107
setLoading('buttons_' + table, table, true);
111
function actionClicked(url, table, action, rowId, paramsAction, directory) {
129
function actionClicked(url, table, action, rowId, paramsAction, directory, page) {
113
131
var pars = '&action=' + action + '&id=' + rowId;
115
133
if ( paramsAction != '' ) {
116
134
pars += '&' + paramsAction;
136
if ( page != undefined ) {
137
pars += '&page=' + page;
140
pars += '&filter=' + inputValue(table + '_filter');
141
pars += '&pageSize=' + inputValue(table + '_pageSize');
119
142
pars += '&directory=' + directory + '&tablename=' + table;
121
144
cleanError(table);
135
158
stripe('dataTable', '#ecf5da', '#ffffff');
137
160
onFailure: function(t) {
138
restoreHidden('actionsCell_' + rowId);
161
restoreHidden('actionsCell_' + rowId, table);
142
165
if ( action == 'del' ) {
143
setLoading('actionsCell_' + rowId);
166
setLoading('actionsCell_' + rowId, table);
145
168
else if ( action == 'move' ) {
146
setLoading('actionsCell_' + rowId);
169
setLoading('actionsCell_' + rowId, table);
151
function changeView(url, table, directory, action, id)
174
function changeView(url, table, directory, action, id, page, isFilter)
153
176
var pars = 'action=' + action + '&tablename=' + table + '&directory=' + directory + '&editid=' + id;
178
pars += '&filter=' + inputValue(table + '_filter');
179
pars += '&pageSize=' + inputValue(table + '_pageSize');
180
pars += '&page=' + page;
155
182
cleanError(table);
157
184
var MyAjax = new Ajax.Updater(
167
194
evalScripts: true,
168
195
onComplete: function(t) {
169
196
// Highlight the element
170
highlightRow(id, true);
197
if (id != undefined) {
198
highlightRow(id, true);
171
200
// Stripe again the table
172
201
stripe('dataTable', '#ecf5da', '#ffffff');
173
202
if ( action == 'changeEdit' ) {
174
restoreHidden('actionsCell_' + id);
203
restoreHidden('actionsCell_' + id, table);
177
206
onFailure: function(t) {
178
207
if ( action == 'changeAdd' ) {
179
restoreHidden('creatingForm');
208
restoreHidden('creatingForm_' + table, table);
181
210
else if ( action == 'changeList' ) {
182
restoreHidden('buttons');
212
restoreHidden('buttons_' + table, table);
184
215
else if ( action == 'changeEdit' ) {
185
restoreHidden('actionsCell_' + id);
216
restoreHidden('actionsCell_' + id, table);
191
222
if ( action == 'changeAdd' ) {
192
setLoading('creatingForm', true);
223
setLoading('creatingForm_' + table, table, true);
194
225
else if ( action == 'changeList' ) {
195
setLoading('buttons', true);
227
setLoading('buttons_' + table, table, true);
197
230
else if ( action == 'changeEdit' ) {
198
setLoading('actionsCell_' + id, true);
231
setLoading('actionsCell_' + id, table, true);
213
246
errorId - div identifier
214
247
url - the URL where the CGI which generates the HTML is placed
215
248
formId - form identifier which has the parameters to pass to the CGI
249
loadingId - String element identifier that it will substitute by the loading image
250
*(Optional)* Default: 'loadingTable'
218
function hangTable(successId, errorId, url, formId)
253
function hangTable(successId, errorId, url, formId, loadingId)
221
256
// Cleaning manually
222
257
$(errorId).innerHTML = "";
260
loadingId = 'loadingTable';
224
263
var ajaxUpdate = new Ajax.Updater(
226
265
success: successId,
232
271
parameters: Form.serialize(formId, true), // The parameters are taken from the form
233
272
asynchronous: true,
234
onComplete: function(t) {
235
restoreHidden('loadingTable');
240
setLoading('loadingTable');
274
onFailure: function(t) {
275
restoreHidden(loadingId);
280
//setLoading(loadingId);
285
Function: selectComponentToHang
287
Call to a component to be hang in a select entry
291
successId - div identifier where the new table will be on on success
292
errorId - div identifier
293
formId - form identifier which has the parameters to pass to the CGI
294
urls - associative array which contains tthe URL where the CGI which generates the HTML is placed
295
loadingId - String element identifier that it will substitute by the loading image
296
*(Optional)* Default: 'loadingTable'
299
function selectComponentToHang(successId, errorId, formId, urls, loadingId)
303
$(errorId).innerHTML = "";
306
loadingId = 'loadingTable';
309
// Currently buggy, since select elements are not inputs
310
// var selects = $(formId).getInputs('select');
311
var children = $(formId).immediateDescendants();
313
for ( var i = 0; i < children.length; i++) {
314
if ( children[i].tagName == 'SELECT' ) {
315
select = children[i];
318
var url = urls[ $F(select.id) ]
320
var pars = "action=view"; // FIXME: maybe the directory could be sent
322
var ajaxUpdate = new Ajax.Updater(
333
onSuccess: function(t) {
334
restoreHidden(loadingId);
336
onFailure: function(t) {
337
restoreHidden(loadingId);
342
setLoading(loadingId);
245
348
Function: showSelected
269
372
var node = $(nodeId).childNodes[idx];
270
373
// I'd like to use constant but in IE 6 simply they don't exist
271
374
if ( node.nodeType == 1 /* Node.ELEMENT_NODE */ ) {
375
var descendants = $(node).descendants();
272
376
if ( node.id == selectedValue ) {
378
// Show not only the selected by its children
379
descendants.each(function(desc) {
384
// Hide not only the selected by its children
386
descendants.each(function(desc) {
429
/* TODO: showPortRange and showPort do things in common
430
like showing/hiding elments depending on which value
431
is selected elsewhere. We should refactor this
432
and provide a generic function to do that. Logic should
433
come from model and translated in javascript.
435
Function: showPortRange
437
Show/Hide elements in PortRange view
441
id - the select identifier which the protocol is chosen
444
function showPortRange(id)
447
var selectId = id + "_range_type";
448
var selectedIdx = $(selectId).selectedIndex;
449
var selectedValue = $(selectId).options[selectedIdx].value;
451
if ( selectedValue == "range") {
453
hide(id + "_single");
454
$(id + "_single_port").value = "";
455
} else if (selectedValue == "single") {
457
show(id + "_single");
458
$(id + "_to_port").value = "";
459
$(id + "_from_port").value = "";
462
hide(id + "_single");
463
$(id + "_to_port").value = "";
464
$(id + "_from_port").value = "";
465
$(id + "_single_port").value = "";
318
470
Function: setLoading
320
472
Set the loading icon on the given HTML element erasing
321
everything which were there
473
everything which were there. If modelName is set, isSaved parameter can be used
325
477
elementId - the element identifier
478
modelName - the model name to distinguish among hiddenDiv tags *(Optional)*
326
479
isSaved - boolean to indicate if the inner HTML should be saved
327
at *hiddenDiv* in order to be rescued afterwards *(Optional)*
480
at *hiddenDiv_<modelName>* in order to be rescued afterwards *(Optional)*
330
function setLoading (elementId, isSaved)
484
function setLoading (elementId, modelName, isSaved)
334
$('hiddenDiv').innerHTML = $(elementId).innerHTML;
487
var hiddenDivId = 'hiddenDiv';
489
hiddenDivId = hiddenDivId + '_' + modelName;
491
$(hiddenDivId).innerHTML = $(elementId).innerHTML;
337
495
$(elementId).innerHTML = "<img src='/data/images/ajax-loader.gif' " +
503
Set the done icon (a tick) on the given HTML element erasing
504
everything which were there.
508
elementId - String the element identifier
512
function setDone (elementId)
515
$(elementId).innerHTML = "<img src='/data/images/apply.gif' " +
516
"alt='done' class='tcenter'/>";
343
522
Function: restoreHidden
345
524
Restore HTML stored in *hiddenDiv*
349
528
elementId - the element identifier where to restore the HTML hidden
529
modelName - the model name to distinguish among hiddenDiv tags
352
function restoreHidden (elementId)
532
function restoreHidden (elementId, modelName)
355
$(elementId).innerHTML = $('hiddenDiv').innerHTML;
356
$('hiddenDiv').innerHTML = '';
536
var hiddenDivId = 'hiddenDiv' + '_' + modelName;
537
if ( $(hiddenDivId).innerHTML != '' ) {
538
$(elementId).innerHTML = $(hiddenDivId).innerHTML;
540
$(hiddenDivId).innerHTML = '';
543
// Remove the loading image if any
544
if ( $(elementId).firstChild ) {
545
if ( $(elementId).firstChild.alt == 'loading...' ) {
546
$(elementId).innerHTML = '';
613
Use $F() to return an input value. It firstly checks
614
using $() if the id exits
618
elementId - the input element to fetch the value from
622
input value if it exits, otherwise empty string
624
function inputValue(elementId) {
627
return $F(elementId);