[5341] | 1 | /* |
---|
| 2 | Todo Otimizar caulculo de timezone |
---|
| 3 | Objeto Date.toString() retorna a data com inserção do offset |
---|
| 4 | Objeto Date.getTime() retorna a data sem inserção do offset |
---|
| 5 | */ |
---|
| 6 | function checkTimezoneCalendar(idCalendar, timezone){ |
---|
| 7 | var obj = DataLayer.get('calendar', idCalendar); |
---|
| 8 | if(User.timezones[obj.timezone] == timezone) |
---|
| 9 | return true; |
---|
| 10 | else |
---|
| 11 | return false; |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | function setDateTimezone(date, timezone, existsTimezone, idCalendar){ |
---|
| 15 | |
---|
| 16 | if(!existsTimezone) |
---|
| 17 | return date; |
---|
| 18 | if(idCalendar) |
---|
| 19 | if(checkTimezoneCalendar(idCalendar, timezone)) |
---|
| 20 | return getDateTimezone(date, timezone, false); |
---|
| 21 | |
---|
| 22 | var timezoneOffset = ''; |
---|
| 23 | if(User.isDaylightSaving == '1') |
---|
| 24 | timezoneOffset = parseInt(timezone.substr(2)) - 100; |
---|
| 25 | else |
---|
| 26 | timezoneOffset = parseInt(timezone.substr(2)); |
---|
| 27 | |
---|
| 28 | var timeCurrent = parseInt((date.getTimezoneOffset()/60)+'00') |
---|
| 29 | var times = 0; |
---|
| 30 | if(timezone.charAt(0) != date.getUTCOffset().charAt(0)) |
---|
| 31 | times = timeCurrent + timezoneOffset ; |
---|
| 32 | else |
---|
| 33 | times = timezoneOffset - timeCurrent ; |
---|
| 34 | |
---|
| 35 | if(times == 0) |
---|
| 36 | return date; |
---|
| 37 | else if(times > 0) |
---|
| 38 | return date.setTimezoneOffset('-0'+(times)); |
---|
| 39 | else |
---|
| 40 | return date.setTimezoneOffset('+0'+((times * -1))); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | function getDateTimezone(date, timezone, recursive){ |
---|
| 45 | if(!timezone) |
---|
| 46 | return date; |
---|
| 47 | |
---|
| 48 | var times = 0; |
---|
| 49 | currentTimezone = parseInt((date.getTimezoneOffset()/60)+'00'); |
---|
| 50 | var timezoneOffset = 0; |
---|
| 51 | if(User.isDaylightSaving == '1') |
---|
| 52 | timezoneOffset = parseInt(timezone.substr(2)) - 100; |
---|
| 53 | else |
---|
| 54 | timezoneOffset = parseInt(timezone.substr(2)); |
---|
| 55 | |
---|
| 56 | var times = timezoneOffset - currentTimezone; |
---|
| 57 | if(times == 0){ |
---|
| 58 | if((timezone.charAt(0) == date.getUTCOffset().charAt(0)) && recursive) |
---|
| 59 | return date.setTimezoneOffset( timezone.charAt(0)+'0'+(currentTimezone)); |
---|
| 60 | else |
---|
| 61 | return date; |
---|
| 62 | }else if (times > 0) |
---|
| 63 | return date.setTimezoneOffset('+0'+(times)); |
---|
| 64 | else{ |
---|
| 65 | return date.setTimezoneOffset('-0'+((times * -1) + (currentTimezone * 2))); |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | function getDateUTC(date, timezone){ |
---|
| 70 | currentTimezone = parseInt(timezone.substr(2)); |
---|
| 71 | if(User.isDaylightSaving == '1') |
---|
| 72 | currentTimezone = currentTimezone - 100; |
---|
| 73 | return(date.setTimezoneOffset(timezone.charAt(0)+'0'+currentTimezone)); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | function createDateTimezone(date, timezone, idCalendar){ |
---|
| 77 | |
---|
| 78 | if(checkTimezoneCalendar(idCalendar, timezone)) |
---|
| 79 | return getDateTimezone(date, timezone, true); |
---|
| 80 | |
---|
| 81 | var times = 0; |
---|
| 82 | |
---|
| 83 | if(timezone.charAt(0) == '+') |
---|
| 84 | times = parseInt(timezone.substr(2)) - parseInt((date.getTimezoneOffset()/60)+'00'); |
---|
| 85 | else |
---|
| 86 | times = (parseInt(timezone.substr(2)) + parseInt((date.getTimezoneOffset()/60)+'00')) * (-1); |
---|
| 87 | if(times == 0) |
---|
| 88 | return date.setTimezoneOffset('0000'); |
---|
| 89 | else if (times > 0) |
---|
| 90 | return date.setTimezoneOffset('+0'+times); |
---|
| 91 | else |
---|
| 92 | return date.setTimezoneOffset('-0'+(times * -1)); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | function defaultToAmPm( Hour ) |
---|
| 96 | { |
---|
| 97 | var HourAmPm = Hour.split(":"); |
---|
| 98 | if(HourAmPm[0] == 0) |
---|
| 99 | HourAmPm[0] = 12; |
---|
| 100 | if(HourAmPm[0] < 12){ |
---|
| 101 | Hour += (Hour.length == 5) ? " am" : ""; |
---|
| 102 | }else if(HourAmPm[0] == 12){ |
---|
| 103 | Hour += (Hour.length == 5) ? " pm" : ""; |
---|
| 104 | }else |
---|
| 105 | Hour = "0"+(HourAmPm[0]-12)+":"+HourAmPm[1]+ ((Hour.length == 5) ? " pm" : ""); |
---|
| 106 | return Hour; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | function validDateEvent(){ |
---|
| 110 | var start_date = $(".new-event-win.active .start-date").val(); |
---|
| 111 | var end_date = $(".new-event-win.active .end-date").val(); |
---|
| 112 | var start_time = $(".new-event-win.active .start-time").val(); |
---|
| 113 | var end_time = $(".new-event-win.active .end-time").val(); |
---|
| 114 | var isAllDay = $('.new-event-win.active input[name="allDay"]').is(':checked'); |
---|
| 115 | |
---|
| 116 | if(start_date == "") |
---|
| 117 | return 'Por favor, informe uma data inicial'; |
---|
| 118 | else if(end_date == "") |
---|
| 119 | return 'Por favor, informe uma data final'; |
---|
| 120 | else if(!isAllDay && start_time == "") |
---|
| 121 | return 'Por favor, informe uma hora inicial'; |
---|
| 122 | else if(!isAllDay && end_time == "") |
---|
| 123 | return 'Por favor, informe uma hora final'; |
---|
| 124 | |
---|
| 125 | var formatString = (isAllDay)? User.preferences.dateFormat+" HH:mm" : User.preferences.dateFormat + " " + User.preferences.hourFormat; |
---|
| 126 | |
---|
| 127 | var spaces = function(hours){ |
---|
| 128 | return hours.replace(/\s$/, ""); |
---|
| 129 | }; |
---|
| 130 | |
---|
| 131 | var startDate = Date.parseExact( isAllDay ? start_date+ " 00:00": start_date + " " + spaces(start_time) , formatString ); |
---|
| 132 | var endDate = Date.parseExact( isAllDay ? end_date+ " 00:00": end_date + " " + spaces(end_time) , formatString ); |
---|
| 133 | |
---|
| 134 | if(startDate == null || startDate.getTime() < 0 ) |
---|
| 135 | return 'Data inicial inválida'; |
---|
| 136 | if(endDate == null || endDate.getTime() < 0) |
---|
| 137 | return 'Data final inválida'; |
---|
| 138 | |
---|
| 139 | if((endDate.compareTo(startDate) != 1) && !((endDate.compareTo(startDate) == 0) && (isAllDay))){ |
---|
| 140 | if(start_date == end_date){ |
---|
| 141 | if(end_time == start_time) |
---|
| 142 | return 'Hora inicial igual a final'; |
---|
| 143 | else |
---|
| 144 | return 'Hora final menor que a inicial'; |
---|
| 145 | |
---|
| 146 | }else |
---|
| 147 | return 'Data final menor que a inicial'; |
---|
| 148 | } |
---|
| 149 | return false; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | /* |
---|
| 153 | function listEvents(){ |
---|
| 154 | var list = $('.fc-header-right').find('.fc-button.fc-button-agendaDay').clone(); |
---|
| 155 | $('.fc-header-right').find('.fc-button-year').toggleClass('fc-corner-right'); |
---|
| 156 | list.addClass('fc-corner-right'); |
---|
| 157 | list.addClass('fc-button-listagem'); |
---|
| 158 | list.removeClass('fc-button-agendaDay'); |
---|
| 159 | list.removeClass('fc-corner-left'); |
---|
| 160 | list.find('.fc-button-content').html('Listagem'); |
---|
| 161 | $('.fc-header-right').append(list); |
---|
| 162 | } |
---|
| 163 | */ |
---|
| 164 | function eventDetails( objEvent, decoded ) |
---|
| 165 | { |
---|
| 166 | if( !decoded ) |
---|
| 167 | objEvent = DataLayer.decode( "schedulable:calendar", objEvent ); |
---|
| 168 | |
---|
| 169 | objEvent = DataLayer.encode( "schedulable:preview", objEvent ); |
---|
| 170 | |
---|
| 171 | if(typeof(objEvent.id) == 'undefined'){ |
---|
| 172 | objEvent.alarms = Calendar.signatureOf[!!User.preferences.defaultCalendar ? User.preferences.defaultCalendar : Calendar.calendarIds[0]].defaultAlarms; |
---|
| 173 | objEvent.useAlarmDefault = 1; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | /** |
---|
| 177 | * canDiscardEventDialog deve ser true se não houver alterações no evento |
---|
| 178 | */ |
---|
| 179 | canDiscardEventDialog = true; |
---|
| 180 | /** |
---|
| 181 | * zebraDiscardEventDialog é uma flag indicando que uma janela de confirmação (Zebra_Dialog) |
---|
| 182 | * já está aberta na tela, uma vez que não é possivel acessar o evento ESC utilizado para fechá-la |
---|
| 183 | */ |
---|
| 184 | zebraDiscardEventDialog = false; |
---|
| 185 | |
---|
| 186 | DataLayer.render( 'templates/event_add.ejs', {event:objEvent}, function( html ){ |
---|
| 187 | |
---|
| 188 | if (!UI.dialogs.addEvent) { |
---|
| 189 | UI.dialogs.addEvent = jQuery('#sandbox').append('<div title="Criar Evento" class="new-event-win active"> <div>').find('.new-event-win.active').html(html).dialog({ |
---|
| 190 | resizable: false, |
---|
| 191 | modal:true, |
---|
| 192 | autoOpen: false, |
---|
| 193 | width:700, |
---|
| 194 | position: 'center', |
---|
| 195 | close: function(event, ui) { |
---|
| 196 | /** |
---|
| 197 | * Remove tooltip possivelmente existente |
---|
| 198 | */ |
---|
| 199 | if ($('dd.attendee-list li:last').data('qtip')) |
---|
| 200 | $('dd.attendee-list li:last').qtip('destroy'); |
---|
| 201 | |
---|
| 202 | }, |
---|
| 203 | beforeClose: function(event, ui) { |
---|
| 204 | |
---|
| 205 | if (!canDiscardEventDialog && !zebraDiscardEventDialog) { |
---|
| 206 | zebraDiscardEventDialog = true; |
---|
| 207 | window.setTimeout(function() { |
---|
| 208 | $.Zebra_Dialog('Suas alterações no evento não foram salvas. Deseja descartar as alterações?', { |
---|
| 209 | 'type': 'question', |
---|
| 210 | 'overlay_opacity': '0.5', |
---|
| 211 | 'buttons': ['Descartar alterações', 'Continuar editando'], |
---|
| 212 | 'onClose': function(clicked) { |
---|
| 213 | if(clicked == 'Descartar alterações') { |
---|
| 214 | canDiscardEventDialog = true; |
---|
| 215 | UI.dialogs.addEvent.dialog('close'); |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | /** |
---|
| 219 | * Uma vez aberta uma janela de confirmação (Zebra_Dialog), ao fechá-la |
---|
| 220 | * com ESC, para que o evento ESC não seja propagado para fechamento da |
---|
| 221 | * janela de edição de eventos, deve ser setada uma flag indicando que |
---|
| 222 | * já existe uma janela de confirmação aberta. |
---|
| 223 | */ |
---|
| 224 | if (!clicked) { |
---|
| 225 | zebraDiscardEventDialog = true; |
---|
| 226 | window.setTimeout(function() { |
---|
| 227 | zebraDiscardEventDialog = false; |
---|
| 228 | }, 200); |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | }); |
---|
| 232 | |
---|
| 233 | }, 300); |
---|
| 234 | |
---|
| 235 | } |
---|
| 236 | return canDiscardEventDialog; |
---|
| 237 | } |
---|
| 238 | }); |
---|
| 239 | |
---|
| 240 | } else { |
---|
| 241 | UI.dialogs.addEvent.html(html); |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | var tabs = UI.dialogs.addEvent.children('.content').tabs(); |
---|
| 245 | var calendar = DataLayer.get('calendar', objEvent.calendar); |
---|
| 246 | |
---|
| 247 | |
---|
| 248 | UI.dialogs.addEvent.find(':input').change(function(event){ |
---|
| 249 | if (event.keyCode != '27' && event.keyCode != '13') |
---|
| 250 | canDiscardEventDialog = false; |
---|
| 251 | }).keydown(function(event){ |
---|
| 252 | if (event.keyCode != '27' && event.keyCode != '13') |
---|
| 253 | canDiscardEventDialog = false; |
---|
| 254 | }); |
---|
| 255 | |
---|
| 256 | if (calendar.timezone != objEvent.timezone){ |
---|
| 257 | UI.dialogs.addEvent.find('.calendar-addevent-details-txt-timezone').find('option[value="'+objEvent.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
| 258 | UI.dialogs.addEvent.find('.calendar_addevent_details_lnk_timezone').addClass('hidden'); |
---|
| 259 | $('.calendar-addevent-details-txt-timezone').removeClass('hidden'); |
---|
| 260 | |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | UI.dialogs.addEvent.find('.calendar_addevent_details_lnk_timezone').click(function(e){ |
---|
| 264 | $(this).addClass('hidden'); |
---|
| 265 | $('.calendar-addevent-details-txt-timezone').removeClass('hidden'); |
---|
| 266 | |
---|
| 267 | e.preventDefault(); |
---|
| 268 | }); |
---|
| 269 | |
---|
| 270 | UI.dialogs.addEvent.find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
| 271 | if( $(this).parent().remove().find('li').is(':empty') ) { |
---|
| 272 | //alert('nao tem'); |
---|
| 273 | } |
---|
| 274 | }); |
---|
| 275 | |
---|
| 276 | /*Adicionar alarms padrões, quando alterado a agenda do usuário*/ |
---|
| 277 | UI.dialogs.addEvent.find('select[name="calendar"]').change(function(){ |
---|
| 278 | if((typeof($('input[name = "idEvent"]').val()) == 'undefined') || ($('input[name = "idEvent"]').val() == '')) { |
---|
| 279 | $('input[name = "isDefaultAlarm[]"]').parent().remove(); |
---|
| 280 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').parent().removeClass('hidden'); |
---|
| 281 | var calendarSelected = Calendar.signatureOf[$(this).val()]; |
---|
| 282 | calendarSelected.useAlarmDefault = 1; |
---|
| 283 | if(calendarSelected.defaultAlarms != ""){ |
---|
| 284 | var li_attach = DataLayer.render('templates/alarms_add_itemlist.ejs', {alarm:calendarSelected}); |
---|
| 285 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
| 286 | if( $(this).parent().remove().find('li').is(':empty') ) { |
---|
| 287 | //alert('nao tem'); |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | }); |
---|
| 291 | }else{ |
---|
| 292 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').parent().addClass('hidden'); |
---|
| 293 | } |
---|
| 294 | } |
---|
| 295 | }); |
---|
| 296 | |
---|
| 297 | /*Checkbox adicionar alarms padrões*/ |
---|
| 298 | UI.dialogs.addEvent.find('input[name="defaultAlarm"]').click(function(){ |
---|
| 299 | if($(this).attr("checked")){ |
---|
| 300 | $('input[name = "isDefaultAlarm[]"]').parent().remove(); |
---|
| 301 | var calendarSelected = Calendar.signatureOf[$('select[name="calendar"]').val()]; |
---|
| 302 | calendarSelected.useAlarmDefault = 1; |
---|
| 303 | if(calendarSelected.defaultAlarms != ""){ |
---|
| 304 | var li_attach = DataLayer.render('templates/alarms_add_itemlist.ejs', {alarm:calendarSelected}); |
---|
| 305 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
| 306 | if( $(this).parent().remove().find('li').is(':empty') ) { |
---|
| 307 | //alert('nao tem'); |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | }); |
---|
| 311 | } |
---|
| 312 | }else |
---|
| 313 | $('input[name = "isDefaultAlarm[]"]').parent().remove(); |
---|
| 314 | }); |
---|
| 315 | /* Checkbox allday */ |
---|
| 316 | UI.dialogs.addEvent.find('input[name="allDay"]').click(function(){ |
---|
| 317 | if($(this).attr("checked")) |
---|
| 318 | UI.dialogs.addEvent.find('.start-time, .end-time').addClass('hidden'); |
---|
| 319 | else |
---|
| 320 | UI.dialogs.addEvent.find('.start-time, .end-time').removeClass('hidden'); |
---|
| 321 | }); |
---|
| 322 | |
---|
| 323 | UI.dialogs.addEvent.find('.button').button(); |
---|
| 324 | UI.dialogs.addEvent.find('.button.add').button({ |
---|
| 325 | icons: { |
---|
| 326 | secondary: "ui-icon-plus" |
---|
| 327 | } |
---|
| 328 | }); |
---|
| 329 | |
---|
| 330 | // ==== validation events ==== |
---|
| 331 | $(".input-group .h1").Watermark("Evento sem título"); |
---|
| 332 | if(User.preferences.hourFormat.length == 5) |
---|
| 333 | $(".new-event-win.active .end-time, .new-event-win.active .start-time").mask("99:99"); |
---|
| 334 | else{ |
---|
| 335 | $.mask.definitions['{']='[ap]'; |
---|
| 336 | $.mask.definitions['}']='[m]'; |
---|
| 337 | $(".new-event-win.active .end-time, .new-event-win.active .start-time").mask("99:99 {}", |
---|
| 338 | {completed:function(){ |
---|
| 339 | $(this).val(defaultToAmPm($(this).val())); |
---|
| 340 | $(this).timepicker("refresh"); |
---|
| 341 | $(this).val($(this).val().replace(/[\.]/gi, "")); |
---|
| 342 | }}); |
---|
| 343 | } |
---|
| 344 | $(".number").numeric(); |
---|
| 345 | if(User.preferences.dateFormat.indexOf('-') > 0) |
---|
| 346 | $(".date").mask("99-99-9999"); |
---|
| 347 | else |
---|
| 348 | $(".date").mask("99/99/9999"); |
---|
| 349 | |
---|
| 350 | UI.dialogs.addEvent.find(".menu-addevent") |
---|
| 351 | |
---|
| 352 | .children(".delete").click(function(){ |
---|
| 353 | $.Zebra_Dialog('Tem certeza que deseja excluir o evento?', { |
---|
| 354 | 'type': 'question', |
---|
| 355 | 'overlay_opacity': '0.5', |
---|
| 356 | 'buttons': ['Sim', 'Não'], |
---|
| 357 | 'onClose': function(clicked) { |
---|
| 358 | if(clicked == 'Sim'){ |
---|
| 359 | DataLayer.remove( "schedulable", UI.dialogs.addEvent.find(".id-event").val() ); |
---|
| 360 | UI.dialogs.addEvent.dialog("close"); |
---|
| 361 | } |
---|
| 362 | } |
---|
| 363 | }); |
---|
| 364 | }).end() |
---|
| 365 | |
---|
| 366 | .children(".cancel").click(function(){ |
---|
| 367 | DataLayer.rollback('participant'); |
---|
| 368 | UI.dialogs.addEvent.dialog("close"); |
---|
| 369 | }).end() |
---|
| 370 | |
---|
| 371 | .children(".save").click(function(){ |
---|
| 372 | /* Validação */ |
---|
| 373 | |
---|
| 374 | var msg = false; |
---|
| 375 | if(msg = validDateEvent()){ |
---|
| 376 | $(".new-event-win.active").find('.messages-validation').removeClass('hidden').find('.message label').html(msg); |
---|
| 377 | return false; |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | canDiscardEventDialog = true; |
---|
| 381 | |
---|
| 382 | UI.dialogs.addEvent.children(".form-addevent").submit(); |
---|
| 383 | UI.dialogs.addEvent.dialog("close"); |
---|
| 384 | }).end() |
---|
| 385 | |
---|
| 386 | .children(".export").click(function(){ |
---|
| 387 | UI.dialogs.addEvent.children(".form-export").submit(); |
---|
| 388 | }); |
---|
| 389 | |
---|
| 390 | UI.dialogs.addEvent.find('input.date').datepicker({dateFormat: 'dd/mm/yy'}); |
---|
| 391 | UI.dialogs.addEvent.find('input.time').timepicker({ |
---|
| 392 | closeText: 'Ok', |
---|
| 393 | hourGrid: 4, |
---|
| 394 | minuteGrid: 10, |
---|
| 395 | ampm : ((User.preferences.hourFormat.length > 5) ? true: false), |
---|
| 396 | timeFormat: "hh:mm tt", |
---|
| 397 | onSelect: function (selectedDateTime){ |
---|
| 398 | if(!(User.preferences.hourFormat.length == 5)) |
---|
| 399 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
| 400 | }, |
---|
| 401 | onClose : function (selectedDateTime){ |
---|
| 402 | if(!(User.preferences.hourFormat.length == 5)) |
---|
| 403 | $(this).val(selectedDateTime.replace(/[\.]/gi, "")); |
---|
| 404 | } |
---|
| 405 | }); |
---|
| 406 | |
---|
| 407 | UI.dialogs.addEvent.find('.button-add-alarms').click(function(){ |
---|
| 408 | var li_attach = DataLayer.render('templates/alarms_add_itemlist.ejs', {}); |
---|
| 409 | |
---|
| 410 | jQuery('.event-alarms-list').append(li_attach).find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
| 411 | if( $(this).parent().remove().find('li').is(':empty') ) { |
---|
| 412 | //alert('nao tem'); |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | }); |
---|
| 416 | |
---|
| 417 | // valicacao de campos numericos |
---|
| 418 | $('.number').numeric(); |
---|
| 419 | }); |
---|
| 420 | |
---|
| 421 | UI.dialogs.addEvent.find('.button-add-attachment').click(function(){ |
---|
| 422 | var li_attach = |
---|
| 423 | '<li class="input_label">' + |
---|
| 424 | '<input type="file" name="attachments[]"" />' + |
---|
| 425 | '</li>'; |
---|
| 426 | jQuery('.attachments-list').append(li_attach); |
---|
| 427 | }); |
---|
| 428 | |
---|
| 429 | DataLayer.render( 'templates/attendee_add.ejs', {event:objEvent}, function( attendeeHtml ){ |
---|
| 430 | |
---|
| 431 | // load template of attendees |
---|
| 432 | var blkAddAtendee = UI.dialogs.addEvent.find('#calendar_addevent_details6').append(attendeeHtml); |
---|
| 433 | |
---|
| 434 | blkAddAtendee.find('li.attendee .button').addClass('small').button({text:false, icons: {primary:'ui-icon-close'}}).click(function () { |
---|
| 435 | var participant = DataLayer.get('participant', ['AND',['=', 'user', $(this).parent().find('[type=checkbox]').val().replace(/[a-z:]/g, "")],['=', 'schedulable', $(this).parents().find('.id-event').first().val()]]); |
---|
| 436 | if(participant) |
---|
| 437 | DataLayer.remove('participant', participant[0].id); |
---|
| 438 | $(this).parent().remove(); |
---|
| 439 | }); |
---|
| 440 | //show or hidden permissions attendees |
---|
| 441 | //blkAddAtendee.find('.block-attendee-list #attendees-users li').click(show_permissions_attendees); |
---|
| 442 | |
---|
| 443 | $(".attendee-list-add .add-attendee-input input").Watermark("digite um email para convidar"); |
---|
| 444 | /* Trata a edição de um novo participante adicionado |
---|
| 445 | * |
---|
| 446 | */ |
---|
| 447 | var hasNewAttendee = false; |
---|
| 448 | $('.attendee-list-add .add-attendee-input input').keydown(function(event) { |
---|
| 449 | |
---|
| 450 | if (event.keyCode == '13' && $(this).val() != '') { |
---|
| 451 | Encoder.EncodeType = "entity"; |
---|
| 452 | $(this).val(Encoder.htmlEncode($(this).val())); |
---|
| 453 | |
---|
| 454 | var newAttendeeEmail = false; |
---|
| 455 | var newAttendeeName = false; |
---|
| 456 | |
---|
| 457 | var info = $(this).val(); |
---|
| 458 | |
---|
| 459 | /** |
---|
| 460 | * email válido? |
---|
| 461 | */ |
---|
| 462 | info.match(/^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/) ? |
---|
| 463 | newAttendeeEmail = info : newAttendeeName = info; |
---|
| 464 | |
---|
| 465 | /** |
---|
| 466 | * 1) busca no banco para saber se o usuário já existe |
---|
| 467 | * 1.1) se existe, atualiza as info na lista de participantes e nao abre o tooltip |
---|
| 468 | * 1.2) se não existe |
---|
| 469 | * a) salva como novo usuario externo no banco (apenas com email) |
---|
| 470 | * b) exibe tooltip pedindo o nome |
---|
| 471 | * c) se o usuário preenche tooltip e salva, atualiza com o nome o usuário recém criado |
---|
| 472 | * d) se o usuário cancela o tooltip, fica o usuário salvo apenas com email e sem nome |
---|
| 473 | */ |
---|
| 474 | |
---|
| 475 | var user = DataLayer.get('user', ["=", "mail", $(this).val()], true); |
---|
| 476 | var isExternal = (user) ? user.isExternal : 1; |
---|
| 477 | |
---|
| 478 | /** |
---|
| 479 | * Remove tooltip possivelmente existente |
---|
| 480 | */ |
---|
| 481 | if (hasNewAttendee && blkAddAtendee.find('dd.attendee-list li:last').data('qtip')) |
---|
| 482 | blkAddAtendee.find('dd.attendee-list li:last').qtip('destroy'); |
---|
| 483 | |
---|
| 484 | var newAttendeeId = ''; |
---|
| 485 | |
---|
| 486 | if (user){ |
---|
| 487 | if(user[0].isExternal) |
---|
| 488 | newAttendeeId = 'external:'+user[0].id; |
---|
| 489 | else |
---|
| 490 | newAttendeeId = 'internal:'+user[0].id; |
---|
| 491 | |
---|
| 492 | blkAddAtendee.find('dd.attendee-list ul.attendee-list').append( |
---|
[5349] | 493 | DataLayer.render('templates/participants_add_itemlist.ejs', [{id:newAttendeeId, name: user[0].name, mail: user[0].mail}]) |
---|
| 494 | ) |
---|
[5341] | 495 | .find('.button.close').addClass('small').button({text:false, icons:{primary:'ui-icon-close'}}).click(function() { |
---|
| 496 | var participant = DataLayer.get('participant', ['AND',['=', 'user', $(this).parent().find('[type=checkbox]').val().replace(/[a-z:]/g, "")],['=', 'schedulable',$(this).parents().find('.id-event').first().val()]]); |
---|
| 497 | if(participant) |
---|
| 498 | DataLayer.remove('participant', participant[0].id); |
---|
| 499 | $(this).parent().remove(); |
---|
[5349] | 500 | }).end() |
---|
| 501 | .scrollTo('max'); |
---|
| 502 | |
---|
[5341] | 503 | $(this).val(''); |
---|
| 504 | |
---|
| 505 | } else { |
---|
| 506 | /** |
---|
| 507 | * a) salva como novo usuario externo no banco (apenas com email) e... |
---|
| 508 | * adiciona novo contato externo à lista de convidados |
---|
| 509 | */ |
---|
| 510 | |
---|
| 511 | newAttendeeId = DataLayer.put('user', {name: newAttendeeName, mail: newAttendeeEmail, isExternal: isExternal}); |
---|
| 512 | |
---|
| 513 | blkAddAtendee.find('dd.attendee-list ul.attendee-list').append( |
---|
| 514 | DataLayer.render('templates/participants_add_itemlist.ejs', [{id:newAttendeeId, name: newAttendeeName, mail: newAttendeeEmail}]) |
---|
| 515 | ).find('.button.close').addClass('small').button({text:false, icons:{primary:'ui-icon-close'}}).click(function() { |
---|
| 516 | var participant = DataLayer.get('participant', ['AND',['=', 'user', $(this).parent().find('[type=checkbox]').val().replace(/[a-z:]/g, "")],['=', 'schedulable', $(this).parents().find('.id-event').first().val()]]); |
---|
| 517 | if(participant) |
---|
| 518 | DataLayer.remove('participant', participant[0].id); |
---|
| 519 | $(this).parent().remove(); |
---|
[5349] | 520 | }).end() |
---|
| 521 | .scrollTo('max'); |
---|
[5341] | 522 | hasNewAttendee = true; |
---|
| 523 | |
---|
| 524 | |
---|
| 525 | /** |
---|
| 526 | * Adiciona tootip para atualização dos dados do contato externo |
---|
| 527 | * recém adicionado. |
---|
| 528 | */ |
---|
| 529 | blkAddAtendee.find('dd.attendee-list li:last').qtip({ |
---|
| 530 | show: {ready: true, solo: true, when: {event: 'click'}}, |
---|
| 531 | hide: false, |
---|
| 532 | content: { |
---|
| 533 | text: $('<div></div>').html( DataLayer.render( 'templates/attendee_quick_edit.ejs', {attendee:{name:newAttendeeName, mail:newAttendeeEmail}} ) ), |
---|
| 534 | title: { |
---|
| 535 | text:'Detalhes do participante', |
---|
| 536 | button: '<a class="button close" href="#">close</a>' |
---|
| 537 | } |
---|
| 538 | }, |
---|
| 539 | style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}}, |
---|
| 540 | position: { |
---|
| 541 | corner: { |
---|
| 542 | target: 'rightMiddle', |
---|
| 543 | tooltip: 'leftMiddle' |
---|
| 544 | }, |
---|
| 545 | adjust: {x:0, y:0} |
---|
| 546 | } |
---|
| 547 | }); |
---|
| 548 | |
---|
| 549 | var saveContact = function() { |
---|
| 550 | Encoder.EncodeType = "entity"; |
---|
| 551 | |
---|
| 552 | var currentTip = $('.qtip-active'); |
---|
| 553 | newAttendeeName = currentTip.find('input[name="name"]').val(); |
---|
| 554 | newAttendeeEmail = currentTip.find('input[name="mail"]').val(); |
---|
| 555 | |
---|
| 556 | var isValidMail = newAttendeeEmail.match(/^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/); |
---|
| 557 | if (!isValidMail) { |
---|
| 558 | currentTip.find('.messages').removeClass('hidden').find('.message label').append('Email inválido.'); |
---|
| 559 | return false; |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | DataLayer.put('user', {id:newAttendeeId, name:newAttendeeName, mail:newAttendeeEmail, isExternal:isExternal}); |
---|
| 563 | |
---|
| 564 | $('dd.attendee-list ul.attendee-list li:last label') |
---|
| 565 | .filter('.name').html(Encoder.htmlEncode(newAttendeeName)).attr('title', Encoder.htmlEncode(newAttendeeName)).end() |
---|
| 566 | .filter('.mail').html(Encoder.htmlEncode(newAttendeeEmail)).attr('title', Encoder.htmlEncode(newAttendeeEmail)); |
---|
| 567 | |
---|
| 568 | return true; |
---|
| 569 | } |
---|
| 570 | |
---|
| 571 | $('dd.attendee-list li:last').qtip("api").onShow = function(arg0) { |
---|
| 572 | |
---|
| 573 | $('.qtip-active .button.close').button({ |
---|
| 574 | icons: {primary: "ui-icon-close"}, |
---|
| 575 | text: false |
---|
| 576 | }); |
---|
| 577 | $('.qtip-active .button').button() |
---|
| 578 | .filter('.save').click(function(event, ui) { |
---|
| 579 | if (saveContact()) { |
---|
| 580 | $('dd.attendee-list li:last').qtip("destroy"); |
---|
| 581 | } else { |
---|
| 582 | return false; |
---|
| 583 | } |
---|
| 584 | }).end() |
---|
| 585 | .filter('.cancel').click(function(event, ui) { |
---|
| 586 | |
---|
| 587 | $('dd.attendee-list li:last').qtip("destroy"); |
---|
| 588 | }) |
---|
| 589 | |
---|
| 590 | /** |
---|
| 591 | * Trata o ENTER no campo da tooltip, equivalente a salvar |
---|
| 592 | * o novo convidado. |
---|
| 593 | */ |
---|
| 594 | $('.qtip-active input').keydown(function(event) { |
---|
| 595 | if (event.keyCode == '13') { |
---|
| 596 | if (saveContact()) { |
---|
| 597 | $('dd.attendee-list li:last').qtip("destroy"); |
---|
| 598 | } |
---|
| 599 | |
---|
| 600 | $('dd.attendee-list li:last').qtip("destroy"); |
---|
| 601 | event.preventDefault(); |
---|
| 602 | } |
---|
| 603 | }) |
---|
| 604 | .filter('[name="name"]').Watermark("informe o nome do contato").end() |
---|
| 605 | .filter('[name="mail"]').Watermark("informe o email do contato"); |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | |
---|
| 609 | $(this).val(''); |
---|
| 610 | |
---|
| 611 | event.preventDefault(); |
---|
| 612 | } |
---|
| 613 | } |
---|
| 614 | }); |
---|
| 615 | |
---|
| 616 | /** |
---|
| 617 | * Trata a busca de usuários para adição de participantes |
---|
| 618 | */ |
---|
| 619 | blkAddAtendee.find('.add-attendee-search input').keydown(function(event) { |
---|
| 620 | |
---|
| 621 | if(event.keyCode == '13') { |
---|
| 622 | Encoder.EncodeType = "entity"; |
---|
| 623 | $(this).val(Encoder.htmlEncode($(this).val())); |
---|
| 624 | |
---|
| 625 | var result = DataLayer.get('user', ["*", "name", $(this).val()], true); |
---|
| 626 | |
---|
| 627 | /** |
---|
| 628 | * TODO: trocar por template |
---|
| 629 | */ |
---|
| 630 | $('ul.search-result-list').empty().css('overflow', 'hidden'); |
---|
| 631 | if (!result) { |
---|
| 632 | $('ul.search-result-list').append('<li><label class="empty">Nenhum resultado encontrado.</label></li>'); |
---|
| 633 | } |
---|
| 634 | |
---|
| 635 | $('ul.search-result-list').append(DataLayer.render( 'templates/participants_search_itemlist.ejs', result)); |
---|
| 636 | |
---|
| 637 | $('ul.search-result-list li').click(function(event, ui){ |
---|
| 638 | if ($(event.target).is('input')) { |
---|
| 639 | old_item = $(event.target).parents('li'); |
---|
| 640 | blkAddAtendee.find('dd.attendee-list ul.attendee-list') |
---|
| 641 | .append(DataLayer.render('templates/participants_add_itemlist.ejs', [{id: 'internal:'+old_item.find('.id').text(), name: old_item.find('.name').html()}])) |
---|
| 642 | .find('.button').addClass('small').button({text:false, icons: {primary:'ui-icon-close'}}).click(function () { |
---|
| 643 | $(this).parent().remove(); |
---|
[5349] | 644 | }).end() |
---|
| 645 | .scrollTo('max'); |
---|
[5341] | 646 | |
---|
| 647 | old_item.remove(); |
---|
| 648 | } |
---|
| 649 | }); |
---|
| 650 | |
---|
| 651 | event.preventDefault(); |
---|
| 652 | } |
---|
| 653 | }); |
---|
| 654 | |
---|
| 655 | |
---|
| 656 | UI.dialogs.addEvent.find('.attendees-list li').hover( |
---|
| 657 | function () { |
---|
| 658 | $(this).addClass("hover"); |
---|
| 659 | }, |
---|
| 660 | function () { |
---|
| 661 | $(this).removeClass("hover"); |
---|
| 662 | } |
---|
| 663 | ); |
---|
| 664 | |
---|
| 665 | //$('.block-add-attendee .search-result-list').selectable(); |
---|
| 666 | |
---|
| 667 | UI.dialogs.addEvent.find('.block-attendee-list select.status').change(function(){ |
---|
| 668 | if ($(this).val() == 'another') { |
---|
| 669 | // jQuery('.block-attendee-list .add-attendee-search').removeClass('hidden'); |
---|
| 670 | $(this).qtip({ |
---|
| 671 | show: {ready: true}, |
---|
| 672 | hide: false, |
---|
| 673 | content: { |
---|
| 674 | text: $('.block-attendee-list .add-attendee-search').clone().removeClass('hidden'), |
---|
| 675 | title: { |
---|
| 676 | text:'Indique o participante', |
---|
| 677 | button: '<a class="button close" href="#">close</a>' |
---|
| 678 | } |
---|
| 679 | }, |
---|
| 680 | style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 250, max:250}}, |
---|
| 681 | position: { |
---|
| 682 | corner: { |
---|
| 683 | target: 'rightMiddle', |
---|
| 684 | tooltip: 'leftMiddle' |
---|
| 685 | }, |
---|
| 686 | adjust: {x:0, y:0} |
---|
| 687 | } |
---|
| 688 | }) |
---|
| 689 | $(this).qtip.onShow = function() { |
---|
| 690 | $('.qtip .button.close').button({ |
---|
| 691 | icons: {primary: "ui-icon-close"}, |
---|
| 692 | text: false |
---|
| 693 | }); |
---|
| 694 | } |
---|
| 695 | } else { |
---|
| 696 | // jQuery('.block-attendee-list .add-attendee-search').addClass('hidden'); |
---|
| 697 | } |
---|
| 698 | }); |
---|
| 699 | }); |
---|
| 700 | UI.dialogs.addEvent.dialog('open'); |
---|
| 701 | }); |
---|
| 702 | |
---|
| 703 | |
---|
| 704 | } |
---|
| 705 | |
---|
| 706 | function add_tab_preferences() |
---|
| 707 | { |
---|
| 708 | if(!(document.getElementById('preference_tab'))) |
---|
| 709 | { |
---|
| 710 | var tab_title = "Preferencias"; |
---|
| 711 | $tabs.tabs( "add", "#preference_tab", tab_title ); |
---|
| 712 | |
---|
| 713 | /* |
---|
| 714 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
| 715 | tabPrefCalendar.find('select[name="timezone"]').html(timezones_options).find('option[value="'+User.preferences.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
| 716 | }); |
---|
| 717 | */ |
---|
| 718 | DataLayer.render( 'templates/preferences_calendar.ejs', {preferences:User.preferences, calendars: Calendar.calendars}, function( template ){ |
---|
| 719 | var tabPrefCalendar = jQuery('#preference_tab').html( template ).find('.preferences-win'); |
---|
| 720 | |
---|
| 721 | tabPrefCalendar.find('option[value="'+User.preferences.defaultCalendar+'"]').attr('selected','selected').trigger('change'); |
---|
| 722 | |
---|
| 723 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
| 724 | tabPrefCalendar.find('select[name="timezone"]').html(timezones_options).find('option[value="'+User.preferences.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
| 725 | }); |
---|
| 726 | |
---|
| 727 | tabPrefCalendar.find('.button').button() |
---|
| 728 | .filter('.save').click(function(evt){ |
---|
| 729 | tabPrefCalendar.find('form').submit(); |
---|
| 730 | $('#calendar').fullCalendar('render'); |
---|
| 731 | $('.block-vertical-toolbox .mini-calendar').datepicker( "refresh" ); |
---|
| 732 | $tabs.tabs( "remove", "#preference_tab"); |
---|
| 733 | }).end().filter('.cancel').click(function(evt){ |
---|
| 734 | $tabs.tabs( "remove", "#preference_tab"); |
---|
| 735 | }); |
---|
| 736 | |
---|
| 737 | tabPrefCalendar.find('.number').numeric(); |
---|
| 738 | }); |
---|
| 739 | } else { |
---|
| 740 | $tabs.tabs("select", "#preference_tab"); |
---|
| 741 | |
---|
| 742 | return true; |
---|
| 743 | } |
---|
| 744 | } |
---|
| 745 | |
---|
| 746 | |
---|
| 747 | function add_tab_configure_calendar(calendar) |
---|
| 748 | { |
---|
| 749 | var calendars = []; |
---|
| 750 | var signatures = []; |
---|
| 751 | var previewActiveCalendarConf = 0; |
---|
| 752 | |
---|
| 753 | for (var i=0; i<Calendar.signatures.length; i++) { |
---|
| 754 | calendars[i] = Calendar.signatures[i].calendar; |
---|
| 755 | signatures[i] = Calendar.signatures[i]; |
---|
| 756 | signatures[i].numberDefaultAlarm = signatures[i].defaultAlarms != '' ? signatures[i].defaultAlarms.length: 0; |
---|
| 757 | if (calendar && calendars[i].id == calendar) |
---|
| 758 | previewActiveCalendarConf = i; |
---|
| 759 | } |
---|
| 760 | |
---|
| 761 | if(!(document.getElementById('configure_tab'))) |
---|
| 762 | { |
---|
| 763 | $('.positionHelper').css('display', 'none'); |
---|
| 764 | var tab_title = "Configurações de agendas"; |
---|
| 765 | $tabs.tabs( "add", "#configure_tab", tab_title ); |
---|
| 766 | |
---|
| 767 | var dataColorPicker = { |
---|
| 768 | colorsSuggestions: colors_suggestions() |
---|
| 769 | }; |
---|
| 770 | |
---|
| 771 | |
---|
| 772 | |
---|
| 773 | var populateAccordionOnActive = function(event, ui) { |
---|
| 774 | var nowActive = (typeof(event) == 'number') ? event : $(event.target).accordion( "option", "active" ); |
---|
| 775 | dataColorPicker.colorsDefined = { |
---|
| 776 | border: '#'+signatures[nowActive].borderColor, |
---|
| 777 | font:'#'+signatures[nowActive].fontColor, |
---|
| 778 | background:'#'+signatures[nowActive].backgroundColor |
---|
| 779 | }; |
---|
| 780 | if (!jQuery('.accordion-user-calendars .ui-accordion-content').eq(nowActive).has('form')) { |
---|
| 781 | return true; |
---|
| 782 | } |
---|
| 783 | |
---|
| 784 | DataLayer.render( 'templates/configure_calendars_itemlist.ejs', {user:User, calendar:calendars[nowActive], signature:signatures[nowActive]}, function( form_template ){ |
---|
| 785 | var form_content = jQuery('.accordion-user-calendars .ui-accordion-content').eq(nowActive).html( form_template ).find('form'); |
---|
| 786 | form_content.find('.preferences-alarms-list .button').button({text:false, icons:{primary:'ui-icon-close'}}); |
---|
| 787 | form_content.find('.button').button(); |
---|
| 788 | |
---|
| 789 | DataLayer.render( 'templates/timezone_list.ejs', {}, function( timezones_options ){ |
---|
| 790 | var valueTimeZone = calendars[nowActive].timezone; |
---|
| 791 | form_content.find('select[name="timezone"]').html(timezones_options).find('option[value="'+valueTimeZone+'"]').attr('selected','selected').trigger('change'); |
---|
| 792 | }); |
---|
| 793 | |
---|
| 794 | form_content.find('.button-add-alarms').click(function(){ |
---|
| 795 | DataLayer.render( 'templates/alarms_add_itemlist.ejs', {}, function( template ){ |
---|
| 796 | jQuery('.preferences-alarms-list').append(template) |
---|
| 797 | .find('li:last label:eq(0)').remove().end() |
---|
| 798 | .find('.number').numeric().end() |
---|
| 799 | .find('.button.remove').button({text:false, icons:{primary:'ui-icon-close'}}).click(function(el) { |
---|
| 800 | $(this).parent().remove(); |
---|
| 801 | }); |
---|
| 802 | }); |
---|
| 803 | }); |
---|
| 804 | |
---|
| 805 | |
---|
| 806 | /** |
---|
| 807 | * Set color picker |
---|
| 808 | */ |
---|
| 809 | DataLayer.render( 'templates/calendar_colorpicker.ejs', dataColorPicker, function( template ){ |
---|
| 810 | form_content.find('.calendar-colorpicker').html( template ); |
---|
| 811 | |
---|
| 812 | var f = $.farbtastic(form_content.find('.colorpicker'), colorpickerPreviewChange); |
---|
| 813 | var selected; |
---|
| 814 | var colorpicker = form_content.find('.calendar-colorpicker'); |
---|
| 815 | |
---|
| 816 | var colorpickerPreviewChange = function(color) { |
---|
| 817 | var pickedup = form_content.find('.colorwell-selected').val(color).css('background-color', color); |
---|
| 818 | |
---|
| 819 | var colorpicker = form_content.find('.calendar-colorpicker'); |
---|
| 820 | |
---|
| 821 | if (pickedup.is('input[name="backgroundColor"]')) { |
---|
| 822 | colorpicker.find('.fc-event-skin').css('background-color',color); |
---|
| 823 | } else if (pickedup.is('input[name="fontColor"]')) { |
---|
| 824 | colorpicker.find('.fc-event-skin').css('color',color); |
---|
| 825 | } else if (pickedup.is('input[name="borderColor"]')) { |
---|
| 826 | colorpicker.find('.fc-event-skin').css('border-color',color); |
---|
| 827 | } |
---|
| 828 | } |
---|
| 829 | |
---|
| 830 | form_content.find('.colorwell').each(function () { |
---|
| 831 | f.linkTo(this); |
---|
| 832 | |
---|
| 833 | if ($(this).is('input[name="backgroundColor"]')) { |
---|
| 834 | colorpicker.find('.fc-event-skin').css('background-color', $(this).val()); |
---|
| 835 | } else if ($(this).is('input[name="fontColor"]')) { |
---|
| 836 | colorpicker.find('.fc-event-skin').css('color', $(this).val()); |
---|
| 837 | } else if ($(this).is('input[name="borderColor"]')) { |
---|
| 838 | colorpicker.find('.fc-event-skin').css('border-color', $(this).val()); |
---|
| 839 | } |
---|
| 840 | }) |
---|
| 841 | .focus(function() { |
---|
| 842 | if (selected) { |
---|
| 843 | $(selected).removeClass('colorwell-selected'); |
---|
| 844 | } |
---|
| 845 | |
---|
| 846 | $(selected = this).addClass('colorwell-selected'); |
---|
| 847 | f.linkTo(this, colorpickerPreviewChange); |
---|
| 848 | f.linkTo(colorpickerPreviewChange); |
---|
| 849 | |
---|
| 850 | }); |
---|
| 851 | |
---|
| 852 | form_content.find('select.color-suggestions').change(function() { |
---|
| 853 | var colors; |
---|
| 854 | |
---|
| 855 | if(colors = dataColorPicker.colorsSuggestions[$(this).val()]) { |
---|
| 856 | colorpicker |
---|
| 857 | .find('input[name="fontColor"]').val(colors.font).focus().end() |
---|
| 858 | .find('input[name="backgroundColor"]').val(colors.background).focus().end() |
---|
| 859 | .find('input[name="borderColor"]').val(colors.border).focus().end() |
---|
| 860 | |
---|
| 861 | .find('.fc-event-skin').css({ |
---|
| 862 | 'background-color':dataColorPicker.colorsSuggestions[$(this).val()].background, |
---|
| 863 | 'border-color':dataColorPicker.colorsSuggestions[$(this).val()].border, |
---|
| 864 | 'color':dataColorPicker.colorsSuggestions[$(this).val()].font |
---|
| 865 | }); |
---|
| 866 | } |
---|
| 867 | }); |
---|
| 868 | |
---|
| 869 | /** |
---|
| 870 | * Trata a mudança dos valores dos campos de cores. |
---|
| 871 | * Se mudar um conjunto de cores sugerido, |
---|
| 872 | * este vira um conjunto de cores personalizado. |
---|
| 873 | */ |
---|
| 874 | form_content.find('.colorwell').change(function (element, ui) { |
---|
| 875 | if (true) { |
---|
| 876 | form_content.find('select.color-suggestions') |
---|
| 877 | .find('option:selected').removeAttr('selected').end() |
---|
| 878 | .find('option[value="custom"]').attr('selected', 'selected').trigger('change'); |
---|
| 879 | } |
---|
| 880 | }); |
---|
| 881 | }); //END set colorpicker |
---|
| 882 | |
---|
| 883 | form_content.find('.phone').mask("+99 (99) 9999-9999"); |
---|
| 884 | form_content.find('.number').numeric(); |
---|
| 885 | |
---|
| 886 | }); //END DataLayer.render( 'templates/configure_calendars_itemlist.ejs' ... |
---|
| 887 | |
---|
| 888 | // === validations preferences ==== |
---|
| 889 | |
---|
| 890 | |
---|
| 891 | } //END populateAccordionOnActive(event, ui) |
---|
| 892 | |
---|
| 893 | |
---|
| 894 | DataLayer.render( 'templates/configure_calendars.ejs', {user:User, calendars:calendars, signatures:signatures}, function( template ){ |
---|
| 895 | var template_content = jQuery('#configure_tab').html( template ).find('.configure-calendars-win'); |
---|
| 896 | template_content.find('.button').button().filter('.save').click(function(evt){ |
---|
| 897 | template_content.find('form').submit(); |
---|
| 898 | $tabs.tabs( "remove", "#configure_tab"); |
---|
| 899 | }).end().filter('.cancel').click(function(evt){ |
---|
| 900 | $tabs.tabs( "remove", "#configure_tab"); |
---|
| 901 | }); |
---|
| 902 | |
---|
| 903 | /** |
---|
| 904 | * Muda a estrutura do template para a aplicação do plugin accordion |
---|
| 905 | */ |
---|
| 906 | template_content.find('.header-menu-container').after('<div class="accordion-user-calendars"></div>').end().find('.accordion-user-calendars') |
---|
| 907 | .append(template_content.children('fieldset')); |
---|
| 908 | |
---|
| 909 | template_content.find('.accordion-user-calendars').children('fieldset').each(function(index) { |
---|
| 910 | $(this).before($('<h3></h3>').html($(this).children('legend'))); |
---|
| 911 | }); |
---|
| 912 | |
---|
| 913 | template_content.find('.accordion-user-calendars').accordion({ |
---|
| 914 | autoHeight: false, |
---|
| 915 | collapsible: true, |
---|
| 916 | clearStyle: true, |
---|
| 917 | active: previewActiveCalendarConf, |
---|
| 918 | changestart: populateAccordionOnActive |
---|
| 919 | }); |
---|
| 920 | populateAccordionOnActive(previewActiveCalendarConf); |
---|
| 921 | }); |
---|
| 922 | |
---|
| 923 | } else { |
---|
| 924 | |
---|
| 925 | $tabs.tabs("select", "#configure_tab"); |
---|
| 926 | $('.accordion-user-calendars').accordion( "activate" , previewActiveCalendarConf ); |
---|
| 927 | |
---|
| 928 | return true; |
---|
| 929 | } |
---|
| 930 | |
---|
| 931 | } |
---|
| 932 | |
---|
| 933 | function getNotSelectedCalendars(){ |
---|
| 934 | var selecteds = {}; |
---|
| 935 | var cont = 0; |
---|
| 936 | jQuery(function() { |
---|
| 937 | jQuery(".my-calendars .calendar-view").each(function(i, obj) { |
---|
| 938 | var check_box = obj; |
---|
| 939 | if(!check_box.checked) { |
---|
| 940 | selecteds[cont] = obj.value; |
---|
| 941 | cont++; |
---|
| 942 | }; |
---|
| 943 | }); |
---|
| 944 | }); |
---|
| 945 | if (!cont) |
---|
| 946 | return false; |
---|
| 947 | |
---|
| 948 | selecteds.length = cont; |
---|
| 949 | return $.makeArray( selecteds ); |
---|
| 950 | } |
---|
| 951 | |
---|
| 952 | function getSelectedCalendars(){ |
---|
| 953 | var selecteds = {}; |
---|
| 954 | var cont = 0; |
---|
| 955 | jQuery(function() { |
---|
| 956 | jQuery(".my-calendars .calendar-view").each(function(i, obj) { |
---|
| 957 | var check_box = obj; |
---|
| 958 | if(check_box.checked) { |
---|
| 959 | selecteds[cont] = obj.value; |
---|
| 960 | cont++; |
---|
| 961 | }; |
---|
| 962 | }); |
---|
| 963 | }); |
---|
| 964 | if (!cont) |
---|
| 965 | return false; |
---|
| 966 | |
---|
| 967 | selecteds.length = cont; |
---|
| 968 | return $.makeArray( selecteds ); |
---|
| 969 | } |
---|
| 970 | |
---|
| 971 | /** |
---|
| 972 | * TODO - transformar em preferência do módulo e criar telas de adição e exclusão de conjunto de cores |
---|
| 973 | */ |
---|
| 974 | function colors_suggestions(){ |
---|
| 975 | return [ |
---|
| 976 | {name:'Padrão', border:'#3366cc', font:'#ffffff', background:'#3366cc'}, |
---|
| 977 | {name:'Coala', border:'#123456', font:'#ffffff', background:'#385c80'}, |
---|
| 978 | {name:'Tomate', border:'#d5130b', font:'#111111', background:'#e36d76'}, |
---|
| 979 | {name:'Limão', border:'#32ed21', font:'#1f3f1c', background:'#b2f1ac'}, |
---|
| 980 | {name:'Alto contraste', border:'#000000', font:'#ffffff', background:'#222222'} |
---|
| 981 | ] |
---|
| 982 | } |
---|
| 983 | |
---|
| 984 | function remove_calendar(){ |
---|
| 985 | /* Pode ser assim $('.cal-list-options-btn.ui-state-active').attr('class').replace(/[a-zA-Z-]+/g, ''); */ |
---|
| 986 | $.Zebra_Dialog('Todos os eventos desta agenda serão apagados. Deseja prosseguir com a operação ?', { |
---|
| 987 | 'type': 'question', |
---|
| 988 | 'overlay_opacity': '0.5', |
---|
| 989 | 'buttons': ['Sim', 'Não'], |
---|
| 990 | 'onClose': function(clicked) { |
---|
| 991 | if(clicked == 'Sim'){ |
---|
| 992 | var idCalendar = $('.cal-list-options-btn.ui-state-active').attr('class').match(/[0-9]+/g); |
---|
| 993 | var signature = ''; |
---|
| 994 | for(var i =0; i < Calendar.signatures.length; i++){ |
---|
| 995 | if(idCalendar[0] == Calendar.signatures[i].calendar.id){ |
---|
| 996 | signature = Calendar.signatures[i].id; |
---|
| 997 | break; |
---|
| 998 | } |
---|
| 999 | } |
---|
| 1000 | DataLayer.remove('calendarSignature', signature); |
---|
| 1001 | $('.positionHelper').css('display', 'none'); |
---|
| 1002 | }else{ |
---|
| 1003 | $('.positionHelper').css('display', 'none'); |
---|
| 1004 | } |
---|
| 1005 | } |
---|
| 1006 | }); |
---|
| 1007 | } |
---|
| 1008 | |
---|
| 1009 | function refresh_calendars(){ |
---|
| 1010 | |
---|
| 1011 | var colorsSuggestions = colors_suggestions(); |
---|
| 1012 | var buttons_colors = ""; |
---|
| 1013 | for(var i = 0; i < colorsSuggestions.length; i++){ |
---|
| 1014 | 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>"; |
---|
| 1015 | } |
---|
| 1016 | |
---|
| 1017 | //DataLayer.render( 'templates/calendar_list.ejs', 'calendar:list', ["IN", "id", Calendar.calendarIds], function( html ){ |
---|
| 1018 | DataLayer.render( 'templates/calendar_list.ejs', Calendar, function( html ){ |
---|
| 1019 | |
---|
| 1020 | var meu_container = $(".calendars-list").html( html ); |
---|
| 1021 | |
---|
| 1022 | $('ul.list-calendars .cal-list-options-btn').each(function(){ |
---|
| 1023 | $(this).menu({ |
---|
| 1024 | content: $(this).next().html(), |
---|
| 1025 | width: '120', |
---|
| 1026 | positionOpts: { |
---|
| 1027 | posX: 'left', |
---|
| 1028 | posY: 'bottom', |
---|
| 1029 | offsetX: 0, |
---|
| 1030 | offsetY: 0, |
---|
| 1031 | directionH: 'right', |
---|
| 1032 | directionV: 'down', |
---|
| 1033 | detectH: true, // do horizontal collision detection |
---|
| 1034 | detectV: true, // do vertical collision detection |
---|
| 1035 | linkToFront: false |
---|
| 1036 | }, |
---|
| 1037 | flyOut: true, |
---|
| 1038 | showSpeed: 100, |
---|
| 1039 | crumbDefaultText: '>' |
---|
| 1040 | }); |
---|
| 1041 | }); |
---|
| 1042 | |
---|
| 1043 | |
---|
| 1044 | meu_container.find(".button.new").button({ |
---|
| 1045 | icons: { |
---|
| 1046 | primary: "ui-icon-plus" |
---|
| 1047 | }, |
---|
| 1048 | text: false |
---|
| 1049 | }).click(function () { |
---|
| 1050 | |
---|
| 1051 | if( $('.qtip.qtip-blue.qtip-active').val() !== ''){ |
---|
| 1052 | $(this).qtip({ |
---|
| 1053 | show: {ready: true, solo: true, when: {event: 'click'}}, |
---|
| 1054 | hide: false, |
---|
| 1055 | content: { |
---|
| 1056 | text: $('<div></div>').html( DataLayer.render( 'templates/calendar_quick_add.ejs', {} ) ), |
---|
| 1057 | title: { |
---|
| 1058 | text:'Nova Agenda', |
---|
| 1059 | button: '<a class="button close" href="#">close</a>' |
---|
| 1060 | } |
---|
| 1061 | }, |
---|
| 1062 | style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}}, |
---|
| 1063 | position: { |
---|
| 1064 | corner: { |
---|
| 1065 | target: 'rightMiddle', |
---|
| 1066 | tooltip: 'leftMiddle' |
---|
| 1067 | }, |
---|
| 1068 | adjust: {x:0, y:-12} |
---|
| 1069 | } |
---|
| 1070 | }) |
---|
| 1071 | .qtip("api").onShow = function(arg0) { |
---|
| 1072 | $('.qtip-active .button.close').button({ |
---|
| 1073 | icons: {primary: "ui-icon-close"}, |
---|
| 1074 | text: false |
---|
| 1075 | }) |
---|
| 1076 | .click(function(){ |
---|
| 1077 | meu_container.find(".button.new").qtip('destroy'); |
---|
| 1078 | }); |
---|
| 1079 | //TODO emplementar tratamento de duplicação de valores no location |
---|
| 1080 | $('.qtip-active .button.save').button().click(function(){ |
---|
| 1081 | for(var i = 0; i < Calendar.calendars.length; i++){ |
---|
| 1082 | if(Calendar.calendars[i].location == $('.qtip-active input').val()){ |
---|
| 1083 | $.Zebra_Dialog('O nome desta agenda já está sendo utilizada em uma Url de outra agenda. Por favor, informe outro nome para agenda.',{ |
---|
| 1084 | 'overlay_opacity': '0.5', |
---|
| 1085 | 'type': 'warning' |
---|
| 1086 | }); |
---|
| 1087 | meu_container.find(".button.new").qtip('destroy'); |
---|
| 1088 | return; |
---|
| 1089 | } |
---|
| 1090 | } |
---|
| 1091 | |
---|
| 1092 | var selected; |
---|
| 1093 | var color = $('.cal-colors-options-btn').each(function(index){ |
---|
| 1094 | if ($(this).is('.color-selected')) |
---|
| 1095 | selected = index; |
---|
| 1096 | }); |
---|
| 1097 | DataLayer.put( "calendarSignature", { |
---|
| 1098 | user: User.me.id, |
---|
| 1099 | calendar: { |
---|
| 1100 | name: $('.qtip-active input').val(), |
---|
| 1101 | timezone: User.preferences.timezone |
---|
| 1102 | }, |
---|
| 1103 | isOwner: 1, |
---|
| 1104 | fontColor: colorsSuggestions[selected]['font'].substring(1) , |
---|
| 1105 | backgroundColor: colorsSuggestions[selected]['background'].substring(1) , |
---|
| 1106 | borderColor: colorsSuggestions[selected]['border'].substring(1) |
---|
| 1107 | }); |
---|
| 1108 | meu_container.find(".button.new").qtip('destroy'); |
---|
| 1109 | }); |
---|
| 1110 | |
---|
| 1111 | $('.qtip-active .button.cancel').button().click(function(){ |
---|
| 1112 | meu_container.find(".button.new").qtip('destroy'); |
---|
| 1113 | }); |
---|
| 1114 | |
---|
| 1115 | $(".qtip-active input").Watermark("Nome da agenda"); |
---|
| 1116 | |
---|
| 1117 | $('.qtip-active').keydown(function(event) { |
---|
| 1118 | if (event.keyCode == '27') { |
---|
| 1119 | meu_container.find(".button.new").qtip('destroy'); |
---|
| 1120 | } |
---|
| 1121 | }); |
---|
| 1122 | |
---|
| 1123 | $('.colors-options').prepend(buttons_colors); |
---|
| 1124 | $('.colors-options .signed-cal-colors-options-btn-0').addClass('color-selected'); |
---|
| 1125 | |
---|
| 1126 | var buttons = $('.cal-colors-options-btn').button(); |
---|
| 1127 | |
---|
| 1128 | buttons.click(function(){ |
---|
| 1129 | buttons.removeClass('color-selected'); |
---|
| 1130 | $(this).addClass('color-selected'); |
---|
| 1131 | }); |
---|
| 1132 | } |
---|
| 1133 | } |
---|
| 1134 | }); |
---|
| 1135 | |
---|
| 1136 | $("img.cal-list-img").click(function(evt) { |
---|
| 1137 | $(".cal-list-options_1").toggleClass( "hidden" ); |
---|
| 1138 | }); |
---|
| 1139 | |
---|
| 1140 | $(".my-calendars a.title-my-calendars").click(function() { |
---|
| 1141 | $(".my-calendars ul.my-list-calendars").toggleClass("hidden") |
---|
| 1142 | $('.my-calendars .status-list').toggleClass("ui-icon-triangle-1-s"); |
---|
| 1143 | $('.my-calendars .status-list').toggleClass("ui-icon-triangle-1-e"); |
---|
| 1144 | }); |
---|
| 1145 | |
---|
| 1146 | $(".signed-calendars a.title-signed-calendars").click(function() { |
---|
| 1147 | $(".signed-calendars ul.signed-list-calendars").toggleClass( "hidden"); |
---|
| 1148 | }); |
---|
| 1149 | |
---|
| 1150 | $("ul li.list-calendars-item").click(function(evt) { |
---|
| 1151 | |
---|
| 1152 | }); |
---|
| 1153 | |
---|
| 1154 | $("ul li.list-calendars-item .ui-corner-all").click(function(evt) { |
---|
| 1155 | //alert('teste'); |
---|
| 1156 | }); |
---|
| 1157 | |
---|
| 1158 | $('.calendar-view').click(function(evt){ |
---|
| 1159 | if($tabs.tabs('option' ,'selected') == 1){ |
---|
| 1160 | pageselectCallback('', 0); |
---|
| 1161 | } |
---|
| 1162 | |
---|
| 1163 | if(Calendar.currentView){ |
---|
| 1164 | var checkBox = $(this); |
---|
| 1165 | Calendar.currentView[ checkBox.val() ].hidden = !checkBox.is(':checked'); |
---|
| 1166 | $('#calendar').fullCalendar( 'refetchEvents' ); |
---|
| 1167 | } |
---|
| 1168 | }); |
---|
| 1169 | }); |
---|
| 1170 | } |
---|
| 1171 | |
---|
| 1172 | function add_events_list(keyword) |
---|
| 1173 | { |
---|
| 1174 | var tab_title = ""; |
---|
| 1175 | if (keyword){ |
---|
| 1176 | if(keyword.length < 10) |
---|
| 1177 | tab_title = keyword; |
---|
| 1178 | else |
---|
| 1179 | tab_title = keyword.substr(0,10) + '..."'; |
---|
| 1180 | }else{ |
---|
| 1181 | tab_title = "Lista de eventos"; |
---|
| 1182 | } |
---|
| 1183 | keyword = ( keyword || '' ).replace( /\s+/g, "_" ); |
---|
| 1184 | |
---|
| 1185 | if(!(document.getElementById('tab_events_list_' + (Base64.encode(keyword)).replace(/[^\w\s]/gi, "") ))) |
---|
| 1186 | { |
---|
| 1187 | Encoder.EncodeType = "entity"; |
---|
| 1188 | $tabs.tabs( "add", "#tab_events_list_" + (Base64.encode(keyword)).replace(/[^\w\s]/gi, ""), Encoder.htmlEncode(tab_title) ); |
---|
| 1189 | } |
---|
| 1190 | else /* Tab already opened */ |
---|
| 1191 | { |
---|
| 1192 | $tabs.tabs("option", "selected", 2); |
---|
| 1193 | } |
---|
| 1194 | |
---|
| 1195 | pageselectCallback(keyword, 0); // load page 1 and insert data on event_list.ejs |
---|
| 1196 | |
---|
| 1197 | $('.preferences-win.active .button.save, .preferences-win.active .button.cancel, .preferences-win.active .button.import, .preferences-win.active .button.export').button(); |
---|
| 1198 | } |
---|
| 1199 | |
---|
| 1200 | function paginatorSearch(currentView){ |
---|
| 1201 | if(parseInt($(currentView+' [name = results]').val()) > 25){ |
---|
| 1202 | $(currentView+' .header-paginator .fc-header-left .fc-button.fc-button-next .fc-button-inner').hover( |
---|
| 1203 | function(){ |
---|
| 1204 | $(this).addClass('fc-state-hover'); |
---|
| 1205 | }, |
---|
| 1206 | function(){ |
---|
| 1207 | $(this).removeClass('fc-state-hover'); |
---|
| 1208 | }).mousedown(function(){ |
---|
| 1209 | $(this).addClass('fc-state-down'); |
---|
| 1210 | }).mouseup(function(){ |
---|
| 1211 | $(this).removeClass('fc-state-down'); |
---|
| 1212 | $('.events-list.events-list-win.active').removeClass('active'); |
---|
| 1213 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($('[name = page_index]').val())) +1)); |
---|
| 1214 | }); |
---|
| 1215 | } |
---|
| 1216 | if(parseInt($(currentView+' [name = page_index]').val()) > 0){ |
---|
| 1217 | $(currentView+' .header-paginator .fc-header-left .fc-button.fc-button-prev .fc-button-inner').hover( |
---|
| 1218 | function(){ |
---|
| 1219 | $(this).addClass('fc-state-hover'); |
---|
| 1220 | }, |
---|
| 1221 | function(){ |
---|
| 1222 | $(this).removeClass('fc-state-hover'); |
---|
| 1223 | }).mousedown(function(){ |
---|
| 1224 | $(this).addClass('fc-state-down'); |
---|
| 1225 | }).mouseup(function(){ |
---|
| 1226 | $(this).removeClass('fc-state-down'); |
---|
| 1227 | $('.events-list.events-list-win.active').removeClass('active'); |
---|
| 1228 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($('[name = page_index]').val())) -1)); |
---|
| 1229 | }); |
---|
| 1230 | } |
---|
| 1231 | } |
---|
| 1232 | |
---|
| 1233 | function mountTitleList(page_index ,view){ |
---|
| 1234 | switch (view){ |
---|
| 1235 | case 'day': |
---|
[5345] | 1236 | case 'basicDay': |
---|
[5341] | 1237 | var date = new Date().add({days: page_index}); |
---|
| 1238 | return (weekOfDay(date.getDay()))+", "+(date.toString('dd MMM yyyy')); |
---|
[5345] | 1239 | case 'agendaWeek': |
---|
[5341] | 1240 | case 'week': |
---|
| 1241 | var dateStart = new Date().moveToDayOfWeek(dayOfWeek(User.preferences.weekDefault)); |
---|
| 1242 | dateStart.add({days: (7 * page_index)}); |
---|
| 1243 | var dateEnd = new Date().moveToDayOfWeek(dayOfWeek(User.preferences.weekDefault)); |
---|
| 1244 | dateEnd.add({days: (page_index * 7)+7}); |
---|
| 1245 | if(dateStart.toString('MM') != dateEnd.toString('MM')) |
---|
| 1246 | return dateStart.toString('dd')+' de '+sortMonthOfNumber(dateStart.getMonth())+' a '+dateEnd.toString('dd')+' de '+monthOfNumber(dateEnd.getMonth())+' - '+dateEnd.toString('yyyy'); |
---|
| 1247 | return +dateStart.toString("dd")+" a "+dateEnd.toString("dd")+" de "+monthOfNumber(dateEnd.getMonth())+" - "+dateEnd.toString('yyyy'); |
---|
| 1248 | case 'month': |
---|
| 1249 | var date = new Date().add({months: page_index}) |
---|
| 1250 | return monthOfNumber(date.getMonth())+" "+date.toString("yyyy"); |
---|
| 1251 | case 'year': |
---|
| 1252 | var date = new Date().add({years: page_index}); |
---|
| 1253 | return date.toString("yyyy"); |
---|
| 1254 | } |
---|
| 1255 | } |
---|
| 1256 | |
---|
| 1257 | function paginatorList(currentView, view){ |
---|
| 1258 | $(currentView+' .events-list.events-list-win.active .list-events-paginator .fc-header-title').html('<h2>'+mountTitleList( parseInt($('[name = page_index]').val()),view)+'</h2>'); |
---|
| 1259 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
[5345] | 1260 | if(view == 'basicDay') |
---|
| 1261 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button-agendaday').addClass('fc-state-active'); |
---|
| 1262 | else |
---|
| 1263 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button-'+((view == 'day' || view == 'week') ? 'agenda'+view : view )).addClass('fc-state-active'); |
---|
[5341] | 1264 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right').addClass('list-right'); |
---|
| 1265 | $(currentView+' .header-paginator .fc-header-right .fc-button-agendaday').hover( |
---|
| 1266 | function(){ |
---|
| 1267 | $(this).addClass('fc-state-hover'); |
---|
| 1268 | }, |
---|
| 1269 | function(){ |
---|
| 1270 | $(this).removeClass('fc-state-hover'); |
---|
| 1271 | }).mousedown(function(){ |
---|
| 1272 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
| 1273 | $(this).addClass('fc-state-active'); |
---|
| 1274 | }).mouseup(function(){ |
---|
| 1275 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'day'); |
---|
| 1276 | }); |
---|
| 1277 | |
---|
| 1278 | $(currentView+' .header-paginator .fc-header-right .fc-button-agendaweek').hover( |
---|
| 1279 | function(){ |
---|
| 1280 | $(this).addClass('fc-state-hover'); |
---|
| 1281 | }, |
---|
| 1282 | function(){ |
---|
| 1283 | $(this).removeClass('fc-state-hover'); |
---|
| 1284 | }).mousedown(function(){ |
---|
| 1285 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
| 1286 | $(this).addClass('fc-state-active'); |
---|
| 1287 | }).mouseup(function(){ |
---|
| 1288 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'week'); |
---|
| 1289 | }); |
---|
| 1290 | |
---|
| 1291 | $(currentView+' .header-paginator .fc-header-right .fc-button-month').hover( |
---|
| 1292 | function(){ |
---|
| 1293 | $(this).addClass('fc-state-hover'); |
---|
| 1294 | }, |
---|
| 1295 | function(){ |
---|
| 1296 | $(this).removeClass('fc-state-hover'); |
---|
| 1297 | }).mousedown(function(){ |
---|
| 1298 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
| 1299 | $(this).addClass('fc-state-active'); |
---|
| 1300 | }).mouseup(function(){ |
---|
| 1301 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'month'); |
---|
| 1302 | }); |
---|
| 1303 | |
---|
| 1304 | $(currentView+' .header-paginator .fc-header-right .fc-button-year').hover( |
---|
| 1305 | function(){ |
---|
| 1306 | $(this).addClass('fc-state-hover'); |
---|
| 1307 | }, |
---|
| 1308 | function(){ |
---|
| 1309 | $(this).removeClass('fc-state-hover'); |
---|
| 1310 | }).mousedown(function(){ |
---|
| 1311 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') |
---|
| 1312 | $(this).addClass('fc-state-active'); |
---|
| 1313 | }).mouseup(function(){ |
---|
| 1314 | pageselectCallback($(currentView+' [name = keyword]').val(), 0, '', 'year'); |
---|
| 1315 | }); |
---|
| 1316 | |
---|
| 1317 | |
---|
| 1318 | $(currentView+' .header-paginator .fc-header-left .fc-button.fc-button-next .fc-button-inner').hover( |
---|
| 1319 | function(){ |
---|
| 1320 | $(this).addClass('fc-state-hover'); |
---|
| 1321 | }, |
---|
| 1322 | function(){ |
---|
| 1323 | $(this).removeClass('fc-state-hover'); |
---|
| 1324 | }).mousedown(function(){ |
---|
| 1325 | $(this).addClass('fc-state-down'); |
---|
| 1326 | }).mouseup(function(){ |
---|
| 1327 | $(this).removeClass('fc-state-down'); |
---|
| 1328 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($('[name = page_index]').val())) +1), '', view); |
---|
| 1329 | }); |
---|
| 1330 | |
---|
| 1331 | $(currentView+' .header-paginator .fc-header-left .fc-button.fc-button-prev .fc-button-inner').hover( |
---|
| 1332 | function(){ |
---|
| 1333 | $(this).addClass('fc-state-hover'); |
---|
| 1334 | }, |
---|
| 1335 | function(){ |
---|
| 1336 | $(this).removeClass('fc-state-hover'); |
---|
| 1337 | }).mousedown(function(){ |
---|
| 1338 | $(this).addClass('fc-state-down'); |
---|
| 1339 | }).mouseup(function(){ |
---|
| 1340 | $(this).removeClass('fc-state-down'); |
---|
| 1341 | pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($('[name = page_index]').val())) -1), '', view); |
---|
| 1342 | }); |
---|
| 1343 | } |
---|
| 1344 | |
---|
| 1345 | function paginatorListEvent(currentView, typeView, view){ |
---|
| 1346 | if(!!$(currentView).find('.fc-calendar').length) |
---|
| 1347 | return; |
---|
| 1348 | $(currentView+' .events-list.events-list-win.active').prepend($('.fc-header').clone()); |
---|
| 1349 | //Remove contudo nao utilizado |
---|
| 1350 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-today').remove(); |
---|
| 1351 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-basicWeek').remove(); |
---|
| 1352 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-basicDay').remove(); |
---|
| 1353 | |
---|
| 1354 | //Adiciona e remove as classes para esta visualizacao |
---|
| 1355 | $(currentView+' .events-list.events-list-win.active .fc-header .fc-header-center').addClass('list-events-paginator'); |
---|
| 1356 | $(currentView+' .events-list.events-list-win.active .fc-header .list-events-paginator').removeClass('fc-header-center'); |
---|
| 1357 | |
---|
| 1358 | //Adicionar class no header padronizar com a tela principal |
---|
| 1359 | $(currentView+' .events-list.events-list-win.active .fc-header').addClass('header-paginator'); |
---|
| 1360 | $(currentView+' .events-list.events-list-win.active .header-paginator').removeClass('fc-header'); |
---|
| 1361 | |
---|
| 1362 | if(typeView == 'search'){ |
---|
| 1363 | $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right').remove() |
---|
| 1364 | $(currentView+' .events-list.events-list-win.active .list-events-paginator .fc-header-title').html('<h2>Resultados para: '+$(currentView+' [name = keyword]').val()+'</h2>'); |
---|
| 1365 | if((parseInt($(currentView+' [name = page_index]').val()) == 0) && (parseInt($(currentView+' [name = results]').val()) <= 25)) |
---|
| 1366 | return; |
---|
| 1367 | paginatorSearch(currentView); |
---|
| 1368 | }else |
---|
| 1369 | paginatorList(currentView, view); |
---|
| 1370 | } |
---|
| 1371 | |
---|
| 1372 | function mountCriteriaList(view, page_index, calerdars_selecteds){ |
---|
| 1373 | switch (view){ |
---|
[5345] | 1374 | case 'basicDay': |
---|
[5341] | 1375 | case 'day': |
---|
| 1376 | return {filter: ['AND', ['IN', 'calendar', calerdars_selecteds], ['=', 'rangeEnd', new Date().add({days: page_index}).toString("yyyy-MM-dd")]], criteria: {order: 'startTime'}}; |
---|
[5345] | 1377 | case 'agendaWeek': |
---|
[5341] | 1378 | case 'week': |
---|
| 1379 | var dateStart = new Date().moveToDayOfWeek(dayOfWeek(User.preferences.weekDefault)); |
---|
| 1380 | var dateEnd = new Date().moveToDayOfWeek(dayOfWeek(User.preferences.weekDefault)); |
---|
| 1381 | return {filter: ['AND', ['IN', 'calendar', calerdars_selecteds], ['AND',['>=', 'rangeEnd', dateStart.add({days: (7 * page_index)}).toString("yyyy-MM-dd")], ['<=', 'rangeEnd', dateEnd.add({days: (7 * page_index)+7}).toString("yyyy-MM-dd")]]], criteria: {order: 'startTime'}}; |
---|
| 1382 | case 'month': |
---|
| 1383 | var date = new Date().add({months: page_index}) |
---|
| 1384 | return {filter: ['AND',['IN', 'calendar', calerdars_selecteds], ['AND',['>=', 'rangeEnd', date.moveToFirstDayOfMonth().toString("yyyy-MM-dd")], ['<=', 'rangeEnd', date.moveToLastDayOfMonth().toString("yyyy-MM-dd")]]], criteria: {order: 'startTime'}}; |
---|
| 1385 | case 'year': |
---|
| 1386 | var dateStart = new Date().add({years: page_index}); |
---|
| 1387 | var dateEnd = new Date().add({years: page_index}); |
---|
| 1388 | if(dateStart.getMonth() != 0) |
---|
| 1389 | dateStart.moveToMonth(0, -1) |
---|
| 1390 | if(dateEnd.getMonth() != 11) |
---|
| 1391 | dateEnd.moveToMonth(11) |
---|
| 1392 | return {filter: ['AND', ['IN', 'calendar', calerdars_selecteds], ['AND',['>=', 'rangeEnd', dateStart.moveToFirstDayOfMonth().toString("yyyy-MM-dd")], ['<=', 'rangeEnd', dateEnd.moveToLastDayOfMonth().toString("yyyy-MM-dd")]]], criteria: {order: 'startTime'}}; |
---|
| 1393 | } |
---|
| 1394 | } |
---|
| 1395 | |
---|
| 1396 | function pageselectCallback(keyword, page_index, jq, view){ |
---|
| 1397 | |
---|
| 1398 | var selecteds = getSelectedCalendars(); |
---|
| 1399 | if(!selecteds && (keyword != '' && keyword != null)){ |
---|
| 1400 | jQuery('#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( |
---|
| 1401 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
| 1402 | '<label>Por favor selecione ao menos uma agenda.</label>' + |
---|
| 1403 | '</div>' |
---|
| 1404 | ); |
---|
| 1405 | }else{ |
---|
| 1406 | var criteria = null; |
---|
| 1407 | if(keyword == '' || keyword == null) |
---|
| 1408 | criteria = mountCriteriaList(!!view ? view : User.preferences.defaultCalView, page_index, selecteds) |
---|
| 1409 | else |
---|
| 1410 | criteria = {filter: ['AND', ['OR', ["i*", "summary", keyword], ["i*", "description", keyword]], ['IN', 'calendar', selecteds]], criteria: {order: 'startTime', offset: (25 * page_index), limit: (((25 * page_index) + 25) + 1)}}; |
---|
| 1411 | var results = DataLayer.get('schedulable:detail', criteria); |
---|
| 1412 | keyword = ( keyword || '' ).replace( /\s+/g, "_" ); |
---|
| 1413 | } |
---|
| 1414 | // não há resultados |
---|
| 1415 | if ((((typeof(results) == 'undefined') || (!results.events_list )) && selecteds) &&(keyword != '' && keyword != null)) { |
---|
| 1416 | jQuery('#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( |
---|
| 1417 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
| 1418 | '<label>Não foi encontrado nenhum evento correspondente à sua pesquisa.</label>' + |
---|
| 1419 | '</div>' |
---|
| 1420 | ); |
---|
| 1421 | // há resultados e Agendas Selecionadas |
---|
| 1422 | } else{ |
---|
| 1423 | if(typeof(results) != 'undefined'){ |
---|
| 1424 | results['page_index'] = page_index; |
---|
| 1425 | results['keyword'] = keyword; |
---|
| 1426 | |
---|
| 1427 | DataLayer.render( 'templates/event_list.ejs', results, function( html ){ |
---|
| 1428 | var currentView = '#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "") || ''); |
---|
| 1429 | jQuery(currentView).html( html ); |
---|
| 1430 | jQuery('.events-list-win .menu-container .button').button(); |
---|
| 1431 | |
---|
| 1432 | $(".event-details-item").parent().click(function(){ |
---|
| 1433 | |
---|
| 1434 | $(this).siblings("div.details-event-list").toggleClass("hidden") |
---|
| 1435 | .find('.button.delete').click(function(){ |
---|
| 1436 | DataLayer.remove('schedulable', $(this).siblings('[name="eventid"]').val()); |
---|
| 1437 | }) |
---|
| 1438 | .end().find('.button.edit').click(function(){ |
---|
| 1439 | eventDetails( DataLayer.get( "schedulable", $(this).siblings('[name="eventid"]').val() ), true ); |
---|
| 1440 | }); |
---|
| 1441 | |
---|
| 1442 | }); |
---|
| 1443 | paginatorListEvent(currentView, (keyword == '' || keyword == null) ? 'list' : 'search', !!view ? view : User.preferences.defaultCalView); |
---|
| 1444 | }); |
---|
| 1445 | }else{ |
---|
| 1446 | var currentView = '#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "") || ''); |
---|
| 1447 | jQuery('#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( |
---|
| 1448 | '<div title="Lista de eventos" class="events-list events-list-win active empty">' + |
---|
| 1449 | '<input type="hidden" name="page_index" value="'+page_index+'"></inpunt>'+ |
---|
| 1450 | '<input type="hidden" name="keyword" value="'+keyword+'"></inpunt>'+ |
---|
| 1451 | '<label>Não foram encontrados eventos neste intervalo.</label>' + |
---|
| 1452 | '</div>' |
---|
| 1453 | ); |
---|
| 1454 | paginatorListEvent(currentView, 'list', !!view ? view : User.preferences.defaultCalView); |
---|
| 1455 | } |
---|
| 1456 | |
---|
| 1457 | } |
---|
| 1458 | |
---|
| 1459 | } |
---|
| 1460 | |
---|
| 1461 | function show_modal_import_export(tab) { |
---|
| 1462 | DataLayer.render( 'templates/import_export.ejs', {calendars: Calendar.calendars, owner: User.me.id}, function( html ){ |
---|
| 1463 | |
---|
| 1464 | if (!UI.dialogs.importCalendar) { |
---|
| 1465 | UI.dialogs.importCalendar = jQuery('#div-import-export-calendar') |
---|
| 1466 | .append('<div title="Importar e Exportar Eventos" class="import-export import-export-win active"> <div>') |
---|
| 1467 | .find('.import-export-win.active').html(html).dialog({ |
---|
| 1468 | resizable: false, |
---|
| 1469 | modal:true, |
---|
| 1470 | width:500, |
---|
| 1471 | position: 'center' |
---|
| 1472 | }); |
---|
| 1473 | |
---|
| 1474 | } else { |
---|
| 1475 | UI.dialogs.importCalendar.html(html); |
---|
| 1476 | } |
---|
| 1477 | |
---|
| 1478 | var tabsImportExport = UI.dialogs.importCalendar.find(".tabs-import-export").tabs({selected: tab}); |
---|
| 1479 | |
---|
| 1480 | UI.dialogs.importCalendar.find('.button').button(); |
---|
| 1481 | |
---|
| 1482 | UI.dialogs.importCalendar.find(".menu-import-event") |
---|
| 1483 | .children(".import").click(function(){ |
---|
| 1484 | |
---|
| 1485 | $('.import-event-form', UI.dialogs.importCalendar).submit(); |
---|
| 1486 | UI.dialogs.importCalendar.dialog("close"); |
---|
| 1487 | /** |
---|
| 1488 | * TODO - implementar ação de importação |
---|
| 1489 | */ |
---|
| 1490 | }); |
---|
| 1491 | |
---|
| 1492 | UI.dialogs.importCalendar.find(".menu-export-event") |
---|
| 1493 | .children(".export").click(function(){ |
---|
| 1494 | |
---|
| 1495 | $('.export-event-form', UI.dialogs.importCalendar).submit(); |
---|
| 1496 | UI.dialogs.importCalendar.dialog("close"); |
---|
| 1497 | /** |
---|
| 1498 | * TODO - implementar ação de exportação |
---|
| 1499 | */ |
---|
| 1500 | }); |
---|
| 1501 | |
---|
| 1502 | UI.dialogs.importCalendar.find(".menu-container") |
---|
| 1503 | .children(".cancel").click(function(){ |
---|
| 1504 | UI.dialogs.importCalendar.dialog("close"); |
---|
| 1505 | }); |
---|
| 1506 | |
---|
| 1507 | UI.dialogs.importCalendar.dialog("open"); |
---|
| 1508 | }); |
---|
| 1509 | } |
---|
| 1510 | |
---|
| 1511 | function dayOfWeek(day) { |
---|
| 1512 | switch (day) { |
---|
| 1513 | case 'SUN': |
---|
| 1514 | return 0; |
---|
| 1515 | break; |
---|
| 1516 | case 'MON': |
---|
| 1517 | return 1; |
---|
| 1518 | break; |
---|
| 1519 | case 'TUE': |
---|
| 1520 | return 2; |
---|
| 1521 | break; |
---|
| 1522 | case 'WED': |
---|
| 1523 | return 3; |
---|
| 1524 | break; |
---|
| 1525 | case 'THU': |
---|
| 1526 | return 4; |
---|
| 1527 | break; |
---|
| 1528 | case 'FRI': |
---|
| 1529 | return 5; |
---|
| 1530 | break; |
---|
| 1531 | case 'SAT': |
---|
| 1532 | return 6; |
---|
| 1533 | break; |
---|
| 1534 | default: |
---|
| 1535 | return false; |
---|
| 1536 | break; |
---|
| 1537 | } |
---|
| 1538 | } |
---|
| 1539 | |
---|
| 1540 | function weekOfDay(week) { |
---|
| 1541 | switch (week) { |
---|
| 1542 | case 0: |
---|
| 1543 | return 'Domingo'; |
---|
| 1544 | case 1: |
---|
| 1545 | return 'Segunda'; |
---|
| 1546 | case 2: |
---|
| 1547 | return 'Terça'; |
---|
| 1548 | case 3: |
---|
| 1549 | return 'Quarta'; |
---|
| 1550 | case 4: |
---|
| 1551 | return 'Quinta'; |
---|
| 1552 | case 5: |
---|
| 1553 | return 'Sexta'; |
---|
| 1554 | case 6: |
---|
| 1555 | return 'Sábado'; |
---|
| 1556 | default: |
---|
| 1557 | return false; |
---|
| 1558 | } |
---|
| 1559 | } |
---|
| 1560 | |
---|
| 1561 | function monthOfNumber(number) { |
---|
| 1562 | switch (number) { |
---|
| 1563 | case 0: |
---|
| 1564 | return 'Janeiro'; |
---|
| 1565 | case 1: |
---|
| 1566 | return 'Fevereiro'; |
---|
| 1567 | case 2: |
---|
| 1568 | return 'Março'; |
---|
| 1569 | case 3: |
---|
| 1570 | return 'Abril'; |
---|
| 1571 | case 4: |
---|
| 1572 | return 'Maio'; |
---|
| 1573 | case 5: |
---|
| 1574 | return 'Junho'; |
---|
| 1575 | case 6: |
---|
| 1576 | return 'Julho'; |
---|
| 1577 | case 7: |
---|
| 1578 | return 'Agosto'; |
---|
| 1579 | case 8: |
---|
| 1580 | return 'Setembro'; |
---|
| 1581 | case 9: |
---|
| 1582 | return 'Outubro'; |
---|
| 1583 | case 10: |
---|
| 1584 | return 'Novembro'; |
---|
| 1585 | case 11: |
---|
| 1586 | return 'Dezembro'; |
---|
| 1587 | default: |
---|
| 1588 | return false; |
---|
| 1589 | } |
---|
| 1590 | } |
---|
| 1591 | |
---|
| 1592 | function sortMonthOfNumber(number) { |
---|
| 1593 | switch (number) { |
---|
| 1594 | case 0: |
---|
| 1595 | return 'Jan'; |
---|
| 1596 | case 1: |
---|
| 1597 | return 'Fev'; |
---|
| 1598 | case 2: |
---|
| 1599 | return 'Mar'; |
---|
| 1600 | case 3: |
---|
| 1601 | return 'Abr'; |
---|
| 1602 | case 4: |
---|
| 1603 | return 'Mai'; |
---|
| 1604 | case 5: |
---|
| 1605 | return 'Jun'; |
---|
| 1606 | case 6: |
---|
| 1607 | return 'Jul'; |
---|
| 1608 | case 7: |
---|
| 1609 | return 'Ago'; |
---|
| 1610 | case 8: |
---|
| 1611 | return 'Set'; |
---|
| 1612 | case 9: |
---|
| 1613 | return 'Out'; |
---|
| 1614 | case 10: |
---|
| 1615 | return 'Nov'; |
---|
| 1616 | case 11: |
---|
| 1617 | return 'Dez'; |
---|
| 1618 | default: |
---|
| 1619 | return false; |
---|
| 1620 | } |
---|
| 1621 | } |
---|