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

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

Ticket #576 - Configurar auto busca na Configuracao do servidor da agenda de eventos.

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