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