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

Revision 18, 9.1 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

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