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