source: trunk/calendar/js/edit_exmail.js @ 2748

Revision 2748, 15.2 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1058 - Corrigindo problema no calendario para adicionar evento e na visao diaria.

  • Property svn:executable set to *
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/*
24        Semelhante a função get_avaiable_users, porém trás apenas usuários, ignorando os grupos...
25*/
26function get_available_only_users(path,context,type) {
27        var handler_get_available_users2 = function(data)
28        {       
29                select_available_users = document.getElementById('user_list_in');
30               
31                for(var i=0; i<select_available_users.options.length; i++){
32                        select_available_users.options[i] = null;
33                        i--;
34                }
35                var options = '###';
36                if (data) {
37                       
38                        options += '<option  value="-1" disabled>------------------- '+document.getElementById("txt_users").value+' ------------------ </option>' + data;
39                       
40                        if(is_firefox_0)
41                                fixBugInnerSelect(select_available_users,options);
42                        else
43                                select_available_users.innerHTML = options;
44
45                        select_available_users.outerHTML = select_available_users.outerHTML;
46                        select_available_users.disabled = false;
47                        select_available_users_clone = document.getElementById('user_list_in').cloneNode(true);
48                        document.getElementById('cal_input_searchUser').value = '';
49                }
50        }       
51
52        document.getElementById('combo_org').value = context;
53        cExecute (path+'.ldap_functions.get_available_users2&valueAsUidNum=1&context='+context+'&type='+type, handler_get_available_users2);   
54}
55
56var handler_get_available_users = function(data)
57{       
58        data = data.JSON( );
59        select_available_users = Element('user_list_in');
60       
61        for(var i=0; i<select_available_users.options.length; i++){
62                select_available_users.options[i] = null;
63                i--;
64        }
65        var options = '###';
66        if (data) {
67                if(data.groups && data.groups.length > 0) {
68                        data.groups = '<option  value="-1" disabled>------------------- '+Element("txt_groups").value+' ------------------ </option>' + data.groups;
69                }               
70                if(data.users && data.users.length > 0) {
71                        data.users = '<option  value="-1" disabled>------------------- '+Element("txt_users").value+' ------------------ </option>' + data.users;
72                }
73                options +=  data.groups && data.groups.length > 0 ? data.groups : '';
74                options +=  data.users  && data.users.length  > 0 ? data.users  : '';
75               
76                if(is_firefox_0)
77                        fixBugInnerSelect(select_available_users,options);
78                else
79                        select_available_users.innerHTML = options;
80
81                select_available_users.outerHTML = select_available_users.outerHTML;
82                select_available_users.disabled = false;
83                select_available_users_clone = Element('user_list_in').cloneNode(true);         
84        }
85}       
86
87function get_available_users(module,context,type, autoSearch){
88        Element('cal_input_searchUser').value = '';
89        if(autoSearch != 'True'){
90                return true;
91        }
92        var context = document.getElementById('combo_org').value;       
93        ExpressoLivre.go( {
94                "access" : module+'.ldap_functions.get_available_users&context='+context+'&type='+type,
95                "handler" : handler_get_available_users
96        } );
97}
98
99function optionFinderTimeout(obj, numMin, type, autoSearch){
100        var oWait = Element("cal_span_searching");
101        oWait.innerHTML = 'Buscando...';
102        clearTimeout(finderTimeout);           
103       
104        if(autoSearch == "True"){
105                finderTimeout = setTimeout("optionFinderLocal('"+obj.id+"')",500);
106        }
107        else if (obj.value.length >= numMin){
108                finderTimeout = setTimeout("optionFinderLdap('"+obj.id+"','"+numMin+"','"+type+"')",500);
109        }else {
110                oWait.innerHTML = 'Mínimo de '+numMin+' letras para pesquisa';
111                var select_available_users_tmp = document.getElementById('user_list_in');
112                for(var i = 0;i < select_available_users_tmp.options.length; i++)
113                select_available_users_tmp.options[i--] = null;
114        }
115}
116// Pesquisa Javascript
117function optionFinderLocal(id){
118        var oText = Element(id);
119        var oWait = Element("cal_span_searching");
120        var select_available_users_tmp = Element('user_list_in');
121        for(var i = 0;i < select_available_users_tmp.options.length; i++)
122                select_available_users_tmp.options[i--] = null;
123        var RegExp_name = new RegExp("\\b"+oText.value, "i");
124
125        for(i = 0; i < select_available_users_clone.length; i++){
126                if (RegExp_name.test(select_available_users_clone[i].text) || select_available_users_clone[i].value =="-1")
127                {
128                        sel = select_available_users_tmp.options;
129                        option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value);
130                        if( select_available_users_clone[i].value == "-1") option.disabled = true;
131                        sel[sel.length] = option;
132                }
133        }
134        oWait.innerHTML = '&nbsp;';     
135}
136
137// Pesquisa LDAP
138function optionFinderLdap(id,numMin, type){
139                var oWait = Element("cal_span_searching");
140                var oText = Element(id);
141                       
142                if (oText.value.length < numMin) {
143                                oWait.innerHTML = '';
144                                var select_available_users_tmp = document.getElementById('user_list_in');
145                                for(var i = 0;i < select_available_users_tmp.options.length; i++)
146                                        select_available_users_tmp.options[i--] = null;
147                }
148               
149                if (oText.value.length >= numMin){
150                        var context = document.getElementById('combo_org').value;
151                        ExpressoLivre.go( {
152                                "access" : 'expressoMail1_2.ldap_functions.search_users&context='+escape(context)+'&type='+(type == '' ? 'list' : 'search')+'&filter='+oText.value,
153                                "handler" : handler_get_available_users
154                        } );
155                        oWait.innerHTML = '&nbsp;';
156                }
157}
158
159function add_user()
160{
161        var select_available_users = document.getElementById('user_list_in');
162        var select_users = document.getElementById('user_list');
163        var count_available_users = select_available_users.length;
164        var count_users = select_users.options.length;
165        var new_options = '';
166       
167        for (i = 0 ; i < count_available_users ; i++) {
168                if (select_available_users.options[i].selected) {
169                        if(document.all) {
170                                if ( (select_users.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' ) {
171                                        new_options +=  '<option value='
172                                                                + select_available_users.options[i].value
173                                                                + '>'
174                                                                + select_available_users.options[i].text
175                                                                + '</option>';
176                                }
177                        }
178                        else if ( (select_users.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' ) {
179                                        new_options +=  '<option value='
180                                                                + select_available_users.options[i].value
181                                                                + '>'
182                                                                + select_available_users.options[i].text
183                                                                + '</option>';
184                        }
185                }
186        }
187
188        if (new_options != '') {
189
190                if(is_firefox_0)
191                        fixBugInnerSelect(select_users,'###' + new_options + select_users.innerHTML);
192                else
193                        select_users.innerHTML = '###' + new_options + select_users.innerHTML;
194
195                select_users.outerHTML = select_users.outerHTML;
196        }
197}
198
199function remove_user(){
200        select_users = document.getElementById('user_list');
201       
202        for(var i = 0;i < select_users.options.length; i++)
203                if(select_users.options[i].selected)
204                        select_users.options[i--] = null;
205}
206
207function submitValues(){
208        var typeField = document.getElementById('cal[type]');
209        if (typeField && typeField.value == 'hourAppointment') {
210                if(document.getElementsByName('categories[]')[0].value == ""){
211                        alert(alert_msg);
212                        return false;
213                }
214        }
215        var select_in = document.getElementById('user_list');
216        for(i = 0; i < select_in.length; i++)
217                select_in.options[i].selected = true;
218}       
219
220function Element(id){
221        return document.getElementById(id);
222}
223
224function loadScript(scriptPath){
225
226        if(!expresso.connector)
227                throw new Error("Error : expresso.connector is not loaded.");
228       
229        if(expresso.connector.oxmlhttp==null)
230                expresso.connector.createXMLHTTP();
231               
232        if (document.getElementById('uploadscript_'+scriptPath)) {
233                return;
234        }
235
236        scriptPath = URL_SERVER + scriptPath;
237
238        expresso.connector.oxmlhttp.open("GET", scriptPath, false);
239    expresso.connector.oxmlhttp.setRequestHeader('Content-Type','text/plain');
240        expresso.connector.oxmlhttp.send(null);
241        if(expresso.connector.oxmlhttp.status != 0 && expresso.connector.oxmlhttp.status != 200 ||      expresso.connector.oxmlhttp.status == 0 && expresso.connector.oxmlhttp.responseText.length == 0)
242                throw new Error("Error " + expresso.connector.oxmlhttp.status + "("+expresso.connector.oxmlhttp.statusText+") when loading script file '"+scriptPath+"'");
243       
244        var head = document.getElementsByTagName("head")[0];
245        var script = document.createElement("SCRIPT");
246        script.id = 'uploadscript_'+scriptPath;
247        script.type = 'text/javascript';               
248        script.text = expresso.connector.oxmlhttp.responseText;
249        head.appendChild(script);
250        return;
251}
252
253function showExParticipants(el,path){
254        Element('tbl_ext_participants').style.display='';
255        el.style.display='none';
256        loadScript(path+"/js/jscode/DropDownContacts.js");
257        loadScript(path+"/js/jscode/common_functions.js");
258        loadScript(path+"/js/jscode/QuickCatalogSearch.js");
259        loadScript("calendar/js/over_fn_exmail.js");
260        if(!contacts)
261                cExecute (path+'.db_functions.get_dropdown_contacts', save_contacts);
262}
263
264function hideExParticipants(el,path){
265        Element('a_ext_participants').style.display = '';
266        Element('tbl_ext_participants').style.display ='none';
267}
268
269function save_contacts(data){
270        contacts = data;       
271        var input_to = Element("ex_participants");
272        input_to.style.width = "100%";
273        input_to.setAttribute("wrap","soft");   
274        input_to.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus', this.id);};
275        input_to.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);};
276        if (!is_ie)
277        {
278                input_to.rows = 2;
279                input_to.onkeypress = function (e)
280                {
281                        if ((e.keyCode) == 120) //F9
282                        {
283                                emQuickSearch(input_to);
284                        }
285                        else
286                        {
287                                if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
288                                {
289                                        e.preventDefault();
290                                        search_contacts(e.keyCode,this.id);
291                                }
292                        }
293                }
294                input_to.onkeyup = function (e)
295                {
296                        if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
297                        {
298                                search_contacts(e.keyCode,this.id);
299                        }
300                }
301        }
302        else
303        {
304                input_to.rows = 3;
305                input_to.onkeyup = function (e)
306                {
307                        if ((window.event.keyCode) == 120) //F9
308                        {
309                                emQuickSearch(input_to);
310                        }
311                        else
312                        {
313                                search_contacts(window.event.keyCode,this.id);
314                        }       
315                }
316        }
317}
318
319function fixBugInnerSelect(objeto,innerHTML){
320/******
321* select_innerHTML - altera o innerHTML de um select independente se é FF ou IE
322* Corrige o problema de não ser possível usar o innerHTML no IE corretamente
323* Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
324* Use a vontade mas coloque meu nome nos créditos. Dúvidas, me mande um email.
325* Versão: 1.0 - 06/04/2006
326* Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
327* Parametros:
328* objeto(tipo object): o select a ser alterado
329* innerHTML(tipo string): o novo valor do innerHTML
330*******/
331    objeto.innerHTML = ""
332    var selTemp = document.createElement("micoxselect")
333    var opt;
334    selTemp.id="micoxselect1"
335    document.body.appendChild(selTemp)
336    selTemp = document.getElementById("micoxselect1")
337    selTemp.style.display="none"
338    if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto
339        innerHTML = "<option>" + innerHTML + "</option>"
340    }
341    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
342    selTemp.innerHTML = innerHTML
343    for(var i=0;i<selTemp.childNodes.length;i++){
344        if(selTemp.childNodes[i].tagName){
345            opt = document.createElement("OPTION")
346            for(var j=0;j<selTemp.childNodes[i].attributes.length;j++){
347                opt.setAttributeNode(selTemp.childNodes[i].attributes[j].cloneNode(true))
348            }
349            opt.value = selTemp.childNodes[i].getAttribute("value")
350            opt.text = selTemp.childNodes[i].innerHTML
351            if(document.all){ //IEca
352                objeto.add(opt)
353            }else{
354                objeto.appendChild(opt)
355            }                   
356        }   
357    }
358    document.body.removeChild(selTemp)
359    selTemp = null
360}
361
362function changeViewMode(eltype){
363        var chValue = eltype;
364        switch (chValue){
365                case 'hourAppointment':
366                        var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval');
367                        for (var i=0; i < names.length; i++)
368                        {
369                                var Field = document.getElementsByName('cal['+names[i]+']');
370                                if (Field[0])
371                                        Field[0].parentNode.parentNode.style.display = "none";
372                        }
373                        Field = document.getElementById('rpt_label');
374                        Field.parentNode.parentNode.style.display = "none";
375                        Field = document.getElementsByName('participants[]');
376                        Field[0].parentNode.parentNode.style.display = "none";
377                        Field[1].parentNode.parentNode.style.display = "none";
378                        Field = document.getElementById('txt_loading');
379                        Field.parentNode.parentNode.style.display = "none";
380                        Field = document.getElementsByName('cal[rpt_day][]');
381                        Field[0].parentNode.parentNode.style.display = "none";
382                        break;
383                case 'privateHiddenFields':
384                        var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval');
385                        for (var i=0; i < names.length; i++)
386                        {
387                                var Field = document.getElementsByName('cal['+names[i]+']');
388                                if (Field[0])
389                                        Field[0].parentNode.parentNode.style.display = "";
390                        }
391                        Field = document.getElementById('rpt_label');
392                        Field.parentNode.parentNode.style.display = "";
393                        Field = document.getElementsByName('participants[]');
394                        Field[0].parentNode.parentNode.style.display = "none";
395                        Field[1].parentNode.parentNode.style.display = "none";
396                        Field = document.getElementById('txt_loading');
397                        Field.parentNode.parentNode.style.display = "none";
398                        Field = document.getElementsByName('cal[rpt_day][]');
399                        Field[0].parentNode.parentNode.style.display = "";
400                        break;
401                default:
402                        var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval');
403                        for (var i=0; i < names.length; i++)
404                        {
405                                var Field = document.getElementsByName('cal['+names[i]+']');
406                                if (Field[0])
407                                        Field[0].parentNode.parentNode.style.display = "";
408                        }
409                        Field = document.getElementById('rpt_label');
410                        Field.parentNode.parentNode.style.display = "";
411                        Field = document.getElementsByName('participants[]');
412                        Field[0].parentNode.parentNode.style.display = "";
413                        Field[1].parentNode.parentNode.style.display = "";
414                        Field = document.getElementById('txt_loading');
415                        Field.parentNode.parentNode.style.display = "";
416                        Field = document.getElementsByName('cal[rpt_day][]');
417                        Field[0].parentNode.parentNode.style.display = "";
418                        break;
419        }
420
421}
422function updateTitleField(select){
423        var typeField = document.getElementsByName('cal[type]');
424        if (typeField[0].value != 'hourAppointment')
425                return;
426        var titleField = document.getElementsByName('cal[title]');
427        var optionsArray = select.childNodes;
428        titleField[0].value = '';
429        for(option in optionsArray)
430                if (optionsArray[option].selected)
431                        titleField[0].value += optionsArray[option].text + ' ';
432}
433
434var __onLoad = window.onload;
435window.onload = function(){
436        __onLoad();
437        var cal_type = document.getElementById('cal[type]').value;
438        changeViewMode(cal_type);
439        if(cal_type == 'hourAppointment'){
440                clearTimeout(timeout_get_available_users);
441        }
442};
Note: See TracBrowser for help on using the repository browser.