- 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
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 (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 = this.imagePath('loading.gif');
123       }
124       else {
125         var src = this.imagePath('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     imagePath: function(image) {
169       return this.LSjsConfig['LS_IMAGES_DIR'] + '/' + image;
170     },
171     
172     getParams: function(name) {
173       if ($type(this.LSjsConfig[name])) {
174         return this.LSjsConfig[name];
175       }
176       return new Hash();
177     }
178
179 });
180
181 window.addEvent(window.ie ? 'load' : 'domready', function() {
182   varLSdefault = new LSdefault();
183 });