Просмотр исходного кода

Merge branch 'getEventSource' of https://github.com/caseyjhol/fullcalendar into v2.7.4-dev

Adam Shaw 9 лет назад
Родитель
Сommit
42220f6d08
2 измененных файлов с 56 добавлено и 0 удалено
  1. 8 0
      src/EventManager.js
  2. 48 0
      tests/automated/getEventSource.js

+ 8 - 0
src/EventManager.js

@@ -19,6 +19,7 @@ function EventManager(options) { // assumed to be a calendar
 	t.fetchEvents = fetchEvents;
 	t.fetchEventSources = fetchEventSources;
 	t.getEventSources = getEventSources;
+	t.getEventSource = getEventSource;
 	t.addEventSource = addEventSource;
 	t.removeEventSource = removeEventSource;
 	t.updateEvent = updateEvent;
@@ -286,6 +287,13 @@ function EventManager(options) { // assumed to be a calendar
 	}
 
 
+	function getEventSource(id) {
+		return $.grep(sources, function(src) {
+			return src.id && src.id === id;
+		})[0];
+	}
+
+
 	function addEventSource(sourceInput) {
 		var source = buildEventSource(sourceInput);
 		if (source) {

+ 48 - 0
tests/automated/getEventSource.js

@@ -0,0 +1,48 @@
+describe('getEventSource', function() {
+	var options;
+	var calendarEl;
+
+	beforeEach(function() {
+		affix('#cal');
+		calendarEl = $('#cal');
+		options = {
+			now: '2015-08-07',
+			defaultView: 'agendaWeek',
+			eventSources: [
+				{
+					events: [
+						{ id: 1, start: '2015-08-07T02:00:00', end: '2015-08-07T03:00:00', title: 'event A' }
+					],
+					id: 'source1'
+				},
+				{
+					events: [
+						{ id: 2, start: '2015-08-07T03:00:00', end: '2015-08-07T04:00:00', title: 'event B' }
+					],
+					id: 'source2'
+				},
+				{
+					events: [
+						{ id: 3, start: '2015-08-07T04:00:00', end: '2015-08-07T05:00:00', title: 'event C' }
+					],
+					id: 'source3'
+				}
+			]
+		};
+	});
+
+	it('retreives the queried event source', function(done) {
+		var eventSource1;
+		var eventSource2;
+
+		calendarEl.fullCalendar(options);
+
+		eventSource1 = calendarEl.fullCalendar('getEventSource', 'source1');
+		eventSource2 = calendarEl.fullCalendar('getEventSource', 'source2');
+
+		expect(eventSource1.id).toBe('source1');
+		expect(eventSource2.id).toBe('source2');
+
+		done();
+	});
+});