source: branches/2.4/calendar/templates/default/js/edit_exmail.js @ 7339

Revision 7339, 24.8 KB checked in by eduardow, 11 years ago (diff)

Ticket #3137 - Compatibilizar normalizacao de dados dos contatos dinamicos com o calendar.

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