source: trunk/calendar/templates/celepar/js/edit_exmail.js @ 1123

Revision 1123, 13.4 KB checked in by rafaelraymundo, 15 years ago (diff)

Ticket #576 - Corrigido problema de sobreposicao da busca autmatica

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