Exemplo n.º 1
0
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * X2Engine" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by X2Engine".
 *****************************************************************************************/
/**
* This file renders the SmallCalendar widget
* The code, is messy as most is taken from the calendar module, 
* Both could use a refactoring, for there is code duplication.
**/
Yii::app()->clientScript->registerScript("smallCalendarJS", "\n\n\n// Put the function in this scope\nfunction giveSaveButtonFocus() {\n    return x2.calendarManager.giveSaveButtonFocus();\n}\n\n\$(function(){\n\n    var justMe;\n    var urls;\n    var myurl; \n    var indicator;\n    var savedForm;\n    var savedTab;\n\n    function initialize(){\n        x2.calendarManager.calendar = '#small-calendar';\n        x2.calendarManager.widgetSettingUrl = '{$widgetSettingUrl}';\n        justMe = {$justMe};\n\n\n        // Initialize the calendar, ensure that only one is present\n        if(\$('#small-calendar .fc-content').length > 0)\n            return;\n\n        // Initialize calendar sources \n        // By fetching the checked user calendars\n        var calendars = {$showCalendars};\n        urls = [];\n        myurl = '{$urls['jsonFeed']}?user={$user}';\n\n        for (var i in calendars.userCalendars){\n            urls.push('{$urls['jsonFeed']}?user='******'{$urls['jsonFeedGroup']}?groupId='+calendars.groupCalendars[i]);\n        }\n\n        indicatorClass();\n        initCalendar();\n        applyHeader();\n        justMeButton();\n        miscModifications();\n        \$('#small-calendar .fc-button').click(responsiveBehavior);\n        responsiveBehavior();\n\n\n    }\n\n    function indicatorClass(){\n        // Singleton class to render the inidcators on the calendar\n        indicator = {\n\n            dayIndicators: [],\n\n            /**\n            *  Adds an event indicator to the calendar\n            *  @param event event full calendar event to be added\n            *  @param view view the full calendar current view\n            */\n            addEvent: function(event, view){\n                if (view.name !== 'month')\n                    return;\n\n                var eventStart = new Date(event.start.valueOf());\n\n                // This is to only show indicators for the current month +/- a margin\n                var viewStart = new Date(view.start);\n                var viewEnd = new Date(view.end);\n                viewStart.setDate( viewStart.getDate() - 7 )\n                viewEnd.setDate( viewEnd.getDate() + 14 )\n\n                // If event starts before the view, move it up.\n                if( event.start.valueOf() < viewStart.valueOf() ){\n                    eventStart = viewStart;\n                }\n\n                // put this function in the scope for readability\n                yyyymmdd = x2.calendarManager.yyyymmdd; \n\n                // Add array of dates and colors for the indicators\n                var dates = [yyyymmdd(eventStart)];\n\n                //Handing if an event spans more than One day\n                if(event.end){\n                    var eventEnd = new Date(event.end.valueOf() - 1000);\n\n                    if( event.end.valueOf() > viewEnd.valueOf() ){\n                        eventEnd = viewEnd;\n                    }\n\n                    var dateEnd = yyyymmdd(eventEnd);\n\n                    //If the event start is after then end, just display one blip at the end\n                    if( eventStart.valueOf() > eventEnd.valueOf() ){\n                        dates = [dateEnd]\n                    } else {\n                        // For every day in the event, \n                        // add the next day to the dates array\n                        var newDate = new Date(eventStart);\n                        for(var i = 0; i < 42; i++){\n                            if(dates[ dates.length - 1 ] == dateEnd)\n                                break;\n\n\n                            newDate.setDate( newDate.getDate() + 1 );\n\n                            dates.push( yyyymmdd(newDate) );\n\n                        }\n                    }\n                }\n\n                \n                var indicator_count = {};\n                // For each date in the array create an event indicator\n                for(var i in dates){\n                    \n                    // If it is already in the array, do not add it again\n                    var contained = false;\n                    for( var j in this.dayIndicators ){\n                        if (this.dayIndicators[j].date === dates[i]) {\n                            //otherwise \n                            if (this.dayIndicators[j].color == event.color){\n                                contained = true;\n                                this.dayIndicators[j].count++;\n                                break;\n                            } \n                        }\n                    }\n\n                    if(!contained)\n                        this.dayIndicators.push({date: dates[i], color: event.color, count: 1});\n\n                }\n            },\n\n            render: function(){\n                //Remove previous indicators\n                \$('#small-calendar .fc-day .fc-indicator-container').children().remove();\n                // \$('#small-calendar .fc-day .fc-day-content').append('<div class=\"fc-indicator-container\"></div>');\n\n                for(var i in this.dayIndicators){\n                    // if (i>5) continue;\n\n                    var event = this.dayIndicators[i];\n\n                    var dayContainer = '#small-calendar .fc-day[data-date=\"'+event.date+'\"] .fc-indicator-container';\n\n                    \$('<div></div>').appendTo( \$(dayContainer) ).\n                    addClass('fc-event-indicator').\n                    css('background-color', event.color).\n                    attr('event-color', event.color).\n                    attr('title', event.count+' event'+ (event.count > 1 ? 's' : '' ));\n                }\n            }\n\n        };\n    }\n\n    function initCalendar(){\n        \$('#small-calendar').fullCalendar({\n\n            // height: 500,\n            theme: true,\n            header: {\n                left: 'title',\n                center: '',\n                right: 'month agendaDay prev,next'\n            },\n            eventSources: justMe ? [myurl] : urls,\n            eventRender: function(event, element, view) {\n                indicator.addEvent(event, view);\n            },\n\n            windowResize: responsiveBehavior,\n\n            dayClick: function(date, allDay, jsEvent, view) {\n\n                    if( view.name == 'month') {\n                        \$('#small-calendar .fc-button-agendaDay').addClass('disabled-link');\n                        \$('#small-calendar .fc-button-month').removeClass('disabled-link');\n                        \$('#small-calendar').fullCalendar ('gotoDate', date);\n                        \$('#small-calendar').fullCalendar ('changeView', 'agendaDay');\n                    } \n                // if (\$(jsEvent.target).hasClass ('day-number-link')) {\n                    // }\n            },\n\n            viewRender: function(view){\n                indicator.dayIndicators = [];\n\n\n            },\n\n            eventAfterAllRender: function(view){\n                indicator.render();\n\n            },\n\n            eventDrop: function(event, dayDelta, minuteDelta, allDay, revertFunc) { \n                \$.post('{$urls['moveAction']}', {\n                        id: event.id, dayChange: dayDelta, minuteChange: minuteDelta, isAllDay: allDay\n                    });\n            },\n            eventResize: function(event, dayDelta, minuteDelta, revertFunc) {\n                \$.post('{$urls['resizeAction']}', {\n                   id: event.id, dayChange: dayDelta, minuteChange: minuteDelta});\n            },\n            eventClick: function(event){\n                eventClickHandler(event);\n            },\n            editable: true,\n            // translate (if local not set to english)\n            buttonText:     " . X2Calendar::translationArray('buttonText') . ",\n            monthNames:     " . X2Calendar::translationArray('monthNames') . ",\n            monthNamesShort:" . X2Calendar::translationArray('monthNamesShort') . ",\n            dayNames:       " . X2Calendar::translationArray('dayNames') . ",\n            dayNamesShort:  " . X2Calendar::translationArray('dayNamesShort') . ",\n\n\n        });\n    }\n    \n\n    \n    function eventClickHandler(event){\n        if (\$('[id=\"dialog-content_' + event.id + '\"]').length != 0) { \n            return;\n        }\n\n        var boxButtons = [ // buttons on bottom of dialog\n            {\n                text: '" . CHtml::encode(Yii::t('app', 'Close')) . "',\n                click: function() {\n                    \$(this).dialog('close');\n                }\n            }\n        ];\n        \n        var viewAction = \$('<div></div>', {id: 'dialog-content' + '_' + event.id}); \n\n        if(event.editable){\n            var boxTitle = '" . Yii::t('calendar', 'Edit Calendar Event') . "';\n            boxButtons.unshift({\n                        text: '" . CHtml::encode(Yii::t('app', 'Save')) . "', // delete event\n                        click: function() {\n                            // delete event from database\n                            \$.post(\n                                '{$urls['saveAction']}?id=' + event.id, \n                                \$(viewAction).find('form').serialize(),\n                                function() {\n                                    \$('#small-calendar').fullCalendar('refetchEvents');\n                                }\n                            ); \n                            \$(this).dialog('close');\n                        }\n                    });\n            boxButtons.unshift({\n                text: '" . CHtml::encode(Yii::t('app', 'Delete')) . "', // delete event\n                click: function() {\n                    if(confirm('" . Yii::t("calendar", "Are you sure you want to delete this event?") . "')) {\n                        // delete event from database\n                        \$.post('{$urls['deleteAction']}', {id: event.id}); \n                        \$('#small-calendar').fullCalendar('removeEvents', event.id);\n                        \$(this).dialog('close');\n                    }\n                }\n            });\n            \$.post(\n                '{$urls['editAction']}', {\n                    'ActionId': event.id, 'IsEvent': event.type=='event'\n                }, function(data) {\n                    \$(viewAction).append(data);\n                    //open dialog after its filled with action/event\n                    viewAction.dialog('open'); \n                }\n            );\n        } else {\n            var boxTitle = '" . Yii::t('calendar', 'View Calendar Event') . "';\n            \$.post(\n                '{$urls['viewAction']}', {\n                    'ActionId': event.id, \n                    'IsEvent': event.type=='event'\n                }, function(data) {\n                    \$(viewAction).append(data);\n                    //open dialog after its filled with action/event\n                    viewAction.dialog('open'); \n                }\n            );\n        }\n\n\n        // Dialog box that pops up when \n        // an event is clicked. \n        viewAction.dialog({\n            title: boxTitle,\n            dialogClass: 'calendarViewEventDialog',\n            autoOpen: false,\n            resizable: true,\n            height: 'auto',\n            width: 500,\n            position: {my: 'right-12', at: 'left bottom', of: '#small-calendar'}, \n            show: 'fade',\n            hide: 'fade',\n            buttons: boxButtons,\n            open: function() {\n                \$('.ui-dialog-buttonpane').find('button:contains(\"" . Yii::t('app', 'Close') . "\")')\n                    .addClass('highlight')\n                    .focus();\n                \$('.ui-dialog-buttonpane').find('button').css('font-size', '0.85em');\n                \$('.ui-dialog-title').css('font-size', '0.8em');\n                \$('.ui-dialog-titlebar').css('padding', '0.2em 0.4em');\n                \$('.ui-dialog-titlebar-close').css({\n                    'height': '18px',\n                    'width': '18px'\n                    });\n                \$(viewAction).css('font-size', '0.75em');\n            },\n            close: function () {\n                \$(this).dialog ('destroy');\n                  //\$('[id=\"dialog-content_' + event.id + '\"]').remove ();\n                // cleanUpDialog ();\n            },\n            resizeStart: function () {\n            },\n            resize: function (event, ui) {\n            }\n        });\n    }\n\n\n    // Make header a link to the full calendar \n    // \$('#small-calendar .fc-header-title h2').wrap('<a href=\"{$urls['index']}\"></a>').\n    // attr('title', 'Go to full calendar');\n     \n\n    function justMeButton(){\n\n        var meButton = \$('#small-calendar-container #me-button');\n        meButton.click(function(evt){\n            if( !meButton.hasClass('pressed') ){\n                \$('#small-calendar').fullCalendar('removeEventSources');\n                \$('#small-calendar').fullCalendar('addEventSource', myurl);\n                meButton.addClass('pressed');\n                x2.calendarManager.updateWidgetSetting('justMe', true);\n            } else {\n                \$('#small-calendar').fullCalendar('removeEventSources');\n                for(var i in urls){\n                    \$('#small-calendar').fullCalendar('addEventSource', urls[i]);\n                }\n                meButton.removeClass('pressed');            \n                x2.calendarManager.updateWidgetSetting('justMe', false);\n            }\n            \n        });\n        \n    }\n\n    function applyHeader(){\n        var headerRight = \$('#small-calendar .fc-header-right').hide();\n        var headerLeft = \$('#small-calendar .fc-header-left').append(\$('<div class=\"x2-button-group\" ></div>'));\n        \n        headerLeft.find('.x2-button-group').append(headerRight.children());\n        \$('#small-calendar #me-button').appendTo(headerLeft).show();\n        \n\n        \$('#small-calendar .page-title').removeClass('page-title');\n\n    }\n\n    function miscModifications(){\n        // remove the hash that scrolls to teh top of the page\n        \$('#small-calendar .day-number-link').attr('href','javascript:;');\n\n\n        // Re render after the portlet is maximized / minimized\n        \$('#widget_SmallCalendar .portlet-minimize-button').bind('click', function() {\n            window.setTimeout(function() { \$('#small-calendar').fullCalendar('render'); }, 1000) ;\n        });\n    }\n\n    function responsiveBehavior(){\n        var width = \$('#small-calendar .fc-day').width();\n        \$('#small-calendar .day-number-link').css('font-size', width/3*1.25);\n        \$('#small-calendar .fc-day-number').css('padding-top', width/3/1.25);\n\n        if(\$('.fc-header-left').height()> 50){\n            \$('#me-button').css('float', 'left');\n        }\n        else {\n            \$('#me-button').css('float', 'right');\n        }\n\n        var title = \$('#widget_SmallCalendar #widget-dropdown');\n\n        var minimizeElement = \$('#widget_SmallCalendar #widget-dropdown .portlet-minimize');\n\n        var view = \$('#small-calendar').fullCalendar('getView');\n        if (typeof view.title === 'undefined') {\n            return;\n        }\n\n        title.html('');\n        title.append('<div id=\"header-title\">'+view.title+'</div>');\n        title.append(minimizeElement);\n\n        \$('#small-calendar .x2-button').removeClass('disabled-link');\n        \$('#small-calendar .fc-button-'+view.name).addClass('disabled-link');\n\n\n        if(view.name == 'month'){\n            \$('#small-calendar-container').height('auto');\n        }\n\n        if(view.name == 'agendaDay'){\n            \$('#small-calendar').fullCalendar('option', 'height', 350);\n        }\n    }\n\n\n    initialize();    \n});\n\n", CClientScript::POS_HEAD);
?>

<div id='small-calendar-container'>
    <div id='small-calendar'>

            <?php 
// Be aware these buttons are added dynamically with JS
//                echo X2Html::link(
//                Yii::t('calendar','Full Calendar'),
//                Yii::app()->createUrl('/calendar'),
//                array (
//                    'style' =>'display:none;',
//                    'class' =>"x2-button fc-button",
//                    'id' =>"add-button",
//                    'type' =>'button',
Exemplo n.º 2
0
?>
,
        monthNames:     <?php 
echo X2Calendar::translationArray('monthNames');
?>
,
        monthNamesShort:<?php 
echo X2Calendar::translationArray('monthNamesShort');
?>
,
        dayNames:       <?php 
echo X2Calendar::translationArray('dayNames');
?>
,
        dayNamesShort:  <?php 
echo X2Calendar::translationArray('dayNamesShort');
?>
,

    });
    
    /*
    *   This section is meant to pre-render the events given to it on loading, 
    *   but causes an amount of problems due to event sources.

    $('#calendar').fullCalendar('addEventSource', <?php 
//echo CJSON::encode($events)
?>
);

    var pushed = false;