- LSview : ajout de input hidden pour contenir les informations du type et du
[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.LSinfos = $('LSinfos');
14
15       this.LSjsConfigEl = $('LSjsConfig');
16       if ($type(this.LSjsConfigEl)) {
17         this.LSjsConfig = JSON.decode(this.LSjsConfigEl.innerHTML);
18       }
19       else {
20         this.LSjsConfig = [];
21       }
22
23       this.loading_img=[];
24       this.loading_img_id=-1;
25       
26       this.LSsession_topDn = $('LSsession_topDn');
27       if (this.LSsession_topDn) {
28         this.LSsession_topDn.addEvent('change',this.onLSsession_topDnChange.bind(this));
29       }
30       
31       this.fx = {
32         LSdebug:  new Fx.Tween(this.LSdebug,{property: 'opacity',duration:600}),
33         LSerror:  new Fx.Tween(this.LSerror,{property: 'opacity',duration:500}),
34         LSinfos:  new Fx.Tween(this.LSinfos,{property: 'opacity',duration:500})
35       };
36       
37       if (this.LSdebugInfos.innerHTML != '') {
38         this.displayDebugBox();
39       }
40       
41       if (this.LSerror.innerHTML != '') {
42         this.displayErrorBox();
43       }
44       
45       if (this.LSinfos.innerHTML != '') {
46         this.displayInfosBox();
47       }
48     },
49
50     onLSsession_topDnChange: function() {
51       $('LSsession_topDn_form').submit();
52     },
53
54     onLSdebugHiddenClick: function(event){
55       new Event(event).stop();
56       this.fx.LSdebug.start(0.8,0);
57     },
58
59     checkAjaxReturn: function(data) {
60       if (typeof(data) == 'object') {
61         if (typeof(data.imgload) != "undefined") {
62           this.loadingImgHide(data.imgload);
63         }
64         else {
65           this.loadingImgHide();
66         }
67         
68         if (typeof(data.LSdebug) != "undefined") {
69           LSdebug(data.LSdebug);
70           this.displayDebug(data.LSdebug);
71         }
72         
73         if (typeof(data.LSerror) != "undefined") {
74           this.displayError(data.LSerror);
75           return;
76         }
77         return true;
78       }
79       else {
80         LSdebug('retour non-interpr├ętable');
81         this.loadingImgHide();
82         return;
83       }
84     },
85
86     displayError: function(html) {
87       this.LSerror.set('html',html);
88       this.displayErrorBox();
89     },
90
91     displayDebug: function(html) {
92       this.LSdebugInfos.set('html',html);
93       this.displayDebugBox();
94     },
95     
96     displayInfos: function(html) {
97       this.LSinfos.set('html',html);
98       this.displayInfosBox();
99     },
100     
101     displayErrorBox: function() {
102       this.LSerror.setStyle('top',getScrollTop()+10);
103       this.fx.LSerror.start(0,0.8);
104       (function(){this.fx.LSerror.start(0.8,0);}).delay(10000, this);
105     },
106     
107     displayInfosBox: function() {
108       this.LSinfos.setStyle('top',getScrollTop()+10);
109       this.fx.LSinfos.start(0,0.9);
110       (function(){this.fx.LSinfos.start(0.9,0);}).delay(5000, this);
111     },
112     
113     displayDebugBox: function() {
114       this.LSdebug.setStyle('top',getScrollTop()+10);
115       this.fx.LSdebug.start(0,0.8);
116     },
117
118     loadingImgDisplay: function(el,position,size) {
119       this.loading_img_id++;
120       this.loading_img[this.loading_img_id] = new Element('img');
121       if (size=='big') {
122         var src = 'templates/images/loading.gif';
123       }
124       else {
125         var src = 'templates/images/ajax-loader.gif';
126       }
127       this.loading_img[this.loading_img_id].src=src;
128       if (position=='inside') {
129         this.loading_img[this.loading_img_id].injectInside(el);
130       }
131       else {
132         this.loading_img[this.loading_img_id].injectAfter(el);
133       }
134       return this.loading_img_id;
135     },
136
137     loadingImgHide: function(id) {
138       if (isNaN(id)) {
139         this.loading_img.each(function(el)  {
140           if (typeof(el) != 'undefined')
141             el.destroy();
142         },this);
143         this.loading_img_id=-1;
144       }
145       else {
146         this.loading_img[id].destroy();
147       }
148     },
149     
150     ajaxDisplayDebugAndError: function() {
151       var LSdebug_txt = $('LSdebug_txt');
152       if (LSdebug_txt) {
153         var debug = LSdebug_txt.innerHTML;
154         if (debug) {
155           this.displayDebug(debug.toString());
156         }
157       }
158       
159       var LSerror_txt = $('LSerror_txt');
160       if (LSerror_txt) {
161         var error=LSerror_txt.innerHTML;
162         if (error) {
163           this.displayError(error.toString());
164         }
165       }
166     }
167
168 });
169
170 window.addEvent(window.ie ? 'load' : 'domready', function() {
171   varLSdefault = new LSdefault();
172 });