- LStips : D├ęplacement de la gestion des LStips de LSform vers LSdefault
[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       this.LStips = new Tips('.LStips');
51     },
52
53     onLSsession_topDnChange: function() {
54       $('LSsession_topDn_form').submit();
55     },
56
57     LSdebugHidde: function(){
58       this.fx.LSdebug.start(0.8,0);
59     },
60
61     checkAjaxReturn: function(data) {
62       if ($type(data) == 'object') {
63         if ($type(data.imgload)) {
64           this.loadingImgHide(data.imgload);
65         }
66         else {
67           this.loadingImgHide();
68         }
69         
70         if ($type(data.LSdebug)) {
71           LSdebug(data.LSdebug);
72           this.displayDebug(data.LSdebug);
73         }
74         
75         if ($type(data.LSinfos)) {
76           this.displayInfos(data.LSinfos);
77         }
78         
79         if ($type(data.LSerror)) {
80           this.displayError(data.LSerror);
81           return;
82         }
83         return true;
84       }
85       else {
86         LSdebug('retour non-interpr├ętable');
87         this.loadingImgHide();
88         return;
89       }
90     },
91
92     displayError: function(html) {
93       this.LSerror.set('html',html);
94       this.displayErrorBox();
95     },
96
97     displayDebug: function(html) {
98       this.LSdebugInfos.set('html',html);
99       this.displayDebugBox();
100     },
101     
102     displayInfos: function(html) {
103       this.LSinfos.set('html',html);
104       this.displayInfosBox();
105     },
106     
107     displayErrorBox: function() {
108       this.LSerror.setStyle('top',getScrollTop()+10);
109       this.fx.LSerror.start(0,0.8);
110       (function(){this.fx.LSerror.start(0.8,0);}).delay(10000, this);
111     },
112     
113     displayInfosBox: function() {
114       this.LSinfos.setStyle('top',getScrollTop()+10);
115       this.fx.LSinfos.start(0,0.9);
116       (function(){this.fx.LSinfos.start(0.9,0);}).delay(5000, this);
117     },
118     
119     displayDebugBox: function() {
120       this.LSdebug.setStyle('top',getScrollTop()+10);
121       this.fx.LSdebug.start(0,0.8);
122     },
123
124     loadingImgDisplay: function(el,position,size) {
125       this.loading_img_id++;
126       this.loading_img[this.loading_img_id] = new Element('img');
127       if (size=='big') {
128         var src = this.imagePath('loading.gif');
129       }
130       else {
131         var src = this.imagePath('ajax-loader.gif');
132       }
133       this.loading_img[this.loading_img_id].src=src;
134       if (position=='inside') {
135         this.loading_img[this.loading_img_id].injectInside(el);
136       }
137       else {
138         this.loading_img[this.loading_img_id].injectAfter(el);
139       }
140       return this.loading_img_id;
141     },
142
143     loadingImgHide: function(id) {
144       if (isNaN(id)) {
145         this.loading_img.each(function(el)  {
146           if (typeof(el) != 'undefined')
147             el.destroy();
148         },this);
149         this.loading_img_id=-1;
150       }
151       else {
152         this.loading_img[id].destroy();
153       }
154     },
155     
156     ajaxDisplayDebugAndError: function() {
157       var LSdebug_txt = $('LSdebug_txt');
158       if (LSdebug_txt) {
159         var debug = LSdebug_txt.innerHTML;
160         if (debug) {
161           this.displayDebug(debug.toString());
162         }
163       }
164       
165       var LSerror_txt = $('LSerror_txt');
166       if (LSerror_txt) {
167         var error=LSerror_txt.innerHTML;
168         if (error) {
169           this.displayError(error.toString());
170         }
171       }
172     },
173     
174     imagePath: function(image) {
175       return this.LSjsConfig['LS_IMAGES_DIR'] + '/' + image;
176     },
177     
178     getParams: function(name) {
179       if ($type(this.LSjsConfig[name])) {
180         return this.LSjsConfig[name];
181       }
182       return new Hash();
183     },
184     
185     addHelpInfo: function(el,group,name) {
186       if ($type(this.LSjsConfig['helpInfos'])) {
187         if ($type(el)=='element') {
188           if ($type(this.LSjsConfig['helpInfos'][group])) {
189             if ($type(this.LSjsConfig['helpInfos'][group][name])) {
190               this.addTip(el);
191               el.store('tip:title',this.LSjsConfig['helpInfos'][group][name]);
192               el.store('tip:text',"");
193             }
194           }
195         }
196       }
197     },
198     
199     setHelpInfo: function(el,group,name) {
200       if ($type(this.LSjsConfig['helpInfos'])) {
201         if ($type(el)=='element') {
202           if ($type(this.LSjsConfig['helpInfos'][group])) {
203             if ($type(this.LSjsConfig['helpInfos'][group][name])) {
204               el.store('tip:title',this.LSjsConfig['helpInfos'][group][name]);
205               el.store('tip:text',"");
206             }
207           }
208         }
209       }
210     },
211     
212     addTip: function(el) {
213       this.LStips.attach(el);
214     },
215     
216     removeTip: function(el) {
217       this.LStips.detach(el);
218     }
219
220 });
221
222 window.addEvent(window.ie ? 'load' : 'domready', function() {
223   varLSdefault = new LSdefault();
224 });