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

Revision 264, 9.3 KB checked in by niltonneto, 16 years ago (diff)

Modificado modo de sobrecarga da função unload,
para não perder seu estado (não sendo IE).

  • 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 optionFinderTimeout(obj)
23{
24        clearTimeout(finderTimeout);   
25        var oWait = document.getElementById("cal_span_searching");
26        oWait.innerHTML = document.getElementById("txt_searching").value + '...';
27        var finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500);
28}
29function optionFinder(id) {
30        var oWait = document.getElementById("cal_span_searching");
31        var oText = document.getElementById(id);                       
32        var select_available_users_tmp = document.getElementById('user_list_in')
33        for(var i = 0;i < select_available_users_tmp.options.length; i++)
34                select_available_users_tmp.options[i--] = null;
35
36        var RegExp_name = new RegExp("\\b"+oText.value, "i");
37
38        for(i = 0; i < select_available_users_clone.length; i++){
39                if (RegExp_name.test(select_available_users_clone[i].text) || select_available_users_clone[i].value =="-1")
40                {
41                        sel = select_available_users_tmp.options;
42                        option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value);
43                        if( select_available_users_clone[i].value == "-1") option.disabled = true;
44                        sel[sel.length] = option;
45                }
46        }       
47        oWait.innerHTML = '&nbsp;';
48}       
49               
50function get_available_users(path,context,type)
51{
52        var handler_get_available_users = function(data)
53        {       
54                select_available_users = document.getElementById('user_list_in');
55               
56                for(var i=0; i<select_available_users.options.length; i++){
57                        select_available_users.options[i] = null;
58                        i--;
59                }
60                var options = '###';
61                if (data) {
62                        if(data.groups && data.groups.length > 0) {
63                                data.groups = '<option  value="-1" disabled>------------------- '+document.getElementById("txt_groups").value+' ------------------ </option>' + data.groups;
64                        }
65                       
66                        if(data.users && data.users.length > 0) {
67                                data.users = '<option  value="-1" disabled>------------------- '+document.getElementById("txt_users").value+' ------------------ </option>' + data.users;
68                        }
69                        options +=  data.groups && data.groups.length > 0 ? data.groups : '';
70                        options +=  data.users  && data.users.length  > 0 ? data.users  : '';
71                       
72                        if(is_firefox_0)
73                                fixBugInnerSelect(select_available_users,options);
74                        else
75                                select_available_users.innerHTML = options;
76
77                        select_available_users.outerHTML = select_available_users.outerHTML;
78                        select_available_users.disabled = false;
79                        select_available_users_clone = document.getElementById('user_list_in').cloneNode(true);
80                        document.getElementById('cal_input_searchUser').value = '';
81                }
82        }       
83
84        document.getElementById('combo_org').value = context;
85        cExecute (path+'.ldap_functions.get_available_users&context='+context+'&type='+type, handler_get_available_users);
86}
87function add_user()
88{
89        var select_available_users = document.getElementById('user_list_in');
90        var select_users = document.getElementById('user_list');
91        var count_available_users = select_available_users.length;
92        var count_users = select_users.options.length;
93        var new_options = '';
94       
95        for (i = 0 ; i < count_available_users ; i++) {
96                if (select_available_users.options[i].selected) {
97                        if(document.all) {
98                                if ( (select_users.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' ) {
99                                        new_options +=  '<option value='
100                                                                + select_available_users.options[i].value
101                                                                + '>'
102                                                                + select_available_users.options[i].text
103                                                                + '</option>';
104                                }
105                        }
106                        else if ( (select_users.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' ) {
107                                        new_options +=  '<option value='
108                                                                + select_available_users.options[i].value
109                                                                + '>'
110                                                                + select_available_users.options[i].text
111                                                                + '</option>';
112                        }
113                }
114        }
115
116        if (new_options != '') {
117
118                if(is_firefox_0)
119                        fixBugInnerSelect(select_users,'###' + new_options + select_users.innerHTML);
120                else
121                        select_users.innerHTML = '###' + new_options + select_users.innerHTML;
122
123                select_users.outerHTML = select_users.outerHTML;
124        }
125}
126
127function remove_user(){
128        select_users = document.getElementById('user_list');
129       
130        for(var i = 0;i < select_users.options.length; i++)
131                if(select_users.options[i].selected)
132                        select_users.options[i--] = null;
133}
134
135function submitValues(){
136        var select_in = document.getElementById('user_list');
137        for(i = 0; i < select_in.length; i++)
138                select_in.options[i].selected = true;
139}       
140
141function Element(id){
142        return document.getElementById(id);
143}
144
145function loadScript(scriptPath){
146
147        if(!connector)
148                throw new Error("Error : Connector is not loaded.");
149               
150        if (document.getElementById('uploadscript_'+scriptPath)) {
151                return;
152        }
153       
154        connector.oxmlhttp.open("GET", scriptPath, false);
155    connector.oxmlhttp.setRequestHeader('Content-Type','text/plain');
156        connector.oxmlhttp.send(null);
157        if(connector.oxmlhttp.status != 0 && connector.oxmlhttp.status != 200 ||        connector.oxmlhttp.status == 0 && connector.oxmlhttp.responseText.length == 0)
158                throw new Error("Error " + connector.oxmlhttp.status + "("+connector.oxmlhttp.statusText+") when loading script file '"+scriptPath+"'");
159       
160        var head = document.getElementsByTagName("head")[0];
161        var script = document.createElement("SCRIPT");
162        script.id = 'uploadscript_'+scriptPath;
163        script.type = 'text/javascript';               
164        script.text = connector.oxmlhttp.responseText;
165        head.appendChild(script);
166        return;
167}
168
169function showExParticipants(el,path){
170        Element('tbl_ext_participants').style.display='';
171        el.style.display='none';
172        loadScript(path+"/js/DropDownContacts.js");
173        loadScript(path+"/js/common_functions.js");
174        loadScript(path+"/js/QuickCatalogSearch.js");
175        loadScript("calendar/templates/celepar/js/over_fn_exmail.js");
176        if(!contacts)
177                cExecute (path+'.db_functions.get_dropdown_contacts', save_contacts);
178}
179
180function hideExParticipants(el,path){
181        Element('a_ext_participants').style.display = '';
182        Element('tbl_ext_participants').style.display ='none';
183}
184
185function save_contacts(data){
186        contacts = data;       
187        var input_to = Element("ex_participants");
188        input_to.style.width = "100%";
189        input_to.setAttribute("wrap","soft");   
190        input_to.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus', this.id);};
191        input_to.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);};
192        if (!is_ie)
193        {
194                input_to.rows = 2;
195                input_to.onkeypress = function (e)
196                {
197                        if ((e.keyCode) == 120) //F9
198                        {
199                                emQuickSearch(input_to);
200                        }
201                        else
202                        {
203                                if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
204                                {
205                                        e.preventDefault();
206                                        search_contacts(e.keyCode,this.id);
207                                }
208                        }
209                }
210                input_to.onkeyup = function (e)
211                {
212                        if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
213                        {
214                                search_contacts(e.keyCode,this.id);
215                        }
216                }
217        }
218        else
219        {
220                input_to.rows = 3;
221                input_to.onkeyup = function (e)
222                {
223                        if ((window.event.keyCode) == 120) //F9
224                        {
225                                emQuickSearch(input_to);
226                        }
227                        else
228                        {
229                                search_contacts(window.event.keyCode,this.id);
230                        }       
231                }
232        }
233}
234
235function fixBugInnerSelect(objeto,innerHTML){
236/******
237* select_innerHTML - altera o innerHTML de um select independente se é FF ou IE
238* Corrige o problema de não ser possível usar o innerHTML no IE corretamente
239* Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
240* Use a vontade mas coloque meu nome nos créditos. Dúvidas, me mande um email.
241* Versão: 1.0 - 06/04/2006
242* Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
243* Parametros:
244* objeto(tipo object): o select a ser alterado
245* innerHTML(tipo string): o novo valor do innerHTML
246*******/
247    objeto.innerHTML = ""
248    var selTemp = document.createElement("micoxselect")
249    var opt;
250    selTemp.id="micoxselect1"
251    document.body.appendChild(selTemp)
252    selTemp = document.getElementById("micoxselect1")
253    selTemp.style.display="none"
254    if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto
255        innerHTML = "<option>" + innerHTML + "</option>"
256    }
257    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
258    selTemp.innerHTML = innerHTML
259    for(var i=0;i<selTemp.childNodes.length;i++){
260        if(selTemp.childNodes[i].tagName){
261            opt = document.createElement("OPTION")
262            for(var j=0;j<selTemp.childNodes[i].attributes.length;j++){
263                opt.setAttributeNode(selTemp.childNodes[i].attributes[j].cloneNode(true))
264            }
265            opt.value = selTemp.childNodes[i].getAttribute("value")
266            opt.text = selTemp.childNodes[i].innerHTML
267            if(document.all){ //IEca
268                objeto.add(opt)
269            }else{
270                objeto.appendChild(opt)
271            }                   
272        }   
273    }
274    document.body.removeChild(selTemp)
275    selTemp = null
276}
Note: See TracBrowser for help on using the repository browser.