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

Revision 5510, 8.3 KB checked in by fernando, 12 years ago (diff)

Ticket #2434 - Calendário diario e semanal exibido a partir da hora inicial padrão

  • Property svn:executable set to *
Line 
1$(document).ready(function() {
2        refresh_calendars();
3        $tabs = $('#tabs').tabs({
4            add: function( event, ui ) {
5                        Calendar.lastView = $tabs.tabs('option' ,'selected');
6                        $('#tabs .events-list-win.active').removeClass('active');
7                        $tabs.tabs('select', '#' + ui.panel.id);
8                },
9                remove: function( event, ui ) {
10                        $tabs.tabs('select', Calendar.lastView);
11                },
12                show: function( event, ui ){
13                        delete Calendar.currentViewKey;
14                        $('#calendar').fullCalendar('refetchEvents');
15                }
16        })
17        .tabs('option', 'tabTemplate', "<li><a href='#{href}'>#{label}</a><span class='ui-icon ui-icon-close'>Remove Tab</span></li>" );
18
19        /**
20          * Make a button to close the tab
21          */
22        $tabs.find( "span.ui-icon-close" ).live( "click", function() {
23                var index = $( "li", $tabs ).index( $( this ).parent() );
24                if($tabs.tabs('option' ,'selected') == index){
25                        if($tabs.tabs("length") == 2 && Calendar.lastView != 1)
26                                $tabs.tabs( "select", 0);
27                        $tabs.tabs( "select", Calendar.lastView);
28                }
29                if($tabs.tabs('option' ,'selected') == 0 || $tabs.tabs('option' ,'selected') == 1)
30                        Calendar.lastView = $tabs.tabs('option' ,'selected');
31                if(index != -1)
32                  $tabs.tabs( "remove", index );       
33                       
34               
35                });     
36        $('.button.config-menu').button({
37            icons: {
38                primary: "ui-icon-gear",
39                secondary: "ui-icon-triangle-1-s"
40            },
41            text: false
42        });
43      $('.button.add').button({
44              icons: {
45                      secondary: "ui-icon-plus"
46              }
47      })
48
49                var miniCalendar = $('.block-vertical-toolbox .mini-calendar').datepicker({
50                        dateFormat: 'yy-m-d',
51                        //dateFormat: 'DD, d MM, yy',
52                        //inline: true,
53                        firstDay: dateCalendar.dayOfWeek[User.preferences.weekStart],
54                        onSelect: function(dateText, inst)
55                        {       
56                                $tabs.tabs("select", "#calendar");
57                                var toDate = $('.block-vertical-toolbox .mini-calendar').datepicker("getDate").toString('yyyy-MM-dd').split('-');
58                                $('#calendar').fullCalendar('gotoDate', toDate[0], parseInt(toDate[1]-1), toDate[2] );
59                                $('#calendar').fullCalendar( 'changeView', 'agendaDay' );
60                        }                       
61                })
62                .find('.ui-icon-circle-triangle-e').removeClass('ui-icon-circle-triangle-e').addClass('ui-icon-triangle-1-e').end()
63                .find('.ui-icon-circle-triangle-w').removeClass('ui-icon-circle-triangle-w').addClass('ui-icon-triangle-1-w');
64               
65                //Onclick do mês
66                $('.ui-datepicker-title .ui-datepicker-month').live('click',function(){
67                        $tabs.tabs("select", "#calendar");
68                        $('#calendar').fullCalendar('gotoDate',$(this).siblings('span').html(), Date.getMonthNumberFromName($(this).html() == 'Março' ? 'Mar' : $(this).html()),'01');
69                        $('#calendar').fullCalendar( 'changeView', 'month');
70                });
71                //Onclick do ano
72                $('.ui-datepicker-title .ui-datepicker-year').live('click',function(){
73                        $tabs.tabs("select", "#calendar");
74                        $('#calendar').fullCalendar('gotoDate',$(this).html(), '0', '01');
75                        $('.fc-button-year').click();
76                });
77               
78        //Onclick em um dia do calendário anual
79        $( ".fc-day-number" ).live( "click", function() {
80                       
81                var date = $(this).parents('[class*="fc-day-"]').attr('class').match(/fc-day-(\d{4})-(\d{2})-(\d{2})/);
82
83                if (date) date.shift();
84                else return false;
85
86                $('#calendar').fullCalendar('gotoDate',date[0],date[1]-1,date[2]);
87                $('#calendar').fullCalendar( 'changeView', 'agendaDay' );
88        });     
89
90        $('.main-search input.search').keydown(function(event){
91                if(event.keyCode == 13) {
92                        Encoder.EncodeType = "entity";
93                        //$(this).val($(this).val());
94                                       
95                        add_events_list($(this).val());
96                        $(this).val('');
97                }
98        });
99                               
100        $('.block-horizontal-toolbox .main-config-menu').menu({
101                content: $('.main-config-menu-content').html(),
102                positionOpts: {
103                        posX: 'left',
104                        posY: 'bottom',
105                        offsetX: -140,
106                        offsetY: 0,
107                        directionH: 'right',
108                        directionV: 'down',
109                        detectH: true, // do horizontal collision detection 
110                        detectV: true, // do vertical collision detection
111                        linkToFront: false
112                },
113                flyOut: true,
114                showSpeed: 100,
115                crumbDefaultText: '>'
116        });
117             
118                $('#trash').droppable({
119                        drop: function(event, ui){
120                                //              calendar.fullCalendar( 'removeEvents', ui.draggable.attr('event-id') );
121                                DataLayer.remove( "event", ui.draggable.attr('event-id') );
122                                $(this).switchClass('empty','full');
123                        },
124                        tolerance: "touch"
125                });
126
127      /* initialize the calendar
128      -----------------------------------------------------------------*/
129                $(".button.add.add-event").click(function(event){
130                        var startEvent = new Date(); 
131                        if(startEvent.toString('mm') < 30)
132                                        startEvent.add({minutes: (30 - parseInt(startEvent.toString('mm')))});
133                        else
134                                        startEvent.add({hours: 1, minutes: '-'+startEvent.toString('mm')});
135                        var endEvent = function(date){
136                                        if(!!User.preferences.defaultCalendar){
137                                                        return  parseInt(date.getTime()) +
138                                                                (       !!Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration ? 
139                                                                        (Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration * 60000) :
140                                                                        (User.preferences.defaultDuration * 60000)
141                                                                );
142                                        }else
143                                                        return parseInt(date.getTime()) + (User.preferences.defaultDuration * 60000);
144                        };       
145                       
146                        eventDetails({
147                                startTime: startEvent.getTime(),
148                                endTime: endEvent(startEvent)
149                        }, true );
150                });
151
152        var calendar = $('#calendar').fullCalendar(DataLayer.merge({
153
154                defaultView: User.preferences.defaultCalView,
155                timeFormat: User.preferences.hourFormat,
156                axisFormat: User.preferences.hourFormat,
157                eventSources: Calendar.sources,
158
159                header: {
160                        left: 'prev,next today,basicWeek,basicDay',
161                        center: 'title',
162                        right: 'agendaDay,agendaWeek,month,year'
163                },
164                firstHour: dateCalendar.getShortestTime(User.preferences.defaultStartHour ? User.preferences.defaultStartHour : '6'),
165                firstDay: dateCalendar.dayOfWeek[User.preferences.weekStart],
166                editable: true,
167                selectable: true,
168                selectHelper: true,
169                droppable: true, // this allows things to be dropped onto the calendar !!!
170                timeFormat: {
171                        agenda: 'HH:mm{ - HH:mm}',
172                        '': 'HH:mm{ - HH:mm} }'
173                },
174                titleFormat: {
175                        month: 'MMMM yyyy',                             
176                        week: "dd[ yyyy] { 'a'[ MMM] dd 'de' MMMM '-' yyyy}",
177                        day: 'dddd,  dd MMM , yyyy'
178                },
179                columnFormat:{
180                        month: 'ddd',   
181                        week: 'ddd dd/MM',
182                        day: 'dddd dd/MM' 
183                },
184               
185                allDayText: 'Dia todo',
186                buttonText: {
187                        today: 'hoje',
188                        month: 'mês',
189                        week: 'semana',
190                        day: 'dia',
191                        year: 'ano'
192                },
193                /*
194                eventRender: function( event, element, view ){
195                        $(element).attr( 'event-id', event.id );
196                },
197                */
198                select: function( start, end, allDay, event, view ){
199                        if (view.name == "month") {
200                                if (User.preferences.defaultStartHour) {
201                                  _start = User.preferences.defaultStartHour;
202                                 
203                                  if (_start.length > 4)
204                                _start = _start.trim().substring(0,5); // remove o am/pm
205                             
206                              _start = _start.split(":");
207                              start.setHours(_start[0]);
208                              start.setMinutes(_start[1]);
209                            }
210                                 
211                                if (User.preferences.defaultEndHour) {
212                                  _end = User.preferences.defaultEndHour;
213                                  if (_end.length > 4)
214                                _end = _end.trim().substring(0,5); // remove o am/pm
215                                                     
216                              _end = _end.split(":");                     
217                              end.setHours(_end[0]);                       
218                              end.setMinutes(_end[1]);
219                                }                   
220                        } // END if (view.name == "month")
221                       
222                        eventDetails( { 'start': start,
223                                        'end': end,
224                                        'allDay': allDay } );
225                },
226
227                eventDrop: function( event ){
228                        DataLayer.put( "schedulable:calendar", event );
229
230                        event.editable = false;
231                        event.className = "blocked-event";
232                        calendar.fullCalendar( 'updateEvent', event );
233                },
234
235                eventResize: function( event ){
236                        DataLayer.put( "schedulable:calendar", event );
237
238                        event.editable = false;
239                        event.className = "blocked-event";
240                        calendar.fullCalendar( 'updateEvent', event );
241                },
242
243                eventClick: function( evt, event, view ){
244                        eventDetails( DataLayer.get( "schedulable", evt.id), true);
245                }
246        }, dateCalendar));
247         
248        if($(window).height() < $('body').height()){
249                var hei = $('body').height() - $(window).height();
250                hei = $('#divAppbox').height() - hei;
251                $('#divAppbox').css('max-height', hei);
252                $('#divAppbox').css('min-height', hei);
253                $('body').css('overflow-y','hidden');
254                delete hei;
255         }
256         
257         $(window).resize(function(){
258                $('#divAppbox').css('max-height', $(window).height() - 104);
259                $('#divAppbox').css('min-height', $(window).height() - 104);
260                $('#divAppbox').css('overflow-x', 'auto');
261                $('#divAppbox').css('overflow-y', 'scroll');
262        });       
263        //Todo chamada do metodo que adiciona ao full calendar o botao de listagem de eventos 
264        //listEvents();
265});
Note: See TracBrowser for help on using the repository browser.