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