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

Revision 5592, 8.8 KB checked in by acoutinho, 12 years ago (diff)

Ticket #2434 - Implementacao de compartilhamento de agendas (agendas usuario e agendas publicas)

  • 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        //efetua pesquisas pelo click na lupa de pesquisa
101        $('.main-search span.ui-icon-search').click(function(event){
102                        add_events_list($(this).parent().find('input.search').val());
103                        $(this).parent().find('input.search').val();
104        });
105       
106        $('.block-horizontal-toolbox .main-config-menu').menu({
107                content: $('.main-config-menu-content').html(),
108                positionOpts: {
109                        posX: 'left',
110                        posY: 'bottom',
111                        offsetX: -140,
112                        offsetY: 0,
113                        directionH: 'right',
114                        directionV: 'down',
115                        detectH: true, // do horizontal collision detection 
116                        detectV: true, // do vertical collision detection
117                        linkToFront: false
118                },
119                flyOut: true,
120                showSpeed: 100,
121                crumbDefaultText: '>'
122        });
123             
124                $('#trash').droppable({
125                        drop: function(event, ui){
126                                //              calendar.fullCalendar( 'removeEvents', ui.draggable.attr('event-id') );
127                                DataLayer.remove( "event", ui.draggable.attr('event-id') );
128                                $(this).switchClass('empty','full');
129                        },
130                        tolerance: "touch"
131                });
132
133      /* initialize the calendar
134      -----------------------------------------------------------------*/
135                $(".button.add.add-event").click(function(event){
136                        var startEvent = new Date(); 
137                        if(startEvent.toString('mm') < 30)
138                                        startEvent.add({minutes: (30 - parseInt(startEvent.toString('mm')))});
139                        else
140                                        startEvent.add({hours: 1, minutes: '-'+startEvent.toString('mm')});
141                        var endEvent = function(date){
142                                        if(!!User.preferences.defaultCalendar){
143                                                        return  parseInt(date.getTime()) +
144                                                                (       !!Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration ? 
145                                                                        (Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration * 60000) :
146                                                                        (User.preferences.defaultDuration * 60000)
147                                                                );
148                                        }else
149                                                        return parseInt(date.getTime()) + (User.preferences.defaultDuration * 60000);
150                        };       
151                       
152                        eventDetails({
153                                startTime: startEvent.getTime(),
154                                endTime: endEvent(startEvent)
155                        }, true );
156                });
157
158        var calendar = $('#calendar').fullCalendar(DataLayer.merge({
159
160                defaultView: User.preferences.defaultCalView,
161                timeFormat: User.preferences.hourFormat,
162                axisFormat: User.preferences.hourFormat,
163                eventSources: Calendar.sources,
164
165                header: {
166                        left: 'prev,next today,basicWeek,basicDay',
167                        center: 'title',
168                        right: 'agendaDay,agendaWeek,month,year'
169                },
170                firstHour: dateCalendar.getShortestTime(User.preferences.defaultStartHour ? User.preferences.defaultStartHour : '6'),
171                firstDay: dateCalendar.dayOfWeek[User.preferences.weekStart],
172                editable: true,
173                selectable: true,
174                selectHelper: true,
175                droppable: true, // this allows things to be dropped onto the calendar !!!
176                timeFormat: {
177                        agenda: 'HH:mm{ - HH:mm}',
178                        '': 'HH:mm{ - HH:mm} }'
179                },
180                titleFormat: {
181                        month: 'MMMM yyyy',                             
182                        week: "dd[ yyyy] { 'a'[ MMM] dd 'de' MMMM '-' yyyy}",
183                        day: 'dddd,  dd MMM , yyyy'
184                },
185                columnFormat:{
186                        month: 'ddd',   
187                        week: 'ddd dd/MM',
188                        day: 'dddd dd/MM' 
189                },
190               
191                allDayText: 'Dia todo',
192                buttonText: {
193                        today: 'hoje',
194                        month: 'mês',
195                        week: 'semana',
196                        day: 'dia',
197                        year: 'ano'
198                },
199                /*
200                eventRender: function( event, element, view ){
201                        $(element).attr( 'event-id', event.id );
202                },
203                */
204                select: function( start, end, allDay, event, view ){
205                        if (view.name == "month") {
206                                if (User.preferences.defaultStartHour) {
207                                  _start = User.preferences.defaultStartHour;
208                                 
209                                  if (_start.length > 4)
210                                _start = _start.trim().substring(0,5); // remove o am/pm
211                             
212                              _start = _start.split(":");
213                              start.setHours(_start[0]);
214                              start.setMinutes(_start[1]);
215                            }
216                                 
217                                if (User.preferences.defaultEndHour) {
218                                  _end = User.preferences.defaultEndHour;
219                                  if (_end.length > 4)
220                                _end = _end.trim().substring(0,5); // remove o am/pm
221                                                     
222                              _end = _end.split(":");                     
223                              end.setHours(_end[0]);                       
224                              end.setMinutes(_end[1]);
225                                }                   
226                        } // END if (view.name == "month")
227                       
228                        eventDetails( { 'start': start,
229                                        'end': end,
230                                        'allDay': allDay } );
231                },
232
233                eventDrop: function( event ){
234                        if(!event.disableDragging){
235                                DataLayer.put( "schedulable:calendar", event );
236
237                                event.editable = false;
238                                event.className = "blocked-event";
239                                calendar.fullCalendar( 'updateEvent', event );
240                        }else
241                                Calendar.rerenderView(true);
242                },
243
244                eventResize: function( event ){
245                        if(!event.disableDragging){
246                        DataLayer.put( "schedulable:calendar", event );
247
248                        event.editable = false;
249                        event.className = "blocked-event";
250                        calendar.fullCalendar( 'updateEvent', event );
251                        }else
252                                Calendar.rerenderView(true);
253                },
254
255                eventClick: function( evt, event, view ){
256                        if(evt.selectable)
257                                eventDetails( DataLayer.get( "schedulable", evt.id), true);
258                }
259        }, dateCalendar));
260 
261        contentMenu();
262         
263         $('body').click(function(){
264                $('#context-menu-event').html('');
265         });
266         
267        if($(window).height() < $('body').height()){
268                var hei = $('body').height() - $(window).height();
269                hei = $('#divAppbox').height() - hei;
270                $('#divAppbox').css('max-height', hei);
271                $('#divAppbox').css('min-height', hei);
272                $('body').css('overflow-y','hidden');
273                delete hei;
274         }
275         
276         $(window).resize(function(){
277                $('#divAppbox').css('max-height', $(window).height() - 104);
278                $('#divAppbox').css('min-height', $(window).height() - 104);
279                $('#divAppbox').css('overflow-x', 'auto');
280                $('#divAppbox').css('overflow-y', 'scroll');
281        });       
282        //Todo chamada do metodo que adiciona ao full calendar o botao de listagem de eventos 
283        //listEvents();
284});
Note: See TracBrowser for help on using the repository browser.