source: branches/2.2.0.1/calendar/js/edit_exmail.js @ 3978

Revision 3978, 15.1 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1601 - Desabilitar F9 para pesquisa de contatos externos na agenda

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