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

Revision 7437, 26.2 KB checked in by acoutinho, 11 years ago (diff)

Ticket #3167 - Melhoria na performance nas pesquisas de contatos dinamicos

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
320
321function controlInputBinds(){
322        var div = $('#tbl_ext_participants').find('textarea');
323        div.bind('keydown',function(e){
324                        //SELECIONA O CONTATO E EVITA OUTROS COMANDOS
325                        if ( e.keyCode === $.ui.keyCode.TAB && $( this ).data( "autocomplete" ).menu.active ) {
326                                e.preventDefault();
327                                return false;
328                        }               
329                       
330                        //FECHA OS CONTATOS DINÂMICOS
331                        if( (e.keyCode == 27) && $( this ).data( "autocomplete" ).menu.active ){
332                                   e.stopPropagation();
333                                   e.preventDefault();
334                        }
335                       
336                        //SELECIONA O CONTATO E EVITA OUTROS COMANDOS
337                        if(e.keyCode == $.ui.keyCode.ENTER && $( this ).data( "autocomplete" ).menu.active){
338                                e.preventDefault();
339                                return false;
340                        }
341                //BUSCA COM A TECLA F9
342                if((e.keyCode) == 120){
343                        quickSearchCatalogUser();
344                        e.preventDefault();
345                        return false;
346                }
347        });
348}
349
350var cache = new Array();
351var dynamicPersonalContacts = new Array();
352var dynamicContacts = new Array();
353var topContact = 0;
354
355function split( val ) {
356        return val.split( /,\s*/ );
357}
358
359function extractLast( term ) {
360        return split( term ).pop();
361}
362
363function updateDynamicContact(userContacts){
364    if(!userContacts)
365        userContacts = REST.get("/usercontacts", false);
366
367    if(userContacts.collection && !userContacts.collection.error){
368        dynamicData = normalizeContacts(userContacts.collection.itens);
369    }else{
370        dynamicData = [];
371    }
372
373    if(dynamicData){
374        var dynamicContactsList = [];
375        $.each(dynamicData, function(index, dynamic){
376
377            var dataType = userContacts.collection.itens[index].dataType;
378
379            dynamic['value'] = (dynamic.name ? dynamic.name +' - ': '') + dynamic.mail;
380            dynamic['type'] = dataType
381            dynamic['typel'] = (dataType.substring(0,7) == "/shared" ? "/"+dataType.substring(7,dataType.length)+"s" : dataType) ;
382            dynamicContactsList.push(dynamic);
383        });
384    }
385
386    dynamicData = dynamicContactsList;
387}
388
389function updateDynamicPersonalContacts(){
390        dynamicPersonalContacts = new Array();
391
392    var personalContacts = REST.get("/personalContact");
393
394    if(personalContacts.collection && !personalContacts.collection.error){
395        var contactsData = normalizeContacts(personalContacts.collection.itens);
396        if(contactsData){
397            $.each(contactsData, function(index, value){
398                var contact = {
399                    id : parseInt(value.id),
400                    name : value.name,
401                    email: value.email,
402                    value: value.name+ " - " + value.email,
403                    type: "P"
404                };
405                dynamicPersonalContacts.push(contact);
406            });
407        }
408    }
409}
410
411function normalizeContacts(data){
412    var decoded = [];
413
414    if(!$.isArray(data)){data = [data];}
415    for(var i = 0; i < data.length; i++){
416        var item = {};
417        $.each(data[i].data, function(j, e){
418            item[e.name] = e.value;
419        });
420        decoded.push(item);
421    }
422    return decoded;
423}
424
425function quickSearchCatalogUser(){
426        var begin,end;
427        var mailList = document.getElementById('ex_participants').value;
428        var search =  "";
429        var ID = 1;
430        var field = "ex_participants";
431        if (mailList.lastIndexOf(',') != -1){
432                begin = mailList.lastIndexOf(',');
433                end = mailList.length;
434                search = mailList.substring(begin+1,255);
435        }
436        else{
437                begin = 0;
438                end = mailList.length;
439                search = mailList;
440        }
441        var handler_Search = function(data){
442                if ((!data.status) && (data.error == "many results")){
443                        return false;
444                }
445                if (data.length > 0){
446                        quickSearchUser.showList(data,begin,end);
447                }
448        }
449        if (search.length > 0)
450        cExecute ("$this.ldap_functions.quicksearchcontact&search_for="+search+"&field="+field+"&ID="+ID, handler_Search);
451}
452
453/*Adiciona um novo contato selecionado*/
454function update_mailField(name,email){
455        var mailList = $('#tbl_ext_participants').find('textarea');
456        var newList = "";
457        if (mailList.val().indexOf(email) != -1){
458                $.Zebra_Dialog('O email <b>'+ email +'</b> já consta na lista!');
459        }
460        if (mailList.val().indexOf(',') > 0){
461                var ctcList = mailList.val().split(',');
462                for(var ii=0; ii<ctcList.length - 1;ii++){
463                        newList += ctcList[ii] + ",";
464                }
465                newList += '"'+ name + '"'+ " <" + email + ">" + ",";
466        }
467        else{
468                newList +=  '"'+ name + '"'+ " <" + email + ">" +",";
469        }
470        mailList.val(newList);
471}
472
473function showExParticipants(el,path){
474        //updateDynamicPersonalContacts();
475        //REST.load("");
476        controlInputBinds();
477        Element('tbl_ext_participants').style.display='';
478        el.style.display='none';
479
480    //PREPARAÇÃO DA ARRAY DOS CONTATOS DINÂMICOS
481
482    var decodeType = {
483        '/dynamiccontacts': {
484            css: 'recent',
485            img: 'recent',
486            text: 'Contato Recente'
487        },
488        '/personalContact':{
489            css: 'personal',
490            img: 'personal',
491            text: 'Contato pessoal'
492        },
493        '/sharedcontact':{
494            css: 'personal',
495            img: 'sharedcontact',
496            text: 'Contato compartilhado'
497        },
498        '/groups':{
499            css: 'group',
500            img: 'group',
501            text: 'Grupo pessoal'
502        },
503        '/sharedgroup':{
504            css: 'group',
505            img: 'sharedgroup',
506            text: 'Grupo compartilhado'
507        }
508    }
509
510    $('#tbl_ext_participants').find('textarea').autocomplete({
511        source: function(request, response){
512            if ( request.term in cache ) {
513                response( cache[ request.term ] );
514                return;
515            }
516
517            if(dynamicData === false){
518                updateDynamicContact();
519            }
520
521            var data = $.ui.autocomplete.filter(dynamicData,  extractLast( request.term ) ).slice(0, 50);
522            cache[ request.term ] = data;
523            response( data );
524        },
525        focus: function() {
526            return false;
527        },
528
529        //EVENTO AO SELECIONAR UM CONTATO DINÂMICO
530        select: function( event, ui ) {
531            event.preventDefault();
532            update_mailField((ui.item.name ? ui.item.name : ""),ui.item.mail);
533        },
534        autoFocus: true,
535        position : { my: "left top", at: "left bottom", collision: "fit" },
536        delay : 120,
537        minLength: 0
538    }).bind('autocompleteopen', function(event, ui) {
539
540        $(this).data('is_open',true);
541
542    }).bind('autocompleteclose', function(event, ui) {
543
544        canMakeBox = true;
545        $(this).data('is_open',false);
546
547    }).data( "autocomplete" )._renderItem = function( ul, item ) {
548
549        if(item.typel == "/groups")
550            return true;
551
552        var autocomplete = $(this)[0].element;
553
554        //cálculo dinâmico da largura da lista
555        var width = (item.label ? item.label.length : (item.value ? item.value.length : (item.mail ? item.mail.length : 20 )));
556        width = width*5 + (is_ie ? 170 : 200) + 16;
557
558        width =  (width <  $(ul).width()) ? $(ul).width() : width;
559
560        ul.css({"min-width":width,"max-width":$('#tbl_ext_participants').find('textarea').width(),"max-height" : "180px", "overflow-y" : "auto", "min-height": "30px"});
561
562        item.raty = ((item.number_of_messages*10)/topContact) > 1 ? ((item.number_of_messages*10)/topContact) : 1;
563
564        if ( item.typel != currentTypeContact) {
565            if((item.typel == "/groups" && $(ul).find(".dynamic-recent").length) || (item.typel == "/personalContact" && ($(ul).find(".dynamic-group").length || $(ul).find(".dynamic-recent").length))){
566                currentTypeContact = item.typel;
567                item.asDiv = true;
568            }else{
569                currentTypeContact = item.typel;
570            }
571        }
572
573        var li = '';
574        if(item.asDiv){
575            li = '<li class="dynamic-separator"><div class="line-separator">&nbsp;</div></li>';
576        }
577        li += '<li class="dynamic-'+ decodeType[item.type].css +'">';
578        li += '<a style="width:'+(item.type == '/dynamiccontacts' ? '91%' : '97.5%')+';  display: inline-block; background: none;">';
579        li += '<img style="position:relative; top:2px; "src="prototype/modules/mail/img/'+ decodeType[item.type].img +'.png" title="'+ decodeType[item.type].text +'"/>';
580        li += ($.trim(item.name) != "" ? ((item.name.length > 20 ? item.name.substring(0,17)+"..." : item.name) + " - " ) : '')  + item.mail;
581        li += item.type == '/dynamiccontacts' ? '<div class="dynamic-stars" style="display: inline-block;float: right;" id="'+item.raty+'_'+item.id+'"/>' : ''
582        li += '</a>';
583        li += '<span style="width:16px; height:16px; top:1px; left:7px; '+ (item.type == '/dynamiccontacts' ? '': 'display:none') +'">Excluir contato recente</span>';
584        li += '</li>';
585
586
587        li = $( li )
588            .data( "item.autocomplete", item )
589            //.append( li )
590            .appendTo( ul );
591
592        li.find("span").button({
593            icons : {
594                primary : "ui-icon-close"
595            },
596            text: false
597        }).click(function(event){
598                if(!event.keyCode)
599                    autocomplete.autocomplete( "close" );
600
601                canMakeBox = false;
602                $.Zebra_Dialog('Deseja remover <b>'+(item.name ? (item.name.length <= 30 ? item.name: item.name.substr(0,27)+"...")+" - " : "")+ item.mail+'</b>?', {
603                    'type':     'question',
604                    'custom_class': (is_ie ? 'configure-zebra-dialog' : ''),
605                    'buttons': ['Sim','Não'],
606                    'overlay_opacity': '0.5',
607                    'onClose':  function(caption) {
608                        if(caption == 'Sim'){
609
610                            REST['delete']("/dynamiccontact/"+item.id);
611                            updateDynamicContact();
612                            cache = new Array();
613                        }else if(caption == 'Não'){
614                            $(focusIn).focus();
615                        }
616                    }
617                });
618            });
619
620        li.find(".dynamic-stars").jRating({
621            step:true,
622            length : 5, // nb of stars
623            decimalLength: 2, // number of decimal in the rate
624            rateMax: 10,
625            isDisabled:true,
626            bigStarsPath : 'prototype/plugins/jquery.jrating/icons/stars.png', // path of the icon stars.png
627            smallStarsPath : 'prototype/plugins/jquery.jrating/icons/small.png' // path of the icon small.png
628        });
629
630        if($(ul).find("li:last").hasClass("dynamic-separator")){
631            $(ul).find("li:last").remove();
632        }
633
634        $(ul).scroll(function(){
635            canMakeBox = false;
636        });
637
638        return li;
639    };
640}
641
642function hideExParticipants(el,path){
643        Element('a_ext_participants').style.display = '';
644        Element('tbl_ext_participants').style.display ='none';
645}
646
647function save_contacts(data){
648        contacts = data;       
649        var input_to = Element("ex_participants");
650        input_to.style.width = "100%";
651        input_to.setAttribute("wrap","soft");   
652        input_to.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer));search_contacts('onfocus', this.id);};
653        input_to.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);};
654        if (!is_ie)
655        {
656                input_to.rows = 2;
657                input_to.onkeypress = function (e)
658                {
659                        if ((e.keyCode) == 120) //F9
660                        {
661                                emQuickSearch(input_to);
662                        }
663                        else
664                        {
665                                if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
666                                {
667                                        e.preventDefault();
668                                        search_contacts(e.keyCode,this.id);
669                                }
670                        }
671                }
672                input_to.onkeyup = function (e)
673                {
674                        if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
675                        {
676                                search_contacts(e.keyCode,this.id);
677                        }
678                }
679        }
680        else
681        {
682                input_to.rows = 3;
683                input_to.onkeyup = function (e)
684                {
685                        if ((window.event.keyCode) == 120) //F9
686                        {
687                                emQuickSearch(input_to);
688                        }
689                        else
690                        {
691                                search_contacts(window.event.keyCode,this.id);
692                        }       
693                }
694        }
695}
696
697function fixBugInnerSelect(objeto,innerHTML){
698/******
699* select_innerHTML - altera o innerHTML de um select independente se é FF ou IE
700* Corrige o problema de não ser possível usar o innerHTML no IE corretamente
701* Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
702* Use a vontade mas coloque meu nome nos créditos. Dúvidas, me mande um email.
703* Versão: 1.0 - 06/04/2006
704* Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
705* Parametros:
706* objeto(tipo object): o select a ser alterado
707* innerHTML(tipo string): o novo valor do innerHTML
708*******/
709    objeto.innerHTML = ""
710    var selTemp = document.createElement("micoxselect")
711    var opt;
712    selTemp.id="micoxselect1"
713    document.body.appendChild(selTemp)
714    selTemp = document.getElementById("micoxselect1")
715    selTemp.style.display="none"
716    if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto
717        innerHTML = "<option>" + innerHTML + "</option>"
718    }
719    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
720    selTemp.innerHTML = innerHTML
721    for(var i=0;i<selTemp.childNodes.length;i++){
722        if(selTemp.childNodes[i].tagName){
723            opt = document.createElement("OPTION")
724            for(var j=0;j<selTemp.childNodes[i].attributes.length;j++){
725                opt.setAttributeNode(selTemp.childNodes[i].attributes[j].cloneNode(true))
726            }
727            opt.value = selTemp.childNodes[i].getAttribute("value")
728            opt.text = selTemp.childNodes[i].innerHTML
729            if(document.all){ //IEca
730                objeto.add(opt)
731            }else{
732                objeto.appendChild(opt)
733            }                   
734        }   
735    }
736    document.body.removeChild(selTemp)
737    selTemp = null
738}
739
740function changeViewMode(eltype){
741        var chValue = eltype;
742        switch (chValue){
743                case 'hourAppointment':
744                        var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label');
745                        for (var i=0; i < names.length; i++)
746                        {
747                                var Field = document.getElementsByName('cal['+names[i]+']');
748                                if (Field[0])
749                                        Field[0].parentNode.parentNode.style.display = "none";
750                        }
751
752                        Field = document.getElementsByName('participants[]');
753                        Field[0].parentNode.parentNode.style.display = "none";
754                        Field[1].parentNode.parentNode.style.display = "none";
755                        Field = document.getElementById('txt_loading');
756                        Field.parentNode.parentNode.style.display = "none";
757                        Field = document.getElementsByName('cal[rpt_day][]');
758                        Field[0].parentNode.parentNode.style.display = "none";
759                        break;
760                case 'privateHiddenFields':
761                        var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label');
762                        for (var i=0; i < names.length; i++)
763                        {
764                                var Field = document.getElementsByName('cal['+names[i]+']');
765                                if (Field[0])
766                                        Field[0].parentNode.parentNode.style.display = "";
767                        }
768                        Field = document.getElementsByName('participants[]');
769                        Field[0].parentNode.parentNode.style.display = "none";
770                        Field[1].parentNode.parentNode.style.display = "none";
771                        Field = document.getElementById('txt_loading');
772                        Field.parentNode.parentNode.style.display = "none";
773                        Field = document.getElementsByName('cal[rpt_day][]');
774                        Field[0].parentNode.parentNode.style.display = "";
775                        break;
776                default:
777                        var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label');
778                        for (var i=0; i < names.length; i++)
779                        {
780                                var Field = document.getElementsByName('cal['+names[i]+']');
781                                if (Field[0])
782                                        Field[0].parentNode.parentNode.style.display = "";
783                        }
784                        Field = document.getElementsByName('participants[]');
785                        Field[0].parentNode.parentNode.style.display = "";
786                        Field[1].parentNode.parentNode.style.display = "";
787                        Field = document.getElementById('txt_loading');
788                        Field.parentNode.parentNode.style.display = "";
789                        Field = document.getElementsByName('cal[rpt_day][]');
790                        Field[0].parentNode.parentNode.style.display = "";
791                        break;
792        }
793
794}
795function updateTitleField(select){
796        var typeField = document.getElementsByName('cal[type]');
797        if (typeField[0].value != 'hourAppointment')
798                return;
799        var titleField = document.getElementsByName('cal[title]');
800        var optionsArray = select.childNodes;
801        titleField[0].value = '';
802        for(option in optionsArray)
803                if (optionsArray[option].selected)
804                        titleField[0].value += optionsArray[option].text + ' ';
805}
806
807var __onLoad = window.onload;
808window.onload = function(){
809        __onLoad();
810        var cal_type = document.getElementById('cal[type]').value;
811        changeViewMode(cal_type);
812        if(cal_type == 'hourAppointment'){
813                clearTimeout(timeout_get_available_users);
814        }
815};
Note: See TracBrowser for help on using the repository browser.