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

Revision 1587, 14.9 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #717 - Alterada a forma de busca de 'name' para 'id' do objeto que contem o texto inadequado

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