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