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

Revision 1125, 13.5 KB checked in by niltonneto, 15 years ago (diff)

Ticket #576 - Correção da busca rápida (várias requisições).

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