File: admin.js

package info (click to toggle)
lwat 0.17-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 860 kB
  • ctags: 945
  • sloc: php: 3,151; sh: 212; makefile: 148
file content (105 lines) | stat: -rw-r--r-- 3,495 bytes parent folder | download | duplicates (2)
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
//
//  LWAT, LDAP Webbased Administration Tool
//  Copyright (C) 2007  Finn-Arne Johansen <faj@bzz.no> BzzWare AS, Norway
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License along
//  with this program; if not, write to the Free Software Foundation, Inc.,
//  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
function toggleLayer( whichLayer ) {
    var elem, vis;
    if( document.getElementById ) // this is the way the standards work
        elem = document.getElementById( whichLayer );
    else if( document.all ) // this is the way old msie versions work
        elem = document.all[whichLayer];
    else if( document.layers ) // this is the way nn4 works
        elem = document.layers[whichLayer];
    vis = elem.style;
    // if the style.display value is blank we try to figure it out here
    if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
        vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
    vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}



//  ajaxRequest
//  Create an ajax object to communicate with serverside.
//  Sorry, need a lot of javascript here :( 
//  returns an object, or false
function ajaxRequest () {
    var request ; 
    try {
        request = new ActiveXObject ("Microsoft.XMLHTTP"); 
        //request = new ActiveXObject ("MSXML2.XMLHTTP.3.0"); 
    } catch (exception) {
        var noIExmlHTTP = true ;
    }
    if (noIExmlHTTP == true) {
        try {
            request = new XMLHttpRequest() ; 
        } catch (exception) {
            request = false ;
        }
    }
    return request ; 
}

// Create a new request
var ajax = ajaxRequest() ; 
var targetToUpdate ; 
var ajaxBusy ; 

// Action 
// Sends of an request, and sets up an handler to handle the response
function Action ($request, $target) {
    if (ajaxBusy) return ;
    if (! ajax) {
        alert ("Sorry, your browser is just to old :( ") ; 
        return ; 
    }
    targetToUpdate=$target
    try { ajax.abort; } catch (exception) {} 
    ajaxBusy = true ; 
    ajax.open ('post', 'admin.php'); 
    ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    ajax.onreadystatechange = handleAction;
    ajax.send('action=' + $request );
}

// handleAction
// test if things are ready, then 
//   show reponse
function handleAction() {
    if (ajax.readyState == 4) {
        var response = ajax.responseText;
        document.getElementById(targetToUpdate).innerHTML = response ; 
        ajaxBusy = false ;
    }
}

// chkBoxAction
// Run through a form and submit the checked boxes
function chkBoxAction ($form, $request,$target) {
    var x=document.getElementById($form) ; 
    var chkBox = '' ; 

    for (var i=0 ; i < x.length ; i++) {
        if (x.elements[i].checked) { 
            chkBox = chkBox + '&checked_' + i + '=' + x.elements[i].value ; 
        }
    }
    Action ($request + chkBox, $target); 
}