Skip to content

Commit

Permalink
Added custom query and itemid handling to fullcalendar
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesegrits committed Aug 23, 2019
1 parent 9954e6f commit 483b8e0
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 16 deletions.
Expand Up @@ -14,6 +14,7 @@
jimport('joomla.application.component.controller');

/**
* Fabrik Calendar Plug-in Controller
* Fabrik Calendar Plug-in Controller
*
* @package Joomla.Plugin
Expand Down Expand Up @@ -101,6 +102,7 @@ public function addEvForm()
$startDateField = FabrikString::safeColNameToArrayKey($startDateField);
$endDateField = FabrikString::safeColNameToArrayKey($endDateField);
$rowId = $input->getString('rowid', '');
$Itemid = $input->get('Itemid', '');

/** @var FabrikFEModelList $listModel */
$listModel = JModelLegacy::getInstance('list', 'FabrikFEModel');
Expand All @@ -110,9 +112,22 @@ public function addEvForm()
$input->set('formid', $table->form_id);
$input->set('tmpl', 'component');
$input->set('ajax', '1');

if (!empty($Itemid))
{
$input->set('Itemid', $Itemid);
}

$nextView = $input->get('nextview', 'form');

$link = 'index.php?option=com_' . $package . '&view=' . $nextView . '&formid=' . $table->form_id . '&rowid=' . $rowId . '&tmpl=component&ajax=1';
$link = 'index.php?option=com_' . $package . '&view=' . $nextView . '&formid=' . $table->form_id;
$link .= '&rowid=' . $rowId . '&tmpl=component&ajax=1';

if (!empty($Itemid))
{
$link .= '&Itemid=' . $Itemid;
}

$link .= '&format=partial&fabrik_window_id=' . $input->get('fabrik_window_id');

$startDate = $input->getString('start_date', '');
Expand Down
6 changes: 6 additions & 0 deletions plugins/fabrik_visualization/fullcalendar/forms/fields.xml
Expand Up @@ -74,6 +74,12 @@
label="PLG_VISUALIZATION_FULLCALENDAR_CUSTOM_URL_LABEL"
description="PLG_VISUALIZATION_FULLCALENDAR_CUSTOM_URL_DESC" />

<field name="fullcalendar_where"
type="field"
size="40"
label="PLG_VISUALIZATION_FULLCALENDAR_WHERE_LABEL"
description="PLG_VISUALIZATION_FULLCALENDAR_WHERE_DESC" />

<field
name="popup_template"
type="textarea"
Expand Down

Large diffs are not rendered by default.

46 changes: 40 additions & 6 deletions plugins/fabrik_visualization/fullcalendar/fullcalendar.js
Expand Up @@ -185,30 +185,63 @@ define(['jquery', 'fab/fabrik', 'fullcalendar'], function (jQuery, Fabrik, fc) {
jQuery.extend(true, this.calOptions, JSON.parse(self.options.calOptions));
this.calendar.fullCalendar(this.calOptions);

document.addEvent('click:relay(button[data-task=viewCalEvent], a[data-task=viewCalEvent])',
//document.addEvent('click:relay(button[data-task=viewCalEvent], a[data-task=viewCalEvent])',
jQuery(document).on('click','button[data-task=viewCalEvent], a[data-task=viewCalEvent]',
function (event) {
event.preventDefault();
var id = jQuery(event.target).closest('.calEventButtonsID')[0].id;
var btn = jQuery(event.target).closest('.calEventButtonsID');

if (btn.length === 0) {
btn = jQuery(event.target).closest('.modal-body').next().find('.calEventButtonsID');
}

if (btn.length === 0) {
return;
}

var id = btn[0].id;
id = id.replace(/_buttons/, '');
var calEvent = self.calendar.fullCalendar('clientEvents', id)[0];
jQuery('#fabrikEvent_modal').modal('hide');
self.viewEntry(calEvent);
});

document.addEvent('click:relay(button[data-task=editCalEvent], a[data-task=editCalEvent])',
//document.addEvent('click:relay(button[data-task=editCalEvent], a[data-task=editCalEvent])',
jQuery(document).on('click','button[data-task=editCalEvent], a[data-task=editCalEvent]',
function (event) {
event.preventDefault();
var id = jQuery(event.target).closest('.calEventButtonsID')[0].id;
var btn = jQuery(event.target).closest('.calEventButtonsID');

if (btn.length === 0) {
btn = jQuery(event.target).closest('.modal-body').next().find('.calEventButtonsID');
}

if (btn.length === 0) {
return;
}

var id = btn[0].id;
id = id.replace(/_buttons/, '');
var calEvent = self.calendar.fullCalendar('clientEvents', id)[0];
jQuery('#fabrikEvent_modal').modal('hide');
self.editEntry(calEvent);
});

document.addEvent('click:relay(button[data-task=deleteCalEvent], a[data-task=deleteCalEvent])',
//document.addEvent('click:relay(button[data-task=deleteCalEvent], a[data-task=deleteCalEvent])',
jQuery(document).on('click','button[data-task=deleteCalEvent], a[data-task=deleteCalEvent]',
function (event) {
event.preventDefault();
var id = jQuery(event.target).closest('.calEventButtonsID')[0].id;
var btn = jQuery(event.target).closest('.calEventButtonsID');

if (btn.length === 0) {
btn = jQuery(event.target).closest('.modal-body').next().find('.calEventButtonsID');
}

if (btn.length === 0) {
return;
}

var id = btn[0].id;
id = id.replace(/_buttons/, '');
var calEvent = self.calendar.fullCalendar('clientEvents', id)[0];
jQuery('#fabrikEvent_modal').modal('hide');
Expand Down Expand Up @@ -351,6 +384,7 @@ define(['jquery', 'fab/fabrik', 'fullcalendar'], function (jQuery, Fabrik, fc) {
url += '&rowid=' + o.rowid;
url += '&fabrik_window_id=' + this.windowopts.id;
url += '&task=addEvForm';
url += '&Itemid=' + this.options.Itemid;
url += '&editLink=' + encodeURI(o.editURL);
url += '&viewLink-' + encodeURI(o.viewURL);

Expand Down
Expand Up @@ -114,4 +114,6 @@ PLG_VISUALIZATION_FULLCALENDAR_CAL_OPTIONS_DESC="To overrride any hard defaults
PLG_VISUALIZATION_FULLCALENDAR_ALLDAY_ELEMENT_LABEL="All day element"
PLG_VISUALIZATION_FULLCALENDAR_ALLDAY_ELEMENT_DESC="Optionally specify an element whose value is evaluated to a boolean true/false. You can use strings true, false, yes, no, on, off, 1, 0 or numeric values with 0 beng false and any other value being true. When true the event is considered an all day event."
PLG_VISUALIZATION_FULLCALENDAR_POPUP_TEMPLATE_LABEL="Popup Template"
PLG_VISUALIZATION_FULLCALENDAR_POPUP_TEMPLATE_DESC="Optional template to add to the event popup, can use placeholders"
PLG_VISUALIZATION_FULLCALENDAR_POPUP_TEMPLATE_DESC="Optional template to add to the event popup, can use placeholders"
PLG_VISUALIZATION_FULLCALENDAR_WHERE_DESC="OPTIONAL - where clause to apply to the select query"
PLG_VISUALIZATION_FULLCALENDAR_WHERE_LABEL="Where Clause"
26 changes: 20 additions & 6 deletions plugins/fabrik_visualization/fullcalendar/models/fullcalendar.php
Expand Up @@ -202,6 +202,7 @@ public function setupEvents()
$table_label = (array) $params->get('fullcalendar_label_element');
$table_startdate = (array) $params->get('fullcalendar_startdate_element');
$table_enddate = (array) $params->get('fullcalendar_enddate_element');
$wheres = (array) $params->get('fullcalendar_where');
$customUrls = (array) $params->get('custom_url');
$colour = (array) $params->get('colour');
$legend = (array) $params->get('legendtext');
Expand Down Expand Up @@ -274,7 +275,8 @@ public function setupEvents()
'customUrl' => $customUrl,
'status' => $status,
'allday' => $allday,
'popupTemplate' => $popupTemplate
'popupTemplate' => $popupTemplate,
'where' => ArrayHelper::getValue($wheres, $i, '')
);
}
}
Expand Down Expand Up @@ -405,6 +407,7 @@ public function getDeleteAccess()

public function getEvents($listid = '', $eventListKey = '')
{
$params = $this->getParams();
$app = JFactory::getApplication();
$package = $app->getUserState('com_fabrik.package', 'fabrik');
$Itemid = FabrikWorker::itemId();
Expand All @@ -417,7 +420,7 @@ public function getEvents($listid = '', $eventListKey = '')
$aLegend = "$this->calName.addLegend([";
$jsevents = array();
$input = $app->input;
$where = $input->get('where', array(), 'array');
//$where = $input->get('where', array(), 'array');
$calStart = $input->get('startDate', '');
$calEnd = $input->get('endDate', '');

Expand All @@ -428,8 +431,8 @@ public function getEvents($listid = '', $eventListKey = '')
continue;
}

$this_where = FArrayHelper::getValue($where, $this_listid, '');
$this_where = html_entity_decode($this_where, ENT_QUOTES);
//$this_where = FArrayHelper::getValue($where, $this_listid, '');
//$this_where = html_entity_decode($this_where, ENT_QUOTES);
$listModel = JModelLegacy::getInstance('list', 'FabrikFEModel');
$listModel->setId($this_listid);

Expand Down Expand Up @@ -500,8 +503,16 @@ public function getEvents($listid = '', $eventListKey = '')
->order($startdate . ' ASC');
$query = $listModel->buildQueryJoin($query);
//$this_where = trim(str_replace('WHERE', '', $this_where));
$this_where = FabrikString::ltrimiword($this_where, 'WHERE');
$query = $this_where === '' ? $listModel->buildQueryWhere(true, $query) : $query->where($this_where);
//$this_where = FabrikString::ltrimiword($this_where, 'WHERE');
//$query = $this_where === '' ? $listModel->buildQueryWhere(true, $query) : $query->where($this_where);

if (!empty($data['where']))
{
$customWhere = $w->parseMessageForPlaceHolder($data['where']);
$listModel->setPluginQueryWhere('fullcalendar', $customWhere);
}

$query = $listModel->buildQueryWhere(true, $query);

$query->where(FabrikString::safeColName($endField) . ' >= ' . $db->quote($calStart));
$query->where(FabrikString::safeColName($startField) . ' <= ' . $db->quote($calEnd));
Expand All @@ -525,8 +536,11 @@ public function getEvents($listid = '', $eventListKey = '')
// . $table->form_id . '&rowid=' . $row->id . '&tmpl=component';
$defaultURL = $listModel->editLink($row);
$defaultURL .= StringHelper::qsSepChar($defaultURL) . 'tmpl=component';
$defaultURL .= '&Itemid=' . $app->input->get('Itemid', '');

$viewURL = $listModel->viewDetailsLink($row);
$viewURL .= StringHelper::qsSepChar($viewURL) . 'tmpl=component';
$viewURL .= '&Itemid=' . $app->input->get('Itemid', '');
$thisCustomUrl = $w->parseMessageForPlaceHolder($customUrl, $row);
//$row->link = $thisCustomUrl !== '' ? $thisCustomUrl : $defaultURL;

Expand Down
Expand Up @@ -137,7 +137,7 @@ private function jsOptions()

// Get all list where statements - which are then included in the ajax call to ensure we get the correct data set loaded
$urlFilters = new stdClass;
$urlFilters->where = $model->buildQueryWhere();
//$urlFilters->where = $model->buildQueryWhere();

// Don't JRoute as its wont load with sef?
$urls->del = 'index.php?option=com_' . $package
Expand Down

0 comments on commit 483b8e0

Please sign in to comment.