Skip to content

Commit

Permalink
Added Axisformat proprty to set time format vertical axis of agenda v…
Browse files Browse the repository at this point in the history
…iews.

Upgraded library to FullCalendar v2.3.2
  • Loading branch information
RoelandSalij committed Jun 15, 2015
1 parent eed571b commit 070cd49
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 1,018 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ This is a calendar widget for Mendix. It shows a Calendar and can render objects
## Contributing
For more information on contributing to this repository visit [Contributing to a GitHub repository](https://world.mendix.com/display/howto50/Contributing+to+a+GitHub+repository)!

## Dependencies
- FullCalendar v2.3.2
- JQuery v2.1.3
- Moments.js v2.9.0

## Features
The Calendar Widget is a Mendix implementation of the open-source jQuery widget [FullCalendar](http://fullcalendar.io/).

Expand Down
12 changes: 6 additions & 6 deletions src/calendar/lib/fullcalendar.min.js

Large diffs are not rendered by default.

184 changes: 184 additions & 0 deletions src/calendar/lib/gcal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*!
* FullCalendar v2.3.2 Google Calendar Plugin
* Docs & License: http://fullcalendar.io/
* (c) 2015 Adam Shaw
*/

(function(factory) {
if (typeof define === 'function' && define.amd) {
define([ 'jquery' ], factory);
}
else if (typeof exports === 'object') { // Node/CommonJS
module.exports = factory(require('jquery'));
}
else {
factory(jQuery);
}
})(function($) {


var API_BASE = 'https://www.googleapis.com/calendar/v3/calendars';
var fc = $.fullCalendar;
var applyAll = fc.applyAll;


fc.sourceNormalizers.push(function(sourceOptions) {
var googleCalendarId = sourceOptions.googleCalendarId;
var url = sourceOptions.url;
var match;

// if the Google Calendar ID hasn't been explicitly defined
if (!googleCalendarId && url) {

// detect if the ID was specified as a single string.
// will match calendars like "[email protected]" in addition to person email calendars.
if (/^[^\/]+@([^\/\.]+\.)*(google|googlemail|gmail)\.com$/.test(url)) {
googleCalendarId = url;
}
// try to scrape it out of a V1 or V3 API feed URL
else if (
(match = /^https:\/\/www.googleapis.com\/calendar\/v3\/calendars\/([^\/]*)/.exec(url)) ||
(match = /^https?:\/\/www.google.com\/calendar\/feeds\/([^\/]*)/.exec(url))
) {
googleCalendarId = decodeURIComponent(match[1]);
}

if (googleCalendarId) {
sourceOptions.googleCalendarId = googleCalendarId;
}
}


if (googleCalendarId) { // is this a Google Calendar?

// make each Google Calendar source uneditable by default
if (sourceOptions.editable == null) {
sourceOptions.editable = false;
}

// We want removeEventSource to work, but it won't know about the googleCalendarId primitive.
// Shoehorn it into the url, which will function as the unique primitive. Won't cause side effects.
// This hack is obsolete since 2.2.3, but keep it so this plugin file is compatible with old versions.
sourceOptions.url = googleCalendarId;
}
});


fc.sourceFetchers.push(function(sourceOptions, start, end, timezone) {
if (sourceOptions.googleCalendarId) {
return transformOptions(sourceOptions, start, end, timezone, this); // `this` is the calendar
}
});


function transformOptions(sourceOptions, start, end, timezone, calendar) {
var url = API_BASE + '/' + encodeURIComponent(sourceOptions.googleCalendarId) + '/events?callback=?'; // jsonp
var apiKey = sourceOptions.googleCalendarApiKey || calendar.options.googleCalendarApiKey;
var success = sourceOptions.success;
var data;
var timezoneArg; // populated when a specific timezone. escaped to Google's liking

function reportError(message, apiErrorObjs) {
var errorObjs = apiErrorObjs || [ { message: message } ]; // to be passed into error handlers
var consoleObj = window.console;
var consoleWarnFunc = consoleObj ? (consoleObj.warn || consoleObj.log) : null;

// call error handlers
(sourceOptions.googleCalendarError || $.noop).apply(calendar, errorObjs);
(calendar.options.googleCalendarError || $.noop).apply(calendar, errorObjs);

// print error to debug console
if (consoleWarnFunc) {
consoleWarnFunc.apply(consoleObj, [ message ].concat(apiErrorObjs || []));
}
}

if (!apiKey) {
reportError("Specify a googleCalendarApiKey. See http://fullcalendar.io/docs/google_calendar/");
return {}; // an empty source to use instead. won't fetch anything.
}

// The API expects an ISO8601 datetime with a time and timezone part.
// Since the calendar's timezone offset isn't always known, request the date in UTC and pad it by a day on each
// side, guaranteeing we will receive all events in the desired range, albeit a superset.
// .utc() will set a zone and give it a 00:00:00 time.
if (!start.hasZone()) {
start = start.clone().utc().add(-1, 'day');
}
if (!end.hasZone()) {
end = end.clone().utc().add(1, 'day');
}

// when sending timezone names to Google, only accepts underscores, not spaces
if (timezone && timezone != 'local') {
timezoneArg = timezone.replace(' ', '_');
}

data = $.extend({}, sourceOptions.data || {}, {
key: apiKey,
timeMin: start.format(),
timeMax: end.format(),
timeZone: timezoneArg,
singleEvents: true,
maxResults: 9999
});

return $.extend({}, sourceOptions, {
googleCalendarId: null, // prevents source-normalizing from happening again
url: url,
data: data,
startParam: false, // `false` omits this parameter. we already included it above
endParam: false, // same
timezoneParam: false, // same
success: function(data) {
var events = [];
var successArgs;
var successRes;

if (data.error) {
reportError('Google Calendar API: ' + data.error.message, data.error.errors);
}
else if (data.items) {
$.each(data.items, function(i, entry) {
var url = entry.htmlLink;

// make the URLs for each event show times in the correct timezone
if (timezoneArg) {
url = injectQsComponent(url, 'ctz=' + timezoneArg);
}

events.push({
id: entry.id,
title: entry.summary,
start: entry.start.dateTime || entry.start.date, // try timed. will fall back to all-day
end: entry.end.dateTime || entry.end.date, // same
url: url,
location: entry.location,
description: entry.description
});
});

// call the success handler(s) and allow it to return a new events array
successArgs = [ events ].concat(Array.prototype.slice.call(arguments, 1)); // forward other jq args
successRes = applyAll(success, this, successArgs);
if ($.isArray(successRes)) {
return successRes;
}
}

return events;
}
});
}


// Injects a string like "arg=value" into the querystring of a URL
function injectQsComponent(url, component) {
// inject it after the querystring but before the fragment
return url.replace(/(\?.*?)?(#|$)/, function(whole, qs, hash) {
return (qs ? qs + '&' : '?') + component + hash;
});
}


});
4 changes: 0 additions & 4 deletions src/calendar/lib/jquery-2.1.1.min.js

This file was deleted.

5 changes: 5 additions & 0 deletions src/calendar/lib/jquery-2.1.3.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/calendar/lib/lang-all.js

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions src/calendar/widget/calendar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*jslint white:true, nomen: true, plusplus: true */
/*global mx, define, require, browser, devel, console */
/*global mx, define, require, browser, devel, console, setTimeout */
/*mendix */
/*
Calendar
Expand All @@ -16,37 +16,33 @@
========================
FullCalendar implementation.
*/

// Required module list. Remove unnecessary modules, you can always get them back from the boilerplate.
require({
require({
packages: [{
name: 'jquery',
location: '../../widgets/calendar/lib',
main: 'jquery-2.1.1.min'
},
{
name: 'moment',
location: '../../widgets/calendar/lib',
main: 'moment.min'
},
{
name: 'fullCalendar',
location: '../../widgets/calendar/lib',
main: 'fullcalendar.min'
},
{
name: 'calendarLang',
location: '../../widgets/calendar/lib',
main: 'lang-all'
}
]
}, [
name: 'jquery',
location: '../../widgets/calendar/lib',
main: 'jquery-2.1.3.min'
},
{
name: 'moment',
location: '../../widgets/calendar/lib',
main: 'moment.min'
}, {
name: 'fullCalendar',
location: '../../widgets/calendar/lib',
main: 'fullcalendar.min'
}, {
name: 'calendarLang',
location: '../../widgets/calendar/lib',
main: 'lang-all'
}]
},
[
'dojo/_base/declare', 'mxui/widget/_WidgetBase', 'dijit/_TemplatedMixin',
'mxui/dom', 'dojo/dom', 'dojo/query', 'dojo/dom-prop', 'dojo/dom-geometry', 'dojo/dom-class', 'dojo/dom-style', 'dojo/dom-construct', 'dojo/_base/array', 'dojo/_base/lang', 'dojo/text',
'jquery', 'moment', 'fullCalendar', 'calendarLang', 'dojo/text!calendar/widget/template/Calendar.html'
'jquery', 'moment', 'fullCalendar', 'calendarLang', 'dojo/text!calendar/widget/template/Calendar.html'
], function (declare, _WidgetBase, _TemplatedMixin, dom, dojoDom, domQuery, domProp, domGeom, domClass, domStyle, domConstruct, dojoArray, lang, text, $, moment, fullCalendar, calendarLang, widgetTemplate) {
'use strict';

// Declare widget's prototype.
return declare('calendar.widget.calendar', [_WidgetBase, _TemplatedMixin], {
// _TemplatedMixin will create our dom node using this HTML template.
Expand Down Expand Up @@ -104,6 +100,10 @@ require({
if (obj) {
this._mxObj = obj;
this._fetchObjects();
if (this._mxObj.get(this.startPos)) {
this._fcNode.fullCalendar('gotoDate', new Date(this._mxObj.get(this.startPos)));
}

}

//subscribe to changes in the event entity and context object(if applicable).
Expand Down
Loading

0 comments on commit 070cd49

Please sign in to comment.