source: trunk/calendar/templates/classic/js/edit_exmail.js @ 1500

Revision 1500, 15.8 KB checked in by eduardoalex, 15 years ago (diff)

Ticket #681 - Criada a função para delegar evento

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