source: trunk/calendar/templates/default/js/edit_exmail.js @ 5143

Revision 5143, 16.7 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus. Calendar: adicionando arquivos.

Line 
1/******************************************************************************\
2|**************************   CALENDAR MODULE   *******************************|
3|********** INCLUDE PARTICIPANTS - PLUGIN USING AJAX EXPRESSOMAIL COMPONENT  **|
4\******************************************************************************/
5var contacts = '';
6var expresso_offline = '';
7var array_lang = new Array();
8var finderTimeout = '';
9// onUnload edit message
10if(!document.all)
11{
12        var beforeunload = window.onbeforeunload;
13        window.onbeforeunload = function()
14        {
15                if ( typeof beforeunload == 'function' )
16                        beforeunload();
17        };
18}
19       
20// Verifica versão do Firefox
21var agt = navigator.userAgent.toLowerCase();
22var is_firefox_0 = agt.indexOf('firefox/1.0') != -1 && agt.indexOf('firefox/0.') ? true : false;
23
24var handler_get_available_users = function(fill)
25{       
26        var groupHandler = function( toGroup )
27        {
28            switch( toGroup[ 'phpgwaccounttype' ] )
29            {
30                case 'u':return 'users';
31                break;
32                case 'g':return 'groups';
33                break;
34                case 's':return 'shared_accounts';
35                break
36            }
37
38            return( false );
39        }
40
41        return fillGroupableSelect( fill, 'user_list_in', groupHandler, default_field );
42}       
43
44function get_available_users(module,context,type, autoSearch){
45//      Element('cal_input_searchUser').value = '';
46//      if(autoSearch != 'True'){
47//              return true;
48//      }
49//      var context = document.getElementById('combo_org').value;       
50//      cExecute (module+'.ldap_functions.get_available_users&context='+context+'&type='+type, handler_get_available_users);
51}
52
53function optionFinderTimeout(obj, numMin, type, autoSearch, event){
54
55        if( event.keyCode === 13 )
56        {
57            //limit = 0;
58
59            optionFinderLdap( obj.id, numMin, type );
60
61            return( false );
62        }
63
64        return( true );
65}
66// Pesquisa Javascript
67function optionFinderLocal(id){
68
69        var sentence = Element( id ).value;
70
71        finder( sentence, 'user_list_in' );
72}
73
74// Pesquisa LDAP
75function optionFinderLdap(id,numMin, type){
76
77        var sentence = Element( id ).value;
78
79        var url = 'expressoMail1_2.ldap_functions.search_users&context=' + document.getElementById('combo_org').value + '&type='+(type == '' ? 'list' : 'search')+'&filter=' + sentence;
80       
81        var parser = function( data ){
82
83            var result = {};
84
85            for( accountType in data )
86            {
87                var target = data[ accountType ];
88
89                accountType = accountType.charAt(0);
90
91                for( value in target )
92                {
93                    result[value] = {};
94                    result[value][default_field] = target[value];
95                    result[value]['phpgwaccounttype'] = accountType;
96                }
97
98            }
99
100            return( result );
101        };
102
103        return userFinder( sentence, handler_get_available_users, url, parser, 'cal_span_searching' );
104}
105
106function add_user()
107{
108        var select_available_users = document.getElementById('user_list_in');
109        var select_users = document.getElementById('user_list');
110        var count_available_users = select_available_users.length;
111        var count_users = select_users.options.length;
112        var new_options = '';
113       
114        for (i = 0 ; i < count_available_users ; i++) {
115                if (select_available_users.options[i].selected) {
116                        if(document.all) {
117                                if ( (select_users.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' ) {
118                                        new_options +=  '<option value='
119                                                                + select_available_users.options[i].value
120                                                                + '>'
121                                                                + select_available_users.options[i].text
122                                                                + '</option>';
123                                }
124                        }
125                        else if ( (select_users.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' ) {
126                                        new_options +=  '<option value='
127                                                                + select_available_users.options[i].value
128                                                                + '>'
129                                                                + select_available_users.options[i].text
130                                                                + '</option>';
131                        }
132                }
133        }
134
135        if (new_options != '') {
136
137                if(is_firefox_0)
138                        fixBugInnerSelect(select_users,'###' + new_options + select_users.innerHTML);
139                else
140                        select_users.innerHTML = '###' + new_options + select_users.innerHTML;
141
142                select_users.outerHTML = select_users.outerHTML;
143        }
144}
145
146function remove_user(){
147        select_users = document.getElementById('user_list');
148       
149        for(var i = 0;i < select_users.options.length; i++)
150                if(select_users.options[i].selected)
151                        select_users.options[i--] = null;
152}
153
154function submitValues(button){
155    loadScript("expressoMail1_2/js/common_functions.js");
156        button.disabled = true; //Desabilita Botão para evitar varios clicks
157
158        var typeField = document.getElementById('cal[type]');
159        if (typeField && typeField.value == 'hourAppointment') {
160                if(document.getElementsByName('categories[]')[0].value == ""){
161                        alert(alert_msg);
162                        button.disabled = false;
163                        return false;
164                }
165        }
166
167        var select_in = document.getElementById('user_list');
168        for(i = 0; i < select_in.length; i++)
169                select_in.options[i].selected = true;
170
171        var rptDay = document.getElementsByName( 'cal[rpt_day][]' );
172        var isChecked = false;
173
174        for(var i = 0 ; i < rptDay.length; i++)
175            if(rptDay[i].checked == true)
176                isChecked = true; 
177       
178        if( !isChecked && !document.getElementsByName( "cal[rpt_use_end]" )[0].checked && !(document.getElementsByName( "cal[recur_type]" )[0].value === "0")){
179            alert("Agendamentos recorrentes precisam de data final da repetição");
180            button.disabled = false;
181            return false;
182        }
183   
184        if( !isChecked && document.getElementsByName( "cal[recur_type]" )[0].value === "2" ){
185            //TODO: por essa mensagem no lang
186            alert("Voce nao especificou um dia na sua repeticao semanal");
187            button.disabled = false;
188            return false;
189        }
190        if(document.getElementsByName( "cal[rpt_use_end]" )[0].checked){
191                if(!validate_date_order(document.getElementById('start[str]').value, document.getElementById('recur_enddate[str]').value)){
192                        alert("A data final não pode ser menor que a data inicial.");
193                        button.disabled = false;
194                        return false;
195                }
196        }
197        //Valida data inicio nao nula
198        if(document.getElementById('start[str]').value == ''){
199                alert("Necessario preencher a data de início.");
200                document.getElementById('start[str]').focus();
201                button.disabled = false;
202                return false;
203        }
204        //Valida data inicio
205        if(document.getElementById('start[str]').value != ''){
206                if(!validate_date(document.getElementById('start[str]').value)){
207                        document.getElementById('start[str]').value = '';
208                        document.getElementById('start[str]').focus();
209                        alert("A data de início não é válida.");
210                        button.disabled = false;
211                        return false;
212                }
213        }
214        //Valida data termino
215        if(document.getElementById('end[str]').value != ''){
216                if(!validate_date(document.getElementById('end[str]').value)){
217                        document.getElementById('end[str]').value = '';
218                        document.getElementById('end[str]').focus();
219                        alert("A data de término não é válida.");
220                        button.disabled = false;
221                        return false;
222                }
223        }
224
225        //Valida hora inicio somente numeros   
226        if(isNaN(parseInt(document.getElementById('start_hour').value))){
227                document.getElementById('start_hour').value = '';
228                document.getElementById('start_hour').focus();
229                alert("A hora de início deve ser números.");
230                button.disabled = false;
231                return false;
232        }
233        //Valida hora inicio somente numeros   
234        if(isNaN(parseInt(document.getElementById('start_minute').value))){
235                document.getElementById('start_minute').value = '';
236                document.getElementById('start_minute').focus();
237                alert("A hora de início deve ser números.");
238                button.disabled = false;
239                return false;
240        }
241        //Valida hora termino somente numeros   
242        if(isNaN(parseInt(document.getElementById('end_hour').value))){
243                document.getElementById('end_hour').value = '';
244                document.getElementById('end_hour').focus();
245                alert("A hora do término deve ser números.");
246                button.disabled = false;
247                return false;
248        }
249        //Valida hora termino somente numeros   
250        if(isNaN(parseInt(document.getElementById('end_minute').value))){
251                document.getElementById('end_minute').value = '';
252                document.getElementById('end_minute').focus();
253                alert("A hora do término deve ser números.");
254                button.disabled = false;
255                return false;
256        }
257         
258        //Valida hora inicial maior que final
259        if( (document.getElementById('start_hour').value != '') && (document.getElementById('end_hour').value != '') ){
260                if( (document.getElementById('start_hour').value) > (document.getElementById('end_hour').value) ){
261                        //JA ESTA ERRADO
262                        document.getElementById('start_hour').value = '';
263                        document.getElementById('end_hour').value = '';
264                        document.getElementById('start_minute').value = '';
265                        document.getElementById('end_minute').value = '';
266                        document.getElementById('start_hour').focus();
267                        alert("A hora final não pode ser menor que a hora inicial.");
268                        button.disabled = false;
269                        return false;
270                }else if ( (document.getElementById('start_hour').value) == (document.getElementById('end_hour').value) ){
271                        if ( (document.getElementById('start_minute').value) > (document.getElementById('end_minute').value) ){
272                                //DEU ERRO
273                                document.getElementById('start_hour').value = '';
274                                document.getElementById('end_hour').value = '';
275                                document.getElementById('start_minute').value = '';
276                                document.getElementById('end_minute').value = '';
277                                document.getElementById('start_hour').focus();
278                                alert("A hora final não pode ser menor que a hora inicial.");
279                                button.disabled = false;
280                                return false;
281                        }
282                }
283        }
284
285       
286        document.getElementById('formEvent').submit();
287}       
288
289function Element(id){
290        return document.getElementById(id);
291}
292
293function loadScript(scriptPath){
294
295        if(!connector)
296                throw new Error("Error : Connector is not loaded.");
297               
298        if (document.getElementById('uploadscript_'+scriptPath)) {
299                return;
300        }
301
302        if( connector.oxmlhttp === null )
303            connector.createXMLHTTP();
304
305        connector.oxmlhttp.open("GET", scriptPath, false);
306        connector.oxmlhttp.setRequestHeader('Content-Type','text/plain');
307        connector.oxmlhttp.send(null);
308        if(connector.oxmlhttp.status != 0 && connector.oxmlhttp.status != 200 ||        connector.oxmlhttp.status == 0 && connector.oxmlhttp.responseText.length == 0)
309                throw new Error("Error " + connector.oxmlhttp.status + "("+connector.oxmlhttp.statusText+") when loading script file '"+scriptPath+"'");
310       
311        var head = document.getElementsByTagName("head")[0];
312        var script = document.createElement("SCRIPT");
313        script.id = 'uploadscript_'+scriptPath;
314        script.type = 'text/javascript';               
315        script.text = connector.oxmlhttp.responseText;
316        head.appendChild(script);
317        return;
318}
319
320function showExParticipants(el,path){
321        Element('tbl_ext_participants').style.display='';
322        el.style.display='none';
323        loadScript(path+"/js/common_functions.js");
324        get_lang = function( key ){
325                var translator = Element( "txt_" + key.replace(/ /g, "_") );
326                if (translator == null)
327                        return "Failed translating string.";
328                var value = translator.value;
329                if(arguments.length > 1) {
330                        for(j = 1; typeof(arguments[j]) != 'undefined'; j++)
331                                value = value.replace("%"+j,arguments[j]);
332                }
333                return value;
334        };
335        loadScript(path+"/js/DropDownContacts.js");
336        loadScript(path+"/js/QuickCatalogSearch.js");
337        loadScript("calendar/templates/default/js/over_fn_exmail.js");
338        if(!contacts)
339                cExecute (path+'.db_functions.get_dropdown_contacts', save_contacts);
340}
341
342function hideExParticipants(el,path){
343        Element('a_ext_participants').style.display = '';
344        Element('tbl_ext_participants').style.display ='none';
345}
346
347function save_contacts(data){
348        contacts = data;       
349        var input_to = Element("ex_participants");
350        input_to.style.width = "100%";
351        input_to.setAttribute("wrap","soft");   
352        input_to.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer));search_contacts('onfocus', this.id);};
353        input_to.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);};
354        if (!is_ie)
355        {
356                input_to.rows = 2;
357                input_to.onkeypress = function (e)
358                {
359                        if ((e.keyCode) == 120) //F9
360                        {
361                                emQuickSearch(input_to);
362                        }
363                        else
364                        {
365                                if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
366                                {
367                                        e.preventDefault();
368                                        search_contacts(e.keyCode,this.id);
369                                }
370                        }
371                }
372                input_to.onkeyup = function (e)
373                {
374                        if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
375                        {
376                                search_contacts(e.keyCode,this.id);
377                        }
378                }
379        }
380        else
381        {
382                input_to.rows = 3;
383                input_to.onkeyup = function (e)
384                {
385                        if ((window.event.keyCode) == 120) //F9
386                        {
387                                emQuickSearch(input_to);
388                        }
389                        else
390                        {
391                                search_contacts(window.event.keyCode,this.id);
392                        }       
393                }
394        }
395}
396
397function fixBugInnerSelect(objeto,innerHTML){
398/******
399* select_innerHTML - altera o innerHTML de um select independente se é FF ou IE
400* Corrige o problema de não ser possível usar o innerHTML no IE corretamente
401* Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
402* Use a vontade mas coloque meu nome nos créditos. Dúvidas, me mande um email.
403* Versão: 1.0 - 06/04/2006
404* Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
405* Parametros:
406* objeto(tipo object): o select a ser alterado
407* innerHTML(tipo string): o novo valor do innerHTML
408*******/
409    objeto.innerHTML = ""
410    var selTemp = document.createElement("micoxselect")
411    var opt;
412    selTemp.id="micoxselect1"
413    document.body.appendChild(selTemp)
414    selTemp = document.getElementById("micoxselect1")
415    selTemp.style.display="none"
416    if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto
417        innerHTML = "<option>" + innerHTML + "</option>"
418    }
419    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
420    selTemp.innerHTML = innerHTML
421    for(var i=0;i<selTemp.childNodes.length;i++){
422        if(selTemp.childNodes[i].tagName){
423            opt = document.createElement("OPTION")
424            for(var j=0;j<selTemp.childNodes[i].attributes.length;j++){
425                opt.setAttributeNode(selTemp.childNodes[i].attributes[j].cloneNode(true))
426            }
427            opt.value = selTemp.childNodes[i].getAttribute("value")
428            opt.text = selTemp.childNodes[i].innerHTML
429            if(document.all){ //IEca
430                objeto.add(opt)
431            }else{
432                objeto.appendChild(opt)
433            }                   
434        }   
435    }
436    document.body.removeChild(selTemp)
437    selTemp = null
438}
439
440function changeViewMode(eltype){
441        var chValue = eltype;
442        switch (chValue){
443                case 'hourAppointment':
444                        var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label');
445                        for (var i=0; i < names.length; i++)
446                        {
447                                var Field = document.getElementsByName('cal['+names[i]+']');
448                                if (Field[0])
449                                        Field[0].parentNode.parentNode.style.display = "none";
450                        }
451
452                        Field = document.getElementsByName('participants[]');
453                        Field[0].parentNode.parentNode.style.display = "none";
454                        Field[1].parentNode.parentNode.style.display = "none";
455                        Field = document.getElementById('txt_loading');
456                        Field.parentNode.parentNode.style.display = "none";
457                        Field = document.getElementsByName('cal[rpt_day][]');
458                        Field[0].parentNode.parentNode.style.display = "none";
459                        break;
460                case 'privateHiddenFields':
461                        var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label');
462                        for (var i=0; i < names.length; i++)
463                        {
464                                var Field = document.getElementsByName('cal['+names[i]+']');
465                                if (Field[0])
466                                        Field[0].parentNode.parentNode.style.display = "";
467                        }
468                        Field = document.getElementsByName('participants[]');
469                        Field[0].parentNode.parentNode.style.display = "none";
470                        Field[1].parentNode.parentNode.style.display = "none";
471                        Field = document.getElementById('txt_loading');
472                        Field.parentNode.parentNode.style.display = "none";
473                        Field = document.getElementsByName('cal[rpt_day][]');
474                        Field[0].parentNode.parentNode.style.display = "";
475                        break;
476                default:
477                        var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label');
478                        for (var i=0; i < names.length; i++)
479                        {
480                                var Field = document.getElementsByName('cal['+names[i]+']');
481                                if (Field[0])
482                                        Field[0].parentNode.parentNode.style.display = "";
483                        }
484                        Field = document.getElementsByName('participants[]');
485                        Field[0].parentNode.parentNode.style.display = "";
486                        Field[1].parentNode.parentNode.style.display = "";
487                        Field = document.getElementById('txt_loading');
488                        Field.parentNode.parentNode.style.display = "";
489                        Field = document.getElementsByName('cal[rpt_day][]');
490                        Field[0].parentNode.parentNode.style.display = "";
491                        break;
492        }
493
494}
495function updateTitleField(select){
496        var typeField = document.getElementsByName('cal[type]');
497        if (typeField[0].value != 'hourAppointment')
498                return;
499        var titleField = document.getElementsByName('cal[title]');
500        var optionsArray = select.childNodes;
501        titleField[0].value = '';
502        for(option in optionsArray)
503                if (optionsArray[option].selected)
504                        titleField[0].value += optionsArray[option].text + ' ';
505}
506
507var __onLoad = window.onload;
508window.onload = function(){
509        __onLoad();
510        var cal_type = document.getElementById('cal[type]').value;
511        changeViewMode(cal_type);
512        if(cal_type == 'hourAppointment'){
513                clearTimeout(timeout_get_available_users);
514        }
515};
Note: See TracBrowser for help on using the repository browser.