- Correction de quelques petites choses pour un meilleur fonctionnement sous
[ldapsaisie.git] / trunk / includes / js / LSdefault.js
1 var LSdefault = new Class({
2     initialize: function(){
3       this.LSdebug = $('LSdebug');
4       this.LSdebug.addEvent('dblclick',this.LSdebugHidde.bind(this));
5       this.LSdebugInfos = $('LSdebug_infos');
6       this.LSdebug.setOpacity(0);
7
8       this.LSdebugHidden = $('LSdebug_hidden');
9       this.LSdebugHidden.addEvent('click',this.LSdebugHidde.bind(this));
10       
11       this.LSerror = $('LSerror');
12       this.LSerror.setOpacity(0);
13       
14       this.LSinfos = $('LSinfos');
15
16       this.LSjsConfigEl = $('LSjsConfig');
17       if ($type(this.LSjsConfigEl)) {
18         this.LSjsConfig = JSON.decode(this.LSjsConfigEl.innerHTML);
19       }
20       else {
21         this.LSjsConfig = [];
22       }
23
24       this.loading_img=[];
25       this.loading_img_id=-1;
26       
27       this.LSsession_topDn = $('LSsession_topDn');
28       if (this.LSsession_topDn) {
29         this.LSsession_topDn.addEvent('change',this.onLSsession_topDnChange.bind(this));
30       }
31       
32       this.fx = {
33         LSdebug:  new Fx.Tween(this.LSdebug,{property: 'opacity',duration:600}),
34         LSerror:  new Fx.Tween(this.LSerror,{property: 'opacity',duration:500}),
35         LSinfos:  new Fx.Tween(this.LSinfos,{property: 'opacity',duration:500})
36       };
37       
38       if (this.LSdebugInfos.innerHTML != '') {
39         this.displayDebugBox();
40       }
41       
42       if (this.LSerror.innerHTML != '') {
43         this.displayErrorBox();
44       }
45       
46       if (this.LSinfos.innerHTML != '') {
47         this.displayInfosBox();
48       }
49     },
50
51     onLSsession_topDnChange: function() {
52       $('LSsession_topDn_form').submit();
53     },
54
55     LSdebugHidde: function(){
56       this.fx.LSdebug.start(0.8,0);
57     },
58
59     checkAjaxReturn: function(data) {
60       if ($type(data) == 'object') {
61         if ($type(data.imgload)) {
62           this.loadingImgHide(data.imgload);
63         }
64         else {
65           this.loadingImgHide();
66         }
67         
68         if ($type(data.LSdebug)) {
69           LSdebug(data.LSdebug);
70           this.displayDebug(data.LSdebug);
71         }
72         
73         if ($type(data.LSinfos)) {
74           this.displayInfos(data.LSinfos);
75         }
76         
77         if ($type(data.LSerror)) {
78           this.displayError(data.LSerror);
79           return;
80         }
81         return true;
82       }
83       else {
84         LSdebug('retour non-interpr├ętable');
85         this.loadingImgHide();
86         return;
87       }
88     },
89
90     displayError: function(html) {
91       this.LSerror.set('html',html);
92       this.displayErrorBox();
93     },
94
95     displayDebug: function(html) {
96       this.LSdebugInfos.set('html',html);
97       this.displayDebugBox();
98     },
99     
100     displayInfos: function(html) {
101       this.LSinfos.set('html',html);
102       this.displayInfosBox();
103     },
104     
105     displayErrorBox: function() {
106       this.LSerror.setStyle('top',getScrollTop()+10);
107       this.fx.LSerror.start(0,0.8);
108       (function(){this.fx.LSerror.start(0.8,0);}).delay(10000, this);
109     },
110     
111     displayInfosBox: function() {
112       this.LSinfos.setStyle('top',getScrollTop()+10);
113       this.fx.LSinfos.start(0,0.9);
114       (function(){this.fx.LSinfos.start(0.9,0);}).delay(5000, this);
115     },
116     
117     displayDebugBox: function() {
118       this.LSdebug.setStyle('top',getScrollTop()+10);
119       this.fx.LSdebug.start(0,0.8);
120     },
121
122     loadingImgDisplay: function(el,position,size) {
123       this.loading_img_id++;
124       this.loading_img[this.loading_img_id] = new Element('img');
125       if (size=='big') {
126         var src = this.imagePath('loading.gif');
127       }
128       else {
129         var src = this.imagePath('ajax-loader.gif');
130       }
131       this.loading_img[this.loading_img_id].src=src;
132       if (position=='inside') {
133         this.loading_img[this.loading_img_id].injectInside(el);
134       }
135       else {
136         this.loading_img[this.loading_img_id].injectAfter(el);
137       }
138       return this.loading_img_id;
139     },
140
141     loadingImgHide: function(id) {
142       if (isNaN(id)) {
143         this.loading_img.each(function(el)  {
144           if (typeof(el) != 'undefined')
145             el.destroy();
146         },this);
147         this.loading_img_id=-1;
148       }
149       else {
150         this.loading_img[id].destroy();
151       }
152     },
153     
154     ajaxDisplayDebugAndError: function() {
155       var LSdebug_txt = $('LSdebug_txt');
156       if (LSdebug_txt) {
157         var debug = LSdebug_txt.innerHTML;
158         if (debug) {
159           this.displayDebug(debug.toString());
160         }
161       }
162       
163       var LSerror_txt = $('LSerror_txt');
164       if (LSerror_txt) {
165         var error=LSerror_txt.innerHTML;
166         if (error) {
167           this.displayError(error.toString());
168         }
169       }
170     },
171     
172     imagePath: function(image) {
173       return this.LSjsConfig['LS_IMAGES_DIR'] + '/' + image;
174     },
175     
176     getParams: function(name) {
177       if ($type(this.LSjsConfig[name])) {
178         return this.LSjsConfig[name];
179       }
180       return new Hash();
181     },
182     
183     addHelpInfo: function(el,group,name) {
184       if ($type(this.LSjsConfig['helpInfos'])) {
185         if ($type(el)=='element') {
186           if ($type(this.LSjsConfig['helpInfos'][group])) {
187             if ($type(this.LSjsConfig['helpInfos'][group][name])) {
188               varLSform.addTip(el);
189               el.store('tip:title',this.LSjsConfig['helpInfos'][group][name]);
190               el.store('tip:text',"");
191             }
192           }
193         }
194       }
195     },
196     
197     setHelpInfo: function(el,group,name) {
198       if ($type(this.LSjsConfig['helpInfos'])) {
199         if ($type(el)=='element') {
200           if ($type(this.LSjsConfig['helpInfos'][group])) {
201             if ($type(this.LSjsConfig['helpInfos'][group][name])) {
202               el.store('tip:title',this.LSjsConfig['helpInfos'][group][name]);
203               el.store('tip:text',"");
204             }
205           }
206         }
207       }
208     }
209
210 });
211
212 window.addEvent(window.ie ? 'load' : 'domready', function() {
213   varLSdefault = new LSdefault();
214 });