public function run() { // Prevent the small calendar from showing when using the larger calendar if (Yii::app()->controller->modelClass == 'X2Calendar' && Yii::app()->controller->action->getId() == 'index') { return; } // Fetch the calendars to display $user = User::model()->findByPk(Yii::app()->user->getId()); if (is_null($user->showCalendars)) { $user->initCheckedCalendars(); } $showCalendars = $user->showCalendars; // Possible urls for the calendar to call $urls = X2Calendar::getCalendarUrls(); $widgetSettingUrl = $this->controller->createUrl('/site/widgetSetting'); $justMe = Profile::getWidgetSetting('SmallCalendar', 'justMe'); Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/js/fullcalendar-1.6.1/fullcalendar/fullcalendar.css'); Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . '/css/components/smallCalendar.css'); Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/fullcalendar-1.6.1/fullcalendar/fullcalendar.js'); Yii::app()->clientScript->registerScriptFile(Yii::app()->getModule('calendar')->assetsUrl . '/js/calendar.js', CClientScript::POS_END); $this->render('smallCalendar', array('showCalendars' => $showCalendars, 'urls' => $urls, 'user' => $user->username, 'widgetSettingUrl' => $widgetSettingUrl, 'justMe' => $justMe)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = X2Calendar::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.')); } return $model; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Actions(); $users = User::getNames(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Actions'])) { // $this->render('test', array('model'=>$_POST)); $temp = $model->attributes; if (isset($_POST['inCalendar'])) { // create new calendar event foreach (array_keys($model->attributes) as $field) { if (isset($_POST['CalendarEvent'][$field])) { $model->{$field} = $_POST['CalendarEvent'][$field]; } } $model->actionDescription = $_POST['Actions']['actionDescription']; // $this->render('test', array('model'=>$_POST['CalendarEvent'])); } else { foreach (array_keys($model->attributes) as $field) { if (isset($_POST['Actions'][$field])) { $model->{$field} = $_POST['Actions'][$field]; } } } if (is_numeric($model->assignedTo)) { // assigned to calendar instead of user? $calendar = X2Calendar::model()->findByPk($model->assignedTo); if (isset($calendar)) { $model->calendarId = $model->assignedTo; $model->assignedTo = null; if ($calendar->googleCalendar && $calendar->googleCalendarId) { $model->dueDate = $this->parseDateTime($model->dueDate); if ($model->completeDate) { $model->completeDate = $this->parseDateTime($model->completeDate); } $calendar->createGoogleEvent($model); // action/event assigned to Google Calendar, no need to create Action since it's saved to google $this->redirect(array('/calendar/index')); } } } $this->create($model, $temp, '0'); } if (isset($_GET['param'])) { $pieces = explode(';', $_GET['param']); $user = $pieces[0]; $pieces2 = explode(':', $pieces[1]); $type = $pieces2[0]; $id = $pieces2[1]; } else { // defaults $user = Yii::app()->user->getName(); $type = 'none'; $id = null; } $model->associationType = $type; $model->assignedTo = $user; if (!empty($id)) { $model->associationId = $id; } $this->render('create', array('model' => $model, 'users' => $users)); }
echo "</ul>\n"; $this->endWidget(); } if (isset($this->googleCalendars) && $this->googleCalendars !== null) { $this->beginWidget('zii.widgets.CPortlet', array('title' => Yii::t('calendar', 'Google Calendars'), 'id' => 'google-calendars')); $showGoogleCalendars = $showCalendars['googleCalendars']; echo '<ul style="font-size: 0.8em; font-weight: bold; color: black;">'; foreach ($this->googleCalendars as $calendarId => $calendarName) { if (isset($editableCalendars[$calendarId])) { // check if current user has permission to edit calendar $editable = 'true'; } else { $editable = 'false'; } echo "<li>\n"; $calendar = X2Calendar::model()->findByPk($calendarId); // checkbox for each user; current user and Anyone are set to checked if ($calendar->googleCalendarId) { // read/write google calendar echo CHtml::checkBox($calendarId, in_array($calendarId, $showGoogleCalendars), array('onChange' => "toggleCalendarSourceGoogle({$calendarId}, this.checked, {$editable});")); } else { // read only google calendar feed echo CHtml::checkBox($calendarId, in_array($calendarId, $showGoogleCalendars), array('onChange' => "toggleCalendarSourceGoogleFeed({$calendarId}, this.checked, '{$calendar->googleFeed}');")); } echo "<label for=\"{$calendarId}\">{$calendarName}</label>\n"; echo "</li>"; } echo "</ul>\n"; $this->endWidget(); } if (isset($this->calendarFilter) && $this->calendarFilter !== null) {
public static function getCalendarFilters() { $user = User::model()->findByPk(Yii::app()->user->id); $calendarFilters = explode(',', $user->calendarFilter); $filters = X2Calendar::getCalendarFilterNames(); $filterList = array(); foreach ($filters as $filter) { if (in_array($filter, $calendarFilters)) { $filterList[$filter] = true; } else { $filterList[$filter] = false; } } return $filterList; }
* 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',
?> , 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;
echo $priorityArray[$model->priority]; ?> <?php /* <?php echo $form->dropDownList($model,'priority', array( 'Low'=>Yii::t('actions','Low'), 'Medium'=>Yii::t('actions','Medium'), 'High'=>Yii::t('actions','High') ), array('onChange'=>'giveSaveButtonFocus();')); */ ?> </div> <div class="cell dialog-cell"> <?php if ($model->assignedTo == null && is_numeric($model->calendarId)) { // assigned to calendar instead of user? $model->assignedTo = $model->calendarId; } ?> <?php echo $form->label($model, 'assignedTo', array('class' => 'dialog-label')); ?> <?php $assignedToArray = $users + X2Calendar::getViewableCalendarNames(); echo $assignedToArray[$model->assignedTo]; ?> </div> <?php $this->endWidget();
echo $form->dropDownList($model, 'color', Actions::getColors(), array('onChange' => 'giveSaveButtonFocus();')); ?> </div> <div class="cell dialog-cell"> <?php if ($model->assignedTo == null && is_numeric($model->calendarId)) { // assigned to calendar instead of user? $model->assignedTo = $model->calendarId; } ?> <?php echo $form->label($model, 'assignedTo', array('class' => 'dialog-label')); ?> <?php echo $form->dropDownList($model, 'assignedTo', $users + X2Calendar::getEditableCalendarNames(), array('id' => 'dialog_actionsAssignedToDropdown', 'onChange' => 'giveSaveButtonFocus();')); ?> <?php /* x2temp */ echo "<br />"; $url = $this->createUrl('groups/getGroups'); echo "<label class=\"dialog-label\">Group?</label>"; echo CHtml::checkBox('group', '', array('id' => 'dialog_groupCheckbox', 'onChange' => 'giveSaveButtonFocus();', 'ajax' => array('type' => 'POST', 'url' => $url, 'update' => '#dialog_actionsAssignedToDropdown', 'complete' => 'function(){ if($("#dialog_groupCheckbox").attr("checked")!="checked"){ $("#dialog_groupCheckbox").attr("checked","checked"); $("#dialog_Actions_visibility option[value=\'2\']").remove(); }else{ $("#dialog_groupCheckbox").removeAttr("checked"); $("#dialog_Actions_visibility").append( $("<option></option>").val("2").html("User\'s Groups") );
//echo $form->error($actionModel,'priority'); ?> <?php echo $form->label($event, 'color'); ?> <?php echo $form->dropDownList($event, 'color', Actions::getColors()); ?> </div> <div class="cell"> <?php echo $form->label($event, 'assignedTo'); ?> <?php echo $form->dropDownList($event, 'assignedTo', $users + X2Calendar::getEditableCalendarNames(), array('id' => 'actionsAssignedToDropdown')); ?> <?php //echo $form->error($actionModel,'assignedTo'); ?> <?php /* x2temp */ echo "<br />"; if ($this instanceof Controller) { $url = $this->createUrl('groups/getGroups'); } else { $url = $this->controller->createUrl('groups/getGroups'); } echo "<label>Group?</label>"; echo CHtml::checkBox('group', '', array('id' => 'eventGroupCheckbox', 'ajax' => array('type' => 'POST', 'url' => $url, 'update' => '#actionsAssignedToDropdown', 'complete' => 'function(){ if($("#groupCheckbox").attr("checked")!="checked"){