1 | /* |
---|
2 | Todo Otimizar caulculo de timezone |
---|
3 | Objeto Date.toString() retorna a data com inserção do offset |
---|
4 | Objeto Date.getTime() retorna a data sem inserção do offset |
---|
5 | */ |
---|
6 | function checkTimezoneCalendar(idCalendar, timezone){ |
---|
7 | var obj = DataLayer.get('calendar', idCalendar); |
---|
8 | if(User.timezones[obj.timezone] == timezone) |
---|
9 | return true; |
---|
10 | else |
---|
11 | return false; |
---|
12 | } |
---|
13 | |
---|
14 | function setDateTimezone(date, timezone, existsTimezone, idCalendar){ |
---|
15 | |
---|
16 | if(!existsTimezone) |
---|
17 | return date; |
---|
18 | if(idCalendar) |
---|
19 | if(checkTimezoneCalendar(idCalendar, timezone)) |
---|
20 | return getDateTimezone(date, timezone, false); |
---|
21 | |
---|
22 | var timezoneOffset = ''; |
---|
23 | if(User.isDaylightSaving == '1') |
---|
24 | timezoneOffset = parseInt(timezone.substr(2)) - 100; |
---|
25 | else |
---|
26 | timezoneOffset = parseInt(timezone.substr(2)); |
---|
27 | |
---|
28 | var timeCurrent = parseInt((date.getTimezoneOffset()/60)+'00') |
---|
29 | var times = 0; |
---|
30 | if(timezone.charAt(0) != date.getUTCOffset().charAt(0)) |
---|
31 | times = timeCurrent + timezoneOffset ; |
---|
32 | else |
---|
33 | times = timezoneOffset - timeCurrent ; |
---|
34 | |
---|
35 | if(times == 0) |
---|
36 | return date; |
---|
37 | else if(times > 0) |
---|
38 | return date.setTimezoneOffset('-0'+(times)); |
---|
39 | else |
---|
40 | return date.setTimezoneOffset('+0'+((times * -1))); |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
44 | function getDateTimezone(date, timezone, recursive){ |
---|
45 | if(!timezone) |
---|
46 | return date; |
---|
47 | |
---|
48 | var times = 0; |
---|
49 | currentTimezone = parseInt((date.getTimezoneOffset()/60)+'00'); |
---|
50 | var timezoneOffset = 0; |
---|
51 | if(User.isDaylightSaving == '1') |
---|
52 | timezoneOffset = parseInt(timezone.substr(2)) - 100; |
---|
53 | else |
---|
54 | timezoneOffset = parseInt(timezone.substr(2)); |
---|
55 | |
---|
56 | var times = timezoneOffset - currentTimezone; |
---|
57 | if(times == 0){ |
---|
58 | if((timezone.charAt(0) == date.getUTCOffset().charAt(0)) && recursive) |
---|
59 | return date.setTimezoneOffset( timezone.charAt(0)+'0'+(currentTimezone)); |
---|
60 | else |
---|
61 | return date; |
---|
62 | }else if (times > 0) |
---|
63 | return date.setTimezoneOffset('+0'+(times)); |
---|
64 | else{ |
---|
65 | return date.setTimezoneOffset('-0'+((times * -1) + (currentTimezone * 2))); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | function getDateUTC(date, timezone){ |
---|
70 | currentTimezone = parseInt(timezone.substr(2)); |
---|
71 | if(User.isDaylightSaving == '1') |
---|
72 | currentTimezone = currentTimezone - 100; |
---|
73 | return(date.setTimezoneOffset(timezone.charAt(0)+'0'+currentTimezone)); |
---|
74 | } |
---|
75 | |
---|
76 | function createDateTimezone(date, timezone, idCalendar){ |
---|
77 | |
---|
78 | if(checkTimezoneCalendar(idCalendar, timezone)) |
---|
79 | return getDateTimezone(date, timezone, true); |
---|
80 | |
---|
81 | var times = 0; |
---|
82 | |
---|
83 | if(timezone.charAt(0) == '+') |
---|
84 | times = parseInt(timezone.substr(2)) - parseInt((date.getTimezoneOffset()/60)+'00'); |
---|
85 | else |
---|
86 | times = (parseInt(timezone.substr(2)) + parseInt((date.getTimezoneOffset()/60)+'00')) * (-1); |
---|
87 | if(times == 0) |
---|
88 | return date.setTimezoneOffset('0000'); |
---|
89 | else if (times > 0) |
---|
90 | return date.setTimezoneOffset('+0'+times); |
---|
91 | else |
---|
92 | return date.setTimezoneOffset('-0'+(times * -1)); |
---|
93 | } |
---|
94 | |
---|
95 | function defaultToAmPm( Hour ) |
---|
96 | { |
---|
97 | var HourAmPm = Hour.split(":"); |
---|
98 | if(HourAmPm[0] == 0) |
---|
99 | HourAmPm[0] = 12; |
---|
100 | if(HourAmPm[0] < 12){ |
---|
101 | Hour += (Hour.length == 5) ? " am" : ""; |
---|
102 | }else if(HourAmPm[0] == 12){ |
---|
103 | Hour += (Hour.length == 5) ? " pm" : ""; |
---|
104 | }else |
---|
105 | Hour = "0"+(HourAmPm[0]-12)+":"+HourAmPm[1]+ ((Hour.length == 5) ? " pm" : ""); |
---|
106 | return Hour; |
---|
107 | } |
---|
108 | |
---|
109 | function validDateEvent(){ |
---|
110 | var start_date = $(".new-event-win.active .start-date").val(); |
---|
111 | var end_date = $(".new-event-win.active .end-date").val(); |
---|
112 | var start_time = $(".new-event-win.active .start-time").val(); |
---|
113 | var end_time = $(".new-event-win.active .end-time").val(); |
---|
114 | var isAllDay = $('.new-event-win.active input[name="allDay"]').is(':checked'); |
---|
115 | |
---|
116 | if(start_date == "") |
---|
117 | return 'Por favor, informe uma data inicial'; |
---|
118 | else if(end_date == "") |
---|
119 | return 'Por favor, informe uma data final'; |
---|
120 | else if(!isAllDay && start_time == "") |
---|
121 | return 'Por favor, informe uma hora inicial'; |
---|
122 | else if(!isAllDay && end_time == "") |
---|
123 | return 'Por favor, informe uma hora final'; |
---|
124 | |
---|
125 | var formatString = (isAllDay)? User.preferences.dateFormat+" HH:mm" : User.preferences.dateFormat + " " + User.preferences.hourFormat; |
---|
126 | |
---|
127 | var spaces = function(hours){ |
---|
128 | return hours.replace(/\s$/, ""); |
---|
129 | }; |
---|
130 | |
---|
131 | var startDate = Date.parseExact( isAllDay ? start_date+ " 00:00": start_date + " " + spaces(start_time) , formatString ); |
---|
132 | var endDate = Date.parseExact( isAllDay ? end_date+ " 00:00": end_date + " " + spaces(end_time) , formatString ); |
---|
133 | |
---|
134 | if(startDate == null || startDate.getTime() < 0 ) |
---|
135 | return 'Data inicial inválida'; |
---|
136 | if(endDate == null || endDate.getTime() < 0) |
---|
137 | return 'Data final inválida'; |
---|
138 | |
---|
139 | if((endDate.compareTo(startDate) != 1) && !((endDate.compareTo(startDate) == 0) && (isAllDay))){ |
---|
140 | if(start_date == end_date){ |
---|
141 | if(end_time == start_time) |
---|
142 | return 'Hora inicial igual a final'; |
---|
143 | else |
---|
144 | return 'Hora final menor que a inicial'; |
---|
145 | |
---|
146 | }else |
---|
147 | return 'Data final menor que a inicial'; |
---|
148 | } |
---|
149 | return false; |
---|
150 | } |
---|
151 | |
---|
152 | /* |
---|
153 | function listEvents(){ |
---|
154 | var list = $('.fc-header-right').find('.fc-button.fc-button-agendaDay').clone(); |
---|
155 | $('.fc-header-right').find('.fc-button-year').toggleClass('fc-corner-right'); |
---|
156 | list.addClass('fc-corner-right'); |
---|
157 | list.addClass('fc-button-listagem'); |
---|
158 | list.removeClass('fc-button-agendaDay'); |
---|
159 | list.removeClass('fc-corner-left'); |
---|
160 | list.find('.fc-button-content').html('Listagem'); |
---|
161 | $('.fc-header-right').append(list); |
---|
162 | } |
---|
163 | */ |
---|
164 | function eventDetails( objEvent, decoded ) |
---|
165 | { |
---|
166 | if( !decoded ) |
---|
167 | objEvent = DataLayer.decode( "schedulable:calendar", objEvent ); |
---|
168 | |
---|
169 | objEvent = DataLayer.encode( "schedulable:preview", objEvent ); |
---|
170 | |
---|
171 | if(typeof(objEvent.id) == 'undefined'){ |
---|
172 | objEvent.alarms = Calendar.signatureOf[!!User.preferences.defaultCalendar ? User.preferences.defaultCalendar : Calendar.calendarIds[0]].defaultAlarms; |
---|
173 | objEvent.useAlarmDefault = 1; |
---|
174 | } |
---|
175 | |
---|
176 | /** |
---|
177 | * canDiscardEventDialog deve ser true se não houver alterações no evento |
---|
178 | */ |
---|
179 | canDiscardEventDialog = true; |
---|
180 | /** |
---|
181 | * zebraDiscardEventDialog é uma flag indicando que uma janela de confirmação (Zebra_Dialog) |
---|
182 | * já está aberta na tela, uma vez que não é possivel acessar o evento ESC utilizado para fechá-la |
---|
183 | */ |
---|
184 | zebraDiscardEventDialog = false; |
---|
185 | |
---|
186 | DataLayer.render( 'templates/event_add.ejs', {event:objEvent}, function( html ){ |
---|
187 | |
---|
188 | if (!UI.dialogs.addEvent) { |
---|
189 | UI.dialogs.addEvent = jQuery('#sandbox').append('<div title="Criar Evento" class="new-event-win active"> <div>').find('.new-event-win.active').html(html).dialog({ |
---|
190 | resizable: false, |
---|
191 | modal:true, |
---|
192 | autoOpen: false, |
---|
193 | width:700, |
---|
194 | position: 'center', |
---|
195 | close: function(event, ui) { |
---|
196 | /** |
---|
197 | * Remove tooltip possivelmente existente |
---|
198 | */ |
---|
199 | if ($('dd.attendee-list li:last').data('qtip')) |
---|
200 | $('dd.attendee-list li:last').qtip('destroy'); |
---|
201 | |
---|
202 | }, |
---|
203 | beforeClose: function(event, ui) { |
---|
204 | |
---|
205 | if (!canDiscardEventDialog && !zebraDiscardEventDialog) { |
---|
206 | zebraDiscardEventDialog = true; |
---|
207 | window.setTimeout(function() { |
---|
208 | $.Zebra_Dialog('Suas alterações no evento não foram salvas. Deseja descartar as alterações?', { |
---|
209 | 'type': 'question', |
---|
210 | 'overlay_opacity': '0.5', |
---|
211 | 'buttons': ['Descartar alterações', 'Continuar editando'], |
---|
212 | 'onClose': function(clicked) { |
---|
213 | if(clicked == 'Descartar alterações') { |
---|
214 | canDiscardEventDialog = true; |
---|
215 | UI.dialogs.addEvent.dialog('close'); |
---|
216 | } |
---|
217 | |
---|
218 | /** |
---|
219 | * Uma vez aberta uma janela de confirmação (Zebra_Dialog), ao fechá-la |
---|
220 | * com ESC, para que o evento ESC não seja propagado para fechamento da |
---|
221 | * janela de edição de eventos, deve ser setada uma flag indicando que |
---|
222 | * já existe uma janela de confirmação aberta. |
---|
223 | */ |
---|
224 | if (!clicked) { |
---|
225 | zebraDiscardEventDialog = true; |
---|
226 | window.setTimeout(function() { |
---|
227 | zebraDiscardEventDialog = false; |
---|
228 | }, 200); |
---|
229 | } |
---|
230 | } |
---|
231 | }); |
---|
232 | |
---|
233 | }, 300); |
---|
234 | |
---|
235 | } |
---|
236 | return canDiscardEventDialog; |
---|
237 | } |
---|
238 | }); |
---|
239 | |
---|
240 | } else { |
---|
241 | UI.dialogs.addEvent.html(html); |
---|
242 | } |
---|
243 | |
---|
244 | var tabs = UI.dialogs.addEvent.children('.content').tabs(); |
---|
245 | var calendar = DataLayer.get('calendar', objEvent.calendar); |
---|
246 | |
---|
247 | |
---|
248 | UI.dialogs.addEvent.find(':input').change(function(event){ |
---|
249 | if (event.keyCode != '27' && event.keyCode != '13') |
---|
250 | canDiscardEventDialog = false; |
---|
251 | }).keydown(function(event){ |
---|
252 | if (event.keyCode != '27' && event.keyCode != '13') |
---|
253 | canDiscardEventDialog = false; |
---|
254 | }); |
---|
255 | |
---|
256 | if (calendar.timezone != objEvent.timezone){ |
---|
257 | UI.dialogs.addEvent.find('.calendar-addevent-details-txt-timezone').find('option[value="'+objEvent.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
258 | UI.dialogs.addEvent.find('.calendar_addevent_details_lnk_timezone').addClass('hidden'); |
---|
259 | $('.calendar-addevent-details-txt-timezone').removeClass('hidden'); |
---|
260 | |
---|
261 | } |
---|
262 | |
---|
263 | UI.dialogs.addEvent.find('.calendar_addevent_details_lnk_timezone').click(function(e){ |
---|
264 | $(this).addClass('hidden'); |
---|
265 | $('.calendar-addevent-details-txt-timezone').removeClass('hidden'); |
---|
266 | |
---|
267 | e.preventDefault(); |
---|
268 | }); |
---|
269 | |
---|
270 | UI.dialogs.addEvent.find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
271 | if( $(this).parent().remove().find('li').is(':empty') ) { |
---|
272 | //alert('nao tem'); |
---|
273 | } |
---|
274 | }); |
---|
275 | |
---|
276 | /*Adicionar alarms padrões, quando alterado a agenda do usuário*/ |
---|
277 | UI.dialogs.addEvent.find('select[name="calendar"]').change(function(){ |
---|
278 | if((typeof($('input[name = "idEvent"]').val()) == 'undefined') || ($('input[name = "idEvent"]').val() == '')) { |
---|
279 | $('input[name = "isDefaultAlarm[]"]').parent().remove(); |
---|
280 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').parent().removeClass('hidden'); |
---|
281 | var calendarSelected = Calendar.signatureOf[$(this).val()]; |
---|
282 | calendarSelected.useAlarmDefault = 1; |
---|
283 | if(calendarSelected.defaultAlarms != ""){ |
---|
284 | var li_attach = DataLayer.render('templates/alarms_add_itemlist.ejs', {alarm:calendarSelected}); |
---|
285 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
286 | if( $(this).parent().remove().find('li').is(':empty') ) { |
---|
287 | //alert('nao tem'); |
---|
288 | } |
---|
289 | |
---|
290 | }); |
---|
291 | }else{ |
---|
292 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').parent().addClass('hidden'); |
---|
293 | } |
---|
294 | } |
---|
295 | }); |
---|
296 | |
---|
297 | /*Checkbox adicionar alarms padrões*/ |
---|
298 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').click(function(){ |
---|
299 | if($(this).attr("checked")){ |
---|
300 | $('input[name = "isDefaultAlarm[]"]').parent().remove(); |
---|
301 | var calendarSelected = Calendar.signatureOf[$('select[name="calendar"]').val()]; |
---|
302 | calendarSelected.useAlarmDefault = 1; |
---|
303 | if(calendarSelected.defaultAlarms != ""){ |
---|
304 | var li_attach = DataLayer.render('templates/alarms_add_itemlist.ejs', {alarm:calendarSelected}); |
---|
305 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
306 | if( $(this).parent().remove().find('li').is(':empty') ) { |
---|
307 | //alert('nao tem'); |
---|
308 | } |
---|
309 | |
---|
310 | }); |
---|
311 | } |
---|
312 | }else |
---|
313 | $('input[name = "isDefaultAlarm[]"]').parent().remove(); |
---|
314 | }); |
---|
315 | /* Checkbox allday */ |
---|
316 | UI.dialogs.addEvent.find('input[name="allDay"]').click(function(){ |
---|
317 | if($(this).attr("checked")) |
---|
318 | UI.dialogs.addEvent.find('.start-time, .end-time').addClass('hidden'); |
---|
319 | else |
---|
320 | UI.dialogs.addEvent.find('.start-time, .end-time').removeClass('hidden'); |
---|
321 | }); |
---|
322 | |
---|
323 | UI.dialogs.addEvent.find('.button').button(); |
---|
324 | UI.dialogs.addEvent.find('.button.add').button({ |
---|
325 | icons: { |
---|
326 | secondary: "ui-icon-plus" |
---|
327 | } |
---|
328 | }); |
---|
329 | |
---|
330 | // ==== validation events ==== |
---|
331 | $(".input-group .h1").Watermark("Evento sem título"); |
---|
332 | if(User.preferences.hourFormat.length == 5) |
---|
333 | $(".new-event-win.active .end-time, .new-event-win.active .start-time").mask("99:99"); |
---|
334 | else{ |
---|
335 | $.mask.definitions['{']='[ap]'; |
---|
336 | $.mask.definitions['}']='[m]'; |
---|
337 | $(".new-event-win.active .end-time, .new-event-win.active .start-time").mask("99:99 {}", |
---|
338 | {completed:function(){ |
---|
339 | $(this).val(defaultToAmPm($(this).val())); |
---|
340 | $(this).timepicker("refresh"); |
---|
341 | $(this).val($(this).val().replace(/[\.]/gi, "")); |
---|
342 | }}); |
---|
343 | } |
---|
344 | $(".number").numeric(); |
---|
345 | if(User.preferences.dateFormat.indexOf('-') > 0) |
---|
346 | $(".date").mask("99-99-9999"); |
---|
347 | else |
---|
348 | $(".date").mask("99/99/9999"); |
---|
349 | |
---|
350 | UI.dialogs.addEvent.find(".menu-addevent") |
---|
351 | |
---|
352 | .children(".delete").click(function(){ |
---|
353 | $.Zebra_Dialog('Tem certeza que deseja excluir o evento?', { |
---|
354 | 'type': 'question', |
---|
355 | 'overlay_opacity': '0.5', |
---|
356 | 'buttons': ['Sim', 'Não'], |
---|
357 | 'onClose': function(clicked) { |
---|
358 | if(clicked == 'Sim'){ |
---|
359 | DataLayer.remove( "schedulable", UI.dialogs.addEvent.find(".id-event").val() ); |
---|
360 | UI.dialogs.addEvent.dialog("close"); |
---|
361 | } |
---|
362 | } |
---|
363 | }); |
---|
364 | }).end() |
---|
365 | |
---|
366 | .children(".cancel").click(function(){ |
---|
367 | DataLayer.rollback('participant'); |
---|
368 | UI.dialogs.addEvent.dialog("close"); |
---|
369 | }).end() |
---|
370 | |
---|
371 | .children(".save").click(function(){ |
---|
372 | /* Validação */ |
---|
373 | |
---|
374 | var msg = false; |
---|
375 | if(msg = validDateEvent()){ |
---|
376 | $(".new-event-win.active").find('.messages-validation').removeClass('hidden').find('.message label').html(msg); |
---|
377 | return false; |
---|
378 | } |
---|
379 | |
---|
380 | canDiscardEventDialog = true; |
---|
381 | |
---|
382 | UI.dialogs.addEvent.children(".form-addevent").submit(); |
---|
383 | UI.dialogs.addEvent.dialog("close"); |
---|
384 | }).end() |
---|
385 | |
---|
386 | .children(".export").click(function(){ |
---|
387 | UI.dialogs.addEvent.children(".form-export").submit(); |
---|
388 | }); |
---|
389 | |
---|
390 | UI.dialogs.addEvent.find('input.date').datepicker({dateFormat: 'dd/mm/yy'}); |
---|
391 | UI.dialogs.addEvent.find('input.time').timepicker({ |
---|
392 | closeText: 'Ok', |
---|
393 | hourGrid: 4, |
---|
394 | minuteGrid: 10, |
---|
395 | ampm : ((User.preferences.hourFormat.length > 5) ? true: false), |
---|
396 | timeFormat: "hh:mm tt", |
---|
397 | onSelect: function (selectedDateTime){ |
---|
398 | if(!(User.preferences.hourFormat.length == 5)) |
---|
399 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
400 | }, |
---|
401 | onClose : function (selectedDateTime){ |
---|
402 | if(!(User.preferences.hourFormat.length == 5)) |
---|
403 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
404 | } |
---|
405 | }); |
---|
406 | |
---|
407 | UI.dialogs.addEvent.find('.button-add-alarms').click(function(){ |
---|
408 | var li_attach = DataLayer.render('templates/alarms_add_itemlist.ejs', {}); |
---|
409 | |
---|
410 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
411 | if( $(this).parent().remove().find('li').is(':empty') ) { |
---|
412 | //alert('nao tem'); |
---|
413 | } |
---|
414 | |
---|
415 | }); |
---|
416 | |
---|
417 | // valicacao de campos numericos |
---|
418 | $('.number').numeric(); |
---|
419 | }); |
---|
420 | |
---|
421 | UI.dialogs.addEvent.find('.button-add-attachment').click(function(){ |
---|
422 | var li_attach = |
---|
423 | '<li class="input_label">' + |
---|
424 | '<input type="file" name="attachments[]"" />' + |
---|
425 | '</li>'; |
---|
426 | jQuery('.attachments-list').append(li_attach); |
---|
427 | }); |
---|
428 | |
---|
429 | DataLayer.render( 'templates/attendee_add.ejs', {event:objEvent}, function( attendeeHtml ){ |
---|
430 | |
---|
431 | // load template of attendees |
---|
432 | var blkAddAtendee = UI.dialogs.addEvent.find('#calendar_addevent_details6').append(attendeeHtml); |
---|
433 | |
---|
434 | blkAddAtendee.find('li.attendee .button').addClass('small').button({text:false, icons: {primary:'ui-icon-close'}}).click(function () { |
---|
435 | var participant = DataLayer.get('participant', ['AND',['=', 'user', $(this).parent().find('[type=checkbox]').val().replace(/[a-z:]/g, "")],['=', 'schedulable', $(this).parents().find('.id-event').first().val()]]); |
---|
436 | if(participant) |
---|
437 | DataLayer.remove('participant', participant[0].id); |
---|
438 | $(this).parent().remove(); |
---|
439 | }); |
---|
440 | //show or hidden permissions attendees |
---|
441 | //blkAddAtendee.find('.block-attendee-list #attendees-users li').click(show_permissions_attendees); |
---|
442 | |
---|
443 | $(".attendee-list-add .add-attendee-input input").Watermark("digite um email para convidar"); |
---|
444 | /* Trata a edição de um novo participante adicionado |
---|
445 | * |
---|
446 | */ |
---|
447 | var hasNewAttendee = false; |
---|
448 | $('.attendee-list-add .add-attendee-input input').keydown(function(event) { |
---|
449 | |
---|
450 | if (event.keyCode == '13' && $(this).val() != '') { |
---|
451 | Encoder.EncodeType = "entity"; |
---|
452 | $(this).val(Encoder.htmlEncode($(this).val())); |
---|
453 | |
---|
454 | var newAttendeeEmail = false; |
---|
455 | var newAttendeeName = false; |
---|
456 | |
---|
457 | var info = $(this).val(); |
---|
458 | |
---|
459 | /** |
---|
460 | * email válido? |
---|
461 | */ |
---|
462 | info.match(/^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/) ? |
---|
463 | newAttendeeEmail = info : newAttendeeName = info; |
---|
464 | |
---|
465 | /** |
---|
466 | * 1) busca no banco para saber se o usuário já existe |
---|
467 | * 1.1) se existe, atualiza as info na lista de participantes e nao abre o tooltip |
---|
468 | * 1.2) se não existe |
---|
469 | * a) salva como novo usuario externo no banco (apenas com email) |
---|
470 | * b) exibe tooltip pedindo o nome |
---|
471 | * c) se o usuário preenche tooltip e salva, atualiza com o nome o usuário recém criado |
---|
472 | * d) se o usuário cancela o tooltip, fica o usuário salvo apenas com email e sem nome |
---|
473 | */ |
---|
474 | |
---|
475 | var user = DataLayer.get('user', ["=", "mail", $(this).val()], true); |
---|
476 | var isExternal = (user) ? user.isExternal : 1; |
---|
477 | |
---|
478 | /** |
---|
479 | * Remove tooltip possivelmente existente |
---|
480 | */ |
---|
481 | if (hasNewAttendee && blkAddAtendee.find('dd.attendee-list li:last').data('qtip')) |
---|
482 | blkAddAtendee.find('dd.attendee-list li:last').qtip('destroy'); |
---|
483 | |
---|
484 | var newAttendeeId = ''; |
---|
485 | |
---|
486 | if (user){ |
---|
487 | if(user[0].isExternal) |
---|
488 | newAttendeeId = 'external:'+user[0].id; |
---|
489 | else |
---|
490 | newAttendeeId = 'internal:'+user[0].id; |
---|
491 | |
---|
492 | blkAddAtendee.find('dd.attendee-list ul.attendee-list').append( |
---|
493 | DataLayer.render('templates/participants_add_itemlist.ejs', [{id:newAttendeeId, name: user[0].name, mail: user[0].mail}])) |
---|
494 | .find('.button.close').addClass('small').button({text:false, icons:{primary:'ui-icon-close'}}).click(function() { |
---|
495 | var participant = DataLayer.get('participant', ['AND',['=', 'user', $(this).parent().find('[type=checkbox]').val().replace(/[a-z:]/g, "")],['=', 'schedulable',$(this).parents().find('.id-event').first().val()]]); |
---|
496 | if(participant) |
---|
497 | DataLayer.remove('participant', participant[0].id); |
---|
498 | $(this).parent().remove(); |
---|
499 | }); |
---|
500 | $(this).val(''); |
---|
501 | |
---|
502 | } else { |
---|
503 | /** |
---|
504 | * a) salva como novo usuario externo no banco (apenas com email) e... |
---|
505 | * adiciona novo contato externo à lista de convidados |
---|
506 | */ |
---|
507 | |
---|
508 | newAttendeeId = DataLayer.put('user', {name: newAttendeeName, mail: newAttendeeEmail, isExternal: isExternal}); |
---|
509 | |
---|
510 | blkAddAtendee.find('dd.attendee-list ul.attendee-list').append( |
---|
511 | DataLayer.render('templates/participants_add_itemlist.ejs', [{id:newAttendeeId, name: newAttendeeName, mail: newAttendeeEmail}]) |
---|
512 | ).find('.button.close').addClass('small').button({text:false, icons:{primary:'ui-icon-close'}}).click(function() { |
---|
513 | var participant = DataLayer.get('participant', ['AND',['=', 'user', $(this).parent().find('[type=checkbox]').val().replace(/[a-z:]/g, "")],['=', 'schedulable', $(this).parents().find('.id-event').first().val()]]); |
---|
514 | if(participant) |
---|
515 | DataLayer.remove('participant', participant[0].id); |
---|
516 | $(this).parent().remove(); |
---|
517 | }); |
---|
518 | hasNewAttendee = true; |
---|
519 | |
---|
520 | |
---|
521 | /** |
---|
522 | * Adiciona tootip para atualização dos dados do contato externo |
---|
523 | * recém adicionado. |
---|
524 | */ |
---|
525 | blkAddAtendee.find('dd.attendee-list li:last').qtip({ |
---|
526 | show: {ready: true, solo: true, when: {event: 'click'}}, |
---|
527 | hide: false, |
---|
528 | content: { |
---|
529 | text: $('<div></div>').html( DataLayer.render( 'templates/attendee_quick_edit.ejs', {attendee:{name:newAttendeeName, mail:newAttendeeEmail}} ) ), |
---|
530 | title: { |
---|
531 | text:'Detalhes do participante', |
---|
532 | button: '<a class="button close" href="#">close</a>' |
---|
533 | } |
---|
534 | }, |
---|
535 | style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}}, |
---|
536 | position: { |
---|
537 | corner: { |
---|
538 | target: 'rightMiddle', |
---|
539 | tooltip: 'leftMiddle' |
---|
540 | }, |
---|
541 | adjust: {x:0, y:0} |
---|
542 | } |
---|
543 | }); |
---|
544 | |
---|
545 | var saveContact = function() { |
---|
546 | Encoder.EncodeType = "entity"; |
---|
547 | |
---|
548 | var currentTip = $('.qtip-active'); |
---|
549 | newAttendeeName = currentTip.find('input[name="name"]').val(); |
---|
550 | newAttendeeEmail = currentTip.find('input[name="mail"]').val(); |
---|
551 | |
---|
552 | var isValidMail = newAttendeeEmail.match(/^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/); |
---|
553 | if (!isValidMail) { |
---|
554 | currentTip.find('.messages').removeClass('hidden').find('.message label').append('Email inválido.'); |
---|
555 | return false; |
---|
556 | } |
---|
557 | |
---|
558 | DataLayer.put('user', {id:newAttendeeId, name:newAttendeeName, mail:newAttendeeEmail, isExternal:isExternal}); |
---|
559 | |
---|
560 | $('dd.attendee-list ul.attendee-list li:last label') |
---|
561 | .filter('.name').html(Encoder.htmlEncode(newAttendeeName)).attr('title', Encoder.htmlEncode(newAttendeeName)).end() |
---|
562 | .filter('.mail').html(Encoder.htmlEncode(newAttendeeEmail)).attr('title', Encoder.htmlEncode(newAttendeeEmail)); |
---|
563 | |
---|
564 | return true; |
---|
565 | } |
---|
566 | |
---|
567 | $('dd.attendee-list li:last').qtip("api").onShow = function(arg0) { |
---|
568 | |
---|
569 | $('.qtip-active .button.close').button({ |
---|
570 | icons: {primary: "ui-icon-close"}, |
---|
571 | text: false |
---|
572 | }); |
---|
573 | $('.qtip-active .button').button() |
---|
574 | .filter('.save').click(function(event, ui) { |
---|
575 | if (saveContact()) { |
---|
576 | $('dd.attendee-list li:last').qtip("destroy"); |
---|
577 | } else { |
---|
578 | return false; |
---|
579 | } |
---|
580 | }).end() |
---|
581 | .filter('.cancel').click(function(event, ui) { |
---|
582 | |
---|
583 | $('dd.attendee-list li:last').qtip("destroy"); |
---|
584 | }) |
---|
585 | |
---|
586 | /** |
---|
587 | * Trata o ENTER no campo da tooltip, equivalente a salvar |
---|
588 | * o novo convidado. |
---|
589 | */ |
---|
590 | $('.qtip-active input').keydown(function(event) { |
---|
591 | if (event.keyCode == '13') { |
---|
592 | if (saveContact()) { |
---|
593 | $('dd.attendee-list li:last').qtip("destroy"); |
---|
594 | } |
---|
595 | |
---|
596 | $('dd.attendee-list li:last').qtip("destroy"); |
---|
597 | event.preventDefault(); |
---|
598 | } |
---|
599 | }) |
---|
600 | .filter('[name="name"]').Watermark("informe o nome do contato").end() |
---|
601 | .filter('[name="mail"]').Watermark("informe o email do contato"); |
---|
602 | } |
---|
603 | |
---|
604 | |
---|
605 | $(this).val(''); |
---|
606 | |
---|
607 | event.preventDefault(); |
---|
608 | } |
---|
609 | } |
---|
610 | }); |
---|
611 | |
---|
612 | /** |
---|
613 | * Trata a busca de usuários para adição de participantes |
---|
614 | */ |
---|
615 | blkAddAtendee.find('.add-attendee-search input').keydown(function(event) { |
---|
616 | |
---|
617 | if(event.keyCode == '13') { |
---|
618 | Encoder.EncodeType = "entity"; |
---|
619 | $(this).val(Encoder.htmlEncode($(this).val())); |
---|
620 | |
---|
621 | var result = DataLayer.get('user', ["*", "name", $(this).val()], true); |
---|
622 | |
---|
623 | /** |
---|
624 | * TODO: trocar por template |
---|
625 | */ |
---|
626 | $('ul.search-result-list').empty().css('overflow', 'hidden'); |
---|
627 | if (!result) { |
---|
628 | $('ul.search-result-list').append('<li><label class="empty">Nenhum resultado encontrado.</label></li>'); |
---|
629 | } |
---|
630 | |
---|
631 | $('ul.search-result-list').append(DataLayer.render( 'templates/participants_search_itemlist.ejs', result)); |
---|
632 | |
---|
633 | $('ul.search-result-list li').click(function(event, ui){ |
---|
634 | if ($(event.target).is('input')) { |
---|
635 | old_item = $(event.target).parents('li'); |
---|
636 | blkAddAtendee.find('dd.attendee-list ul.attendee-list') |
---|
637 | .append(DataLayer.render('templates/participants_add_itemlist.ejs', [{id: 'internal:'+old_item.find('.id').text(), name: old_item.find('.name').html()}])) |
---|
638 | .find('.button').addClass('small').button({text:false, icons: {primary:'ui-icon-close'}}).click(function () { |
---|
639 | $(this).parent().remove(); |
---|
640 | }); |
---|
641 | |
---|
642 | old_item.remove(); |
---|
643 | } |
---|
644 | }); |
---|
645 | |
---|
646 | event.preventDefault(); |
---|
647 | } |
---|
648 | }); |
---|
649 | |
---|
650 | |
---|
651 | UI.dialogs.addEvent.find('.attendees-list li').hover( |
---|
652 | function () { |
---|
653 | $(this).addClass("hover"); |
---|
654 | }, |
---|
655 | function () { |
---|
656 | $(this).removeClass("hover"); |
---|
657 | } |
---|
658 | ); |
---|
659 | |
---|
660 | //$('.block-add-attendee .search-result-list').selectable(); |
---|
661 | |
---|
662 | UI.dialogs.addEvent.find('.block-attendee-list select.status').change(function(){ |
---|
663 | if ($(this).val() == 'another') { |
---|
664 | // jQuery('.block-attendee-list .add-attendee-search').removeClass('hidden'); |
---|
665 | $(this).qtip({ |
---|
666 | show: {ready: true}, |
---|
667 | hide: false, |
---|
668 | content: { |
---|
669 | text: $('.block-attendee-list .add-attendee-search').clone().removeClass('hidden'), |
---|
670 | title: { |
---|
671 | text:'Indique o participante', |
---|
672 | button: '<a class="button close" href="#">close</a>' |
---|
673 | } |
---|
674 | }, |
---|
675 | style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 250, max:250}}, |
---|
676 | position: { |
---|
677 | corner: { |
---|
678 | target: 'rightMiddle', |
---|
679 | tooltip: 'leftMiddle' |
---|
680 | }, |
---|
681 | adjust: {x:0, y:0} |
---|
682 | } |
---|
683 | }) |
---|
684 | $(this).qtip.onShow = function() { |
---|
685 | $('.qtip .button.close').button({ |
---|
686 | icons: {primary: "ui-icon-close"}, |
---|
687 | text: false |
---|
688 | }); |
---|
689 | } |
---|
690 | } else { |
---|
691 | // jQuery('.block-attendee-list .add-attendee-search').addClass('hidden'); |
---|
692 | } |
---|
693 | }); |
---|
694 | }); |
---|
695 | UI.dialogs.addEvent.dialog('open'); |
---|
696 | }); |
---|
697 | |
---|
698 | |
---|
699 | } |
---|
700 | |
---|
701 | function add_tab_preferences() |
---|
702 | { |
---|
703 | if(!(document.getElementById('preference_tab'))) |
---|
704 | { |
---|
705 | var tab_title = "Preferencias"; |
---|
706 | $tabs.tabs( "add", "#preference_tab", tab_title ); |
---|
707 | |
---|
708 | /* |
---|
709 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
710 | tabPrefCalendar.find('select[name="timezone"]').html(timezones_options).find('option[value="'+User.preferences.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
711 | }); |
---|
712 | */ |
---|
713 | DataLayer.render( 'templates/preferences_calendar.ejs', {preferences:User.preferences, calendars: Calendar.calendars}, function( template ){ |
---|
714 | var tabPrefCalendar = jQuery('#preference_tab').html( template ).find('.preferences-win'); |
---|
715 | |
---|
716 | tabPrefCalendar.find('option[value="'+User.preferences.defaultCalendar+'"]').attr('selected','selected').trigger('change'); |
---|
717 | |
---|
718 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
719 | tabPrefCalendar.find('select[name="timezone"]').html(timezones_options).find('option[value="'+User.preferences.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
720 | }); |
---|
721 | |
---|
722 | tabPrefCalendar.find('.button').button() |
---|
723 | .filter('.save').click(function(evt){ |
---|
724 | tabPrefCalendar.find('form').submit(); |
---|
725 | $('#calendar').fullCalendar('render'); |
---|
726 | $('.block-vertical-toolbox .mini-calendar').datepicker( "refresh" ); |
---|
727 | $tabs.tabs( "remove", "#preference_tab"); |
---|
728 | }).end().filter('.cancel').click(function(evt){ |
---|
729 | $tabs.tabs( "remove", "#preference_tab"); |
---|
730 | }); |
---|
731 | |
---|
732 | tabPrefCalendar.find('.number').numeric(); |
---|
733 | }); |
---|
734 | } else { |
---|
735 | $tabs.tabs("select", "#preference_tab"); |
---|
736 | |
---|
737 | return true; |
---|
738 | } |
---|
739 | } |
---|
740 | |
---|
741 | |
---|
742 | function add_tab_configure_calendar(calendar) |
---|
743 | { |
---|
744 | var calendars = []; |
---|
745 | var signatures = []; |
---|
746 | var previewActiveCalendarConf = 0; |
---|
747 | |
---|
748 | for (var i=0; i<Calendar.signatures.length; i++) { |
---|
749 | calendars[i] = Calendar.signatures[i].calendar; |
---|
750 | signatures[i] = Calendar.signatures[i]; |
---|
751 | signatures[i].numberDefaultAlarm = signatures[i].defaultAlarms != '' ? signatures[i].defaultAlarms.length: 0; |
---|
752 | if (calendar && calendars[i].id == calendar) |
---|
753 | previewActiveCalendarConf = i; |
---|
754 | } |
---|
755 | |
---|
756 | if(!(document.getElementById('configure_tab'))) |
---|
757 | { |
---|
758 | $('.positionHelper').css('display', 'none'); |
---|
759 | var tab_title = "Configurações de agendas"; |
---|
760 | $tabs.tabs( "add", "#configure_tab", tab_title ); |
---|
761 | |
---|
762 | var dataColorPicker = { |
---|
763 | colorsSuggestions: colors_suggestions() |
---|
764 | }; |
---|
765 | |
---|
766 | |
---|
767 | |
---|
768 | var populateAccordionOnActive = function(event, ui) { |
---|
769 | var nowActive = (typeof(event) == 'number') ? event : $(event.target).accordion( "option", "active" ); |
---|
770 | dataColorPicker.colorsDefined = { |
---|
771 | border: '#'+signatures[nowActive].borderColor, |
---|
772 | font:'#'+signatures[nowActive].fontColor, |
---|
773 | background:'#'+signatures[nowActive].backgroundColor |
---|
774 | }; |
---|
775 | if (!jQuery('.accordion-user-calendars .ui-accordion-content').eq(nowActive).has('form')) { |
---|
776 | return true; |
---|
777 | } |
---|
778 | |
---|
779 | DataLayer.render( 'templates/configure_calendars_itemlist.ejs', {user:User, calendar:calendars[nowActive], signature:signatures[nowActive]}, function( form_template ){ |
---|
780 | var form_content = jQuery('.accordion-user-calendars .ui-accordion-content').eq(nowActive).html( form_template ).find('form'); |
---|
781 | form_content.find('.preferences-alarms-list .button').button({text:false, icons:{primary:'ui-icon-close'}}); |
---|
782 | form_content.find('.button').button(); |
---|
783 | |
---|
784 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
785 | var valueTimeZone = calendars[nowActive].timezone; |
---|
786 | form_content.find('select[name="timezone"]').html(timezones_options).find('option[value="'+valueTimeZone+'"]').attr('selected','selected').trigger('change'); |
---|
787 | }); |
---|
788 | |
---|
789 | form_content.find('.button-add-alarms').click(function(){ |
---|
790 | DataLayer.render( 'templates/alarms_add_itemlist.ejs', {}, function( template ){ |
---|
791 | jQuery('.preferences-alarms-list').append(template) |
---|
792 | .find('li:last label:eq(0)').remove().end() |
---|
793 | .find('.number').numeric().end() |
---|
794 | .find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
795 | $(this).parent().remove(); |
---|
796 | }); |
---|
797 | }); |
---|
798 | }); |
---|
799 | |
---|
800 | |
---|
801 | /** |
---|
802 | * Set color picker |
---|
803 | */ |
---|
804 | DataLayer.render( 'templates/calendar_colorpicker.ejs', dataColorPicker, function( template ){ |
---|
805 | form_content.find('.calendar-colorpicker').html( template ); |
---|
806 | |
---|
807 | var f = $.farbtastic(form_content.find('.colorpicker'), colorpickerPreviewChange); |
---|
808 | var selected; |
---|
809 | var colorpicker = form_content.find('.calendar-colorpicker'); |
---|
810 | |
---|
811 | var colorpickerPreviewChange = function(color) { |
---|
812 | var pickedup = form_content.find('.colorwell-selected').val(color).css('background-color', color); |
---|
813 | |
---|
814 | var colorpicker = form_content.find('.calendar-colorpicker'); |
---|
815 | |
---|
816 | if (pickedup.is('input[name="backgroundColor"]')) { |
---|
817 | colorpicker.find('.fc-event-skin').css('background-color',color); |
---|
818 | } else if (pickedup.is('input[name="fontColor"]')) { |
---|
819 | colorpicker.find('.fc-event-skin').css('color',color); |
---|
820 | } else if (pickedup.is('input[name="borderColor"]')) { |
---|
821 | colorpicker.find('.fc-event-skin').css('border-color',color); |
---|
822 | } |
---|
823 | } |
---|
824 | |
---|
825 | form_content.find('.colorwell').each(function () { |
---|
826 | f.linkTo(this); |
---|
827 | |
---|
828 | if ($(this).is('input[name="backgroundColor"]')) { |
---|
829 | colorpicker.find('.fc-event-skin').css('background-color', $(this).val()); |
---|
830 | } else if ($(this).is('input[name="fontColor"]')) { |
---|
831 | colorpicker.find('.fc-event-skin').css('color', $(this).val()); |
---|
832 | } else if ($(this).is('input[name="borderColor"]')) { |
---|
833 | colorpicker.find('.fc-event-skin').css('border-color', $(this).val()); |
---|
834 | } |
---|
835 | }) |
---|
836 | .focus(function() { |
---|
837 | if (selected) { |
---|
838 | $(selected).removeClass('colorwell-selected'); |
---|
839 | } |
---|
840 | |
---|
841 | $(selected = this).addClass('colorwell-selected'); |
---|
842 | f.linkTo(this, colorpickerPreviewChange); |
---|
843 | f.linkTo(colorpickerPreviewChange); |
---|
844 | |
---|
845 | }); |
---|
846 | |
---|
847 | form_content.find('select.color-suggestions').change(function() { |
---|
848 | var colors; |
---|
849 | |
---|
850 | if(colors = dataColorPicker.colorsSuggestions[$(this).val()]) { |
---|
851 | colorpicker |
---|
852 | .find('input[name="fontColor"]').val(colors.font).focus().end() |
---|
853 | .find('input[name="backgroundColor"]').val(colors.background).focus().end() |
---|
854 | .find('input[name="borderColor"]').val(colors.border).focus().end() |
---|
855 | |
---|
856 | .find('.fc-event-skin').css({ |
---|
857 | 'background-color':dataColorPicker.colorsSuggestions[$(this).val()].background, |
---|
858 | 'border-color':dataColorPicker.colorsSuggestions[$(this).val()].border, |
---|
859 | 'color':dataColorPicker.colorsSuggestions[$(this).val()].font |
---|
860 | }); |
---|
861 | } |
---|
862 | }); |
---|
863 | |
---|
864 | /** |
---|
865 | * Trata a mudança dos valores dos campos de cores. |
---|
866 | * Se mudar um conjunto de cores sugerido, |
---|
867 | * este vira um conjunto de cores personalizado. |
---|
868 | */ |
---|
869 | form_content.find('.colorwell').change(function (element, ui) { |
---|
870 | if (true) { |
---|
871 | form_content.find('select.color-suggestions') |
---|
872 | .find('option:selected').removeAttr('selected').end() |
---|
873 | .find('option[value="custom"]').attr('selected', 'selected').trigger('change'); |
---|
874 | } |
---|
875 | }); |
---|
876 | }); //END set colorpicker |
---|
877 | |
---|
878 | form_content.find('.phone').mask("+99 (99) 9999-9999"); |
---|
879 | form_content.find('.number').numeric(); |
---|
880 | |
---|
881 | }); //END DataLayer.render( 'templates/configure_calendars_itemlist.ejs' ... |
---|
882 | |
---|
883 | // === validations preferences ==== |
---|
884 | |
---|
885 | |
---|
886 | } //END populateAccordionOnActive(event, ui) |
---|
887 | |
---|
888 | |
---|
889 | DataLayer.render( 'templates/configure_calendars.ejs', {user:User, calendars:calendars, signatures:signatures}, function( template ){ |
---|
890 | var template_content = jQuery('#configure_tab').html( template ).find('.configure-calendars-win'); |
---|
891 | template_content.find('.button').button().filter('.save').click(function(evt){ |
---|
892 | template_content.find('form').submit(); |
---|
893 | $tabs.tabs( "remove", "#configure_tab"); |
---|
894 | }).end().filter('.cancel').click(function(evt){ |
---|
895 | $tabs.tabs( "remove", "#configure_tab"); |
---|
896 | }); |
---|
897 | |
---|
898 | /** |
---|
899 | * Muda a estrutura do template para a aplicação do plugin accordion |
---|
900 | */ |
---|
901 | template_content.find('.header-menu-container').after('<div class="accordion-user-calendars"></div>').end().find('.accordion-user-calendars') |
---|
902 | .append(template_content.children('fieldset')); |
---|
903 | |
---|
904 | template_content.find('.accordion-user-calendars').children('fieldset').each(function(index) { |
---|
905 | $(this).before($('<h3></h3>').html($(this).children('legend'))); |
---|
906 | }); |
---|
907 | |
---|
908 | template_content.find('.accordion-user-calendars').accordion({ |
---|
909 | autoHeight: false, |
---|
910 | collapsible: true, |
---|
911 | clearStyle: true, |
---|
912 | active: previewActiveCalendarConf, |
---|
913 | changestart: populateAccordionOnActive |
---|
914 | }); |
---|
915 | populateAccordionOnActive(previewActiveCalendarConf); |
---|
916 | }); |
---|
917 | |
---|
918 | } else { |
---|
919 | |
---|
920 | $tabs.tabs("select", "#configure_tab"); |
---|
921 | $('.accordion-user-calendars').accordion( "activate" , previewActiveCalendarConf ); |
---|
922 | |
---|
923 | return true; |
---|
924 | } |
---|
925 | |
---|
926 | } |
---|
927 | |
---|
928 | function getNotSelectedCalendars(){ |
---|
929 | var selecteds = {}; |
---|
930 | var cont = 0; |
---|
931 | jQuery(function() { |
---|
932 | jQuery(".my-calendars .calendar-view").each(function(i, obj) { |
---|
933 | var check_box = obj; |
---|
934 | if(!check_box.checked) { |
---|
935 | selecteds[cont] = obj.value; |
---|
936 | cont++; |
---|
937 | }; |
---|
938 | }); |
---|
939 | }); |
---|
940 | if (!cont) |
---|
941 | return false; |
---|
942 | |
---|
943 | selecteds.length = cont; |
---|
944 | return $.makeArray( selecteds ); |
---|
945 | } |
---|
946 | |
---|
947 | function getSelectedCalendars(){ |
---|
948 | var selecteds = {}; |
---|
949 | var cont = 0; |
---|
950 | jQuery(function() { |
---|
951 | jQuery(".my-calendars .calendar-view").each(function(i, obj) { |
---|
952 | var check_box = obj; |
---|
953 | if(check_box.checked) { |
---|
954 | selecteds[cont] = obj.value; |
---|
955 | cont++; |
---|
956 | }; |
---|
957 | }); |
---|
958 | }); |
---|
959 | if (!cont) |
---|
960 | return false; |
---|
961 | |
---|
962 | selecteds.length = cont; |
---|
963 | return $.makeArray( selecteds ); |
---|
964 | } |
---|
965 | |
---|
966 | /** |
---|
967 | * TODO - transformar em preferência do módulo e criar telas de adição e exclusão de conjunto de cores |
---|
968 | */ |
---|
969 | function colors_suggestions(){ |
---|
970 | return [ |
---|
971 | {name:'Padrão', border:'#3366cc', font:'#ffffff', background:'#3366cc'}, |
---|
972 | {name:'Coala', border:'#123456', font:'#ffffff', background:'#385c80'}, |
---|
973 | {name:'Tomate', border:'#d5130b', font:'#111111', background:'#e36d76'}, |
---|
974 | {name:'Limão', border:'#32ed21', font:'#1f3f1c', background:'#b2f1ac'}, |
---|
975 | {name:'Alto contraste', border:'#000000', font:'#ffffff', background:'#222222'} |
---|
976 | ] |
---|
977 | } |
---|
978 | |
---|
979 | function remove_calendar(){ |
---|
980 | /* Pode ser assim $('.cal-list-options-btn.ui-state-active').attr('class').replace(/[a-zA-Z-]+/g, ''); */ |
---|
981 | $.Zebra_Dialog('Todos os eventos desta agenda serão apagados. Deseja prosseguir com a operação ?', { |
---|
982 | 'type': 'question', |
---|
983 | 'overlay_opacity': '0.5', |
---|
984 | 'buttons': ['Sim', 'Não'], |
---|
985 | 'onClose': function(clicked) { |
---|
986 | if(clicked == 'Sim'){ |
---|
987 | var idCalendar = $('.cal-list-options-btn.ui-state-active').attr('class').match(/[0-9]+/g); |
---|
988 | var signature = ''; |
---|
989 | for(var i =0; i < Calendar.signatures.length; i++){ |
---|
990 | if(idCalendar[0] == Calendar.signatures[i].calendar.id){ |
---|
991 | signature = Calendar.signatures[i].id; |
---|
992 | break; |
---|
993 | } |
---|
994 | } |
---|
995 | DataLayer.remove('calendarSignature', signature); |
---|
996 | $('.positionHelper').css('display', 'none'); |
---|
997 | }else{ |
---|
998 | $('.positionHelper').css('display', 'none'); |
---|
999 | } |
---|
1000 | } |
---|
1001 | }); |
---|
1002 | } |
---|
1003 | |
---|
1004 | function refresh_calendars(){ |
---|
1005 | |
---|
1006 | var colorsSuggestions = colors_suggestions(); |
---|
1007 | var buttons_colors = ""; |
---|
1008 | for(var i = 0; i < colorsSuggestions.length; i++){ |
---|
1009 | buttons_colors += "<a class=\"cal-colors-options-btn ui-icon ui-button-icon-primary signed-cal-colors-options-btn-"+i+"\" style=\"background-color:"+colorsSuggestions[i]['background']+"; border-color:"+colorsSuggestions[i]['border']+"; color:"+colorsSuggestions[i]['font']+"\">•</a>"; |
---|
1010 | } |
---|
1011 | |
---|
1012 | //DataLayer.render( 'templates/calendar_list.ejs', 'calendar:list', ["IN", "id", Calendar.calendarIds], function( html ){ |
---|
1013 | DataLayer.render( 'templates/calendar_list.ejs', Calendar, function( html ){ |
---|
1014 | |
---|
1015 | var meu_container = $(".calendars-list").html( html ); |
---|
1016 | |
---|
1017 | $('ul.list-calendars .cal-list-options-btn').each(function(){ |
---|
1018 | $(this).menu({ |
---|
1019 | content: $(this).next().html(), |
---|
1020 | width: '120', |
---|
1021 | positionOpts: { |
---|
1022 | posX: 'left', |
---|
1023 | posY: 'bottom', |
---|
1024 | offsetX: 0, |
---|
1025 | offsetY: 0, |
---|
1026 | directionH: 'right', |
---|
1027 | directionV: 'down', |
---|
1028 | detectH: true, // do horizontal collision detection |
---|
1029 | detectV: true, // do vertical collision detection |
---|
1030 | linkToFront: false |
---|
1031 | }, |
---|
1032 | flyOut: true, |
---|
1033 | showSpeed: 100, |
---|
1034 | crumbDefaultText: '>' |
---|
1035 | }); |
---|
1036 | }); |
---|
1037 | |
---|
1038 | |
---|
1039 | meu_container.find(".button.new").button({ |
---|
1040 | icons: { |
---|
1041 | primary: "ui-icon-plus" |
---|
1042 | }, |
---|
1043 | text: false |
---|
1044 | }).click(function () { |
---|
1045 | |
---|
1046 | if( $('.qtip.qtip-blue.qtip-active').val() !== ''){ |
---|
1047 | $(this).qtip({ |
---|
1048 | show: {ready: true, solo: true, when: {event: 'click'}}, |
---|
1049 | hide: false, |
---|
1050 | content: { |
---|
1051 | text: $('<div></div>').html( DataLayer.render( 'templates/calendar_quick_add.ejs', {} ) ), |
---|
1052 | title: { |
---|
1053 | text:'Nova Agenda', |
---|
1054 | button: '<a class="button close" href="#">close</a>' |
---|
1055 | } |
---|
1056 | }, |
---|
1057 | style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}}, |
---|
1058 | position: { |
---|
1059 | corner: { |
---|
1060 | target: 'rightMiddle', |
---|
1061 | tooltip: 'leftMiddle' |
---|
1062 | }, |
---|
1063 | adjust: {x:0, y:-12} |
---|
1064 | } |
---|
1065 | }) |
---|
1066 | .qtip("api").onShow = function(arg0) { |
---|
1067 | $('.qtip-active .button.close').button({ |
---|
1068 | icons: {primary: "ui-icon-close"}, |
---|
1069 | text: false |
---|
1070 | }) |
---|
1071 | .click(function(){ |
---|
1072 | meu_container.find(".button.new").qtip('destroy'); |
---|
1073 | }); |
---|
1074 | //TODO emplementar tratamento de duplicação de valores no location |
---|
1075 | $('.qtip-active .button.save').button().click(function(){ |
---|
1076 | for(var i = 0; i < Calendar.calendars.length; i++){ |
---|
1077 | if(Calendar.calendars[i].location == $('.qtip-active input').val()){ |
---|
1078 | $.Zebra_Dialog('O nome desta agenda já está sendo utilizada em uma Url de outra agenda. Por favor, informe outro nome para agenda.',{ |
---|
1079 | 'overlay_opacity': '0.5', |
---|
1080 | 'type': 'warning' |
---|
1081 | }); |
---|
1082 | meu_container.find(".button.new").qtip('destroy'); |
---|
1083 | return; |
---|
1084 | } |
---|
1085 | } |
---|
1086 | |
---|
1087 | var selected; |
---|
1088 | var color = $('.cal-colors-options-btn').each(function(index){ |
---|
1089 | if ($(this).is('.color-selected')) |
---|
1090 | selected = index; |
---|
1091 | }); |
---|
1092 | DataLayer.put( "calendarSignature", { |
---|
1093 | user: User.me.id, |
---|
1094 | calendar: { |
---|
1095 | name: $('.qtip-active input').val(), |
---|
1096 | timezone: User.preferences.timezone |
---|
1097 | }, |
---|
1098 | isOwner: 1, |
---|
1099 | fontColor: colorsSuggestions[selected]['font'].substring(1) , |
---|
1100 | backgroundColor: colorsSuggestions[selected]['background'].substring(1) , |
---|
1101 | borderColor: colorsSuggestions[selected]['border'].substring(1) |
---|
1102 | }); |
---|
1103 | meu_container.find(".button.new").qtip('destroy'); |
---|
1104 | }); |
---|
1105 | |
---|
1106 | $('.qtip-active .button.cancel').button().click(function(){ |
---|
1107 | meu_container.find(".button.new").qtip('destroy'); |
---|
1108 | }); |
---|
1109 | |
---|
1110 | $(".qtip-active input").Watermark("Nome da agenda"); |
---|
1111 | |
---|
1112 | $('.qtip-active').keydown(function(event) { |
---|
1113 | if (event.keyCode == '27') { |
---|
1114 | meu_container.find(".button.new").qtip('destroy'); |
---|
1115 | } |
---|
1116 | }); |
---|
1117 | |
---|
1118 | $('.colors-options').prepend(buttons_colors); |
---|
1119 | $('.colors-options .signed-cal-colors-options-btn-0').addClass('color-selected'); |
---|
1120 | |
---|
1121 | var buttons = $('.cal-colors-options-btn').button(); |
---|
1122 | |
---|
1123 | buttons.click(function(){ |
---|
1124 | buttons.removeClass('color-selected'); |
---|
1125 | $(this).addClass('color-selected'); |
---|
1126 | }); |
---|
1127 | } |
---|
1128 | } |
---|
1129 | }); |
---|
1130 | |
---|
1131 | $("img.cal-list-img").click(function(evt) { |
---|
1132 | $(".cal-list-options_1").toggleClass( "hidden" ); |
---|
1133 | }); |
---|
1134 | |
---|
1135 | $(".my-calendars a.title-my-calendars").click(function() { |
---|
1136 | $(".my-calendars ul.my-list-calendars").toggleClass("hidden") |
---|
1137 | $('.my-calendars .status-list').toggleClass("ui-icon-triangle-1-s"); |
---|
1138 | $('.my-calendars .status-list').toggleClass("ui-icon-triangle-1-e"); |
---|
1139 | }); |
---|
1140 | |
---|
1141 | $(".signed-calendars a.title-signed-calendars").click(function() { |
---|
1142 | $(".signed-calendars ul.signed-list-calendars").toggleClass( "hidden"); |
---|
1143 | }); |
---|
1144 | |
---|
1145 | $("ul li.list-calendars-item").click(function(evt) { |
---|
1146 | |
---|
1147 | }); |
---|
1148 | |
---|
1149 | $("ul li.list-calendars-item .ui-corner-all").click(function(evt) { |
---|
1150 | //alert('teste'); |
---|
1151 | }); |
---|
1152 | |
---|
1153 | $('.calendar-view').click(function(evt){ |
---|
1154 | if($tabs.tabs('option' ,'selected') == 1){ |
---|
1155 | pageselectCallback('', 0); |
---|
1156 | } |
---|
1157 | |
---|
1158 | if(Calendar.currentView){ |
---|
1159 | var checkBox = $(this); |
---|
1160 | Calendar.currentView[ checkBox.val() ].hidden = !checkBox.is(':checked'); |
---|
1161 | $('#calendar').fullCalendar( 'refetchEvents' ); |
---|
1162 | } |
---|
1163 | }); |
---|
1164 | }); |
---|
1165 | } |
---|
1166 | |
---|
1167 | function add_events_list(keyword) |
---|
1168 | { |
---|
1169 | var tab_title = ""; |
---|
1170 | if (keyword){ |
---|
1171 | if(keyword.length < 10) |
---|
1172 | tab_title = keyword; |
---|
1173 | else |
---|
1174 | tab_title = keyword.substr(0,10) + '..."'; |
---|
1175 | }else{ |
---|
1176 | tab_title = "Lista de eventos"; |
---|
1177 | } |
---|
1178 | keyword = ( keyword || '' ).replace( /\s+/g, "_" ); |
---|
1179 | |
---|
1180 | if(!(document.getElementById('tab_events_list_' + (Base64.encode(keyword)).replace(/[^\w\s]/gi, "") ))) |
---|
1181 | { |
---|
1182 | Encoder.EncodeType = "entity"; |
---|
1183 | $tabs.tabs( "add", "#tab_events_list_" + (Base64.encode(keyword)).replace(/[^\w\s]/gi, ""), Encoder.htmlEncode(tab_title) ); |
---|
1184 | } |
---|
1185 | else /* Tab already opened */ |
---|
1186 | { |
---|
1187 | $tabs.tabs("option", "selected", 2); |
---|
1188 | } |
---|
1189 | |
---|
1190 | pageselectCallback(keyword, 0); // load page 1 and insert data on event_list.ejs |
---|
1191 | |
---|
1192 | $('.preferences-win.active .button.save, .preferences-win.active .button.cancel, .preferences-win.active .button.import, .preferences-win.active .button.export').button(); |
---|
1193 | } |
---|
1194 | |
---|
1195 | function paginatorSearch(currentView){ |
---|
1196 | if(parseInt($(currentView+' [name = results]').val()) > 25){ |
---|
1197 | $(currentView+' .header-paginator .fc-header-left .fc-button.fc-button-next .fc-button-inner').hover( |
---|
1198 | function(){ |
---|
1199 | $(this).addClass('fc-state-hover'); |
---|
1200 | }, |
---|
1201 | function(){ |
---|
1202 | $(this).removeClass('fc-state-hover'); |
---|
1203 | }).mousedown(function(){ |
---|
1204 | $(this).addClass('fc-state-down'); |
---|
1205 | }).mouseup(function(){ |
---|
1206 | $(this).removeClass('fc-state-down'); |
---|
1207 | $('.events-list.events-list-win.active').removeClass('active'); |
---|
1208 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($('[name = page_index]').val())) +1)); |
---|
1209 | }); |
---|
1210 | } |
---|
1211 | if(parseInt($(currentView+' [name = page_index]').val()) > 0){ |
---|
1212 | $(currentView+' .header-paginator .fc-header-left .fc-button.fc-button-prev .fc-button-inner').hover( |
---|
1213 | function(){ |
---|
1214 | $(this).addClass('fc-state-hover'); |
---|
1215 | }, |
---|
1216 | function(){ |
---|
1217 | $(this).removeClass('fc-state-hover'); |
---|
1218 | }).mousedown(function(){ |
---|
1219 | $(this).addClass('fc-state-down'); |
---|
1220 | }).mouseup(function(){ |
---|
1221 | $(this).removeClass('fc-state-down'); |
---|
1222 | $('.events-list.events-list-win.active').removeClass('active'); |
---|
1223 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($('[name = page_index]').val())) -1)); |
---|
1224 | }); |
---|
1225 | } |
---|
1226 | } |
---|
1227 | |
---|
1228 | function mountTitleList(page_index ,view){ |
---|
1229 | switch (view){ |
---|
1230 | case 'day': |
---|
1231 | var date = new Date().add({days: page_index}); |
---|
1232 | return (weekOfDay(date.getDay()))+", "+(date.toString('dd MMM yyyy')); |
---|
1233 | case 'week': |
---|
1234 | var dateStart = new Date().moveToDayOfWeek(dayOfWeek(User.preferences.weekDefault)); |
---|
1235 | dateStart.add({days: (7 * page_index)}); |
---|
1236 | var dateEnd = new Date().moveToDayOfWeek(dayOfWeek(User.preferences.weekDefault)); |
---|
1237 | dateEnd.add({days: (page_index * 7)+7}); |
---|
1238 | if(dateStart.toString('MM') != dateEnd.toString('MM')) |
---|
1239 | return dateStart.toString('dd')+' de '+sortMonthOfNumber(dateStart.getMonth())+' a '+dateEnd.toString('dd')+' de '+monthOfNumber(dateEnd.getMonth())+' - '+dateEnd.toString('yyyy'); |
---|
1240 | return +dateStart.toString("dd")+" a "+dateEnd.toString("dd")+" de "+monthOfNumber(dateEnd.getMonth())+" - "+dateEnd.toString('yyyy'); |
---|
1241 | case 'month': |
---|
1242 | var date = new Date().add({months: page_index}) |
---|
1243 | return monthOfNumber(date.getMonth())+" "+date.toString("yyyy"); |
---|
1244 | case 'year': |
---|
1245 | var date = new Date().add({years: page_index}); |
---|
1246 | return date.toString("yyyy"); |
---|
1247 | } |
---|
1248 | } |
---|
1249 | |
---|
1250 | function paginatorList(currentView, view){ |
---|
1251 | $(currentView+' .events-list.events-list-win.active .list-events-paginator .fc-header-title').html('<h2>'+mountTitleList( parseInt($('[name = page_index]').val()),view)+'</h2>'); |
---|
1252 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
1253 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button-'+((view == 'day' || view == 'week') ? 'agenda'+view : view )).addClass('fc-state-active'); |
---|
1254 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right').addClass('list-right'); |
---|
1255 | $(currentView+' .header-paginator .fc-header-right .fc-button-agendaday').hover( |
---|
1256 | function(){ |
---|
1257 | $(this).addClass('fc-state-hover'); |
---|
1258 | }, |
---|
1259 | function(){ |
---|
1260 | $(this).removeClass('fc-state-hover'); |
---|
1261 | }).mousedown(function(){ |
---|
1262 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
1263 | $(this).addClass('fc-state-active'); |
---|
1264 | }).mouseup(function(){ |
---|
1265 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'day'); |
---|
1266 | }); |
---|
1267 | |
---|
1268 | $(currentView+' .header-paginator .fc-header-right .fc-button-agendaweek').hover( |
---|
1269 | function(){ |
---|
1270 | $(this).addClass('fc-state-hover'); |
---|
1271 | }, |
---|
1272 | function(){ |
---|
1273 | $(this).removeClass('fc-state-hover'); |
---|
1274 | }).mousedown(function(){ |
---|
1275 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
1276 | $(this).addClass('fc-state-active'); |
---|
1277 | }).mouseup(function(){ |
---|
1278 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'week'); |
---|
1279 | }); |
---|
1280 | |
---|
1281 | $(currentView+' .header-paginator .fc-header-right .fc-button-month').hover( |
---|
1282 | function(){ |
---|
1283 | $(this).addClass('fc-state-hover'); |
---|
1284 | }, |
---|
1285 | function(){ |
---|
1286 | $(this).removeClass('fc-state-hover'); |
---|
1287 | }).mousedown(function(){ |
---|
1288 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
1289 | $(this).addClass('fc-state-active'); |
---|
1290 | }).mouseup(function(){ |
---|
1291 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'month'); |
---|
1292 | }); |
---|
1293 | |
---|
1294 | $(currentView+' .header-paginator .fc-header-right .fc-button-year').hover( |
---|
1295 | function(){ |
---|
1296 | $(this).addClass('fc-state-hover'); |
---|
1297 | }, |
---|
1298 | function(){ |
---|
1299 | $(this).removeClass('fc-state-hover'); |
---|
1300 | }).mousedown(function(){ |
---|
1301 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
1302 | $(this).addClass('fc-state-active'); |
---|
1303 | }).mouseup(function(){ |
---|
1304 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'year'); |
---|
1305 | }); |
---|
1306 | |
---|
1307 | |
---|
1308 | $(currentView+' .header-paginator .fc-header-left .fc-button.fc-button-next .fc-button-inner').hover( |
---|
1309 | function(){ |
---|
1310 | $(this).addClass('fc-state-hover'); |
---|
1311 | }, |
---|
1312 | function(){ |
---|
1313 | $(this).removeClass('fc-state-hover'); |
---|
1314 | }).mousedown(function(){ |
---|
1315 | $(this).addClass('fc-state-down'); |
---|
1316 | }).mouseup(function(){ |
---|
1317 | $(this).removeClass('fc-state-down'); |
---|
1318 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($('[name = page_index]').val())) +1), '', view); |
---|
1319 | }); |
---|
1320 | |
---|
1321 | $(currentView+' .header-paginator .fc-header-left .fc-button.fc-button-prev .fc-button-inner').hover( |
---|
1322 | function(){ |
---|
1323 | $(this).addClass('fc-state-hover'); |
---|
1324 | }, |
---|
1325 | function(){ |
---|
1326 | $(this).removeClass('fc-state-hover'); |
---|
1327 | }).mousedown(function(){ |
---|
1328 | $(this).addClass('fc-state-down'); |
---|
1329 | }).mouseup(function(){ |
---|
1330 | $(this).removeClass('fc-state-down'); |
---|
1331 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($('[name = page_index]').val())) -1), '', view); |
---|
1332 | }); |
---|
1333 | } |
---|
1334 | |
---|
1335 | function paginatorListEvent(currentView, typeView, view){ |
---|
1336 | if(!!$(currentView).find('.fc-calendar').length) |
---|
1337 | return; |
---|
1338 | $(currentView+' .events-list.events-list-win.active').prepend($('.fc-header').clone()); |
---|
1339 | //Remove contudo nao utilizado |
---|
1340 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-today').remove(); |
---|
1341 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-basicWeek').remove(); |
---|
1342 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-basicDay').remove(); |
---|
1343 | |
---|
1344 | //Adiciona e remove as classes para esta visualizacao |
---|
1345 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-header-center').addClass('list-events-paginator'); |
---|
1346 | $(currentView+' .events-list.events-list-win.active .fc-header .list-events-paginator').removeClass('fc-header-center'); |
---|
1347 | |
---|
1348 | //Adicionar class no header padronizar com a tela principal |
---|
1349 | $(currentView+' .events-list.events-list-win.active .fc-header').addClass('header-paginator'); |
---|
1350 | $(currentView+' .events-list.events-list-win.active .header-paginator').removeClass('fc-header'); |
---|
1351 | |
---|
1352 | if(typeView == 'search'){ |
---|
1353 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right').remove() |
---|
1354 | $(currentView+' .events-list.events-list-win.active .list-events-paginator .fc-header-title').html('<h2>Resultados para: '+$(currentView+' [name = keyword]').val()+'</h2>'); |
---|
1355 | if((parseInt($(currentView+' [name = page_index]').val()) == 0) && (parseInt($(currentView+' [name = results]').val()) <= 25)) |
---|
1356 | return; |
---|
1357 | paginatorSearch(currentView); |
---|
1358 | }else |
---|
1359 | paginatorList(currentView, view); |
---|
1360 | } |
---|
1361 | |
---|
1362 | function mountCriteriaList(view, page_index, calerdars_selecteds){ |
---|
1363 | switch (view){ |
---|
1364 | case 'day': |
---|
1365 | return {filter: ['AND', ['IN', 'calendar', calerdars_selecteds], ['=', 'rangeEnd', new Date().add({days: page_index}).toString("yyyy-MM-dd")]], criteria: {order: 'startTime'}}; |
---|
1366 | case 'week': |
---|
1367 | var dateStart = new Date().moveToDayOfWeek(dayOfWeek(User.preferences.weekDefault)); |
---|
1368 | var dateEnd = new Date().moveToDayOfWeek(dayOfWeek(User.preferences.weekDefault)); |
---|
1369 | return {filter: ['AND', ['IN', 'calendar', calerdars_selecteds], ['AND',['>=', 'rangeEnd', dateStart.add({days: (7 * page_index)}).toString("yyyy-MM-dd")], ['<=', 'rangeEnd', dateEnd.add({days: (7 * page_index)+7}).toString("yyyy-MM-dd")]]], criteria: {order: 'startTime'}}; |
---|
1370 | case 'month': |
---|
1371 | var date = new Date().add({months: page_index}) |
---|
1372 | return {filter: ['AND',['IN', 'calendar', calerdars_selecteds], ['AND',['>=', 'rangeEnd', date.moveToFirstDayOfMonth().toString("yyyy-MM-dd")], ['<=', 'rangeEnd', date.moveToLastDayOfMonth().toString("yyyy-MM-dd")]]], criteria: {order: 'startTime'}}; |
---|
1373 | case 'year': |
---|
1374 | var dateStart = new Date().add({years: page_index}); |
---|
1375 | var dateEnd = new Date().add({years: page_index}); |
---|
1376 | if(dateStart.getMonth() != 0) |
---|
1377 | dateStart.moveToMonth(0, -1) |
---|
1378 | if(dateEnd.getMonth() != 11) |
---|
1379 | dateEnd.moveToMonth(11) |
---|
1380 | return {filter: ['AND', ['IN', 'calendar', calerdars_selecteds], ['AND',['>=', 'rangeEnd', dateStart.moveToFirstDayOfMonth().toString("yyyy-MM-dd")], ['<=', 'rangeEnd', dateEnd.moveToLastDayOfMonth().toString("yyyy-MM-dd")]]], criteria: {order: 'startTime'}}; |
---|
1381 | } |
---|
1382 | } |
---|
1383 | |
---|
1384 | function pageselectCallback(keyword, page_index, jq, view){ |
---|
1385 | |
---|
1386 | var selecteds = getSelectedCalendars(); |
---|
1387 | if(!selecteds && (keyword != '' && keyword != null)){ |
---|
1388 | jQuery('#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( |
---|
1389 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
1390 | '<label>Por favor selecione ao menos uma agenda.</label>' + |
---|
1391 | '</div>' |
---|
1392 | ); |
---|
1393 | }else{ |
---|
1394 | var criteria = null; |
---|
1395 | if(keyword == '' || keyword == null) |
---|
1396 | criteria = mountCriteriaList(!!view ? view : User.preferences.defaultCalView, page_index, selecteds) |
---|
1397 | else |
---|
1398 | criteria = {filter: ['AND', ['OR', ["i*", "summary", keyword], ["i*", "description", keyword]], ['IN', 'calendar', selecteds]], criteria: {order: 'startTime', offset: (25 * page_index), limit: (((25 * page_index) + 25) + 1)}}; |
---|
1399 | var results = DataLayer.get('schedulable:detail', criteria); |
---|
1400 | keyword = ( keyword || '' ).replace( /\s+/g, "_" ); |
---|
1401 | } |
---|
1402 | // não há resultados |
---|
1403 | if ((((typeof(results) == 'undefined') || (!results.events_list )) && selecteds) &&(keyword != '' && keyword != null)) { |
---|
1404 | jQuery('#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( |
---|
1405 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
1406 | '<label>Não foi encontrado nenhum evento correspondente à sua pesquisa.</label>' + |
---|
1407 | '</div>' |
---|
1408 | ); |
---|
1409 | // há resultados e Agendas Selecionadas |
---|
1410 | } else{ |
---|
1411 | if(typeof(results) != 'undefined'){ |
---|
1412 | results['page_index'] = page_index; |
---|
1413 | results['keyword'] = keyword; |
---|
1414 | |
---|
1415 | DataLayer.render( 'templates/event_list.ejs', results, function( html ){ |
---|
1416 | var currentView = '#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "") || ''); |
---|
1417 | jQuery(currentView).html( html ); |
---|
1418 | jQuery('.events-list-win .menu-container .button').button(); |
---|
1419 | |
---|
1420 | $(".event-details-item").parent().click(function(){ |
---|
1421 | |
---|
1422 | $(this).siblings("div.details-event-list").toggleClass("hidden") |
---|
1423 | .find('.button.delete').click(function(){ |
---|
1424 | DataLayer.remove('schedulable', $(this).siblings('[name="eventid"]').val()); |
---|
1425 | }) |
---|
1426 | .end().find('.button.edit').click(function(){ |
---|
1427 | eventDetails( DataLayer.get( "schedulable", $(this).siblings('[name="eventid"]').val() ), true ); |
---|
1428 | }); |
---|
1429 | |
---|
1430 | }); |
---|
1431 | paginatorListEvent(currentView, (keyword == '' || keyword == null) ? 'list' : 'search', !!view ? view : User.preferences.defaultCalView); |
---|
1432 | }); |
---|
1433 | }else{ |
---|
1434 | var currentView = '#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "") || ''); |
---|
1435 | jQuery('#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( |
---|
1436 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
1437 | '<input type="hidden" name="page_index" value="'+page_index+'"></inpunt>'+ |
---|
1438 | '<input type="hidden" name="keyword" value="'+keyword+'"></inpunt>'+ |
---|
1439 | '<label>Não foram encontrados eventos neste intervalo.</label>' + |
---|
1440 | '</div>' |
---|
1441 | ); |
---|
1442 | paginatorListEvent(currentView, 'list', !!view ? view : User.preferences.defaultCalView); |
---|
1443 | } |
---|
1444 | |
---|
1445 | } |
---|
1446 | |
---|
1447 | } |
---|
1448 | |
---|
1449 | function show_modal_import_export(tab) { |
---|
1450 | DataLayer.render( 'templates/import_export.ejs', {calendars: Calendar.calendars, owner: User.me.id}, function( html ){ |
---|
1451 | |
---|
1452 | if (!UI.dialogs.importCalendar) { |
---|
1453 | UI.dialogs.importCalendar = jQuery('#div-import-export-calendar') |
---|
1454 | .append('<div title="Importar e Exportar Eventos" class="import-export import-export-win active"> <div>') |
---|
1455 | .find('.import-export-win.active').html(html).dialog({ |
---|
1456 | resizable: false, |
---|
1457 | modal:true, |
---|
1458 | width:500, |
---|
1459 | position: 'center' |
---|
1460 | }); |
---|
1461 | |
---|
1462 | } else { |
---|
1463 | UI.dialogs.importCalendar.html(html); |
---|
1464 | } |
---|
1465 | |
---|
1466 | var tabsImportExport = UI.dialogs.importCalendar.find(".tabs-import-export").tabs({selected: tab}); |
---|
1467 | |
---|
1468 | UI.dialogs.importCalendar.find('.button').button(); |
---|
1469 | |
---|
1470 | UI.dialogs.importCalendar.find(".menu-import-event") |
---|
1471 | .children(".import").click(function(){ |
---|
1472 | |
---|
1473 | $('.import-event-form', UI.dialogs.importCalendar).submit(); |
---|
1474 | UI.dialogs.importCalendar.dialog("close"); |
---|
1475 | /** |
---|
1476 | * TODO - implementar ação de importação |
---|
1477 | */ |
---|
1478 | }); |
---|
1479 | |
---|
1480 | UI.dialogs.importCalendar.find(".menu-export-event") |
---|
1481 | .children(".export").click(function(){ |
---|
1482 | |
---|
1483 | $('.export-event-form', UI.dialogs.importCalendar).submit(); |
---|
1484 | UI.dialogs.importCalendar.dialog("close"); |
---|
1485 | /** |
---|
1486 | * TODO - implementar ação de exportação |
---|
1487 | */ |
---|
1488 | }); |
---|
1489 | |
---|
1490 | UI.dialogs.importCalendar.find(".menu-container") |
---|
1491 | .children(".cancel").click(function(){ |
---|
1492 | UI.dialogs.importCalendar.dialog("close"); |
---|
1493 | }); |
---|
1494 | |
---|
1495 | UI.dialogs.importCalendar.dialog("open"); |
---|
1496 | }); |
---|
1497 | } |
---|
1498 | |
---|
1499 | function dayOfWeek(day) { |
---|
1500 | switch (day) { |
---|
1501 | case 'SUN': |
---|
1502 | return 0; |
---|
1503 | break; |
---|
1504 | case 'MON': |
---|
1505 | return 1; |
---|
1506 | break; |
---|
1507 | case 'TUE': |
---|
1508 | return 2; |
---|
1509 | break; |
---|
1510 | case 'WED': |
---|
1511 | return 3; |
---|
1512 | break; |
---|
1513 | case 'THU': |
---|
1514 | return 4; |
---|
1515 | break; |
---|
1516 | case 'FRI': |
---|
1517 | return 5; |
---|
1518 | break; |
---|
1519 | case 'SAT': |
---|
1520 | return 6; |
---|
1521 | break; |
---|
1522 | default: |
---|
1523 | return false; |
---|
1524 | break; |
---|
1525 | } |
---|
1526 | } |
---|
1527 | |
---|
1528 | function weekOfDay(week) { |
---|
1529 | switch (week) { |
---|
1530 | case 0: |
---|
1531 | return 'Domingo'; |
---|
1532 | case 1: |
---|
1533 | return 'Segunda'; |
---|
1534 | case 2: |
---|
1535 | return 'Terça'; |
---|
1536 | case 3: |
---|
1537 | return 'Quarta'; |
---|
1538 | case 4: |
---|
1539 | return 'Quinta'; |
---|
1540 | case 5: |
---|
1541 | return 'Sexta'; |
---|
1542 | case 6: |
---|
1543 | return 'Sábado'; |
---|
1544 | default: |
---|
1545 | return false; |
---|
1546 | } |
---|
1547 | } |
---|
1548 | |
---|
1549 | function monthOfNumber(number) { |
---|
1550 | switch (number) { |
---|
1551 | case 0: |
---|
1552 | return 'Janeiro'; |
---|
1553 | case 1: |
---|
1554 | return 'Fevereiro'; |
---|
1555 | case 2: |
---|
1556 | return 'Março'; |
---|
1557 | case 3: |
---|
1558 | return 'Abril'; |
---|
1559 | case 4: |
---|
1560 | return 'Maio'; |
---|
1561 | case 5: |
---|
1562 | return 'Junho'; |
---|
1563 | case 6: |
---|
1564 | return 'Julho'; |
---|
1565 | case 7: |
---|
1566 | return 'Agosto'; |
---|
1567 | case 8: |
---|
1568 | return 'Setembro'; |
---|
1569 | case 9: |
---|
1570 | return 'Outubro'; |
---|
1571 | case 10: |
---|
1572 | return 'Novembro'; |
---|
1573 | case 11: |
---|
1574 | return 'Dezembro'; |
---|
1575 | default: |
---|
1576 | return false; |
---|
1577 | } |
---|
1578 | } |
---|
1579 | |
---|
1580 | function sortMonthOfNumber(number) { |
---|
1581 | switch (number) { |
---|
1582 | case 0: |
---|
1583 | return 'Jan'; |
---|
1584 | case 1: |
---|
1585 | return 'Fev'; |
---|
1586 | case 2: |
---|
1587 | return 'Mar'; |
---|
1588 | case 3: |
---|
1589 | return 'Abr'; |
---|
1590 | case 4: |
---|
1591 | return 'Mai'; |
---|
1592 | case 5: |
---|
1593 | return 'Jun'; |
---|
1594 | case 6: |
---|
1595 | return 'Jul'; |
---|
1596 | case 7: |
---|
1597 | return 'Ago'; |
---|
1598 | case 8: |
---|
1599 | return 'Set'; |
---|
1600 | case 9: |
---|
1601 | return 'Out'; |
---|
1602 | case 10: |
---|
1603 | return 'Nov'; |
---|
1604 | case 11: |
---|
1605 | return 'Dez'; |
---|
1606 | default: |
---|
1607 | return false; |
---|
1608 | } |
---|
1609 | } |
---|