[5515] | 1 | function formatBytes(bytes) { |
---|
| 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'; |
---|
| 12 | }; |
---|
| 13 | |
---|
[5341] | 14 | function validDateEvent(){ |
---|
| 15 | var start_date = $(".new-event-win.active .start-date").val(); |
---|
| 16 | var end_date = $(".new-event-win.active .end-date").val(); |
---|
| 17 | var start_time = $(".new-event-win.active .start-time").val(); |
---|
| 18 | var end_time = $(".new-event-win.active .end-time").val(); |
---|
[5409] | 19 | var isAllDay = $('.new-event-win.active input[name="allDay"]').is(':checked'); |
---|
[5341] | 20 | |
---|
| 21 | if(start_date == "") |
---|
| 22 | return 'Por favor, informe uma data inicial'; |
---|
| 23 | else if(end_date == "") |
---|
| 24 | return 'Por favor, informe uma data final'; |
---|
| 25 | else if(!isAllDay && start_time == "") |
---|
| 26 | return 'Por favor, informe uma hora inicial'; |
---|
| 27 | else if(!isAllDay && end_time == "") |
---|
| 28 | return 'Por favor, informe uma hora final'; |
---|
| 29 | |
---|
| 30 | var formatString = (isAllDay)? User.preferences.dateFormat+" HH:mm" : User.preferences.dateFormat + " " + User.preferences.hourFormat; |
---|
[5409] | 31 | |
---|
| 32 | var startDate = Date.parseExact( isAllDay ? start_date+ " 00:00": start_date + " " + $.trim(start_time) , formatString ); |
---|
| 33 | var endDate = Date.parseExact( isAllDay ? end_date+ " 00:00": end_date + " " + $.trim(end_time) , formatString ); |
---|
[5510] | 34 | |
---|
[5341] | 35 | if(startDate == null || startDate.getTime() < 0 ) |
---|
| 36 | return 'Data inicial inválida'; |
---|
| 37 | if(endDate == null || endDate.getTime() < 0) |
---|
| 38 | return 'Data final inválida'; |
---|
| 39 | |
---|
| 40 | if((endDate.compareTo(startDate) != 1) && !((endDate.compareTo(startDate) == 0) && (isAllDay))){ |
---|
[5409] | 41 | return (start_date == end_date) ? |
---|
| 42 | ((end_time == start_time) ? 'Hora inicial igual a final' : 'Hora final menor que a inicial') : |
---|
| 43 | 'Data final menor que a inicial'; |
---|
[5341] | 44 | } |
---|
| 45 | return false; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | /* |
---|
| 49 | function listEvents(){ |
---|
| 50 | var list = $('.fc-header-right').find('.fc-button.fc-button-agendaDay').clone(); |
---|
| 51 | $('.fc-header-right').find('.fc-button-year').toggleClass('fc-corner-right'); |
---|
| 52 | list.addClass('fc-corner-right'); |
---|
| 53 | list.addClass('fc-button-listagem'); |
---|
| 54 | list.removeClass('fc-button-agendaDay'); |
---|
| 55 | list.removeClass('fc-corner-left'); |
---|
| 56 | list.find('.fc-button-content').html('Listagem'); |
---|
| 57 | $('.fc-header-right').append(list); |
---|
| 58 | } |
---|
| 59 | */ |
---|
[5514] | 60 | |
---|
[5746] | 61 | /* |
---|
| 62 | * TODO - repeat foi adicionado pois melhorias devem ser feitas no rollback do |
---|
| 63 | *DataLayer, repeat somente é usado quando se trata da criação de um evento |
---|
| 64 | *pela edição de uma ocorrência. |
---|
| 65 | */ |
---|
| 66 | |
---|
| 67 | function eventDetails( objEvent, decoded, path, isMail, repeat) |
---|
[5341] | 68 | { |
---|
[5636] | 69 | attendees = {}; |
---|
| 70 | |
---|
[5389] | 71 | if(path == undefined) |
---|
| 72 | path = ""; |
---|
| 73 | |
---|
[5341] | 74 | if( !decoded ) |
---|
| 75 | objEvent = DataLayer.decode( "schedulable:calendar", objEvent ); |
---|
| 76 | |
---|
[5592] | 77 | if(!isMail) |
---|
[5341] | 78 | objEvent = DataLayer.encode( "schedulable:preview", objEvent ); |
---|
| 79 | |
---|
| 80 | if(typeof(objEvent.id) == 'undefined'){ |
---|
[5409] | 81 | objEvent.alarms = Calendar.signatureOf[User.preferences.defaultCalendar || Calendar.calendarIds[0]].defaultAlarms || false; |
---|
[5341] | 82 | objEvent.useAlarmDefault = 1; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | * canDiscardEventDialog deve ser true se não houver alterações no evento |
---|
| 87 | */ |
---|
| 88 | canDiscardEventDialog = true; |
---|
| 89 | /** |
---|
| 90 | * zebraDiscardEventDialog é uma flag indicando que uma janela de confirmação (Zebra_Dialog) |
---|
| 91 | * já está aberta na tela, uma vez que não é possivel acessar o evento ESC utilizado para fechá-la |
---|
| 92 | */ |
---|
| 93 | zebraDiscardEventDialog = false; |
---|
| 94 | |
---|
[5514] | 95 | /** |
---|
| 96 | ACLs do participant |
---|
| 97 | */ |
---|
| 98 | acl_names = { |
---|
| 99 | 'w': 'acl-white', |
---|
| 100 | 'i': 'acl-invite-guests', |
---|
| 101 | 'p': 'acl-participation-required' |
---|
| 102 | }; |
---|
[5636] | 103 | |
---|
[5514] | 104 | var callbackAttendee = function(){ |
---|
| 105 | //Cria qtip de permissões pelo click do checkbox |
---|
| 106 | var checked = false; |
---|
| 107 | blkAddAtendee.find("li.not-attendee").addClass('hidden'); |
---|
| 108 | |
---|
| 109 | blkAddAtendee.find("li .button").filter(".close.new").button({ |
---|
| 110 | icons: { |
---|
| 111 | primary: "ui-icon-close" |
---|
| 112 | }, |
---|
| 113 | text: false |
---|
| 114 | }).click(function () { |
---|
| 115 | DataLayer.remove('participant', $(this).parents('li').find('[type=checkbox]').val()); |
---|
[5530] | 116 | if($(this).parent().find('.button.delegate').hasClass('attendee-permissions-change-button')){ |
---|
| 117 | |
---|
| 118 | blkAddAtendee.find('.request-update').addClass('hidden'); |
---|
| 119 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
| 120 | |
---|
| 121 | blkAddAtendee.find('option[value=1]').attr('selected','selected').trigger('change'); |
---|
| 122 | } |
---|
| 123 | |
---|
[5514] | 124 | $(this).parents('li').remove(); |
---|
[5530] | 125 | |
---|
[5514] | 126 | if(blkAddAtendee.find(".attendee-list li").length == 1) |
---|
| 127 | blkAddAtendee.find("li.not-attendee").removeClass('hidden'); |
---|
| 128 | }) |
---|
| 129 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
| 130 | .removeClass('new').end() |
---|
| 131 | |
---|
| 132 | .filter(".delegate.new").button({ |
---|
| 133 | icons: { |
---|
| 134 | primary: "ui-icon-transferthick-e-w" |
---|
| 135 | }, |
---|
| 136 | text: false |
---|
| 137 | }).click(function () { |
---|
| 138 | |
---|
| 139 | if($(this).hasClass('attendee-permissions-change-button')){ |
---|
| 140 | $(this).removeClass('attendee-permissions-change-button') |
---|
| 141 | .find('.ui-icon-transferthick-e-w').removeClass('attendee-permissions-change').end(); |
---|
| 142 | |
---|
| 143 | $(this).parents('li').find('input[name="delegatedFrom[]"]').val(''); |
---|
| 144 | |
---|
| 145 | blkAddAtendee.find('.request-update').addClass('hidden'); |
---|
| 146 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | blkAddAtendee.find('option[value=1]').attr('selected','selected').trigger('change'); |
---|
| 150 | |
---|
| 151 | }else{ |
---|
| 152 | blkAddAtendee.find('.delegate').removeClass('attendee-permissions-change-button'); |
---|
| 153 | blkAddAtendee.find('.ui-icon-transferthick-e-w').removeClass('attendee-permissions-change'); |
---|
| 154 | |
---|
| 155 | $(this).addClass('attendee-permissions-change-button') |
---|
| 156 | .find('.ui-icon-transferthick-e-w').addClass('attendee-permissions-change').end(); |
---|
| 157 | $(this).parents('li').find('input[name="delegatedFrom[]"]').val(blkAddAtendee.find('.me input[name="attendee[]"]').val()); |
---|
| 158 | |
---|
| 159 | blkAddAtendee.find('.request-update').removeClass('hidden'); |
---|
| 160 | if(blkAddAtendee.find('.status option.hidden').length == 1) |
---|
| 161 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
| 162 | |
---|
| 163 | blkAddAtendee.find('option[value=5]').attr('selected','selected').trigger('change'); |
---|
| 164 | } |
---|
| 165 | }) |
---|
| 166 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
| 167 | .removeClass('new').end() |
---|
| 168 | |
---|
| 169 | .filter(".edit.new").button({ |
---|
| 170 | icons: { |
---|
| 171 | primary: "ui-icon-key" |
---|
| 172 | }, |
---|
| 173 | text: false |
---|
| 174 | }).click(function() { |
---|
| 175 | |
---|
| 176 | if(!!!checked) |
---|
| 177 | $(this).parents('li').find('[type=checkbox]').attr('checked', (!$(this).parent().find('[type=checkbox]').is(':checked'))).end(); |
---|
| 178 | |
---|
| 179 | var aclsParticipant = $(this).parents('li').find('input[name="attendeeAcl[]"]').val(); |
---|
| 180 | checked = false; |
---|
| 181 | |
---|
| 182 | if( $('.qtip.qtip-blue.qtip-active').val() !== ''){ |
---|
| 183 | blkAddAtendee.find('dd.attendee-list').qtip({ |
---|
| 184 | show: {ready: true, solo: true, when: {event: 'click'}}, |
---|
| 185 | hide: false, |
---|
| 186 | content: { |
---|
| 187 | text: $('<div></div>').html( DataLayer.render( 'templates/attendee_permissions.ejs', {} ) ), |
---|
| 188 | title: { |
---|
| 189 | text:'Permissões', |
---|
| 190 | button: '<a class="button close" href="#">close</a>' |
---|
| 191 | } |
---|
| 192 | }, |
---|
| 193 | style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}}, |
---|
| 194 | position: { |
---|
| 195 | corner: { |
---|
| 196 | target: 'rightMiddle', |
---|
| 197 | tooltip: 'leftMiddle' |
---|
| 198 | }, |
---|
| 199 | adjust: {x:0, y:0} |
---|
| 200 | } |
---|
| 201 | }) |
---|
| 202 | .qtip("api").onShow = function(arg0) { |
---|
| 203 | $('.qtip-active .button.close').button({ |
---|
| 204 | icons: {primary: "ui-icon-close"}, |
---|
| 205 | text: false |
---|
| 206 | }) |
---|
| 207 | .click(function(){ |
---|
| 208 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
| 209 | }); |
---|
| 210 | |
---|
| 211 | $('.qtip-active .button.save').button().click(function(){ |
---|
| 212 | |
---|
| 213 | var acl = ''; |
---|
| 214 | $('.qtip-active').find('[type=checkbox]:checked').each(function(i, obj) { |
---|
| 215 | acl+= obj.value; |
---|
| 216 | }); |
---|
| 217 | |
---|
| 218 | blkAddAtendee.find('dd.attendee-list [type=checkbox]:checked').siblings('input[name="attendeeAcl[]"]').each(function(i, obj) { |
---|
| 219 | obj.value = 'r'+acl; |
---|
| 220 | }).parents('li').find('.button.edit').addClass('attendee-permissions-change-button') |
---|
| 221 | .find('.ui-icon-key').addClass('attendee-permissions-change'); |
---|
| 222 | |
---|
| 223 | blkAddAtendee.find('dd.attendee-list [type=checkbox]').attr('checked', false); |
---|
| 224 | |
---|
| 225 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
| 226 | |
---|
| 227 | }); |
---|
| 228 | $('.qtip-active .button.cancel').button().click(function(){ |
---|
| 229 | blkAddAtendee.find('dd.attendee-list [type=checkbox]').attr('checked', false); |
---|
| 230 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
| 231 | }); |
---|
| 232 | |
---|
| 233 | if(aclsParticipant) |
---|
| 234 | for(var i = 1; i < aclsParticipant.length; i++){ |
---|
| 235 | $('.qtip-active').find('input[name="'+acl_names[aclsParticipant.charAt(i)]+'"]').attr('checked', true); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | |
---|
| 239 | $('.button').button(); |
---|
| 240 | |
---|
| 241 | }; |
---|
| 242 | }else{ |
---|
| 243 | if(!$('.new-event-win dd.attendee-list').find('[type=checkbox]:checked').length){ |
---|
| 244 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
| 245 | }else{ |
---|
| 246 | $('.qtip-active .button.save .ui-button-text').html('Aplicar a todos') |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | }; |
---|
| 250 | }) |
---|
| 251 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
| 252 | .removeClass('new').end() |
---|
| 253 | |
---|
| 254 | .filter(".open-delegate.new").click(function(){ |
---|
| 255 | if($(this).hasClass('ui-icon-triangle-1-e')){ |
---|
| 256 | $(this).removeClass('ui-icon-triangle-1-e').addClass('ui-icon-triangle-1-s'); |
---|
| 257 | $(this).parents('li').find('.list-delegates').removeClass('hidden'); |
---|
| 258 | }else{ |
---|
| 259 | $(this).removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e'); |
---|
| 260 | $(this).parents('li').find('.list-delegates').addClass('hidden'); |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | }).removeClass('new'); |
---|
| 264 | |
---|
| 265 | |
---|
| 266 | blkAddAtendee.find("li input[type=checkbox].new").click(function(){ |
---|
| 267 | if(!$('.new-event-win dd.attendee-list').find('[type=checkbox]:checked').length){ |
---|
| 268 | blkAddAtendee.find('dd.attendee-list').qtip('destroy'); |
---|
| 269 | }else{ |
---|
| 270 | checked = true; |
---|
[5641] | 271 | $(this).parents('li').find('.button.edit').click(); |
---|
[5514] | 272 | } |
---|
| 273 | }).removeClass('new'); |
---|
| 274 | |
---|
| 275 | UI.dialogs.addEvent.find('.attendees-list li').hover( |
---|
| 276 | function () { |
---|
| 277 | $(this).addClass("hover-attendee"); |
---|
| 278 | $(this).find('.button').removeClass('disable ui-button-disabled ui-state-disabled').end() |
---|
| 279 | .find('.attendee-options').addClass('hover-attendee'); |
---|
| 280 | }, |
---|
| 281 | function () { |
---|
| 282 | $(this).removeClass("hover-attendee"); |
---|
| 283 | $(this).find('.button').addClass('disable ui-button-disabled ui-state-disabled').end() |
---|
| 284 | .find('.attendee-options').removeClass('hover-attendee');; |
---|
| 285 | } |
---|
| 286 | ); |
---|
| 287 | |
---|
| 288 | |
---|
| 289 | } |
---|
| 290 | |
---|
[5389] | 291 | var html = DataLayer.render( path+'templates/event_add.ejs', {event:objEvent}); |
---|
[5341] | 292 | |
---|
| 293 | if (!UI.dialogs.addEvent) { |
---|
| 294 | UI.dialogs.addEvent = jQuery('#sandbox').append('<div title="Criar Evento" class="new-event-win active"> <div>').find('.new-event-win.active').html(html).dialog({ |
---|
| 295 | resizable: false, |
---|
| 296 | modal:true, |
---|
| 297 | autoOpen: false, |
---|
| 298 | width:700, |
---|
| 299 | position: 'center', |
---|
| 300 | close: function(event, ui) { |
---|
| 301 | /** |
---|
| 302 | * Remove tooltip possivelmente existente |
---|
| 303 | */ |
---|
| 304 | if ($('dd.attendee-list li:last').data('qtip')) |
---|
| 305 | $('dd.attendee-list li:last').qtip('destroy'); |
---|
[5636] | 306 | |
---|
| 307 | attendees = {}; |
---|
[5341] | 308 | |
---|
| 309 | }, |
---|
| 310 | beforeClose: function(event, ui) { |
---|
| 311 | |
---|
| 312 | if (!canDiscardEventDialog && !zebraDiscardEventDialog) { |
---|
| 313 | zebraDiscardEventDialog = true; |
---|
| 314 | window.setTimeout(function() { |
---|
| 315 | $.Zebra_Dialog('Suas alterações no evento não foram salvas. Deseja descartar as alterações?', { |
---|
| 316 | 'type': 'question', |
---|
| 317 | 'overlay_opacity': '0.5', |
---|
| 318 | 'buttons': ['Descartar alterações', 'Continuar editando'], |
---|
| 319 | 'onClose': function(clicked) { |
---|
| 320 | if(clicked == 'Descartar alterações') { |
---|
| 321 | canDiscardEventDialog = true; |
---|
[5514] | 322 | /** |
---|
| 323 | *Remoção dos anexos do eventos caso seja cancelado a edição |
---|
| 324 | */ |
---|
| 325 | var ids = []; |
---|
[5746] | 326 | $.each($('.attachment-list input'), function (i, input) {ids.push(input.value);}); |
---|
[5514] | 327 | if(ids.length > 0) |
---|
| 328 | DataLayer.remove('attachment', {filter: ['IN', 'id', ids]}); |
---|
| 329 | |
---|
[5746] | 330 | DataLayer.rollback(); |
---|
| 331 | |
---|
[5341] | 332 | UI.dialogs.addEvent.dialog('close'); |
---|
[5381] | 333 | }else{ |
---|
| 334 | zebraDiscardEventDialog = false; |
---|
[5341] | 335 | } |
---|
| 336 | |
---|
| 337 | /** |
---|
| 338 | * Uma vez aberta uma janela de confirmação (Zebra_Dialog), ao fechá-la |
---|
| 339 | * com ESC, para que o evento ESC não seja propagado para fechamento da |
---|
| 340 | * janela de edição de eventos, deve ser setada uma flag indicando que |
---|
| 341 | * já existe uma janela de confirmação aberta. |
---|
| 342 | */ |
---|
| 343 | if (!clicked) { |
---|
| 344 | window.setTimeout(function() { |
---|
| 345 | zebraDiscardEventDialog = false; |
---|
| 346 | }, 200); |
---|
| 347 | } |
---|
| 348 | } |
---|
| 349 | }); |
---|
| 350 | |
---|
| 351 | }, 300); |
---|
| 352 | |
---|
| 353 | } |
---|
| 354 | return canDiscardEventDialog; |
---|
| 355 | } |
---|
| 356 | }); |
---|
| 357 | |
---|
| 358 | } else { |
---|
| 359 | UI.dialogs.addEvent.html(html); |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | var tabs = UI.dialogs.addEvent.children('.content').tabs(); |
---|
| 363 | var calendar = DataLayer.get('calendar', objEvent.calendar); |
---|
[5381] | 364 | |
---|
[5341] | 365 | if (calendar.timezone != objEvent.timezone){ |
---|
| 366 | UI.dialogs.addEvent.find('.calendar-addevent-details-txt-timezone').find('option[value="'+objEvent.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
| 367 | UI.dialogs.addEvent.find('.calendar_addevent_details_lnk_timezone').addClass('hidden'); |
---|
| 368 | $('.calendar-addevent-details-txt-timezone').removeClass('hidden'); |
---|
| 369 | |
---|
| 370 | } |
---|
[5715] | 371 | |
---|
| 372 | DataLayer.render( 'templates/event_repeat.ejs', {event:objEvent}, function( repeatHtml ){ |
---|
| 373 | |
---|
| 374 | UI.dialogs.addEvent.find('#calendar_addevent_details3').html(repeatHtml); |
---|
| 375 | $(".date").datepicker(); |
---|
| 376 | |
---|
| 377 | if(objEvent.repeat) |
---|
| 378 | { |
---|
| 379 | if( objEvent.repeat['id'] ) |
---|
| 380 | { |
---|
| 381 | $("[name='repeatId']:last").val( objEvent.repeat['id'] ); |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | if( objEvent.repeat['frequency'] !== 'none' ) |
---|
| 385 | { |
---|
| 386 | if( objEvent.repeat['startTime'] && objEvent.repeat['startTime'] !== "0" ) |
---|
| 387 | { |
---|
| 388 | $("[name='startOptions'] [value='customDate']:last").attr( 'selected', 'selected' ); |
---|
| 389 | $("[name='start']:last").val(new Date( parseInt(objEvent.repeat['startTime']) ).toString( User.preferences.dateFormat ) ); |
---|
| 390 | } |
---|
| 391 | else |
---|
| 392 | { |
---|
| 393 | $("[name='start']:last").val($("[name='startDate']:last").val()); |
---|
| 394 | $("[name='start']:last").readOnly=true; |
---|
| 395 | $("[name='start']:last").datepicker("disable"); |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | $(".finish_event").removeClass("hidden"); |
---|
| 399 | |
---|
| 400 | if(objEvent.repeat['endTime'] && objEvent.repeat['endTime'] !== "0" ) |
---|
| 401 | { |
---|
| 402 | //$("[name='occurrences']").addClass("hidden"); |
---|
| 403 | $(".customDateEnd").removeClass("hidden"); |
---|
| 404 | $(".endRepeat option[value='customDate']").attr('selected', 'selected') |
---|
| 405 | $(".customDateEnd").val( new Date( parseInt(objEvent.repeat['endTime']) )/*.setTimezoneOffset( Timezone.timezone( objEvent.timezone ) )*/.toString( User.preferences.dateFormat ) ); |
---|
| 406 | } |
---|
| 407 | else if (objEvent.repeat['count'] && objEvent.repeat['count'] !== "0" ) { |
---|
| 408 | $(".endRepeat option[value='occurrences']").attr('selected', 'selected'); |
---|
| 409 | $(".occurrencesEnd").removeClass("hidden"); |
---|
| 410 | $(".occurrencesEnd").val(objEvent.repeat['count']); |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | switch ( objEvent.repeat['frequency'] ) |
---|
| 414 | { |
---|
| 415 | case "daily": |
---|
| 416 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Dia(s)"); |
---|
| 417 | $(".frequency option[value='daily']").attr('selected', 'selected'); |
---|
| 418 | break; |
---|
| 419 | case "weekly": |
---|
| 420 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Semana(s)"); |
---|
| 421 | $(".frequency option[value='weekly']").attr('selected', 'selected'); |
---|
| 422 | objEvent.repeat['interval'] ? $(".event-repeat-container:last").find(".repeat-in").find(".eventInterval").val(objEvent.repeat['interval']) : $(".event-repeat-container:last").find(".repeat-in").find(".eventInterval").val("0"); |
---|
| 423 | |
---|
| 424 | $(".event-repeat-weekly").removeClass("hidden"); |
---|
| 425 | |
---|
| 426 | var day = []; |
---|
| 427 | |
---|
| 428 | if( objEvent.repeat.byday ) |
---|
| 429 | day = objEvent.repeat.byday.split(','); |
---|
| 430 | |
---|
| 431 | for(i=0; i<day.length; i++) |
---|
| 432 | $(".event-repeat-weekly [value='" + day[i] + "']").attr("checked","checked"); |
---|
| 433 | |
---|
| 434 | break; |
---|
| 435 | case "monthly": |
---|
| 436 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Mes(s)"); |
---|
| 437 | $(".frequency option[value='monthly']").attr('selected', 'selected') |
---|
| 438 | $(".event-repeat-monthly:last").removeClass("hidden").find("input[type=radio][name=repeatmonthyType]").click(function(){ |
---|
| 439 | if($("input[type=radio][name=repeatmonthyType]:checked").val() == "1") |
---|
| 440 | $(".event-repeat-weekly:last").removeClass("hidden"); |
---|
| 441 | else |
---|
| 442 | $(".event-repeat-weekly:last").addClass("hidden"); |
---|
| 443 | }); |
---|
| 444 | if($("input[type=radio][name=repeatmonthyType]:checked").val() == "1") |
---|
| 445 | $(".event-repeat-weekly:last").removeClass("hidden"); |
---|
| 446 | else |
---|
| 447 | $(".event-repeat-weekly:last").addClass("hidden"); |
---|
| 448 | break; |
---|
| 449 | case "yearly": |
---|
| 450 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Ano(s)"); |
---|
| 451 | $(".frequency option[value='yearly']").attr('selected', 'selected') |
---|
| 452 | break; |
---|
| 453 | } |
---|
| 454 | } |
---|
| 455 | } |
---|
| 456 | else { |
---|
| 457 | $(".endRepeat option[value='never']").attr('selected', 'selected'); |
---|
| 458 | } |
---|
| 459 | |
---|
| 460 | |
---|
| 461 | $(".event-repeat-container:last").find(".repeat-in").find("[name=startOptions]").change(function(){ |
---|
| 462 | |
---|
| 463 | if($(this).find("option:selected").val() == "Today"){ |
---|
| 464 | $("[name='start']:last").val($("[name='startDate']:last").val()); |
---|
| 465 | $("[name='start']:last").readOnly=true; |
---|
| 466 | $("[name='start']:last").datepicker("disable"); |
---|
| 467 | } |
---|
| 468 | else{ |
---|
| 469 | $("[name='start']:last").readOnly=false; |
---|
| 470 | $("[name='start']:last").datepicker("enable"); |
---|
| 471 | } |
---|
| 472 | }); |
---|
| 473 | $(".event-repeat-container:last").find(".repeat-in").find("[name=endOptions]").change(function(){ |
---|
| 474 | if($(this).find("option:selected").val() == "never"){ |
---|
| 475 | $("[name='occurrences']").addClass("hidden"); |
---|
| 476 | $("[name='end']:last").addClass("hidden"); |
---|
| 477 | } |
---|
| 478 | else if($(this).find("option:selected").val() == "customDate"){ |
---|
| 479 | $("[name='occurrences']").addClass("hidden"); |
---|
| 480 | $("[name='end']:last").removeClass("hidden"); |
---|
| 481 | } |
---|
| 482 | else{ |
---|
| 483 | $("[name='end']:last").addClass("hidden"); |
---|
| 484 | $("[name='occurrences']").removeClass("hidden"); |
---|
| 485 | } |
---|
| 486 | }); |
---|
| 487 | |
---|
| 488 | $("[name='frequency']:last").change(function () { |
---|
| 489 | $(".frequency-option").addClass("hidden"); |
---|
| 490 | if($(this).val() == "none"){ |
---|
| 491 | $(".repeat-in").addClass("hidden"); |
---|
| 492 | return; |
---|
| 493 | }else{ |
---|
| 494 | $(".repeat-in").removeClass("hidden"); |
---|
| 495 | $("[name='start']:last").val($("[name='startDate']:last").val()); |
---|
| 496 | } |
---|
| 497 | |
---|
| 498 | |
---|
| 499 | switch($(this).val()){ |
---|
| 500 | case "daily": |
---|
| 501 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Dia(s)"); |
---|
| 502 | break; |
---|
| 503 | case "weekly": |
---|
| 504 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Semana(s)"); |
---|
| 505 | $(".event-repeat-weekly:last").removeClass("hidden"); |
---|
| 506 | break; |
---|
| 507 | case "monthly": |
---|
| 508 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Mes(s)"); |
---|
| 509 | $(".event-repeat-monthly:last").removeClass("hidden").find("input[type=radio][name=repeatmonthyType]").click(function(){ |
---|
| 510 | if($("input[type=radio][name=repeatmonthyType]:checked").val() == "1") |
---|
| 511 | $(".event-repeat-weekly:last").removeClass("hidden"); |
---|
| 512 | else |
---|
| 513 | $(".event-repeat-weekly:last").addClass("hidden"); |
---|
| 514 | }); |
---|
| 515 | if($("input[type=radio][name=repeatmonthyType]:checked").val() == "1") |
---|
| 516 | $(".event-repeat-weekly:last").removeClass("hidden"); |
---|
| 517 | else |
---|
| 518 | $(".event-repeat-weekly:last").addClass("hidden"); |
---|
| 519 | break; |
---|
| 520 | default: |
---|
| 521 | $(".event-repeat-container:last").find(".repeat-in").find(".interval").html("Ano(s)"); |
---|
| 522 | break; |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | }); |
---|
| 526 | }); |
---|
| 527 | |
---|
[5341] | 528 | UI.dialogs.addEvent.find('.calendar_addevent_details_lnk_timezone').click(function(e){ |
---|
| 529 | $(this).addClass('hidden'); |
---|
| 530 | $('.calendar-addevent-details-txt-timezone').removeClass('hidden'); |
---|
| 531 | e.preventDefault(); |
---|
| 532 | }); |
---|
| 533 | |
---|
[5376] | 534 | UI.dialogs.addEvent.find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el){ |
---|
| 535 | var id; |
---|
| 536 | if( id = $(this).parent().find('input[name="alarmId[]"]').val()) |
---|
| 537 | DataLayer.remove('alarm', id); |
---|
[5409] | 538 | $(this).parent().remove().find('li').is(':empty'); |
---|
[5341] | 539 | }); |
---|
| 540 | |
---|
[5381] | 541 | /*Seleciona a agenda padrão para criação de um evento*/ |
---|
[5437] | 542 | UI.dialogs.addEvent.find('option[value="'+objEvent.calendar || User.preferences.defaultCalendar+'"]').attr('selected','selected').trigger('change'); |
---|
[5381] | 543 | |
---|
[5341] | 544 | /*Adicionar alarms padrões, quando alterado a agenda do usuário*/ |
---|
| 545 | UI.dialogs.addEvent.find('select[name="calendar"]').change(function(){ |
---|
[5409] | 546 | if((typeof($('input[name = "idEvent"]').val()) == 'undefined') || (!!!$('input[name = "idEvent"]').val())) { |
---|
[5341] | 547 | $('input[name = "isDefaultAlarm[]"]').parent().remove(); |
---|
| 548 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').parent().removeClass('hidden'); |
---|
| 549 | var calendarSelected = Calendar.signatureOf[$(this).val()]; |
---|
| 550 | calendarSelected.useAlarmDefault = 1; |
---|
| 551 | if(calendarSelected.defaultAlarms != ""){ |
---|
[5389] | 552 | var li_attach = DataLayer.render(path+'templates/alarms_add_itemlist.ejs', {alarm:calendarSelected}); |
---|
[5341] | 553 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
[5409] | 554 | $(this).parent().remove().find('li').is(':empty'); |
---|
[5341] | 555 | }); |
---|
| 556 | }else{ |
---|
| 557 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').parent().addClass('hidden'); |
---|
| 558 | } |
---|
| 559 | } |
---|
| 560 | }); |
---|
| 561 | |
---|
| 562 | /*Checkbox adicionar alarms padrões*/ |
---|
| 563 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').click(function(){ |
---|
| 564 | if($(this).attr("checked")){ |
---|
[5354] | 565 | $('input[name="isDefaultAlarm[]"]').parent().remove(); |
---|
[5341] | 566 | var calendarSelected = Calendar.signatureOf[$('select[name="calendar"]').val()]; |
---|
| 567 | calendarSelected.useAlarmDefault = 1; |
---|
| 568 | if(calendarSelected.defaultAlarms != ""){ |
---|
[5389] | 569 | var li_attach = DataLayer.render(path+'templates/alarms_add_itemlist.ejs', {alarm:calendarSelected}); |
---|
[5341] | 570 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
[5376] | 571 | var id; |
---|
| 572 | if( id = $(this).parent().find('input[name="alarmId[]"]').val()) |
---|
| 573 | DataLayer.remove('alarm', id); |
---|
[5409] | 574 | $(this).parent().remove().find('li').is(':empty') |
---|
[5341] | 575 | }); |
---|
| 576 | } |
---|
[5354] | 577 | } else { |
---|
| 578 | $('input[name="isDefaultAlarm[]"]').parent().remove(); |
---|
| 579 | } |
---|
[5341] | 580 | }); |
---|
| 581 | /* Checkbox allday */ |
---|
| 582 | UI.dialogs.addEvent.find('input[name="allDay"]').click(function(){ |
---|
[5409] | 583 | $(this).attr("checked") ? |
---|
| 584 | UI.dialogs.addEvent.find('.start-time, .end-time').addClass('hidden') : |
---|
[5341] | 585 | UI.dialogs.addEvent.find('.start-time, .end-time').removeClass('hidden'); |
---|
[5636] | 586 | updateMap(true); |
---|
[5341] | 587 | }); |
---|
| 588 | |
---|
| 589 | UI.dialogs.addEvent.find('.button').button(); |
---|
| 590 | UI.dialogs.addEvent.find('.button.add').button({ |
---|
| 591 | icons: { |
---|
| 592 | secondary: "ui-icon-plus" |
---|
| 593 | } |
---|
| 594 | }); |
---|
| 595 | |
---|
| 596 | // ==== validation events ==== |
---|
[5354] | 597 | UI.dialogs.addEvent.find(".input-group .h1").Watermark("Evento sem título"); |
---|
| 598 | if(User.preferences.hourFormat.length == 5) { |
---|
[5636] | 599 | UI.dialogs.addEvent.find(".end-time, .start-time").mask("99:99", { |
---|
| 600 | completed: function(){ |
---|
| 601 | updateMap(); |
---|
| 602 | } |
---|
| 603 | }); |
---|
[5354] | 604 | } else { |
---|
[5341] | 605 | $.mask.definitions['{']='[ap]'; |
---|
| 606 | $.mask.definitions['}']='[m]'; |
---|
[5354] | 607 | UI.dialogs.addEvent.find(".end-time, .start-time").mask("99:99 {}", { |
---|
| 608 | completed:function(){ |
---|
[5409] | 609 | $(this).val(date.Calendar.defaultToAmPm($(this).val())); |
---|
[5341] | 610 | $(this).timepicker("refresh"); |
---|
| 611 | $(this).val($(this).val().replace(/[\.]/gi, "")); |
---|
[5636] | 612 | updateMap(); |
---|
[5354] | 613 | } |
---|
| 614 | }); |
---|
[5341] | 615 | } |
---|
[5354] | 616 | UI.dialogs.addEvent.find(".number").numeric(); |
---|
[5409] | 617 | User.preferences.dateFormat.indexOf('-') > 0 ? |
---|
[5636] | 618 | UI.dialogs.addEvent.find(".date").mask("99-99-9999", { |
---|
| 619 | completed:function(){ |
---|
| 620 | updateMap(); |
---|
| 621 | } |
---|
| 622 | }) : |
---|
| 623 | UI.dialogs.addEvent.find(".date").mask("99/99/9999", { |
---|
| 624 | completed:function(){ |
---|
| 625 | updateMap(); |
---|
| 626 | } |
---|
| 627 | }); |
---|
[5341] | 628 | |
---|
| 629 | UI.dialogs.addEvent.find(".menu-addevent") |
---|
| 630 | .children(".delete").click(function(){ |
---|
| 631 | $.Zebra_Dialog('Tem certeza que deseja excluir o evento?', { |
---|
| 632 | 'type': 'question', |
---|
| 633 | 'overlay_opacity': '0.5', |
---|
| 634 | 'buttons': ['Sim', 'Não'], |
---|
| 635 | 'onClose': function(clicked) { |
---|
| 636 | if(clicked == 'Sim'){ |
---|
| 637 | DataLayer.remove( "schedulable", UI.dialogs.addEvent.find(".id-event").val() ); |
---|
| 638 | UI.dialogs.addEvent.dialog("close"); |
---|
| 639 | } |
---|
| 640 | } |
---|
| 641 | }); |
---|
| 642 | }).end() |
---|
| 643 | |
---|
| 644 | .children(".cancel").click(function(){ |
---|
| 645 | DataLayer.rollback('participant'); |
---|
| 646 | UI.dialogs.addEvent.dialog("close"); |
---|
| 647 | }).end() |
---|
| 648 | |
---|
| 649 | .children(".save").click(function(){ |
---|
| 650 | /* Validação */ |
---|
[5354] | 651 | var msg = false; |
---|
| 652 | if(msg = validDateEvent()){ |
---|
| 653 | $(".new-event-win.active").find('.messages-validation').removeClass('hidden').find('.message label').html(msg); |
---|
| 654 | return false; |
---|
| 655 | } |
---|
[5341] | 656 | |
---|
| 657 | canDiscardEventDialog = true; |
---|
| 658 | |
---|
[5752] | 659 | var exit = function(event){ |
---|
| 660 | if(event) |
---|
| 661 | DataLayer.remove('schedulable', event, false); |
---|
| 662 | |
---|
[5746] | 663 | UI.dialogs.addEvent.children().find('form.form-addevent').submit(); |
---|
| 664 | UI.dialogs.addEvent.dialog("close"); |
---|
| 665 | } |
---|
| 666 | |
---|
| 667 | if(repeat){ |
---|
| 668 | DataLayer.remove('repeat', false); |
---|
| 669 | DataLayer.put('repeat', repeat); |
---|
[5752] | 670 | DataLayer.commit('repeat', false, exit(repeat.schedulable)); |
---|
[5746] | 671 | }else |
---|
| 672 | exit(); |
---|
[5341] | 673 | }).end() |
---|
| 674 | |
---|
| 675 | .children(".export").click(function(){ |
---|
[5514] | 676 | UI.dialogs.addEvent.children().find(".form-export").submit(); |
---|
[5341] | 677 | }); |
---|
| 678 | |
---|
[5636] | 679 | var dates = UI.dialogs.addEvent.find('input.date').datepicker({ |
---|
| 680 | dateFormat: 'dd/mm/yy', |
---|
| 681 | onSelect : function( selectedDate ){ |
---|
| 682 | updateMap(); |
---|
| 683 | } |
---|
| 684 | }); |
---|
| 685 | //if(path == ""){ |
---|
| 686 | UI.dialogs.addEvent.find('input.time').timepicker({ |
---|
| 687 | closeText: 'Ok', |
---|
| 688 | hourGrid: 4, |
---|
| 689 | minuteGrid: 10, |
---|
| 690 | ampm : ((User.preferences.hourFormat.length > 5) ? true: false), |
---|
| 691 | timeFormat: "hh:mm tt", |
---|
| 692 | onSelect: function (selectedDateTime){ |
---|
| 693 | if(!(User.preferences.hourFormat.length == 5)) |
---|
| 694 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
| 695 | updateMap(); |
---|
| 696 | }, |
---|
| 697 | onClose : function (selectedDateTime){ |
---|
| 698 | if(!(User.preferences.hourFormat.length == 5)) |
---|
| 699 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
| 700 | } |
---|
| 701 | }); |
---|
| 702 | //} |
---|
[5341] | 703 | |
---|
| 704 | UI.dialogs.addEvent.find('.button-add-alarms').click(function(){ |
---|
[5389] | 705 | var li_attach = DataLayer.render(path+'templates/alarms_add_itemlist.ejs', {}); |
---|
[5341] | 706 | |
---|
| 707 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
[5409] | 708 | $(this).parent().remove().find('li').is(':empty') |
---|
[5341] | 709 | }); |
---|
| 710 | // valicacao de campos numericos |
---|
| 711 | $('.number').numeric(); |
---|
| 712 | }); |
---|
| 713 | |
---|
[5514] | 714 | |
---|
| 715 | UI.dialogs.addEvent.find('.button.suggestion-hours').button({ |
---|
| 716 | icons: { |
---|
| 717 | primary: "ui-icon-clock" |
---|
| 718 | }, |
---|
| 719 | text: 'Sugerir horário' |
---|
| 720 | }).click(function () { |
---|
| 721 | $(this).siblings('input').removeAttr('disabled') |
---|
| 722 | .end().parents().find('input[name="allDay"]').removeAttr('disabled'); |
---|
| 723 | }); |
---|
| 724 | |
---|
| 725 | |
---|
[5746] | 726 | if(!repeat) |
---|
| 727 | if(objEvent.me.id == User.me.id){ |
---|
| 728 | objEvent.me.id = DataLayer.put('participant', {user: objEvent.me.id, mail: objEvent.me.mail}); |
---|
| 729 | objEvent.organizer.id = objEvent.me.id; |
---|
| 730 | } |
---|
| 731 | |
---|
[5514] | 732 | var attendeeHtml = DataLayer.render( path+'templates/attendee_add.ejs', {event:objEvent}); |
---|
[5341] | 733 | |
---|
| 734 | // load template of attendees |
---|
| 735 | var blkAddAtendee = UI.dialogs.addEvent.find('#calendar_addevent_details6').append(attendeeHtml); |
---|
[5514] | 736 | if(objEvent.attendee.length) |
---|
| 737 | callbackAttendee(); |
---|
| 738 | /** |
---|
| 739 | Opções de delegação do participante/organizer |
---|
| 740 | */ |
---|
| 741 | blkAddAtendee.find(".button.participant-delegate").button({ |
---|
| 742 | icons: { |
---|
| 743 | primary: "ui-icon-transferthick-e-w" |
---|
| 744 | }, |
---|
| 745 | text: false |
---|
| 746 | }).click(function () { |
---|
| 747 | if($(this).hasClass('attendee-permissions-change-button')){ |
---|
| 748 | if(!$(this).hasClass('disable')){ |
---|
| 749 | $(this).removeClass('attendee-permissions-change-button') |
---|
| 750 | .find('.ui-icon-transferthick-e-w').removeClass('attendee-permissions-change').end(); |
---|
| 751 | blkAddAtendee.find('.block-add-attendee.search').addClass('hidden'); |
---|
| 752 | blkAddAtendee.find('.block-add-attendee.search dt').html('Adicionar outros contatos'); |
---|
| 753 | } |
---|
| 754 | }else{ |
---|
| 755 | $(this).addClass('attendee-permissions-change-button') |
---|
| 756 | .find('.ui-icon-transferthick-e-w').addClass('attendee-permissions-change').end(); |
---|
| 757 | blkAddAtendee.find('.block-add-attendee.search dt').html('Delegar participação para'); |
---|
| 758 | blkAddAtendee.find('.block-add-attendee.search').removeClass('hidden'); |
---|
| 759 | blkAddAtendee.find('.block-add-attendee.search input.search').focus(); |
---|
| 760 | } |
---|
| 761 | }) |
---|
| 762 | .addClass('tiny'); |
---|
[5341] | 763 | |
---|
| 764 | //show or hidden permissions attendees |
---|
| 765 | //blkAddAtendee.find('.block-attendee-list #attendees-users li').click(show_permissions_attendees); |
---|
| 766 | |
---|
[5354] | 767 | UI.dialogs.addEvent.find(".attendee-list-add .add-attendee-input input").Watermark("digite um email para convidar"); |
---|
[5341] | 768 | /* Trata a edição de um novo participante adicionado |
---|
| 769 | * |
---|
| 770 | */ |
---|
| 771 | var hasNewAttendee = false; |
---|
[5641] | 772 | |
---|
| 773 | blkAddAtendee.find('.attendee-list-add .add-attendee-input span').click(function(data){ |
---|
| 774 | blkAddAtendee.find('.attendee-list-add .add-attendee-input input').keydown(); |
---|
| 775 | }); |
---|
| 776 | |
---|
[5360] | 777 | blkAddAtendee.find('.attendee-list-add .add-attendee-input input').keydown(function(event) { |
---|
[5341] | 778 | |
---|
[5641] | 779 | if (event.keyCode == '13' && $(this).val() != '' || (event.keyCode == undefined && $(this).val() != '')) { |
---|
[5341] | 780 | Encoder.EncodeType = "entity"; |
---|
| 781 | $(this).val(Encoder.htmlEncode($(this).val())); |
---|
| 782 | |
---|
[5353] | 783 | newAttendeeEmail = false; |
---|
[5354] | 784 | newAttendeeName = false; |
---|
| 785 | skipAddNewLine = false; |
---|
[5341] | 786 | |
---|
| 787 | var info = $(this).val(); |
---|
| 788 | |
---|
| 789 | /** |
---|
| 790 | * email válido? |
---|
| 791 | */ |
---|
| 792 | info.match(/^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/) ? |
---|
| 793 | newAttendeeEmail = info : newAttendeeName = info; |
---|
| 794 | |
---|
| 795 | /** |
---|
| 796 | * 1) busca no banco para saber se o usuário já existe |
---|
| 797 | * 1.1) se existe, atualiza as info na lista de participantes e nao abre o tooltip |
---|
| 798 | * 1.2) se não existe |
---|
| 799 | * a) salva como novo usuario externo no banco (apenas com email) |
---|
| 800 | * b) exibe tooltip pedindo o nome |
---|
| 801 | * c) se o usuário preenche tooltip e salva, atualiza com o nome o usuário recém criado |
---|
| 802 | * d) se o usuário cancela o tooltip, fica o usuário salvo apenas com email e sem nome |
---|
| 803 | */ |
---|
| 804 | |
---|
[5636] | 805 | var user = DataLayer.get('user', ["=", "mail", $(this).val()]); |
---|
[5641] | 806 | if(!!user && user[0].id) |
---|
[5746] | 807 | attendees[user[0].id] = {name: user[0].name}; |
---|
[5353] | 808 | |
---|
[5354] | 809 | /** |
---|
| 810 | * guarda o último tooltip aberto referente à lista de participantes |
---|
| 811 | */ |
---|
| 812 | lastEditAttendeeToolTip = []; |
---|
| 813 | |
---|
| 814 | /** |
---|
| 815 | * Valida email e salva um participante externo |
---|
| 816 | */ |
---|
| 817 | var saveContact = function() { |
---|
| 818 | Encoder.EncodeType = "entity"; |
---|
| 819 | |
---|
| 820 | var currentTip = $('.qtip-active'); |
---|
| 821 | newAttendeeName = currentTip.find('input[name="name"]').val(); |
---|
| 822 | newAttendeeEmail = currentTip.find('input[name="mail"]').val(); |
---|
| 823 | |
---|
[5409] | 824 | if (!(!!newAttendeeEmail.match(/^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/))) { |
---|
[5381] | 825 | currentTip.find('.messages').removeClass('hidden').find('.message label').html('Email inválido.'); |
---|
[5354] | 826 | return false; |
---|
| 827 | } |
---|
| 828 | |
---|
[5364] | 829 | DataLayer.put('user', {id:userId, name:newAttendeeName, mail:newAttendeeEmail, isExternal:isExternal}); |
---|
[5354] | 830 | |
---|
[5360] | 831 | lastEditAttendeeToolTip.find('label') |
---|
[5354] | 832 | .filter('.name').html(Encoder.htmlEncode(newAttendeeName)).attr('title', Encoder.htmlEncode(newAttendeeName)).end() |
---|
| 833 | .filter('.mail').html(Encoder.htmlEncode(newAttendeeEmail)).attr('title', Encoder.htmlEncode(newAttendeeEmail)); |
---|
| 834 | |
---|
[5360] | 835 | blkAddAtendee.find('.attendee-list-add .add-attendee-input input').val(''); |
---|
[5354] | 836 | return true; |
---|
| 837 | } |
---|
| 838 | |
---|
| 839 | /** |
---|
| 840 | * Formata e adequa um tootip abert para edição de um participante na lista |
---|
| 841 | */ |
---|
[5353] | 842 | var onShowToolTip = function(arg0) { |
---|
| 843 | $('.qtip-active .button.close').button({ |
---|
| 844 | icons: {primary: "ui-icon-close"}, |
---|
| 845 | text: false |
---|
| 846 | }); |
---|
| 847 | $('.qtip-active .button').button() |
---|
| 848 | .filter('.save').click(function(event, ui) { |
---|
[5409] | 849 | if(saveContact()) |
---|
[5354] | 850 | lastEditAttendeeToolTip.qtip("destroy"); |
---|
[5409] | 851 | else |
---|
[5353] | 852 | return false; |
---|
| 853 | }).end() |
---|
| 854 | .filter('.cancel').click(function(event, ui) { |
---|
[5354] | 855 | lastEditAttendeeToolTip.qtip("destroy"); |
---|
[5353] | 856 | }) |
---|
| 857 | |
---|
| 858 | /** |
---|
| 859 | * Trata o ENTER no campo da tooltip, equivalente a salvar |
---|
| 860 | * o novo convidado. |
---|
| 861 | */ |
---|
| 862 | $('.qtip-active input').keydown(function(event) { |
---|
| 863 | if (event.keyCode == '13') { |
---|
[5409] | 864 | if (saveContact()) |
---|
[5354] | 865 | lastEditAttendeeToolTip.qtip("destroy"); |
---|
[5409] | 866 | |
---|
[5354] | 867 | lastEditAttendeeToolTip.qtip("destroy"); |
---|
[5353] | 868 | event.preventDefault(); |
---|
| 869 | } |
---|
| 870 | }) |
---|
| 871 | .filter('[name="name"]').Watermark("informe o nome do contato").end() |
---|
| 872 | .filter('[name="mail"]').Watermark("informe o email do contato"); |
---|
| 873 | } |
---|
| 874 | |
---|
[5354] | 875 | /** |
---|
| 876 | * Se o email digitado já foi adicionado na lista, |
---|
| 877 | * o usuário deve ser avisado e um botão de edição deve ser exibido |
---|
| 878 | */ |
---|
| 879 | if(blkAddAtendee.find('label.mail[title="' + newAttendeeEmail + '"]').length) { |
---|
[5360] | 880 | hasNewAttendee = false; |
---|
[5354] | 881 | newAttendeeName = blkAddAtendee.find('label.mail[title="' + newAttendeeEmail + '"]').parents('li').find('label.name').attr('title'); |
---|
| 882 | |
---|
| 883 | blkAddAtendee.find('.email-validation').removeClass('hidden') |
---|
[5353] | 884 | .find('.message label').html("O usuário acima já foi adicionado! <a class=\"small button\">Editar</a>") |
---|
| 885 | .find(".button").button().click(function () { |
---|
[5354] | 886 | /** |
---|
| 887 | * Se o usuário optar por editar o participante anteriormente adicionado, |
---|
| 888 | * uma tooltip deve ser aberta para este participante, viabilizando a edição |
---|
| 889 | */ |
---|
| 890 | blkAddAtendee.find("ul.attendee-list").scrollTo('label.mail[title="' + newAttendeeEmail + '"]'); |
---|
| 891 | /** |
---|
| 892 | * Remove tooltip possivelmente existente |
---|
| 893 | */ |
---|
[5360] | 894 | if (lastEditAttendeeToolTip.length && lastEditAttendeeToolTip.data('qtip')) |
---|
[5354] | 895 | lastEditAttendeeToolTip.qtip('destroy'); |
---|
| 896 | |
---|
| 897 | lastEditAttendeeToolTip = blkAddAtendee.find('label.mail[title="' + newAttendeeEmail + '"]').parents('li'); |
---|
| 898 | lastEditAttendeeToolTip.qtip({ |
---|
[5353] | 899 | show: {ready: true, solo: true, when: {event: 'click'}}, |
---|
| 900 | hide: false, |
---|
| 901 | content: { |
---|
[5389] | 902 | text: $('<div></div>').html( DataLayer.render( path+'templates/attendee_quick_edit.ejs', {attendee:{name:newAttendeeName, mail:newAttendeeEmail}} ) ), |
---|
[5353] | 903 | title: { |
---|
| 904 | text:'Detalhes do participante', |
---|
| 905 | button: '<a class="button close" href="#">close</a>' |
---|
| 906 | } |
---|
| 907 | }, |
---|
| 908 | style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}}, |
---|
| 909 | position: { |
---|
| 910 | corner: { |
---|
| 911 | target: 'rightMiddle', |
---|
| 912 | tooltip: 'leftMiddle' |
---|
| 913 | }, |
---|
| 914 | adjust: {x:0, y:0} |
---|
| 915 | } |
---|
| 916 | }); |
---|
[5354] | 917 | lastEditAttendeeToolTip.qtip("api").onShow = onShowToolTip; |
---|
| 918 | }); |
---|
| 919 | skipAddNewLine = true; |
---|
[5360] | 920 | } else { |
---|
| 921 | hasNewAttendee = true; |
---|
| 922 | blkAddAtendee.find('.email-validation').addClass('hidden'); |
---|
[5353] | 923 | } |
---|
| 924 | |
---|
| 925 | |
---|
[5387] | 926 | var isExternal = (!!user && !(!!user.isExternal)) ? 0 : 1; |
---|
[5341] | 927 | |
---|
| 928 | /** |
---|
| 929 | * Remove tooltip possivelmente existente |
---|
| 930 | */ |
---|
[5360] | 931 | if (lastEditAttendeeToolTip.length && lastEditAttendeeToolTip.data('qtip')) |
---|
[5354] | 932 | lastEditAttendeeToolTip.qtip('destroy'); |
---|
[5341] | 933 | |
---|
[5364] | 934 | userId = ''; |
---|
[5341] | 935 | var newAttendeeId = ''; |
---|
| 936 | |
---|
| 937 | if (user){ |
---|
[5354] | 938 | if (!skipAddNewLine) { |
---|
[5592] | 939 | user[0].id = DataLayer.put('participant', {user: user[0].id, isExternal: isExternal, acl: 'r'}); |
---|
| 940 | user[0].acl = objEvent.acl |
---|
| 941 | |
---|
[5354] | 942 | blkAddAtendee.find('dd.attendee-list ul.attendee-list').append( |
---|
[5592] | 943 | DataLayer.render(path+'templates/participants_add_itemlist.ejs', user) |
---|
[5354] | 944 | ) |
---|
| 945 | .scrollTo('max'); |
---|
[5514] | 946 | callbackAttendee(); |
---|
[5354] | 947 | } |
---|
[5349] | 948 | |
---|
[5341] | 949 | $(this).val(''); |
---|
| 950 | |
---|
[5354] | 951 | } else if (!skipAddNewLine) { |
---|
[5341] | 952 | /** |
---|
| 953 | * a) salva como novo usuario externo no banco (apenas com email) e... |
---|
| 954 | * adiciona novo contato externo à lista de convidados |
---|
| 955 | */ |
---|
| 956 | |
---|
[5358] | 957 | userId = DataLayer.put('user', {name: newAttendeeName, mail: newAttendeeEmail, isExternal: isExternal}); |
---|
| 958 | newAttendeeId = DataLayer.put('participant', {user: userId, isExternal: isExternal}); |
---|
[5341] | 959 | |
---|
[5354] | 960 | |
---|
[5341] | 961 | blkAddAtendee.find('dd.attendee-list ul.attendee-list').append( |
---|
[5514] | 962 | DataLayer.render(path+'templates/participants_add_itemlist.ejs', [{id:newAttendeeId, name: newAttendeeName, mail: newAttendeeEmail, isExternal: 1, acl: objEvent.acl}]) |
---|
| 963 | ).scrollTo('max'); |
---|
| 964 | callbackAttendee(); |
---|
[5341] | 965 | |
---|
| 966 | /** |
---|
| 967 | * Adiciona tootip para atualização dos dados do contato externo |
---|
| 968 | * recém adicionado. |
---|
| 969 | */ |
---|
[5354] | 970 | lastEditAttendeeToolTip = blkAddAtendee.find('dd.attendee-list li:last'); |
---|
| 971 | lastEditAttendeeToolTip.qtip({ |
---|
[5341] | 972 | show: {ready: true, solo: true, when: {event: 'click'}}, |
---|
| 973 | hide: false, |
---|
| 974 | content: { |
---|
[5389] | 975 | text: $('<div></div>').html( DataLayer.render( path+'templates/attendee_quick_edit.ejs', {attendee:{name:newAttendeeName, mail:newAttendeeEmail}} ) ), |
---|
[5341] | 976 | title: { |
---|
| 977 | text:'Detalhes do participante', |
---|
| 978 | button: '<a class="button close" href="#">close</a>' |
---|
| 979 | } |
---|
| 980 | }, |
---|
| 981 | style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}}, |
---|
| 982 | position: { |
---|
| 983 | corner: { |
---|
| 984 | target: 'rightMiddle', |
---|
| 985 | tooltip: 'leftMiddle' |
---|
| 986 | }, |
---|
| 987 | adjust: {x:0, y:0} |
---|
| 988 | } |
---|
| 989 | }); |
---|
| 990 | |
---|
[5354] | 991 | lastEditAttendeeToolTip.qtip("api").onShow = onShowToolTip; |
---|
[5341] | 992 | |
---|
[5354] | 993 | $(this).val(''); |
---|
[5341] | 994 | |
---|
[5353] | 995 | |
---|
[5341] | 996 | } |
---|
[5354] | 997 | event.preventDefault(); |
---|
[5341] | 998 | } |
---|
[5354] | 999 | |
---|
[5341] | 1000 | }); |
---|
| 1001 | |
---|
| 1002 | /** |
---|
| 1003 | * Trata a busca de usuários para adição de participantes |
---|
| 1004 | */ |
---|
[5592] | 1005 | blkAddAtendee.find('.add-attendee-search .ui-icon-search').click(function(event) { |
---|
| 1006 | blkAddAtendee.find('.add-attendee-search input').keydown(); |
---|
| 1007 | }); |
---|
| 1008 | |
---|
| 1009 | |
---|
[5341] | 1010 | blkAddAtendee.find('.add-attendee-search input').keydown(function(event) { |
---|
| 1011 | |
---|
[5592] | 1012 | if(event.keyCode == '13' || typeof(event.keyCode) == 'undefined') { |
---|
[5341] | 1013 | var result = DataLayer.get('user', ["*", "name", $(this).val()], true); |
---|
| 1014 | |
---|
| 1015 | /** |
---|
| 1016 | * TODO: trocar por template |
---|
| 1017 | */ |
---|
[5360] | 1018 | blkAddAtendee.find('ul.search-result-list').empty().css('overflow', 'hidden'); |
---|
[5341] | 1019 | if (!result) { |
---|
[5360] | 1020 | blkAddAtendee.find('ul.search-result-list').append('<li><label class="empty">Nenhum resultado encontrado.</label></li>'); |
---|
[5341] | 1021 | } |
---|
| 1022 | |
---|
[5363] | 1023 | for(i=0; i<result.length; i++) |
---|
| 1024 | result[i].enabled = (blkAddAtendee.find('dd.attendee-list ul.attendee-list label.mail[title="' + result[i].mail + '"]').length) ? false : true; |
---|
| 1025 | |
---|
[5389] | 1026 | blkAddAtendee.find('ul.search-result-list').append(DataLayer.render( path+'templates/participants_search_itemlist.ejs', result)); |
---|
[5341] | 1027 | |
---|
[5360] | 1028 | blkAddAtendee.find('ul.search-result-list li').click(function(event, ui){ |
---|
[5341] | 1029 | if ($(event.target).is('input')) { |
---|
| 1030 | old_item = $(event.target).parents('li'); |
---|
[5358] | 1031 | newAttendeeId = DataLayer.put('participant', {user: old_item.find('.id').html(), isExternal: 0}); |
---|
[5636] | 1032 | |
---|
| 1033 | attendees[old_item.find('.id').html()] = old_item.find('.name').html(); |
---|
| 1034 | |
---|
[5341] | 1035 | blkAddAtendee.find('dd.attendee-list ul.attendee-list') |
---|
[5514] | 1036 | .append(DataLayer.render(path+'templates/participants_add_itemlist.ejs', [{id: newAttendeeId, name: old_item.find('.name').html(), mail: old_item.find('.mail').html(), isExternal: 0, acl: objEvent.acl}])) |
---|
[5349] | 1037 | .scrollTo('max'); |
---|
[5514] | 1038 | /** |
---|
| 1039 | * Delegação de participação de um participante com permissão apenas de leitura |
---|
| 1040 | * |
---|
| 1041 | */ |
---|
| 1042 | if(!objEvent.acl.organization && !objEvent.acl.write && !objEvent.acl.inviteGuests && objEvent.acl.read ){ |
---|
| 1043 | |
---|
| 1044 | blkAddAtendee.find('.block-add-attendee.search').addClass('hidden'); |
---|
| 1045 | blkAddAtendee.find('.block-add-attendee.search dt').html('Adicionar outros contatos'); |
---|
| 1046 | |
---|
| 1047 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
| 1048 | blkAddAtendee.find('option[value=5]').attr('selected','selected').trigger('change'); |
---|
| 1049 | blkAddAtendee.find('.request-update').removeClass('hidden'); |
---|
[5341] | 1050 | |
---|
[5514] | 1051 | 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()); |
---|
| 1052 | |
---|
| 1053 | blkAddAtendee.find('.me .participant-delegate').addClass('disable ui-button-disabled ui-state-disabled'); |
---|
| 1054 | blkAddAtendee.find(".button.close").button({ |
---|
| 1055 | icons: { |
---|
| 1056 | primary: "ui-icon-close" |
---|
| 1057 | }, |
---|
| 1058 | text: false |
---|
| 1059 | }).click(function () { |
---|
| 1060 | |
---|
| 1061 | $(this).parents('li').find('input[name="delegatedFrom[]"]').val(''); |
---|
| 1062 | blkAddAtendee.find('.request-update').addClass('hidden'); |
---|
| 1063 | blkAddAtendee.find('.status option').toggleClass('hidden'); |
---|
| 1064 | blkAddAtendee.find('option[value=1]').attr('selected','selected').trigger('change'); |
---|
| 1065 | blkAddAtendee.find('.me .participant-delegate').removeClass('disable ui-button-disabled ui-state-disabled attendee-permissions-change-button') |
---|
| 1066 | .find('.ui-icon-person').removeClass('attendee-permissions-change').end(); |
---|
| 1067 | |
---|
| 1068 | DataLayer.remove('participant', $(this).parents('li').find('[type=checkbox]').val()); |
---|
| 1069 | $(this).parents('li').remove(); |
---|
| 1070 | }) |
---|
| 1071 | .addClass('tiny'); |
---|
| 1072 | }else{ |
---|
| 1073 | callbackAttendee(); |
---|
| 1074 | old_item.remove(); |
---|
| 1075 | } |
---|
[5341] | 1076 | } |
---|
| 1077 | }); |
---|
| 1078 | |
---|
| 1079 | event.preventDefault(); |
---|
| 1080 | } |
---|
| 1081 | }); |
---|
| 1082 | //$('.block-add-attendee .search-result-list').selectable(); |
---|
| 1083 | |
---|
[5514] | 1084 | UI.dialogs.addEvent.find('.row.fileupload-buttonbar .button').filter('.delete').button({ |
---|
| 1085 | icons: { |
---|
| 1086 | primary: "ui-icon-close" |
---|
| 1087 | }, |
---|
| 1088 | text: 'Excluir' |
---|
| 1089 | }).click(function () { |
---|
| 1090 | $('.row.fileupload-buttonbar .attachments-list p').remove(); |
---|
| 1091 | |
---|
| 1092 | var ids = []; |
---|
[5746] | 1093 | $.each($('.attachment-list input'), function (i, input) {ids.push(input.value);}); |
---|
[5514] | 1094 | if(ids.length > 0){ |
---|
| 1095 | DataLayer.remove('attachment', {filter: ['IN', 'id', ids]}); |
---|
| 1096 | $('.attachment-list input').remove(); |
---|
[5341] | 1097 | } |
---|
[5514] | 1098 | }).end() |
---|
| 1099 | .filter('.close').button({ |
---|
| 1100 | icons: { |
---|
| 1101 | primary: "ui-icon-close" |
---|
| 1102 | }, |
---|
| 1103 | text: false |
---|
| 1104 | }).click(function () { |
---|
| 1105 | DataLayer.remove('attachment', $(this).parents('p').find('input[name="fileId[]"]').val()); |
---|
| 1106 | $(this).parents('p').remove(); |
---|
| 1107 | }).end() |
---|
| 1108 | .filter('.downlaod-archive').button({ |
---|
| 1109 | icons: { |
---|
| 1110 | primary: "ui-icon-arrowthickstop-1-s" |
---|
| 1111 | }, |
---|
| 1112 | text: false |
---|
[5381] | 1113 | }); |
---|
[5720] | 1114 | var maxSizeFile = 2000000; |
---|
[5514] | 1115 | $('#fileupload').fileupload({ |
---|
| 1116 | sequentialUploads: true, |
---|
| 1117 | add: function (e, data) { |
---|
[5720] | 1118 | if(data.files[0].size < maxSizeFile) |
---|
[5514] | 1119 | data.submit(); |
---|
| 1120 | }, |
---|
| 1121 | change: function (e, data) { |
---|
| 1122 | $.each(data.files, function (index, file) { |
---|
| 1123 | var attach = {}; |
---|
| 1124 | attach.fileName = file.name; |
---|
[5720] | 1125 | var ext = file.name.split('.'); |
---|
[5514] | 1126 | if(file.name.length > 10) |
---|
[5720] | 1127 | attach.fileName = ext.length == 1 ? file.name.substr(0, 10) : file.name.substr(0, 6) + '.' + ext[ext.length -1]; |
---|
[5515] | 1128 | attach.fileSize = formatBytes(file.size); |
---|
[5720] | 1129 | if(file.size > maxSizeFile) |
---|
[5514] | 1130 | attach.error = 'Tamanho de arquivo nao permitido!!' |
---|
| 1131 | |
---|
| 1132 | $('.attachments-list').append(DataLayer.render(path+'templates/attachment_add_itemlist.ejs', {file : attach})); |
---|
| 1133 | |
---|
[5720] | 1134 | if(file.size < maxSizeFile){ |
---|
[5514] | 1135 | $('.fileinput-button.new').append(data.fileInput[0]).removeClass('new'); |
---|
| 1136 | $('.attachments-list').find('[type=file]').addClass('hidden'); |
---|
| 1137 | |
---|
| 1138 | }else |
---|
| 1139 | $('.fileinput-button.new').removeClass('new'); |
---|
| 1140 | |
---|
| 1141 | |
---|
| 1142 | $('.attachments-list').find('.button.close').button({ |
---|
| 1143 | icons: { |
---|
| 1144 | primary: "ui-icon-close" |
---|
| 1145 | }, |
---|
| 1146 | text: false |
---|
| 1147 | }).click(function(){ |
---|
| 1148 | var idAttach = $(this).parent().find('input[name="fileId[]"]').val(); |
---|
| 1149 | $('.attachment-list').find('input[value="'+idAttach+'"]') |
---|
| 1150 | $(this).parent().remove(); |
---|
| 1151 | }); |
---|
| 1152 | |
---|
| 1153 | })}, |
---|
| 1154 | progress: function(e, data){ |
---|
| 1155 | var value = parseInt(data.loaded / data.total * 100, 10); |
---|
| 1156 | $('.progress.in-progress:first').removeClass('hidden') |
---|
| 1157 | $('.progress.in-progress:first').progressbar({ |
---|
| 1158 | value: value |
---|
| 1159 | }); |
---|
| 1160 | |
---|
| 1161 | if(value == 100){ |
---|
| 1162 | $('.progress.in-progress:first').removeClass('in-progress').addClass('on-complete').fadeOut('slow'); |
---|
| 1163 | } |
---|
| 1164 | |
---|
| 1165 | }, |
---|
| 1166 | done: function(e, data){ |
---|
| 1167 | if(!!data.result && data.result != "[]"){ |
---|
| 1168 | var newAttach = jQuery.parseJSON(data.result); |
---|
| 1169 | $('.attachment-list').append('<input tyepe="hidden" name="attachment[]" value="'+newAttach['attachment'][0][0].id+'"/>'); |
---|
| 1170 | $('.progress.on-complete:first').removeClass('on-complete').parents('p') |
---|
| 1171 | .append('<input type="hidden" name="fileId[]" value="'+newAttach['attachment'][0][0].id+'"/>') |
---|
| 1172 | .find('.status-upload').addClass('ui-icon ui-icon-check'); |
---|
| 1173 | }else |
---|
| 1174 | $('.progress.on-complete:first').removeClass('on-complete').parents('p').find('.status-upload').addClass('ui-icon ui-icon-cancel'); |
---|
| 1175 | } |
---|
| 1176 | }); |
---|
[5515] | 1177 | $('.attachments-list .button').button(); |
---|
| 1178 | |
---|
[5514] | 1179 | $('#fileupload').bind('fileuploadstart', function () { |
---|
| 1180 | var widget = $(this), |
---|
| 1181 | progressElement = $('#fileupload-progress').fadeIn(), |
---|
| 1182 | interval = 500, |
---|
| 1183 | total = 0, |
---|
| 1184 | loaded = 0, |
---|
| 1185 | loadedBefore = 0, |
---|
| 1186 | progressTimer, |
---|
| 1187 | progressHandler = function (e, data) { |
---|
| 1188 | loaded = data.loaded; |
---|
| 1189 | total = data.total; |
---|
| 1190 | }, |
---|
| 1191 | stopHandler = function () { |
---|
| 1192 | widget |
---|
| 1193 | .unbind('fileuploadprogressall', progressHandler) |
---|
| 1194 | .unbind('fileuploadstop', stopHandler); |
---|
| 1195 | window.clearInterval(progressTimer); |
---|
| 1196 | progressElement.fadeOut(function () { |
---|
| 1197 | progressElement.html(''); |
---|
| 1198 | }); |
---|
| 1199 | }, |
---|
| 1200 | formatTime = function (seconds) { |
---|
| 1201 | var date = new Date(seconds * 1000); |
---|
| 1202 | return ('0' + date.getUTCHours()).slice(-2) + ':' + |
---|
| 1203 | ('0' + date.getUTCMinutes()).slice(-2) + ':' + |
---|
| 1204 | ('0' + date.getUTCSeconds()).slice(-2); |
---|
| 1205 | }, |
---|
[5515] | 1206 | /* formatBytes = function (bytes) { |
---|
[5514] | 1207 | if (bytes >= 1000000000) { |
---|
| 1208 | return (bytes / 1000000000).toFixed(2) + ' GB'; |
---|
| 1209 | } |
---|
| 1210 | if (bytes >= 1000000) { |
---|
| 1211 | return (bytes / 1000000).toFixed(2) + ' MB'; |
---|
| 1212 | } |
---|
| 1213 | if (bytes >= 1000) { |
---|
| 1214 | return (bytes / 1000).toFixed(2) + ' KB'; |
---|
| 1215 | } |
---|
| 1216 | return bytes + ' B'; |
---|
[5515] | 1217 | },*/ |
---|
[5514] | 1218 | formatPercentage = function (floatValue) { |
---|
| 1219 | return (floatValue * 100).toFixed(2) + ' %'; |
---|
| 1220 | }, |
---|
| 1221 | updateProgressElement = function (loaded, total, bps) { |
---|
| 1222 | progressElement.html( |
---|
| 1223 | formatBytes(bps) + 'ps | ' + |
---|
| 1224 | formatTime((total - loaded) / bps) + ' | ' + |
---|
| 1225 | formatPercentage(loaded / total) + ' | ' + |
---|
| 1226 | formatBytes(loaded) + ' / ' + formatBytes(total) |
---|
| 1227 | ); |
---|
| 1228 | }, |
---|
| 1229 | intervalHandler = function () { |
---|
| 1230 | var diff = loaded - loadedBefore; |
---|
| 1231 | if (!diff) { |
---|
| 1232 | return; |
---|
| 1233 | } |
---|
| 1234 | loadedBefore = loaded; |
---|
| 1235 | updateProgressElement( |
---|
| 1236 | loaded, |
---|
| 1237 | total, |
---|
| 1238 | diff * (1000 / interval) |
---|
| 1239 | ); |
---|
| 1240 | }; |
---|
| 1241 | widget |
---|
| 1242 | .bind('fileuploadprogressall', progressHandler) |
---|
| 1243 | .bind('fileuploadstop', stopHandler); |
---|
| 1244 | progressTimer = window.setInterval(intervalHandler, interval); |
---|
| 1245 | }); |
---|
[5592] | 1246 | |
---|
| 1247 | if(objEvent.isShared){ |
---|
[5514] | 1248 | |
---|
[5592] | 1249 | var acls = Calendar.signatureOf[objEvent.calendar].permission.acl; |
---|
[5514] | 1250 | |
---|
[5592] | 1251 | if(!acls.write){ |
---|
| 1252 | UI.dialogs.addEvent.find(':input').attr('disabled', 'disabled'); |
---|
| 1253 | UI.dialogs.addEvent.find('.button').hide(); |
---|
| 1254 | } |
---|
| 1255 | |
---|
| 1256 | if(acls.remove) |
---|
| 1257 | UI.dialogs.addEvent.find('.button.remove').show(); |
---|
| 1258 | |
---|
| 1259 | UI.dialogs.addEvent.find('.button.cancel').show(); |
---|
| 1260 | |
---|
| 1261 | |
---|
| 1262 | } |
---|
[5636] | 1263 | |
---|
| 1264 | disponibily(objEvent, path, attendees); |
---|
| 1265 | |
---|
| 1266 | UI.dialogs.addEvent.find(':input').change(function(event){ |
---|
| 1267 | if (event.keyCode != '27' && event.keyCode != '13') |
---|
| 1268 | canDiscardEventDialog = false; |
---|
| 1269 | }).keydown(function(event){ |
---|
| 1270 | if (event.keyCode != '27' && event.keyCode != '13') |
---|
| 1271 | canDiscardEventDialog = false; |
---|
| 1272 | }); |
---|
| 1273 | |
---|
[5592] | 1274 | UI.dialogs.addEvent.dialog('open'); |
---|
[5636] | 1275 | //$('[href="#calendar_addevent_details7"]').trigger('click'); |
---|
| 1276 | //$('[href="#calendar_addevent_details2"]').trigger('click'); |
---|
[5341] | 1277 | } |
---|
| 1278 | |
---|
[5353] | 1279 | |
---|
| 1280 | |
---|
[5341] | 1281 | function add_tab_preferences() |
---|
| 1282 | { |
---|
| 1283 | if(!(document.getElementById('preference_tab'))) |
---|
| 1284 | { |
---|
| 1285 | var tab_title = "Preferencias"; |
---|
| 1286 | $tabs.tabs( "add", "#preference_tab", tab_title ); |
---|
| 1287 | |
---|
| 1288 | /* |
---|
| 1289 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
| 1290 | tabPrefCalendar.find('select[name="timezone"]').html(timezones_options).find('option[value="'+User.preferences.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
| 1291 | }); |
---|
| 1292 | */ |
---|
| 1293 | DataLayer.render( 'templates/preferences_calendar.ejs', {preferences:User.preferences, calendars: Calendar.calendars}, function( template ){ |
---|
| 1294 | var tabPrefCalendar = jQuery('#preference_tab').html( template ).find('.preferences-win'); |
---|
| 1295 | |
---|
| 1296 | tabPrefCalendar.find('option[value="'+User.preferences.defaultCalendar+'"]').attr('selected','selected').trigger('change'); |
---|
| 1297 | |
---|
| 1298 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
| 1299 | tabPrefCalendar.find('select[name="timezone"]').html(timezones_options).find('option[value="'+User.preferences.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
| 1300 | }); |
---|
| 1301 | |
---|
| 1302 | tabPrefCalendar.find('.button').button() |
---|
| 1303 | .filter('.save').click(function(evt){ |
---|
| 1304 | tabPrefCalendar.find('form').submit(); |
---|
| 1305 | $('#calendar').fullCalendar('render'); |
---|
| 1306 | $('.block-vertical-toolbox .mini-calendar').datepicker( "refresh" ); |
---|
| 1307 | $tabs.tabs( "remove", "#preference_tab"); |
---|
| 1308 | }).end().filter('.cancel').click(function(evt){ |
---|
| 1309 | $tabs.tabs( "remove", "#preference_tab"); |
---|
| 1310 | }); |
---|
| 1311 | |
---|
| 1312 | tabPrefCalendar.find('.number').numeric(); |
---|
[5510] | 1313 | |
---|
| 1314 | tabPrefCalendar.find('input.time').timepicker({ |
---|
| 1315 | closeText: 'Ok', |
---|
| 1316 | hourGrid: 4, |
---|
| 1317 | minuteGrid: 10, |
---|
| 1318 | ampm : (parseInt($("select[name=hourFormat] option:selected").val().length) > 5 ? true : false), //((User.preferences.hourFormat.length > 5) ? true: false), |
---|
| 1319 | timeFormat: "hh:mm tt", |
---|
| 1320 | onSelect: function (selectedDateTime){ |
---|
| 1321 | if(!(User.preferences.hourFormat.length == 5)) { |
---|
| 1322 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
| 1323 | } |
---|
| 1324 | }, |
---|
| 1325 | onClose : function (selectedDateTime){ |
---|
| 1326 | if(!(User.preferences.hourFormat.length == 5)) { |
---|
| 1327 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
| 1328 | } |
---|
| 1329 | } |
---|
| 1330 | }); |
---|
| 1331 | |
---|
| 1332 | $.mask.definitions['{']='[ap]'; |
---|
| 1333 | $.mask.definitions['}']='[m]'; |
---|
| 1334 | tabPrefCalendar.find("input.time").mask( ((User.preferences.hourFormat.length > 5) ? "99:99 {}" : "99:99"), { |
---|
| 1335 | completed:function(){ |
---|
| 1336 | $(this).val(dateCalendar.defaultToAmPm($(this).val())); |
---|
| 1337 | $(this).timepicker("refresh"); |
---|
| 1338 | $(this).val($(this).val().replace(/[\.]/gi, "")); |
---|
| 1339 | } |
---|
| 1340 | }); |
---|
| 1341 | |
---|
| 1342 | tabPrefCalendar.find("select[name=hourFormat]").change( function() { // evento ao selecionar formato de hora |
---|
| 1343 | |
---|
| 1344 | tabPrefCalendar.find("input.time").timepicker("destroy"); |
---|
| 1345 | |
---|
| 1346 | tabPrefCalendar.find('input.time').timepicker({ |
---|
| 1347 | closeText: 'Ok', |
---|
| 1348 | hourGrid: 4, |
---|
| 1349 | minuteGrid: 10, |
---|
| 1350 | ampm : (parseInt($("select[name=hourFormat] option:selected").val().length) > 5 ? true : false), |
---|
| 1351 | timeFormat: "hh:mm tt", |
---|
| 1352 | onSelect: function (selectedDateTime){ |
---|
| 1353 | if(!(User.preferences.hourFormat.length == 5)) { |
---|
| 1354 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
| 1355 | } |
---|
| 1356 | }, |
---|
| 1357 | onClose : function (selectedDateTime){ |
---|
| 1358 | if(!(User.preferences.hourFormat.length == 5)) { |
---|
| 1359 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
| 1360 | } |
---|
| 1361 | } |
---|
| 1362 | }); |
---|
| 1363 | |
---|
| 1364 | var defaultStartHour = tabPrefCalendar.find("input[name=defaultStartHour]").val().trim(); |
---|
| 1365 | var defaultEndHour = tabPrefCalendar.find("input[name=defaultEndHour]").val().trim(); |
---|
| 1366 | |
---|
| 1367 | tabPrefCalendar.find("input.time").mask( (($("select[name=hourFormat] option:selected").val().trim().length > 5) ? "99:99 {}" : "99:99") ); |
---|
| 1368 | |
---|
| 1369 | if (parseInt($("select[name=hourFormat] option:selected").val().length) > 5) { // am/pm |
---|
| 1370 | tabPrefCalendar.find("input[name=defaultStartHour]").val(dateCalendar.defaultToAmPm(defaultStartHour)); |
---|
| 1371 | tabPrefCalendar.find("input[name=defaultEndHour]").val(dateCalendar.defaultToAmPm(defaultEndHour)) |
---|
| 1372 | |
---|
| 1373 | } else { //24h |
---|
| 1374 | tabPrefCalendar.find("input[name=defaultStartHour]").val(dateCalendar.AmPmTo24(defaultStartHour)); |
---|
| 1375 | tabPrefCalendar.find("input[name=defaultEndHour]").val(dateCalendar.AmPmTo24(defaultEndHour)); |
---|
| 1376 | } |
---|
| 1377 | }); |
---|
| 1378 | |
---|
| 1379 | |
---|
| 1380 | |
---|
[5341] | 1381 | }); |
---|
| 1382 | } else { |
---|
| 1383 | $tabs.tabs("select", "#preference_tab"); |
---|
| 1384 | |
---|
| 1385 | return true; |
---|
| 1386 | } |
---|
| 1387 | } |
---|
| 1388 | |
---|
| 1389 | |
---|
| 1390 | function add_tab_configure_calendar(calendar) |
---|
| 1391 | { |
---|
| 1392 | var calendars = []; |
---|
| 1393 | var signatures = []; |
---|
| 1394 | var previewActiveCalendarConf = 0; |
---|
| 1395 | |
---|
| 1396 | for (var i=0; i<Calendar.signatures.length; i++) { |
---|
| 1397 | calendars[i] = Calendar.signatures[i].calendar; |
---|
| 1398 | signatures[i] = Calendar.signatures[i]; |
---|
| 1399 | signatures[i].numberDefaultAlarm = signatures[i].defaultAlarms != '' ? signatures[i].defaultAlarms.length: 0; |
---|
| 1400 | if (calendar && calendars[i].id == calendar) |
---|
| 1401 | previewActiveCalendarConf = i; |
---|
| 1402 | } |
---|
| 1403 | |
---|
| 1404 | if(!(document.getElementById('configure_tab'))) |
---|
| 1405 | { |
---|
| 1406 | $('.positionHelper').css('display', 'none'); |
---|
| 1407 | var tab_title = "Configurações de agendas"; |
---|
| 1408 | $tabs.tabs( "add", "#configure_tab", tab_title ); |
---|
| 1409 | |
---|
| 1410 | var dataColorPicker = { |
---|
| 1411 | colorsSuggestions: colors_suggestions() |
---|
| 1412 | }; |
---|
| 1413 | |
---|
| 1414 | |
---|
| 1415 | |
---|
| 1416 | var populateAccordionOnActive = function(event, ui) { |
---|
| 1417 | var nowActive = (typeof(event) == 'number') ? event : $(event.target).accordion( "option", "active" ); |
---|
| 1418 | dataColorPicker.colorsDefined = { |
---|
| 1419 | border: '#'+signatures[nowActive].borderColor, |
---|
| 1420 | font:'#'+signatures[nowActive].fontColor, |
---|
| 1421 | background:'#'+signatures[nowActive].backgroundColor |
---|
| 1422 | }; |
---|
| 1423 | if (!jQuery('.accordion-user-calendars .ui-accordion-content').eq(nowActive).has('form')) { |
---|
| 1424 | return true; |
---|
| 1425 | } |
---|
| 1426 | |
---|
| 1427 | DataLayer.render( 'templates/configure_calendars_itemlist.ejs', {user:User, calendar:calendars[nowActive], signature:signatures[nowActive]}, function( form_template ){ |
---|
| 1428 | var form_content = jQuery('.accordion-user-calendars .ui-accordion-content').eq(nowActive).html( form_template ).find('form'); |
---|
| 1429 | form_content.find('.preferences-alarms-list .button').button({text:false, icons:{primary:'ui-icon-close'}}); |
---|
| 1430 | form_content.find('.button').button(); |
---|
| 1431 | |
---|
| 1432 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
| 1433 | var valueTimeZone = calendars[nowActive].timezone; |
---|
| 1434 | form_content.find('select[name="timezone"]').html(timezones_options).find('option[value="'+valueTimeZone+'"]').attr('selected','selected').trigger('change'); |
---|
| 1435 | }); |
---|
| 1436 | |
---|
| 1437 | form_content.find('.button-add-alarms').click(function(){ |
---|
[5376] | 1438 | DataLayer.render( 'templates/alarms_add_itemlist.ejs', {}, function( template ){ |
---|
[5341] | 1439 | jQuery('.preferences-alarms-list').append(template) |
---|
| 1440 | .find('li:last label:eq(0)').remove().end() |
---|
| 1441 | .find('.number').numeric().end() |
---|
| 1442 | .find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
| 1443 | $(this).parent().remove(); |
---|
| 1444 | }); |
---|
| 1445 | }); |
---|
| 1446 | }); |
---|
| 1447 | |
---|
| 1448 | |
---|
| 1449 | /** |
---|
| 1450 | * Set color picker |
---|
| 1451 | */ |
---|
| 1452 | DataLayer.render( 'templates/calendar_colorpicker.ejs', dataColorPicker, function( template ){ |
---|
| 1453 | form_content.find('.calendar-colorpicker').html( template ); |
---|
| 1454 | |
---|
| 1455 | var f = $.farbtastic(form_content.find('.colorpicker'), colorpickerPreviewChange); |
---|
| 1456 | var selected; |
---|
| 1457 | var colorpicker = form_content.find('.calendar-colorpicker'); |
---|
| 1458 | |
---|
| 1459 | var colorpickerPreviewChange = function(color) { |
---|
| 1460 | var pickedup = form_content.find('.colorwell-selected').val(color).css('background-color', color); |
---|
| 1461 | |
---|
| 1462 | var colorpicker = form_content.find('.calendar-colorpicker'); |
---|
| 1463 | |
---|
| 1464 | if (pickedup.is('input[name="backgroundColor"]')) { |
---|
| 1465 | colorpicker.find('.fc-event-skin').css('background-color',color); |
---|
| 1466 | } else if (pickedup.is('input[name="fontColor"]')) { |
---|
| 1467 | colorpicker.find('.fc-event-skin').css('color',color); |
---|
| 1468 | } else if (pickedup.is('input[name="borderColor"]')) { |
---|
| 1469 | colorpicker.find('.fc-event-skin').css('border-color',color); |
---|
| 1470 | } |
---|
| 1471 | } |
---|
| 1472 | |
---|
| 1473 | form_content.find('.colorwell').each(function () { |
---|
| 1474 | f.linkTo(this); |
---|
| 1475 | |
---|
| 1476 | if ($(this).is('input[name="backgroundColor"]')) { |
---|
| 1477 | colorpicker.find('.fc-event-skin').css('background-color', $(this).val()); |
---|
| 1478 | } else if ($(this).is('input[name="fontColor"]')) { |
---|
| 1479 | colorpicker.find('.fc-event-skin').css('color', $(this).val()); |
---|
| 1480 | } else if ($(this).is('input[name="borderColor"]')) { |
---|
| 1481 | colorpicker.find('.fc-event-skin').css('border-color', $(this).val()); |
---|
| 1482 | } |
---|
| 1483 | }) |
---|
| 1484 | .focus(function() { |
---|
| 1485 | if (selected) { |
---|
| 1486 | $(selected).removeClass('colorwell-selected'); |
---|
| 1487 | } |
---|
| 1488 | |
---|
| 1489 | $(selected = this).addClass('colorwell-selected'); |
---|
| 1490 | f.linkTo(this, colorpickerPreviewChange); |
---|
| 1491 | f.linkTo(colorpickerPreviewChange); |
---|
| 1492 | |
---|
| 1493 | }); |
---|
| 1494 | |
---|
| 1495 | form_content.find('select.color-suggestions').change(function() { |
---|
| 1496 | var colors; |
---|
| 1497 | |
---|
| 1498 | if(colors = dataColorPicker.colorsSuggestions[$(this).val()]) { |
---|
| 1499 | colorpicker |
---|
| 1500 | .find('input[name="fontColor"]').val(colors.font).focus().end() |
---|
| 1501 | .find('input[name="backgroundColor"]').val(colors.background).focus().end() |
---|
| 1502 | .find('input[name="borderColor"]').val(colors.border).focus().end() |
---|
| 1503 | |
---|
| 1504 | .find('.fc-event-skin').css({ |
---|
| 1505 | 'background-color':dataColorPicker.colorsSuggestions[$(this).val()].background, |
---|
| 1506 | 'border-color':dataColorPicker.colorsSuggestions[$(this).val()].border, |
---|
| 1507 | 'color':dataColorPicker.colorsSuggestions[$(this).val()].font |
---|
| 1508 | }); |
---|
| 1509 | } |
---|
| 1510 | }); |
---|
| 1511 | |
---|
| 1512 | /** |
---|
| 1513 | * Trata a mudança dos valores dos campos de cores. |
---|
| 1514 | * Se mudar um conjunto de cores sugerido, |
---|
| 1515 | * este vira um conjunto de cores personalizado. |
---|
| 1516 | */ |
---|
| 1517 | form_content.find('.colorwell').change(function (element, ui) { |
---|
| 1518 | if (true) { |
---|
| 1519 | form_content.find('select.color-suggestions') |
---|
| 1520 | .find('option:selected').removeAttr('selected').end() |
---|
| 1521 | .find('option[value="custom"]').attr('selected', 'selected').trigger('change'); |
---|
| 1522 | } |
---|
| 1523 | }); |
---|
| 1524 | }); //END set colorpicker |
---|
| 1525 | |
---|
| 1526 | form_content.find('.phone').mask("+99 (99) 9999-9999"); |
---|
| 1527 | form_content.find('.number').numeric(); |
---|
| 1528 | |
---|
| 1529 | }); //END DataLayer.render( 'templates/configure_calendars_itemlist.ejs' ... |
---|
| 1530 | |
---|
| 1531 | // === validations preferences ==== |
---|
| 1532 | |
---|
| 1533 | |
---|
| 1534 | } //END populateAccordionOnActive(event, ui) |
---|
| 1535 | |
---|
| 1536 | |
---|
| 1537 | DataLayer.render( 'templates/configure_calendars.ejs', {user:User, calendars:calendars, signatures:signatures}, function( template ){ |
---|
| 1538 | var template_content = jQuery('#configure_tab').html( template ).find('.configure-calendars-win'); |
---|
| 1539 | template_content.find('.button').button().filter('.save').click(function(evt){ |
---|
| 1540 | template_content.find('form').submit(); |
---|
| 1541 | $tabs.tabs( "remove", "#configure_tab"); |
---|
[5615] | 1542 | DataLayer.commit( false, false, function( received ){ |
---|
| 1543 | delete Calendar.currentViewKey; |
---|
| 1544 | Calendar.load(); |
---|
| 1545 | refresh_calendars(); |
---|
| 1546 | }); |
---|
[5341] | 1547 | }).end().filter('.cancel').click(function(evt){ |
---|
| 1548 | $tabs.tabs( "remove", "#configure_tab"); |
---|
| 1549 | }); |
---|
| 1550 | |
---|
| 1551 | /** |
---|
| 1552 | * Muda a estrutura do template para a aplicação do plugin accordion |
---|
| 1553 | */ |
---|
| 1554 | template_content.find('.header-menu-container').after('<div class="accordion-user-calendars"></div>').end().find('.accordion-user-calendars') |
---|
| 1555 | .append(template_content.children('fieldset')); |
---|
| 1556 | |
---|
| 1557 | template_content.find('.accordion-user-calendars').children('fieldset').each(function(index) { |
---|
| 1558 | $(this).before($('<h3></h3>').html($(this).children('legend'))); |
---|
| 1559 | }); |
---|
| 1560 | |
---|
| 1561 | template_content.find('.accordion-user-calendars').accordion({ |
---|
| 1562 | autoHeight: false, |
---|
| 1563 | collapsible: true, |
---|
| 1564 | clearStyle: true, |
---|
| 1565 | active: previewActiveCalendarConf, |
---|
| 1566 | changestart: populateAccordionOnActive |
---|
| 1567 | }); |
---|
| 1568 | populateAccordionOnActive(previewActiveCalendarConf); |
---|
| 1569 | }); |
---|
| 1570 | |
---|
| 1571 | } else { |
---|
| 1572 | |
---|
| 1573 | $tabs.tabs("select", "#configure_tab"); |
---|
| 1574 | $('.accordion-user-calendars').accordion( "activate" , previewActiveCalendarConf ); |
---|
| 1575 | |
---|
| 1576 | return true; |
---|
| 1577 | } |
---|
| 1578 | |
---|
| 1579 | } |
---|
| 1580 | |
---|
[5409] | 1581 | function getSelectedCalendars( reverse ){ |
---|
[5341] | 1582 | var selecteds = {}; |
---|
| 1583 | var cont = 0; |
---|
| 1584 | jQuery(function() { |
---|
| 1585 | jQuery(".my-calendars .calendar-view").each(function(i, obj) { |
---|
| 1586 | var check_box = obj; |
---|
[5409] | 1587 | if( reverse ? !check_box.checked : check_box.checked ) { |
---|
[5341] | 1588 | selecteds[cont] = obj.value; |
---|
| 1589 | cont++; |
---|
| 1590 | }; |
---|
| 1591 | }); |
---|
| 1592 | }); |
---|
| 1593 | if (!cont) |
---|
| 1594 | return false; |
---|
| 1595 | |
---|
| 1596 | selecteds.length = cont; |
---|
| 1597 | return $.makeArray( selecteds ); |
---|
| 1598 | } |
---|
| 1599 | |
---|
| 1600 | /** |
---|
| 1601 | * TODO - transformar em preferência do módulo e criar telas de adição e exclusão de conjunto de cores |
---|
| 1602 | */ |
---|
| 1603 | function colors_suggestions(){ |
---|
| 1604 | return [ |
---|
| 1605 | {name:'Padrão', border:'#3366cc', font:'#ffffff', background:'#3366cc'}, |
---|
| 1606 | {name:'Coala', border:'#123456', font:'#ffffff', background:'#385c80'}, |
---|
| 1607 | {name:'Tomate', border:'#d5130b', font:'#111111', background:'#e36d76'}, |
---|
| 1608 | {name:'Limão', border:'#32ed21', font:'#1f3f1c', background:'#b2f1ac'}, |
---|
| 1609 | {name:'Alto contraste', border:'#000000', font:'#ffffff', background:'#222222'} |
---|
| 1610 | ] |
---|
| 1611 | } |
---|
| 1612 | |
---|
[5592] | 1613 | function remove_event(eventId){ |
---|
| 1614 | $.Zebra_Dialog('Tem certeza que deseja excluir o evento?', { |
---|
| 1615 | 'type': 'question', |
---|
| 1616 | 'overlay_opacity': '0.5', |
---|
| 1617 | 'buttons': ['Sim', 'Não'], |
---|
| 1618 | 'onClose': function(clicked) { |
---|
| 1619 | if(clicked == 'Sim'){ |
---|
| 1620 | DataLayer.remove('schedulable', ''+eventId); |
---|
[5746] | 1621 | DataLayer.commit(); |
---|
[5592] | 1622 | } |
---|
| 1623 | } |
---|
| 1624 | }); |
---|
| 1625 | } |
---|
| 1626 | |
---|
[5746] | 1627 | function mount_exception(eventID, idException){ |
---|
| 1628 | |
---|
| 1629 | var schedulable = DataLayer.get('schedulable', ''+eventID); |
---|
| 1630 | var edit = {repeat: (DataLayer.get('repeat', schedulable.repeat))}; |
---|
[5592] | 1631 | |
---|
[5746] | 1632 | edit.repeat.startTime = new Date(parseInt(edit.repeat.startTime)).toString('yyyy-MM-dd HH:mm:00'); |
---|
[5752] | 1633 | edit.repeat.endTime = parseInt(edit.repeat.count) > 0 ? '0' : new Date(parseInt(edit.repeat.endTime)).toString('yyyy-MM-dd HH:mm:00'); |
---|
[5746] | 1634 | |
---|
| 1635 | edit.repeat.exceptions = (schedulable.occurrences[idException]); |
---|
| 1636 | |
---|
| 1637 | return edit.repeat; |
---|
| 1638 | |
---|
| 1639 | } |
---|
| 1640 | |
---|
| 1641 | function remove_ocurrence(eventId, idRecurrence){ |
---|
| 1642 | $.Zebra_Dialog('Tem certeza que deseja excluir esta ocorrência?', { |
---|
| 1643 | 'type': 'question', |
---|
| 1644 | 'overlay_opacity': '0.5', |
---|
| 1645 | 'buttons': ['Sim', 'Não'], |
---|
| 1646 | 'onClose': function(clicked) { |
---|
| 1647 | if(clicked == 'Sim'){ |
---|
| 1648 | var repeat = mount_exception(eventId, idRecurrence); |
---|
| 1649 | DataLayer.remove('repeat', false); |
---|
| 1650 | DataLayer.put('repeat', repeat); |
---|
| 1651 | DataLayer.commit(false, false, function(data){ |
---|
| 1652 | Calendar.rerenderView(true); |
---|
| 1653 | }); |
---|
| 1654 | } |
---|
| 1655 | } |
---|
| 1656 | }); |
---|
| 1657 | } |
---|
| 1658 | |
---|
| 1659 | |
---|
[5341] | 1660 | function remove_calendar(){ |
---|
| 1661 | /* Pode ser assim $('.cal-list-options-btn.ui-state-active').attr('class').replace(/[a-zA-Z-]+/g, ''); */ |
---|
[5381] | 1662 | $.Zebra_Dialog('Todos os eventos desta agenda serão removidos. Deseja prosseguir com a operação?', { |
---|
[5341] | 1663 | 'type': 'question', |
---|
| 1664 | 'overlay_opacity': '0.5', |
---|
| 1665 | 'buttons': ['Sim', 'Não'], |
---|
| 1666 | 'onClose': function(clicked) { |
---|
| 1667 | if(clicked == 'Sim'){ |
---|
| 1668 | var idCalendar = $('.cal-list-options-btn.ui-state-active').attr('class').match(/[0-9]+/g); |
---|
[5592] | 1669 | |
---|
| 1670 | DataLayer.remove('calendarSignature', Calendar.signatureOf[idCalendar[0]].id ); |
---|
| 1671 | |
---|
[5384] | 1672 | if(idCalendar == User.preferences.defaultCalendar) |
---|
| 1673 | DataLayer.remove( 'modulePreference', User.preferenceIds['defaultCalendar']); |
---|
[5636] | 1674 | |
---|
[5615] | 1675 | DataLayer.commit( false, false, function( received ){ |
---|
| 1676 | delete Calendar.currentViewKey; |
---|
| 1677 | Calendar.load(); |
---|
| 1678 | refresh_calendars(); |
---|
| 1679 | }); |
---|
[5409] | 1680 | } |
---|
[5341] | 1681 | $('.positionHelper').css('display', 'none'); |
---|
[5409] | 1682 | |
---|
[5341] | 1683 | } |
---|
| 1684 | }); |
---|
| 1685 | } |
---|
| 1686 | |
---|
| 1687 | function refresh_calendars(){ |
---|
| 1688 | |
---|
| 1689 | var colorsSuggestions = colors_suggestions(); |
---|
| 1690 | var buttons_colors = ""; |
---|
| 1691 | for(var i = 0; i < colorsSuggestions.length; i++){ |
---|
| 1692 | 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>"; |
---|
| 1693 | } |
---|
| 1694 | |
---|
| 1695 | //DataLayer.render( 'templates/calendar_list.ejs', 'calendar:list', ["IN", "id", Calendar.calendarIds], function( html ){ |
---|
| 1696 | DataLayer.render( 'templates/calendar_list.ejs', Calendar, function( html ){ |
---|
| 1697 | |
---|
| 1698 | var meu_container = $(".calendars-list").html( html ); |
---|
| 1699 | |
---|
| 1700 | $('ul.list-calendars .cal-list-options-btn').each(function(){ |
---|
| 1701 | $(this).menu({ |
---|
| 1702 | content: $(this).next().html(), |
---|
| 1703 | width: '120', |
---|
| 1704 | positionOpts: { |
---|
| 1705 | posX: 'left', |
---|
| 1706 | posY: 'bottom', |
---|
| 1707 | offsetX: 0, |
---|
| 1708 | offsetY: 0, |
---|
| 1709 | directionH: 'right', |
---|
| 1710 | directionV: 'down', |
---|
| 1711 | detectH: true, // do horizontal collision detection |
---|
| 1712 | detectV: true, // do vertical collision detection |
---|
| 1713 | linkToFront: false |
---|
| 1714 | }, |
---|
| 1715 | flyOut: true, |
---|
| 1716 | showSpeed: 100, |
---|
| 1717 | crumbDefaultText: '>' |
---|
| 1718 | }); |
---|
| 1719 | }); |
---|
| 1720 | |
---|
[5592] | 1721 | meu_container.find(".button.new-calendar").button({ |
---|
[5341] | 1722 | icons: { |
---|
| 1723 | primary: "ui-icon-plus" |
---|
| 1724 | }, |
---|
| 1725 | text: false |
---|
| 1726 | }).click(function () { |
---|
| 1727 | |
---|
| 1728 | if( $('.qtip.qtip-blue.qtip-active').val() !== ''){ |
---|
| 1729 | $(this).qtip({ |
---|
| 1730 | show: {ready: true, solo: true, when: {event: 'click'}}, |
---|
| 1731 | hide: false, |
---|
| 1732 | content: { |
---|
| 1733 | text: $('<div></div>').html( DataLayer.render( 'templates/calendar_quick_add.ejs', {} ) ), |
---|
| 1734 | title: { |
---|
| 1735 | text:'Nova Agenda', |
---|
| 1736 | button: '<a class="button close" href="#">close</a>' |
---|
| 1737 | } |
---|
| 1738 | }, |
---|
| 1739 | style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}}, |
---|
| 1740 | position: { |
---|
| 1741 | corner: { |
---|
| 1742 | target: 'rightMiddle', |
---|
| 1743 | tooltip: 'leftMiddle' |
---|
| 1744 | }, |
---|
| 1745 | adjust: {x:0, y:-12} |
---|
| 1746 | } |
---|
| 1747 | }) |
---|
| 1748 | .qtip("api").onShow = function(arg0) { |
---|
| 1749 | $('.qtip-active .button.close').button({ |
---|
| 1750 | icons: {primary: "ui-icon-close"}, |
---|
| 1751 | text: false |
---|
| 1752 | }) |
---|
| 1753 | .click(function(){ |
---|
[5592] | 1754 | meu_container.find(".button.new-calendar").qtip('destroy'); |
---|
[5341] | 1755 | }); |
---|
| 1756 | //TODO emplementar tratamento de duplicação de valores no location |
---|
| 1757 | $('.qtip-active .button.save').button().click(function(){ |
---|
| 1758 | for(var i = 0; i < Calendar.calendars.length; i++){ |
---|
| 1759 | if(Calendar.calendars[i].location == $('.qtip-active input').val()){ |
---|
| 1760 | $.Zebra_Dialog('O nome desta agenda já está sendo utilizada em uma Url de outra agenda. Por favor, informe outro nome para agenda.',{ |
---|
| 1761 | 'overlay_opacity': '0.5', |
---|
| 1762 | 'type': 'warning' |
---|
| 1763 | }); |
---|
| 1764 | meu_container.find(".button.new").qtip('destroy'); |
---|
| 1765 | return; |
---|
| 1766 | } |
---|
| 1767 | } |
---|
| 1768 | |
---|
| 1769 | var selected; |
---|
| 1770 | var color = $('.cal-colors-options-btn').each(function(index){ |
---|
| 1771 | if ($(this).is('.color-selected')) |
---|
| 1772 | selected = index; |
---|
| 1773 | }); |
---|
| 1774 | DataLayer.put( "calendarSignature", { |
---|
| 1775 | user: User.me.id, |
---|
| 1776 | calendar: { |
---|
[5384] | 1777 | name: Encoder.htmlEncode($('.qtip-active input').val()), |
---|
[5341] | 1778 | timezone: User.preferences.timezone |
---|
| 1779 | }, |
---|
| 1780 | isOwner: 1, |
---|
| 1781 | fontColor: colorsSuggestions[selected]['font'].substring(1) , |
---|
| 1782 | backgroundColor: colorsSuggestions[selected]['background'].substring(1) , |
---|
| 1783 | borderColor: colorsSuggestions[selected]['border'].substring(1) |
---|
| 1784 | }); |
---|
[5615] | 1785 | DataLayer.commit( false, false, function( received ){ |
---|
| 1786 | delete Calendar.currentViewKey; |
---|
| 1787 | Calendar.load(); |
---|
| 1788 | refresh_calendars(); |
---|
| 1789 | }); |
---|
[5341] | 1790 | meu_container.find(".button.new").qtip('destroy'); |
---|
| 1791 | }); |
---|
| 1792 | |
---|
| 1793 | $('.qtip-active .button.cancel').button().click(function(){ |
---|
| 1794 | meu_container.find(".button.new").qtip('destroy'); |
---|
| 1795 | }); |
---|
| 1796 | |
---|
| 1797 | $(".qtip-active input").Watermark("Nome da agenda"); |
---|
| 1798 | |
---|
| 1799 | $('.qtip-active').keydown(function(event) { |
---|
| 1800 | if (event.keyCode == '27') { |
---|
| 1801 | meu_container.find(".button.new").qtip('destroy'); |
---|
| 1802 | } |
---|
| 1803 | }); |
---|
| 1804 | |
---|
| 1805 | $('.colors-options').prepend(buttons_colors); |
---|
| 1806 | $('.colors-options .signed-cal-colors-options-btn-0').addClass('color-selected'); |
---|
| 1807 | |
---|
| 1808 | var buttons = $('.cal-colors-options-btn').button(); |
---|
| 1809 | |
---|
| 1810 | buttons.click(function(){ |
---|
| 1811 | buttons.removeClass('color-selected'); |
---|
| 1812 | $(this).addClass('color-selected'); |
---|
| 1813 | }); |
---|
| 1814 | } |
---|
| 1815 | } |
---|
| 1816 | }); |
---|
| 1817 | |
---|
| 1818 | $("img.cal-list-img").click(function(evt) { |
---|
| 1819 | $(".cal-list-options_1").toggleClass( "hidden" ); |
---|
| 1820 | }); |
---|
| 1821 | |
---|
| 1822 | $(".my-calendars a.title-my-calendars").click(function() { |
---|
| 1823 | $(".my-calendars ul.my-list-calendars").toggleClass("hidden") |
---|
| 1824 | $('.my-calendars .status-list').toggleClass("ui-icon-triangle-1-s"); |
---|
| 1825 | $('.my-calendars .status-list').toggleClass("ui-icon-triangle-1-e"); |
---|
| 1826 | }); |
---|
[5381] | 1827 | |
---|
[5341] | 1828 | $(".signed-calendars a.title-signed-calendars").click(function() { |
---|
| 1829 | $(".signed-calendars ul.signed-list-calendars").toggleClass( "hidden"); |
---|
| 1830 | }); |
---|
| 1831 | |
---|
| 1832 | $("ul li.list-calendars-item").click(function(evt) { |
---|
| 1833 | |
---|
| 1834 | }); |
---|
| 1835 | |
---|
| 1836 | $("ul li.list-calendars-item .ui-corner-all").click(function(evt) { |
---|
| 1837 | //alert('teste'); |
---|
| 1838 | }); |
---|
| 1839 | |
---|
[5592] | 1840 | meu_container.find(".button.new-calendar-shared").button({ |
---|
| 1841 | icons: { |
---|
| 1842 | primary: "ui-icon-plus" |
---|
| 1843 | }, |
---|
| 1844 | text: false |
---|
| 1845 | }).click(function (event) { |
---|
| 1846 | show_modal_search_shared(); |
---|
| 1847 | }); |
---|
| 1848 | |
---|
| 1849 | |
---|
| 1850 | //TODO Implementar ocultar agendas. |
---|
| 1851 | meu_container.find('.title-signed-calendars').click(function(evt){ |
---|
| 1852 | var status = $(this).parent().find('.status-list-shared'); |
---|
| 1853 | |
---|
| 1854 | if(status.hasClass('ui-icon-triangle-1-s')) |
---|
| 1855 | status.removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e'); |
---|
| 1856 | else |
---|
| 1857 | status.removeClass('ui-icon-triangle-1-e').addClass('ui-icon-triangle-1-s'); |
---|
| 1858 | }); |
---|
| 1859 | |
---|
[5341] | 1860 | $('.calendar-view').click(function(evt){ |
---|
| 1861 | if($tabs.tabs('option' ,'selected') == 1){ |
---|
| 1862 | pageselectCallback('', 0); |
---|
| 1863 | } |
---|
| 1864 | |
---|
[5384] | 1865 | if(Calendar.currentView){ |
---|
[5341] | 1866 | var checkBox = $(this); |
---|
[5384] | 1867 | if(!!Calendar.currentView[ checkBox.val() ]){ |
---|
| 1868 | Calendar.currentView[ checkBox.val() ].hidden = !checkBox.is(':checked'); |
---|
| 1869 | $('#calendar').fullCalendar( 'refetchEvents' ); |
---|
| 1870 | } |
---|
| 1871 | } |
---|
[5341] | 1872 | }); |
---|
| 1873 | }); |
---|
| 1874 | } |
---|
| 1875 | |
---|
| 1876 | function add_events_list(keyword) |
---|
| 1877 | { |
---|
| 1878 | var tab_title = ""; |
---|
| 1879 | if (keyword){ |
---|
| 1880 | if(keyword.length < 10) |
---|
| 1881 | tab_title = keyword; |
---|
| 1882 | else |
---|
| 1883 | tab_title = keyword.substr(0,10) + '..."'; |
---|
| 1884 | }else{ |
---|
| 1885 | tab_title = "Lista de eventos"; |
---|
| 1886 | } |
---|
| 1887 | keyword = ( keyword || '' ).replace( /\s+/g, "_" ); |
---|
| 1888 | |
---|
| 1889 | if(!(document.getElementById('tab_events_list_' + (Base64.encode(keyword)).replace(/[^\w\s]/gi, "") ))) |
---|
| 1890 | { |
---|
| 1891 | Encoder.EncodeType = "entity"; |
---|
| 1892 | $tabs.tabs( "add", "#tab_events_list_" + (Base64.encode(keyword)).replace(/[^\w\s]/gi, ""), Encoder.htmlEncode(tab_title) ); |
---|
| 1893 | } |
---|
| 1894 | else /* Tab already opened */ |
---|
| 1895 | { |
---|
| 1896 | $tabs.tabs("option", "selected", 2); |
---|
| 1897 | } |
---|
| 1898 | |
---|
| 1899 | pageselectCallback(keyword, 0); // load page 1 and insert data on event_list.ejs |
---|
| 1900 | |
---|
| 1901 | $('.preferences-win.active .button.save, .preferences-win.active .button.cancel, .preferences-win.active .button.import, .preferences-win.active .button.export').button(); |
---|
| 1902 | } |
---|
| 1903 | |
---|
| 1904 | function paginatorSearch(currentView){ |
---|
[5381] | 1905 | $(currentView+' .header-paginator .fc-header-left .fc-button').hover( |
---|
| 1906 | function(){ |
---|
| 1907 | $(this).addClass('fc-state-hover'); |
---|
| 1908 | }, |
---|
| 1909 | function(){ |
---|
| 1910 | $(this).removeClass('fc-state-hover'); |
---|
| 1911 | }).mousedown(function(){ |
---|
| 1912 | $(this).addClass('fc-state-down'); |
---|
| 1913 | }).mouseup(function(){ |
---|
| 1914 | $(this).removeClass('fc-state-down'); |
---|
| 1915 | $('.events-list.events-list-win.active').removeClass('active'); |
---|
| 1916 | var paginator = $(this).attr('class'); |
---|
| 1917 | if(paginator.indexOf('next') > 0){ |
---|
| 1918 | if(parseInt($(currentView+' [name = results]').val()) > 25) |
---|
| 1919 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($(currentView+' [name = page_index]').val())) +1)); |
---|
| 1920 | }else{ |
---|
| 1921 | if(parseInt($(currentView+' [name = page_index]').val()) > 0) |
---|
| 1922 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($(currentView+' [name = page_index]').val())) -1)); |
---|
| 1923 | } |
---|
| 1924 | }); |
---|
[5341] | 1925 | } |
---|
| 1926 | |
---|
| 1927 | function mountTitleList(page_index ,view){ |
---|
| 1928 | switch (view){ |
---|
| 1929 | case 'day': |
---|
[5345] | 1930 | case 'basicDay': |
---|
[5341] | 1931 | var date = new Date().add({days: page_index}); |
---|
[5409] | 1932 | return (dateCalendar.dayNames[date.getDay()])+", "+(date.toString('dd MMM yyyy')); |
---|
[5345] | 1933 | case 'agendaWeek': |
---|
[5341] | 1934 | case 'week': |
---|
[5409] | 1935 | var dateStart = new Date().moveToDayOfWeek(dateCalendar.dayOfWeek[User.preferences.weekStart]); |
---|
[5341] | 1936 | dateStart.add({days: (7 * page_index)}); |
---|
[5409] | 1937 | var dateEnd = new Date().moveToDayOfWeek(dateCalendar.dayOfWeek[User.preferences.weekStart]); |
---|
[5341] | 1938 | dateEnd.add({days: (page_index * 7)+7}); |
---|
| 1939 | if(dateStart.toString('MM') != dateEnd.toString('MM')) |
---|
[5409] | 1940 | return dateStart.toString('dd')+' de '+dateCalendar.monthNamesShort[dateStart.getMonth()]+' a '+dateEnd.toString('dd')+' de '+dateCalendar.monthNames[dateEnd.getMonth()]+' - '+dateEnd.toString('yyyy'); |
---|
| 1941 | return +dateStart.toString("dd")+" a "+dateEnd.toString("dd")+" de "+dateCalendar.monthNames[dateEnd.getMonth()]+" - "+dateEnd.toString('yyyy'); |
---|
[5341] | 1942 | case 'month': |
---|
| 1943 | var date = new Date().add({months: page_index}) |
---|
[5409] | 1944 | return dateCalendar.monthNames[date.getMonth()]+" "+date.toString("yyyy"); |
---|
[5341] | 1945 | case 'year': |
---|
| 1946 | var date = new Date().add({years: page_index}); |
---|
| 1947 | return date.toString("yyyy"); |
---|
| 1948 | } |
---|
| 1949 | } |
---|
| 1950 | |
---|
| 1951 | function paginatorList(currentView, view){ |
---|
| 1952 | $(currentView+' .events-list.events-list-win.active .list-events-paginator .fc-header-title').html('<h2>'+mountTitleList( parseInt($('[name = page_index]').val()),view)+'</h2>'); |
---|
| 1953 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
[5345] | 1954 | if(view == 'basicDay') |
---|
| 1955 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button-agendaday').addClass('fc-state-active'); |
---|
| 1956 | else |
---|
| 1957 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button-'+((view == 'day' || view == 'week') ? 'agenda'+view : view )).addClass('fc-state-active'); |
---|
[5341] | 1958 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right').addClass('list-right'); |
---|
[5381] | 1959 | |
---|
| 1960 | $(currentView+' .header-paginator .fc-header-right .fc-button').hover( |
---|
[5341] | 1961 | function(){ |
---|
| 1962 | $(this).addClass('fc-state-hover'); |
---|
| 1963 | }, |
---|
| 1964 | function(){ |
---|
| 1965 | $(this).removeClass('fc-state-hover'); |
---|
| 1966 | }).mousedown(function(){ |
---|
| 1967 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
| 1968 | $(this).addClass('fc-state-active'); |
---|
| 1969 | }).mouseup(function(){ |
---|
[5381] | 1970 | var goView = $(this).attr('class'); |
---|
| 1971 | if(goView.indexOf('agendaDay') > 0) |
---|
| 1972 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'day'); |
---|
| 1973 | else if(goView.indexOf('month') > 0) |
---|
| 1974 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'month'); |
---|
| 1975 | else if(goView.indexOf('year') > 0) |
---|
| 1976 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'year'); |
---|
| 1977 | else if(goView.indexOf('agendaWeek') > 0) |
---|
| 1978 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'week'); |
---|
| 1979 | |
---|
[5341] | 1980 | }); |
---|
[5381] | 1981 | |
---|
| 1982 | $(currentView+' .header-paginator .fc-header-left .fc-button').hover( |
---|
[5341] | 1983 | function(){ |
---|
| 1984 | $(this).addClass('fc-state-hover'); |
---|
| 1985 | }, |
---|
| 1986 | function(){ |
---|
| 1987 | $(this).removeClass('fc-state-hover'); |
---|
| 1988 | }).mousedown(function(){ |
---|
| 1989 | $(this).addClass('fc-state-down'); |
---|
| 1990 | }).mouseup(function(){ |
---|
| 1991 | $(this).removeClass('fc-state-down'); |
---|
[5381] | 1992 | var paginator = $(this).attr('class'); |
---|
| 1993 | if(paginator.indexOf('next') > 0) |
---|
| 1994 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($('[name = page_index]').val())) +1), '', view); |
---|
| 1995 | else |
---|
| 1996 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($('[name = page_index]').val())) -1), '', view); |
---|
| 1997 | }); |
---|
[5341] | 1998 | } |
---|
| 1999 | |
---|
| 2000 | function paginatorListEvent(currentView, typeView, view){ |
---|
| 2001 | if(!!$(currentView).find('.fc-calendar').length) |
---|
| 2002 | return; |
---|
| 2003 | $(currentView+' .events-list.events-list-win.active').prepend($('.fc-header').clone()); |
---|
| 2004 | //Remove contudo nao utilizado |
---|
| 2005 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-today').remove(); |
---|
| 2006 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-basicWeek').remove(); |
---|
| 2007 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-basicDay').remove(); |
---|
| 2008 | |
---|
| 2009 | //Adiciona e remove as classes para esta visualizacao |
---|
| 2010 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-header-center').addClass('list-events-paginator'); |
---|
| 2011 | $(currentView+' .events-list.events-list-win.active .fc-header .list-events-paginator').removeClass('fc-header-center'); |
---|
| 2012 | |
---|
| 2013 | //Adicionar class no header padronizar com a tela principal |
---|
| 2014 | $(currentView+' .events-list.events-list-win.active .fc-header').addClass('header-paginator'); |
---|
| 2015 | $(currentView+' .events-list.events-list-win.active .header-paginator').removeClass('fc-header'); |
---|
| 2016 | |
---|
| 2017 | if(typeView == 'search'){ |
---|
| 2018 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right').remove() |
---|
| 2019 | $(currentView+' .events-list.events-list-win.active .list-events-paginator .fc-header-title').html('<h2>Resultados para: '+$(currentView+' [name = keyword]').val()+'</h2>'); |
---|
| 2020 | if((parseInt($(currentView+' [name = page_index]').val()) == 0) && (parseInt($(currentView+' [name = results]').val()) <= 25)) |
---|
| 2021 | return; |
---|
| 2022 | paginatorSearch(currentView); |
---|
| 2023 | }else |
---|
| 2024 | paginatorList(currentView, view); |
---|
| 2025 | } |
---|
| 2026 | |
---|
| 2027 | function mountCriteriaList(view, page_index, calerdars_selecteds){ |
---|
[5437] | 2028 | var rangeStart , rangeEnd; |
---|
[5341] | 2029 | switch (view){ |
---|
[5345] | 2030 | case 'basicDay': |
---|
[5341] | 2031 | case 'day': |
---|
[5592] | 2032 | rangeStart = new Date().add({days: page_index}).getTime(); |
---|
[5437] | 2033 | rangeEnd = rangeStart; |
---|
| 2034 | break; |
---|
[5345] | 2035 | case 'agendaWeek': |
---|
[5341] | 2036 | case 'week': |
---|
[5437] | 2037 | var dateStart = new Date().moveToDayOfWeek(dateCalendar.dayOfWeek[User.preferences.weekStart]); |
---|
| 2038 | var dateEnd = new Date().moveToDayOfWeek(dateCalendar.dayOfWeek[User.preferences.weekStart]); |
---|
[5592] | 2039 | rangeStart = dateStart.add({days: (7 * page_index)}).getTime(); |
---|
| 2040 | rangeEnd = dateEnd.add({days: (7 * page_index)+7}).getTime(); |
---|
[5437] | 2041 | break; |
---|
[5341] | 2042 | case 'month': |
---|
[5592] | 2043 | var date = Date.today().add({months: page_index}) |
---|
| 2044 | rangeStart = date.moveToFirstDayOfMonth().getTime(); |
---|
| 2045 | rangeEnd = date.moveToLastDayOfMonth().getTime(); |
---|
[5437] | 2046 | break; |
---|
[5341] | 2047 | case 'year': |
---|
| 2048 | var dateStart = new Date().add({years: page_index}); |
---|
| 2049 | var dateEnd = new Date().add({years: page_index}); |
---|
| 2050 | if(dateStart.getMonth() != 0) |
---|
| 2051 | dateStart.moveToMonth(0, -1) |
---|
| 2052 | if(dateEnd.getMonth() != 11) |
---|
| 2053 | dateEnd.moveToMonth(11) |
---|
[5592] | 2054 | rangeStart = dateStart.moveToFirstDayOfMonth().getTime(); |
---|
| 2055 | rangeEnd = dateEnd.moveToLastDayOfMonth().getTime(); |
---|
[5437] | 2056 | break; |
---|
| 2057 | } |
---|
[5641] | 2058 | |
---|
| 2059 | var timezone = {}; |
---|
| 2060 | for(var i in Calendar.signatureOf) |
---|
| 2061 | timezone[i] = Calendar.signatureOf[i].calendar.timezone; |
---|
| 2062 | |
---|
| 2063 | return {filter: ['AND', ['>=', 'rangeStart', rangeStart], ['<=', 'rangeEnd', rangeEnd] , ['IN', 'calendar', calerdars_selecteds]], criteria: {deepness: 2, order: 'startTime', timezones: timezone}}; |
---|
[5437] | 2064 | |
---|
[5341] | 2065 | } |
---|
| 2066 | |
---|
| 2067 | function pageselectCallback(keyword, page_index, jq, view){ |
---|
| 2068 | |
---|
| 2069 | var selecteds = getSelectedCalendars(); |
---|
| 2070 | if(!selecteds && (keyword != '' && keyword != null)){ |
---|
| 2071 | jQuery('#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( |
---|
| 2072 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
| 2073 | '<label>Por favor selecione ao menos uma agenda.</label>' + |
---|
| 2074 | '</div>' |
---|
| 2075 | ); |
---|
| 2076 | }else{ |
---|
| 2077 | var criteria = null; |
---|
| 2078 | if(keyword == '' || keyword == null) |
---|
| 2079 | criteria = mountCriteriaList(!!view ? view : User.preferences.defaultCalView, page_index, selecteds) |
---|
| 2080 | else |
---|
[5409] | 2081 | criteria = {filter: ['AND', ['OR', ["i*", "summary", keyword], ["i*", "description", keyword]], ['IN', 'calendar', selecteds]], criteria: {order: 'startTime', offset: (25 * page_index), limit: (((25 * page_index) + 25) + 1), deepness: 2}}; |
---|
[5341] | 2082 | var results = DataLayer.get('schedulable:detail', criteria); |
---|
| 2083 | keyword = ( keyword || '' ).replace( /\s+/g, "_" ); |
---|
| 2084 | } |
---|
| 2085 | // não há resultados |
---|
| 2086 | if ((((typeof(results) == 'undefined') || (!results.events_list )) && selecteds) &&(keyword != '' && keyword != null)) { |
---|
| 2087 | jQuery('#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( |
---|
| 2088 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
| 2089 | '<label>Não foi encontrado nenhum evento correspondente à sua pesquisa.</label>' + |
---|
| 2090 | '</div>' |
---|
| 2091 | ); |
---|
| 2092 | // há resultados e Agendas Selecionadas |
---|
| 2093 | } else{ |
---|
| 2094 | if(typeof(results) != 'undefined'){ |
---|
| 2095 | results['page_index'] = page_index; |
---|
| 2096 | results['keyword'] = keyword; |
---|
| 2097 | |
---|
| 2098 | DataLayer.render( 'templates/event_list.ejs', results, function( html ){ |
---|
| 2099 | var currentView = '#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "") || ''); |
---|
| 2100 | jQuery(currentView).html( html ); |
---|
| 2101 | jQuery('.events-list-win .menu-container .button').button(); |
---|
| 2102 | |
---|
| 2103 | $(".event-details-item").parent().click(function(){ |
---|
| 2104 | |
---|
| 2105 | $(this).siblings("div.details-event-list").toggleClass("hidden") |
---|
| 2106 | .find('.button.delete').click(function(){ |
---|
[5381] | 2107 | var eventId = $(this).siblings('[name="eventid"]').val(); |
---|
| 2108 | $.Zebra_Dialog('Tem certeza que deseja excluir o evento?', { |
---|
| 2109 | 'type': 'question', |
---|
| 2110 | 'overlay_opacity': '0.5', |
---|
| 2111 | 'buttons': ['Sim', 'Não'], |
---|
| 2112 | 'onClose': function(clicked) { |
---|
| 2113 | if(clicked == 'Sim'){ |
---|
| 2114 | DataLayer.remove('schedulable', eventId); |
---|
| 2115 | } |
---|
| 2116 | } |
---|
| 2117 | }); |
---|
[5341] | 2118 | }) |
---|
| 2119 | .end().find('.button.edit').click(function(){ |
---|
| 2120 | eventDetails( DataLayer.get( "schedulable", $(this).siblings('[name="eventid"]').val() ), true ); |
---|
| 2121 | }); |
---|
| 2122 | |
---|
| 2123 | }); |
---|
| 2124 | paginatorListEvent(currentView, (keyword == '' || keyword == null) ? 'list' : 'search', !!view ? view : User.preferences.defaultCalView); |
---|
| 2125 | }); |
---|
| 2126 | }else{ |
---|
| 2127 | var currentView = '#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "") || ''); |
---|
| 2128 | jQuery('#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( |
---|
| 2129 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
| 2130 | '<input type="hidden" name="page_index" value="'+page_index+'"></inpunt>'+ |
---|
| 2131 | '<input type="hidden" name="keyword" value="'+keyword+'"></inpunt>'+ |
---|
| 2132 | '<label>Não foram encontrados eventos neste intervalo.</label>' + |
---|
| 2133 | '</div>' |
---|
| 2134 | ); |
---|
| 2135 | paginatorListEvent(currentView, 'list', !!view ? view : User.preferences.defaultCalView); |
---|
| 2136 | } |
---|
| 2137 | |
---|
| 2138 | } |
---|
| 2139 | |
---|
| 2140 | } |
---|
| 2141 | |
---|
[5381] | 2142 | function show_modal_import_export(tab, calendarId) { |
---|
[5341] | 2143 | DataLayer.render( 'templates/import_export.ejs', {calendars: Calendar.calendars, owner: User.me.id}, function( html ){ |
---|
| 2144 | |
---|
| 2145 | if (!UI.dialogs.importCalendar) { |
---|
| 2146 | UI.dialogs.importCalendar = jQuery('#div-import-export-calendar') |
---|
| 2147 | .append('<div title="Importar e Exportar Eventos" class="import-export import-export-win active"> <div>') |
---|
| 2148 | .find('.import-export-win.active').html(html).dialog({ |
---|
| 2149 | resizable: false, |
---|
| 2150 | modal:true, |
---|
| 2151 | width:500, |
---|
| 2152 | position: 'center' |
---|
| 2153 | }); |
---|
| 2154 | |
---|
| 2155 | } else { |
---|
| 2156 | UI.dialogs.importCalendar.html(html); |
---|
| 2157 | } |
---|
| 2158 | |
---|
| 2159 | var tabsImportExport = UI.dialogs.importCalendar.find(".tabs-import-export").tabs({selected: tab}); |
---|
| 2160 | |
---|
| 2161 | UI.dialogs.importCalendar.find('.button').button(); |
---|
| 2162 | |
---|
[5381] | 2163 | tabsImportExport.find('option[value="'+calendarId+'"]').attr('selected','selected').trigger('change'); |
---|
| 2164 | |
---|
| 2165 | |
---|
[5341] | 2166 | UI.dialogs.importCalendar.find(".menu-import-event") |
---|
[5381] | 2167 | .children(".import").click(function(data){ |
---|
| 2168 | $('.import-event-form', UI.dialogs.importCalendar).submit(); |
---|
[5341] | 2169 | UI.dialogs.importCalendar.dialog("close"); |
---|
[5384] | 2170 | isValidCalback = true; |
---|
[5341] | 2171 | /** |
---|
| 2172 | * TODO - implementar ação de importação |
---|
| 2173 | */ |
---|
| 2174 | }); |
---|
| 2175 | |
---|
| 2176 | UI.dialogs.importCalendar.find(".menu-export-event") |
---|
| 2177 | .children(".export").click(function(){ |
---|
| 2178 | |
---|
| 2179 | $('.export-event-form', UI.dialogs.importCalendar).submit(); |
---|
| 2180 | UI.dialogs.importCalendar.dialog("close"); |
---|
| 2181 | /** |
---|
| 2182 | * TODO - implementar ação de exportação |
---|
| 2183 | */ |
---|
| 2184 | }); |
---|
| 2185 | |
---|
| 2186 | UI.dialogs.importCalendar.find(".menu-container") |
---|
| 2187 | .children(".cancel").click(function(){ |
---|
| 2188 | UI.dialogs.importCalendar.dialog("close"); |
---|
| 2189 | }); |
---|
| 2190 | |
---|
| 2191 | UI.dialogs.importCalendar.dialog("open"); |
---|
| 2192 | }); |
---|
[5592] | 2193 | } |
---|
| 2194 | |
---|
[5746] | 2195 | function copyAndMoveTo(calendar, event, idRecurrence, type, evt){ |
---|
| 2196 | /* |
---|
| 2197 | * Types |
---|
| 2198 | * 0 = Move |
---|
| 2199 | * 1 = Copy Event end Repet |
---|
| 2200 | * 2 = Copy Ocurrence |
---|
| 2201 | * 3 = Copy to edit ocurrence |
---|
| 2202 | * |
---|
| 2203 | **/ |
---|
| 2204 | if(!type) |
---|
| 2205 | type = $('.calendar-copy-move input[name="typeEvent"]').val(); |
---|
[5592] | 2206 | |
---|
[5746] | 2207 | var schedulable = DataLayer.get('schedulable', event+''); |
---|
[5592] | 2208 | |
---|
[5746] | 2209 | calendar = !!calendar ? calendar : schedulable.calendar; |
---|
| 2210 | |
---|
[5592] | 2211 | if(typeof(schedulable) == "array") |
---|
| 2212 | schedulable = schedulable[0]; |
---|
| 2213 | |
---|
| 2214 | //Move eventos entre agendas |
---|
[5746] | 2215 | if(parseInt(type) == 0){ |
---|
[5592] | 2216 | |
---|
| 2217 | schedulable.calendar = calendar; |
---|
| 2218 | DataLayer.put('schedulable', schedulable); |
---|
| 2219 | |
---|
| 2220 | DataLayer.commit(); |
---|
| 2221 | //copia eventos entre agendas |
---|
| 2222 | }else{ |
---|
| 2223 | |
---|
| 2224 | var newSchedulable = schedulable; |
---|
| 2225 | |
---|
| 2226 | delete newSchedulable.id; |
---|
| 2227 | delete newSchedulable.uid; |
---|
| 2228 | delete newSchedulable.sequence; |
---|
| 2229 | delete newSchedulable.dtstamp; |
---|
[5746] | 2230 | |
---|
[5615] | 2231 | delete schedulable.DayLigth; |
---|
| 2232 | delete schedulable.rangeStart |
---|
| 2233 | delete schedulable.rangeEnd; |
---|
| 2234 | delete schedulable.lastUpdate; |
---|
[5746] | 2235 | |
---|
| 2236 | delete schedulable.calendar; |
---|
| 2237 | |
---|
| 2238 | if(schedulable.repeat && type == "1" ){ |
---|
| 2239 | var repeat = DataLayer.get('repeat', schedulable.repeat); |
---|
| 2240 | delete repeat.schedulable; |
---|
| 2241 | delete repeat.id; |
---|
| 2242 | repeat.startTime = new Date(parseInt(repeat.startTime)).toString('yyyy-MM-dd HH:mm:00'); |
---|
| 2243 | repeat.endTime = new Date(parseInt(repeat.endTime)).toString('yyyy-MM-dd HH:mm:00'); |
---|
| 2244 | |
---|
| 2245 | var exceptions = DataLayer.get('repeatOccurrence', {filter: ['AND', ['=','repeat', schedulable.repeat], ['=','exception','1']]}, true); |
---|
| 2246 | if(exceptions){ |
---|
| 2247 | repeat.exceptions = ''; |
---|
| 2248 | for(var i in exceptions ) |
---|
| 2249 | repeat.exceptions += exceptions[i].occurrence + ((exceptions.length -1) == parseInt(i) ? '' : ','); |
---|
| 2250 | |
---|
| 2251 | } |
---|
| 2252 | |
---|
| 2253 | |
---|
| 2254 | schedulable.repeat = repeat; |
---|
| 2255 | }else{ |
---|
| 2256 | if(!!idRecurrence){ |
---|
| 2257 | newSchedulable.endTime = parseInt(schedulable.occurrences[idRecurrence]) + (parseInt(newSchedulable.endTime) - parseInt(newSchedulable.startTime)); |
---|
| 2258 | newSchedulable.startTime = schedulable.occurrences[idRecurrence]; |
---|
| 2259 | } |
---|
| 2260 | delete schedulable.repeat; |
---|
| 2261 | } |
---|
| 2262 | delete schedulable.occurrences; |
---|
| 2263 | |
---|
[5615] | 2264 | schedulable.calendar = DataLayer.copy(calendar); |
---|
[5592] | 2265 | |
---|
| 2266 | var participants = DataLayer.copy(schedulable.participants); |
---|
| 2267 | delete schedulable.participants; |
---|
| 2268 | |
---|
| 2269 | schedulable.participants = $.map( participants, function( attendee, i ){ |
---|
| 2270 | |
---|
[5746] | 2271 | var participant = DataLayer.get('participant', attendee, false); |
---|
[5592] | 2272 | |
---|
| 2273 | if(typeof(participant) == 'array') |
---|
[5746] | 2274 | participant = participant[0]; |
---|
[5592] | 2275 | |
---|
[5746] | 2276 | delete participant.delegatedFrom; |
---|
[5592] | 2277 | delete participant.id; |
---|
[5746] | 2278 | delete participant.schedulable; |
---|
| 2279 | |
---|
| 2280 | participant.id = DataLayer.put('participant', participant); |
---|
[5592] | 2281 | |
---|
| 2282 | return participant ; |
---|
[5746] | 2283 | }); |
---|
| 2284 | //Edit ocurrence |
---|
| 2285 | if(parseInt(type) == 3){ |
---|
| 2286 | newSchedulable.endTime = !!evt.end ? evt.end.getTime() : ((evt.start).getTime() + 86400000); |
---|
| 2287 | newSchedulable.startTime = evt.start.getTime(); |
---|
| 2288 | |
---|
| 2289 | return newSchedulable; |
---|
| 2290 | } |
---|
| 2291 | newSchedulable.endTime = new Date(parseInt(newSchedulable.endTime) - (newSchedulable.allDay ? 86400000 : 0)).toString('yyyy-MM-dd hh:mm:00'); |
---|
| 2292 | newSchedulable.startTime = new Date(parseInt(newSchedulable.startTime)).toString('yyyy-MM-dd hh:mm:00'); |
---|
[5592] | 2293 | |
---|
[5636] | 2294 | DataLayer.put('schedulable', newSchedulable); |
---|
| 2295 | |
---|
[5592] | 2296 | } |
---|
| 2297 | |
---|
| 2298 | |
---|
[5341] | 2299 | } |
---|