1 | /******************************************************************************\ |
---|
2 | |************************** CALENDAR MODULE *******************************| |
---|
3 | |********** INCLUDE PARTICIPANTS - PLUGIN USING AJAX EXPRESSOMAIL COMPONENT **| |
---|
4 | \******************************************************************************/ |
---|
5 | var contacts = ''; |
---|
6 | var array_lang = new Array(); |
---|
7 | // onUnload edit message |
---|
8 | if(!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 |
---|
19 | var agt = navigator.userAgent.toLowerCase(); |
---|
20 | var is_firefox_0 = agt.indexOf('firefox/1.0') != -1 && agt.indexOf('firefox/0.') ? true : false; |
---|
21 | |
---|
22 | function 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 | } |
---|
29 | function 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 = ' '; |
---|
48 | } |
---|
49 | |
---|
50 | function 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 | } |
---|
87 | function 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 | |
---|
127 | function 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 | |
---|
135 | function submitValues(){ |
---|
136 | var typeField = document.getElementById('cal[type]'); |
---|
137 | if (typeField && typeField.value == 'hourAppointment') { |
---|
138 | if(document.getElementsByName('categories[]')[0].value == ""){ |
---|
139 | alert(alert_msg); |
---|
140 | return false; |
---|
141 | } |
---|
142 | } |
---|
143 | var select_in = document.getElementById('user_list'); |
---|
144 | for(i = 0; i < select_in.length; i++) |
---|
145 | select_in.options[i].selected = true; |
---|
146 | } |
---|
147 | |
---|
148 | function Element(id){ |
---|
149 | return document.getElementById(id); |
---|
150 | } |
---|
151 | |
---|
152 | function loadScript(scriptPath){ |
---|
153 | |
---|
154 | if(!connector) |
---|
155 | throw new Error("Error : Connector is not loaded."); |
---|
156 | |
---|
157 | if (document.getElementById('uploadscript_'+scriptPath)) { |
---|
158 | return; |
---|
159 | } |
---|
160 | |
---|
161 | connector.oxmlhttp.open("GET", scriptPath, false); |
---|
162 | connector.oxmlhttp.setRequestHeader('Content-Type','text/plain'); |
---|
163 | connector.oxmlhttp.send(null); |
---|
164 | if(connector.oxmlhttp.status != 0 && connector.oxmlhttp.status != 200 || connector.oxmlhttp.status == 0 && connector.oxmlhttp.responseText.length == 0) |
---|
165 | throw new Error("Error " + connector.oxmlhttp.status + "("+connector.oxmlhttp.statusText+") when loading script file '"+scriptPath+"'"); |
---|
166 | |
---|
167 | var head = document.getElementsByTagName("head")[0]; |
---|
168 | var script = document.createElement("SCRIPT"); |
---|
169 | script.id = 'uploadscript_'+scriptPath; |
---|
170 | script.type = 'text/javascript'; |
---|
171 | script.text = connector.oxmlhttp.responseText; |
---|
172 | head.appendChild(script); |
---|
173 | return; |
---|
174 | } |
---|
175 | |
---|
176 | function showExParticipants(el,path){ |
---|
177 | Element('tbl_ext_participants').style.display=''; |
---|
178 | el.style.display='none'; |
---|
179 | loadScript(path+"/js/DropDownContacts.js"); |
---|
180 | loadScript(path+"/js/common_functions.js"); |
---|
181 | loadScript(path+"/js/QuickCatalogSearch.js"); |
---|
182 | loadScript("calendar/templates/celepar/js/over_fn_exmail.js"); |
---|
183 | if(!contacts) |
---|
184 | cExecute (path+'.db_functions.get_dropdown_contacts', save_contacts); |
---|
185 | } |
---|
186 | |
---|
187 | function hideExParticipants(el,path){ |
---|
188 | Element('a_ext_participants').style.display = ''; |
---|
189 | Element('tbl_ext_participants').style.display ='none'; |
---|
190 | } |
---|
191 | |
---|
192 | function save_contacts(data){ |
---|
193 | contacts = data; |
---|
194 | var input_to = Element("ex_participants"); |
---|
195 | input_to.style.width = "100%"; |
---|
196 | input_to.setAttribute("wrap","soft"); |
---|
197 | input_to.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus', this.id);}; |
---|
198 | input_to.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);}; |
---|
199 | if (!is_ie) |
---|
200 | { |
---|
201 | input_to.rows = 2; |
---|
202 | input_to.onkeypress = function (e) |
---|
203 | { |
---|
204 | if ((e.keyCode) == 120) //F9 |
---|
205 | { |
---|
206 | emQuickSearch(input_to); |
---|
207 | } |
---|
208 | else |
---|
209 | { |
---|
210 | if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden')) |
---|
211 | { |
---|
212 | e.preventDefault(); |
---|
213 | search_contacts(e.keyCode,this.id); |
---|
214 | } |
---|
215 | } |
---|
216 | } |
---|
217 | input_to.onkeyup = function (e) |
---|
218 | { |
---|
219 | if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40)) |
---|
220 | { |
---|
221 | search_contacts(e.keyCode,this.id); |
---|
222 | } |
---|
223 | } |
---|
224 | } |
---|
225 | else |
---|
226 | { |
---|
227 | input_to.rows = 3; |
---|
228 | input_to.onkeyup = function (e) |
---|
229 | { |
---|
230 | if ((window.event.keyCode) == 120) //F9 |
---|
231 | { |
---|
232 | emQuickSearch(input_to); |
---|
233 | } |
---|
234 | else |
---|
235 | { |
---|
236 | search_contacts(window.event.keyCode,this.id); |
---|
237 | } |
---|
238 | } |
---|
239 | } |
---|
240 | } |
---|
241 | |
---|
242 | function fixBugInnerSelect(objeto,innerHTML){ |
---|
243 | /****** |
---|
244 | * select_innerHTML - altera o innerHTML de um select independente se é FF ou IE |
---|
245 | * Corrige o problema de não ser possível usar o innerHTML no IE corretamente |
---|
246 | * Veja o problema em: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228 |
---|
247 | * Use a vontade mas coloque meu nome nos créditos. Dúvidas, me mande um email. |
---|
248 | * Versão: 1.0 - 06/04/2006 |
---|
249 | * Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br |
---|
250 | * Parametros: |
---|
251 | * objeto(tipo object): o select a ser alterado |
---|
252 | * innerHTML(tipo string): o novo valor do innerHTML |
---|
253 | *******/ |
---|
254 | objeto.innerHTML = "" |
---|
255 | var selTemp = document.createElement("micoxselect") |
---|
256 | var opt; |
---|
257 | selTemp.id="micoxselect1" |
---|
258 | document.body.appendChild(selTemp) |
---|
259 | selTemp = document.getElementById("micoxselect1") |
---|
260 | selTemp.style.display="none" |
---|
261 | if(innerHTML.toLowerCase().indexOf("<option")<0){//se não é option eu converto |
---|
262 | innerHTML = "<option>" + innerHTML + "</option>" |
---|
263 | } |
---|
264 | innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span") |
---|
265 | selTemp.innerHTML = innerHTML |
---|
266 | for(var i=0;i<selTemp.childNodes.length;i++){ |
---|
267 | if(selTemp.childNodes[i].tagName){ |
---|
268 | opt = document.createElement("OPTION") |
---|
269 | for(var j=0;j<selTemp.childNodes[i].attributes.length;j++){ |
---|
270 | opt.setAttributeNode(selTemp.childNodes[i].attributes[j].cloneNode(true)) |
---|
271 | } |
---|
272 | opt.value = selTemp.childNodes[i].getAttribute("value") |
---|
273 | opt.text = selTemp.childNodes[i].innerHTML |
---|
274 | if(document.all){ //IEca |
---|
275 | objeto.add(opt) |
---|
276 | }else{ |
---|
277 | objeto.appendChild(opt) |
---|
278 | } |
---|
279 | } |
---|
280 | } |
---|
281 | document.body.removeChild(selTemp) |
---|
282 | selTemp = null |
---|
283 | } |
---|
284 | |
---|
285 | function changeViewMode(eltype){ |
---|
286 | var chValue = eltype; |
---|
287 | |
---|
288 | switch (chValue){ |
---|
289 | case 'hourAppointment': |
---|
290 | var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label'); |
---|
291 | for (var i=0; i < names.length; i++) |
---|
292 | { |
---|
293 | var Field = document.getElementsByName('cal['+names[i]+']'); |
---|
294 | if (Field[0]) |
---|
295 | Field[0].parentNode.parentNode.style.display = "none"; |
---|
296 | } |
---|
297 | |
---|
298 | Field = document.getElementsByName('participants[]'); |
---|
299 | Field[0].parentNode.parentNode.style.display = "none"; |
---|
300 | Field[1].parentNode.parentNode.style.display = "none"; |
---|
301 | Field = document.getElementById('txt_loading'); |
---|
302 | Field.parentNode.parentNode.style.display = "none"; |
---|
303 | Field = document.getElementsByName('cal[rpt_day][]'); |
---|
304 | Field[0].parentNode.parentNode.style.display = "none"; |
---|
305 | break; |
---|
306 | default: |
---|
307 | var names=new Array('title','priority','location','alarmhours','alarmminutes','recur_type','rpt_use_end','recur_interval','rpt_label'); |
---|
308 | for (var i=0; i < names.length; i++) |
---|
309 | { |
---|
310 | var Field = document.getElementsByName('cal['+names[i]+']'); |
---|
311 | if (Field[0]) |
---|
312 | Field[0].parentNode.parentNode.style.display = ""; |
---|
313 | } |
---|
314 | Field = document.getElementsByName('participants[]'); |
---|
315 | Field[0].parentNode.parentNode.style.display = ""; |
---|
316 | Field[1].parentNode.parentNode.style.display = ""; |
---|
317 | Field = document.getElementById('txt_loading'); |
---|
318 | Field.parentNode.parentNode.style.display = ""; |
---|
319 | Field = document.getElementsByName('cal[rpt_day][]'); |
---|
320 | Field[0].parentNode.parentNode.style.display = ""; |
---|
321 | break; |
---|
322 | } |
---|
323 | |
---|
324 | } |
---|
325 | function updateTitleField(select){ |
---|
326 | var typeField = document.getElementsByName('cal[type]'); |
---|
327 | if (typeField[0].value != 'hourAppointment') |
---|
328 | return; |
---|
329 | var titleField = document.getElementsByName('cal[title]'); |
---|
330 | var optionsArray = select.childNodes; |
---|
331 | titleField[0].value = ''; |
---|
332 | for(option in optionsArray) |
---|
333 | if (optionsArray[option].selected) |
---|
334 | titleField[0].value += optionsArray[option].text + ' '; |
---|
335 | } |
---|
336 | |
---|
337 | var __onLoad = window.onload; |
---|
338 | window.onload = function(){ |
---|
339 | __onLoad(); |
---|
340 | var cal_type = document.getElementById('cal[type]').value; |
---|
341 | changeViewMode(cal_type); |
---|
342 | if(cal_type == 'hourAppointment'){ |
---|
343 | clearTimeout(timeout_get_available_users); |
---|
344 | } |
---|
345 | }; |
---|