1 | //****c* ExpressoLivreAPI/ExpressoLivre |
---|
2 | // NAME |
---|
3 | // ExpressoLivre |
---|
4 | // |
---|
5 | // DESCRIPTION |
---|
6 | // Composto pelas classes utilizadas no ExpressoLivre |
---|
7 | // |
---|
8 | // AUTHOR |
---|
9 | // Rodrigo Souza dos Santos |
---|
10 | // |html <br /><a href="mailto:%72%6f%64%72%69%67%6f%2e%73%6f%75%7a%61%40%63%65%6c%65%70%61%72%2e%70%72%2e%67%6f%76%2e%62%72">rodrigo.souza@celepar.pr.gov.br</a> |
---|
11 | // |html <br /><a href="mailto:%72%6f%64%72%69%67%6f%73%6f%75%7a%61%64%6f%73%73%61%6e%74%6f%73%40%67%6d%61%69%6c%2e%63%6f%6d">rodrigosouzadossantos@gmail.com</a> |
---|
12 | // |
---|
13 | // NOTES |
---|
14 | // A composição possui instâncias configuradas de forma a atender a maioria |
---|
15 | // dos casos independente do módulo. |
---|
16 | // |
---|
17 | //****** |
---|
18 | // You can use this space for remarks that should not be included |
---|
19 | // in the documentation. |
---|
20 | // |
---|
21 | ( function( ) |
---|
22 | { |
---|
23 | var _configuration = ExpressoLivre( ).JSON( ); |
---|
24 | |
---|
25 | var _xconnector = null; |
---|
26 | var _xlink = null; |
---|
27 | |
---|
28 | window.array_lang = [ ]; |
---|
29 | |
---|
30 | var _language = [ ]; |
---|
31 | |
---|
32 | var _divAppboxHeader = null; |
---|
33 | var _divAppbox = null; |
---|
34 | |
---|
35 | var _loading = new Image( ); |
---|
36 | |
---|
37 | var _events_registred = { |
---|
38 | "onload" : null, |
---|
39 | "onunload" : null |
---|
40 | }; |
---|
41 | |
---|
42 | function _events( ) |
---|
43 | { |
---|
44 | return ( new function( ) |
---|
45 | { |
---|
46 | //****m* ExpressoLivreAPI/ExpressoLivre/events/config |
---|
47 | // NAME |
---|
48 | // config |
---|
49 | // |
---|
50 | // DESCRIPTION |
---|
51 | // Atribui uma ação a um evento em um objeto |
---|
52 | // |
---|
53 | // SYNOPSIS |
---|
54 | // config( Object, String, Function ) |
---|
55 | // |
---|
56 | // INPUTS |
---|
57 | // |
---|
58 | // EXAMPLE |
---|
59 | // function myHandler( ) |
---|
60 | // { |
---|
61 | // /*do something*/ |
---|
62 | // } |
---|
63 | // |
---|
64 | // ExpressoLivre.config( node, "onclick", myHandler ); |
---|
65 | // |
---|
66 | // ExpressoLivre.config( node, "onclick", function( ) |
---|
67 | // { |
---|
68 | // /*do something*/ |
---|
69 | // } ); |
---|
70 | // |
---|
71 | //****** |
---|
72 | this.config = XEvents.add; |
---|
73 | this.fire = ( new function( ) |
---|
74 | { |
---|
75 | this.onload = function( ) |
---|
76 | { |
---|
77 | if ( _events_registred.onload ) |
---|
78 | { |
---|
79 | _events_registred.onload( ); |
---|
80 | _events_registred.onload = null; |
---|
81 | } |
---|
82 | }; |
---|
83 | this.onunload = function( ) |
---|
84 | { |
---|
85 | if ( _events_registred.onunload ) |
---|
86 | { |
---|
87 | _events_registred.onunload( ); |
---|
88 | _events_registred.onunload = null; |
---|
89 | } |
---|
90 | }; |
---|
91 | } ); |
---|
92 | this.onload = function( ) |
---|
93 | { |
---|
94 | if ( arguments.length && arguments[ 0 ] == null ) |
---|
95 | return false; |
---|
96 | |
---|
97 | if ( arguments[ 0 ].constructor == Boolean && arguments[ 0 ] == false ) |
---|
98 | { |
---|
99 | _events_registred.onload = null; |
---|
100 | return true; |
---|
101 | } |
---|
102 | |
---|
103 | if ( arguments[ 0 ].constructor == Function ) |
---|
104 | { |
---|
105 | _events_registred.onload = arguments[ 0 ]; |
---|
106 | return true; |
---|
107 | } |
---|
108 | |
---|
109 | return false; |
---|
110 | }; |
---|
111 | this.onunload = function( ) |
---|
112 | { |
---|
113 | if ( arguments.length && arguments[ 0 ] == null ) |
---|
114 | return false; |
---|
115 | |
---|
116 | if ( arguments[ 0 ].constructor == Boolean && arguments[ 0 ] == false ) |
---|
117 | { |
---|
118 | _events_registred.onunload = null; |
---|
119 | return true; |
---|
120 | } |
---|
121 | |
---|
122 | if ( arguments[ 0 ].constructor == Function ) |
---|
123 | { |
---|
124 | _events_registred.onunload = arguments[ 0 ]; |
---|
125 | return true; |
---|
126 | } |
---|
127 | |
---|
128 | return false; |
---|
129 | }; |
---|
130 | } ); |
---|
131 | } |
---|
132 | |
---|
133 | function _form( ) |
---|
134 | { |
---|
135 | if ( ! arguments.length ) |
---|
136 | return false; |
---|
137 | |
---|
138 | var _handler = null; |
---|
139 | |
---|
140 | if ( arguments.length > 1 && arguments[ 1 ] && arguments[ 1 ].constructor == Function ) |
---|
141 | _handler = arguments[ 1 ]; |
---|
142 | else |
---|
143 | _handler = _xlink.manipulator; |
---|
144 | |
---|
145 | _wait( ); |
---|
146 | |
---|
147 | return XForm( arguments[ 0 ], _handler ); |
---|
148 | } |
---|
149 | |
---|
150 | function _go( ) |
---|
151 | { |
---|
152 | _xconnector.go.apply( _xconnector, arguments ); |
---|
153 | } |
---|
154 | |
---|
155 | function _lang( ) |
---|
156 | { |
---|
157 | if ( ! ( arguments.length && arguments[ 0 ].constructor == String ) ) |
---|
158 | return false; |
---|
159 | |
---|
160 | var module = arguments[ 0 ]; |
---|
161 | var lang = document.getElementsByTagName( 'html' ).item( 0 ).getAttribute( 'xml:lang' ); |
---|
162 | |
---|
163 | _xconnector.go( { |
---|
164 | 'access' : 'phpgwapi.expressolivre.lang&lang=' + lang + '&module=' + module, |
---|
165 | 'cache' : true, |
---|
166 | 'handler' : function( data ) |
---|
167 | { |
---|
168 | data = data.JSON( ); |
---|
169 | for ( var key in data ) |
---|
170 | window.array_lang[ key ] = _language[ key ] = data[ key ]; |
---|
171 | } |
---|
172 | } ); |
---|
173 | } |
---|
174 | |
---|
175 | function _link( ) |
---|
176 | { |
---|
177 | _xlink.click.apply( _xlink, arguments ); |
---|
178 | } |
---|
179 | |
---|
180 | function _path( ) |
---|
181 | { |
---|
182 | return _configuration.url; |
---|
183 | } |
---|
184 | |
---|
185 | function _template( ) |
---|
186 | { |
---|
187 | return _configuration.template; |
---|
188 | } |
---|
189 | |
---|
190 | function _theme( ) |
---|
191 | { |
---|
192 | return _configuration.theme; |
---|
193 | } |
---|
194 | |
---|
195 | function _translate( ) |
---|
196 | { |
---|
197 | if ( ! ( arguments.length && arguments[ 0 ].constructor == String ) ) |
---|
198 | return false; |
---|
199 | |
---|
200 | var _phrase = arguments[ 0 ]; |
---|
201 | |
---|
202 | if ( _language[ _phrase.toLowerCase( ) ] ) |
---|
203 | _phrase = _language[ _phrase.toLowerCase( ) ]; |
---|
204 | else |
---|
205 | _phrase += '*'; |
---|
206 | |
---|
207 | if ( arguments.length > 1 ) |
---|
208 | for ( var j = 1; j < ( arguments.length ); j++ ) |
---|
209 | if ( arguments[ j ] && ( arguments[ j ].constructor == String || arguments[ j ].constructor == Number)) |
---|
210 | _phrase = _phrase.replace( "%" + j, arguments[ j ] ); |
---|
211 | |
---|
212 | return _phrase; |
---|
213 | } |
---|
214 | |
---|
215 | function _wait( ) |
---|
216 | { |
---|
217 | _ExpressoLivre.events.fire.onunload( ); |
---|
218 | |
---|
219 | if ( _divAppboxHeader ) |
---|
220 | _divAppboxHeader.innerHTML = ''; |
---|
221 | |
---|
222 | if ( _divAppbox ) |
---|
223 | { |
---|
224 | var _center = document.createElement( 'center' ); |
---|
225 | _center.appendChild( _loading ); |
---|
226 | |
---|
227 | _divAppbox.innerHTML = ''; |
---|
228 | _divAppbox.appendChild( _center ); |
---|
229 | } |
---|
230 | } |
---|
231 | |
---|
232 | var _ExpressoLivre = ( new function( ) |
---|
233 | { |
---|
234 | //****m* ExpressoLivreAPI/ExpressoLivre/events |
---|
235 | // NAME |
---|
236 | // events |
---|
237 | // |
---|
238 | // DESCRIPTION |
---|
239 | // Realiza uma requisição ao servidor. |
---|
240 | // |
---|
241 | // SYNOPSIS |
---|
242 | // events( Object ) |
---|
243 | // |
---|
244 | // INPUTS |
---|
245 | // |
---|
246 | // EXAMPLE |
---|
247 | // |
---|
248 | //****** |
---|
249 | this.events = _events( ); |
---|
250 | |
---|
251 | //****m* ExpressoLivreAPI/ExpressoLivre/form |
---|
252 | // NAME |
---|
253 | // form |
---|
254 | // |
---|
255 | // DESCRIPTION |
---|
256 | // Processa e envia um formulário, utilizando a URL do atributo "action". |
---|
257 | // |
---|
258 | // SYNOPSIS |
---|
259 | // form( Form ) |
---|
260 | // |
---|
261 | // INPUTS |
---|
262 | // Form : referencia ao formulário a ser enviado. |
---|
263 | // |
---|
264 | // EXAMPLE |
---|
265 | // <form action="/url/to/action" onsubmit="ExpressoLivre.form( this );"> |
---|
266 | // |
---|
267 | // ExpressoLivre.form( document.forms[ 0 ] ); |
---|
268 | // |
---|
269 | // NOTES |
---|
270 | // TODO: campo do tipo file não é tratado |
---|
271 | // |
---|
272 | //****** |
---|
273 | this.form = _form; |
---|
274 | |
---|
275 | //****m* ExpressoLivreAPI/ExpressoLivre/go |
---|
276 | // NAME |
---|
277 | // go |
---|
278 | // |
---|
279 | // DESCRIPTION |
---|
280 | // Realiza uma requisição ao servidor. |
---|
281 | // |
---|
282 | // SYNOPSIS |
---|
283 | // go( Object ) |
---|
284 | // |
---|
285 | // INPUTS |
---|
286 | // { |
---|
287 | // "access" : String, |
---|
288 | // "handler" : Function, |
---|
289 | // [ "params" : String ] |
---|
290 | // } |
---|
291 | // |
---|
292 | // EXAMPLE |
---|
293 | // function myHandler( ) |
---|
294 | // { |
---|
295 | // /*do something*/ |
---|
296 | // } |
---|
297 | // |
---|
298 | // ExpressoLivre.go( { |
---|
299 | // "access" : "module.class.method", |
---|
300 | // "handler" : myHandler |
---|
301 | // } ); |
---|
302 | // |
---|
303 | // ExpressoLivre.go( { |
---|
304 | // "access" : "module.class.method", |
---|
305 | // "handler" : function |
---|
306 | // { |
---|
307 | // /*do something*/ |
---|
308 | // } |
---|
309 | // } ); |
---|
310 | // |
---|
311 | //****** |
---|
312 | this.go = _go; |
---|
313 | |
---|
314 | //****m* ExpressoLivreAPI/ExpressoLivre/lang |
---|
315 | // NAME |
---|
316 | // lang |
---|
317 | // |
---|
318 | // DESCRIPTION |
---|
319 | // Carrega a tradução para o módulo. |
---|
320 | // |
---|
321 | // SYNOPSIS |
---|
322 | // lang( String ) |
---|
323 | // |
---|
324 | // INPUTS |
---|
325 | // String : nome do módulo |
---|
326 | // |
---|
327 | // EXAMPLE |
---|
328 | // ExpressoLivre.lang( 'expressoAdmin1_2' ); |
---|
329 | // |
---|
330 | // ExpressoLivre.lang( 'expressoMail1_2' ); |
---|
331 | // |
---|
332 | // ExpressoLivre.lang( 'filemager' ); |
---|
333 | // |
---|
334 | //****** |
---|
335 | this.lang = _lang; |
---|
336 | |
---|
337 | //****m* ExpressoLivreAPI/ExpressoLivre/link |
---|
338 | // NAME |
---|
339 | // link |
---|
340 | // |
---|
341 | // DESCRIPTION |
---|
342 | // Realiza uma requisição ao servidor, trata o resultado interceptando os |
---|
343 | // links existentes e carrega os javascripts externos uma única vez. |
---|
344 | // |
---|
345 | // SYNOPSIS |
---|
346 | // link( String link, [[Boolean cache], [String post]] ) |
---|
347 | // |
---|
348 | // INPUTS |
---|
349 | // String link : URL da requisição a ser realizada |
---|
350 | // Boolean cache : 'true' para manter cache do resultado da requisição |
---|
351 | // String post : query string que será enviada ao servidor |
---|
352 | // |
---|
353 | // EXAMPLE |
---|
354 | // ExpressoLivre.link( ); |
---|
355 | // |
---|
356 | //****** |
---|
357 | this.link = _link; |
---|
358 | |
---|
359 | //****m* ExpressoLivreAPI/ExpressoLivre/path |
---|
360 | // NAME |
---|
361 | // path |
---|
362 | // |
---|
363 | // DESCRIPTION |
---|
364 | // Retorna a URL base do servidor ExpressoLivre. |
---|
365 | // |
---|
366 | // SYNOPSIS |
---|
367 | // String path( ) |
---|
368 | // |
---|
369 | // RESULT |
---|
370 | // FQDN do servidor concatenado com o path do ExpressoLivre. |
---|
371 | // |
---|
372 | // EXAMPLE |
---|
373 | // ExpressoLivre.path( ); |
---|
374 | // |
---|
375 | //****** |
---|
376 | this.path = _path; |
---|
377 | |
---|
378 | //****m* ExpressoLivreAPI/ExpressoLivre/theme |
---|
379 | // NAME |
---|
380 | // theme |
---|
381 | // |
---|
382 | // DESCRIPTION |
---|
383 | // Retorna o tema que corrente do usuário. |
---|
384 | // |
---|
385 | // SYNOPSIS |
---|
386 | // String theme( ) |
---|
387 | // |
---|
388 | // RESULT |
---|
389 | // Nome do tema. |
---|
390 | // |
---|
391 | // EXAMPLE |
---|
392 | // ExpressoLivre.theme( ); |
---|
393 | // |
---|
394 | //****** |
---|
395 | this.theme = _theme; |
---|
396 | |
---|
397 | //****m* ExpressoLivreAPI/ExpressoLivre/template |
---|
398 | // NAME |
---|
399 | // template |
---|
400 | // |
---|
401 | // DESCRIPTION |
---|
402 | // Retorna o template que corrente do usuário. |
---|
403 | // |
---|
404 | // SYNOPSIS |
---|
405 | // String template( ) |
---|
406 | // |
---|
407 | // RESULT |
---|
408 | // Nome do template. |
---|
409 | // |
---|
410 | // EXAMPLE |
---|
411 | // ExpressoLivre.template( ); |
---|
412 | // |
---|
413 | //****** |
---|
414 | this.template = _template; |
---|
415 | |
---|
416 | //****m* ExpressoLivreAPI/ExpressoLivre/translate |
---|
417 | // NAME |
---|
418 | // translate |
---|
419 | // |
---|
420 | // DESCRIPTION |
---|
421 | // Realiza a tradução para o idioma corrente. |
---|
422 | // |
---|
423 | // SYNOPSIS |
---|
424 | // String template( String phrase[, String ...] ) |
---|
425 | // |
---|
426 | // INPUTS |
---|
427 | // String : frase a ser traduzida |
---|
428 | // |
---|
429 | // RESULT |
---|
430 | // Frase traduzida ou, em caso de não haver a tradução, a frase com um |
---|
431 | // asterisco concatenado ao final. |
---|
432 | // |
---|
433 | // EXAMPLE |
---|
434 | // ExpressoLivre.translate( 'A phrase to translate' ); |
---|
435 | // |
---|
436 | //****** |
---|
437 | this.translate = _translate; |
---|
438 | } ); |
---|
439 | window.ExpressoLivre = _ExpressoLivre; |
---|
440 | |
---|
441 | _xlink = new XLink( _path( ) ); |
---|
442 | _xlink.handler( { |
---|
443 | "data" : function( _pData ) |
---|
444 | { |
---|
445 | return ( _pData + '<script>ExpressoLivre.events.fire.onload( );</script>' ); |
---|
446 | }, |
---|
447 | "before" : _wait, |
---|
448 | "after" : function( ) |
---|
449 | { |
---|
450 | if ( _divAppbox ) |
---|
451 | _divAppbox.innerHTML = ''; |
---|
452 | |
---|
453 | while ( arguments[ 0 ].hasChildNodes( ) ) |
---|
454 | _divAppbox.appendChild( arguments[ 0 ].firstChild ); |
---|
455 | } |
---|
456 | } ); |
---|
457 | |
---|
458 | _xconnector = new XConnector( { |
---|
459 | "path" : _path( ), |
---|
460 | "controller" : "?menuaction=" |
---|
461 | } ); |
---|
462 | |
---|
463 | _loading.src = _path( ) + 'phpgwapi/templates/' + _template( ) + '/images/loading.gif'; |
---|
464 | |
---|
465 | XEvents.add( window, 'onload', function( ) |
---|
466 | { |
---|
467 | _divAppboxHeader = document.getElementById( 'divAppboxHeader' ); |
---|
468 | _divAppboxHeader.innerHTML = ''; |
---|
469 | |
---|
470 | _divAppbox = document.getElementById( 'divAppbox' ); |
---|
471 | _divAppbox.innerHTML = ''; |
---|
472 | |
---|
473 | document.title = 'ExpressoLivre'; |
---|
474 | |
---|
475 | document.getElementsByTagName( 'body' ).item( 0 ).style.overflowY = 'scroll'; |
---|
476 | |
---|
477 | var _scripts = document.getElementsByTagName( 'head' ).item( 0 ).getElementsByTagName( 'script' ); |
---|
478 | var _loaded = [ ]; |
---|
479 | |
---|
480 | for ( var i = 0; i < _scripts.length; i++ ) |
---|
481 | if ( _scripts.item( i ).getAttribute( 'src' ) != null ) |
---|
482 | _loaded[ _loaded.length ] = _scripts.item( i ).getAttribute( 'src' ).substr( |
---|
483 | _path( ).length - 1, |
---|
484 | _scripts.item( i ).getAttribute( 'src' ).indexOf( '?' ) - _path( ).length + 1 |
---|
485 | ); |
---|
486 | |
---|
487 | new XScript( _loaded ); |
---|
488 | |
---|
489 | var _links = document.getElementsByTagName( 'a' ); |
---|
490 | for ( var i = 0; i < _links.length; i++ ) |
---|
491 | _xlink.intercept( _links.item( i ) ); |
---|
492 | } ); |
---|
493 | } )( ); |
---|