- select.php & view.php : Correction d'un bug concernant le trie lors d'un
[ldapsaisie.git] / trunk / includes / js / LSdefault.js
1 var LSdefault = new Class({
2     initialize: function(){
3       this.LSdebug = $('LSdebug');
4       this.LSdebugInfos = $('LSdebug_infos');
5       this.LSdebug.setOpacity(0);
6
7       this.LSdebugHidden = $('LSdebug_hidden');
8       this.LSdebugHidden.addEvent('click',this.onLSdebugHiddenClick.bindWithEvent(this));
9       
10       this.LSerror = $('LSerror');
11       this.LSerror.setOpacity(0);
12
13       this.loading_img=[];
14       this.loading_img_id=-1;
15       
16       this.LSsession_topDn = $('LSsession_topDn');
17       if (this.LSsession_topDn) {
18         this.LSsession_topDn.addEvent('change',this.onLSsession_topDnChange.bind(this));
19       }
20       
21       this.fx = {
22         LSdebug:  new Fx.Tween(this.LSdebug,{property: 'opacity',duration:600}),
23         LSerror:  new Fx.Tween(this.LSerror,{property: 'opacity',duration:500})
24       };
25       
26       if (this.LSdebugInfos.innerHTML != '') {
27         this.displayDebugBox();
28       }
29       
30       if (this.LSerror.innerHTML != '') {
31         this.displayErrorBox.bind(this);
32       }
33     },
34
35     onLSsession_topDnChange: function() {
36       $('LSsession_topDn_form').submit();
37     },
38
39     onLSdebugHiddenClick: function(event){
40       new Event(event).stop();
41       this.fx.LSdebug.start(0.8,0);
42     },
43
44     checkAjaxReturn: function(data) {
45       if (typeof(data) == 'object') {
46         if (typeof(data.imgload) != "undefined") {
47           this.loadingImgHide(data.imgload);
48         }
49         else {
50           this.loadingImgHide();
51         }
52         
53         if (typeof(data.LSdebug) != "undefined") {
54           LSdebug(data.LSdebug);
55           this.displayDebug(data.LSdebug);
56         }
57         
58         if (typeof(data.LSerror) != "undefined") {
59           this.displayError(data.LSerror);
60           return;
61         }
62         return true;
63       }
64       else {
65         LSdebug('retour non-interpr├ętable');
66         this.loadingImgHide();
67         return;
68       }
69     },
70
71     displayError: function(html) {
72       this.LSerror.set('html',html);
73       this.displayErrorBox();
74     },
75
76     displayDebug: function(html) {
77       this.LSdebugInfos.set('html',html);
78       this.displayDebugBox();
79     },
80
81     displayErrorBox: function() {
82       this.LSerror.setStyle('top',getScrollTop()+10);
83       this.fx.LSerror.start(0,0.8);
84       (function(){this.fx.LSerror.start(0.8,0);}).delay(10000, this);
85     },
86     
87     displayDebugBox: function() {
88       this.LSdebug.setStyle('top',getScrollTop()+10);
89       this.fx.LSdebug.start(0,0.8);
90     },
91
92     loadingImgDisplay: function(el,position,size) {
93       this.loading_img_id++;
94       this.loading_img[this.loading_img_id] = new Element('img');
95       if (size=='big') {
96         var src = 'templates/images/loading.gif';
97       }
98       else {
99         var src = 'templates/images/ajax-loader.gif';
100       }
101       this.loading_img[this.loading_img_id].src=src;
102       if (position=='inside') {
103         this.loading_img[this.loading_img_id].injectInside(el);
104       }
105       else {
106         this.loading_img[this.loading_img_id].injectAfter(el);
107       }
108       return this.loading_img_id;
109     },
110
111     loadingImgHide: function(id) {
112       if (isNaN(id)) {
113         this.loading_img.each(function(el)  {
114           if (typeof(el) != 'undefined')
115             el.destroy();
116         },this);
117         this.loading_img_id=-1;
118       }
119       else {
120         this.loading_img[id].destroy();
121       }
122     },
123     
124     ajaxDisplayDebugAndError: function() {
125       var LSdebug_txt = $('LSdebug_txt');
126       if (LSdebug_txt) {
127         var debug = LSdebug_txt.innerHTML;
128         if (debug) {
129           this.displayDebug(debug.toString());
130         }
131       }
132       
133       var LSerror_txt = $('LSerror_txt');
134       if (LSerror_txt) {
135         var error=LSerror_txt.innerHTML;
136         if (error) {
137           this.displayError(error.toString());
138         }
139       }
140     }
141
142 });
143 window.addEvent(window.ie ? 'load' : 'domready', function() {
144   varLSdefault = new LSdefault();
145 });
146
147 var LSdebug_active = 0;
148
149 function LSdebug() {
150     if (LSdebug_active != 1) return;
151     if (typeof console == 'undefined') return;
152     console.log.apply(this, arguments);
153 }