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