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