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

Revision 2630, 15.1 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1009 - Mitigando problema com escopo do dominio.

  • 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        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(!expresso.connector)
220                throw new Error("Error : expresso.connector is not loaded.");
221       
222        if(expresso.connector.oxmlhttp==null)
223                expresso.connector.createXMLHTTP();
224               
225        if (document.getElementById('uploadscript_'+scriptPath)) {
226                return;
227        }
228
229        scriptPath = URL_SERVER + scriptPath;
230
231        expresso.connector.oxmlhttp.open("GET", scriptPath, false);
232    expresso.connector.oxmlhttp.setRequestHeader('Content-Type','text/plain');
233        expresso.connector.oxmlhttp.send(null);
234        if(expresso.connector.oxmlhttp.status != 0 && expresso.connector.oxmlhttp.status != 200 ||      expresso.connector.oxmlhttp.status == 0 && expresso.connector.oxmlhttp.responseText.length == 0)
235                throw new Error("Error " + expresso.connector.oxmlhttp.status + "("+expresso.connector.oxmlhttp.statusText+") when loading script file '"+scriptPath+"'");
236       
237        var head = document.getElementsByTagName("head")[0];
238        var script = document.createElement("SCRIPT");
239        script.id = 'uploadscript_'+scriptPath;
240        script.type = 'text/javascript';               
241        script.text = expresso.connector.oxmlhttp.responseText;
242        head.appendChild(script);
243        return;
244}
245
246function showExParticipants(el,path){
247        Element('tbl_ext_participants').style.display='';
248        el.style.display='none';
249        loadScript(path+"/js/jscode/DropDownContacts.js");
250        loadScript(path+"/js/jscode/common_functions.js");
251        loadScript(path+"/js/jscode/QuickCatalogSearch.js");
252        loadScript("calendar/js/over_fn_exmail.js");
253        if(!contacts)
254                cExecute (path+'.db_functions.get_dropdown_contacts', save_contacts);
255}
256
257function hideExParticipants(el,path){
258        Element('a_ext_participants').style.display = '';
259        Element('tbl_ext_participants').style.display ='none';
260}
261
262function save_contacts(data){
263        contacts = data;       
264        var input_to = Element("ex_participants");
265        input_to.style.width = "100%";
266        input_to.setAttribute("wrap","soft");   
267        input_to.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus', this.id);};
268        input_to.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);};
269        if (!is_ie)
270        {
271                input_to.rows = 2;
272                input_to.onkeypress = function (e)
273                {
274                        if ((e.keyCode) == 120) //F9
275                        {
276                                emQuickSearch(input_to);
277                        }
278                        else
279                        {
280                                if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
281                                {
282                                        e.preventDefault();
283                                        search_contacts(e.keyCode,this.id);
284                                }
285                        }
286                }
287                input_to.onkeyup = function (e)
288                {
289                        if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
290                        {
291                                search_contacts(e.keyCode,this.id);
292                        }
293                }
294        }
295        else
296        {
297                input_to.rows = 3;
298                input_to.onkeyup = function (e)
299                {
300                        if ((window.event.keyCode) == 120) //F9
301                        {
302                                emQuickSearch(input_to);
303                        }
304                        else
305                        {
306                                search_contacts(window.event.keyCode,this.id);
307                        }       
308                }
309        }
310}
311
312function fixBugInnerSelect(objeto,innerHTML){
313/******
314* select_innerHTML - altera o innerHTML de um select independente se é FF ou IE
315* Corrige o problema de não ser possível usar o innerHTML no IE corretamente
316* Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
317* Use a vontade mas coloque meu nome nos créditos. Dúvidas, me mande um email.
318* Versão: 1.0 - 06/04/2006
319* Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
320* Parametros:
321* objeto(tipo object): o select a ser alterado
322* innerHTML(tipo string): o novo valor do innerHTML
323*******/
324    objeto.innerHTML = ""
325    var selTemp = document.createElement("micoxselect")
326    var opt;
327    selTemp.id="micoxselect1"
328    document.body.appendChild(selTemp)
329    selTemp = document.getElementById("micoxselect1")
330    selTemp.style.display="none"
331    if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto
332        innerHTML = "<option>" + innerHTML + "</option>"
333    }
334    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
335    selTemp.innerHTML = innerHTML
336    for(var i=0;i<selTemp.childNodes.length;i++){
337        if(selTemp.childNodes[i].tagName){
338            opt = document.createElement("OPTION")
339            for(var j=0;j<selTemp.childNodes[i].attributes.length;j++){
340                opt.setAttributeNode(selTemp.childNodes[i].attributes[j].cloneNode(true))
341            }
342            opt.value = selTemp.childNodes[i].getAttribute("value")
343            opt.text = selTemp.childNodes[i].innerHTML
344            if(document.all){ //IEca
345                objeto.add(opt)
346            }else{
347                objeto.appendChild(opt)
348            }                   
349        }   
350    }
351    document.body.removeChild(selTemp)
352    selTemp = null
353}
354
355function changeViewMode(eltype){
356        var chValue = eltype;
357        switch (chValue){
358                case 'hourAppointment':
359                        var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval');
360                        for (var i=0; i < names.length; i++)
361                        {
362                                var Field = document.getElementsByName('cal['+names[i]+']');
363                                if (Field[0])
364                                        Field[0].parentNode.parentNode.style.display = "none";
365                        }
366                        Field = document.getElementById('rpt_label');
367                        Field.parentNode.parentNode.style.display = "none";
368                        Field = document.getElementsByName('participants[]');
369                        Field[0].parentNode.parentNode.style.display = "none";
370                        Field[1].parentNode.parentNode.style.display = "none";
371                        Field = document.getElementById('txt_loading');
372                        Field.parentNode.parentNode.style.display = "none";
373                        Field = document.getElementsByName('cal[rpt_day][]');
374                        Field[0].parentNode.parentNode.style.display = "none";
375                        break;
376                case 'privateHiddenFields':
377                        var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval');
378                        for (var i=0; i < names.length; i++)
379                        {
380                                var Field = document.getElementsByName('cal['+names[i]+']');
381                                if (Field[0])
382                                        Field[0].parentNode.parentNode.style.display = "";
383                        }
384                        Field = document.getElementById('rpt_label');
385                        Field.parentNode.parentNode.style.display = "";
386                        Field = document.getElementsByName('participants[]');
387                        Field[0].parentNode.parentNode.style.display = "none";
388                        Field[1].parentNode.parentNode.style.display = "none";
389                        Field = document.getElementById('txt_loading');
390                        Field.parentNode.parentNode.style.display = "none";
391                        Field = document.getElementsByName('cal[rpt_day][]');
392                        Field[0].parentNode.parentNode.style.display = "";
393                        break;
394                default:
395                        var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval');
396                        for (var i=0; i < names.length; i++)
397                        {
398                                var Field = document.getElementsByName('cal['+names[i]+']');
399                                if (Field[0])
400                                        Field[0].parentNode.parentNode.style.display = "";
401                        }
402                        Field = document.getElementById('rpt_label');
403                        Field.parentNode.parentNode.style.display = "";
404                        Field = document.getElementsByName('participants[]');
405                        Field[0].parentNode.parentNode.style.display = "";
406                        Field[1].parentNode.parentNode.style.display = "";
407                        Field = document.getElementById('txt_loading');
408                        Field.parentNode.parentNode.style.display = "";
409                        Field = document.getElementsByName('cal[rpt_day][]');
410                        Field[0].parentNode.parentNode.style.display = "";
411                        break;
412        }
413
414}
415function updateTitleField(select){
416        var typeField = document.getElementsByName('cal[type]');
417        if (typeField[0].value != 'hourAppointment')
418                return;
419        var titleField = document.getElementsByName('cal[title]');
420        var optionsArray = select.childNodes;
421        titleField[0].value = '';
422        for(option in optionsArray)
423                if (optionsArray[option].selected)
424                        titleField[0].value += optionsArray[option].text + ' ';
425}
426
427var __onLoad = window.onload;
428window.onload = function(){
429        __onLoad();
430        var cal_type = document.getElementById('cal[type]').value;
431        changeViewMode(cal_type);
432        if(cal_type == 'hourAppointment'){
433                clearTimeout(timeout_get_available_users);
434        }
435};
Note: See TracBrowser for help on using the repository browser.