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