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