Skip to content

Commit

Permalink
added: calendar viz - min/max limit options for when users can add ev…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
pollen8 committed Jan 10, 2014
1 parent c1f6fe3 commit 766cab9
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 5 deletions.
2 changes: 1 addition & 1 deletion plugins/fabrik_visualization/calendar/calendar-min.js

Large diffs are not rendered by default.

31 changes: 30 additions & 1 deletion plugins/fabrik_visualization/calendar/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ var fabrikCalendar = new Class({
restFilterStart: 'na',
j3: false,
showFullDetails: false,
readonlyMonth: false
readonlyMonth: false,
dateLimits: {min: '', max: ''}
},

initialize: function (el) {
Expand Down Expand Up @@ -926,6 +927,10 @@ var fabrikCalendar = new Class({
rawd = this._getTimeFromClassName(e.target.className);
}

if (!this.dateInLimits(rawd)) {
return;
}

this.date.setTime(rawd);
d = 0;

Expand Down Expand Up @@ -962,6 +967,30 @@ var fabrikCalendar = new Class({
this.addEvForm(o);
}
},

dateInLimits: function (time) {
var d = new Date();
d.setTime(time);

if (this.options.dateLimits.min !== '') {
var min = new Date(this.options.dateLimits.min);
if (d < min) {
alert(Joomla.JText._('PLG_VISUALIZATION_CALENDAR_DATE_ADD_TOO_EARLY'));
return false;
}
}

if (this.options.dateLimits.max !== '') {
var max = new Date(this.options.dateLimits.max);
console.log(max);
if (d > max) {
alert(Joomla.JText._('PLG_VISUALIZATION_CALENDAR_DATE_ADD_TOO_LATE'));
return false;
}
}

return true;
},

openChooseEventTypeForm: function (d, rawd)
{
Expand Down
14 changes: 14 additions & 0 deletions plugins/fabrik_visualization/calendar/forms/fields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@
description="PLG_VISUALIZATION_CALENDAR_CUSTOM_URL_DESC" />
</fieldset>

<fieldset name="plg-visualization-calendar-limits" label="PLG_VISUALIZATION_CALENDAR_LIMITS">

<field name="limit_min"
type="text"
description="PLG_VISUALIZATION_CALENDAR_LIMIT_MIN_DESC"
label="PLG_VISUALIZATION_CALENDAR_LIMIT_MIN_LABEL" />

<field name="limit_max"
type="text"
description="PLG_VISUALIZATION_CALENDAR_LIMIT_MAX_DESC"
label="PLG_VISUALIZATION_CALENDAR_LIMIT_MAX_LABEL" />

</fieldset>

<fieldset addfieldpath="/administrator/components/com_fabrik/models/fields" name="plg-visualization-calendar" label="COM_FABRIK_OPTIONS">

<field name="calendar_layout"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
; Note : All ini files need to be saved as UTF-8 - No BOM

; Administration
PLG_VISUALIZATION_CALENDAR_DATE_ADD_TOO_EARLY="Sorry you can't add an event this far back"
PLG_VISUALIZATION_CALENDAR_DATE_ADD_TOO_LATE="Sorry, you can't add an event this far ahead"
PLG_VISUALIZATION_CALENDAR_TABLE_LABEL="Table"
PLG_VISUALIZATION_CALENDAR_TEMPLATE_LABEL="Template"
PLG_VISUALIZATION_CALENDAR_SHOW_LEGEND_LABEL="Show legend"
Expand All @@ -26,6 +28,11 @@ PLG_VISUALIZATION_CALENDAR_END_DATE_ELEMENT_LABEL="End date element"
PLG_VISUALIZATION_CALENDAR_END_DATE_ELEMENT_DESC="Optional : select the date element you want to use as the event end date. If left blank, only start date will be shown on calendar"
PLG_VISUALIZATION_CALENDAR_LABEL_ELEMENT_LABEL="Label element"
PLG_VISUALIZATION_CALENDAR_LABEL_ELEMENT_DESC="Select the element you want to use as the event label. Can be left blank."
PLG_VISUALIZATION_CALENDAR_LIMIT_MIN_DESC="Earliest date at which the user can add dates the to calendar, accepts mySQL formatted dates e.g yyyy-mm-dd hh:mm:ss Or modifiers from todays date e.g. '-1 year'"
PLG_VISUALIZATION_CALENDAR_LIMIT_MIN_LABEL="Minimum date"
PLG_VISUALIZATION_CALENDAR_LIMIT_MAX_DESC="Earliest date at which the user can add dates the to calendar, accepts mySQL formatted dates e.g yyyy-mm-dd hh:mm:ss Or modifiers from todays date e.g. '+1 year'"
PLG_VISUALIZATION_CALENDAR_LIMIT_MAX_LABEL="Maxium date"
PLG_VISUALIZATION_CALENDAR_LIMITS="Limits"
PLG_VISUALIZATION_CALENDAR_COLOR_LABEL="Colour"
PLG_VISUALIZATION_CALENDAR_COLOR_DESC="hex colour value (e.g. '#eeffff')"
PLG_VISUALIZATION_CALENDAR_LEGEND_TEXT_LABEL="Legend"
Expand Down Expand Up @@ -85,5 +92,8 @@ PLG_VISUALIZATION_CALENDAR_DOUBLE_CLICK_TO_ADD="Double click a date to add an ev
PLG_VISUALIZATION_CALENDAR_SHOW_MESSAGES_DESC="Display some simple instructions at the top of the calendar page"
PLG_VISUALIZATION_CALENDAR_SHOW_MESSAGES_LABEL="Show Instructions"
PLG_VISUALIZATION_CALENDAR_EVENT_START_END="Start: {start} <br />End: {end}"
PLG_VISUALIZATION_CALENDAR_LIMIT_AFTER="You can add dates after %s"
PLG_VISUALIZATION_CALENDAR_LIMIT_BEFORE="You can add dates before %s"
PLG_VISUALIZATION_CALENDAR_LIMIT_RANGE="You can add dates between %s and %s"
PLG_VISUALIZATION_CALENDAR_STATUS_ELEMENT_DESC="Optionally specify an element whose value will be assigned to the event as a class name"
PLG_VISUALIZATION_CALENDAR_STATUS_ELEMENT_LABEL="Status element"
51 changes: 51 additions & 0 deletions plugins/fabrik_visualization/calendar/models/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ public function getEvents()
}

$params = $this->getParams();

$addEvent = json_encode($jsevents);

return $addEvent;
Expand Down Expand Up @@ -626,4 +627,54 @@ public function deleteEvent()
$tableDb->setQuery($query);
$tableDb->execute();
}

/**
* Create the min/max dates between which events can be added.
*
* @return stdClass min/max properties containing sql formatted dates
*/
public function getDateLimits()
{
$params = $this->getParams();
$limits = new stdClass;
$min = $params->get('limit_min', '');
$max = $params->get('limit_max', '');
$limits->min = ($min === '') ? '' : JFactory::getDate($min)->toSql();
$limits->max = ($max === '') ? '' : JFactory::getDate($max)->toSql();

return $limits;
}

/**
* Build the notice which explains between which dates you can add events.
*
* @return string
*/
public function getDateLimitsMsg()
{
$params = $this->getParams();
$min = $params->get('limit_min', '');
$max = $params->get('limit_max', '');
$msg = '';
$f = JText::_('DATE_FORMAT_LC2');

if ($min !== '' && $max === '')
{
$msg = '<br />' . JText::sprintf('PLG_VISUALIZATION_CALENDAR_LIMIT_AFTER', JFactory::getDate($min)->format($f));
}

if ($min === '' && $max !== '')
{
$msg = '<br />' . JText::sprintf('PLG_VISUALIZATION_CALENDAR_LIMIT_BEFORE', JFactory::getDate($max)->format($f));
}

if ($min !== '' && $max !== '')
{
$min = JFactory::getDate($min)->format($f);
$max = JFactory::getDate($max)->format($f);
$msg = '<br />' . JText::sprintf('PLG_VISUALIZATION_CALENDAR_LIMIT_RANGE', $min, $max);
}

return $msg;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public function display($tpl = 'default')

if ($params->get('calendar_show_messages', '1') == '1' && $this->canAdd && $this->requiredFiltersFound)
{
$app->enqueueMessage(JText::_('PLG_VISUALIZATION_CALENDAR_DOUBLE_CLICK_TO_ADD'));
$msg = JText::_('PLG_VISUALIZATION_CALENDAR_DOUBLE_CLICK_TO_ADD');
$msg .= $model->getDateLimitsMsg();
$app->enqueueMessage($msg);
}

JHTML::stylesheet('media/com_fabrik/css/list.css');
Expand Down Expand Up @@ -91,8 +93,10 @@ public function display($tpl = 'default')
$tpl = $params->get('calendar_layout', $j3);
$options = new stdClass;
$options->url = $urls;
$options->deleteables = $this->get('DeleteAccess');
$options->eventLists = $this->get('eventLists');
$options->dateLimits = $model->getDateLimits();

$options->deleteables = $model->getDeleteAccess();
$options->eventLists = $model->getEventLists();
$options->calendarId = $calendar->id;
$options->popwiny = $params->get('yoffset', 0);
$options->urlfilters = $urlfilters;
Expand Down Expand Up @@ -175,6 +179,8 @@ public function display($tpl = 'default')
JText::script('PLG_VISUALIZATION_CALENDAR_ADD_EDIT_EVENT');
JText::script('COM_FABRIK_FORM_SAVED');
JText::script('PLG_VISUALIZATION_CALENDAR_EVENT_START_END');
JText::script('PLG_VISUALIZATION_CALENDAR_DATE_ADD_TOO_LATE');
JText::script('PLG_VISUALIZATION_CALENDAR_DATE_ADD_TOO_EARLY');

$ref = $model->getJSRenderContext();

Expand Down

0 comments on commit 766cab9

Please sign in to comment.