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

components should use their own dateProfile

Adam Shaw 8 лет назад
Родитель
Сommit
5e7be57c61

+ 7 - 1
src/View.js

@@ -1071,6 +1071,8 @@ var View = FC.View = InteractiveDateComponent.extend({
 View.watch('dateProfileMisc', [ 'dateProfile' ], function(deps) {
 	var calendar = this.calendar;
 	var dateProfile = deps.dateProfile;
+	var children = this.children;
+	var i;
 
 	// DEPRECATED, but we need to keep it updated...
 	this.start = calendar.msToMoment(dateProfile.activeUnzonedRange.startMs, dateProfile.isRangeAllDay);
@@ -1079,7 +1081,11 @@ View.watch('dateProfileMisc', [ 'dateProfile' ], function(deps) {
 	this.intervalEnd = calendar.msToMoment(dateProfile.currentUnzonedRange.endMs, dateProfile.isRangeAllDay);
 
 	this.title = this.computeTitle(dateProfile);
-	this.calendar.reportViewDatesChanged(this, dateProfile);
+	this.calendar.reportViewDatesChanged(this, dateProfile); // TODO: reverse pubsub
+
+	for (i = 0; i < children.length; i++) {
+		children[i].set('dateProfile', dateProfile);
+	}
 });
 
 

+ 5 - 4
src/agenda/AgendaView.js

@@ -371,15 +371,16 @@ var agendaTimeGridMethods = {
 	// Generates the HTML that will go before the day-of week header cells
 	renderHeadIntroHtml: function() {
 		var view = this.view;
-		var dateProfile = view.get('dateProfile');
-		var weekStart = view.calendar.msToUtcMoment(dateProfile.renderUnzonedRange.startMs, true);
+		var calendar = view.calendar;
+		var dateProfile = this.get('dateProfile');
+		var weekStart = calendar.msToUtcMoment(dateProfile.renderUnzonedRange.startMs, true);
 		var weekText;
 
 		if (this.opt('weekNumbers')) {
 			weekText = weekStart.format(this.opt('smallWeekFormat'));
 
 			return '' +
-				'<th class="fc-axis fc-week-number ' + view.calendar.theme.getClass('widgetHeader') + '" ' + view.axisStyleAttr() + '>' +
+				'<th class="fc-axis fc-week-number ' + calendar.theme.getClass('widgetHeader') + '" ' + view.axisStyleAttr() + '>' +
 					view.buildGotoAnchorHtml( // aside from link, important for matchCellWidths
 						{ date: weekStart, type: 'week', forceOff: this.colCnt > 1 },
 						htmlEscape(weekText) // inner HTML
@@ -387,7 +388,7 @@ var agendaTimeGridMethods = {
 				'</th>';
 		}
 		else {
-			return '<th class="fc-axis ' + view.calendar.theme.getClass('widgetHeader') + '" ' + view.axisStyleAttr() + '></th>';
+			return '<th class="fc-axis ' + calendar.theme.getClass('widgetHeader') + '" ' + view.axisStyleAttr() + '></th>';
 		}
 	},
 

+ 4 - 4
src/agenda/TimeGrid.js

@@ -75,7 +75,7 @@ var TimeGrid = FC.TimeGrid = InteractiveDateComponent.extend(StandardInteraction
 
 
 	rangeUpdated: function() {
-		var dateProfile = this.view.get('dateProfile');
+		var dateProfile = this.get('dateProfile');
 
 		this.updateDayTable();
 
@@ -223,7 +223,7 @@ var TimeGrid = FC.TimeGrid = InteractiveDateComponent.extend(StandardInteraction
 		var calendar = view.calendar;
 		var theme = calendar.theme;
 		var isRTL = this.isRTL;
-		var dateProfile = view.get('dateProfile');
+		var dateProfile = this.get('dateProfile');
 		var html = '';
 		var slotTime = moment.duration(+dateProfile.minTime); // wish there was .clone() for durations
 		var slotIterator = moment.duration(0);
@@ -423,7 +423,7 @@ var TimeGrid = FC.TimeGrid = InteractiveDateComponent.extend(StandardInteraction
 	// Computes the top coordinate, relative to the bounds of the grid, of the given time (a Duration).
 	computeTimeTop: function(time) {
 		var len = this.slatEls.length;
-		var dateProfile = this.view.get('dateProfile');
+		var dateProfile = this.get('dateProfile');
 		var slatCoverage = (time - dateProfile.minTime) / this.slotDuration; // floating-point value of # of slots covered
 		var slatIndex;
 		var slatRemainder;
@@ -557,7 +557,7 @@ var TimeGrid = FC.TimeGrid = InteractiveDateComponent.extend(StandardInteraction
 
 	// Given a row number of the grid, representing a "snap", returns a time (Duration) from its start-of-day
 	computeSnapTime: function(snapIndex) {
-		return moment.duration(this.view.get('dateProfile').minTime + this.snapDuration * snapIndex);
+		return moment.duration(this.get('dateProfile').minTime + this.snapDuration * snapIndex);
 	},
 
 

+ 1 - 1
src/basic/DayGrid.js

@@ -185,7 +185,7 @@ var DayGrid = FC.DayGrid = InteractiveDateComponent.extend(StandardInteractionsM
 	renderNumberCellHtml: function(date) {
 		var view = this.view;
 		var html = '';
-		var isDateValid = view.get('dateProfile').activeUnzonedRange.containsDate(date); // TODO: called too frequently. cache somehow.
+		var isDateValid = this.get('dateProfile').activeUnzonedRange.containsDate(date); // TODO: called too frequently. cache somehow.
 		var isDayNumberVisible = view.dayNumbersVisible && isDateValid;
 		var classes;
 		var weekCalcFirstDoW;

+ 3 - 4
src/component/DateComponent.js

@@ -141,8 +141,7 @@ var DateComponent = Component.extend({
 
 	// TODO: eventually rename to `renderEvents` once legacy is gone.
 	renderEventsPayload: function(eventsPayload) {
-		var view = this._getView();
-		var dateProfile = view.get('dateProfile');
+		var dateProfile = this.get('dateProfile');
 		var id, eventInstanceGroup;
 		var eventRenderRanges;
 		var eventFootprints;
@@ -382,10 +381,10 @@ var DateComponent = Component.extend({
 
 
 	getSafeHitFootprint: function(hit) {
-		var view = this._getView();
+		var dateProfile = this.get('dateProfile');
 		var footprint = this.getHitFootprint(hit);
 
-		if (!view.get('dateProfile').activeUnzonedRange.containsRange(footprint.unzonedRange)) {
+		if (!dateProfile.activeUnzonedRange.containsRange(footprint.unzonedRange)) {
 			return null;
 		}
 

+ 1 - 1
src/component/DateComponent.util.js

@@ -59,7 +59,7 @@ DateComponent.mixin({
 		var classes = [];
 		var today;
 
-		if (!view.get('dateProfile').activeUnzonedRange.containsDate(date)) {
+		if (!this.get('dateProfile').activeUnzonedRange.containsDate(date)) {
 			classes.push('fc-disabled-day'); // TODO: jQuery UI theme?
 		}
 		else {

+ 3 - 3
src/component/DayTableMixin.js

@@ -18,7 +18,7 @@ var DayTableMixin = FC.DayTableMixin = {
 	updateDayTable: function() {
 		var view = this.view;
 		var calendar = view.calendar;
-		var dateProfile = view.get('dateProfile');
+		var dateProfile = this.get('dateProfile');
 		var date = calendar.msToUtcMoment(dateProfile.renderUnzonedRange.startMs, true);
 		var end = calendar.msToUtcMoment(dateProfile.renderUnzonedRange.endMs, true);
 		var dayIndex = -1;
@@ -297,7 +297,7 @@ var DayTableMixin = FC.DayTableMixin = {
 	// (colspan should be no different)
 	renderHeadDateCellHtml: function(date, colspan, otherAttrs) {
 		var view = this.view;
-		var isDateValid = view.get('dateProfile').activeUnzonedRange.containsDate(date); // TODO: called too frequently. cache somehow.
+		var isDateValid = this.get('dateProfile').activeUnzonedRange.containsDate(date); // TODO: called too frequently. cache somehow.
 		var classNames = [
 			'fc-day-header',
 			view.calendar.theme.getClass('widgetHeader')
@@ -375,7 +375,7 @@ var DayTableMixin = FC.DayTableMixin = {
 
 	renderBgCellHtml: function(date, otherAttrs) {
 		var view = this.view;
-		var isDateValid = view.get('dateProfile').activeUnzonedRange.containsDate(date); // TODO: called too frequently. cache somehow.
+		var isDateValid = this.get('dateProfile').activeUnzonedRange.containsDate(date); // TODO: called too frequently. cache somehow.
 		var classes = this.getDayClasses(date);
 
 		classes.unshift('fc-day', view.calendar.theme.getClass('widgetContent'));

+ 2 - 2
src/component/InteractiveDateComponent.js

@@ -295,7 +295,7 @@ var InteractiveDateComponent = DateComponent.extend({
 	// NOTE: very similar to isExternalInstanceGroupAllowed
 	isEventInstanceGroupAllowed: function(eventInstanceGroup) {
 		var view = this._getView();
-		var dateProfile = view.get('dateProfile');
+		var dateProfile = this.get('dateProfile');
 		var eventFootprints = this.eventRangesToEventFootprints(eventInstanceGroup.getAllEventRanges());
 		var i;
 
@@ -314,7 +314,7 @@ var InteractiveDateComponent = DateComponent.extend({
 	// when it's a completely anonymous external drag, no event.
 	isExternalInstanceGroupAllowed: function(eventInstanceGroup) {
 		var view = this._getView();
-		var dateProfile = view.get('dateProfile');
+		var dateProfile = this.get('dateProfile');
 		var eventFootprints = this.eventRangesToEventFootprints(eventInstanceGroup.getAllEventRanges());
 		var i;
 

+ 1 - 1
src/component/interactions/DateSelecting.js

@@ -152,7 +152,7 @@ var DateSelecting = Interaction.extend({
 
 
 	isSelectionFootprintAllowed: function(componentFootprint) {
-		return this.view.get('dateProfile').validUnzonedRange.containsRange(componentFootprint.unzonedRange) &&
+		return this.component.get('dateProfile').validUnzonedRange.containsRange(componentFootprint.unzonedRange) &&
 			this.view.calendar.isSelectionFootprintAllowed(componentFootprint);
 	}
 

+ 1 - 1
src/component/interactions/EventDragging.js

@@ -198,7 +198,7 @@ var EventDragging = Interaction.extend({
 					eventDefMutation &&
 					view.renderDrag( // truthy if rendered something
 						component.eventRangesToEventFootprints(
-							mutatedEventInstanceGroup.sliceRenderRanges(view.get('dateProfile').renderUnzonedRange, calendar)
+							mutatedEventInstanceGroup.sliceRenderRanges(component.get('dateProfile').renderUnzonedRange, calendar)
 						),
 						seg,
 						dragListener.isTouch

+ 1 - 1
src/component/interactions/EventResizing.js

@@ -118,7 +118,7 @@ var EventResizing = Interaction.extend({
 
 					component.renderEventResize(
 						component.eventRangesToEventFootprints(
-							mutatedEventInstanceGroup.sliceRenderRanges(view.get('dateProfile').renderUnzonedRange, calendar)
+							mutatedEventInstanceGroup.sliceRenderRanges(component.get('dateProfile').renderUnzonedRange, calendar)
 						),
 						seg
 					);

+ 1 - 1
src/component/interactions/ExternalDropping.js

@@ -100,7 +100,7 @@ var ExternalDropping = Interaction.extend(ListenerMixin, {
 				if (singleEventDef) {
 					component.renderDrag( // called without a seg parameter
 						component.eventRangesToEventFootprints(
-							mutatedEventInstanceGroup.sliceRenderRanges(view.get('dateProfile').renderUnzonedRange, view.calendar)
+							mutatedEventInstanceGroup.sliceRenderRanges(component.get('dateProfile').renderUnzonedRange, view.calendar)
 						)
 					);
 				}