Skip to content

Commit

Permalink
Fixing Calendar so that it works in SilverStripe 3.2, 3.3 as well as …
Browse files Browse the repository at this point in the history
…still working in 3.1.
  • Loading branch information
3Dgoo committed Mar 24, 2016
1 parent 90871fd commit e749172
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 133 deletions.
16 changes: 8 additions & 8 deletions code/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ public function getCMSFields() {

$configuration = _t('Calendar.CONFIGURATION','Configuration');
$f->addFieldsToTab("Root.$configuration", array(
new DropdownField('DefaultView',_t('Calendar.DEFAULTVIEW','Default view'), array (
DropdownField::create('DefaultView',_t('Calendar.DEFAULTVIEW','Default view'), array (
'upcoming' => _t('Calendar.UPCOMINGVIEW',"Show a list of upcoming events."),
'month' => _t('Calendar.MONTHVIEW',"Show this month's events."),
'week' => _t('Calendar.WEEKVIEW',"Show this week's events. If none, fall back on this month's"),
'today' => _t('Calendar.TODAYVIEW',"Show today's events. If none, fall back on this week's events"),
'weekend' => _t('Calendar.WEEKENDVIEW',"Show this weekend's events.")
)),
new NumericField('DefaultFutureMonths', _t('Calendar.DEFAULTFUTUREMONTHS','Number maximum number of future months to show in default view')),
new NumericField('EventsPerPage', _t('Calendar.EVENTSPERPAGE','Events per page')),
new TextField('DefaultDateHeader', _t('Calendar.DEFAULTDATEHEADER','Default date header (displays when no date range has been selected)')),
new NumericField('OtherDatesCount', _t('Calendar.NUMBERFUTUREDATES','Number of future dates to show for repeating events'))
))->addExtraClass('defaultView'),
NumericField::create('DefaultFutureMonths', _t('Calendar.DEFAULTFUTUREMONTHS','Number maximum number of future months to show in default view'))->addExtraClass('defaultFutureMonths'),
NumericField::create('EventsPerPage', _t('Calendar.EVENTSPERPAGE','Events per page')),
TextField::create('DefaultDateHeader', _t('Calendar.DEFAULTDATEHEADER','Default date header (displays when no date range has been selected)')),
NumericField::create('OtherDatesCount', _t('Calendar.NUMBERFUTUREDATES','Number of future dates to show for repeating events'))
));

// Announcements
Expand Down Expand Up @@ -430,7 +430,7 @@ public function RecentEvents($limit = null, $filter = null) {
$l
);
$events->sort('StartDate','DESC');
return $events->getRange(0,$limit);
return $events->limit($limit);
}

public function CalendarWidget() {
Expand Down Expand Up @@ -657,7 +657,7 @@ public function rss() {
HTTP::add_cache_headers();
$this->getResponse()->addHeader('Content-Type', 'application/rss+xml');
$this->getResponse()->setBody($xml);
return $this->getResponse();
return $this->getResponse();
}

public function monthjson(SS_HTTPRequest $r) {
Expand Down
69 changes: 35 additions & 34 deletions code/CalendarEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function getCMSFields() {

$this->beforeUpdateCMSFields(function($f) use ($self) {
Requirements::javascript('event_calendar/javascript/calendar_cms.js');
Requirements::css('event_calendar/css/calendar_cms.css');

$f->addFieldToTab("Root.Main",
TextField::create(
Expand All @@ -60,62 +61,62 @@ public function getCMSFields() {
);

$f->addFieldsToTab("Root.$recursion", array(
new CheckboxField('Recursion',_t('CalendarEvent.REPEATEVENT','Repeat this event')),
new OptionsetField(
CheckboxField::create('Recursion',_t('CalendarEvent.REPEATEVENT','Repeat this event'))->addExtraClass('recursion'),
OptionsetField::create(
'CustomRecursionType',
_t('CalendarEvent.DESCRIBEINTERVAL','Describe the interval at which this event recurs.'),
array (
'1' => _t('CalendarEvent.DAILY','Daily'),
'2' => _t('CalendarEvent.WEEKLY','Weekly'),
'3' => _t('CalendarEvent.MONTHLY','Monthly')
)
)
)->setHasEmptyDefault(true)
));

$f->addFieldToTab("Root.$recursion", $dailyInterval = new FieldGroup(
new LabelField($name = "every1", $title = _t("CalendarEvent.EVERY","Every ")),
new DropdownField('DailyInterval', '', array_combine(range(1,10), range(1,10))),
new LabelField($name = "days",$title = _t("CalendarEvent.DAYS"," day(s)"))
));
$f->addFieldToTab("Root.$recursion", $dailyInterval = FieldGroup::create(
LabelField::create($name = "every1", $title = _t("CalendarEvent.EVERY","Every ")),
DropdownField::create('DailyInterval', '', array_combine(range(1,10), range(1,10))),
LabelField::create($name = "days",$title = _t("CalendarEvent.DAYS"," day(s)"))
));

$f->addFieldToTab("Root.$recursion", $weeklyInterval = new FieldGroup(
new LabelField($name = "every2", $title = _t("CalendarEvent.EVERY","Every ")),
new DropdownField('WeeklyInterval', '', array_combine(range(1,10), range(1,10))),
new LabelField($name = "weeks", $title = _t("CalendarEvent.WEEKS", " weeks"))
$f->addFieldToTab("Root.$recursion", $weeklyInterval = FieldGroup::create(
LabelField::create($name = "every2", $title = _t("CalendarEvent.EVERY","Every ")),
DropdownField::create('WeeklyInterval', '', array_combine(range(1,10), range(1,10))),
LabelField::create($name = "weeks", $title = _t("CalendarEvent.WEEKS", " weeks"))
));

$f->addFieldToTab("Root.$recursion", new CheckboxSetField(
'RecurringDaysOfWeek',
_t('CalendarEvent.ONFOLLOWINGDAYS','On the following day(s)...'),
DataList::create("RecurringDayOfWeek")->map("ID", "Title")
$f->addFieldToTab("Root.$recursion", CheckboxSetField::create(
'RecurringDaysOfWeek',
_t('CalendarEvent.ONFOLLOWINGDAYS','On the following day(s)...'),
DataList::create("RecurringDayOfWeek")->map("ID", "Title")
));

$f->addFieldToTab("Root.$recursion", $monthlyInterval = new FieldGroup(
new LabelField($name="every3", $title = _t("CalendarEvent.EVERY","Every ")),
new DropdownField('MonthlyInterval', '', array_combine(range(1,10), range(1,10))),
new LabelField($name = "months", $title = _t("CalendarEvent.MONTHS"," month(s)"))
$f->addFieldToTab("Root.$recursion", $monthlyInterval = FieldGroup::create(
LabelField::create($name="every3", $title = _t("CalendarEvent.EVERY", "Every ")),
DropdownField::create('MonthlyInterval', '', array_combine(range(1,10), range(1,10))),
LabelField::create($name = "months", $title = _t("CalendarEvent.MONTHS", " month(s)"))
));

$f->addFieldsToTab("Root.$recursion", array (
new OptionsetField('MonthlyRecursionType1','', array('1' => _t('CalendarEvent.ONTHESEDATES','On these date(s)...'))),
new CheckboxSetField('RecurringDaysOfMonth', '', DataList::create("RecurringDayOfMonth")->map("ID", "Value")),
new OptionsetField('MonthlyRecursionType2','', array('1' => _t('CalendarEvent.ONTHE','On the...')))
OptionsetField::create('MonthlyRecursionType1','', array('1' => _t('CalendarEvent.ONTHESEDATES','On these date(s)...')))->setHasEmptyDefault(true),
CheckboxSetField::create('RecurringDaysOfMonth', '', DataList::create("RecurringDayOfMonth")->map("ID", "Value")),
OptionsetField::create('MonthlyRecursionType2','', array('1' => _t('CalendarEvent.ONTHE','On the...')))->setHasEmptyDefault(true)
));

$f->addFieldToTab("Root.$recursion", $monthlyIndex = new FieldGroup(
new DropdownField('MonthlyIndex','', array (
'1' => _t('CalendarEvent.FIRST','First'),
'2' => _t('CalendarEvent.SECOND','Second'),
'3' => _t('CalendarEvent.THIRD','Third'),
'4' => _t('CalendarEvent.FOURTH','Fourth'),
'5' => _t('CalendarEvent.LAST','Last')
)),
new DropdownField('MonthlyDayOfWeek','', DataList::create("RecurringDayOfWeek")->map("Value", "Title")),
new LabelField( $name = "ofthemonth", $title = _t("CalendarEvent.OFTHEMONTH"," of the month."))
$f->addFieldToTab("Root.$recursion", $monthlyIndex = FieldGroup::create(
DropdownField::create('MonthlyIndex', '', array (
'1' => _t('CalendarEvent.FIRST', 'First'),
'2' => _t('CalendarEvent.SECOND', 'Second'),
'3' => _t('CalendarEvent.THIRD', 'Third'),
'4' => _t('CalendarEvent.FOURTH', 'Fourth'),
'5' => _t('CalendarEvent.LAST', 'Last')
))->setHasEmptyDefault(true),
DropdownField::create('MonthlyDayOfWeek','', DataList::create('RecurringDayOfWeek')->map('Value', 'Title'))->setHasEmptyDefault(true),
LabelField::create( $name = "ofthemonth", $title = _t("CalendarEvent.OFTHEMONTH"," of the month."))
));
$f->addFieldToTab("Root.$recursion",
GridField::create(
"Exceptions",
'Exceptions',
_t('CalendarEvent.ANYEXCEPTIONS','Any exceptions to this pattern? Add the dates below.'),
$self->Exceptions(),
GridFieldConfig_RecordEditor::create()
Expand Down
11 changes: 6 additions & 5 deletions css/calendar_cms.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@

#RecurringDaysOfMonth div.middleColumn, #RecurringDaysOfWeek div.middleColumn, #RecurringDaysOfMonth span.middleColumn, #RecurringDaysOfWeek span.middleColumn { overflow:hidden; }

#RecurringDaysOfMonth .optionset li, #RecurringDaysOfWeek .optionset li { width:50px; padding:0; margin:0; height:50px; font-weight:bold; padding-top:0px; }
#RecurringDaysOfMonth .optionset li, #RecurringDaysOfWeek .optionset li { position: relative; width:50px; padding:0; margin:0; height:50px; text-align:center; font-weight:bold; padding-top: 0; }

#RecurringDaysOfMonth .optionset li label, #RecurringDaysOfWeek .optionset li label { display:block; height:30px; font-size:16px; margin-top:0; text-align:center; padding-top:20px; }
#RecurringDaysOfMonth .optionset li input, #RecurringDaysOfWeek .optionset li input { float:left; }
#RecurringDaysOfMonth .optionset li input, #RecurringDaysOfWeek .optionset li input { position: absolute; top: 5px; left: 50%; -webkit-transform: -webkit-translateX(-50%); -moz-transform: -moz-translateX(-50%); -ms-transform: -ms-translateX(-50%); -o-transform: -o-translateX(-50%); transform: translateX(-50%); }
#RecurringDaysOfMonth .optionset li label, #RecurringDaysOfWeek .optionset li label { display:block; height:30px; margin-top:0; text-align: center; padding: 27px 0 0 0; }

#RecurringDaysOfWeek .optionset li { border-bottom:1px solid #666; }
#RecurringDaysOfMonth .optionset li.selected, #RecurringDaysOfWeek .optionset li.selected { background:#aaa; }

#RecurringDaysOfMonth .optionset li.b-btm, #RecurringDaysOfWeek .optionset li.b-btm { border-bottom:1px solid #666; }
#RecurringDaysOfMonth .optionset li.b-top, #RecurringDaysOfWeek .optionset li.b-top { border-top:1px solid #666; }
#RecurringDaysOfMonth .optionset li.b-lft, #RecurringDaysOfWeek .optionset li.b-lft { border-left:1px solid #666; }
#RecurringDaysOfMonth .optionset li.b-rgt, #RecurringDaysOfWeek .optionset li.b-rgt { border-right:1px solid #666; }

#Repeat_Alert_Message { background:#fff3a7; padding:2px 4px; border-top:1px solid #d3af22; border-bottom:1px solid #d3af22; }
#Repeat_Alert_Message { background:#fff3a7; padding:2px 4px; border-top:1px solid #d3af22; border-bottom:1px solid #d3af22; }

.optionset li.val { display: none; }
183 changes: 97 additions & 86 deletions javascript/calendar_cms.js
Original file line number Diff line number Diff line change
@@ -1,100 +1,111 @@
(function($) {
$(function() {

$('#DefaultView select').live("change",function() {
$('#DefaultFutureMonths').hide();
if($(this).val() == "upcoming") {
$('#DefaultFutureMonths').show();
}
}).change();


$('#Recursion').entwine({
$('.field.defaultView select').entwine({
onmatch: function() {


var $tab = this.closest('.tab');
var $recursion = this;
var $customRecursionType = $tab.find('#CustomRecursionType').hide();
var $dailyInterval = $tab.find('.dailyinterval').hide();
var $weeklyInterval = $tab.find('.weeklyinterval').hide();
var $monthlyInterval = $tab.find('.monthlyinterval').hide();
var $monthlyIndex = $tab.find('.monthlyindex').hide();
var $recurringDaysOfWeek = $tab.find('#RecurringDaysOfWeek').hide();
var $recurringDaysOfMonth = $tab.find('#RecurringDaysOfMonth').hide();
var $monthlyRecursionType1 = $tab.find('#MonthlyRecursionType1').hide();
var $monthlyRecursionType2 = $tab.find('#MonthlyRecursionType2').hide();

var resetPanels = function () {
$dailyInterval.hide();
$weeklyInterval.hide();
$monthlyInterval.hide();
$recurringDaysOfWeek.hide();
$recurringDaysOfMonth.hide().find(':checkbox').attr('disabled', true);
$monthlyRecursionType1.hide();
$monthlyRecursionType2.hide();
$monthlyIndex.hide().find('select').attr('disabled', true);
}

$recursion.find('input').change(function() {
if($(this).is(':checked')) {
$customRecursionType.show();
if ($(this).val() != 'upcoming') {
$('.field.defaultFutureMonths').hide();
}
else {
$tab.find(':checkbox, :radio').attr('checked', false);
$customRecursionType.hide();
resetPanels();
},
onchange: function() {
$('.field.defaultFutureMonths').hide();
if ($(this).val() == 'upcoming') {
$('.field.defaultFutureMonths').show();
}
}).change();
}
});

$customRecursionType.find('input').change(function() {
if($(this).is(':checked')) {
resetPanels();
switch($(this).val()) {
case "1":
$dailyInterval.show();
break;

case "2":
$weeklyInterval.show();
$recurringDaysOfWeek.show();
break;
$('.field.checkbox.recursion').entwine({
onmatch: function() {

case "3":
$monthlyInterval.show();
$recurringDaysOfMonth.show();
$monthlyRecursionType1.show();
$monthlyRecursionType2.show();
$monthlyIndex.show();
break;
var $tab = this.closest('.tab');
var $recursion = this;
var $customRecursionType = $tab.find('#CustomRecursionType').hide();
var $dailyInterval = $tab.find('.dailyinterval').hide();
var $weeklyInterval = $tab.find('.weeklyinterval').hide();
var $monthlyInterval = $tab.find('.monthlyinterval').hide();
var $monthlyIndex = $tab.find('.monthlyindex').hide();
var $recurringDaysOfWeek = $tab.find('#RecurringDaysOfWeek').hide();
var $recurringDaysOfMonth = $tab.find('#RecurringDaysOfMonth').hide();
var $monthlyRecursionType1 = $tab.find('#MonthlyRecursionType1').hide();
var $monthlyRecursionType2 = $tab.find('#MonthlyRecursionType2').hide();

var resetPanels = function () {
$dailyInterval.hide();
$weeklyInterval.hide();
$monthlyInterval.hide();
$recurringDaysOfWeek.hide();
$recurringDaysOfMonth.hide().find(':checkbox').attr('disabled', true);
$monthlyRecursionType1.hide();
$monthlyRecursionType2.hide();
$monthlyIndex.hide().find('select').attr('disabled', true);
};

var resetSubPanels = function () {
$recurringDaysOfMonth.hide().find(':checkbox').attr('disabled', true);
$monthlyIndex.hide().find('select').attr('disabled', true);
};

$recursion.find('input').change(function() {
if($(this).is(':checked')) {
$customRecursionType.show();
}
}
}).change();

$monthlyRecursionType1.find('input').change(function() {
if($(this).is(':checked')) {
$recurringDaysOfMonth.find(':checkbox').attr('disabled', false);
$monthlyIndex.find('select').attr('disabled', true);
$monthlyRecursionType2.find('input').attr('checked', false).change();
}
}).change();

$monthlyRecursionType2.find('input').change(function() {
if($(this).is(':checked')) {
$recurringDaysOfMonth.find(':checkbox').attr('disabled', true);
$monthlyIndex.find('select').attr('disabled', false);
$monthlyRecursionType1.find('input').attr('checked', false).change();
}
}).change();

else {
$tab.find(':checkbox, :radio').attr('checked', false);
$customRecursionType.hide();
resetPanels();
}
}).change();

$customRecursionType.find('input').change(function() {
if($(this).is(':checked')) {
resetPanels();
switch($(this).val()) {
case "1":
$dailyInterval.show();
break;

case "2":
$weeklyInterval.show();
$recurringDaysOfWeek.show();
break;

case "3":
$monthlyInterval.show();
$monthlyRecursionType1.show();
$monthlyRecursionType2.show();
break;
}
}
}).change();

$monthlyRecursionType1.find('input').change(function() {
if($(this).is(':checked')) {

resetSubPanels();
$recurringDaysOfMonth.show();

$recurringDaysOfMonth.find(':checkbox').attr('disabled', false);
$monthlyIndex.find('select').attr('disabled', true);
$monthlyRecursionType2.find('input').attr('checked', false).change();
}
}).change();

$monthlyRecursionType2.find('input').change(function() {
if($(this).is(':checked')) {

resetSubPanels();
$monthlyIndex.show();

$recurringDaysOfMonth.find(':checkbox').attr('disabled', true);
$monthlyIndex.find('select').attr('disabled', false);
$monthlyRecursionType1.find('input').attr('checked', false).change();
}
}).change();


}});





}
});

});
})(jQuery);

0 comments on commit e749172

Please sign in to comment.