1 | function formatBytes(bytes) { |
---|
2 | if (bytes >= 1000000000) { |
---|
3 | return (bytes / 1000000000).toFixed(2) + ' GB'; |
---|
4 | } |
---|
5 | if (bytes >= 1000000) { |
---|
6 | return (bytes / 1000000).toFixed(2) + ' MB'; |
---|
7 | } |
---|
8 | if (bytes >= 1000) { |
---|
9 | return (bytes / 1000).toFixed(2) + ' KB'; |
---|
10 | } |
---|
11 | return bytes + ' B'; |
---|
12 | }; |
---|
13 | |
---|
14 | function validDateEvent(){ |
---|
15 | |
---|
16 | var errors = { |
---|
17 | 'emptyInitData': 'Por favor, informe uma data inicial', |
---|
18 | 'emptyEndData': 'Por favor, informe uma data final', |
---|
19 | 'emptyInitHour': 'Por favor, informe uma hora inicial', |
---|
20 | 'emptyEndHour': 'Por favor, informe uma hora final', |
---|
21 | |
---|
22 | 'invalidInitData' : 'Data inicial inválida', |
---|
23 | 'invalidEndData' : 'Data final inválida', |
---|
24 | |
---|
25 | 'equalData' : 'Hora inicial igual a final', |
---|
26 | 'theirData' : 'Data final menor que a inicial', |
---|
27 | 'theirHour' : 'Hora final menor que a inicial', |
---|
28 | |
---|
29 | 'emptyOcurrence' : 'Por favor, informe o número de ocorrências', |
---|
30 | 'invalidOcurrence' : 'Por favor, informe um valor válido para a quantidade de ocorrências', |
---|
31 | |
---|
32 | 'emptyInterval' : 'Por favor, informe o intervalo', |
---|
33 | 'invalidInterval' : 'Por favor informe um valor válido para o intervalo' |
---|
34 | }; |
---|
35 | |
---|
36 | var start_date = $(".new-event-win.active .start-date").val(); |
---|
37 | var end_date = $(".new-event-win.active .end-date").val(); |
---|
38 | var start_time = $(".new-event-win.active .start-time").val(); |
---|
39 | var end_time = $(".new-event-win.active .end-time").val(); |
---|
40 | var isAllDay = $('.new-event-win.active input[name="allDay"]').is(':checked'); |
---|
41 | var customDate = $(".endRepeat").val() == "customDate"; |
---|
42 | var occurrences = $(".endRepeat").val() == "occurrences"; |
---|
43 | var eventInterval = $('.eventInterval').val(); |
---|
44 | |
---|
45 | if(start_date == "") |
---|
46 | return errors['emptyInitData']; |
---|
47 | else if(end_date == "") |
---|
48 | return errors['emptyEndData']; |
---|
49 | else if(!isAllDay && start_time == "") |
---|
50 | return errors['emptyInitHour']; |
---|
51 | else if(!isAllDay && end_time == "") |
---|
52 | return errors['emptyEndHour']; |
---|
53 | |
---|
54 | var formatString = User.preferences.dateFormat + " " + User.preferences.hourFormat; |
---|
55 | |
---|
56 | var startDate = Date.parseExact( start_date + " " + $.trim(start_time) , formatString ); |
---|
57 | var endDate = Date.parseExact( end_date + " " + $.trim(end_time) , formatString ); |
---|
58 | |
---|
59 | if(startDate == null || startDate.getTime() < 0 ) |
---|
60 | return errors['invalidInitData']; |
---|
61 | if(endDate == null || endDate.getTime() < 0) |
---|
62 | return errors['invalidEndData']; |
---|
63 | |
---|
64 | if(isAllDay){ |
---|
65 | startDate.clearTime(); |
---|
66 | endDate.clearTime(); |
---|
67 | if(endDate.compareTo(startDate) == -1) |
---|
68 | return errors['theirData']; |
---|
69 | }else{ |
---|
70 | var condition = endDate.compareTo(startDate); |
---|
71 | if(condition != 1){ |
---|
72 | if(condition < 0){ |
---|
73 | startDate.clearTime(); |
---|
74 | endDate.clearTime(); |
---|
75 | condition = endDate.compareTo(startDate); |
---|
76 | return (errors[ condition == 0 ? 'theirHour' : 'theirData'] ); |
---|
77 | } |
---|
78 | else |
---|
79 | return errors['equalData']; |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | if (customDate) |
---|
84 | if ( !($('.new-event-win.active .customDateEnd').val().length) ) |
---|
85 | return errors['emptyEndData']; |
---|
86 | |
---|
87 | if (occurrences){ |
---|
88 | if ( !($('.occurrencesEnd').val().length) ) |
---|
89 | return errors['emptyOcurrence']; |
---|
90 | else if (parseInt($('.occurrencesEnd').val(),10) <= 0 || parseInt($('.occurrencesEnd').val(),10).toString() == "NaN") |
---|
91 | return errors['invalidOcurrence']; |
---|
92 | } |
---|
93 | |
---|
94 | if (!($('.new-event-win.active p.input-group.finish_event.repeat-in').hasClass('hidden'))){ |
---|
95 | if (!eventInterval.length) |
---|
96 | return errors['emptyInterval']; |
---|
97 | else if (parseInt(eventInterval,10) < 1 || parseInt(eventInterval,10).toString() == "NaN") |
---|
98 | return errors['invalidInterval']; |
---|
99 | } |
---|
100 | return false; |
---|
101 | } |
---|
102 | |
---|
103 | /* |
---|
104 | function listEvents(){ |
---|
105 | var list = $('.fc-header-right').find('.fc-button.fc-button-agendaDay').clone(); |
---|
106 | $('.fc-header-right').find('.fc-button-year').toggleClass('fc-corner-right'); |
---|
107 | list.addClass('fc-corner-right'); |
---|
108 | list.addClass('fc-button-listagem'); |
---|
109 | list.removeClass('fc-button-agendaDay'); |
---|
110 | list.removeClass('fc-corner-left'); |
---|
111 | list.find('.fc-button-content').html('Listagem'); |
---|
112 | $('.fc-header-right').append(list); |
---|
113 | } |
---|
114 | */ |
---|
115 | |
---|
116 | /* |
---|
117 | * TODO - repeat foi adicionado pois melhorias devem ser feitas no rollback do |
---|
118 | *DataLayer, repeat somente é usado quando se trata da criação de um evento |
---|
119 | *pela edição de uma ocorrência. |
---|
120 | */ |
---|
121 | |
---|
122 | function eventDetails( objEvent, decoded, path, isMail, repeat) |
---|
123 | { |
---|
124 | attendees = {}; |
---|
125 | |
---|
126 | if(path == undefined) |
---|
127 | path = ""; |
---|
128 | |
---|
129 | if( !decoded ) |
---|
130 | objEvent = DataLayer.decode( "schedulable:calendar", objEvent ); |
---|
131 | |
---|
132 | if(!isMail) |
---|
133 | objEvent = DataLayer.encode( "schedulable:preview", objEvent ); |
---|
134 | |
---|
135 | if(typeof(objEvent.id) == 'undefined'){ |
---|
136 | objEvent.alarms = Calendar.signatureOf[User.preferences.defaultCalendar || Calendar.calendarIds[0]].defaultAlarms || false; |
---|
137 | objEvent.useAlarmDefault = 1; |
---|
138 | } |
---|
139 | |
---|
140 | /** |
---|
141 | * canDiscardEventDialog deve ser true se não houver alterações no evento |
---|
142 | */ |
---|
143 | canDiscardEventDialog = true; |
---|
144 | /** |
---|
145 | * zebraDiscardEventDialog é uma flag indicando que uma janela de confirmação (Zebra_Dialog) |
---|
146 | * já está aberta na tela, uma vez que não é possivel acessar o evento ESC utilizado para fechá-la |
---|
147 | */ |
---|
148 | zebraDiscardEventDialog = false; |
---|
149 | |
---|
150 | /** |
---|
151 | ACLs do participant |
---|
152 | */ |
---|
153 | acl_names = { |
---|
154 | 'w': 'acl-white', |
---|
155 | 'i': 'acl-invite-guests', |
---|
156 | 'p': 'acl-participation-required' |
---|
157 | }; |
---|
158 | |
---|
159 | var dependsDelegate = function(reference, inverse){ |
---|
160 | if(inverse){ |
---|
161 | if(reference.find('input[name="attendee[]"]').val() == blkAddAtendee.find('li.organizer input[name="attendee_organizer"]').val()) |
---|
162 | blkAddAtendee.find('li.organizer input[name="attendee_organizer"]').val(blkAddAtendee.find('.me input[name="attendee[]"]').val()); |
---|
163 | }else{ |
---|
164 | if(blkAddAtendee.find('.me input[name="attendee[]"]').val() == blkAddAtendee.find('li.organizer input[name="attendee_organizer"]').val()) |
---|
165 | blkAddAtendee.find('li.organizer input[name="attendee_organizer"]').val(reference.find('input[name="attendee[]"]').val()); |
---|
166 | } |
---|
167 | |
---|
168 | }; |
---|
169 | |
---|
170 | var removeOthers = function(){ |
---|
171 | var other = blkAddAtendee.find('.delegate.attendee-permissions-change-button'); |
---|
172 | if(other.lenght){ |
---|
173 | dependsDelegate(other.parents('li'), true); |
---|
174 | } |
---|
175 | blkAddAtendee.find('.delegate').removeClass('attendee-permissions-change-button'); |
---|
176 | blkAddAtendee.find('.ui-icon-transferthick-e-w').removeClass('attendee-permissions-change'); |
---|
177 | |
---|
178 | }; |
---|
179 | |
---|
180 | var callbackAttendee = function(){ |
---|
181 | //Cria qtip de permissões pelo click do checkbox |
---|
182 | var checked = false; |
---|
183 | blkAddAtendee.find("li.not-attendee").addClass('hidden'); |
---|
184 | |
---|
185 | blkAddAtendee.find("li .button").filter(".close.new").button({ |
---|
186 | icons: { |
---|
187 | primary: "ui-icon-close" |
---|
188 | }, |
---|
189 | text: false |
---|
190 | }).click(function () { |
---|
191 | DataLayer.remove('participant', $(this).parents('li').find('[type=checkbox]').val()); |
---|
192 | if($(this).parent().find('.button.delegate').hasClass('attendee-permissions-change-button')){ |
---|
193 | removeOthers(); |
---|
194 | blkAddAtendee.find('.request-update').addClass('hidden'); |
---|
195 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
196 | |
---|
197 | blkAddAtendee.find('option[value=1]').attr('selected','selected').trigger('change'); |
---|
198 | } |
---|
199 | |
---|
200 | $(this).parents('li').remove(); |
---|
201 | |
---|
202 | if(blkAddAtendee.find(".attendee-list li").length == 1) |
---|
203 | blkAddAtendee.find("li.not-attendee").removeClass('hidden'); |
---|
204 | }) |
---|
205 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
206 | .removeClass('new').end() |
---|
207 | |
---|
208 | .filter(".delegate.new").button({ |
---|
209 | icons: { |
---|
210 | primary: "ui-icon-transferthick-e-w" |
---|
211 | }, |
---|
212 | text: false |
---|
213 | }).click(function () { |
---|
214 | var me = $(this).parents('li'); |
---|
215 | if($(this).hasClass('attendee-permissions-change-button')){ |
---|
216 | $(this).removeClass('attendee-permissions-change-button') |
---|
217 | .find('.ui-icon-transferthick-e-w').removeClass('attendee-permissions-change').end(); |
---|
218 | |
---|
219 | me.find('input[name="delegatedFrom[]"]').val(''); |
---|
220 | dependsDelegate(me, true); |
---|
221 | |
---|
222 | blkAddAtendee.find('.request-update').addClass('hidden'); |
---|
223 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
224 | |
---|
225 | blkAddAtendee.find('option[value=1]').attr('selected','selected').trigger('change'); |
---|
226 | |
---|
227 | }else{ |
---|
228 | removeOthers(); |
---|
229 | |
---|
230 | $(this).addClass('attendee-permissions-change-button') |
---|
231 | .find('.ui-icon-transferthick-e-w').addClass('attendee-permissions-change').end(); |
---|
232 | |
---|
233 | me.find('input[name="delegatedFrom[]"]').val(blkAddAtendee.find('.me input[name="attendee[]"]').val()); |
---|
234 | |
---|
235 | dependsDelegate(me, false); |
---|
236 | |
---|
237 | blkAddAtendee.find('.request-update').removeClass('hidden'); |
---|
238 | if(blkAddAtendee.find('.status option.hidden').length == 1) |
---|
239 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
240 | |
---|
241 | blkAddAtendee.find('option[value=5]').attr('selected','selected').trigger('change'); |
---|
242 | } |
---|
243 | }) |
---|
244 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
245 | .removeClass('new').end() |
---|
246 | |
---|
247 | .filter(".edit.new").button({ |
---|
248 | icons: { |
---|
249 | primary: "ui-icon-key" |
---|
250 | }, |
---|
251 | text: false |
---|
252 | }).click(function() { |
---|
253 | |
---|
254 | if(!!!checked) |
---|
255 | $(this).parents('li').find('[type=checkbox]').attr('checked', (!$(this).parent().find('[type=checkbox]').is(':checked'))).end(); |
---|
256 | |
---|
257 | var aclsParticipant = $(this).parents('li').find('input[name="attendeeAcl[]"]').val(); |
---|
258 | checked = false; |
---|
259 | |
---|
260 | if( $('.qtip.qtip-blue.qtip-active').val() !== ''){ |
---|
261 | blkAddAtendee.find('dd.attendee-list').qtip({ |
---|
262 | show: { |
---|
263 | ready: true, |
---|
264 | solo: true, |
---|
265 | when: { |
---|
266 | event: 'click' |
---|
267 | } |
---|
268 | }, |
---|
269 | hide: false, |
---|
270 | content: { |
---|
271 | text: $('<div></div>').html( DataLayer.render( 'templates/attendee_permissions.ejs', {} ) ), |
---|
272 | title: { |
---|
273 | text:'Permissões', |
---|
274 | button: '<a class="button close" href="#">close</a>' |
---|
275 | } |
---|
276 | }, |
---|
277 | style: { |
---|
278 | name: 'blue', |
---|
279 | tip: { |
---|
280 | corner: 'leftMiddle' |
---|
281 | }, |
---|
282 | border: { |
---|
283 | width: 4, |
---|
284 | radius: 8 |
---|
285 | }, |
---|
286 | width: { |
---|
287 | min: 230, |
---|
288 | max:230 |
---|
289 | } |
---|
290 | }, |
---|
291 | position: { |
---|
292 | corner: { |
---|
293 | target: 'rightMiddle', |
---|
294 | tooltip: 'leftMiddle' |
---|
295 | }, |
---|
296 | adjust: { |
---|
297 | x:0, |
---|
298 | y:0 |
---|
299 | } |
---|
300 | } |
---|
301 | }) |
---|
302 | .qtip("api").onShow = function(arg0) { |
---|
303 | $('.qtip-active .button.close').button({ |
---|
304 | icons: { |
---|
305 | primary: "ui-icon-close" |
---|
306 | }, |
---|
307 | text: false |
---|
308 | }) |
---|
309 | .click(function(){ |
---|
310 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
311 | }); |
---|
312 | |
---|
313 | $('.qtip-active .button.save').button().click(function(){ |
---|
314 | |
---|
315 | var acl = ''; |
---|
316 | $('.qtip-active').find('[type=checkbox]:checked').each(function(i, obj) { |
---|
317 | acl+= obj.value; |
---|
318 | }); |
---|
319 | |
---|
320 | blkAddAtendee.find('dd.attendee-list [type=checkbox]:checked').siblings('input[name="attendeeAcl[]"]').each(function(i, obj) { |
---|
321 | obj.value = 'r'+acl; |
---|
322 | }).parents('li').find('.button.edit').addClass('attendee-permissions-change-button') |
---|
323 | .find('.ui-icon-key').addClass('attendee-permissions-change'); |
---|
324 | |
---|
325 | blkAddAtendee.find('dd.attendee-list [type=checkbox]').attr('checked', false); |
---|
326 | |
---|
327 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
328 | |
---|
329 | }); |
---|
330 | $('.qtip-active .button.cancel').button().click(function(){ |
---|
331 | blkAddAtendee.find('dd.attendee-list [type=checkbox]').attr('checked', false); |
---|
332 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
333 | }); |
---|
334 | |
---|
335 | if(aclsParticipant) |
---|
336 | for(var i = 1; i < aclsParticipant.length; i++){ |
---|
337 | $('.qtip-active').find('input[name="'+acl_names[aclsParticipant.charAt(i)]+'"]').attr('checked', true); |
---|
338 | } |
---|
339 | |
---|
340 | |
---|
341 | $('.button').button(); |
---|
342 | |
---|
343 | }; |
---|
344 | }else{ |
---|
345 | if(!$('.new-event-win dd.attendee-list').find('[type=checkbox]:checked').length){ |
---|
346 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
347 | }else{ |
---|
348 | $('.qtip-active .button.save .ui-button-text').html('Aplicar a todos') |
---|
349 | } |
---|
350 | |
---|
351 | }; |
---|
352 | }) |
---|
353 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
354 | .removeClass('new').end() |
---|
355 | |
---|
356 | .filter(".open-delegate.new").click(function(){ |
---|
357 | if($(this).hasClass('ui-icon-triangle-1-e')){ |
---|
358 | $(this).removeClass('ui-icon-triangle-1-e').addClass('ui-icon-triangle-1-s'); |
---|
359 | $(this).parents('li').find('.list-delegates').removeClass('hidden'); |
---|
360 | }else{ |
---|
361 | $(this).removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e'); |
---|
362 | $(this).parents('li').find('.list-delegates').addClass('hidden'); |
---|
363 | } |
---|
364 | |
---|
365 | }).removeClass('new'); |
---|
366 | |
---|
367 | |
---|
368 | blkAddAtendee.find("li input[type=checkbox].new").click(function(){ |
---|
369 | if(!$('.new-event-win dd.attendee-list').find('[type=checkbox]:checked').length){ |
---|
370 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
371 | }else{ |
---|
372 | checked = true; |
---|
373 | $(this).parents('li').find('.button.edit').click(); |
---|
374 | } |
---|
375 | }).removeClass('new'); |
---|
376 | |
---|
377 | UI.dialogs.addEvent.find('.attendees-list li').hover( |
---|
378 | function () { |
---|
379 | $(this).addClass("hover-attendee"); |
---|
380 | $(this).find('.button').removeClass('disable ui-button-disabled ui-state-disabled').end() |
---|
381 | .find('.attendee-options').addClass('hover-attendee'); |
---|
382 | }, |
---|
383 | function () { |
---|
384 | $(this).removeClass("hover-attendee"); |
---|
385 | $(this).find('.button').addClass('disable ui-button-disabled ui-state-disabled').end() |
---|
386 | .find('.attendee-options').removeClass('hover-attendee');; |
---|
387 | } |
---|
388 | ); |
---|
389 | |
---|
390 | |
---|
391 | } |
---|
392 | |
---|
393 | var html = DataLayer.render( path+'templates/event_add.ejs', { |
---|
394 | event:objEvent |
---|
395 | }); |
---|
396 | |
---|
397 | if (!UI.dialogs.addEvent) { |
---|
398 | UI.dialogs.addEvent = jQuery('#sandbox').append('<div title="Criar Evento" class="new-event-win active"> <div>').find('.new-event-win.active').html(html).dialog({ |
---|
399 | resizable: false, |
---|
400 | modal:true, |
---|
401 | autoOpen: false, |
---|
402 | width:700, |
---|
403 | position: 'center', |
---|
404 | close: function(event, ui) { |
---|
405 | /** |
---|
406 | * Remove tooltip possivelmente existente |
---|
407 | */ |
---|
408 | if ($('dd.attendee-list li:last').data('qtip')) |
---|
409 | $('dd.attendee-list li:last').qtip('destroy'); |
---|
410 | |
---|
411 | attendees = {}; |
---|
412 | |
---|
413 | }, |
---|
414 | beforeClose: function(event, ui) { |
---|
415 | |
---|
416 | if (!canDiscardEventDialog && !zebraDiscardEventDialog) { |
---|
417 | zebraDiscardEventDialog = true; |
---|
418 | window.setTimeout(function() { |
---|
419 | $.Zebra_Dialog('Suas alterações no evento não foram salvas. Deseja descartar as alterações?', { |
---|
420 | 'type': 'question', |
---|
421 | 'overlay_opacity': '0.5', |
---|
422 | 'buttons': ['Descartar alterações', 'Continuar editando'], |
---|
423 | 'onClose': function(clicked) { |
---|
424 | if(clicked == 'Descartar alterações') { |
---|
425 | canDiscardEventDialog = true; |
---|
426 | /** |
---|
427 | *Remoção dos anexos do eventos caso seja cancelado a edição |
---|
428 | */ |
---|
429 | DataLayer.rollback(); |
---|
430 | |
---|
431 | var ids = false; |
---|
432 | $.each($('.attachment-list input'), function (i, input) { |
---|
433 | DataLayer.put('attachment', {id: ''+input.value}); |
---|
434 | DataLayer.remove('attachment', ''+input.value); |
---|
435 | ids = true; |
---|
436 | }); |
---|
437 | if(ids) |
---|
438 | DataLayer.commit(); |
---|
439 | |
---|
440 | |
---|
441 | |
---|
442 | UI.dialogs.addEvent.dialog('close'); |
---|
443 | }else{ |
---|
444 | zebraDiscardEventDialog = false; |
---|
445 | } |
---|
446 | |
---|
447 | /** |
---|
448 | * Uma vez aberta uma janela de confirmação (Zebra_Dialog), ao fechá-la |
---|
449 | * com ESC, para que o evento ESC não seja propagado para fechamento da |
---|
450 | * janela de edição de eventos, deve ser setada uma flag indicando que |
---|
451 | * já existe uma janela de confirmação aberta. |
---|
452 | */ |
---|
453 | if (!clicked) { |
---|
454 | window.setTimeout(function() { |
---|
455 | zebraDiscardEventDialog = false; |
---|
456 | }, 200); |
---|
457 | } |
---|
458 | } |
---|
459 | }); |
---|
460 | |
---|
461 | }, 300); |
---|
462 | |
---|
463 | } |
---|
464 | //DataLayer.rollback(); |
---|
465 | return canDiscardEventDialog; |
---|
466 | } |
---|
467 | }); |
---|
468 | |
---|
469 | } else { |
---|
470 | UI.dialogs.addEvent.html(html); |
---|
471 | } |
---|
472 | |
---|
473 | var tabs = UI.dialogs.addEvent.children('.content').tabs(); |
---|
474 | var calendar = DataLayer.get('calendar', objEvent.calendar); |
---|
475 | |
---|
476 | if (calendar.timezone != objEvent.timezone){ |
---|
477 | UI.dialogs.addEvent.find('.calendar-addevent-details-txt-timezone').find('option[value="'+objEvent.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
478 | UI.dialogs.addEvent.find('.calendar_addevent_details_lnk_timezone').addClass('hidden'); |
---|
479 | $('.calendar-addevent-details-txt-timezone').removeClass('hidden'); |
---|
480 | |
---|
481 | } |
---|
482 | |
---|
483 | DataLayer.render( path+'templates/event_repeat.ejs', { |
---|
484 | event:objEvent |
---|
485 | }, function( repeatHtml ){ |
---|
486 | |
---|
487 | UI.dialogs.addEvent.find('#calendar_addevent_details3').html(repeatHtml); |
---|
488 | $(".date").datepicker({ |
---|
489 | dateFormat: User.preferences.dateFormat.replace(/M/g, 'm').replace(/yyyy/g, 'yy') |
---|
490 | }); |
---|
491 | |
---|
492 | if(objEvent.repeat) |
---|
493 | { |
---|
494 | if( objEvent.repeat['id'] ) |
---|
495 | { |
---|
496 | $("[name='repeatId']:last").val( objEvent.repeat['id'] ); |
---|
497 | } |
---|
498 | |
---|
499 | if( objEvent.repeat['frequency'] !== 'none' ) |
---|
500 | { |
---|
501 | if( objEvent.repeat['startTime'] && objEvent.repeat['startTime'] !== "0" ) |
---|
502 | { |
---|
503 | $("[name='startOptions'] [value='customDate']:last").attr( 'selected', 'selected' ); |
---|
504 | $("[name='start']:last").val(new Date( parseInt(objEvent.repeat['startTime']) ).toString( User.preferences.dateFormat ) ); |
---|
505 | } |
---|
506 | else |
---|
507 | { |
---|
508 | $("[name='start']:last").val($("[name='startDate']:last").val()); |
---|
509 | $("[name='start']:last").readOnly=true; |
---|
510 | $("[name='start']:last").datepicker("disable"); |
---|
511 | } |
---|
512 | |
---|
513 | $(".finish_event").removeClass("hidden"); |
---|
514 | |
---|
515 | if(objEvent.repeat['endTime'] && objEvent.repeat['endTime'] !== "0" ) |
---|
516 | { |
---|
517 | //$("[name='occurrences']").addClass("hidden"); |
---|
518 | $(".customDateEnd").removeClass("hidden"); |
---|
519 | $(".endRepeat option[value='customDate']").attr('selected', 'selected') |
---|
520 | $(".customDateEnd").val( new Date( parseInt(objEvent.repeat['endTime']) )/*.setTimezoneOffset( Timezone.timezone( objEvent.timezone ) )*/.toString( User.preferences.dateFormat ) ); |
---|
521 | } |
---|
522 | else if (objEvent.repeat['count'] && objEvent.repeat['count'] !== "0" ) { |
---|
523 | $(".endRepeat option[value='occurrences']").attr('selected', 'selected'); |
---|
524 | $(".occurrencesEnd").removeClass("hidden"); |
---|
525 | $(".occurrencesEnd").val(objEvent.repeat['count']); |
---|
526 | } |
---|
527 | |
---|
528 | switch ( objEvent.repeat['frequency'] ) |
---|
529 | { |
---|
530 | case "daily": |
---|
531 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Dia(s)") |
---|
532 | .end().find(".eventInterval").val( objEvent.repeat['interval'] || "1" ); |
---|
533 | $(".frequency option[value='daily']").attr('selected', 'selected'); |
---|
534 | break; |
---|
535 | case "weekly": |
---|
536 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Semana(s)") |
---|
537 | .end().find(".eventInterval").val( objEvent.repeat['interval'] || "1" ); |
---|
538 | $(".frequency option[value='weekly']").attr('selected', 'selected'); |
---|
539 | |
---|
540 | $(".event-repeat-weekly").removeClass("hidden"); |
---|
541 | |
---|
542 | var day = []; |
---|
543 | |
---|
544 | if( objEvent.repeat.byday ) |
---|
545 | day = objEvent.repeat.byday.split(','); |
---|
546 | |
---|
547 | for(i=0; i<day.length; i++) |
---|
548 | $(".event-repeat-weekly [value='" + day[i] + "']").attr("checked","checked"); |
---|
549 | |
---|
550 | break; |
---|
551 | case "monthly": |
---|
552 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Mes(s)") |
---|
553 | .end().find(".eventInterval").val( objEvent.repeat['interval'] || "1" ); |
---|
554 | $(".frequency option[value='monthly']").attr('selected', 'selected') |
---|
555 | $(".event-repeat-monthly:last").removeClass("hidden").find("input[type=radio][name=repeatmonthyType]").click(function(){ |
---|
556 | if($("input[type=radio][name=repeatmonthyType]:checked").val() == "1") |
---|
557 | $(".event-repeat-weekly:last").removeClass("hidden"); |
---|
558 | else |
---|
559 | $(".event-repeat-weekly:last").addClass("hidden"); |
---|
560 | }); |
---|
561 | if($("input[type=radio][name=repeatmonthyType]:checked").val() == "1") |
---|
562 | $(".event-repeat-weekly:last").removeClass("hidden"); |
---|
563 | else |
---|
564 | $(".event-repeat-weekly:last").addClass("hidden"); |
---|
565 | break; |
---|
566 | case "yearly": |
---|
567 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Ano(s)") |
---|
568 | .end().find(".eventInterval").val( objEvent.repeat['interval'] || "1" ); |
---|
569 | $(".frequency option[value='yearly']").attr('selected', 'selected') |
---|
570 | break; |
---|
571 | } |
---|
572 | } |
---|
573 | } |
---|
574 | else { |
---|
575 | $(".endRepeat option[value='never']").attr('selected', 'selected'); |
---|
576 | } |
---|
577 | |
---|
578 | |
---|
579 | $(".event-repeat-container:last").find(".repeat-in").find("[name=startOptions]").change(function(){ |
---|
580 | |
---|
581 | if($(this).find("option:selected").val() == "Today"){ |
---|
582 | $("[name='start']:last").val($("[name='startDate']:last").val()); |
---|
583 | $("[name='start']:last").readOnly=true; |
---|
584 | $("[name='start']:last").datepicker("disable"); |
---|
585 | } |
---|
586 | else{ |
---|
587 | $("[name='start']:last").readOnly=false; |
---|
588 | $("[name='start']:last").datepicker("enable"); |
---|
589 | } |
---|
590 | }); |
---|
591 | $(".event-repeat-container:last").find(".repeat-in").find("[name=endOptions]").change(function(){ |
---|
592 | if($(this).find("option:selected").val() == "never"){ |
---|
593 | $("[name='occurrences']").addClass("hidden"); |
---|
594 | $("[name='end']:last").addClass("hidden"); |
---|
595 | } |
---|
596 | else if($(this).find("option:selected").val() == "customDate"){ |
---|
597 | $("[name='occurrences']").addClass("hidden"); |
---|
598 | $("[name='end']:last").removeClass("hidden"); |
---|
599 | } |
---|
600 | else{ |
---|
601 | $("[name='end']:last").addClass("hidden"); |
---|
602 | $("[name='occurrences']").removeClass("hidden"); |
---|
603 | } |
---|
604 | }); |
---|
605 | |
---|
606 | $("[name='frequency']:last").change(function () { |
---|
607 | $(".frequency-option").addClass("hidden"); |
---|
608 | if($(this).val() == "none"){ |
---|
609 | $(".repeat-in").addClass("hidden"); |
---|
610 | return; |
---|
611 | }else{ |
---|
612 | $(".repeat-in").removeClass("hidden"); |
---|
613 | $("[name='start']:last").val($("[name='startDate']:last").val()); |
---|
614 | } |
---|
615 | |
---|
616 | |
---|
617 | switch($(this).val()){ |
---|
618 | case "daily": |
---|
619 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Dia(s)"); |
---|
620 | break; |
---|
621 | case "weekly": |
---|
622 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Semana(s)"); |
---|
623 | $(".event-repeat-weekly:last").removeClass("hidden"); |
---|
624 | break; |
---|
625 | case "monthly": |
---|
626 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Mes(s)"); |
---|
627 | $(".event-repeat-monthly:last").removeClass("hidden").find("input[type=radio][name=repeatmonthyType]").click(function(){ |
---|
628 | if($("input[type=radio][name=repeatmonthyType]:checked").val() == "1") |
---|
629 | $(".event-repeat-weekly:last").removeClass("hidden"); |
---|
630 | else |
---|
631 | $(".event-repeat-weekly:last").addClass("hidden"); |
---|
632 | }); |
---|
633 | if($("input[type=radio][name=repeatmonthyType]:checked").val() == "1") |
---|
634 | $(".event-repeat-weekly:last").removeClass("hidden"); |
---|
635 | else |
---|
636 | $(".event-repeat-weekly:last").addClass("hidden"); |
---|
637 | break; |
---|
638 | default: |
---|
639 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Ano(s)"); |
---|
640 | break; |
---|
641 | } |
---|
642 | |
---|
643 | }); |
---|
644 | }); |
---|
645 | |
---|
646 | UI.dialogs.addEvent.find('.calendar_addevent_details_lnk_timezone').click(function(e){ |
---|
647 | $(this).addClass('hidden'); |
---|
648 | $('.calendar-addevent-details-txt-timezone').removeClass('hidden'); |
---|
649 | e.preventDefault(); |
---|
650 | }); |
---|
651 | |
---|
652 | UI.dialogs.addEvent.find('.button.remove').button({ |
---|
653 | text:false, |
---|
654 | icons:{ |
---|
655 | primary:'ui-icon-close' |
---|
656 | } |
---|
657 | }).click(function(el){ |
---|
658 | var id; |
---|
659 | if( id = $(this).parent().find('input[name="alarmId[]"]').val()) |
---|
660 | DataLayer.remove('alarm', id); |
---|
661 | $(this).parent().remove().find('li').is(':empty'); |
---|
662 | }); |
---|
663 | |
---|
664 | var myCalendar = function(){ |
---|
665 | for(var i in Calendar.signatures) |
---|
666 | if(Calendar.signatures[i].isOwner == "1") |
---|
667 | return Calendar.signatures[i].calendar.id; |
---|
668 | } |
---|
669 | |
---|
670 | /*Seleciona a agenda padrão para visualização/edição de um evento*/ |
---|
671 | if(objEvent.id) |
---|
672 | UI.dialogs.addEvent.find('option[value="'+objEvent.calendar+'"]').attr('selected','selected').trigger('change'); |
---|
673 | |
---|
674 | /*Adicionar alarms padrões, quando alterado a agenda do usuário*/ |
---|
675 | UI.dialogs.addEvent.find('select[name="calendar"]').change(function(){ |
---|
676 | if((typeof($('input[name = "idEvent"]').val()) == 'undefined') || (!!!$('input[name = "idEvent"]').val())) { |
---|
677 | $('input[name = "isDefaultAlarm[]"]').parent().remove(); |
---|
678 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').parent().removeClass('hidden'); |
---|
679 | var calendarSelected = Calendar.signatureOf[$(this).val()]; |
---|
680 | calendarSelected.useAlarmDefault = 1; |
---|
681 | if(calendarSelected.defaultAlarms != ""){ |
---|
682 | var li_attach = DataLayer.render(path+'templates/alarms_add_itemlist.ejs', { |
---|
683 | alarm:calendarSelected |
---|
684 | }); |
---|
685 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({ |
---|
686 | text:false, |
---|
687 | icons:{ |
---|
688 | primary:'ui-icon-close' |
---|
689 | } |
---|
690 | }).click(function(el) { |
---|
691 | $(this).parent().remove().find('li').is(':empty'); |
---|
692 | }); |
---|
693 | |
---|
694 | }else{ |
---|
695 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').parent().addClass('hidden'); |
---|
696 | } |
---|
697 | } |
---|
698 | |
---|
699 | var participant = UI.dialogs.addEvent.find('dd.me input[name="attendee[]"]').val(); |
---|
700 | var calendar = $(this).val(); |
---|
701 | |
---|
702 | if( !parseInt(Calendar.signatureOf[calendar].isOwner) ){ |
---|
703 | var signature = Calendar.signatureOf[calendar]; |
---|
704 | var organizer = DataLayer.get('calendarSignature', { |
---|
705 | filter: ['AND', ['=','calendar',signature.calendar.id], ['=','isOwner','1']], |
---|
706 | criteria: { |
---|
707 | deepness: 2 |
---|
708 | } |
---|
709 | }); |
---|
710 | |
---|
711 | if($.isArray(organizer)) |
---|
712 | organizer = organizer[0]; |
---|
713 | DataLayer.put('participant', { |
---|
714 | id: participant, |
---|
715 | user: organizer.user.id, |
---|
716 | mail: organizer.user.mail |
---|
717 | }); |
---|
718 | |
---|
719 | UI.dialogs.addEvent.find('dt.me').html(organizer.user.name); |
---|
720 | UI.dialogs.addEvent.find('li.organizer input[name="attendee_organizer"]').val(participant); |
---|
721 | UI.dialogs.addEvent.find('li.organizer label').filter('.name').html(organizer.user.name).end() |
---|
722 | .filter('.mail').html(organizer.user.mail).attr('title',organizer.user.mail); |
---|
723 | |
---|
724 | }else{ |
---|
725 | UI.dialogs.addEvent.find('dt.me').html(User.me.name); |
---|
726 | DataLayer.put('participant', { |
---|
727 | id: participant, |
---|
728 | user: User.me.id, |
---|
729 | mail: User.me.mail |
---|
730 | }); |
---|
731 | UI.dialogs.addEvent.find('li.organizer input[name="attendee_organizer"]').val(participant); |
---|
732 | UI.dialogs.addEvent.find('li.organizer label').filter('.name').html(User.me.name).end() |
---|
733 | .filter('.mail').html(User.me.mail).attr('title',User.me.mail); |
---|
734 | } |
---|
735 | |
---|
736 | }); |
---|
737 | |
---|
738 | /*Checkbox adicionar alarms padrões*/ |
---|
739 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').click(function(){ |
---|
740 | if($(this).attr("checked")){ |
---|
741 | $('input[name="isDefaultAlarm[]"]').parent().remove(); |
---|
742 | var calendarSelected = Calendar.signatureOf[$('select[name="calendar"]').val()]; |
---|
743 | calendarSelected.useAlarmDefault = 1; |
---|
744 | if(calendarSelected.defaultAlarms != ""){ |
---|
745 | var li_attach = DataLayer.render(path+'templates/alarms_add_itemlist.ejs', { |
---|
746 | alarm:calendarSelected |
---|
747 | }); |
---|
748 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({ |
---|
749 | text:false, |
---|
750 | icons:{ |
---|
751 | primary:'ui-icon-close' |
---|
752 | } |
---|
753 | }).click(function(el) { |
---|
754 | var id; |
---|
755 | if( id = $(this).parent().find('input[name="alarmId[]"]').val()) |
---|
756 | DataLayer.remove('alarm', id); |
---|
757 | $(this).parent().remove().find('li').is(':empty') |
---|
758 | }); |
---|
759 | } |
---|
760 | } else { |
---|
761 | $('input[name="isDefaultAlarm[]"]').parent().remove(); |
---|
762 | } |
---|
763 | }); |
---|
764 | /* Checkbox allday */ |
---|
765 | UI.dialogs.addEvent.find('input[name="allDay"]').click(function(){ |
---|
766 | $(this).attr("checked") ? |
---|
767 | UI.dialogs.addEvent.find('.start-time, .end-time').addClass('hidden') : |
---|
768 | UI.dialogs.addEvent.find('.start-time, .end-time').removeClass('hidden'); |
---|
769 | updateMap(true); |
---|
770 | }); |
---|
771 | |
---|
772 | UI.dialogs.addEvent.find('.button').button(); |
---|
773 | UI.dialogs.addEvent.find('.button.add').button({ |
---|
774 | icons: { |
---|
775 | secondary: "ui-icon-plus" |
---|
776 | } |
---|
777 | }); |
---|
778 | |
---|
779 | // ==== validation events ==== |
---|
780 | UI.dialogs.addEvent.find(".input-group .h1").Watermark("Evento sem título"); |
---|
781 | if(User.preferences.hourFormat.length == 5) { |
---|
782 | UI.dialogs.addEvent.find(".end-time, .start-time").mask("99:99", { |
---|
783 | completed: function(){ |
---|
784 | updateMap(); |
---|
785 | } |
---|
786 | }); |
---|
787 | } else { |
---|
788 | $.mask.definitions['{']='[ap]'; |
---|
789 | $.mask.definitions['}']='[m]'; |
---|
790 | UI.dialogs.addEvent.find(".end-time, .start-time").mask("99:99 {}", { |
---|
791 | completed:function(){ |
---|
792 | $(this).val(date.Calendar.defaultToAmPm($(this).val())); |
---|
793 | $(this).timepicker("refresh"); |
---|
794 | $(this).val($(this).val().replace(/[\.]/gi, "")); |
---|
795 | updateMap(); |
---|
796 | } |
---|
797 | }); |
---|
798 | } |
---|
799 | UI.dialogs.addEvent.find(".number").numeric(); |
---|
800 | User.preferences.dateFormat.indexOf('-') > 0 ? |
---|
801 | UI.dialogs.addEvent.find(".date").mask("99-99-9999", { |
---|
802 | completed:function(){ |
---|
803 | updateMap(); |
---|
804 | } |
---|
805 | }) : |
---|
806 | UI.dialogs.addEvent.find(".date").mask("99/99/9999", { |
---|
807 | completed:function(){ |
---|
808 | updateMap(); |
---|
809 | } |
---|
810 | }); |
---|
811 | |
---|
812 | UI.dialogs.addEvent.find(".menu-addevent") |
---|
813 | .children(".delete").click(function(){ |
---|
814 | $.Zebra_Dialog('Tem certeza que deseja excluir o evento?', { |
---|
815 | 'type': 'question', |
---|
816 | 'overlay_opacity': '0.5', |
---|
817 | 'buttons': ['Sim', 'Não'], |
---|
818 | 'onClose': function(clicked) { |
---|
819 | if(clicked == 'Sim'){ |
---|
820 | canDiscardEventDialog = true; |
---|
821 | /* Remove por filtro */ |
---|
822 | DataLayer.removeFilter('schedulable', {filter: ['AND', ['=', 'id', objEvent.id], ['=', 'calendar', objEvent.calendar], ['=','user',(objEvent.me.user ? objEvent.me.user.id : objEvent.me.id)]]}); |
---|
823 | Calendar.rerenderView(true); |
---|
824 | /********************/ |
---|
825 | UI.dialogs.addEvent.dialog("close"); |
---|
826 | } |
---|
827 | } |
---|
828 | }); |
---|
829 | }).end() |
---|
830 | |
---|
831 | .children(".cancel").click(function(){ |
---|
832 | UI.dialogs.addEvent.dialog("close"); |
---|
833 | }).end() |
---|
834 | |
---|
835 | .children(".save").click(function(){ |
---|
836 | /* Validação */ |
---|
837 | var msg = false; |
---|
838 | if(msg = validDateEvent()){ |
---|
839 | $(".new-event-win.active").find('.messages-validation').removeClass('hidden').find('.message label').html(msg); |
---|
840 | return false; |
---|
841 | } |
---|
842 | |
---|
843 | canDiscardEventDialog = true; |
---|
844 | |
---|
845 | var exit = function(event){ |
---|
846 | if(event) |
---|
847 | DataLayer.remove('schedulable', event, false); |
---|
848 | |
---|
849 | UI.dialogs.addEvent.children().find('form.form-addevent').submit(); |
---|
850 | UI.dialogs.addEvent.dialog("close"); |
---|
851 | } |
---|
852 | |
---|
853 | if(repeat){ |
---|
854 | DataLayer.remove('repeat', false); |
---|
855 | DataLayer.put('repeat', repeat); |
---|
856 | DataLayer.commit('repeat', false, exit(repeat.schedulable)); |
---|
857 | }else |
---|
858 | exit(); |
---|
859 | }).end() |
---|
860 | |
---|
861 | .children(".export").click(function(){ |
---|
862 | UI.dialogs.addEvent.children().find(".form-export").submit(); |
---|
863 | }); |
---|
864 | |
---|
865 | var dates = UI.dialogs.addEvent.find('input.date').datepicker({ |
---|
866 | dateFormat: User.preferences.dateFormat.replace(/M/g, 'm').replace(/yyyy/g, 'yy'), |
---|
867 | onSelect : function( selectedDate ){ |
---|
868 | updateMap(); |
---|
869 | } |
---|
870 | }); |
---|
871 | //if(path == ""){ |
---|
872 | UI.dialogs.addEvent.find('input.time').timepicker({ |
---|
873 | closeText: 'Ok', |
---|
874 | hourGrid: 4, |
---|
875 | minuteGrid: 10, |
---|
876 | ampm : ((User.preferences.hourFormat.length > 5) ? true: false), |
---|
877 | timeFormat: "hh:mm tt", |
---|
878 | onSelect: function (selectedDateTime){ |
---|
879 | if(!(User.preferences.hourFormat.length == 5)) |
---|
880 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
881 | updateMap(); |
---|
882 | }, |
---|
883 | onClose : function (selectedDateTime){ |
---|
884 | if(!(User.preferences.hourFormat.length == 5)) |
---|
885 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
886 | } |
---|
887 | }); |
---|
888 | //} |
---|
889 | |
---|
890 | UI.dialogs.addEvent.find('.button-add-alarms').click(function(){ |
---|
891 | var li_attach = DataLayer.render(path+'templates/alarms_add_itemlist.ejs', {}); |
---|
892 | |
---|
893 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({ |
---|
894 | text:false, |
---|
895 | icons:{ |
---|
896 | primary:'ui-icon-close' |
---|
897 | } |
---|
898 | }).click(function(el) { |
---|
899 | $(this).parent().remove().find('li').is(':empty') |
---|
900 | }); |
---|
901 | // valicacao de campos numericos |
---|
902 | $('.number').numeric(); |
---|
903 | }); |
---|
904 | |
---|
905 | |
---|
906 | UI.dialogs.addEvent.find('.button.suggestion-hours').button({ |
---|
907 | icons: { |
---|
908 | primary: "ui-icon-clock" |
---|
909 | }, |
---|
910 | text: 'Sugerir horário' |
---|
911 | }).click(function () { |
---|
912 | $(this).siblings('input').removeAttr('disabled') |
---|
913 | .end().parents().find('input[name="allDay"]').removeAttr('disabled'); |
---|
914 | }); |
---|
915 | |
---|
916 | |
---|
917 | if(!repeat) |
---|
918 | if(objEvent.me.id == User.me.id){ |
---|
919 | objEvent.me.id = DataLayer.put('participant', { |
---|
920 | user: objEvent.me.id, |
---|
921 | mail: objEvent.me.mail |
---|
922 | }); |
---|
923 | objEvent.organizer.id = objEvent.me.id; |
---|
924 | } |
---|
925 | |
---|
926 | var attendeeHtml = DataLayer.render( path+'templates/attendee_add.ejs', { |
---|
927 | event:objEvent |
---|
928 | }); |
---|
929 | |
---|
930 | // load template of attendees |
---|
931 | var blkAddAtendee = UI.dialogs.addEvent.find('#calendar_addevent_details6').append(attendeeHtml); |
---|
932 | if(objEvent.attendee.length) |
---|
933 | callbackAttendee(); |
---|
934 | /** |
---|
935 | Opções de delegação do participante/organizer |
---|
936 | */ |
---|
937 | blkAddAtendee.find(".button.participant-delegate").button({ |
---|
938 | icons: { |
---|
939 | primary: "ui-icon-transferthick-e-w" |
---|
940 | }, |
---|
941 | text: false |
---|
942 | }).click(function () { |
---|
943 | if($(this).hasClass('attendee-permissions-change-button')){ |
---|
944 | if(!$(this).hasClass('disable')){ |
---|
945 | $(this).removeClass('attendee-permissions-change-button') |
---|
946 | .find('.ui-icon-transferthick-e-w').removeClass('attendee-permissions-change').end(); |
---|
947 | blkAddAtendee.find('.block-add-attendee.search').addClass('hidden'); |
---|
948 | blkAddAtendee.find('.block-add-attendee.search dt').html('Adicionar outros contatos'); |
---|
949 | } |
---|
950 | }else{ |
---|
951 | $(this).addClass('attendee-permissions-change-button') |
---|
952 | .find('.ui-icon-transferthick-e-w').addClass('attendee-permissions-change').end(); |
---|
953 | blkAddAtendee.find('.block-add-attendee.search dt').html('Delegar participação para'); |
---|
954 | blkAddAtendee.find('.block-add-attendee.search').removeClass('hidden'); |
---|
955 | blkAddAtendee.find('.block-add-attendee.search input.search').focus(); |
---|
956 | } |
---|
957 | }) |
---|
958 | .addClass('tiny'); |
---|
959 | |
---|
960 | //show or hidden permissions attendees |
---|
961 | //blkAddAtendee.find('.block-attendee-list #attendees-users li').click(show_permissions_attendees); |
---|
962 | |
---|
963 | UI.dialogs.addEvent.find(".attendee-list-add .add-attendee-input input").Watermark("digite um email para convidar"); |
---|
964 | /* Trata a edição de um novo participante adicionado |
---|
965 | * |
---|
966 | */ |
---|
967 | var hasNewAttendee = false; |
---|
968 | |
---|
969 | blkAddAtendee.find('.attendee-list-add .add-attendee-input span').click(function(data){ |
---|
970 | blkAddAtendee.find('.attendee-list-add .add-attendee-input input').keydown(); |
---|
971 | }); |
---|
972 | |
---|
973 | blkAddAtendee.find('.attendee-list-add .add-attendee-input input').keydown(function(event) { |
---|
974 | |
---|
975 | if (event.keyCode == '13' && $(this).val() != '' || (event.keyCode == undefined && $(this).val() != '')) { |
---|
976 | Encoder.EncodeType = "entity"; |
---|
977 | $(this).val(Encoder.htmlEncode($(this).val())); |
---|
978 | |
---|
979 | newAttendeeEmail = false; |
---|
980 | newAttendeeName = false; |
---|
981 | skipAddNewLine = false; |
---|
982 | |
---|
983 | var info = $(this).val(); |
---|
984 | |
---|
985 | /** |
---|
986 | * email válido? |
---|
987 | */ |
---|
988 | info.match(/^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/) ? |
---|
989 | newAttendeeEmail = info : newAttendeeName = info; |
---|
990 | |
---|
991 | /** |
---|
992 | * 1) busca no banco para saber se o usuário já existe |
---|
993 | * 1.1) se existe, atualiza as info na lista de participantes e nao abre o tooltip |
---|
994 | * 1.2) se não existe |
---|
995 | * a) salva como novo usuario externo no banco (apenas com email) |
---|
996 | * b) exibe tooltip pedindo o nome |
---|
997 | * c) se o usuário preenche tooltip e salva, atualiza com o nome o usuário recém criado |
---|
998 | * d) se o usuário cancela o tooltip, fica o usuário salvo apenas com email e sem nome |
---|
999 | */ |
---|
1000 | |
---|
1001 | var user = DataLayer.get('user', ["=", "mail", $(this).val()]); |
---|
1002 | if(!!user && user[0].id) |
---|
1003 | attendees[user[0].id] = { |
---|
1004 | name: user[0].name |
---|
1005 | }; |
---|
1006 | |
---|
1007 | /** |
---|
1008 | * guarda o último tooltip aberto referente à lista de participantes |
---|
1009 | */ |
---|
1010 | lastEditAttendeeToolTip = []; |
---|
1011 | |
---|
1012 | /** |
---|
1013 | * Valida email e salva um participante externo |
---|
1014 | */ |
---|
1015 | var saveContact = function() { |
---|
1016 | Encoder.EncodeType = "entity"; |
---|
1017 | |
---|
1018 | var currentTip = $('.qtip-active'); |
---|
1019 | newAttendeeName = currentTip.find('input[name="name"]').val(); |
---|
1020 | newAttendeeEmail = currentTip.find('input[name="mail"]').val(); |
---|
1021 | |
---|
1022 | if (!(!!newAttendeeEmail.match(/^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/))) { |
---|
1023 | currentTip.find('.messages').removeClass('hidden').find('.message label').html('Email inválido.'); |
---|
1024 | return false; |
---|
1025 | } |
---|
1026 | |
---|
1027 | DataLayer.put('user', { |
---|
1028 | id:userId, |
---|
1029 | name:newAttendeeName, |
---|
1030 | mail:newAttendeeEmail, |
---|
1031 | isExternal:isExternal |
---|
1032 | }); |
---|
1033 | |
---|
1034 | lastEditAttendeeToolTip.find('label') |
---|
1035 | .filter('.name').html(Encoder.htmlEncode(newAttendeeName)).attr('title', Encoder.htmlEncode(newAttendeeName)).end() |
---|
1036 | .filter('.mail').html(Encoder.htmlEncode(newAttendeeEmail)).attr('title', Encoder.htmlEncode(newAttendeeEmail)); |
---|
1037 | |
---|
1038 | blkAddAtendee.find('.attendee-list-add .add-attendee-input input').val(''); |
---|
1039 | return true; |
---|
1040 | } |
---|
1041 | |
---|
1042 | /** |
---|
1043 | * Formata e adequa um tootip abert para edição de um participante na lista |
---|
1044 | */ |
---|
1045 | var onShowToolTip = function(arg0) { |
---|
1046 | $('.qtip-active .button.close').button({ |
---|
1047 | icons: { |
---|
1048 | primary: "ui-icon-close" |
---|
1049 | }, |
---|
1050 | text: false |
---|
1051 | }); |
---|
1052 | $('.qtip-active .button').button() |
---|
1053 | .filter('.save').click(function(event, ui) { |
---|
1054 | if(saveContact()) |
---|
1055 | lastEditAttendeeToolTip.qtip("destroy"); |
---|
1056 | else |
---|
1057 | return false; |
---|
1058 | }).end() |
---|
1059 | .filter('.cancel').click(function(event, ui) { |
---|
1060 | lastEditAttendeeToolTip.qtip("destroy"); |
---|
1061 | }) |
---|
1062 | |
---|
1063 | /** |
---|
1064 | * Trata o ENTER no campo da tooltip, equivalente a salvar |
---|
1065 | * o novo convidado. |
---|
1066 | */ |
---|
1067 | $('.qtip-active input').keydown(function(event) { |
---|
1068 | if (event.keyCode == '13') { |
---|
1069 | if (saveContact()) |
---|
1070 | lastEditAttendeeToolTip.qtip("destroy"); |
---|
1071 | |
---|
1072 | lastEditAttendeeToolTip.qtip("destroy"); |
---|
1073 | event.preventDefault(); |
---|
1074 | } |
---|
1075 | }) |
---|
1076 | .filter('[name="name"]').Watermark("informe o nome do contato").end() |
---|
1077 | .filter('[name="mail"]').Watermark("informe o email do contato"); |
---|
1078 | } |
---|
1079 | |
---|
1080 | /** |
---|
1081 | * Se o email digitado já foi adicionado na lista, |
---|
1082 | * o usuário deve ser avisado e um botão de edição deve ser exibido |
---|
1083 | */ |
---|
1084 | if(blkAddAtendee.find('label.mail[title="' + newAttendeeEmail + '"]').length) { |
---|
1085 | hasNewAttendee = false; |
---|
1086 | newAttendeeName = blkAddAtendee.find('label.mail[title="' + newAttendeeEmail + '"]').parents('li').find('label.name').attr('title'); |
---|
1087 | |
---|
1088 | blkAddAtendee.find('.email-validation').removeClass('hidden') |
---|
1089 | .find('.message label').html("O usuário acima já foi adicionado! <a class=\"small button\">Editar</a>") |
---|
1090 | .find(".button").button().click(function () { |
---|
1091 | /** |
---|
1092 | * Se o usuário optar por editar o participante anteriormente adicionado, |
---|
1093 | * uma tooltip deve ser aberta para este participante, viabilizando a edição |
---|
1094 | */ |
---|
1095 | blkAddAtendee.find("ul.attendee-list").scrollTo('label.mail[title="' + newAttendeeEmail + '"]'); |
---|
1096 | /** |
---|
1097 | * Remove tooltip possivelmente existente |
---|
1098 | */ |
---|
1099 | if (lastEditAttendeeToolTip.length && lastEditAttendeeToolTip.data('qtip')) |
---|
1100 | lastEditAttendeeToolTip.qtip('destroy'); |
---|
1101 | |
---|
1102 | lastEditAttendeeToolTip = blkAddAtendee.find('label.mail[title="' + newAttendeeEmail + '"]').parents('li'); |
---|
1103 | lastEditAttendeeToolTip.qtip({ |
---|
1104 | show: { |
---|
1105 | ready: true, |
---|
1106 | solo: true, |
---|
1107 | when: { |
---|
1108 | event: 'click' |
---|
1109 | } |
---|
1110 | }, |
---|
1111 | hide: false, |
---|
1112 | content: { |
---|
1113 | text: $('<div></div>').html( DataLayer.render( path+'templates/attendee_quick_edit.ejs', { |
---|
1114 | attendee:{ |
---|
1115 | name:newAttendeeName, |
---|
1116 | mail:newAttendeeEmail |
---|
1117 | } |
---|
1118 | } ) ), |
---|
1119 | title: { |
---|
1120 | text:'Detalhes do participante', |
---|
1121 | button: '<a class="button close" href="#">close</a>' |
---|
1122 | } |
---|
1123 | }, |
---|
1124 | style: { |
---|
1125 | name: 'blue', |
---|
1126 | tip: { |
---|
1127 | corner: 'leftMiddle' |
---|
1128 | }, |
---|
1129 | border: { |
---|
1130 | width: 4, |
---|
1131 | radius: 8 |
---|
1132 | }, |
---|
1133 | width: { |
---|
1134 | min: 230, |
---|
1135 | max:230 |
---|
1136 | } |
---|
1137 | }, |
---|
1138 | position: { |
---|
1139 | corner: { |
---|
1140 | target: 'rightMiddle', |
---|
1141 | tooltip: 'leftMiddle' |
---|
1142 | }, |
---|
1143 | adjust: { |
---|
1144 | x:0, |
---|
1145 | y:0 |
---|
1146 | } |
---|
1147 | } |
---|
1148 | }); |
---|
1149 | lastEditAttendeeToolTip.qtip("api").onShow = onShowToolTip; |
---|
1150 | }); |
---|
1151 | skipAddNewLine = true; |
---|
1152 | } else { |
---|
1153 | hasNewAttendee = true; |
---|
1154 | blkAddAtendee.find('.email-validation').addClass('hidden'); |
---|
1155 | } |
---|
1156 | |
---|
1157 | |
---|
1158 | var isExternal = (!!user && !(!!user.isExternal)) ? 0 : 1; |
---|
1159 | |
---|
1160 | /** |
---|
1161 | * Remove tooltip possivelmente existente |
---|
1162 | */ |
---|
1163 | if (lastEditAttendeeToolTip.length && lastEditAttendeeToolTip.data('qtip')) |
---|
1164 | lastEditAttendeeToolTip.qtip('destroy'); |
---|
1165 | |
---|
1166 | userId = ''; |
---|
1167 | var newAttendeeId = ''; |
---|
1168 | |
---|
1169 | if (user){ |
---|
1170 | if (!skipAddNewLine) { |
---|
1171 | user[0].id = DataLayer.put('participant', { |
---|
1172 | user: user[0].id, |
---|
1173 | isExternal: isExternal, |
---|
1174 | acl: 'r' |
---|
1175 | }); |
---|
1176 | user[0].acl = objEvent.acl; |
---|
1177 | user[0].isDirty = !!!objEvent.id; |
---|
1178 | |
---|
1179 | blkAddAtendee.find('dd.attendee-list ul.attendee-list').append( |
---|
1180 | DataLayer.render(path+'templates/participants_add_itemlist.ejs', user) |
---|
1181 | ) |
---|
1182 | .scrollTo('max'); |
---|
1183 | callbackAttendee(); |
---|
1184 | } |
---|
1185 | |
---|
1186 | $(this).val(''); |
---|
1187 | |
---|
1188 | } else if (!skipAddNewLine) { |
---|
1189 | /** |
---|
1190 | * a) salva como novo usuario externo no banco (apenas com email) e... |
---|
1191 | * adiciona novo contato externo à lista de convidados |
---|
1192 | */ |
---|
1193 | |
---|
1194 | userId = DataLayer.put('user', { |
---|
1195 | name: newAttendeeName, |
---|
1196 | mail: newAttendeeEmail, |
---|
1197 | isExternal: isExternal |
---|
1198 | }); |
---|
1199 | newAttendeeId = DataLayer.put('participant', { |
---|
1200 | user: userId, |
---|
1201 | isExternal: isExternal |
---|
1202 | }); |
---|
1203 | |
---|
1204 | |
---|
1205 | blkAddAtendee.find('dd.attendee-list ul.attendee-list').append( |
---|
1206 | DataLayer.render(path+'templates/participants_add_itemlist.ejs', [{ |
---|
1207 | id:newAttendeeId, |
---|
1208 | name: newAttendeeName, |
---|
1209 | mail: newAttendeeEmail, |
---|
1210 | isExternal: 1, |
---|
1211 | acl: objEvent.acl, |
---|
1212 | isDirty: !!!objEvent.id |
---|
1213 | }]) |
---|
1214 | ).scrollTo('max'); |
---|
1215 | callbackAttendee(); |
---|
1216 | |
---|
1217 | /** |
---|
1218 | * Adiciona tootip para atualização dos dados do contato externo |
---|
1219 | * recém adicionado. |
---|
1220 | */ |
---|
1221 | lastEditAttendeeToolTip = blkAddAtendee.find('dd.attendee-list li:last'); |
---|
1222 | lastEditAttendeeToolTip.qtip({ |
---|
1223 | show: { |
---|
1224 | ready: true, |
---|
1225 | solo: true, |
---|
1226 | when: { |
---|
1227 | event: 'click' |
---|
1228 | } |
---|
1229 | }, |
---|
1230 | hide: false, |
---|
1231 | content: { |
---|
1232 | text: $('<div></div>').html( DataLayer.render( path+'templates/attendee_quick_edit.ejs', { |
---|
1233 | attendee:{ |
---|
1234 | name:newAttendeeName, |
---|
1235 | mail:newAttendeeEmail |
---|
1236 | } |
---|
1237 | } ) ), |
---|
1238 | title: { |
---|
1239 | text:'Detalhes do participante', |
---|
1240 | button: '<a class="button close" href="#">close</a>' |
---|
1241 | } |
---|
1242 | }, |
---|
1243 | style: { |
---|
1244 | name: 'blue', |
---|
1245 | tip: { |
---|
1246 | corner: 'leftMiddle' |
---|
1247 | }, |
---|
1248 | border: { |
---|
1249 | width: 4, |
---|
1250 | radius: 8 |
---|
1251 | }, |
---|
1252 | width: { |
---|
1253 | min: 230, |
---|
1254 | max:230 |
---|
1255 | } |
---|
1256 | }, |
---|
1257 | position: { |
---|
1258 | corner: { |
---|
1259 | target: 'rightMiddle', |
---|
1260 | tooltip: 'leftMiddle' |
---|
1261 | }, |
---|
1262 | adjust: { |
---|
1263 | x:0, |
---|
1264 | y:0 |
---|
1265 | } |
---|
1266 | } |
---|
1267 | }); |
---|
1268 | |
---|
1269 | lastEditAttendeeToolTip.qtip("api").onShow = onShowToolTip; |
---|
1270 | |
---|
1271 | $(this).val(''); |
---|
1272 | |
---|
1273 | |
---|
1274 | } |
---|
1275 | event.preventDefault(); |
---|
1276 | } |
---|
1277 | |
---|
1278 | }); |
---|
1279 | |
---|
1280 | /** |
---|
1281 | * Trata a busca de usuários para adição de participantes |
---|
1282 | */ |
---|
1283 | blkAddAtendee.find('.add-attendee-search .ui-icon-search').click(function(event) { |
---|
1284 | blkAddAtendee.find('.add-attendee-search input').keydown(); |
---|
1285 | }); |
---|
1286 | |
---|
1287 | |
---|
1288 | blkAddAtendee.find('.add-attendee-search input').keydown(function(event) { |
---|
1289 | |
---|
1290 | if(event.keyCode == '13' || typeof(event.keyCode) == 'undefined') { |
---|
1291 | var result = DataLayer.get('user', ["*", "name", $(this).val()], true); |
---|
1292 | |
---|
1293 | /** |
---|
1294 | * TODO: trocar por template |
---|
1295 | */ |
---|
1296 | blkAddAtendee.find('ul.search-result-list').empty().css('overflow', 'hidden'); |
---|
1297 | if (!result) { |
---|
1298 | blkAddAtendee.find('ul.search-result-list').append('<li><label class="empty">Nenhum resultado encontrado.</label></li>'); |
---|
1299 | } |
---|
1300 | |
---|
1301 | for(i=0; i<result.length; i++) |
---|
1302 | result[i].enabled = (blkAddAtendee.find('dd.attendee-list ul.attendee-list label.mail[title="' + result[i].mail + '"]').length) ? false : true; |
---|
1303 | |
---|
1304 | blkAddAtendee.find('ul.search-result-list').append(DataLayer.render( path+'templates/participants_search_itemlist.ejs', result)); |
---|
1305 | |
---|
1306 | blkAddAtendee.find('ul.search-result-list li').click(function(event, ui){ |
---|
1307 | if ($(event.target).is('input')) { |
---|
1308 | old_item = $(event.target).parents('li'); |
---|
1309 | newAttendeeId = DataLayer.put('participant', { |
---|
1310 | user: old_item.find('.id').html(), |
---|
1311 | isExternal: old_item.find('.isExternal').html() |
---|
1312 | }); |
---|
1313 | |
---|
1314 | attendees[old_item.find('.id').html()] = old_item.find('.name').html(); |
---|
1315 | |
---|
1316 | blkAddAtendee.find('dd.attendee-list ul.attendee-list') |
---|
1317 | .append(DataLayer.render(path+'templates/participants_add_itemlist.ejs', [{ |
---|
1318 | id: newAttendeeId, |
---|
1319 | name: old_item.find('.name').html(), |
---|
1320 | mail: old_item.find('.mail').html(), |
---|
1321 | isExternal: old_item.find('.isExternal').html(), |
---|
1322 | acl: objEvent.acl, |
---|
1323 | isDirty: !!!objEvent.id |
---|
1324 | }])) |
---|
1325 | .scrollTo('max'); |
---|
1326 | /** |
---|
1327 | * Delegação de participação de um participante com permissão apenas de leitura |
---|
1328 | * |
---|
1329 | */ |
---|
1330 | if(!objEvent.acl.organization && !objEvent.acl.write && !objEvent.acl.inviteGuests && objEvent.acl.read ){ |
---|
1331 | |
---|
1332 | blkAddAtendee.find('.block-add-attendee.search').addClass('hidden'); |
---|
1333 | blkAddAtendee.find('.block-add-attendee.search dt').html('Adicionar outros contatos'); |
---|
1334 | |
---|
1335 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
1336 | blkAddAtendee.find('option[value=5]').attr('selected','selected').trigger('change'); |
---|
1337 | blkAddAtendee.find('.request-update').removeClass('hidden'); |
---|
1338 | |
---|
1339 | blkAddAtendee.find('dd.attendee-list ul.attendee-list li .button.close').parents('li').find('input[name="delegatedFrom[]"]').val(blkAddAtendee.find('.me input[name="attendee[]"]').val()); |
---|
1340 | |
---|
1341 | blkAddAtendee.find('.me .participant-delegate').addClass('disable ui-button-disabled ui-state-disabled'); |
---|
1342 | blkAddAtendee.find(".button.close").button({ |
---|
1343 | icons: { |
---|
1344 | primary: "ui-icon-close" |
---|
1345 | }, |
---|
1346 | text: false |
---|
1347 | }).click(function () { |
---|
1348 | |
---|
1349 | $(this).parents('li').find('input[name="delegatedFrom[]"]').val(''); |
---|
1350 | blkAddAtendee.find('.request-update').addClass('hidden'); |
---|
1351 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
1352 | blkAddAtendee.find('option[value=1]').attr('selected','selected').trigger('change'); |
---|
1353 | blkAddAtendee.find('.me .participant-delegate').removeClass('disable ui-button-disabled ui-state-disabled attendee-permissions-change-button') |
---|
1354 | .find('.ui-icon-person').removeClass('attendee-permissions-change').end(); |
---|
1355 | |
---|
1356 | DataLayer.remove('participant', $(this).parents('li').find('[type=checkbox]').val()); |
---|
1357 | $(this).parents('li').remove(); |
---|
1358 | }) |
---|
1359 | .addClass('tiny'); |
---|
1360 | }else{ |
---|
1361 | callbackAttendee(); |
---|
1362 | old_item.remove(); |
---|
1363 | } |
---|
1364 | } |
---|
1365 | }); |
---|
1366 | |
---|
1367 | event.preventDefault(); |
---|
1368 | } |
---|
1369 | }); |
---|
1370 | //$('.block-add-attendee .search-result-list').selectable(); |
---|
1371 | |
---|
1372 | UI.dialogs.addEvent.find('.row.fileupload-buttonbar .button').filter('.delete').button({ |
---|
1373 | icons: { |
---|
1374 | primary: "ui-icon-close" |
---|
1375 | }, |
---|
1376 | text: 'Excluir' |
---|
1377 | }).click(function () { |
---|
1378 | $.Zebra_Dialog('Tem certeza que deseja excluir todos anexos?', { |
---|
1379 | 'type': 'question', |
---|
1380 | 'overlay_opacity': '0.5', |
---|
1381 | 'buttons': ['Sim', 'Não'], |
---|
1382 | 'onClose': function(clicked) { |
---|
1383 | if(clicked == 'Sim'){ |
---|
1384 | |
---|
1385 | var ids = []; |
---|
1386 | $.each($('.attachment-list input'), function (i, input) { |
---|
1387 | DataLayer.remove('schedulableToAttachment', { |
---|
1388 | filter: ['=', 'id', ''+input.value] |
---|
1389 | }); |
---|
1390 | }); |
---|
1391 | $('.attachment-list input').remove(); |
---|
1392 | $('.row.fileupload-buttonbar .attachments-list p').remove(); |
---|
1393 | } |
---|
1394 | }}); |
---|
1395 | }).end() |
---|
1396 | .filter('.close').button({ |
---|
1397 | icons: { |
---|
1398 | primary: "ui-icon-close" |
---|
1399 | }, |
---|
1400 | text: false |
---|
1401 | }).click(function () { |
---|
1402 | DataLayer.remove('schedulableToAttachment', $(this).parents('p').find('input[name="fileId[]"]').val()); |
---|
1403 | $(this).parents('p').remove(); |
---|
1404 | }).end() |
---|
1405 | .filter('.downlaod-archive').button({ |
---|
1406 | icons: { |
---|
1407 | primary: "ui-icon-arrowthickstop-1-s" |
---|
1408 | }, |
---|
1409 | text: false |
---|
1410 | }); |
---|
1411 | var maxSizeFile = 2000000; |
---|
1412 | $('#fileupload').fileupload({ |
---|
1413 | sequentialUploads: true, |
---|
1414 | add: function (e, data) { |
---|
1415 | if(data.files[0].size < maxSizeFile) |
---|
1416 | data.submit(); |
---|
1417 | }, |
---|
1418 | change: function (e, data) { |
---|
1419 | $.each(data.files, function (index, file) { |
---|
1420 | var attach = {}; |
---|
1421 | attach.fileName = file.name; |
---|
1422 | var ext = file.name.split('.'); |
---|
1423 | if(file.name.length > 10) |
---|
1424 | attach.fileName = ext.length == 1 ? file.name.substr(0, 10) : file.name.substr(0, 6) + '.' + ext[ext.length -1]; |
---|
1425 | attach.fileSize = formatBytes(file.size); |
---|
1426 | if(file.size > maxSizeFile) |
---|
1427 | attach.error = 'Tamanho de arquivo nao permitido!!' |
---|
1428 | |
---|
1429 | $('.attachments-list').append(DataLayer.render(path+'templates/attachment_add_itemlist.ejs', { |
---|
1430 | file : attach |
---|
1431 | })); |
---|
1432 | |
---|
1433 | if(file.size < maxSizeFile){ |
---|
1434 | $('.fileinput-button.new').append(data.fileInput[0]).removeClass('new'); |
---|
1435 | $('.attachments-list').find('[type=file]').addClass('hidden'); |
---|
1436 | |
---|
1437 | }else |
---|
1438 | $('.fileinput-button.new').removeClass('new'); |
---|
1439 | |
---|
1440 | |
---|
1441 | $('.attachments-list').find('.button.close').button({ |
---|
1442 | icons: { |
---|
1443 | primary: "ui-icon-close" |
---|
1444 | }, |
---|
1445 | text: false |
---|
1446 | }).click(function(){ |
---|
1447 | var idAttach = $(this).parent().find('input[name="fileId[]"]').val(); |
---|
1448 | $('.attachment-list').find('input[value="'+idAttach+'"]') |
---|
1449 | $(this).parent().remove(); |
---|
1450 | }); |
---|
1451 | |
---|
1452 | }) |
---|
1453 | }, |
---|
1454 | done: function(e, data){ |
---|
1455 | var currentUpload = $('.progress.after-upload:first').removeClass('after-upload').addClass('on-complete').hide(); |
---|
1456 | |
---|
1457 | if(!!data.result && data.result != "[]"){ |
---|
1458 | var newAttach = (attch = jQuery.parseJSON(data.result)) ? attch : jQuery.parseJSON(data.result[0].activeElement.childNodes[0].data); |
---|
1459 | $('.attachment-list').append('<input tyepe="hidden" name="attachment[]" value="'+newAttach['attachment'][0][0].id+'"/>'); |
---|
1460 | currentUpload.removeClass('on-complete').parents('p') |
---|
1461 | .append('<input type="hidden" name="fileId[]" value="'+newAttach['attachment'][0][0].id+'"/>') |
---|
1462 | .find('.status-upload').addClass('ui-icon ui-icon-check'); |
---|
1463 | }else |
---|
1464 | currentUpload.removeClass('on-complete').parents('p').find('.status-upload').addClass('ui-icon ui-icon-cancel'); |
---|
1465 | } |
---|
1466 | }); |
---|
1467 | $('.attachments-list .button').button(); |
---|
1468 | |
---|
1469 | if(!!window.FormData) |
---|
1470 | $('#fileupload').bind('fileuploadstart', function () { |
---|
1471 | var widget = $(this), |
---|
1472 | progressElement = $('#fileupload-progress').fadeIn(), |
---|
1473 | interval = 500, |
---|
1474 | total = 0, |
---|
1475 | loaded = 0, |
---|
1476 | loadedBefore = 0, |
---|
1477 | progressTimer, |
---|
1478 | progressHandler = function (e, data) { |
---|
1479 | loaded = data.loaded; |
---|
1480 | total = data.total; |
---|
1481 | }, |
---|
1482 | stopHandler = function () { |
---|
1483 | widget |
---|
1484 | .unbind('fileuploadprogressall', progressHandler) |
---|
1485 | .unbind('fileuploadstop', stopHandler); |
---|
1486 | window.clearInterval(progressTimer); |
---|
1487 | progressElement.fadeOut(function () { |
---|
1488 | progressElement.html(''); |
---|
1489 | }); |
---|
1490 | }, |
---|
1491 | formatTime = function (seconds) { |
---|
1492 | var date = new Date(seconds * 1000); |
---|
1493 | return ('0' + date.getUTCHours()).slice(-2) + ':' + |
---|
1494 | ('0' + date.getUTCMinutes()).slice(-2) + ':' + |
---|
1495 | ('0' + date.getUTCSeconds()).slice(-2); |
---|
1496 | }, |
---|
1497 | /* formatBytes = function (bytes) { |
---|
1498 | if (bytes >= 1000000000) { |
---|
1499 | return (bytes / 1000000000).toFixed(2) + ' GB'; |
---|
1500 | } |
---|
1501 | if (bytes >= 1000000) { |
---|
1502 | return (bytes / 1000000).toFixed(2) + ' MB'; |
---|
1503 | } |
---|
1504 | if (bytes >= 1000) { |
---|
1505 | return (bytes / 1000).toFixed(2) + ' KB'; |
---|
1506 | } |
---|
1507 | return bytes + ' B'; |
---|
1508 | },*/ |
---|
1509 | formatPercentage = function (floatValue) { |
---|
1510 | return (floatValue * 100).toFixed(2) + ' %'; |
---|
1511 | }, |
---|
1512 | updateProgressElement = function (loaded, total, bps) { |
---|
1513 | progressElement.html( |
---|
1514 | formatBytes(bps) + 'ps | ' + |
---|
1515 | formatTime((total - loaded) / bps) + ' | ' + |
---|
1516 | formatPercentage(loaded / total) + ' | ' + |
---|
1517 | formatBytes(loaded) + ' / ' + formatBytes(total) |
---|
1518 | ); |
---|
1519 | }, |
---|
1520 | intervalHandler = function () { |
---|
1521 | var diff = loaded - loadedBefore; |
---|
1522 | if (!diff) { |
---|
1523 | return; |
---|
1524 | } |
---|
1525 | loadedBefore = loaded; |
---|
1526 | updateProgressElement( |
---|
1527 | loaded, |
---|
1528 | total, |
---|
1529 | diff * (1000 / interval) |
---|
1530 | ); |
---|
1531 | }; |
---|
1532 | widget |
---|
1533 | .bind('fileuploadprogressall', progressHandler) |
---|
1534 | .bind('fileuploadstop', stopHandler); |
---|
1535 | progressTimer = window.setInterval(intervalHandler, interval); |
---|
1536 | }); |
---|
1537 | |
---|
1538 | if(objEvent.isShared){ |
---|
1539 | |
---|
1540 | var acls = Calendar.signatureOf[objEvent.calendar].permission.acl; |
---|
1541 | |
---|
1542 | if(!acls.write){ |
---|
1543 | UI.dialogs.addEvent.find(':input').attr('disabled', 'disabled'); |
---|
1544 | UI.dialogs.addEvent.find('.button').hide(); |
---|
1545 | } |
---|
1546 | |
---|
1547 | if(acls.remove) |
---|
1548 | UI.dialogs.addEvent.find('.button.remove').show(); |
---|
1549 | |
---|
1550 | UI.dialogs.addEvent.find('.button.cancel').show(); |
---|
1551 | } |
---|
1552 | |
---|
1553 | disponibily(objEvent, path, attendees); |
---|
1554 | |
---|
1555 | /*Seleciona a agenda padrão para criação de um evento*/ |
---|
1556 | if(!objEvent.id){ |
---|
1557 | var selectedCalendar = (objEvent.calendar != undefined) ? objEvent.calendar : (User.preferences.defaultCalendar ? User.preferences.defaultCalendar : myCalendar()); |
---|
1558 | UI.dialogs.addEvent.find('option[value="'+selectedCalendar+'"]').attr('selected','selected').trigger('change'); |
---|
1559 | } |
---|
1560 | UI.dialogs.addEvent.find(':input').change(function(event){ |
---|
1561 | if (event.keyCode != '27' && event.keyCode != '13') |
---|
1562 | canDiscardEventDialog = false; |
---|
1563 | }).keydown(function(event){ |
---|
1564 | if (event.keyCode != '27' && event.keyCode != '13') |
---|
1565 | canDiscardEventDialog = false; |
---|
1566 | }); |
---|
1567 | |
---|
1568 | UI.dialogs.addEvent.dialog('open'); |
---|
1569 | //$('[href="#calendar_addevent_details7"]').trigger('click'); |
---|
1570 | //$('[href="#calendar_addevent_details2"]').trigger('click'); |
---|
1571 | } |
---|
1572 | |
---|
1573 | |
---|
1574 | |
---|
1575 | function add_tab_preferences() |
---|
1576 | { |
---|
1577 | if(!(document.getElementById('preference_tab'))) |
---|
1578 | { |
---|
1579 | var tab_title = "Preferencias"; |
---|
1580 | $tabs.tabs( "add", "#preference_tab", tab_title ); |
---|
1581 | |
---|
1582 | /* |
---|
1583 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
1584 | tabPrefCalendar.find('select[name="timezone"]').html(timezones_options).find('option[value="'+User.preferences.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
1585 | }); |
---|
1586 | */ |
---|
1587 | DataLayer.render( 'templates/preferences_calendar.ejs', { |
---|
1588 | preferences:User.preferences, |
---|
1589 | calendars: Calendar.calendars |
---|
1590 | }, function( template ){ |
---|
1591 | var tabPrefCalendar = jQuery('#preference_tab').html( template ).find('.preferences-win'); |
---|
1592 | |
---|
1593 | tabPrefCalendar.find('option[value="'+User.preferences.defaultCalendar+'"]').attr('selected','selected').trigger('change'); |
---|
1594 | |
---|
1595 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
1596 | tabPrefCalendar.find('select[name="timezone"]').html(timezones_options).find('option[value="'+User.preferences.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
1597 | }); |
---|
1598 | |
---|
1599 | tabPrefCalendar.find('.button').button() |
---|
1600 | .filter('.save').click(function(evt){ |
---|
1601 | tabPrefCalendar.find('form').submit(); |
---|
1602 | $('#calendar').fullCalendar('render'); |
---|
1603 | $('.block-vertical-toolbox .mini-calendar').datepicker( "refresh" ); |
---|
1604 | $tabs.tabs( "remove", "#preference_tab"); |
---|
1605 | }).end().filter('.cancel').click(function(evt){ |
---|
1606 | $tabs.tabs( "remove", "#preference_tab"); |
---|
1607 | }); |
---|
1608 | |
---|
1609 | tabPrefCalendar.find('.number').numeric(); |
---|
1610 | |
---|
1611 | tabPrefCalendar.find('input.time').timepicker({ |
---|
1612 | closeText: 'Ok', |
---|
1613 | hourGrid: 4, |
---|
1614 | minuteGrid: 10, |
---|
1615 | ampm : (parseInt($("select[name=hourFormat] option:selected").val().length) > 5 ? true : false), //((User.preferences.hourFormat.length > 5) ? true: false), |
---|
1616 | timeFormat: "hh:mm tt", |
---|
1617 | onSelect: function (selectedDateTime){ |
---|
1618 | if(!(User.preferences.hourFormat.length == 5)) { |
---|
1619 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
1620 | } |
---|
1621 | }, |
---|
1622 | onClose : function (selectedDateTime){ |
---|
1623 | if(!(User.preferences.hourFormat.length == 5)) { |
---|
1624 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
1625 | } |
---|
1626 | } |
---|
1627 | }); |
---|
1628 | |
---|
1629 | $.mask.definitions['{']='[ap]'; |
---|
1630 | $.mask.definitions['}']='[m]'; |
---|
1631 | tabPrefCalendar.find("input.time").mask( ((User.preferences.hourFormat.length > 5) ? "99:99 {}" : "99:99"), { |
---|
1632 | completed:function(){ |
---|
1633 | $(this).val(dateCalendar.defaultToAmPm($(this).val())); |
---|
1634 | $(this).timepicker("refresh"); |
---|
1635 | $(this).val($(this).val().replace(/[\.]/gi, "")); |
---|
1636 | } |
---|
1637 | }); |
---|
1638 | |
---|
1639 | tabPrefCalendar.find("select[name=hourFormat]").change( function() { // evento ao selecionar formato de hora |
---|
1640 | |
---|
1641 | tabPrefCalendar.find("input.time").timepicker("destroy"); |
---|
1642 | |
---|
1643 | tabPrefCalendar.find('input.time').timepicker({ |
---|
1644 | closeText: 'Ok', |
---|
1645 | hourGrid: 4, |
---|
1646 | minuteGrid: 10, |
---|
1647 | ampm : (parseInt($("select[name=hourFormat] option:selected").val().length) > 5 ? true : false), |
---|
1648 | timeFormat: "hh:mm tt", |
---|
1649 | onSelect: function (selectedDateTime){ |
---|
1650 | if(!(User.preferences.hourFormat.length == 5)) { |
---|
1651 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
1652 | } |
---|
1653 | }, |
---|
1654 | onClose : function (selectedDateTime){ |
---|
1655 | if(!(User.preferences.hourFormat.length == 5)) { |
---|
1656 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
1657 | } |
---|
1658 | } |
---|
1659 | }); |
---|
1660 | |
---|
1661 | var defaultStartHour = tabPrefCalendar.find("input[name=defaultStartHour]").val().trim(); |
---|
1662 | var defaultEndHour = tabPrefCalendar.find("input[name=defaultEndHour]").val().trim(); |
---|
1663 | |
---|
1664 | tabPrefCalendar.find("input.time").mask( (($("select[name=hourFormat] option:selected").val().trim().length > 5) ? "99:99 {}" : "99:99") ); |
---|
1665 | |
---|
1666 | if (parseInt($("select[name=hourFormat] option:selected").val().length) > 5) { // am/pm |
---|
1667 | tabPrefCalendar.find("input[name=defaultStartHour]").val(dateCalendar.defaultToAmPm(defaultStartHour)); |
---|
1668 | tabPrefCalendar.find("input[name=defaultEndHour]").val(dateCalendar.defaultToAmPm(defaultEndHour)) |
---|
1669 | |
---|
1670 | } else { //24h |
---|
1671 | tabPrefCalendar.find("input[name=defaultStartHour]").val(dateCalendar.AmPmTo24(defaultStartHour)); |
---|
1672 | tabPrefCalendar.find("input[name=defaultEndHour]").val(dateCalendar.AmPmTo24(defaultEndHour)); |
---|
1673 | } |
---|
1674 | }); |
---|
1675 | |
---|
1676 | |
---|
1677 | |
---|
1678 | }); |
---|
1679 | } else { |
---|
1680 | $tabs.tabs("select", "#preference_tab"); |
---|
1681 | |
---|
1682 | return true; |
---|
1683 | } |
---|
1684 | } |
---|
1685 | |
---|
1686 | |
---|
1687 | function add_tab_configure_calendar(calendar) |
---|
1688 | { |
---|
1689 | var calendars = []; |
---|
1690 | var signatures = []; |
---|
1691 | var previewActiveCalendarConf = 0; |
---|
1692 | var calendarAlarms = []; |
---|
1693 | |
---|
1694 | for (var i=0; i<Calendar.signatures.length; i++) { |
---|
1695 | calendars[i] = Calendar.signatures[i].calendar; |
---|
1696 | signatures[i] = Calendar.signatures[i]; |
---|
1697 | signatures[i].numberDefaultAlarm = signatures[i].defaultAlarms != '' ? signatures[i].defaultAlarms.length: 0; |
---|
1698 | if (calendar && calendars[i].id == calendar) |
---|
1699 | previewActiveCalendarConf = i; |
---|
1700 | } |
---|
1701 | |
---|
1702 | if(!(document.getElementById('configure_tab'))) |
---|
1703 | { |
---|
1704 | $('.positionHelper').css('display', 'none'); |
---|
1705 | var tab_title = "Configurações de agendas"; |
---|
1706 | $tabs.tabs( "add", "#configure_tab", tab_title ); |
---|
1707 | |
---|
1708 | var dataColorPicker = { |
---|
1709 | colorsSuggestions: colors_suggestions() |
---|
1710 | }; |
---|
1711 | |
---|
1712 | |
---|
1713 | |
---|
1714 | var populateAccordionOnActive = function(event, ui) { |
---|
1715 | var nowActive = (typeof(event) == 'number') ? event : $(event.target).accordion( "option", "active" ); |
---|
1716 | dataColorPicker.colorsDefined = { |
---|
1717 | border: '#'+signatures[nowActive].borderColor, |
---|
1718 | font:'#'+signatures[nowActive].fontColor, |
---|
1719 | background:'#'+signatures[nowActive].backgroundColor |
---|
1720 | }; |
---|
1721 | if (!jQuery('.accordion-user-calendars .ui-accordion-content').eq(nowActive).has('form')) { |
---|
1722 | return true; |
---|
1723 | } |
---|
1724 | |
---|
1725 | DataLayer.render( 'templates/configure_calendars_itemlist.ejs', { |
---|
1726 | user:User, |
---|
1727 | calendar:calendars[nowActive], |
---|
1728 | signature:signatures[nowActive] |
---|
1729 | }, function( form_template ){ |
---|
1730 | var form_content = jQuery('.accordion-user-calendars .ui-accordion-content').eq(nowActive).html( form_template ).find('form'); |
---|
1731 | form_content.find('.preferences-alarms-list .button').button({ |
---|
1732 | text:false, |
---|
1733 | icons:{ |
---|
1734 | primary:'ui-icon-close' |
---|
1735 | } |
---|
1736 | }); |
---|
1737 | form_content.find('.button').button(); |
---|
1738 | jQuery('.preferences-alarms-list').find('.button.remove').click(function(el){ |
---|
1739 | calendarAlarms[calendarAlarms.length] = $(this).parent('li').find('input[name="alarmId[]"]').val(); |
---|
1740 | $(this).parent().remove(); |
---|
1741 | }); |
---|
1742 | |
---|
1743 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
1744 | var valueTimeZone = calendars[nowActive].timezone; |
---|
1745 | form_content.find('select[name="timezone"]').html(timezones_options).find('option[value="'+valueTimeZone+'"]').attr('selected','selected').trigger('change'); |
---|
1746 | }); |
---|
1747 | |
---|
1748 | form_content.find('.button-add-alarms').click(function(){ |
---|
1749 | DataLayer.render( 'templates/alarms_add_itemlist.ejs', {}, function( template ){ |
---|
1750 | jQuery('.preferences-alarms-list').append(template) |
---|
1751 | .find('li:last label:eq(0)').remove().end() |
---|
1752 | .find('.number').numeric().end() |
---|
1753 | .find('.button.remove').button({ |
---|
1754 | text:false, |
---|
1755 | icons:{ |
---|
1756 | primary:'ui-icon-close' |
---|
1757 | } |
---|
1758 | }).click(function(el) { |
---|
1759 | $(this).parent().remove(); |
---|
1760 | }); |
---|
1761 | }); |
---|
1762 | }); |
---|
1763 | |
---|
1764 | |
---|
1765 | /** |
---|
1766 | * Set color picker |
---|
1767 | */ |
---|
1768 | DataLayer.render( 'templates/calendar_colorpicker.ejs', dataColorPicker, function( template ){ |
---|
1769 | form_content.find('.calendar-colorpicker').html( template ); |
---|
1770 | |
---|
1771 | var f = $.farbtastic(form_content.find('.colorpicker'), colorpickerPreviewChange); |
---|
1772 | var selected; |
---|
1773 | var colorpicker = form_content.find('.calendar-colorpicker'); |
---|
1774 | |
---|
1775 | var colorpickerPreviewChange = function(color) { |
---|
1776 | var pickedup = form_content.find('.colorwell-selected').val(color).css('background-color', color); |
---|
1777 | |
---|
1778 | var colorpicker = form_content.find('.calendar-colorpicker'); |
---|
1779 | |
---|
1780 | if (pickedup.is('input[name="backgroundColor"]')) { |
---|
1781 | colorpicker.find('.fc-event-skin').css('background-color',color); |
---|
1782 | } else if (pickedup.is('input[name="fontColor"]')) { |
---|
1783 | colorpicker.find('.fc-event-skin').css('color',color); |
---|
1784 | } else if (pickedup.is('input[name="borderColor"]')) { |
---|
1785 | colorpicker.find('.fc-event-skin').css('border-color',color); |
---|
1786 | } |
---|
1787 | } |
---|
1788 | |
---|
1789 | form_content.find('.colorwell').each(function () { |
---|
1790 | f.linkTo(this); |
---|
1791 | |
---|
1792 | if ($(this).is('input[name="backgroundColor"]')) { |
---|
1793 | colorpicker.find('.fc-event-skin').css('background-color', $(this).val()); |
---|
1794 | } else if ($(this).is('input[name="fontColor"]')) { |
---|
1795 | colorpicker.find('.fc-event-skin').css('color', $(this).val()); |
---|
1796 | } else if ($(this).is('input[name="borderColor"]')) { |
---|
1797 | colorpicker.find('.fc-event-skin').css('border-color', $(this).val()); |
---|
1798 | } |
---|
1799 | }) |
---|
1800 | .focus(function() { |
---|
1801 | if (selected) { |
---|
1802 | $(selected).removeClass('colorwell-selected'); |
---|
1803 | } |
---|
1804 | |
---|
1805 | $(selected = this).addClass('colorwell-selected'); |
---|
1806 | f.linkTo(this, colorpickerPreviewChange); |
---|
1807 | f.linkTo(colorpickerPreviewChange); |
---|
1808 | |
---|
1809 | }); |
---|
1810 | |
---|
1811 | form_content.find('select.color-suggestions').change(function() { |
---|
1812 | var colors; |
---|
1813 | |
---|
1814 | if(colors = dataColorPicker.colorsSuggestions[$(this).val()]) { |
---|
1815 | colorpicker |
---|
1816 | .find('input[name="fontColor"]').val(colors.font).focus().end() |
---|
1817 | .find('input[name="backgroundColor"]').val(colors.background).focus().end() |
---|
1818 | .find('input[name="borderColor"]').val(colors.border).focus().end() |
---|
1819 | |
---|
1820 | .find('.fc-event-skin').css({ |
---|
1821 | 'background-color':dataColorPicker.colorsSuggestions[$(this).val()].background, |
---|
1822 | 'border-color':dataColorPicker.colorsSuggestions[$(this).val()].border, |
---|
1823 | 'color':dataColorPicker.colorsSuggestions[$(this).val()].font |
---|
1824 | }); |
---|
1825 | } |
---|
1826 | }); |
---|
1827 | |
---|
1828 | /** |
---|
1829 | * Trata a mudança dos valores dos campos de cores. |
---|
1830 | * Se mudar um conjunto de cores sugerido, |
---|
1831 | * este vira um conjunto de cores personalizado. |
---|
1832 | */ |
---|
1833 | form_content.find('.colorwell').change(function (element, ui) { |
---|
1834 | if (true) { |
---|
1835 | form_content.find('select.color-suggestions') |
---|
1836 | .find('option:selected').removeAttr('selected').end() |
---|
1837 | .find('option[value="custom"]').attr('selected', 'selected').trigger('change'); |
---|
1838 | } |
---|
1839 | }); |
---|
1840 | }); //END set colorpicker |
---|
1841 | |
---|
1842 | form_content.find('.phone').mask("+99 (99) 9999-9999"); |
---|
1843 | form_content.find('.number').numeric(); |
---|
1844 | |
---|
1845 | }); //END DataLayer.render( 'templates/configure_calendars_itemlist.ejs' ... |
---|
1846 | |
---|
1847 | // === validations preferences ==== |
---|
1848 | |
---|
1849 | |
---|
1850 | } //END populateAccordionOnActive(event, ui) |
---|
1851 | |
---|
1852 | |
---|
1853 | DataLayer.render( 'templates/configure_calendars.ejs', { |
---|
1854 | user:User, |
---|
1855 | calendars:calendars, |
---|
1856 | signatures:signatures |
---|
1857 | }, function( template ){ |
---|
1858 | var template_content = jQuery('#configure_tab').html( template ).find('.configure-calendars-win'); |
---|
1859 | template_content.find('.button').button().filter('.save').click(function(evt){ |
---|
1860 | if(calendarAlarms.length) |
---|
1861 | DataLayer.removeFilter('calendarSignatureAlarm', {filter: ['IN','id', calendarAlarms]}); |
---|
1862 | template_content.find('form').submit(); |
---|
1863 | $tabs.tabs( "remove", "#configure_tab"); |
---|
1864 | DataLayer.commit( false, false, function( received ){ |
---|
1865 | delete Calendar.currentViewKey; |
---|
1866 | Calendar.load(); |
---|
1867 | refresh_calendars(); |
---|
1868 | }); |
---|
1869 | if(calendarAlarms.length) |
---|
1870 | Calendar.load(); |
---|
1871 | }).end().filter('.cancel').click(function(evt){ |
---|
1872 | $tabs.tabs( "remove", "#configure_tab"); |
---|
1873 | }); |
---|
1874 | |
---|
1875 | /** |
---|
1876 | * Muda a estrutura do template para a aplicação do plugin accordion |
---|
1877 | */ |
---|
1878 | template_content.find('.header-menu-container').after('<div class="accordion-user-calendars"></div>').end().find('.accordion-user-calendars') |
---|
1879 | .append(template_content.children('fieldset')); |
---|
1880 | |
---|
1881 | template_content.find('.accordion-user-calendars').children('fieldset').each(function(index) { |
---|
1882 | $(this).before($('<h3></h3>').html($(this).children('legend'))); |
---|
1883 | }); |
---|
1884 | |
---|
1885 | template_content.find('.accordion-user-calendars').accordion({ |
---|
1886 | autoHeight: false, |
---|
1887 | collapsible: true, |
---|
1888 | clearStyle: true, |
---|
1889 | active: previewActiveCalendarConf, |
---|
1890 | changestart: populateAccordionOnActive |
---|
1891 | }); |
---|
1892 | populateAccordionOnActive(previewActiveCalendarConf); |
---|
1893 | }); |
---|
1894 | |
---|
1895 | } else { |
---|
1896 | |
---|
1897 | $tabs.tabs("select", "#configure_tab"); |
---|
1898 | $('.accordion-user-calendars').accordion( "activate" , previewActiveCalendarConf ); |
---|
1899 | |
---|
1900 | return true; |
---|
1901 | } |
---|
1902 | |
---|
1903 | } |
---|
1904 | |
---|
1905 | function getSelectedCalendars( reverse ){ |
---|
1906 | var selecteds = {}; |
---|
1907 | var cont = 0; |
---|
1908 | jQuery(function() { |
---|
1909 | jQuery(".my-calendars .calendar-view").each(function(i, obj) { |
---|
1910 | var check_box = obj; |
---|
1911 | if( reverse ? !check_box.checked : check_box.checked ) { |
---|
1912 | selecteds[cont] = obj.value; |
---|
1913 | cont++; |
---|
1914 | }; |
---|
1915 | }); |
---|
1916 | }); |
---|
1917 | if (!cont) |
---|
1918 | return false; |
---|
1919 | |
---|
1920 | selecteds.length = cont; |
---|
1921 | return $.makeArray( selecteds ); |
---|
1922 | } |
---|
1923 | |
---|
1924 | /** |
---|
1925 | * TODO - transformar em preferência do módulo e criar telas de adição e exclusão de conjunto de cores |
---|
1926 | */ |
---|
1927 | function colors_suggestions(){ |
---|
1928 | return [ |
---|
1929 | { |
---|
1930 | name:'Padrão', |
---|
1931 | border:'#3366cc', |
---|
1932 | font:'#ffffff', |
---|
1933 | background:'#3366cc' |
---|
1934 | }, |
---|
1935 | |
---|
1936 | { |
---|
1937 | name:'Coala', |
---|
1938 | border:'#123456', |
---|
1939 | font:'#ffffff', |
---|
1940 | background:'#385c80' |
---|
1941 | }, |
---|
1942 | |
---|
1943 | { |
---|
1944 | name:'Tomate', |
---|
1945 | border:'#d5130b', |
---|
1946 | font:'#111111', |
---|
1947 | background:'#e36d76' |
---|
1948 | }, |
---|
1949 | |
---|
1950 | { |
---|
1951 | name:'Limão', |
---|
1952 | border:'#32ed21', |
---|
1953 | font:'#1f3f1c', |
---|
1954 | background:'#b2f1ac' |
---|
1955 | }, |
---|
1956 | |
---|
1957 | { |
---|
1958 | name:'Alto contraste', |
---|
1959 | border:'#000000', |
---|
1960 | font:'#ffffff', |
---|
1961 | background:'#222222' |
---|
1962 | } |
---|
1963 | ] |
---|
1964 | } |
---|
1965 | |
---|
1966 | function remove_event(eventId, idCalendar){ |
---|
1967 | $.Zebra_Dialog('Tem certeza que deseja excluir o evento?', { |
---|
1968 | 'type': 'question', |
---|
1969 | 'overlay_opacity': '0.5', |
---|
1970 | 'buttons': ['Sim', 'Não'], |
---|
1971 | 'onClose': function(clicked) { |
---|
1972 | if(clicked == 'Sim'){ |
---|
1973 | |
---|
1974 | var schedulable = DataLayer.get('schedulable', ''+eventId); |
---|
1975 | schedulable.calendar = ''+idCalendar; |
---|
1976 | var schudableDecode = DataLayer.encode( "schedulable:preview", schedulable); |
---|
1977 | var me = schudableDecode.me.user ? schudableDecode.me.user.id : schudableDecode.me.id; |
---|
1978 | |
---|
1979 | DataLayer.removeFilter('schedulable', {filter: ['AND', ['=','id',eventId], ['=','calendar',idCalendar], ['=','user', me]]}) |
---|
1980 | Calendar.rerenderView(true); |
---|
1981 | } |
---|
1982 | } |
---|
1983 | }); |
---|
1984 | } |
---|
1985 | |
---|
1986 | function mount_exception(eventID, idException){ |
---|
1987 | |
---|
1988 | var schedulable = DataLayer.get('schedulable', ''+eventID); |
---|
1989 | var edit = { |
---|
1990 | repeat: (DataLayer.get('repeat', schedulable.repeat)) |
---|
1991 | }; |
---|
1992 | |
---|
1993 | edit.repeat.startTime = new Date(parseInt(edit.repeat.startTime)).toString('yyyy-MM-dd HH:mm:00'); |
---|
1994 | edit.repeat.endTime = parseInt(edit.repeat.count) > 0 ? '0' : new Date(parseInt(edit.repeat.endTime)).toString('yyyy-MM-dd HH:mm:00'); |
---|
1995 | |
---|
1996 | edit.repeat.exceptions = (schedulable.occurrences[idException]); |
---|
1997 | |
---|
1998 | return edit.repeat; |
---|
1999 | |
---|
2000 | } |
---|
2001 | |
---|
2002 | function remove_ocurrence(eventId, idRecurrence){ |
---|
2003 | $.Zebra_Dialog('Tem certeza que deseja excluir esta ocorrência?', { |
---|
2004 | 'type': 'question', |
---|
2005 | 'overlay_opacity': '0.5', |
---|
2006 | 'buttons': ['Sim', 'Não'], |
---|
2007 | 'onClose': function(clicked) { |
---|
2008 | if(clicked == 'Sim'){ |
---|
2009 | var repeat = mount_exception(eventId, idRecurrence); |
---|
2010 | DataLayer.remove('repeat', false); |
---|
2011 | DataLayer.put('repeat', repeat); |
---|
2012 | DataLayer.commit(false, false, function(data){ |
---|
2013 | Calendar.rerenderView(true); |
---|
2014 | }); |
---|
2015 | } |
---|
2016 | } |
---|
2017 | }); |
---|
2018 | } |
---|
2019 | |
---|
2020 | |
---|
2021 | function remove_calendar(){ |
---|
2022 | /* Pode ser assim $('.cal-list-options-btn.ui-state-active').attr('class').replace(/[a-zA-Z-]+/g, ''); */ |
---|
2023 | $.Zebra_Dialog('Todos os eventos desta agenda serão removidos. Deseja prosseguir com a operação?', { |
---|
2024 | 'type': 'question', |
---|
2025 | 'overlay_opacity': '0.5', |
---|
2026 | 'buttons': ['Sim', 'Não'], |
---|
2027 | 'onClose': function(clicked) { |
---|
2028 | if(clicked == 'Sim'){ |
---|
2029 | var idCalendar = $('.cal-list-options-btn.ui-state-active').attr('class').match(/[0-9]+/g); |
---|
2030 | |
---|
2031 | DataLayer.remove('calendarSignature', Calendar.signatureOf[idCalendar[0]].id ); |
---|
2032 | |
---|
2033 | if(idCalendar == User.preferences.defaultCalendar) |
---|
2034 | DataLayer.remove( 'modulePreference', User.preferenceIds['defaultCalendar']); |
---|
2035 | |
---|
2036 | DataLayer.commit( false, false, function( received ){ |
---|
2037 | delete Calendar.currentViewKey; |
---|
2038 | Calendar.load(); |
---|
2039 | refresh_calendars(); |
---|
2040 | }); |
---|
2041 | } |
---|
2042 | $('.positionHelper').css('display', 'none'); |
---|
2043 | |
---|
2044 | } |
---|
2045 | }); |
---|
2046 | } |
---|
2047 | |
---|
2048 | function refresh_calendars(){ |
---|
2049 | |
---|
2050 | var colorsSuggestions = colors_suggestions(); |
---|
2051 | var buttons_colors = ""; |
---|
2052 | for(var i = 0; i < colorsSuggestions.length; i++){ |
---|
2053 | 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>"; |
---|
2054 | } |
---|
2055 | |
---|
2056 | //DataLayer.render( 'templates/calendar_list.ejs', 'calendar:list', ["IN", "id", Calendar.calendarIds], function( html ){ |
---|
2057 | DataLayer.render( 'templates/calendar_list.ejs', Calendar, function( html ){ |
---|
2058 | |
---|
2059 | var meu_container = $(".calendars-list").html( html ); |
---|
2060 | |
---|
2061 | $('ul.list-calendars .cal-list-options-btn').each(function(){ |
---|
2062 | $(this).menu({ |
---|
2063 | content: $(this).next().html(), |
---|
2064 | width: '120', |
---|
2065 | positionOpts: { |
---|
2066 | posX: 'left', |
---|
2067 | posY: 'bottom', |
---|
2068 | offsetX: 0, |
---|
2069 | offsetY: 0, |
---|
2070 | directionH: 'right', |
---|
2071 | directionV: 'down', |
---|
2072 | detectH: true, // do horizontal collision detection |
---|
2073 | detectV: true, // do vertical collision detection |
---|
2074 | linkToFront: false |
---|
2075 | }, |
---|
2076 | flyOut: true, |
---|
2077 | showSpeed: 100, |
---|
2078 | crumbDefaultText: '>' |
---|
2079 | }); |
---|
2080 | }); |
---|
2081 | |
---|
2082 | meu_container.find(".button.new-calendar").button({ |
---|
2083 | icons: { |
---|
2084 | primary: "ui-icon-plus" |
---|
2085 | }, |
---|
2086 | text: false |
---|
2087 | }).click(function () { |
---|
2088 | |
---|
2089 | if( $('.qtip.qtip-blue.qtip-active').val() !== ''){ |
---|
2090 | $(this).qtip({ |
---|
2091 | show: { |
---|
2092 | ready: true, |
---|
2093 | solo: true, |
---|
2094 | when: { |
---|
2095 | event: 'click' |
---|
2096 | } |
---|
2097 | }, |
---|
2098 | hide: false, |
---|
2099 | content: { |
---|
2100 | text: $('<div></div>').html( DataLayer.render( 'templates/calendar_quick_add.ejs', {} ) ), |
---|
2101 | title: { |
---|
2102 | text:'Nova Agenda', |
---|
2103 | button: '<a class="button close" href="#">close</a>' |
---|
2104 | } |
---|
2105 | }, |
---|
2106 | style: { |
---|
2107 | name: 'blue', |
---|
2108 | tip: { |
---|
2109 | corner: 'leftMiddle' |
---|
2110 | }, |
---|
2111 | border: { |
---|
2112 | width: 4, |
---|
2113 | radius: 8 |
---|
2114 | }, |
---|
2115 | width: { |
---|
2116 | min: 230, |
---|
2117 | max:230 |
---|
2118 | } |
---|
2119 | }, |
---|
2120 | position: { |
---|
2121 | corner: { |
---|
2122 | target: 'rightMiddle', |
---|
2123 | tooltip: 'leftMiddle' |
---|
2124 | }, |
---|
2125 | adjust: { |
---|
2126 | x:0, |
---|
2127 | y:-12 |
---|
2128 | } |
---|
2129 | } |
---|
2130 | }) |
---|
2131 | .qtip("api").onShow = function(arg0) { |
---|
2132 | $('.qtip-active .button.close').button({ |
---|
2133 | icons: { |
---|
2134 | primary: "ui-icon-close" |
---|
2135 | }, |
---|
2136 | text: false |
---|
2137 | }) |
---|
2138 | .click(function(){ |
---|
2139 | meu_container.find(".button.new-calendar").qtip('destroy'); |
---|
2140 | }); |
---|
2141 | //TODO emplementar tratamento de duplicação de valores no location |
---|
2142 | $('.qtip-active .button.save').button().click(function(){ |
---|
2143 | for(var i = 0; i < Calendar.calendars.length; i++){ |
---|
2144 | if(Calendar.calendars[i].location == ( User.me.uid + '/' + $('.qtip-active input').val())){ |
---|
2145 | $.Zebra_Dialog('O nome desta agenda já está sendo utilizada em uma Url de outra agenda. Por favor, informe outro nome para agenda.',{ |
---|
2146 | 'overlay_opacity': '0.5', |
---|
2147 | 'type': 'warning' |
---|
2148 | }); |
---|
2149 | meu_container.find(".button.new").qtip('destroy'); |
---|
2150 | return; |
---|
2151 | } |
---|
2152 | } |
---|
2153 | |
---|
2154 | var selected; |
---|
2155 | var color = $('.cal-colors-options-btn').each(function(index){ |
---|
2156 | if ($(this).is('.color-selected')) |
---|
2157 | selected = index; |
---|
2158 | }); |
---|
2159 | DataLayer.put( "calendarSignature", { |
---|
2160 | user: User.me.id, |
---|
2161 | calendar: { |
---|
2162 | name: Encoder.htmlEncode($('.qtip-active input').val()), |
---|
2163 | timezone: User.preferences.timezone |
---|
2164 | }, |
---|
2165 | isOwner: 1, |
---|
2166 | fontColor: colorsSuggestions[selected]['font'].substring(1) , |
---|
2167 | backgroundColor: colorsSuggestions[selected]['background'].substring(1) , |
---|
2168 | borderColor: colorsSuggestions[selected]['border'].substring(1) |
---|
2169 | }); |
---|
2170 | DataLayer.commit( false, false, function( received ){ |
---|
2171 | delete Calendar.currentViewKey; |
---|
2172 | Calendar.load(); |
---|
2173 | refresh_calendars(); |
---|
2174 | }); |
---|
2175 | meu_container.find(".button.new").qtip('destroy'); |
---|
2176 | }); |
---|
2177 | |
---|
2178 | $('.qtip-active .button.cancel').button().click(function(){ |
---|
2179 | meu_container.find(".button.new").qtip('destroy'); |
---|
2180 | }); |
---|
2181 | |
---|
2182 | $(".qtip-active input").Watermark("Nome da agenda"); |
---|
2183 | |
---|
2184 | $('.qtip-active').keydown(function(event) { |
---|
2185 | if (event.keyCode == '27') { |
---|
2186 | meu_container.find(".button.new").qtip('destroy'); |
---|
2187 | } |
---|
2188 | }); |
---|
2189 | |
---|
2190 | $('.colors-options').prepend(buttons_colors); |
---|
2191 | $('.colors-options .signed-cal-colors-options-btn-0').addClass('color-selected'); |
---|
2192 | |
---|
2193 | var buttons = $('.cal-colors-options-btn').button(); |
---|
2194 | |
---|
2195 | buttons.click(function(){ |
---|
2196 | buttons.removeClass('color-selected'); |
---|
2197 | $(this).addClass('color-selected'); |
---|
2198 | }); |
---|
2199 | } |
---|
2200 | } |
---|
2201 | }); |
---|
2202 | |
---|
2203 | $("img.cal-list-img").click(function(evt) { |
---|
2204 | $(".cal-list-options_1").toggleClass( "hidden" ); |
---|
2205 | }); |
---|
2206 | |
---|
2207 | $(".my-calendars a.title-my-calendars").click(function() { |
---|
2208 | $(".my-calendars ul.my-list-calendars").toggleClass("hidden") |
---|
2209 | $('.my-calendars .status-list').toggleClass("ui-icon-triangle-1-s"); |
---|
2210 | $('.my-calendars .status-list').toggleClass("ui-icon-triangle-1-e"); |
---|
2211 | }); |
---|
2212 | |
---|
2213 | $(".signed-calendars a.title-signed-calendars").click(function() { |
---|
2214 | $(".signed-calendars ul.signed-list-calendars").toggleClass( "hidden"); |
---|
2215 | }); |
---|
2216 | |
---|
2217 | $("ul li.list-calendars-item").click(function(evt) { |
---|
2218 | |
---|
2219 | }); |
---|
2220 | |
---|
2221 | $("ul li.list-calendars-item .ui-corner-all").click(function(evt) { |
---|
2222 | //alert('teste'); |
---|
2223 | }); |
---|
2224 | |
---|
2225 | meu_container.find(".button.new-calendar-shared").button({ |
---|
2226 | icons: { |
---|
2227 | primary: "ui-icon-plus" |
---|
2228 | }, |
---|
2229 | text: false |
---|
2230 | }).click(function (event) { |
---|
2231 | show_modal_search_shared(); |
---|
2232 | }); |
---|
2233 | |
---|
2234 | |
---|
2235 | //TODO Implementar ocultar agendas. |
---|
2236 | meu_container.find('.title-signed-calendars').click(function(evt){ |
---|
2237 | var status = $(this).parent().find('.status-list-shared'); |
---|
2238 | |
---|
2239 | if(status.hasClass('ui-icon-triangle-1-s')) |
---|
2240 | status.removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e'); |
---|
2241 | else |
---|
2242 | status.removeClass('ui-icon-triangle-1-e').addClass('ui-icon-triangle-1-s'); |
---|
2243 | }); |
---|
2244 | |
---|
2245 | $('.calendar-view').click(function(evt){ |
---|
2246 | if($tabs.tabs('option' ,'selected') == 1){ |
---|
2247 | pageselectCallback('', 0); |
---|
2248 | } |
---|
2249 | |
---|
2250 | if(Calendar.currentView){ |
---|
2251 | var checkBox = $(this); |
---|
2252 | if(!!Calendar.currentView[ checkBox.val() ]){ |
---|
2253 | Calendar.currentView[ checkBox.val() ].hidden = !checkBox.is(':checked'); |
---|
2254 | $('#calendar').fullCalendar( 'refetchEvents' ); |
---|
2255 | } |
---|
2256 | } |
---|
2257 | }); |
---|
2258 | }); |
---|
2259 | } |
---|
2260 | |
---|
2261 | function add_events_list(keyword) |
---|
2262 | { |
---|
2263 | var tab_title = ""; |
---|
2264 | if (keyword){ |
---|
2265 | if(keyword.length < 10) |
---|
2266 | tab_title = keyword; |
---|
2267 | else |
---|
2268 | tab_title = keyword.substr(0,10) + '..."'; |
---|
2269 | }else{ |
---|
2270 | tab_title = "Lista de eventos"; |
---|
2271 | } |
---|
2272 | keyword = ( keyword || '' ).replace( /\s+/g, "_" ); |
---|
2273 | |
---|
2274 | if(!(document.getElementById('tab_events_list_' + (Base64.encode(keyword)).replace(/[^\w\s]/gi, "") ))) |
---|
2275 | { |
---|
2276 | Encoder.EncodeType = "entity"; |
---|
2277 | $tabs.tabs( "add", "#tab_events_list_" + (Base64.encode(keyword)).replace(/[^\w\s]/gi, ""), Encoder.htmlEncode(tab_title) ); |
---|
2278 | } |
---|
2279 | else /* Tab already opened */ |
---|
2280 | { |
---|
2281 | $tabs.tabs("option", "selected", 2); |
---|
2282 | } |
---|
2283 | |
---|
2284 | pageselectCallback(keyword, 0); // load page 1 and insert data on event_list.ejs |
---|
2285 | |
---|
2286 | $('.preferences-win.active .button.save, .preferences-win.active .button.cancel, .preferences-win.active .button.import, .preferences-win.active .button.export').button(); |
---|
2287 | } |
---|
2288 | |
---|
2289 | function paginatorSearch(currentView){ |
---|
2290 | $(currentView+' .header-paginator .fc-header-left .fc-button').hover( |
---|
2291 | function(){ |
---|
2292 | $(this).addClass('fc-state-hover'); |
---|
2293 | }, |
---|
2294 | function(){ |
---|
2295 | $(this).removeClass('fc-state-hover'); |
---|
2296 | }).mousedown(function(){ |
---|
2297 | $(this).addClass('fc-state-down'); |
---|
2298 | }).mouseup(function(){ |
---|
2299 | $(this).removeClass('fc-state-down'); |
---|
2300 | $('.events-list.events-list-win.active').removeClass('active'); |
---|
2301 | var paginator = $(this).attr('class'); |
---|
2302 | if(paginator.indexOf('next') > 0){ |
---|
2303 | if(parseInt($(currentView+' [name = results]').val()) > 25) |
---|
2304 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($(currentView+' [name = page_index]').val())) +1)); |
---|
2305 | }else{ |
---|
2306 | if(parseInt($(currentView+' [name = page_index]').val()) > 0) |
---|
2307 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($(currentView+' [name = page_index]').val())) -1)); |
---|
2308 | } |
---|
2309 | }); |
---|
2310 | } |
---|
2311 | |
---|
2312 | function mountTitleList(page_index ,view){ |
---|
2313 | switch (view){ |
---|
2314 | case 'agendaDay': |
---|
2315 | case 'basicDay': |
---|
2316 | var date = new Date().add({ |
---|
2317 | days: page_index |
---|
2318 | }); |
---|
2319 | return (dateCalendar.dayNames[date.getDay()])+", "+(date.toString('dd MMM yyyy')); |
---|
2320 | case 'agendaWeek': |
---|
2321 | var dateStart = new Date().moveToDayOfWeek(dateCalendar.dayOfWeek[User.preferences.weekStart]); |
---|
2322 | dateStart.add({ |
---|
2323 | days: (7 * page_index) |
---|
2324 | }); |
---|
2325 | var dateEnd = new Date().moveToDayOfWeek(dateCalendar.dayOfWeek[User.preferences.weekStart]); |
---|
2326 | dateEnd.add({ |
---|
2327 | days: (page_index * 7)+7 |
---|
2328 | }); |
---|
2329 | if(dateStart.toString('MM') != dateEnd.toString('MM')) |
---|
2330 | return dateStart.toString('dd')+' de '+dateCalendar.monthNamesShort[dateStart.getMonth()]+' a '+dateEnd.toString('dd')+' de '+dateCalendar.monthNames[dateEnd.getMonth()]+' - '+dateEnd.toString('yyyy'); |
---|
2331 | return +dateStart.toString("dd")+" a "+dateEnd.toString("dd")+" de "+dateCalendar.monthNames[dateEnd.getMonth()]+" - "+dateEnd.toString('yyyy'); |
---|
2332 | case 'month': |
---|
2333 | var date = new Date().add({ |
---|
2334 | months: page_index |
---|
2335 | }) |
---|
2336 | return dateCalendar.monthNames[date.getMonth()]+" "+date.toString("yyyy"); |
---|
2337 | case 'year': |
---|
2338 | var date = new Date().add({ |
---|
2339 | years: page_index |
---|
2340 | }); |
---|
2341 | return date.toString("yyyy"); |
---|
2342 | } |
---|
2343 | } |
---|
2344 | |
---|
2345 | function paginatorList(currentView, view){ |
---|
2346 | $(currentView+' .events-list.events-list-win.active .list-events-paginator .fc-header-title').html('<h2>'+mountTitleList( parseInt($('[name = page_index]').val()),view)+'</h2>'); |
---|
2347 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
2348 | if(view == 'basicDay') |
---|
2349 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button-agendaDay').addClass('fc-state-active'); |
---|
2350 | else |
---|
2351 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button-'+view).addClass('fc-state-active'); |
---|
2352 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right').addClass('list-right'); |
---|
2353 | |
---|
2354 | $(currentView+' .header-paginator .fc-header-right .fc-button').hover( |
---|
2355 | function(){ |
---|
2356 | $(this).addClass('fc-state-hover'); |
---|
2357 | }, |
---|
2358 | function(){ |
---|
2359 | $(this).removeClass('fc-state-hover'); |
---|
2360 | }).mousedown(function(){ |
---|
2361 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
2362 | $(this).addClass('fc-state-active'); |
---|
2363 | }).mouseup(function(){ |
---|
2364 | var goView = $(this).attr('class'); |
---|
2365 | if(goView.indexOf('agendaDay') > 0) |
---|
2366 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'agendaDay'); |
---|
2367 | else if(goView.indexOf('month') > 0) |
---|
2368 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'month'); |
---|
2369 | else if(goView.indexOf('year') > 0) |
---|
2370 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'year'); |
---|
2371 | else if(goView.indexOf('agendaWeek') > 0) |
---|
2372 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'agendaWeek'); |
---|
2373 | |
---|
2374 | }); |
---|
2375 | |
---|
2376 | $(currentView+' .header-paginator .fc-header-left .fc-button').hover( |
---|
2377 | function(){ |
---|
2378 | $(this).addClass('fc-state-hover'); |
---|
2379 | }, |
---|
2380 | function(){ |
---|
2381 | $(this).removeClass('fc-state-hover'); |
---|
2382 | }).mousedown(function(){ |
---|
2383 | $(this).addClass('fc-state-down'); |
---|
2384 | }).mouseup(function(){ |
---|
2385 | $(this).removeClass('fc-state-down'); |
---|
2386 | var paginator = $(this).attr('class'); |
---|
2387 | if(paginator.indexOf('next') > 0) |
---|
2388 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($('[name = page_index]').val())) +1), '', view); |
---|
2389 | else |
---|
2390 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($('[name = page_index]').val())) -1), '', view); |
---|
2391 | }); |
---|
2392 | } |
---|
2393 | |
---|
2394 | function paginatorListEvent(currentView, typeView, view){ |
---|
2395 | if(!!$(currentView).find('.fc-calendar').length) |
---|
2396 | return; |
---|
2397 | $(currentView+' .events-list.events-list-win.active').prepend($('.fc-header:first').clone()); |
---|
2398 | //Remove contudo nao utilizado |
---|
2399 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-today').remove(); |
---|
2400 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-basicWeek').remove(); |
---|
2401 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-basicDay').remove(); |
---|
2402 | |
---|
2403 | //Adiciona e remove as classes para esta visualizacao |
---|
2404 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-header-center').addClass('list-events-paginator'); |
---|
2405 | $(currentView+' .events-list.events-list-win.active .fc-header .list-events-paginator').removeClass('fc-header-center'); |
---|
2406 | |
---|
2407 | //Adicionar class no header padronizar com a tela principal |
---|
2408 | $(currentView+' .events-list.events-list-win.active .fc-header').addClass('header-paginator'); |
---|
2409 | $(currentView+' .events-list.events-list-win.active .header-paginator').removeClass('fc-header'); |
---|
2410 | |
---|
2411 | if(typeView == 'search'){ |
---|
2412 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right').remove() |
---|
2413 | $(currentView+' .events-list.events-list-win.active .list-events-paginator .fc-header-title').html('<h2>Resultados para: '+$(currentView+' [name = keyword]').val()+'</h2>'); |
---|
2414 | if((parseInt($(currentView+' [name = page_index]').val()) == 0) && (parseInt($(currentView+' [name = results]').val()) <= 25)) |
---|
2415 | return; |
---|
2416 | paginatorSearch(currentView); |
---|
2417 | }else |
---|
2418 | paginatorList(currentView, view); |
---|
2419 | } |
---|
2420 | |
---|
2421 | function mountCriteriaList(view, page_index, calerdars_selecteds){ |
---|
2422 | var rangeStart , rangeEnd; |
---|
2423 | switch (view){ |
---|
2424 | case 'basicDay': |
---|
2425 | case 'agendaDay': |
---|
2426 | rangeStart = new Date().add({ |
---|
2427 | days: page_index |
---|
2428 | }).getTime(); |
---|
2429 | rangeEnd = rangeStart; |
---|
2430 | break; |
---|
2431 | case 'agendaWeek': |
---|
2432 | var dateStart = new Date().moveToDayOfWeek(dateCalendar.dayOfWeek[User.preferences.weekStart]); |
---|
2433 | var dateEnd = new Date().moveToDayOfWeek(dateCalendar.dayOfWeek[User.preferences.weekStart]); |
---|
2434 | rangeStart = dateStart.add({ |
---|
2435 | days: (7 * page_index) |
---|
2436 | }).getTime(); |
---|
2437 | rangeEnd = dateEnd.add({ |
---|
2438 | days: (7 * page_index)+7 |
---|
2439 | }).getTime(); |
---|
2440 | break; |
---|
2441 | case 'month': |
---|
2442 | var date = Date.today().add({ |
---|
2443 | months: page_index |
---|
2444 | }) |
---|
2445 | rangeStart = date.moveToFirstDayOfMonth().getTime(); |
---|
2446 | rangeEnd = date.moveToLastDayOfMonth().getTime(); |
---|
2447 | break; |
---|
2448 | case 'year': |
---|
2449 | var dateStart = new Date().add({ |
---|
2450 | years: page_index |
---|
2451 | }); |
---|
2452 | var dateEnd = new Date().add({ |
---|
2453 | years: page_index |
---|
2454 | }); |
---|
2455 | if(dateStart.getMonth() != 0) |
---|
2456 | dateStart.moveToMonth(0, -1) |
---|
2457 | if(dateEnd.getMonth() != 11) |
---|
2458 | dateEnd.moveToMonth(11) |
---|
2459 | rangeStart = dateStart.moveToFirstDayOfMonth().getTime(); |
---|
2460 | rangeEnd = dateEnd.moveToLastDayOfMonth().getTime(); |
---|
2461 | break; |
---|
2462 | } |
---|
2463 | |
---|
2464 | var timezone = {}; |
---|
2465 | for(var i in Calendar.signatureOf) |
---|
2466 | timezone[i] = Calendar.signatureOf[i].calendar.timezone; |
---|
2467 | |
---|
2468 | return { |
---|
2469 | filter: ['AND', |
---|
2470 | ['OR', |
---|
2471 | ['AND', |
---|
2472 | ['>=', 'rangeEnd', rangeStart], |
---|
2473 | ['<=', 'rangeEnd', rangeEnd] , |
---|
2474 | ], |
---|
2475 | ['AND', |
---|
2476 | ['>=', 'rangeStart', rangeStart], |
---|
2477 | ['<=', 'rangeStart', rangeEnd] , |
---|
2478 | ], |
---|
2479 | ['AND', |
---|
2480 | ['<=', 'rangeStart', rangeStart], |
---|
2481 | ['>=', 'rangeEnd', rangeEnd] , |
---|
2482 | ] |
---|
2483 | ], |
---|
2484 | ['IN', 'calendar', calerdars_selecteds] |
---|
2485 | ], |
---|
2486 | criteria: { |
---|
2487 | deepness: 2, |
---|
2488 | order: 'startTime', |
---|
2489 | timezones: timezone |
---|
2490 | } |
---|
2491 | }; |
---|
2492 | |
---|
2493 | } |
---|
2494 | |
---|
2495 | function pageselectCallback(keyword, page_index, jq, view){ |
---|
2496 | |
---|
2497 | var selecteds = getSelectedCalendars(); |
---|
2498 | if(!selecteds && (keyword != '' && keyword != null)){ |
---|
2499 | jQuery('#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( |
---|
2500 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
2501 | '<label>Por favor selecione ao menos uma agenda.</label>' + |
---|
2502 | '</div>' |
---|
2503 | ); |
---|
2504 | }else{ |
---|
2505 | var criteria = null; |
---|
2506 | if(keyword == '' || keyword == null) |
---|
2507 | criteria = mountCriteriaList(!!view ? view : User.preferences.defaultCalView, page_index, selecteds) |
---|
2508 | else |
---|
2509 | criteria = { |
---|
2510 | filter: ['AND', ['OR', ["i*", "summary", keyword], ["i*", "description", keyword]], ['IN', 'calendar', selecteds]], |
---|
2511 | criteria: { |
---|
2512 | searchEvent: true, |
---|
2513 | order: 'startTime', |
---|
2514 | offset: (25 * page_index), |
---|
2515 | limit: (((25 * page_index) + 25) + 1), |
---|
2516 | deepness: 2 |
---|
2517 | } |
---|
2518 | }; |
---|
2519 | var results = DataLayer.get('schedulable:detail', criteria); |
---|
2520 | keyword = ( keyword || '' ).replace( /\s+/g, "_" ); |
---|
2521 | } |
---|
2522 | // não há resultados |
---|
2523 | |
---|
2524 | var currentView = '#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "") || ''); |
---|
2525 | |
---|
2526 | if ((((typeof(results) == 'undefined') || (!results.events_list )) && selecteds) &&(keyword != '' && keyword != null)) { |
---|
2527 | $(currentView).html( |
---|
2528 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
2529 | '<label>Não foi encontrado nenhum evento correspondente à sua pesquisa.</label>' + |
---|
2530 | '</div>' |
---|
2531 | ); |
---|
2532 | // há resultados e Agendas Selecionadas |
---|
2533 | } else{ |
---|
2534 | if(typeof(results) != 'undefined'){ |
---|
2535 | results['page_index'] = page_index; |
---|
2536 | results['keyword'] = keyword; |
---|
2537 | |
---|
2538 | DataLayer.render( 'templates/event_list.ejs', results, function( html ){ |
---|
2539 | |
---|
2540 | $(currentView).html( html ); |
---|
2541 | $('.events-list-win .menu-container .button').button(); |
---|
2542 | |
---|
2543 | $(".event-details-item").parent().click(function(){ |
---|
2544 | |
---|
2545 | $(this).siblings("div.details-event-list").toggleClass("hidden") |
---|
2546 | .find('.button.delete').click(function(){ |
---|
2547 | var eventId = $(this).siblings('[name="eventid"]').val(); |
---|
2548 | var calendarId = $(this).siblings('[name="calendarid"]').val(); |
---|
2549 | |
---|
2550 | remove_event(eventId, calendarId); |
---|
2551 | }) |
---|
2552 | .end().find('.button.edit').click(function(){ |
---|
2553 | eventDetails( DataLayer.get( "schedulable", $(this).siblings('[name="eventid"]').val() ), true ); |
---|
2554 | }); |
---|
2555 | |
---|
2556 | }); |
---|
2557 | paginatorListEvent(currentView, (keyword == '' || keyword == null) ? 'list' : 'search', !!view ? view : User.preferences.defaultCalView); |
---|
2558 | }); |
---|
2559 | }else{ |
---|
2560 | $(currentView).html( |
---|
2561 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
2562 | '<input type="hidden" name="page_index" value="'+page_index+'"></inpunt>'+ |
---|
2563 | '<input type="hidden" name="keyword" value="'+keyword+'"></inpunt>'+ |
---|
2564 | '<label class="empty-result">Não foram encontrados eventos neste intervalo.</label>' + |
---|
2565 | '</div>' |
---|
2566 | ); |
---|
2567 | paginatorListEvent(currentView, 'list', !!view ? view : User.preferences.defaultCalView); |
---|
2568 | } |
---|
2569 | } |
---|
2570 | if(currentView != '#tab_events_list_') |
---|
2571 | $tabs.tabs("select", currentView); |
---|
2572 | } |
---|
2573 | |
---|
2574 | function show_modal_import_export(tab, calendarId) { |
---|
2575 | DataLayer.render( 'templates/import_export.ejs', { |
---|
2576 | calendars: Calendar.calendars, |
---|
2577 | owner: User.me.id |
---|
2578 | }, function( html ){ |
---|
2579 | |
---|
2580 | if (!UI.dialogs.importCalendar) { |
---|
2581 | UI.dialogs.importCalendar = jQuery('#div-import-export-calendar') |
---|
2582 | .append('<div title="Importar e Exportar Eventos" class="import-export import-export-win active"> <div>') |
---|
2583 | .find('.import-export-win.active').html(html).dialog({ |
---|
2584 | resizable: false, |
---|
2585 | modal:true, |
---|
2586 | width:500, |
---|
2587 | position: 'center' |
---|
2588 | }); |
---|
2589 | |
---|
2590 | } else { |
---|
2591 | UI.dialogs.importCalendar.html(html); |
---|
2592 | } |
---|
2593 | |
---|
2594 | var tabsImportExport = UI.dialogs.importCalendar.find(".tabs-import-export").tabs({ |
---|
2595 | selected: tab |
---|
2596 | }); |
---|
2597 | |
---|
2598 | UI.dialogs.importCalendar.find('.button').button(); |
---|
2599 | |
---|
2600 | tabsImportExport.find('option[value="'+calendarId+'"]').attr('selected','selected').trigger('change'); |
---|
2601 | |
---|
2602 | var form = false; |
---|
2603 | $('.import-event-form').fileupload({ |
---|
2604 | sequentialUploads: true, |
---|
2605 | add: function (e, data) { |
---|
2606 | form = data |
---|
2607 | var name = form.files[0].name; |
---|
2608 | $('.import-event-form').find('input[type="file"]').hide(); |
---|
2609 | $('.import-event-form').find('span.file-add').removeClass('hidden'); |
---|
2610 | $('.import-event-form').find('span.file-add').append('<span>'+ name +'</span><a class="button remove-attachment tiny"></a>'); |
---|
2611 | $('.import-event-form').find('.button.remove-attachment').button({ |
---|
2612 | icons: { |
---|
2613 | primary: "ui-icon-close" |
---|
2614 | }, |
---|
2615 | text: false |
---|
2616 | }).click(function (event){ |
---|
2617 | $('.import-event-form').find('input[type="file"]').show(); |
---|
2618 | $('.import-event-form').find('span.file-add').addClass('hidden').html(''); |
---|
2619 | form = false; |
---|
2620 | }); |
---|
2621 | |
---|
2622 | |
---|
2623 | }, |
---|
2624 | done: function(e, data){ |
---|
2625 | var msg = ''; |
---|
2626 | var type = ''; |
---|
2627 | |
---|
2628 | if(!!data.result && data.result == "[][[]]"){ |
---|
2629 | msg = 'Não foram encontrados novos eventos na importação!'; |
---|
2630 | type = 'information'; |
---|
2631 | }else if(!!data.result && data.result == '[][false]'){ |
---|
2632 | msg = 'Erro ao realizar a importação, por favor verifique o arquivo .ics'; |
---|
2633 | type = 'warning'; |
---|
2634 | }else{ |
---|
2635 | msg = 'Importação realizada com sucesso!'; |
---|
2636 | type = 'confirmation'; |
---|
2637 | Calendar.rerenderView(true); |
---|
2638 | } |
---|
2639 | |
---|
2640 | $.Zebra_Dialog(msg, { |
---|
2641 | 'type': type, |
---|
2642 | 'overlay_opacity': '0.5', |
---|
2643 | 'buttons': ['Fechar'] |
---|
2644 | }); |
---|
2645 | } |
---|
2646 | }); |
---|
2647 | |
---|
2648 | UI.dialogs.importCalendar.find(".menu-import-event") |
---|
2649 | .children(".import").click(function(data){ |
---|
2650 | $('.import-event-form fieldset.import-calendar', UI.dialogs.importCalendar).append( |
---|
2651 | '<input type="hidden" name="params[calendar_timezone]" value="'+ |
---|
2652 | Calendar.signatureOf[$('.import-event-form option:selected').val()].calendar.timezone |
---|
2653 | +'"/>') |
---|
2654 | if(form) |
---|
2655 | form.submit(); |
---|
2656 | UI.dialogs.importCalendar.dialog("close"); |
---|
2657 | /** |
---|
2658 | * TODO - implementar ação de importação |
---|
2659 | */ |
---|
2660 | }); |
---|
2661 | |
---|
2662 | UI.dialogs.importCalendar.find(".menu-export-event") |
---|
2663 | .children(".export").click(function(){ |
---|
2664 | |
---|
2665 | $('.export-event-form', UI.dialogs.importCalendar).submit(); |
---|
2666 | UI.dialogs.importCalendar.dialog("close"); |
---|
2667 | /** |
---|
2668 | * TODO - implementar ação de exportação |
---|
2669 | */ |
---|
2670 | }); |
---|
2671 | |
---|
2672 | UI.dialogs.importCalendar.find(".menu-container") |
---|
2673 | .children(".cancel").click(function(){ |
---|
2674 | UI.dialogs.importCalendar.dialog("close"); |
---|
2675 | }); |
---|
2676 | |
---|
2677 | UI.dialogs.importCalendar.dialog("open"); |
---|
2678 | }); |
---|
2679 | } |
---|
2680 | |
---|
2681 | function copyAndMoveTo(calendar, event, idRecurrence, type, evt){ |
---|
2682 | /* |
---|
2683 | * Types |
---|
2684 | * 0 = Move |
---|
2685 | * 1 = Copy Event end Repet |
---|
2686 | * 2 = Copy Ocurrence |
---|
2687 | * 3 = Copy to edit ocurrence |
---|
2688 | * |
---|
2689 | **/ |
---|
2690 | if(!type) |
---|
2691 | type = $('.calendar-copy-move input[name="typeEvent"]').val(); |
---|
2692 | |
---|
2693 | var schedulable = DataLayer.get('schedulable', event+''); |
---|
2694 | |
---|
2695 | calendar = !!calendar ? calendar : schedulable.calendar; |
---|
2696 | |
---|
2697 | if(typeof(schedulable) == "array") |
---|
2698 | schedulable = schedulable[0]; |
---|
2699 | |
---|
2700 | //Move eventos entre agendas |
---|
2701 | if(parseInt(type) == 0){ |
---|
2702 | |
---|
2703 | schedulable.lastCalendar = schedulable.calendar; |
---|
2704 | schedulable.calendar = calendar; |
---|
2705 | DataLayer.put('schedulable', schedulable); |
---|
2706 | |
---|
2707 | DataLayer.commit(); |
---|
2708 | //copia eventos entre agendas |
---|
2709 | }else{ |
---|
2710 | |
---|
2711 | var newSchedulable = schedulable; |
---|
2712 | |
---|
2713 | delete newSchedulable.id; |
---|
2714 | delete newSchedulable.uid; |
---|
2715 | delete newSchedulable.sequence; |
---|
2716 | delete newSchedulable.dtstamp; |
---|
2717 | |
---|
2718 | delete schedulable.DayLigth; |
---|
2719 | delete schedulable.rangeStart |
---|
2720 | delete schedulable.rangeEnd; |
---|
2721 | delete schedulable.lastUpdate; |
---|
2722 | |
---|
2723 | delete schedulable.calendar; |
---|
2724 | |
---|
2725 | if(schedulable.repeat && type == "1" ){ |
---|
2726 | var repeat = DataLayer.get('repeat', schedulable.repeat); |
---|
2727 | delete repeat.schedulable; |
---|
2728 | delete repeat.id; |
---|
2729 | repeat.startTime = new Date(parseInt(repeat.startTime)).toString('yyyy-MM-dd HH:mm:00'); |
---|
2730 | repeat.endTime = new Date(parseInt(repeat.endTime)).toString('yyyy-MM-dd HH:mm:00'); |
---|
2731 | |
---|
2732 | var exceptions = DataLayer.get('repeatOccurrence', { |
---|
2733 | filter: ['AND', ['=','repeat', schedulable.repeat], ['=','exception','1']] |
---|
2734 | }, true); |
---|
2735 | if(exceptions){ |
---|
2736 | repeat.exceptions = ''; |
---|
2737 | for(var i in exceptions ) |
---|
2738 | repeat.exceptions += exceptions[i].occurrence + ((exceptions.length -1) == parseInt(i) ? '' : ','); |
---|
2739 | |
---|
2740 | } |
---|
2741 | |
---|
2742 | |
---|
2743 | schedulable.repeat = repeat; |
---|
2744 | }else{ |
---|
2745 | if(!!idRecurrence){ |
---|
2746 | newSchedulable.endTime = parseInt(schedulable.occurrences[idRecurrence]) + (parseInt(newSchedulable.endTime) - parseInt(newSchedulable.startTime)); |
---|
2747 | newSchedulable.startTime = schedulable.occurrences[idRecurrence]; |
---|
2748 | } |
---|
2749 | delete schedulable.repeat; |
---|
2750 | } |
---|
2751 | delete schedulable.occurrences; |
---|
2752 | |
---|
2753 | schedulable.calendar = DataLayer.copy(calendar); |
---|
2754 | |
---|
2755 | var participants = DataLayer.copy(schedulable.participants); |
---|
2756 | delete schedulable.participants; |
---|
2757 | |
---|
2758 | schedulable.participants = $.map( participants, function( attendee, i ){ |
---|
2759 | |
---|
2760 | var participant = DataLayer.get('participant', attendee, false); |
---|
2761 | |
---|
2762 | if(typeof(participant) == 'array') |
---|
2763 | participant = participant[0]; |
---|
2764 | |
---|
2765 | delete participant.delegatedFrom; |
---|
2766 | delete participant.id; |
---|
2767 | delete participant.schedulable; |
---|
2768 | |
---|
2769 | participant.id = DataLayer.put('participant', participant); |
---|
2770 | |
---|
2771 | return participant ; |
---|
2772 | }); |
---|
2773 | //Edit ocurrence |
---|
2774 | if(parseInt(type) == 3){ |
---|
2775 | newSchedulable.endTime = !!evt.end ? evt.end.getTime() : ((evt.start).getTime() + 86400000); |
---|
2776 | newSchedulable.startTime = evt.start.getTime(); |
---|
2777 | |
---|
2778 | return newSchedulable; |
---|
2779 | } |
---|
2780 | newSchedulable.endTime = new Date(parseInt(newSchedulable.endTime) - (newSchedulable.allDay ? 86400000 : 0)).toString('yyyy-MM-dd hh:mm:00'); |
---|
2781 | newSchedulable.startTime = new Date(parseInt(newSchedulable.startTime)).toString('yyyy-MM-dd hh:mm:00'); |
---|
2782 | |
---|
2783 | DataLayer.put('schedulable', newSchedulable); |
---|
2784 | |
---|
2785 | } |
---|
2786 | } |
---|
2787 | |
---|
2788 | function messageHelper(msg, isShow){ |
---|
2789 | if(isShow) |
---|
2790 | new $.Zebra_Dialog('<span style="width: 50px; height: 50px;">'+ |
---|
2791 | '<img src="'+DataLayer.dispatchPath+'/modules/calendar/img/loading.gif"></img>'+ |
---|
2792 | '</span><label class="messagesHelpers"> '+ msg +' </label>' , { |
---|
2793 | 'buttons': false, |
---|
2794 | 'modal': true, |
---|
2795 | 'overlay_opacity': '0.5', |
---|
2796 | 'keyboard': false, |
---|
2797 | 'overlay_close': false, |
---|
2798 | 'type': false, |
---|
2799 | 'custom_class': 'messagesHelpersExpressoCalendar' |
---|
2800 | } |
---|
2801 | ); |
---|
2802 | else{ |
---|
2803 | $('.messagesHelpersExpressoCalendar').remove(); |
---|
2804 | $('.ZebraDialogOverlay').remove(); |
---|
2805 | } |
---|
2806 | } |
---|