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