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