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