source: trunk/prototype/modules/calendar/js/init.js @ 7653

Revision 7653, 20.3 KB checked in by acoutinho, 11 years ago (diff)

Ticket #2215 - A agenda esta com problema para ser exibida no IE

  • Property svn:executable set to *
Line 
1$(document).ready(function() {
2        $("#wrap").css("visibility","visible");
3        //Remove o icone de configuraçõe padrão antigo do expresso
4        $('#sideboxdragarea').addClass('hidden');
5
6        refresh_calendars();
7        $tabs = $('#tabs').tabs({
8            add: function( event, ui ) {
9                        Calendar.lastView = $tabs.tabs('option' ,'selected');
10                        $('#tabs .events-list-win.active').removeClass('active');
11                        $tabs.tabs('select', '#' + ui.panel.id);
12                },
13                remove: function( event, ui ) {
14                        $tabs.tabs('select', Calendar.lastView);
15                },
16                show: function( event, ui ){
17                        delete Calendar.currentViewKey;
18                        $('#calendar').fullCalendar('refetchEvents');
19                }
20        })
21        .tabs('option', 'tabTemplate', "<li><a href='#{href}'>#{label}</a><span class='ui-icon ui-icon-close'>Remove Tab</span></li>" );
22
23        /**
24          * Make a button to close the tab
25          */
26        $tabs.find( "span.ui-icon-close" ).live( "click", function() {
27                var index = $( "li", $tabs ).index( $( this ).parent() );
28                if($tabs.tabs('option' ,'selected') == index){
29                        if($tabs.tabs("length") == 2 && Calendar.lastView != 1)
30                                $tabs.tabs( "select", 0);
31                        $tabs.tabs( "select", Calendar.lastView);
32                }
33                if($tabs.tabs('option' ,'selected') == 0 || $tabs.tabs('option' ,'selected') == 1)
34                        Calendar.lastView = $tabs.tabs('option' ,'selected');
35                if(index != -1)
36                  $tabs.tabs( "remove", index );       
37                       
38               
39                });     
40        $('.button.config-menu').button({
41            icons: {
42                primary: "ui-icon-gear",
43                secondary: "ui-icon-triangle-1-s"
44            },
45            text: false
46        });
47      $('.button.add').button({
48              icons: {
49                      secondary: "ui-icon-plus"
50              }
51      })
52
53                var miniCalendar = $('.block-vertical-toolbox .mini-calendar').datepicker({
54                        dateFormat: 'yy-m-d',
55                        //dateFormat: 'DD, d MM, yy',
56                        //inline: true,
57                        firstDay: dateCalendar.dayOfWeek[User.preferences.weekStart],
58                        onSelect: function(dateText, inst)
59                        {       
60                                $tabs.tabs("select", "#calendar");
61                                var toDate = $('.block-vertical-toolbox .mini-calendar').datepicker("getDate").toString('yyyy-MM-dd').split('-');
62                                $('#calendar').fullCalendar('gotoDate', toDate[0], parseInt(toDate[1]-1), toDate[2] );
63                                $('#calendar').fullCalendar( 'changeView', 'agendaDay' );
64                        }                       
65                })
66                .find('.ui-icon-circle-triangle-e').removeClass('ui-icon-circle-triangle-e').addClass('ui-icon-triangle-1-e').end()
67                .find('.ui-icon-circle-triangle-w').removeClass('ui-icon-circle-triangle-w').addClass('ui-icon-triangle-1-w');
68               
69                //Onclick do mês
70                $('.ui-datepicker-title .ui-datepicker-month').live('click',function(){
71                        $tabs.tabs("select", "#calendar");
72                        $('#calendar').fullCalendar('gotoDate',$(this).siblings('span').html(), Date.getMonthNumberFromName($(this).html() == 'Março' ? 'Mar' : $(this).html()),'01');
73                        $('#calendar').fullCalendar( 'changeView', 'month');
74                });
75                //Onclick do ano
76                $('.ui-datepicker-title .ui-datepicker-year').live('click',function(){
77                        $tabs.tabs("select", "#calendar");
78                        $('#calendar').fullCalendar('gotoDate',$(this).html(), '0', '01');
79                        $('.fc-button-year').click();
80                });
81               
82        //Onclick em um dia do calendário anual
83        $( ".fc-day-number" ).live( "click", function() {
84                       
85                var date = $(this).parents('[class*="fc-day-"]').attr('class').match(/fc-day-(\d{4})-(\d{2})-(\d{2})/);
86
87                if (date) date.shift();
88                else return false;
89
90                $('#calendar').fullCalendar('gotoDate',date[0],date[1]-1,date[2]);
91                $('#calendar').fullCalendar( 'changeView', 'agendaDay' );
92        });     
93
94        $('.main-search input.search').keydown(function(event){
95                if(event.keyCode == 13) {
96                        Encoder.EncodeType = "entity";
97                        //$(this).val($(this).val());
98                                       
99                        add_events_list($(this).val());
100                        $(this).val('');
101                }
102        });
103       
104        //efetua pesquisas pelo click na lupa de pesquisa
105        $('.main-search span.ui-icon-search').click(function(event){
106                        add_events_list($(this).parent().find('input.search').val());
107                        $(this).parent().find('input.search').val();
108        });
109       
110        $('.block-horizontal-toolbox .main-config-menu').menu({
111                content: $('.main-config-menu-content').html(),
112                positionOpts: {
113                        posX: 'left',
114                        posY: 'bottom',
115                        offsetX: -140,
116                        offsetY: 0,
117                        directionH: 'right',
118                        directionV: 'down',
119                        detectH: true, // do horizontal collision detection 
120                        detectV: true, // do vertical collision detection
121                        linkToFront: false
122                },
123                flyOut: true,
124                showSpeed: 100,
125                crumbDefaultText: '>'
126        });
127             
128                $('#trash').droppable({
129                        drop: function(event, ui){
130                                //              calendar.fullCalendar( 'removeEvents', ui.draggable.attr('event-id') );
131                                DataLayer.remove( "event", ui.draggable.attr('event-id') );
132                                $(this).switchClass('empty','full');
133                        },
134                        tolerance: "touch"
135                });
136
137      /* initialize the calendar
138      -----------------------------------------------------------------*/
139                $(".button.add.add-event").click(function(event){
140                        var startEvent = new Date();
141                        var configData = (startEvent.toString('mm') < 30)  ? {minutes: (30 - parseInt(startEvent.toString('mm')))} : {hours: 1, minutes: '-'+startEvent.toString('mm')};
142                        startEvent.add(configData);
143
144                        eventDetails({
145                                startTime: startEvent.getTime(),
146                                endTime: dateCalendar.decodeRange(startEvent, (!!User.preferences.defaultCalendar ? (   !!Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration ? 
147                                                (Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration) : (User.preferences.defaultDuration)) : (User.preferences.defaultDuration)))
148                        }, true );
149                });
150               
151                var currentToolTip = null;
152                $('#divAppbox').on('scroll',function(){
153                        if ($(".new-task").length)                     
154                                currentToolTip.qtip('destroy');
155                });
156               
157                /* Quick add task
158        -----------------------------------------------------------------*/
159                $(".button.add.add-task").click(function(event){
160                        currentToolTip = $(this);
161                        var componente = $(this);
162                       
163            if(!$('div.qtip.qtip-blue.new-task').length){
164
165                $('div.qtip.qtip-blue').remove();
166
167                        $(componente).qtip({
168                            show: {
169                                ready: true,
170                                solo: true,
171                                when: {
172                                        event: 'click'
173                                }
174                                },
175                                hide: false,
176                                content: {
177                                        text: $('<div></div>').html( DataLayer.render( 'templates/task_quick_add.ejs', {"componente" : componente} ) ),
178                                        title: {
179                                                text:'Nova Tarefa',
180                                                button: '<a class="button close" href="#">close</a>'
181                                        }
182                                },
183                                style: {
184                                        name: 'blue',
185                                tip: {
186                                                corner: 'leftMiddle'
187                                        },
188                                border: {
189                                            width: 4,
190                                            radius: 8
191                                        },
192                                width: {
193                                                min: 225,
194                                            max:225
195                                        }
196                                },
197                        position: {
198                                corner: {
199                                            target: 'rightMiddle',
200                                            tooltip: 'leftMiddle'
201                                },
202                                adjust: {
203                                            x:0,
204                                            y:0
205                                }
206                        }
207                    })
208                .qtip("api").onShow = function(arg0) {
209
210                        /*------------------------------------------------------------------------*/
211                        /*               Seta os valores padrões nos inputs do qtip               */
212                         $('div.qtip div.add-simple-task input.task').Watermark("Tarefa sem título");
213                             $('div.qtip div.add-simple-task textarea').Watermark("Descrição");
214                        /*------------------------------------------------------------------------*/
215
216                            $('.qtip-active .button.close').button({
217                                icons: {
218                                    primary: "ui-icon-close"
219                                },
220                                text: false
221                            })
222                            .click(function(){
223                                        $(componente).qtip('destroy');
224                            });
225                                                       
226                            $('.qtip-active .button.save').button().click(function(){
227                               
228                                var title = $('div.qtip div.add-simple-task input.task').val();
229                                        var description = $('div.qtip div.add-simple-task textarea').val();
230
231                                        var calendar, timezone = '';
232
233                                        for (var i = 0; i < Calendar.signatures.length; i++){
234                                                if(Calendar.signatures[i].type == 1 && Calendar.signatures[i].calendar.type == 1){
235                                                        calendar = Calendar.signatures[i].calendar.id;
236                                                        timezone = Calendar.signatures[i].calendar.timezone;
237                                                        break;
238                                                }
239                                        }
240
241                                DataLayer.put('schedulable',
242                                {
243                                        summary: title,
244                                        description: description,
245                                        type: '2',
246                                        calendar: calendar,
247                                        timezone: timezone,
248                                        'class':'1',
249                                                        status: '1',
250                                        startTime: new Date().toString('yyyy-MM-dd 00:00:00'),
251                                        endTime: new Date().toString('yyyy-MM-dd 00:00:00'),
252                                        allDay: '1',
253                            priority: '1',
254                                        participants:
255                                        [{ 
256                                            user: User.me.id,
257                                            isOrganizer: 1,
258                                            acl: 'row'
259                                        }]
260                                });
261                               
262                        $(componente).qtip('destroy');
263
264                    });
265
266                            $('.qtip-active .button.advanced').button().click(function(){
267
268                                var startEvent = new Date();
269                                        var configData = (startEvent.toString('mm') < 30)  ? {minutes: (30 - parseInt(startEvent.toString('mm')))} : {hours: 1, minutes: '-'+startEvent.toString('mm')};
270                                        startEvent.add(configData);
271                       
272                                                var componente = $(this);
273                        var description = $('div.qtip div.add-simple-task textarea[name="description"]').val();
274
275                                        taskDetails({
276                            summary: $('div.qtip div.add-simple-task input[name="summary"]').val(),
277                            description: description == 'Descrição' ? '' : description,
278                                                startTime: startEvent.getTime(),
279                                                endTime: dateCalendar.decodeRange(startEvent, (!!User.preferences.defaultCalendar ? (   !!Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration ? 
280                                                        (Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration) : (User.preferences.defaultDuration)) : (User.preferences.defaultDuration)))
281                                        }, true );
282
283                        $(componente).qtip('destroy');
284                            });
285                                                               
286                                $('.qtip-active .button.cancel').button().click(function(){
287                                        $(componente).qtip('destroy');
288                            });
289                                                       
290                            $('.qtip-active .button').button();
291                       
292                        $('div.qtip.qtip-blue.qtip-active').addClass('new-task');
293            }
294        }
295                });
296
297        $(".button.add.add-activity").click(function(event){
298                        var startEvent = new Date();
299                        var configData = (startEvent.toString('mm') < 30)  ? {minutes: (30 - parseInt(startEvent.toString('mm')))} : {hours: 1, minutes: '-'+startEvent.toString('mm')};
300                        startEvent.add(configData);
301                       
302                        activityDetails({
303                                startTime: startEvent.getTime(),
304                                endTime: dateCalendar.decodeRange(startEvent, (!!User.preferences.defaultCalendar ? (   !!Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration ? 
305                                                (Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration) : (User.preferences.defaultDuration)) : (User.preferences.defaultDuration)))
306                        }, true );
307
308        });
309
310        var calendar = $('#calendar').fullCalendar(DataLayer.merge({
311
312                defaultView: User.preferences.defaultCalView,
313                timeFormat: User.preferences.hourFormat,
314                axisFormat: User.preferences.hourFormat,
315                eventSources: Calendar.sources,
316
317                header: {
318                        left: 'prev,next today,agendaWeek,agendaDay',
319                        center: 'title',
320                        right: 'agendaDay,agendaWeek,month,year'
321                },
322                firstHour: dateCalendar.getShortestTime(User.preferences.defaultStartHour ? User.preferences.defaultStartHour : '6'),
323                firstDay: dateCalendar.dayOfWeek[User.preferences.weekStart],
324                editable: true,
325                selectable: true,
326                selectHelper: true,
327                droppable: true, // this allows things to be dropped onto the calendar !!!
328                timeFormat: {
329                        agenda: 'HH:mm{ - HH:mm}',
330                        '': 'HH:mm{ - HH:mm} }'
331                },
332                titleFormat: {
333                        month: 'MMMM yyyy',                             
334                        week: "dd[ yyyy] { 'a'[ MMM] dd 'de' MMMM '-' yyyy}",
335                        day: 'dddd,  dd MMM , yyyy'
336                },
337                columnFormat:{
338                        month: 'ddd',   
339                        week: 'ddd dd/MM',
340                        day: 'dddd dd/MM' 
341                },
342               
343                allDayText: 'Dia todo',
344                buttonText: {
345                        today: 'hoje',
346                        month: 'mês',
347                        week: 'semana',
348                        day: 'dia',
349                        year: 'ano'
350                },
351
352
353        eventRender: function( event, element, view ){
354                    $('#calendar td.fc-year-have-event').removeClass('fc-year-have-event');
355
356                        var img_icon = "";
357                        if(event.type == 1)
358                                img_icon = "mini-event.png";
359                        if(event.type == 2)
360                                img_icon = "mini-task.png";
361                        if(event.type == 3)
362                                img_icon = "mini-activity.png";
363
364                       
365            element.find(".fc-event-inner.fc-event-skin").prepend($('<img style="width: 11px; height: 13px;" class="" src="../prototype/modules/calendar/img/' + img_icon + '"></img>'));
366                },
367
368                select: function( start, end, allDay, event, view ){
369                        if (view.name == "month") {
370                                if (User.preferences.defaultStartHour) {
371                                  _start = User.preferences.defaultStartHour;
372                                 
373                                  if (_start.length > 4)
374                                _start = _start.trim().substring(0,5); // remove o am/pm
375                             
376                              _start = _start.split(":");
377                              start.setHours(_start[0]);
378                              start.setMinutes(_start[1]);
379                            }
380                                 
381                                if (User.preferences.defaultEndHour) {
382                                  _end = User.preferences.defaultEndHour;
383                                  if (_end.length > 4)
384                                _end = _end.trim().substring(0,5); // remove o am/pm
385                                                     
386                              _end = _end.split(":");                     
387                              end.setHours(_end[0]);                       
388                              end.setMinutes(_end[1]);
389                                }                   
390                        } // END if (view.name == "month")
391                       
392                        eventDetails( { 'start': start,
393                                        'end': end,
394                                        'allDay': allDay } );
395                },
396
397                eventDrop: function( evt, event, view  ){
398                        evt.id = evt.id.split('-')[0];
399                        if(!evt.disableDragging){
400                           
401                             if(evt.isRepeat){
402                                 var schedulable = copyAndMoveTo(false , evt.id , false, "3", evt);
403                                 
404                                 var repeat = mount_exception(evt.id, evt.occurrence);
405                                 DataLayer.remove('repeat', false);
406                                 DataLayer.put('repeat', repeat);
407                                 DataLayer.commit('repeat', false, function(data){
408                                   
409                                    DataLayer.remove('schedulable', repeat.schedulable, false);
410                                    DataLayer.put('schedulable', schedulable);
411                                     
412                                 });
413
414                             }else{                                 
415                                DataLayer.put( "schedulable:calendar", evt );
416
417                                event.editable = false;
418                                event.className = "blocked-event";
419                                calendar.fullCalendar( 'updateEvent', evt );
420                             }
421                             
422                        }else
423                            Calendar.rerenderView(true);
424                },
425
426                eventResize: function( evt, event, view ){
427                        evt.id = evt.id.split('-')[0];
428                        if(!evt.disableDragging){
429                             if(evt.isRepeat){
430                                 var schedulable = copyAndMoveTo(false , evt.id , false, "3", evt);
431                                 
432                                 //Normaliza a data para o backend
433                                 schedulable.startTime = new Date(parseInt(schedulable.startTime)).toString('yyyy-MM-dd hh:mm:00');
434                                 schedulable.endTime = new Date(parseInt(schedulable.endTime)).toString('yyyy-MM-dd hh:mm:00');
435                                 
436                                 var repeat = mount_exception(evt.id, evt.occurrence);
437                                 
438                                 DataLayer.remove('repeat', false);
439                                 DataLayer.put('repeat', repeat);
440                                 DataLayer.commit('repeat', false, function(data){
441                                     
442                                    DataLayer.remove('schedulable', repeat.schedulable, false);
443                                    DataLayer.put('schedulable', schedulable);
444                                     
445                                 });
446                             }else{                                 
447                                DataLayer.put( "schedulable:calendar", evt );   
448                                evt.editable = false;
449                                evt.className = "blocked-event";
450                                calendar.fullCalendar( 'updateEvent', evt );
451                             }
452                       
453                        }else
454                                Calendar.rerenderView(true);
455                },
456
457                eventClick: function( evt, event, view ){
458                        evt.id = evt.id.split('-')[0];
459           
460            switch (parseInt(evt.type)){
461                case 1:
462                    if(evt.selectable){
463                        if(evt.isRepeat){
464                            $.Zebra_Dialog(evt.title + ' é um evento com repetição.', {
465                                'type':     'question',
466                                'overlay_opacity': '0.5',
467                                'width': 427,
468                                'buttons':  ['Editar todas ocorrências', 'Editar essa ocorrência', 'Cancelar'],
469                                'onClose':  function(clicked) {
470                                    if(clicked == 'Editar todas ocorrências') {
471                                        eventDetails( DataLayer.get( "schedulable", evt.id), true);
472                                    }else if (clicked == 'Editar essa ocorrência'){
473                                        /*
474                                        * TODO - repeat foi adicionado pois melhorias devem ser feitas no rollback do
475                                        *DataLayer, repeat somente é usado quando se trata da criação de um evento
476                                        *pela edição de uma ocorrência.
477                                        */     
478                                        var repeat = mount_exception(evt.id, evt.occurrence);
479                                                                                         
480                                        $('.calendar-copy-move input[name="typeEvent"]').val("3");
481                                       
482                                        eventDetails(copyAndMoveTo(false , evt.id , false, "3", evt), true, '', false, repeat);
483                                    }       
484                                }
485                            });
486                        }else{
487                            var schedulable = DataLayer.get( "schedulable", evt.id);
488                            schedulable.calendar = evt.calendar;
489                            eventDetails( schedulable, true);
490                            }
491                        }
492                        break;
493                    case 2:
494                        var task = DataLayer.get( "schedulable", evt.id);
495                        task.group = evt.calendar;
496                        taskDetails( task, true);
497                        break;
498                    case 3:
499                        var activity = DataLayer.get( "schedulable", evt.id);
500                        activity.group = evt.calendar;
501                        activityDetails( activity, true);
502                        break;
503            }
504                },
505               
506                eventAfterRender: function(event, element, view){
507
508                        contentMenu();
509
510                }
511        }, dateCalendar));     
512
513        $('#calendar .fc-header-left .fc-button-agendaWeek, #calendar .fc-header-left .fc-button-agendaDay').click(function(){
514                $(this).parent().find(".fc-button-today").click();
515        });
516               
517        contentMenu();
518         
519         $('body').click(function(){
520                $('#context-menu-event').html('');
521         });
522
523
524    if( $.browser.msie ){
525
526        $('body').css('overflow-y','hidden');
527
528
529    }else{
530
531        if($(window).height() < $('body').height()){
532            var hei = $('body').height() - $(window).height();
533            hei = $('#divAppbox').height() - hei;
534            $('#divAppbox').css('max-height', hei);
535            $('#divAppbox').css('min-height', hei);
536            $('body').css('overflow-y','hidden');
537            delete hei;
538        }
539
540        $(window).resize(function(){
541            $('#divAppbox').css('max-height', $(window).height() - 104);
542            $('#divAppbox').css('min-height', $(window).height() - 104);
543            $('#divAppbox').css('overflow-x', 'auto');
544            $('#divAppbox').css('overflow-y', 'scroll');
545        });
546    }
547         
548
549
550    if( $.browser.msie ){
551
552        $('#divAppbox').css('width', $(window).width());
553    }
554
555
556        //Todo chamada do metodo que adiciona ao full calendar o botao de listagem de eventos 
557        printEvents();
558});
559
560
561function useDesktopNotification(){
562
563        return !!parseInt(User.preferences.useDesktopNotification);
564
565}
Note: See TracBrowser for help on using the repository browser.