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