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