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 | function eventDetails( objEvent, decoded, path) |
---|
62 | { |
---|
63 | if(path == undefined) |
---|
64 | path = ""; |
---|
65 | |
---|
66 | if( !decoded ) |
---|
67 | objEvent = DataLayer.decode( "schedulable:calendar", objEvent ); |
---|
68 | |
---|
69 | objEvent = DataLayer.encode( "schedulable:preview", objEvent ); |
---|
70 | |
---|
71 | if(typeof(objEvent.id) == 'undefined'){ |
---|
72 | objEvent.alarms = Calendar.signatureOf[User.preferences.defaultCalendar || Calendar.calendarIds[0]].defaultAlarms || false; |
---|
73 | objEvent.useAlarmDefault = 1; |
---|
74 | } |
---|
75 | |
---|
76 | /** |
---|
77 | * canDiscardEventDialog deve ser true se não houver alterações no evento |
---|
78 | */ |
---|
79 | canDiscardEventDialog = true; |
---|
80 | /** |
---|
81 | * zebraDiscardEventDialog é uma flag indicando que uma janela de confirmação (Zebra_Dialog) |
---|
82 | * já está aberta na tela, uma vez que não é possivel acessar o evento ESC utilizado para fechá-la |
---|
83 | */ |
---|
84 | zebraDiscardEventDialog = false; |
---|
85 | |
---|
86 | /** |
---|
87 | ACLs do participant |
---|
88 | */ |
---|
89 | acl_names = { |
---|
90 | 'w': 'acl-white', |
---|
91 | 'i': 'acl-invite-guests', |
---|
92 | 'p': 'acl-participation-required' |
---|
93 | }; |
---|
94 | /** |
---|
95 | * callback de participantes generico |
---|
96 | */ |
---|
97 | var callbackAttendee = function(){ |
---|
98 | //Cria qtip de permissões pelo click do checkbox |
---|
99 | var checked = false; |
---|
100 | blkAddAtendee.find("li.not-attendee").addClass('hidden'); |
---|
101 | |
---|
102 | blkAddAtendee.find("li .button").filter(".close.new").button({ |
---|
103 | icons: { |
---|
104 | primary: "ui-icon-close" |
---|
105 | }, |
---|
106 | text: false |
---|
107 | }).click(function () { |
---|
108 | DataLayer.remove('participant', $(this).parents('li').find('[type=checkbox]').val()); |
---|
109 | if($(this).parent().find('.button.delegate').hasClass('attendee-permissions-change-button')){ |
---|
110 | |
---|
111 | blkAddAtendee.find('.request-update').addClass('hidden'); |
---|
112 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
113 | |
---|
114 | blkAddAtendee.find('option[value=1]').attr('selected','selected').trigger('change'); |
---|
115 | } |
---|
116 | |
---|
117 | $(this).parents('li').remove(); |
---|
118 | |
---|
119 | if(blkAddAtendee.find(".attendee-list li").length == 1) |
---|
120 | blkAddAtendee.find("li.not-attendee").removeClass('hidden'); |
---|
121 | }) |
---|
122 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
123 | .removeClass('new').end() |
---|
124 | |
---|
125 | .filter(".delegate.new").button({ |
---|
126 | icons: { |
---|
127 | primary: "ui-icon-transferthick-e-w" |
---|
128 | }, |
---|
129 | text: false |
---|
130 | }).click(function () { |
---|
131 | |
---|
132 | if($(this).hasClass('attendee-permissions-change-button')){ |
---|
133 | $(this).removeClass('attendee-permissions-change-button') |
---|
134 | .find('.ui-icon-transferthick-e-w').removeClass('attendee-permissions-change').end(); |
---|
135 | |
---|
136 | $(this).parents('li').find('input[name="delegatedFrom[]"]').val(''); |
---|
137 | |
---|
138 | blkAddAtendee.find('.request-update').addClass('hidden'); |
---|
139 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
140 | |
---|
141 | |
---|
142 | blkAddAtendee.find('option[value=1]').attr('selected','selected').trigger('change'); |
---|
143 | |
---|
144 | }else{ |
---|
145 | blkAddAtendee.find('.delegate').removeClass('attendee-permissions-change-button'); |
---|
146 | blkAddAtendee.find('.ui-icon-transferthick-e-w').removeClass('attendee-permissions-change'); |
---|
147 | |
---|
148 | $(this).addClass('attendee-permissions-change-button') |
---|
149 | .find('.ui-icon-transferthick-e-w').addClass('attendee-permissions-change').end(); |
---|
150 | $(this).parents('li').find('input[name="delegatedFrom[]"]').val(blkAddAtendee.find('.me input[name="attendee[]"]').val()); |
---|
151 | |
---|
152 | blkAddAtendee.find('.request-update').removeClass('hidden'); |
---|
153 | if(blkAddAtendee.find('.status option.hidden').length == 1) |
---|
154 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
155 | |
---|
156 | blkAddAtendee.find('option[value=5]').attr('selected','selected').trigger('change'); |
---|
157 | } |
---|
158 | }) |
---|
159 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
160 | .removeClass('new').end() |
---|
161 | |
---|
162 | .filter(".edit.new").button({ |
---|
163 | icons: { |
---|
164 | primary: "ui-icon-key" |
---|
165 | }, |
---|
166 | text: false |
---|
167 | }).click(function() { |
---|
168 | |
---|
169 | if(!!!checked) |
---|
170 | $(this).parents('li').find('[type=checkbox]').attr('checked', (!$(this).parent().find('[type=checkbox]').is(':checked'))).end(); |
---|
171 | |
---|
172 | var aclsParticipant = $(this).parents('li').find('input[name="attendeeAcl[]"]').val(); |
---|
173 | checked = false; |
---|
174 | |
---|
175 | if( $('.qtip.qtip-blue.qtip-active').val() !== ''){ |
---|
176 | blkAddAtendee.find('dd.attendee-list').qtip({ |
---|
177 | show: {ready: true, solo: true, when: {event: 'click'}}, |
---|
178 | hide: false, |
---|
179 | content: { |
---|
180 | text: $('<div></div>').html( DataLayer.render( 'templates/attendee_permissions.ejs', {} ) ), |
---|
181 | title: { |
---|
182 | text:'Permissões', |
---|
183 | button: '<a class="button close" href="#">close</a>' |
---|
184 | } |
---|
185 | }, |
---|
186 | style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}}, |
---|
187 | position: { |
---|
188 | corner: { |
---|
189 | target: 'rightMiddle', |
---|
190 | tooltip: 'leftMiddle' |
---|
191 | }, |
---|
192 | adjust: {x:0, y:0} |
---|
193 | } |
---|
194 | }) |
---|
195 | .qtip("api").onShow = function(arg0) { |
---|
196 | $('.qtip-active .button.close').button({ |
---|
197 | icons: {primary: "ui-icon-close"}, |
---|
198 | text: false |
---|
199 | }) |
---|
200 | .click(function(){ |
---|
201 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
202 | }); |
---|
203 | |
---|
204 | $('.qtip-active .button.save').button().click(function(){ |
---|
205 | |
---|
206 | var acl = ''; |
---|
207 | $('.qtip-active').find('[type=checkbox]:checked').each(function(i, obj) { |
---|
208 | acl+= obj.value; |
---|
209 | }); |
---|
210 | |
---|
211 | blkAddAtendee.find('dd.attendee-list [type=checkbox]:checked').siblings('input[name="attendeeAcl[]"]').each(function(i, obj) { |
---|
212 | obj.value = 'r'+acl; |
---|
213 | }).parents('li').find('.button.edit').addClass('attendee-permissions-change-button') |
---|
214 | .find('.ui-icon-key').addClass('attendee-permissions-change'); |
---|
215 | |
---|
216 | blkAddAtendee.find('dd.attendee-list [type=checkbox]').attr('checked', false); |
---|
217 | |
---|
218 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
219 | |
---|
220 | }); |
---|
221 | $('.qtip-active .button.cancel').button().click(function(){ |
---|
222 | blkAddAtendee.find('dd.attendee-list [type=checkbox]').attr('checked', false); |
---|
223 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
224 | }); |
---|
225 | |
---|
226 | if(aclsParticipant) |
---|
227 | for(var i = 1; i < aclsParticipant.length; i++){ |
---|
228 | $('.qtip-active').find('input[name="'+acl_names[aclsParticipant.charAt(i)]+'"]').attr('checked', true); |
---|
229 | } |
---|
230 | |
---|
231 | |
---|
232 | $('.button').button(); |
---|
233 | |
---|
234 | }; |
---|
235 | }else{ |
---|
236 | if(!$('.new-event-win dd.attendee-list').find('[type=checkbox]:checked').length){ |
---|
237 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
238 | }else{ |
---|
239 | $('.qtip-active .button.save .ui-button-text').html('Aplicar a todos') |
---|
240 | } |
---|
241 | |
---|
242 | }; |
---|
243 | }) |
---|
244 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
245 | .removeClass('new').end() |
---|
246 | |
---|
247 | .filter(".open-delegate.new").click(function(){ |
---|
248 | if($(this).hasClass('ui-icon-triangle-1-e')){ |
---|
249 | $(this).removeClass('ui-icon-triangle-1-e').addClass('ui-icon-triangle-1-s'); |
---|
250 | $(this).parents('li').find('.list-delegates').removeClass('hidden'); |
---|
251 | }else{ |
---|
252 | $(this).removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e'); |
---|
253 | $(this).parents('li').find('.list-delegates').addClass('hidden'); |
---|
254 | } |
---|
255 | |
---|
256 | }).removeClass('new'); |
---|
257 | |
---|
258 | |
---|
259 | blkAddAtendee.find("li input[type=checkbox].new").click(function(){ |
---|
260 | if(!$('.new-event-win dd.attendee-list').find('[type=checkbox]:checked').length){ |
---|
261 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
262 | }else{ |
---|
263 | checked = true; |
---|
264 | $(this).parents('li').find('.button.edit').click(); |
---|
265 | } |
---|
266 | }).removeClass('new'); |
---|
267 | |
---|
268 | UI.dialogs.addEvent.find('.attendees-list li').hover( |
---|
269 | function () { |
---|
270 | $(this).addClass("hover-attendee"); |
---|
271 | $(this).find('.button').removeClass('disable ui-button-disabled ui-state-disabled').end() |
---|
272 | .find('.attendee-options').addClass('hover-attendee'); |
---|
273 | }, |
---|
274 | function () { |
---|
275 | $(this).removeClass("hover-attendee"); |
---|
276 | $(this).find('.button').addClass('disable ui-button-disabled ui-state-disabled').end() |
---|
277 | .find('.attendee-options').removeClass('hover-attendee');; |
---|
278 | } |
---|
279 | ); |
---|
280 | |
---|
281 | |
---|
282 | } |
---|
283 | |
---|
284 | var html = DataLayer.render( path+'templates/event_add.ejs', {event:objEvent}); |
---|
285 | |
---|
286 | if (!UI.dialogs.addEvent) { |
---|
287 | UI.dialogs.addEvent = jQuery('#sandbox').append('<div title="Criar Evento" class="new-event-win active"> <div>').find('.new-event-win.active').html(html).dialog({ |
---|
288 | resizable: false, |
---|
289 | modal:true, |
---|
290 | autoOpen: false, |
---|
291 | width:700, |
---|
292 | position: 'center', |
---|
293 | close: function(event, ui) { |
---|
294 | /** |
---|
295 | * Remove tooltip possivelmente existente |
---|
296 | */ |
---|
297 | if ($('dd.attendee-list li:last').data('qtip')) |
---|
298 | $('dd.attendee-list li:last').qtip('destroy'); |
---|
299 | |
---|
300 | }, |
---|
301 | beforeClose: function(event, ui) { |
---|
302 | |
---|
303 | if (!canDiscardEventDialog && !zebraDiscardEventDialog) { |
---|
304 | zebraDiscardEventDialog = true; |
---|
305 | window.setTimeout(function() { |
---|
306 | $.Zebra_Dialog('Suas alterações no evento não foram salvas. Deseja descartar as alterações?', { |
---|
307 | 'type': 'question', |
---|
308 | 'overlay_opacity': '0.5', |
---|
309 | 'buttons': ['Descartar alterações', 'Continuar editando'], |
---|
310 | 'onClose': function(clicked) { |
---|
311 | if(clicked == 'Descartar alterações') { |
---|
312 | canDiscardEventDialog = true; |
---|
313 | /** |
---|
314 | *Remoção dos anexos do eventos caso seja cancelado a edição |
---|
315 | */ |
---|
316 | var ids = []; |
---|
317 | $.each($('.attachment-list input'), function (i, input) { ids.push(input.value); }); |
---|
318 | if(ids.length > 0) |
---|
319 | DataLayer.remove('attachment', {filter: ['IN', 'id', ids]}); |
---|
320 | |
---|
321 | UI.dialogs.addEvent.dialog('close'); |
---|
322 | }else{ |
---|
323 | zebraDiscardEventDialog = false; |
---|
324 | } |
---|
325 | |
---|
326 | /** |
---|
327 | * Uma vez aberta uma janela de confirmação (Zebra_Dialog), ao fechá-la |
---|
328 | * com ESC, para que o evento ESC não seja propagado para fechamento da |
---|
329 | * janela de edição de eventos, deve ser setada uma flag indicando que |
---|
330 | * já existe uma janela de confirmação aberta. |
---|
331 | */ |
---|
332 | if (!clicked) { |
---|
333 | window.setTimeout(function() { |
---|
334 | zebraDiscardEventDialog = false; |
---|
335 | }, 200); |
---|
336 | } |
---|
337 | } |
---|
338 | }); |
---|
339 | |
---|
340 | }, 300); |
---|
341 | |
---|
342 | } |
---|
343 | return canDiscardEventDialog; |
---|
344 | } |
---|
345 | }); |
---|
346 | |
---|
347 | } else { |
---|
348 | UI.dialogs.addEvent.html(html); |
---|
349 | } |
---|
350 | |
---|
351 | var tabs = UI.dialogs.addEvent.children('.content').tabs(); |
---|
352 | var calendar = DataLayer.get('calendar', objEvent.calendar); |
---|
353 | |
---|
354 | if (calendar.timezone != objEvent.timezone){ |
---|
355 | UI.dialogs.addEvent.find('.calendar-addevent-details-txt-timezone').find('option[value="'+objEvent.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
356 | UI.dialogs.addEvent.find('.calendar_addevent_details_lnk_timezone').addClass('hidden'); |
---|
357 | $('.calendar-addevent-details-txt-timezone').removeClass('hidden'); |
---|
358 | |
---|
359 | } |
---|
360 | |
---|
361 | UI.dialogs.addEvent.find('.calendar_addevent_details_lnk_timezone').click(function(e){ |
---|
362 | $(this).addClass('hidden'); |
---|
363 | $('.calendar-addevent-details-txt-timezone').removeClass('hidden'); |
---|
364 | e.preventDefault(); |
---|
365 | }); |
---|
366 | |
---|
367 | UI.dialogs.addEvent.find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el){ |
---|
368 | var id; |
---|
369 | if( id = $(this).parent().find('input[name="alarmId[]"]').val()) |
---|
370 | DataLayer.remove('alarm', id); |
---|
371 | $(this).parent().remove().find('li').is(':empty'); |
---|
372 | }); |
---|
373 | |
---|
374 | /*Seleciona a agenda padrão para criação de um evento*/ |
---|
375 | UI.dialogs.addEvent.find('option[value="'+objEvent.calendar || User.preferences.defaultCalendar+'"]').attr('selected','selected').trigger('change'); |
---|
376 | |
---|
377 | /*Adicionar alarms padrões, quando alterado a agenda do usuário*/ |
---|
378 | UI.dialogs.addEvent.find('select[name="calendar"]').change(function(){ |
---|
379 | if((typeof($('input[name = "idEvent"]').val()) == 'undefined') || (!!!$('input[name = "idEvent"]').val())) { |
---|
380 | $('input[name = "isDefaultAlarm[]"]').parent().remove(); |
---|
381 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').parent().removeClass('hidden'); |
---|
382 | var calendarSelected = Calendar.signatureOf[$(this).val()]; |
---|
383 | calendarSelected.useAlarmDefault = 1; |
---|
384 | if(calendarSelected.defaultAlarms != ""){ |
---|
385 | var li_attach = DataLayer.render(path+'templates/alarms_add_itemlist.ejs', {alarm:calendarSelected}); |
---|
386 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
387 | $(this).parent().remove().find('li').is(':empty'); |
---|
388 | }); |
---|
389 | }else{ |
---|
390 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').parent().addClass('hidden'); |
---|
391 | } |
---|
392 | } |
---|
393 | }); |
---|
394 | |
---|
395 | /*Checkbox adicionar alarms padrões*/ |
---|
396 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').click(function(){ |
---|
397 | if($(this).attr("checked")){ |
---|
398 | $('input[name="isDefaultAlarm[]"]').parent().remove(); |
---|
399 | var calendarSelected = Calendar.signatureOf[$('select[name="calendar"]').val()]; |
---|
400 | calendarSelected.useAlarmDefault = 1; |
---|
401 | if(calendarSelected.defaultAlarms != ""){ |
---|
402 | var li_attach = DataLayer.render(path+'templates/alarms_add_itemlist.ejs', {alarm:calendarSelected}); |
---|
403 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
404 | var id; |
---|
405 | if( id = $(this).parent().find('input[name="alarmId[]"]').val()) |
---|
406 | DataLayer.remove('alarm', id); |
---|
407 | $(this).parent().remove().find('li').is(':empty') |
---|
408 | }); |
---|
409 | } |
---|
410 | } else { |
---|
411 | $('input[name="isDefaultAlarm[]"]').parent().remove(); |
---|
412 | } |
---|
413 | }); |
---|
414 | /* Checkbox allday */ |
---|
415 | UI.dialogs.addEvent.find('input[name="allDay"]').click(function(){ |
---|
416 | $(this).attr("checked") ? |
---|
417 | UI.dialogs.addEvent.find('.start-time, .end-time').addClass('hidden') : |
---|
418 | UI.dialogs.addEvent.find('.start-time, .end-time').removeClass('hidden'); |
---|
419 | }); |
---|
420 | |
---|
421 | UI.dialogs.addEvent.find('.button').button(); |
---|
422 | UI.dialogs.addEvent.find('.button.add').button({ |
---|
423 | icons: { |
---|
424 | secondary: "ui-icon-plus" |
---|
425 | } |
---|
426 | }); |
---|
427 | |
---|
428 | // ==== validation events ==== |
---|
429 | UI.dialogs.addEvent.find(".input-group .h1").Watermark("Evento sem título"); |
---|
430 | if(User.preferences.hourFormat.length == 5) { |
---|
431 | UI.dialogs.addEvent.find(".end-time, .start-time").mask("99:99"); |
---|
432 | } else { |
---|
433 | $.mask.definitions['{']='[ap]'; |
---|
434 | $.mask.definitions['}']='[m]'; |
---|
435 | UI.dialogs.addEvent.find(".end-time, .start-time").mask("99:99 {}", { |
---|
436 | completed:function(){ |
---|
437 | $(this).val(date.Calendar.defaultToAmPm($(this).val())); |
---|
438 | $(this).timepicker("refresh"); |
---|
439 | $(this).val($(this).val().replace(/[\.]/gi, "")); |
---|
440 | } |
---|
441 | }); |
---|
442 | } |
---|
443 | UI.dialogs.addEvent.find(".number").numeric(); |
---|
444 | User.preferences.dateFormat.indexOf('-') > 0 ? |
---|
445 | UI.dialogs.addEvent.find(".date").mask("99-99-9999") : |
---|
446 | UI.dialogs.addEvent.find(".date").mask("99/99/9999"); |
---|
447 | |
---|
448 | UI.dialogs.addEvent.find(".menu-addevent") |
---|
449 | .children(".delete").click(function(){ |
---|
450 | $.Zebra_Dialog('Tem certeza que deseja excluir o evento?', { |
---|
451 | 'type': 'question', |
---|
452 | 'overlay_opacity': '0.5', |
---|
453 | 'buttons': ['Sim', 'Não'], |
---|
454 | 'onClose': function(clicked) { |
---|
455 | if(clicked == 'Sim'){ |
---|
456 | DataLayer.remove( "schedulable", UI.dialogs.addEvent.find(".id-event").val() ); |
---|
457 | UI.dialogs.addEvent.dialog("close"); |
---|
458 | } |
---|
459 | } |
---|
460 | }); |
---|
461 | }).end() |
---|
462 | |
---|
463 | .children(".cancel").click(function(){ |
---|
464 | DataLayer.rollback('participant'); |
---|
465 | UI.dialogs.addEvent.dialog("close"); |
---|
466 | }).end() |
---|
467 | |
---|
468 | .children(".save").click(function(){ |
---|
469 | /* Validação */ |
---|
470 | var msg = false; |
---|
471 | if(msg = validDateEvent()){ |
---|
472 | $(".new-event-win.active").find('.messages-validation').removeClass('hidden').find('.message label').html(msg); |
---|
473 | return false; |
---|
474 | } |
---|
475 | |
---|
476 | canDiscardEventDialog = true; |
---|
477 | |
---|
478 | UI.dialogs.addEvent.children().find('form.form-addevent').submit(); |
---|
479 | UI.dialogs.addEvent.dialog("close"); |
---|
480 | }).end() |
---|
481 | |
---|
482 | .children(".export").click(function(){ |
---|
483 | UI.dialogs.addEvent.children().find(".form-export").submit(); |
---|
484 | }); |
---|
485 | |
---|
486 | UI.dialogs.addEvent.find('input.date').datepicker({dateFormat: 'dd/mm/yy'}); |
---|
487 | if(path == ""){ |
---|
488 | UI.dialogs.addEvent.find('input.time').timepicker({ |
---|
489 | closeText: 'Ok', |
---|
490 | hourGrid: 4, |
---|
491 | minuteGrid: 10, |
---|
492 | ampm : ((User.preferences.hourFormat.length > 5) ? true: false), |
---|
493 | timeFormat: "hh:mm tt", |
---|
494 | onSelect: function (selectedDateTime){ |
---|
495 | if(!(User.preferences.hourFormat.length == 5)) |
---|
496 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
497 | }, |
---|
498 | onClose : function (selectedDateTime){ |
---|
499 | if(!(User.preferences.hourFormat.length == 5)) |
---|
500 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
501 | } |
---|
502 | }); |
---|
503 | } |
---|
504 | |
---|
505 | UI.dialogs.addEvent.find('.button-add-alarms').click(function(){ |
---|
506 | var li_attach = DataLayer.render(path+'templates/alarms_add_itemlist.ejs', {}); |
---|
507 | |
---|
508 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
509 | $(this).parent().remove().find('li').is(':empty') |
---|
510 | }); |
---|
511 | // valicacao de campos numericos |
---|
512 | $('.number').numeric(); |
---|
513 | }); |
---|
514 | |
---|
515 | |
---|
516 | UI.dialogs.addEvent.find('.button.suggestion-hours').button({ |
---|
517 | icons: { |
---|
518 | primary: "ui-icon-clock" |
---|
519 | }, |
---|
520 | text: 'Sugerir horário' |
---|
521 | }).click(function () { |
---|
522 | $(this).siblings('input').removeAttr('disabled') |
---|
523 | .end().parents().find('input[name="allDay"]').removeAttr('disabled'); |
---|
524 | }); |
---|
525 | |
---|
526 | if(objEvent.me.id == User.me.id){ |
---|
527 | objEvent.me.id = DataLayer.put('participant', {user: objEvent.me.id, mail: objEvent.me.mail }); |
---|
528 | objEvent.organizer.id = objEvent.me.id; |
---|
529 | } |
---|
530 | |
---|
531 | var attendeeHtml = DataLayer.render( path+'templates/attendee_add.ejs', {event:objEvent}); |
---|
532 | |
---|
533 | // load template of attendees |
---|
534 | var blkAddAtendee = UI.dialogs.addEvent.find('#calendar_addevent_details6').append(attendeeHtml); |
---|
535 | if(objEvent.attendee.length) |
---|
536 | callbackAttendee(); |
---|
537 | /** |
---|
538 | Opções de delegação do participante/organizer |
---|
539 | */ |
---|
540 | blkAddAtendee.find(".button.participant-delegate").button({ |
---|
541 | icons: { |
---|
542 | primary: "ui-icon-transferthick-e-w" |
---|
543 | }, |
---|
544 | text: false |
---|
545 | }).click(function () { |
---|
546 | if($(this).hasClass('attendee-permissions-change-button')){ |
---|
547 | if(!$(this).hasClass('disable')){ |
---|
548 | $(this).removeClass('attendee-permissions-change-button') |
---|
549 | .find('.ui-icon-transferthick-e-w').removeClass('attendee-permissions-change').end(); |
---|
550 | blkAddAtendee.find('.block-add-attendee.search').addClass('hidden'); |
---|
551 | blkAddAtendee.find('.block-add-attendee.search dt').html('Adicionar outros contatos'); |
---|
552 | } |
---|
553 | }else{ |
---|
554 | $(this).addClass('attendee-permissions-change-button') |
---|
555 | .find('.ui-icon-transferthick-e-w').addClass('attendee-permissions-change').end(); |
---|
556 | blkAddAtendee.find('.block-add-attendee.search dt').html('Delegar participação para'); |
---|
557 | blkAddAtendee.find('.block-add-attendee.search').removeClass('hidden'); |
---|
558 | blkAddAtendee.find('.block-add-attendee.search input.search').focus(); |
---|
559 | } |
---|
560 | }) |
---|
561 | .addClass('tiny'); |
---|
562 | |
---|
563 | //show or hidden permissions attendees |
---|
564 | //blkAddAtendee.find('.block-attendee-list #attendees-users li').click(show_permissions_attendees); |
---|
565 | |
---|
566 | UI.dialogs.addEvent.find(".attendee-list-add .add-attendee-input input").Watermark("digite um email para convidar"); |
---|
567 | /* Trata a edição de um novo participante adicionado |
---|
568 | * |
---|
569 | */ |
---|
570 | var hasNewAttendee = false; |
---|
571 | blkAddAtendee.find('.attendee-list-add .add-attendee-input input').keydown(function(event) { |
---|
572 | |
---|
573 | if (event.keyCode == '13' && $(this).val() != '') { |
---|
574 | Encoder.EncodeType = "entity"; |
---|
575 | $(this).val(Encoder.htmlEncode($(this).val())); |
---|
576 | |
---|
577 | newAttendeeEmail = false; |
---|
578 | newAttendeeName = false; |
---|
579 | skipAddNewLine = false; |
---|
580 | |
---|
581 | var info = $(this).val(); |
---|
582 | |
---|
583 | /** |
---|
584 | * email válido? |
---|
585 | */ |
---|
586 | info.match(/^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/) ? |
---|
587 | newAttendeeEmail = info : newAttendeeName = info; |
---|
588 | |
---|
589 | /** |
---|
590 | * 1) busca no banco para saber se o usuário já existe |
---|
591 | * 1.1) se existe, atualiza as info na lista de participantes e nao abre o tooltip |
---|
592 | * 1.2) se não existe |
---|
593 | * a) salva como novo usuario externo no banco (apenas com email) |
---|
594 | * b) exibe tooltip pedindo o nome |
---|
595 | * c) se o usuário preenche tooltip e salva, atualiza com o nome o usuário recém criado |
---|
596 | * d) se o usuário cancela o tooltip, fica o usuário salvo apenas com email e sem nome |
---|
597 | */ |
---|
598 | |
---|
599 | var user = DataLayer.get('user', ["=", "mail", $(this).val()], true); |
---|
600 | |
---|
601 | |
---|
602 | /** |
---|
603 | * guarda o último tooltip aberto referente à lista de participantes |
---|
604 | */ |
---|
605 | lastEditAttendeeToolTip = []; |
---|
606 | |
---|
607 | /** |
---|
608 | * Valida email e salva um participante externo |
---|
609 | */ |
---|
610 | var saveContact = function() { |
---|
611 | Encoder.EncodeType = "entity"; |
---|
612 | |
---|
613 | var currentTip = $('.qtip-active'); |
---|
614 | newAttendeeName = currentTip.find('input[name="name"]').val(); |
---|
615 | newAttendeeEmail = currentTip.find('input[name="mail"]').val(); |
---|
616 | |
---|
617 | if (!(!!newAttendeeEmail.match(/^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/))) { |
---|
618 | currentTip.find('.messages').removeClass('hidden').find('.message label').html('Email inválido.'); |
---|
619 | return false; |
---|
620 | } |
---|
621 | |
---|
622 | DataLayer.put('user', {id:userId, name:newAttendeeName, mail:newAttendeeEmail, isExternal:isExternal}); |
---|
623 | |
---|
624 | lastEditAttendeeToolTip.find('label') |
---|
625 | .filter('.name').html(Encoder.htmlEncode(newAttendeeName)).attr('title', Encoder.htmlEncode(newAttendeeName)).end() |
---|
626 | .filter('.mail').html(Encoder.htmlEncode(newAttendeeEmail)).attr('title', Encoder.htmlEncode(newAttendeeEmail)); |
---|
627 | |
---|
628 | blkAddAtendee.find('.attendee-list-add .add-attendee-input input').val(''); |
---|
629 | return true; |
---|
630 | } |
---|
631 | |
---|
632 | /** |
---|
633 | * Formata e adequa um tootip abert para edição de um participante na lista |
---|
634 | */ |
---|
635 | var onShowToolTip = function(arg0) { |
---|
636 | $('.qtip-active .button.close').button({ |
---|
637 | icons: {primary: "ui-icon-close"}, |
---|
638 | text: false |
---|
639 | }); |
---|
640 | $('.qtip-active .button').button() |
---|
641 | .filter('.save').click(function(event, ui) { |
---|
642 | if(saveContact()) |
---|
643 | lastEditAttendeeToolTip.qtip("destroy"); |
---|
644 | else |
---|
645 | return false; |
---|
646 | }).end() |
---|
647 | .filter('.cancel').click(function(event, ui) { |
---|
648 | lastEditAttendeeToolTip.qtip("destroy"); |
---|
649 | }) |
---|
650 | |
---|
651 | /** |
---|
652 | * Trata o ENTER no campo da tooltip, equivalente a salvar |
---|
653 | * o novo convidado. |
---|
654 | */ |
---|
655 | $('.qtip-active input').keydown(function(event) { |
---|
656 | if (event.keyCode == '13') { |
---|
657 | if (saveContact()) |
---|
658 | lastEditAttendeeToolTip.qtip("destroy"); |
---|
659 | |
---|
660 | lastEditAttendeeToolTip.qtip("destroy"); |
---|
661 | event.preventDefault(); |
---|
662 | } |
---|
663 | }) |
---|
664 | .filter('[name="name"]').Watermark("informe o nome do contato").end() |
---|
665 | .filter('[name="mail"]').Watermark("informe o email do contato"); |
---|
666 | } |
---|
667 | |
---|
668 | /** |
---|
669 | * Se o email digitado já foi adicionado na lista, |
---|
670 | * o usuário deve ser avisado e um botão de edição deve ser exibido |
---|
671 | */ |
---|
672 | if(blkAddAtendee.find('label.mail[title="' + newAttendeeEmail + '"]').length) { |
---|
673 | hasNewAttendee = false; |
---|
674 | newAttendeeName = blkAddAtendee.find('label.mail[title="' + newAttendeeEmail + '"]').parents('li').find('label.name').attr('title'); |
---|
675 | |
---|
676 | blkAddAtendee.find('.email-validation').removeClass('hidden') |
---|
677 | .find('.message label').html("O usuário acima já foi adicionado! <a class=\"small button\">Editar</a>") |
---|
678 | .find(".button").button().click(function () { |
---|
679 | /** |
---|
680 | * Se o usuário optar por editar o participante anteriormente adicionado, |
---|
681 | * uma tooltip deve ser aberta para este participante, viabilizando a edição |
---|
682 | */ |
---|
683 | blkAddAtendee.find("ul.attendee-list").scrollTo('label.mail[title="' + newAttendeeEmail + '"]'); |
---|
684 | /** |
---|
685 | * Remove tooltip possivelmente existente |
---|
686 | */ |
---|
687 | if (lastEditAttendeeToolTip.length && lastEditAttendeeToolTip.data('qtip')) |
---|
688 | lastEditAttendeeToolTip.qtip('destroy'); |
---|
689 | |
---|
690 | lastEditAttendeeToolTip = blkAddAtendee.find('label.mail[title="' + newAttendeeEmail + '"]').parents('li'); |
---|
691 | lastEditAttendeeToolTip.qtip({ |
---|
692 | show: {ready: true, solo: true, when: {event: 'click'}}, |
---|
693 | hide: false, |
---|
694 | content: { |
---|
695 | text: $('<div></div>').html( DataLayer.render( path+'templates/attendee_quick_edit.ejs', {attendee:{name:newAttendeeName, mail:newAttendeeEmail}} ) ), |
---|
696 | title: { |
---|
697 | text:'Detalhes do participante', |
---|
698 | button: '<a class="button close" href="#">close</a>' |
---|
699 | } |
---|
700 | }, |
---|
701 | style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}}, |
---|
702 | position: { |
---|
703 | corner: { |
---|
704 | target: 'rightMiddle', |
---|
705 | tooltip: 'leftMiddle' |
---|
706 | }, |
---|
707 | adjust: {x:0, y:0} |
---|
708 | } |
---|
709 | }); |
---|
710 | lastEditAttendeeToolTip.qtip("api").onShow = onShowToolTip; |
---|
711 | }); |
---|
712 | skipAddNewLine = true; |
---|
713 | } else { |
---|
714 | hasNewAttendee = true; |
---|
715 | blkAddAtendee.find('.email-validation').addClass('hidden'); |
---|
716 | } |
---|
717 | |
---|
718 | |
---|
719 | var isExternal = (!!user && !(!!user.isExternal)) ? 0 : 1; |
---|
720 | |
---|
721 | /** |
---|
722 | * Remove tooltip possivelmente existente |
---|
723 | */ |
---|
724 | if (lastEditAttendeeToolTip.length && lastEditAttendeeToolTip.data('qtip')) |
---|
725 | lastEditAttendeeToolTip.qtip('destroy'); |
---|
726 | |
---|
727 | userId = ''; |
---|
728 | var newAttendeeId = ''; |
---|
729 | |
---|
730 | if (user){ |
---|
731 | if (!skipAddNewLine) { |
---|
732 | user[0].id = DataLayer.put('participant', {user: user[0].id, isExternal: isExternal}); |
---|
733 | blkAddAtendee.find('dd.attendee-list ul.attendee-list').append( |
---|
734 | DataLayer.render(path+'templates/participants_add_itemlist.ejs', {user:user, acl: objEvent.acl}) |
---|
735 | ) |
---|
736 | .scrollTo('max'); |
---|
737 | callbackAttendee(); |
---|
738 | } |
---|
739 | |
---|
740 | $(this).val(''); |
---|
741 | |
---|
742 | } else if (!skipAddNewLine) { |
---|
743 | /** |
---|
744 | * a) salva como novo usuario externo no banco (apenas com email) e... |
---|
745 | * adiciona novo contato externo à lista de convidados |
---|
746 | */ |
---|
747 | |
---|
748 | userId = DataLayer.put('user', {name: newAttendeeName, mail: newAttendeeEmail, isExternal: isExternal}); |
---|
749 | newAttendeeId = DataLayer.put('participant', {user: userId, isExternal: isExternal}); |
---|
750 | |
---|
751 | |
---|
752 | blkAddAtendee.find('dd.attendee-list ul.attendee-list').append( |
---|
753 | DataLayer.render(path+'templates/participants_add_itemlist.ejs', [{id:newAttendeeId, name: newAttendeeName, mail: newAttendeeEmail, isExternal: 1, acl: objEvent.acl}]) |
---|
754 | ).scrollTo('max'); |
---|
755 | callbackAttendee(); |
---|
756 | |
---|
757 | /** |
---|
758 | * Adiciona tootip para atualização dos dados do contato externo |
---|
759 | * recém adicionado. |
---|
760 | */ |
---|
761 | lastEditAttendeeToolTip = blkAddAtendee.find('dd.attendee-list li:last'); |
---|
762 | lastEditAttendeeToolTip.qtip({ |
---|
763 | show: {ready: true, solo: true, when: {event: 'click'}}, |
---|
764 | hide: false, |
---|
765 | content: { |
---|
766 | text: $('<div></div>').html( DataLayer.render( path+'templates/attendee_quick_edit.ejs', {attendee:{name:newAttendeeName, mail:newAttendeeEmail}} ) ), |
---|
767 | title: { |
---|
768 | text:'Detalhes do participante', |
---|
769 | button: '<a class="button close" href="#">close</a>' |
---|
770 | } |
---|
771 | }, |
---|
772 | style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}}, |
---|
773 | position: { |
---|
774 | corner: { |
---|
775 | target: 'rightMiddle', |
---|
776 | tooltip: 'leftMiddle' |
---|
777 | }, |
---|
778 | adjust: {x:0, y:0} |
---|
779 | } |
---|
780 | }); |
---|
781 | |
---|
782 | lastEditAttendeeToolTip.qtip("api").onShow = onShowToolTip; |
---|
783 | |
---|
784 | $(this).val(''); |
---|
785 | |
---|
786 | |
---|
787 | } |
---|
788 | event.preventDefault(); |
---|
789 | } |
---|
790 | |
---|
791 | }); |
---|
792 | |
---|
793 | /** |
---|
794 | * Trata a busca de usuários para adição de participantes |
---|
795 | */ |
---|
796 | blkAddAtendee.find('.add-attendee-search input').keydown(function(event) { |
---|
797 | |
---|
798 | if(event.keyCode == '13') { |
---|
799 | var result = DataLayer.get('user', ["*", "name", $(this).val()], true); |
---|
800 | |
---|
801 | /** |
---|
802 | * TODO: trocar por template |
---|
803 | */ |
---|
804 | blkAddAtendee.find('ul.search-result-list').empty().css('overflow', 'hidden'); |
---|
805 | if (!result) { |
---|
806 | blkAddAtendee.find('ul.search-result-list').append('<li><label class="empty">Nenhum resultado encontrado.</label></li>'); |
---|
807 | } |
---|
808 | |
---|
809 | for(i=0; i<result.length; i++) |
---|
810 | result[i].enabled = (blkAddAtendee.find('dd.attendee-list ul.attendee-list label.mail[title="' + result[i].mail + '"]').length) ? false : true; |
---|
811 | |
---|
812 | blkAddAtendee.find('ul.search-result-list').append(DataLayer.render( path+'templates/participants_search_itemlist.ejs', result)); |
---|
813 | |
---|
814 | blkAddAtendee.find('ul.search-result-list li').click(function(event, ui){ |
---|
815 | if ($(event.target).is('input')) { |
---|
816 | old_item = $(event.target).parents('li'); |
---|
817 | newAttendeeId = DataLayer.put('participant', {user: old_item.find('.id').html(), isExternal: 0}); |
---|
818 | blkAddAtendee.find('dd.attendee-list ul.attendee-list') |
---|
819 | .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}])) |
---|
820 | .scrollTo('max'); |
---|
821 | /** |
---|
822 | * Delegação de participação de um participante com permissão apenas de leitura |
---|
823 | * |
---|
824 | */ |
---|
825 | if(!objEvent.acl.organization && !objEvent.acl.write && !objEvent.acl.inviteGuests && objEvent.acl.read ){ |
---|
826 | |
---|
827 | blkAddAtendee.find('.block-add-attendee.search').addClass('hidden'); |
---|
828 | blkAddAtendee.find('.block-add-attendee.search dt').html('Adicionar outros contatos'); |
---|
829 | |
---|
830 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
831 | blkAddAtendee.find('option[value=5]').attr('selected','selected').trigger('change'); |
---|
832 | blkAddAtendee.find('.request-update').removeClass('hidden'); |
---|
833 | |
---|
834 | 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()); |
---|
835 | |
---|
836 | blkAddAtendee.find('.me .participant-delegate').addClass('disable ui-button-disabled ui-state-disabled'); |
---|
837 | blkAddAtendee.find(".button.close").button({ |
---|
838 | icons: { |
---|
839 | primary: "ui-icon-close" |
---|
840 | }, |
---|
841 | text: false |
---|
842 | }).click(function () { |
---|
843 | |
---|
844 | $(this).parents('li').find('input[name="delegatedFrom[]"]').val(''); |
---|
845 | blkAddAtendee.find('.request-update').addClass('hidden'); |
---|
846 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
847 | blkAddAtendee.find('option[value=1]').attr('selected','selected').trigger('change'); |
---|
848 | blkAddAtendee.find('.me .participant-delegate').removeClass('disable ui-button-disabled ui-state-disabled attendee-permissions-change-button') |
---|
849 | .find('.ui-icon-person').removeClass('attendee-permissions-change').end(); |
---|
850 | |
---|
851 | DataLayer.remove('participant', $(this).parents('li').find('[type=checkbox]').val()); |
---|
852 | $(this).parents('li').remove(); |
---|
853 | }) |
---|
854 | .addClass('tiny'); |
---|
855 | }else{ |
---|
856 | callbackAttendee(); |
---|
857 | old_item.remove(); |
---|
858 | } |
---|
859 | } |
---|
860 | }); |
---|
861 | |
---|
862 | event.preventDefault(); |
---|
863 | } |
---|
864 | }); |
---|
865 | //$('.block-add-attendee .search-result-list').selectable(); |
---|
866 | |
---|
867 | UI.dialogs.addEvent.find('.row.fileupload-buttonbar .button').filter('.delete').button({ |
---|
868 | icons: { |
---|
869 | primary: "ui-icon-close" |
---|
870 | }, |
---|
871 | text: 'Excluir' |
---|
872 | }).click(function () { |
---|
873 | $('.row.fileupload-buttonbar .attachments-list p').remove(); |
---|
874 | |
---|
875 | var ids = []; |
---|
876 | $.each($('.attachment-list input'), function (i, input) { ids.push(input.value); }); |
---|
877 | if(ids.length > 0){ |
---|
878 | DataLayer.remove('attachment', {filter: ['IN', 'id', ids]}); |
---|
879 | $('.attachment-list input').remove(); |
---|
880 | } |
---|
881 | }).end() |
---|
882 | .filter('.close').button({ |
---|
883 | icons: { |
---|
884 | primary: "ui-icon-close" |
---|
885 | }, |
---|
886 | text: false |
---|
887 | }).click(function () { |
---|
888 | DataLayer.remove('attachment', $(this).parents('p').find('input[name="fileId[]"]').val()); |
---|
889 | $(this).parents('p').remove(); |
---|
890 | }).end() |
---|
891 | .filter('.downlaod-archive').button({ |
---|
892 | icons: { |
---|
893 | primary: "ui-icon-arrowthickstop-1-s" |
---|
894 | }, |
---|
895 | text: false |
---|
896 | }); |
---|
897 | |
---|
898 | $('#fileupload').fileupload({ |
---|
899 | sequentialUploads: true, |
---|
900 | add: function (e, data) { |
---|
901 | if(data.files[0].size < 30000000) |
---|
902 | data.submit(); |
---|
903 | }, |
---|
904 | change: function (e, data) { |
---|
905 | $.each(data.files, function (index, file) { |
---|
906 | var attach = {}; |
---|
907 | attach.fileName = file.name; |
---|
908 | if(file.name.length > 10) |
---|
909 | attach.fileName = file.name.substr(0, 6) + file.name.substr(file.name.length-4, file.name.length); |
---|
910 | attach.fileSize = formatBytes(file.size); |
---|
911 | if(file.size > 30000000) |
---|
912 | attach.error = 'Tamanho de arquivo nao permitido!!' |
---|
913 | |
---|
914 | $('.attachments-list').append(DataLayer.render(path+'templates/attachment_add_itemlist.ejs', {file : attach})); |
---|
915 | |
---|
916 | if(file.size < 30000000){ |
---|
917 | $('.fileinput-button.new').append(data.fileInput[0]).removeClass('new'); |
---|
918 | $('.attachments-list').find('[type=file]').addClass('hidden'); |
---|
919 | |
---|
920 | }else |
---|
921 | $('.fileinput-button.new').removeClass('new'); |
---|
922 | |
---|
923 | |
---|
924 | $('.attachments-list').find('.button.close').button({ |
---|
925 | icons: { |
---|
926 | primary: "ui-icon-close" |
---|
927 | }, |
---|
928 | text: false |
---|
929 | }).click(function(){ |
---|
930 | var idAttach = $(this).parent().find('input[name="fileId[]"]').val(); |
---|
931 | $('.attachment-list').find('input[value="'+idAttach+'"]') |
---|
932 | $(this).parent().remove(); |
---|
933 | }); |
---|
934 | |
---|
935 | })}, |
---|
936 | progress: function(e, data){ |
---|
937 | var value = parseInt(data.loaded / data.total * 100, 10); |
---|
938 | $('.progress.in-progress:first').removeClass('hidden') |
---|
939 | $('.progress.in-progress:first').progressbar({ |
---|
940 | value: value |
---|
941 | }); |
---|
942 | |
---|
943 | if(value == 100){ |
---|
944 | $('.progress.in-progress:first').removeClass('in-progress').addClass('on-complete').fadeOut('slow'); |
---|
945 | } |
---|
946 | |
---|
947 | }, |
---|
948 | done: function(e, data){ |
---|
949 | if(!!data.result && data.result != "[]"){ |
---|
950 | var newAttach = jQuery.parseJSON(data.result); |
---|
951 | $('.attachment-list').append('<input tyepe="hidden" name="attachment[]" value="'+newAttach['attachment'][0][0].id+'"/>'); |
---|
952 | $('.progress.on-complete:first').removeClass('on-complete').parents('p') |
---|
953 | .append('<input type="hidden" name="fileId[]" value="'+newAttach['attachment'][0][0].id+'"/>') |
---|
954 | .find('.status-upload').addClass('ui-icon ui-icon-check'); |
---|
955 | }else |
---|
956 | $('.progress.on-complete:first').removeClass('on-complete').parents('p').find('.status-upload').addClass('ui-icon ui-icon-cancel'); |
---|
957 | } |
---|
958 | }); |
---|
959 | $('.attachments-list .button').button(); |
---|
960 | |
---|
961 | $('#fileupload').bind('fileuploadstart', function () { |
---|
962 | var widget = $(this), |
---|
963 | progressElement = $('#fileupload-progress').fadeIn(), |
---|
964 | interval = 500, |
---|
965 | total = 0, |
---|
966 | loaded = 0, |
---|
967 | loadedBefore = 0, |
---|
968 | progressTimer, |
---|
969 | progressHandler = function (e, data) { |
---|
970 | loaded = data.loaded; |
---|
971 | total = data.total; |
---|
972 | }, |
---|
973 | stopHandler = function () { |
---|
974 | widget |
---|
975 | .unbind('fileuploadprogressall', progressHandler) |
---|
976 | .unbind('fileuploadstop', stopHandler); |
---|
977 | window.clearInterval(progressTimer); |
---|
978 | progressElement.fadeOut(function () { |
---|
979 | progressElement.html(''); |
---|
980 | }); |
---|
981 | }, |
---|
982 | formatTime = function (seconds) { |
---|
983 | var date = new Date(seconds * 1000); |
---|
984 | return ('0' + date.getUTCHours()).slice(-2) + ':' + |
---|
985 | ('0' + date.getUTCMinutes()).slice(-2) + ':' + |
---|
986 | ('0' + date.getUTCSeconds()).slice(-2); |
---|
987 | }, |
---|
988 | /* formatBytes = function (bytes) { |
---|
989 | if (bytes >= 1000000000) { |
---|
990 | return (bytes / 1000000000).toFixed(2) + ' GB'; |
---|
991 | } |
---|
992 | if (bytes >= 1000000) { |
---|
993 | return (bytes / 1000000).toFixed(2) + ' MB'; |
---|
994 | } |
---|
995 | if (bytes >= 1000) { |
---|
996 | return (bytes / 1000).toFixed(2) + ' KB'; |
---|
997 | } |
---|
998 | return bytes + ' B'; |
---|
999 | },*/ |
---|
1000 | formatPercentage = function (floatValue) { |
---|
1001 | return (floatValue * 100).toFixed(2) + ' %'; |
---|
1002 | }, |
---|
1003 | updateProgressElement = function (loaded, total, bps) { |
---|
1004 | progressElement.html( |
---|
1005 | formatBytes(bps) + 'ps | ' + |
---|
1006 | formatTime((total - loaded) / bps) + ' | ' + |
---|
1007 | formatPercentage(loaded / total) + ' | ' + |
---|
1008 | formatBytes(loaded) + ' / ' + formatBytes(total) |
---|
1009 | ); |
---|
1010 | }, |
---|
1011 | intervalHandler = function () { |
---|
1012 | var diff = loaded - loadedBefore; |
---|
1013 | if (!diff) { |
---|
1014 | return; |
---|
1015 | } |
---|
1016 | loadedBefore = loaded; |
---|
1017 | updateProgressElement( |
---|
1018 | loaded, |
---|
1019 | total, |
---|
1020 | diff * (1000 / interval) |
---|
1021 | ); |
---|
1022 | }; |
---|
1023 | widget |
---|
1024 | .bind('fileuploadprogressall', progressHandler) |
---|
1025 | .bind('fileuploadstop', stopHandler); |
---|
1026 | progressTimer = window.setInterval(intervalHandler, interval); |
---|
1027 | }); |
---|
1028 | |
---|
1029 | UI.dialogs.addEvent.find(':input').change(function(event){ |
---|
1030 | if (event.keyCode != '27' && event.keyCode != '13') |
---|
1031 | canDiscardEventDialog = false; |
---|
1032 | }).keydown(function(event){ |
---|
1033 | if (event.keyCode != '27' && event.keyCode != '13') |
---|
1034 | canDiscardEventDialog = false; |
---|
1035 | }); |
---|
1036 | |
---|
1037 | |
---|
1038 | UI.dialogs.addEvent.dialog('open'); |
---|
1039 | } |
---|
1040 | |
---|
1041 | |
---|
1042 | |
---|
1043 | function add_tab_preferences() |
---|
1044 | { |
---|
1045 | if(!(document.getElementById('preference_tab'))) |
---|
1046 | { |
---|
1047 | var tab_title = "Preferencias"; |
---|
1048 | $tabs.tabs( "add", "#preference_tab", tab_title ); |
---|
1049 | |
---|
1050 | /* |
---|
1051 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
1052 | tabPrefCalendar.find('select[name="timezone"]').html(timezones_options).find('option[value="'+User.preferences.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
1053 | }); |
---|
1054 | */ |
---|
1055 | DataLayer.render( 'templates/preferences_calendar.ejs', {preferences:User.preferences, calendars: Calendar.calendars}, function( template ){ |
---|
1056 | var tabPrefCalendar = jQuery('#preference_tab').html( template ).find('.preferences-win'); |
---|
1057 | |
---|
1058 | tabPrefCalendar.find('option[value="'+User.preferences.defaultCalendar+'"]').attr('selected','selected').trigger('change'); |
---|
1059 | |
---|
1060 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
1061 | tabPrefCalendar.find('select[name="timezone"]').html(timezones_options).find('option[value="'+User.preferences.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
1062 | }); |
---|
1063 | |
---|
1064 | tabPrefCalendar.find('.button').button() |
---|
1065 | .filter('.save').click(function(evt){ |
---|
1066 | tabPrefCalendar.find('form').submit(); |
---|
1067 | $('#calendar').fullCalendar('render'); |
---|
1068 | $('.block-vertical-toolbox .mini-calendar').datepicker( "refresh" ); |
---|
1069 | $tabs.tabs( "remove", "#preference_tab"); |
---|
1070 | }).end().filter('.cancel').click(function(evt){ |
---|
1071 | $tabs.tabs( "remove", "#preference_tab"); |
---|
1072 | }); |
---|
1073 | |
---|
1074 | tabPrefCalendar.find('.number').numeric(); |
---|
1075 | |
---|
1076 | tabPrefCalendar.find('input.time').timepicker({ |
---|
1077 | closeText: 'Ok', |
---|
1078 | hourGrid: 4, |
---|
1079 | minuteGrid: 10, |
---|
1080 | ampm : (parseInt($("select[name=hourFormat] option:selected").val().length) > 5 ? true : false), //((User.preferences.hourFormat.length > 5) ? true: false), |
---|
1081 | timeFormat: "hh:mm tt", |
---|
1082 | onSelect: function (selectedDateTime){ |
---|
1083 | if(!(User.preferences.hourFormat.length == 5)) { |
---|
1084 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
1085 | } |
---|
1086 | }, |
---|
1087 | onClose : function (selectedDateTime){ |
---|
1088 | if(!(User.preferences.hourFormat.length == 5)) { |
---|
1089 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
1090 | } |
---|
1091 | } |
---|
1092 | }); |
---|
1093 | |
---|
1094 | $.mask.definitions['{']='[ap]'; |
---|
1095 | $.mask.definitions['}']='[m]'; |
---|
1096 | tabPrefCalendar.find("input.time").mask( ((User.preferences.hourFormat.length > 5) ? "99:99 {}" : "99:99"), { |
---|
1097 | completed:function(){ |
---|
1098 | $(this).val(dateCalendar.defaultToAmPm($(this).val())); |
---|
1099 | $(this).timepicker("refresh"); |
---|
1100 | $(this).val($(this).val().replace(/[\.]/gi, "")); |
---|
1101 | } |
---|
1102 | }); |
---|
1103 | |
---|
1104 | tabPrefCalendar.find("select[name=hourFormat]").change( function() { // evento ao selecionar formato de hora |
---|
1105 | |
---|
1106 | tabPrefCalendar.find("input.time").timepicker("destroy"); |
---|
1107 | |
---|
1108 | tabPrefCalendar.find('input.time').timepicker({ |
---|
1109 | closeText: 'Ok', |
---|
1110 | hourGrid: 4, |
---|
1111 | minuteGrid: 10, |
---|
1112 | ampm : (parseInt($("select[name=hourFormat] option:selected").val().length) > 5 ? true : false), |
---|
1113 | timeFormat: "hh:mm tt", |
---|
1114 | onSelect: function (selectedDateTime){ |
---|
1115 | if(!(User.preferences.hourFormat.length == 5)) { |
---|
1116 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
1117 | } |
---|
1118 | }, |
---|
1119 | onClose : function (selectedDateTime){ |
---|
1120 | if(!(User.preferences.hourFormat.length == 5)) { |
---|
1121 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
1122 | } |
---|
1123 | } |
---|
1124 | }); |
---|
1125 | |
---|
1126 | var defaultStartHour = tabPrefCalendar.find("input[name=defaultStartHour]").val().trim(); |
---|
1127 | var defaultEndHour = tabPrefCalendar.find("input[name=defaultEndHour]").val().trim(); |
---|
1128 | |
---|
1129 | tabPrefCalendar.find("input.time").mask( (($("select[name=hourFormat] option:selected").val().trim().length > 5) ? "99:99 {}" : "99:99") ); |
---|
1130 | |
---|
1131 | if (parseInt($("select[name=hourFormat] option:selected").val().length) > 5) { // am/pm |
---|
1132 | tabPrefCalendar.find("input[name=defaultStartHour]").val(dateCalendar.defaultToAmPm(defaultStartHour)); |
---|
1133 | tabPrefCalendar.find("input[name=defaultEndHour]").val(dateCalendar.defaultToAmPm(defaultEndHour)) |
---|
1134 | |
---|
1135 | } else { //24h |
---|
1136 | tabPrefCalendar.find("input[name=defaultStartHour]").val(dateCalendar.AmPmTo24(defaultStartHour)); |
---|
1137 | tabPrefCalendar.find("input[name=defaultEndHour]").val(dateCalendar.AmPmTo24(defaultEndHour)); |
---|
1138 | } |
---|
1139 | }); |
---|
1140 | |
---|
1141 | |
---|
1142 | |
---|
1143 | }); |
---|
1144 | } else { |
---|
1145 | $tabs.tabs("select", "#preference_tab"); |
---|
1146 | |
---|
1147 | return true; |
---|
1148 | } |
---|
1149 | } |
---|
1150 | |
---|
1151 | |
---|
1152 | function add_tab_configure_calendar(calendar) |
---|
1153 | { |
---|
1154 | var calendars = []; |
---|
1155 | var signatures = []; |
---|
1156 | var previewActiveCalendarConf = 0; |
---|
1157 | |
---|
1158 | for (var i=0; i<Calendar.signatures.length; i++) { |
---|
1159 | calendars[i] = Calendar.signatures[i].calendar; |
---|
1160 | signatures[i] = Calendar.signatures[i]; |
---|
1161 | signatures[i].numberDefaultAlarm = signatures[i].defaultAlarms != '' ? signatures[i].defaultAlarms.length: 0; |
---|
1162 | if (calendar && calendars[i].id == calendar) |
---|
1163 | previewActiveCalendarConf = i; |
---|
1164 | } |
---|
1165 | |
---|
1166 | if(!(document.getElementById('configure_tab'))) |
---|
1167 | { |
---|
1168 | $('.positionHelper').css('display', 'none'); |
---|
1169 | var tab_title = "Configurações de agendas"; |
---|
1170 | $tabs.tabs( "add", "#configure_tab", tab_title ); |
---|
1171 | |
---|
1172 | var dataColorPicker = { |
---|
1173 | colorsSuggestions: colors_suggestions() |
---|
1174 | }; |
---|
1175 | |
---|
1176 | |
---|
1177 | |
---|
1178 | var populateAccordionOnActive = function(event, ui) { |
---|
1179 | var nowActive = (typeof(event) == 'number') ? event : $(event.target).accordion( "option", "active" ); |
---|
1180 | dataColorPicker.colorsDefined = { |
---|
1181 | border: '#'+signatures[nowActive].borderColor, |
---|
1182 | font:'#'+signatures[nowActive].fontColor, |
---|
1183 | background:'#'+signatures[nowActive].backgroundColor |
---|
1184 | }; |
---|
1185 | if (!jQuery('.accordion-user-calendars .ui-accordion-content').eq(nowActive).has('form')) { |
---|
1186 | return true; |
---|
1187 | } |
---|
1188 | |
---|
1189 | DataLayer.render( 'templates/configure_calendars_itemlist.ejs', {user:User, calendar:calendars[nowActive], signature:signatures[nowActive]}, function( form_template ){ |
---|
1190 | var form_content = jQuery('.accordion-user-calendars .ui-accordion-content').eq(nowActive).html( form_template ).find('form'); |
---|
1191 | form_content.find('.preferences-alarms-list .button').button({text:false, icons:{primary:'ui-icon-close'}}); |
---|
1192 | form_content.find('.button').button(); |
---|
1193 | |
---|
1194 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
1195 | var valueTimeZone = calendars[nowActive].timezone; |
---|
1196 | form_content.find('select[name="timezone"]').html(timezones_options).find('option[value="'+valueTimeZone+'"]').attr('selected','selected').trigger('change'); |
---|
1197 | }); |
---|
1198 | |
---|
1199 | form_content.find('.button-add-alarms').click(function(){ |
---|
1200 | DataLayer.render( 'templates/alarms_add_itemlist.ejs', {}, function( template ){ |
---|
1201 | jQuery('.preferences-alarms-list').append(template) |
---|
1202 | .find('li:last label:eq(0)').remove().end() |
---|
1203 | .find('.number').numeric().end() |
---|
1204 | .find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
1205 | $(this).parent().remove(); |
---|
1206 | }); |
---|
1207 | }); |
---|
1208 | }); |
---|
1209 | |
---|
1210 | |
---|
1211 | /** |
---|
1212 | * Set color picker |
---|
1213 | */ |
---|
1214 | DataLayer.render( 'templates/calendar_colorpicker.ejs', dataColorPicker, function( template ){ |
---|
1215 | form_content.find('.calendar-colorpicker').html( template ); |
---|
1216 | |
---|
1217 | var f = $.farbtastic(form_content.find('.colorpicker'), colorpickerPreviewChange); |
---|
1218 | var selected; |
---|
1219 | var colorpicker = form_content.find('.calendar-colorpicker'); |
---|
1220 | |
---|
1221 | var colorpickerPreviewChange = function(color) { |
---|
1222 | var pickedup = form_content.find('.colorwell-selected').val(color).css('background-color', color); |
---|
1223 | |
---|
1224 | var colorpicker = form_content.find('.calendar-colorpicker'); |
---|
1225 | |
---|
1226 | if (pickedup.is('input[name="backgroundColor"]')) { |
---|
1227 | colorpicker.find('.fc-event-skin').css('background-color',color); |
---|
1228 | } else if (pickedup.is('input[name="fontColor"]')) { |
---|
1229 | colorpicker.find('.fc-event-skin').css('color',color); |
---|
1230 | } else if (pickedup.is('input[name="borderColor"]')) { |
---|
1231 | colorpicker.find('.fc-event-skin').css('border-color',color); |
---|
1232 | } |
---|
1233 | } |
---|
1234 | |
---|
1235 | form_content.find('.colorwell').each(function () { |
---|
1236 | f.linkTo(this); |
---|
1237 | |
---|
1238 | if ($(this).is('input[name="backgroundColor"]')) { |
---|
1239 | colorpicker.find('.fc-event-skin').css('background-color', $(this).val()); |
---|
1240 | } else if ($(this).is('input[name="fontColor"]')) { |
---|
1241 | colorpicker.find('.fc-event-skin').css('color', $(this).val()); |
---|
1242 | } else if ($(this).is('input[name="borderColor"]')) { |
---|
1243 | colorpicker.find('.fc-event-skin').css('border-color', $(this).val()); |
---|
1244 | } |
---|
1245 | }) |
---|
1246 | .focus(function() { |
---|
1247 | if (selected) { |
---|
1248 | $(selected).removeClass('colorwell-selected'); |
---|
1249 | } |
---|
1250 | |
---|
1251 | $(selected = this).addClass('colorwell-selected'); |
---|
1252 | f.linkTo(this, colorpickerPreviewChange); |
---|
1253 | f.linkTo(colorpickerPreviewChange); |
---|
1254 | |
---|
1255 | }); |
---|
1256 | |
---|
1257 | form_content.find('select.color-suggestions').change(function() { |
---|
1258 | var colors; |
---|
1259 | |
---|
1260 | if(colors = dataColorPicker.colorsSuggestions[$(this).val()]) { |
---|
1261 | colorpicker |
---|
1262 | .find('input[name="fontColor"]').val(colors.font).focus().end() |
---|
1263 | .find('input[name="backgroundColor"]').val(colors.background).focus().end() |
---|
1264 | .find('input[name="borderColor"]').val(colors.border).focus().end() |
---|
1265 | |
---|
1266 | .find('.fc-event-skin').css({ |
---|
1267 | 'background-color':dataColorPicker.colorsSuggestions[$(this).val()].background, |
---|
1268 | 'border-color':dataColorPicker.colorsSuggestions[$(this).val()].border, |
---|
1269 | 'color':dataColorPicker.colorsSuggestions[$(this).val()].font |
---|
1270 | }); |
---|
1271 | } |
---|
1272 | }); |
---|
1273 | |
---|
1274 | /** |
---|
1275 | * Trata a mudança dos valores dos campos de cores. |
---|
1276 | * Se mudar um conjunto de cores sugerido, |
---|
1277 | * este vira um conjunto de cores personalizado. |
---|
1278 | */ |
---|
1279 | form_content.find('.colorwell').change(function (element, ui) { |
---|
1280 | if (true) { |
---|
1281 | form_content.find('select.color-suggestions') |
---|
1282 | .find('option:selected').removeAttr('selected').end() |
---|
1283 | .find('option[value="custom"]').attr('selected', 'selected').trigger('change'); |
---|
1284 | } |
---|
1285 | }); |
---|
1286 | }); //END set colorpicker |
---|
1287 | |
---|
1288 | form_content.find('.phone').mask("+99 (99) 9999-9999"); |
---|
1289 | form_content.find('.number').numeric(); |
---|
1290 | |
---|
1291 | }); //END DataLayer.render( 'templates/configure_calendars_itemlist.ejs' ... |
---|
1292 | |
---|
1293 | // === validations preferences ==== |
---|
1294 | |
---|
1295 | |
---|
1296 | } //END populateAccordionOnActive(event, ui) |
---|
1297 | |
---|
1298 | |
---|
1299 | DataLayer.render( 'templates/configure_calendars.ejs', {user:User, calendars:calendars, signatures:signatures}, function( template ){ |
---|
1300 | var template_content = jQuery('#configure_tab').html( template ).find('.configure-calendars-win'); |
---|
1301 | template_content.find('.button').button().filter('.save').click(function(evt){ |
---|
1302 | template_content.find('form').submit(); |
---|
1303 | $tabs.tabs( "remove", "#configure_tab"); |
---|
1304 | }).end().filter('.cancel').click(function(evt){ |
---|
1305 | $tabs.tabs( "remove", "#configure_tab"); |
---|
1306 | }); |
---|
1307 | |
---|
1308 | /** |
---|
1309 | * Muda a estrutura do template para a aplicação do plugin accordion |
---|
1310 | */ |
---|
1311 | template_content.find('.header-menu-container').after('<div class="accordion-user-calendars"></div>').end().find('.accordion-user-calendars') |
---|
1312 | .append(template_content.children('fieldset')); |
---|
1313 | |
---|
1314 | template_content.find('.accordion-user-calendars').children('fieldset').each(function(index) { |
---|
1315 | $(this).before($('<h3></h3>').html($(this).children('legend'))); |
---|
1316 | }); |
---|
1317 | |
---|
1318 | template_content.find('.accordion-user-calendars').accordion({ |
---|
1319 | autoHeight: false, |
---|
1320 | collapsible: true, |
---|
1321 | clearStyle: true, |
---|
1322 | active: previewActiveCalendarConf, |
---|
1323 | changestart: populateAccordionOnActive |
---|
1324 | }); |
---|
1325 | populateAccordionOnActive(previewActiveCalendarConf); |
---|
1326 | }); |
---|
1327 | |
---|
1328 | } else { |
---|
1329 | |
---|
1330 | $tabs.tabs("select", "#configure_tab"); |
---|
1331 | $('.accordion-user-calendars').accordion( "activate" , previewActiveCalendarConf ); |
---|
1332 | |
---|
1333 | return true; |
---|
1334 | } |
---|
1335 | |
---|
1336 | } |
---|
1337 | |
---|
1338 | function getSelectedCalendars( reverse ){ |
---|
1339 | var selecteds = {}; |
---|
1340 | var cont = 0; |
---|
1341 | jQuery(function() { |
---|
1342 | jQuery(".my-calendars .calendar-view").each(function(i, obj) { |
---|
1343 | var check_box = obj; |
---|
1344 | if( reverse ? !check_box.checked : check_box.checked ) { |
---|
1345 | selecteds[cont] = obj.value; |
---|
1346 | cont++; |
---|
1347 | }; |
---|
1348 | }); |
---|
1349 | }); |
---|
1350 | if (!cont) |
---|
1351 | return false; |
---|
1352 | |
---|
1353 | selecteds.length = cont; |
---|
1354 | return $.makeArray( selecteds ); |
---|
1355 | } |
---|
1356 | |
---|
1357 | /** |
---|
1358 | * TODO - transformar em preferência do módulo e criar telas de adição e exclusão de conjunto de cores |
---|
1359 | */ |
---|
1360 | function colors_suggestions(){ |
---|
1361 | return [ |
---|
1362 | {name:'Padrão', border:'#3366cc', font:'#ffffff', background:'#3366cc'}, |
---|
1363 | {name:'Coala', border:'#123456', font:'#ffffff', background:'#385c80'}, |
---|
1364 | {name:'Tomate', border:'#d5130b', font:'#111111', background:'#e36d76'}, |
---|
1365 | {name:'Limão', border:'#32ed21', font:'#1f3f1c', background:'#b2f1ac'}, |
---|
1366 | {name:'Alto contraste', border:'#000000', font:'#ffffff', background:'#222222'} |
---|
1367 | ] |
---|
1368 | } |
---|
1369 | |
---|
1370 | function remove_calendar(){ |
---|
1371 | /* Pode ser assim $('.cal-list-options-btn.ui-state-active').attr('class').replace(/[a-zA-Z-]+/g, ''); */ |
---|
1372 | $.Zebra_Dialog('Todos os eventos desta agenda serão removidos. Deseja prosseguir com a operação?', { |
---|
1373 | 'type': 'question', |
---|
1374 | 'overlay_opacity': '0.5', |
---|
1375 | 'buttons': ['Sim', 'Não'], |
---|
1376 | 'onClose': function(clicked) { |
---|
1377 | if(clicked == 'Sim'){ |
---|
1378 | var idCalendar = $('.cal-list-options-btn.ui-state-active').attr('class').match(/[0-9]+/g); |
---|
1379 | var signature = ''; |
---|
1380 | for(var i =0; i < Calendar.signatures.length; i++){ |
---|
1381 | if(idCalendar[0] == Calendar.signatures[i].calendar.id){ |
---|
1382 | signature = Calendar.signatures[i].id; |
---|
1383 | break; |
---|
1384 | } |
---|
1385 | } |
---|
1386 | DataLayer.remove('calendarSignature', signature); |
---|
1387 | if(idCalendar == User.preferences.defaultCalendar) |
---|
1388 | DataLayer.remove( 'modulePreference', User.preferenceIds['defaultCalendar']); |
---|
1389 | } |
---|
1390 | $('.positionHelper').css('display', 'none'); |
---|
1391 | |
---|
1392 | } |
---|
1393 | }); |
---|
1394 | } |
---|
1395 | |
---|
1396 | function refresh_calendars(){ |
---|
1397 | |
---|
1398 | var colorsSuggestions = colors_suggestions(); |
---|
1399 | var buttons_colors = ""; |
---|
1400 | for(var i = 0; i < colorsSuggestions.length; i++){ |
---|
1401 | 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>"; |
---|
1402 | } |
---|
1403 | |
---|
1404 | //DataLayer.render( 'templates/calendar_list.ejs', 'calendar:list', ["IN", "id", Calendar.calendarIds], function( html ){ |
---|
1405 | DataLayer.render( 'templates/calendar_list.ejs', Calendar, function( html ){ |
---|
1406 | |
---|
1407 | var meu_container = $(".calendars-list").html( html ); |
---|
1408 | |
---|
1409 | $('ul.list-calendars .cal-list-options-btn').each(function(){ |
---|
1410 | $(this).menu({ |
---|
1411 | content: $(this).next().html(), |
---|
1412 | width: '120', |
---|
1413 | positionOpts: { |
---|
1414 | posX: 'left', |
---|
1415 | posY: 'bottom', |
---|
1416 | offsetX: 0, |
---|
1417 | offsetY: 0, |
---|
1418 | directionH: 'right', |
---|
1419 | directionV: 'down', |
---|
1420 | detectH: true, // do horizontal collision detection |
---|
1421 | detectV: true, // do vertical collision detection |
---|
1422 | linkToFront: false |
---|
1423 | }, |
---|
1424 | flyOut: true, |
---|
1425 | showSpeed: 100, |
---|
1426 | crumbDefaultText: '>' |
---|
1427 | }); |
---|
1428 | }); |
---|
1429 | |
---|
1430 | |
---|
1431 | meu_container.find(".button.new").button({ |
---|
1432 | icons: { |
---|
1433 | primary: "ui-icon-plus" |
---|
1434 | }, |
---|
1435 | text: false |
---|
1436 | }).click(function () { |
---|
1437 | |
---|
1438 | if( $('.qtip.qtip-blue.qtip-active').val() !== ''){ |
---|
1439 | $(this).qtip({ |
---|
1440 | show: {ready: true, solo: true, when: {event: 'click'}}, |
---|
1441 | hide: false, |
---|
1442 | content: { |
---|
1443 | text: $('<div></div>').html( DataLayer.render( 'templates/calendar_quick_add.ejs', {} ) ), |
---|
1444 | title: { |
---|
1445 | text:'Nova Agenda', |
---|
1446 | button: '<a class="button close" href="#">close</a>' |
---|
1447 | } |
---|
1448 | }, |
---|
1449 | style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}}, |
---|
1450 | position: { |
---|
1451 | corner: { |
---|
1452 | target: 'rightMiddle', |
---|
1453 | tooltip: 'leftMiddle' |
---|
1454 | }, |
---|
1455 | adjust: {x:0, y:-12} |
---|
1456 | } |
---|
1457 | }) |
---|
1458 | .qtip("api").onShow = function(arg0) { |
---|
1459 | $('.qtip-active .button.close').button({ |
---|
1460 | icons: {primary: "ui-icon-close"}, |
---|
1461 | text: false |
---|
1462 | }) |
---|
1463 | .click(function(){ |
---|
1464 | meu_container.find(".button.new").qtip('destroy'); |
---|
1465 | }); |
---|
1466 | //TODO emplementar tratamento de duplicação de valores no location |
---|
1467 | $('.qtip-active .button.save').button().click(function(){ |
---|
1468 | for(var i = 0; i < Calendar.calendars.length; i++){ |
---|
1469 | if(Calendar.calendars[i].location == $('.qtip-active input').val()){ |
---|
1470 | $.Zebra_Dialog('O nome desta agenda já está sendo utilizada em uma Url de outra agenda. Por favor, informe outro nome para agenda.',{ |
---|
1471 | 'overlay_opacity': '0.5', |
---|
1472 | 'type': 'warning' |
---|
1473 | }); |
---|
1474 | meu_container.find(".button.new").qtip('destroy'); |
---|
1475 | return; |
---|
1476 | } |
---|
1477 | } |
---|
1478 | |
---|
1479 | var selected; |
---|
1480 | var color = $('.cal-colors-options-btn').each(function(index){ |
---|
1481 | if ($(this).is('.color-selected')) |
---|
1482 | selected = index; |
---|
1483 | }); |
---|
1484 | DataLayer.put( "calendarSignature", { |
---|
1485 | user: User.me.id, |
---|
1486 | calendar: { |
---|
1487 | name: Encoder.htmlEncode($('.qtip-active input').val()), |
---|
1488 | timezone: User.preferences.timezone |
---|
1489 | }, |
---|
1490 | isOwner: 1, |
---|
1491 | fontColor: colorsSuggestions[selected]['font'].substring(1) , |
---|
1492 | backgroundColor: colorsSuggestions[selected]['background'].substring(1) , |
---|
1493 | borderColor: colorsSuggestions[selected]['border'].substring(1) |
---|
1494 | }); |
---|
1495 | meu_container.find(".button.new").qtip('destroy'); |
---|
1496 | }); |
---|
1497 | |
---|
1498 | $('.qtip-active .button.cancel').button().click(function(){ |
---|
1499 | meu_container.find(".button.new").qtip('destroy'); |
---|
1500 | }); |
---|
1501 | |
---|
1502 | $(".qtip-active input").Watermark("Nome da agenda"); |
---|
1503 | |
---|
1504 | $('.qtip-active').keydown(function(event) { |
---|
1505 | if (event.keyCode == '27') { |
---|
1506 | meu_container.find(".button.new").qtip('destroy'); |
---|
1507 | } |
---|
1508 | }); |
---|
1509 | |
---|
1510 | $('.colors-options').prepend(buttons_colors); |
---|
1511 | $('.colors-options .signed-cal-colors-options-btn-0').addClass('color-selected'); |
---|
1512 | |
---|
1513 | var buttons = $('.cal-colors-options-btn').button(); |
---|
1514 | |
---|
1515 | buttons.click(function(){ |
---|
1516 | buttons.removeClass('color-selected'); |
---|
1517 | $(this).addClass('color-selected'); |
---|
1518 | }); |
---|
1519 | } |
---|
1520 | } |
---|
1521 | }); |
---|
1522 | |
---|
1523 | $("img.cal-list-img").click(function(evt) { |
---|
1524 | $(".cal-list-options_1").toggleClass( "hidden" ); |
---|
1525 | }); |
---|
1526 | |
---|
1527 | $(".my-calendars a.title-my-calendars").click(function() { |
---|
1528 | $(".my-calendars ul.my-list-calendars").toggleClass("hidden") |
---|
1529 | $('.my-calendars .status-list').toggleClass("ui-icon-triangle-1-s"); |
---|
1530 | $('.my-calendars .status-list').toggleClass("ui-icon-triangle-1-e"); |
---|
1531 | }); |
---|
1532 | |
---|
1533 | $(".signed-calendars a.title-signed-calendars").click(function() { |
---|
1534 | $(".signed-calendars ul.signed-list-calendars").toggleClass( "hidden"); |
---|
1535 | }); |
---|
1536 | |
---|
1537 | $("ul li.list-calendars-item").click(function(evt) { |
---|
1538 | |
---|
1539 | }); |
---|
1540 | |
---|
1541 | $("ul li.list-calendars-item .ui-corner-all").click(function(evt) { |
---|
1542 | //alert('teste'); |
---|
1543 | }); |
---|
1544 | |
---|
1545 | $('.calendar-view').click(function(evt){ |
---|
1546 | if($tabs.tabs('option' ,'selected') == 1){ |
---|
1547 | pageselectCallback('', 0); |
---|
1548 | } |
---|
1549 | |
---|
1550 | if(Calendar.currentView){ |
---|
1551 | var checkBox = $(this); |
---|
1552 | if(!!Calendar.currentView[ checkBox.val() ]){ |
---|
1553 | Calendar.currentView[ checkBox.val() ].hidden = !checkBox.is(':checked'); |
---|
1554 | $('#calendar').fullCalendar( 'refetchEvents' ); |
---|
1555 | } |
---|
1556 | } |
---|
1557 | }); |
---|
1558 | }); |
---|
1559 | } |
---|
1560 | |
---|
1561 | function add_events_list(keyword) |
---|
1562 | { |
---|
1563 | var tab_title = ""; |
---|
1564 | if (keyword){ |
---|
1565 | if(keyword.length < 10) |
---|
1566 | tab_title = keyword; |
---|
1567 | else |
---|
1568 | tab_title = keyword.substr(0,10) + '..."'; |
---|
1569 | }else{ |
---|
1570 | tab_title = "Lista de eventos"; |
---|
1571 | } |
---|
1572 | keyword = ( keyword || '' ).replace( /\s+/g, "_" ); |
---|
1573 | |
---|
1574 | if(!(document.getElementById('tab_events_list_' + (Base64.encode(keyword)).replace(/[^\w\s]/gi, "") ))) |
---|
1575 | { |
---|
1576 | Encoder.EncodeType = "entity"; |
---|
1577 | $tabs.tabs( "add", "#tab_events_list_" + (Base64.encode(keyword)).replace(/[^\w\s]/gi, ""), Encoder.htmlEncode(tab_title) ); |
---|
1578 | } |
---|
1579 | else /* Tab already opened */ |
---|
1580 | { |
---|
1581 | $tabs.tabs("option", "selected", 2); |
---|
1582 | } |
---|
1583 | |
---|
1584 | pageselectCallback(keyword, 0); // load page 1 and insert data on event_list.ejs |
---|
1585 | |
---|
1586 | $('.preferences-win.active .button.save, .preferences-win.active .button.cancel, .preferences-win.active .button.import, .preferences-win.active .button.export').button(); |
---|
1587 | } |
---|
1588 | |
---|
1589 | function paginatorSearch(currentView){ |
---|
1590 | $(currentView+' .header-paginator .fc-header-left .fc-button').hover( |
---|
1591 | function(){ |
---|
1592 | $(this).addClass('fc-state-hover'); |
---|
1593 | }, |
---|
1594 | function(){ |
---|
1595 | $(this).removeClass('fc-state-hover'); |
---|
1596 | }).mousedown(function(){ |
---|
1597 | $(this).addClass('fc-state-down'); |
---|
1598 | }).mouseup(function(){ |
---|
1599 | $(this).removeClass('fc-state-down'); |
---|
1600 | $('.events-list.events-list-win.active').removeClass('active'); |
---|
1601 | var paginator = $(this).attr('class'); |
---|
1602 | if(paginator.indexOf('next') > 0){ |
---|
1603 | if(parseInt($(currentView+' [name = results]').val()) > 25) |
---|
1604 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($(currentView+' [name = page_index]').val())) +1)); |
---|
1605 | }else{ |
---|
1606 | if(parseInt($(currentView+' [name = page_index]').val()) > 0) |
---|
1607 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($(currentView+' [name = page_index]').val())) -1)); |
---|
1608 | } |
---|
1609 | }); |
---|
1610 | } |
---|
1611 | |
---|
1612 | function mountTitleList(page_index ,view){ |
---|
1613 | switch (view){ |
---|
1614 | case 'day': |
---|
1615 | case 'basicDay': |
---|
1616 | var date = new Date().add({days: page_index}); |
---|
1617 | return (dateCalendar.dayNames[date.getDay()])+", "+(date.toString('dd MMM yyyy')); |
---|
1618 | case 'agendaWeek': |
---|
1619 | case 'week': |
---|
1620 | var dateStart = new Date().moveToDayOfWeek(dateCalendar.dayOfWeek[User.preferences.weekStart]); |
---|
1621 | dateStart.add({days: (7 * page_index)}); |
---|
1622 | var dateEnd = new Date().moveToDayOfWeek(dateCalendar.dayOfWeek[User.preferences.weekStart]); |
---|
1623 | dateEnd.add({days: (page_index * 7)+7}); |
---|
1624 | if(dateStart.toString('MM') != dateEnd.toString('MM')) |
---|
1625 | return dateStart.toString('dd')+' de '+dateCalendar.monthNamesShort[dateStart.getMonth()]+' a '+dateEnd.toString('dd')+' de '+dateCalendar.monthNames[dateEnd.getMonth()]+' - '+dateEnd.toString('yyyy'); |
---|
1626 | return +dateStart.toString("dd")+" a "+dateEnd.toString("dd")+" de "+dateCalendar.monthNames[dateEnd.getMonth()]+" - "+dateEnd.toString('yyyy'); |
---|
1627 | case 'month': |
---|
1628 | var date = new Date().add({months: page_index}) |
---|
1629 | return dateCalendar.monthNames[date.getMonth()]+" "+date.toString("yyyy"); |
---|
1630 | case 'year': |
---|
1631 | var date = new Date().add({years: page_index}); |
---|
1632 | return date.toString("yyyy"); |
---|
1633 | } |
---|
1634 | } |
---|
1635 | |
---|
1636 | function paginatorList(currentView, view){ |
---|
1637 | $(currentView+' .events-list.events-list-win.active .list-events-paginator .fc-header-title').html('<h2>'+mountTitleList( parseInt($('[name = page_index]').val()),view)+'</h2>'); |
---|
1638 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
1639 | if(view == 'basicDay') |
---|
1640 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button-agendaday').addClass('fc-state-active'); |
---|
1641 | else |
---|
1642 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button-'+((view == 'day' || view == 'week') ? 'agenda'+view : view )).addClass('fc-state-active'); |
---|
1643 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right').addClass('list-right'); |
---|
1644 | |
---|
1645 | $(currentView+' .header-paginator .fc-header-right .fc-button').hover( |
---|
1646 | function(){ |
---|
1647 | $(this).addClass('fc-state-hover'); |
---|
1648 | }, |
---|
1649 | function(){ |
---|
1650 | $(this).removeClass('fc-state-hover'); |
---|
1651 | }).mousedown(function(){ |
---|
1652 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
1653 | $(this).addClass('fc-state-active'); |
---|
1654 | }).mouseup(function(){ |
---|
1655 | var goView = $(this).attr('class'); |
---|
1656 | if(goView.indexOf('agendaDay') > 0) |
---|
1657 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'day'); |
---|
1658 | else if(goView.indexOf('month') > 0) |
---|
1659 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'month'); |
---|
1660 | else if(goView.indexOf('year') > 0) |
---|
1661 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'year'); |
---|
1662 | else if(goView.indexOf('agendaWeek') > 0) |
---|
1663 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'week'); |
---|
1664 | |
---|
1665 | }); |
---|
1666 | |
---|
1667 | $(currentView+' .header-paginator .fc-header-left .fc-button').hover( |
---|
1668 | function(){ |
---|
1669 | $(this).addClass('fc-state-hover'); |
---|
1670 | }, |
---|
1671 | function(){ |
---|
1672 | $(this).removeClass('fc-state-hover'); |
---|
1673 | }).mousedown(function(){ |
---|
1674 | $(this).addClass('fc-state-down'); |
---|
1675 | }).mouseup(function(){ |
---|
1676 | $(this).removeClass('fc-state-down'); |
---|
1677 | var paginator = $(this).attr('class'); |
---|
1678 | if(paginator.indexOf('next') > 0) |
---|
1679 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($('[name = page_index]').val())) +1), '', view); |
---|
1680 | else |
---|
1681 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($('[name = page_index]').val())) -1), '', view); |
---|
1682 | }); |
---|
1683 | } |
---|
1684 | |
---|
1685 | function paginatorListEvent(currentView, typeView, view){ |
---|
1686 | if(!!$(currentView).find('.fc-calendar').length) |
---|
1687 | return; |
---|
1688 | $(currentView+' .events-list.events-list-win.active').prepend($('.fc-header').clone()); |
---|
1689 | //Remove contudo nao utilizado |
---|
1690 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-today').remove(); |
---|
1691 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-basicWeek').remove(); |
---|
1692 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-basicDay').remove(); |
---|
1693 | |
---|
1694 | //Adiciona e remove as classes para esta visualizacao |
---|
1695 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-header-center').addClass('list-events-paginator'); |
---|
1696 | $(currentView+' .events-list.events-list-win.active .fc-header .list-events-paginator').removeClass('fc-header-center'); |
---|
1697 | |
---|
1698 | //Adicionar class no header padronizar com a tela principal |
---|
1699 | $(currentView+' .events-list.events-list-win.active .fc-header').addClass('header-paginator'); |
---|
1700 | $(currentView+' .events-list.events-list-win.active .header-paginator').removeClass('fc-header'); |
---|
1701 | |
---|
1702 | if(typeView == 'search'){ |
---|
1703 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right').remove() |
---|
1704 | $(currentView+' .events-list.events-list-win.active .list-events-paginator .fc-header-title').html('<h2>Resultados para: '+$(currentView+' [name = keyword]').val()+'</h2>'); |
---|
1705 | if((parseInt($(currentView+' [name = page_index]').val()) == 0) && (parseInt($(currentView+' [name = results]').val()) <= 25)) |
---|
1706 | return; |
---|
1707 | paginatorSearch(currentView); |
---|
1708 | }else |
---|
1709 | paginatorList(currentView, view); |
---|
1710 | } |
---|
1711 | |
---|
1712 | function mountCriteriaList(view, page_index, calerdars_selecteds){ |
---|
1713 | var rangeStart , rangeEnd; |
---|
1714 | switch (view){ |
---|
1715 | case 'basicDay': |
---|
1716 | case 'day': |
---|
1717 | rangeStart = new Date().add({days: page_index}).toString("yyyy-MM-dd"); |
---|
1718 | rangeEnd = rangeStart; |
---|
1719 | break; |
---|
1720 | case 'agendaWeek': |
---|
1721 | case 'week': |
---|
1722 | var dateStart = new Date().moveToDayOfWeek(dateCalendar.dayOfWeek[User.preferences.weekStart]); |
---|
1723 | var dateEnd = new Date().moveToDayOfWeek(dateCalendar.dayOfWeek[User.preferences.weekStart]); |
---|
1724 | rangeStart = dateStart.add({days: (7 * page_index)}).toString("yyyy-MM-dd"); |
---|
1725 | rangeEnd = dateEnd.add({days: (7 * page_index)+7}).toString("yyyy-MM-dd"); |
---|
1726 | break; |
---|
1727 | case 'month': |
---|
1728 | var date = new Date().add({months: page_index}) |
---|
1729 | rangeStart = date.moveToFirstDayOfMonth().toString("yyyy-MM-dd"); |
---|
1730 | rangeEnd = date.moveToLastDayOfMonth().toString("yyyy-MM-dd"); |
---|
1731 | break; |
---|
1732 | case 'year': |
---|
1733 | var dateStart = new Date().add({years: page_index}); |
---|
1734 | var dateEnd = new Date().add({years: page_index}); |
---|
1735 | if(dateStart.getMonth() != 0) |
---|
1736 | dateStart.moveToMonth(0, -1) |
---|
1737 | if(dateEnd.getMonth() != 11) |
---|
1738 | dateEnd.moveToMonth(11) |
---|
1739 | rangeStart = dateStart.moveToFirstDayOfMonth().toString("yyyy-MM-dd"); |
---|
1740 | rangeEnd = dateEnd.moveToLastDayOfMonth().toString("yyyy-MM-dd"); |
---|
1741 | break; |
---|
1742 | } |
---|
1743 | return {filter: ['AND', ['>=', 'rangeStart', rangeStart], ['<=', 'rangeEnd', rangeEnd] , ['IN', 'calendar', calerdars_selecteds]], criteria: {deepness: 2, order: 'startTime'}}; |
---|
1744 | |
---|
1745 | } |
---|
1746 | |
---|
1747 | function pageselectCallback(keyword, page_index, jq, view){ |
---|
1748 | |
---|
1749 | var selecteds = getSelectedCalendars(); |
---|
1750 | if(!selecteds && (keyword != '' && keyword != null)){ |
---|
1751 | jQuery('#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( |
---|
1752 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
1753 | '<label>Por favor selecione ao menos uma agenda.</label>' + |
---|
1754 | '</div>' |
---|
1755 | ); |
---|
1756 | }else{ |
---|
1757 | var criteria = null; |
---|
1758 | if(keyword == '' || keyword == null) |
---|
1759 | criteria = mountCriteriaList(!!view ? view : User.preferences.defaultCalView, page_index, selecteds) |
---|
1760 | else |
---|
1761 | 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}}; |
---|
1762 | var results = DataLayer.get('schedulable:detail', criteria); |
---|
1763 | keyword = ( keyword || '' ).replace( /\s+/g, "_" ); |
---|
1764 | } |
---|
1765 | // não há resultados |
---|
1766 | if ((((typeof(results) == 'undefined') || (!results.events_list )) && selecteds) &&(keyword != '' && keyword != null)) { |
---|
1767 | jQuery('#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( |
---|
1768 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
1769 | '<label>Não foi encontrado nenhum evento correspondente à sua pesquisa.</label>' + |
---|
1770 | '</div>' |
---|
1771 | ); |
---|
1772 | // há resultados e Agendas Selecionadas |
---|
1773 | } else{ |
---|
1774 | if(typeof(results) != 'undefined'){ |
---|
1775 | results['page_index'] = page_index; |
---|
1776 | results['keyword'] = keyword; |
---|
1777 | |
---|
1778 | DataLayer.render( 'templates/event_list.ejs', results, function( html ){ |
---|
1779 | var currentView = '#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "") || ''); |
---|
1780 | jQuery(currentView).html( html ); |
---|
1781 | jQuery('.events-list-win .menu-container .button').button(); |
---|
1782 | |
---|
1783 | $(".event-details-item").parent().click(function(){ |
---|
1784 | |
---|
1785 | $(this).siblings("div.details-event-list").toggleClass("hidden") |
---|
1786 | .find('.button.delete').click(function(){ |
---|
1787 | var eventId = $(this).siblings('[name="eventid"]').val(); |
---|
1788 | $.Zebra_Dialog('Tem certeza que deseja excluir o evento?', { |
---|
1789 | 'type': 'question', |
---|
1790 | 'overlay_opacity': '0.5', |
---|
1791 | 'buttons': ['Sim', 'Não'], |
---|
1792 | 'onClose': function(clicked) { |
---|
1793 | if(clicked == 'Sim'){ |
---|
1794 | DataLayer.remove('schedulable', eventId); |
---|
1795 | } |
---|
1796 | } |
---|
1797 | }); |
---|
1798 | }) |
---|
1799 | .end().find('.button.edit').click(function(){ |
---|
1800 | eventDetails( DataLayer.get( "schedulable", $(this).siblings('[name="eventid"]').val() ), true ); |
---|
1801 | }); |
---|
1802 | |
---|
1803 | }); |
---|
1804 | paginatorListEvent(currentView, (keyword == '' || keyword == null) ? 'list' : 'search', !!view ? view : User.preferences.defaultCalView); |
---|
1805 | }); |
---|
1806 | }else{ |
---|
1807 | var currentView = '#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "") || ''); |
---|
1808 | jQuery('#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( |
---|
1809 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
1810 | '<input type="hidden" name="page_index" value="'+page_index+'"></inpunt>'+ |
---|
1811 | '<input type="hidden" name="keyword" value="'+keyword+'"></inpunt>'+ |
---|
1812 | '<label>Não foram encontrados eventos neste intervalo.</label>' + |
---|
1813 | '</div>' |
---|
1814 | ); |
---|
1815 | paginatorListEvent(currentView, 'list', !!view ? view : User.preferences.defaultCalView); |
---|
1816 | } |
---|
1817 | |
---|
1818 | } |
---|
1819 | |
---|
1820 | } |
---|
1821 | |
---|
1822 | function show_modal_import_export(tab, calendarId) { |
---|
1823 | DataLayer.render( 'templates/import_export.ejs', {calendars: Calendar.calendars, owner: User.me.id}, function( html ){ |
---|
1824 | |
---|
1825 | if (!UI.dialogs.importCalendar) { |
---|
1826 | UI.dialogs.importCalendar = jQuery('#div-import-export-calendar') |
---|
1827 | .append('<div title="Importar e Exportar Eventos" class="import-export import-export-win active"> <div>') |
---|
1828 | .find('.import-export-win.active').html(html).dialog({ |
---|
1829 | resizable: false, |
---|
1830 | modal:true, |
---|
1831 | width:500, |
---|
1832 | position: 'center' |
---|
1833 | }); |
---|
1834 | |
---|
1835 | } else { |
---|
1836 | UI.dialogs.importCalendar.html(html); |
---|
1837 | } |
---|
1838 | |
---|
1839 | var tabsImportExport = UI.dialogs.importCalendar.find(".tabs-import-export").tabs({selected: tab}); |
---|
1840 | |
---|
1841 | UI.dialogs.importCalendar.find('.button').button(); |
---|
1842 | |
---|
1843 | tabsImportExport.find('option[value="'+calendarId+'"]').attr('selected','selected').trigger('change'); |
---|
1844 | |
---|
1845 | |
---|
1846 | UI.dialogs.importCalendar.find(".menu-import-event") |
---|
1847 | .children(".import").click(function(data){ |
---|
1848 | $('.import-event-form', UI.dialogs.importCalendar).submit(); |
---|
1849 | UI.dialogs.importCalendar.dialog("close"); |
---|
1850 | isValidCalback = true; |
---|
1851 | /** |
---|
1852 | * TODO - implementar ação de importação |
---|
1853 | */ |
---|
1854 | }); |
---|
1855 | |
---|
1856 | UI.dialogs.importCalendar.find(".menu-export-event") |
---|
1857 | .children(".export").click(function(){ |
---|
1858 | |
---|
1859 | $('.export-event-form', UI.dialogs.importCalendar).submit(); |
---|
1860 | UI.dialogs.importCalendar.dialog("close"); |
---|
1861 | /** |
---|
1862 | * TODO - implementar ação de exportação |
---|
1863 | */ |
---|
1864 | }); |
---|
1865 | |
---|
1866 | UI.dialogs.importCalendar.find(".menu-container") |
---|
1867 | .children(".cancel").click(function(){ |
---|
1868 | UI.dialogs.importCalendar.dialog("close"); |
---|
1869 | }); |
---|
1870 | |
---|
1871 | UI.dialogs.importCalendar.dialog("open"); |
---|
1872 | }); |
---|
1873 | } |
---|