source: trunk/calendar/js/edit_exmail.js @ 2802

Revision 2802, 15.4 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1058 - Permitindo o envio de formulário por requisição background

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