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

Revision 1640, 14.9 KB checked in by niltonneto, 14 years ago (diff)

Ticket #745 - Corrigido problema que não respeita configuração do módulo.

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