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

begin to set up business hours rendering

Adam Shaw 8 лет назад
Родитель
Сommit
2ac1155071
4 измененных файлов с 25 добавлено и 18 удалено
  1. 1 0
      src/Calendar.js
  2. 17 0
      src/Calendar.render.js
  3. 7 7
      src/View.js
  4. 0 11
      src/component/DateComponent.js

+ 1 - 0
src/Calendar.js

@@ -5,6 +5,7 @@ var Calendar = FC.Calendar = Class.extend(EmitterMixin, ListenerMixin, {
 	viewsByType: null, // holds all instantiated view instances, current or not
 	currentDate: null, // unzoned moment. private (public API should use getDate instead)
 	theme: null,
+	businessHourGenerator: null,
 	loadingLevel: 0, // number of simultaneous loading tasks
 
 

+ 17 - 0
src/Calendar.render.js

@@ -72,6 +72,16 @@ Calendar.mixin({
 			}
 		});
 
+		this.optionsModel.watch('settingBusinessHourGenerator', [ '?businessHours' ], function(deps) {
+			_this.businessHourGenerator = new BusinessHourGenerator(deps.businessHours, _this);
+
+			if (_this.view) {
+				_this.view.set('businessHourGenerator', _this.businessHourGenerator)
+			}
+		}, function() {
+			_this.businessHourGenerator = null;
+		});
+
 		// called immediately, and upon option change.
 		// HACK: locale often affects isRTL, so we explicitly listen to that too.
 		this.optionsModel.watch('applyingDirClasses', [ '?isRTL', '?locale' ], function(opts) {
@@ -108,6 +118,7 @@ Calendar.mixin({
 
 		// removes theme-related root className
 		this.optionsModel.unwatch('settingTheme');
+		this.optionsModel.unwatch('settingBusinessHourGenerator');
 
 		this.el.off('.fc'); // unbind nav link handlers
 
@@ -233,6 +244,12 @@ Calendar.mixin({
 		}
 
 		if (this.view && this.elementVisible()) {
+
+			// prevent unnecessary change firing
+			if (this.view.get('businessHourGenerator') !== this.businessHourGenerator) {
+				this.view.set('businessHourGenerator', this.businessHourGenerator);
+			}
+
 			this.view.setDate(this.currentDate);
 		}
 

+ 7 - 7
src/View.js

@@ -225,13 +225,6 @@ var View = FC.View = InteractiveDateComponent.extend({
 			this.render(); // TODO: deprecate
 		}
 
-		// this.renderBusinessHours()
-		//// TODO: business hours
-		// new BusinessHourGenerator(
-		// 	deps.rawBusinessHours,
-		// 	this.calendar // TODO: untangle
-		// );
-
 		this.trigger('datesRendered');
 		this.addScroll({ isDateInit: true });
 		this.startNowIndicator(); // shouldn't render yet because updateSize will be called soon
@@ -863,6 +856,13 @@ View.watch('displayingDates', [ 'isInDom', 'dateProfile' ], function(deps) {
 });
 
 
+View.watch('displayingBusinessHours', [ 'displayingDates', 'businessHourGenerator' ], function() {
+	;
+}, function() {
+	;
+});
+
+
 View.watch('initialEvents', [ 'dateProfile' ], function(deps) {
 	return this.fetchInitialEvents(deps.dateProfile);
 });

+ 0 - 11
src/component/DateComponent.js

@@ -55,15 +55,6 @@ var DateComponent = FC.DateComponent = Component.extend({
 		if (!this.childrenByUid[child.uid]) {
 			this.childrenByUid[child.uid] = child;
 
-			// make new children catch up with old props
-			// TODO: what about eventDataSource? better system for this?
-			if (this.has('dateProfile')) {
-				child.set('dateProfile', this.get('dateProfile'));
-			}
-			if (this.has('businessHourGenerator')) {
-				this.setBusinessHourGeneratorInChild(this.get('businessHourGenerator'), child);
-			}
-
 			return true;
 		}
 
@@ -75,8 +66,6 @@ var DateComponent = FC.DateComponent = Component.extend({
 		if (this.childrenByUid[child.uid]) {
 			delete this.childrenByUid[child.uid];
 
-			this.stopListeningTo(child);
-
 			return true;
 		}