source: companies/serpro/calendar/templates/celepar/js/edit_exmail.js @ 903

Revision 903, 12.8 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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//function get_available_users(path,context,type)
24{
25        var handler_get_available_users = function(data)
26        {       
27                select_available_users = document.getElementById('user_list_in');
28               
29                for(var i=0; i<select_available_users.options.length; i++){
30                        select_available_users.options[i] = null;
31                        i--;
32                }
33                var options = '###';
34                if (data) {
35                        if(data.groups && data.groups.length > 0) {
36                                data.groups = '<option  value="-1" disabled>------------------- '+document.getElementById("txt_groups").value+' ------------------ </option>' + data.groups;
37                        }
38                       
39                        if(data.users && data.users.length > 0) {
40                                data.users = '<option  value="-1" disabled>------------------- '+document.getElementById("txt_users").value+' ------------------ </option>' + data.users;
41                        }
42                        options +=  data.groups && data.groups.length > 0 ? data.groups : '';
43                        options +=  data.users  && data.users.length  > 0 ? data.users  : '';
44                       
45                        if(is_firefox_0)
46                                fixBugInnerSelect(select_available_users,options);
47                        else
48                                select_available_users.innerHTML = options;
49
50                        select_available_users.outerHTML = select_available_users.outerHTML;
51                        select_available_users.disabled = false;
52                        select_available_users_clone = document.getElementById('user_list_in').cloneNode(true);
53                        //document.getElementById('cal_input_searchUser').value = '';
54                }
55        }       
56                context = document.getElementById('combo_org').value;
57                cExecute ('expressoMail1_2'+'.ldap_functions.search_users&filter='+filter+'&context='+context+'&type=search', handler_get_available_users);
58                //cExecute (path+'.ldap_functions.get_available_users&context='+context+'&type='+type, handler_get_available_users);
59}
60
61function optionFinderTimeout(obj,numMin){
62                var oWait = document.getElementById("cal_span_searching");
63                if (obj.value.length >= numMin){
64                        clearTimeout(finderTimeout);   
65                        oWait.innerHTML = 'Buscando...';
66                        var finderTimeout = setTimeout("optionFinder('"+obj.id+"','"+numMin+"')",500);
67                }else {
68                        oWait.innerHTML = 'Mínimo de '+numMin+' letras para pesquisa';
69                        var select_available_users_tmp = document.getElementById('user_list_in');
70                        for(var i = 0;i < select_available_users_tmp.options.length; i++)
71                        select_available_users_tmp.options[i--] = null;
72                }
73}
74       
75function optionFinder(id,numMin){
76       
77                var oWait = document.getElementById("cal_span_searching");
78                var oText = document.getElementById(id);
79                       
80                if (oText.value.length < numMin) {
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 >= numMin) {
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        switch (chValue){
300                case 'hourAppointment':
301                        var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label');
302                        for (var i=0; i < names.length; i++)
303                        {
304                                var Field = document.getElementsByName('cal['+names[i]+']');
305                                if (Field[0])
306                                        Field[0].parentNode.parentNode.style.display = "none";
307                        }
308
309                        Field = document.getElementsByName('participants[]');
310                        Field[0].parentNode.parentNode.style.display = "none";
311                        Field[1].parentNode.parentNode.style.display = "none";
312                        Field = document.getElementById('txt_loading');
313                        Field.parentNode.parentNode.style.display = "none";
314                        Field = document.getElementsByName('cal[rpt_day][]');
315                        Field[0].parentNode.parentNode.style.display = "none";
316                        break;
317                case 'private':
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 = "";
324                        }
325                        Field = document.getElementsByName('participants[]');
326                        Field[0].parentNode.parentNode.style.display = "none";
327                        Field[1].parentNode.parentNode.style.display = "none";
328                        Field = document.getElementById('txt_loading');
329                        Field.parentNode.parentNode.style.display = "none";
330                        Field = document.getElementsByName('cal[rpt_day][]');
331                        Field[0].parentNode.parentNode.style.display = "none";
332                        break;
333                default:
334                        var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label');
335                        for (var i=0; i < names.length; i++)
336                        {
337                                var Field = document.getElementsByName('cal['+names[i]+']');
338                                if (Field[0])
339                                        Field[0].parentNode.parentNode.style.display = "";
340                        }
341                        Field = document.getElementsByName('participants[]');
342                        Field[0].parentNode.parentNode.style.display = "";
343                        Field[1].parentNode.parentNode.style.display = "";
344                        Field = document.getElementById('txt_loading');
345                        Field.parentNode.parentNode.style.display = "";
346                        Field = document.getElementsByName('cal[rpt_day][]');
347                        Field[0].parentNode.parentNode.style.display = "";
348                        break;
349        }
350
351}
352function updateTitleField(select){
353        var typeField = document.getElementsByName('cal[type]');
354        if (typeField[0].value != 'hourAppointment')
355                return;
356        var titleField = document.getElementsByName('cal[title]');
357        var optionsArray = select.childNodes;
358        titleField[0].value = '';
359        for(option in optionsArray)
360                if (optionsArray[option].selected)
361                        titleField[0].value += optionsArray[option].text + ' ';
362}
363
364var __onLoad = window.onload;
365window.onload = function(){
366        __onLoad();
367        var cal_type = document.getElementById('cal[type]').value;
368        changeViewMode(cal_type);
369        if(cal_type == 'hourAppointment'){
370                clearTimeout(timeout_get_available_users);
371        }
372};
Note: See TracBrowser for help on using the repository browser.