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

Revision 925, 11.8 KB checked in by rafaelraymundo, 15 years ago (diff)

Ticket #525 - Alteracoes para a busca Ajax. Adicionada a funcao search_users em class.ldap_functions.inc.php
do ExpressoMail? para realizar as buscas na adicao de participantes.

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