source: contrib/Timesheet/templates/default/js/edit_exmail.js @ 3526

Revision 3526, 13.5 KB checked in by afernandes, 13 years ago (diff)

Ticket #1416 - Disponibilizado modulos Timesheet e DMS para a comunidade.

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