瀏覽代碼

change how the cell system generates dates and misc data

Adam Shaw 10 年之前
父節點
當前提交
59f1fd348a
共有 4 個文件被更改,包括 41 次插入31 次删除
  1. 2 0
      src/common/CoordMap.js
  2. 5 2
      src/common/DayGrid.js
  3. 16 15
      src/common/Grid.js
  4. 18 14
      src/common/TimeGrid.js

+ 2 - 0
src/common/CoordMap.js

@@ -30,6 +30,7 @@ var GridCoordMap = Class.extend({
 
 	// Queries the grid for the coordinates of all the cells
 	build: function() {
+		this.grid.build();
 		this.rowCoords = this.grid.computeRowCoords();
 		this.colCoords = this.grid.computeColCoords();
 		this.computeBounds();
@@ -38,6 +39,7 @@ var GridCoordMap = Class.extend({
 
 	// Clears the coordinates data to free up memory
 	clear: function() {
+		this.grid.clear();
 		this.rowCoords = null;
 		this.colCoords = null;
 	},

+ 5 - 2
src/common/DayGrid.js

@@ -136,13 +136,16 @@ var DayGrid = Grid.extend({
 	------------------------------------------------------------------------------------------------------------------*/
 
 
-	// Initializes row/col information
-	updateCells: function() {
+	// Tells the grid about what period of time to display.
+	// Any date-related cell system internal data should be generated.
+	setRange: function() {
 		var cellDates;
 		var firstDay;
 		var rowCnt;
 		var colCnt;
 
+		Grid.prototype.setRange.apply(this, arguments); // call the super-method
+
 		this.updateCellDates(); // populates cellDates and dayToCellOffsets
 		cellDates = this.cellDates;
 

+ 16 - 15
src/common/Grid.js

@@ -9,8 +9,6 @@ var Grid = fc.Grid = RowRenderer.extend({
 
 	rowCnt: 0, // number of rows
 	colCnt: 0, // number of cols
-	rowData: null, // array of objects, holding misc data for each row
-	colData: null, // array of objects, holding misc data for each column
 
 	el: null, // the containing element
 	coordMap: null, // a GridCoordMap that converts pixel values to datetimes
@@ -76,7 +74,20 @@ var Grid = fc.Grid = RowRenderer.extend({
 	------------------------------------------------------------------------------------------------------------------*/
 
 
-	// Tells the grid about what period of time to display. Grid will subsequently compute dates for cell system.
+	// Called before the grid will need to be queried for cells.
+	// Any non-date-related cell system internal data should be built.
+	build: function() {
+	},
+
+
+	// Called after the grid is done being relied upon.
+	// Any non-date-related cell system internal data should be cleared.
+	clear: function() {
+	},
+
+
+	// Tells the grid about what period of time to display.
+	// Any date-related cell system internal data should be generated.
 	setRange: function(range) {
 		var view = this.view;
 		var displayEventTime;
@@ -85,10 +96,6 @@ var Grid = fc.Grid = RowRenderer.extend({
 		this.start = range.start.clone();
 		this.end = range.end.clone();
 
-		this.rowData = [];
-		this.colData = [];
-		this.updateCells();
-
 		// Populate option-derived settings. Look for override first, then compute if necessary.
 		this.colHeadFormat = view.opt('columnFormat') || this.computeColHeadFormat();
 
@@ -112,12 +119,6 @@ var Grid = fc.Grid = RowRenderer.extend({
 	},
 
 
-	// Responsible for setting rowCnt/colCnt and any other row/col data
-	updateCells: function() {
-		// subclasses must implement
-	},
-
-
 	// Converts a range with an inclusive `start` and an exclusive `end` into an array of segment objects
 	rangeToSegs: function(range) {
 		// subclasses must implement
@@ -186,13 +187,13 @@ var Grid = fc.Grid = RowRenderer.extend({
 
 	// Retrieves misc data about the given row
 	getRowData: function(row) {
-		return this.rowData[row] || {};
+		return {};
 	},
 
 
 	// Retrieves misc data baout the given column
 	getColData: function(col) {
-		return this.colData[col] || {};
+		return {};
 	},
 
 

+ 18 - 14
src/common/TimeGrid.js

@@ -6,10 +6,9 @@ var TimeGrid = Grid.extend({
 
 	slotDuration: null, // duration of a "slot", a distinct time segment on given day, visualized by lines
 	snapDuration: null, // granularity of time for dragging and selecting
-
 	minTime: null, // Duration object that denotes the first visible time of any given day
 	maxTime: null, // Duration object that denotes the exclusive visible end time of any given day
-
+	colDates: null, // whole-day dates for each column. left to right
 	axisFormat: null, // formatting string for times running along vertical axis
 
 	dayEls: null, // cells elements in the day-row background
@@ -157,36 +156,41 @@ var TimeGrid = Grid.extend({
 	------------------------------------------------------------------------------------------------------------------*/
 
 
-	// Initializes row/col information
-	updateCells: function() {
+	// Tells the grid about what period of time to display.
+	// Any date-related cell system internal data should be generated.
+	setRange: function() {
 		var view = this.view;
-		var colData = [];
+		var colDates = [];
 		var date;
 
+		Grid.prototype.setRange.apply(this, arguments); // call the super-method
+
 		date = this.start.clone();
 		while (date.isBefore(this.end)) {
-			colData.push({
-				day: date.clone()
-			});
+			colDates.push(date.clone());
 			date.add(1, 'day');
 			date = view.skipHiddenDays(date);
 		}
 
 		if (this.isRTL) {
-			colData.reverse();
+			colDates.reverse();
 		}
 
-		this.colData = colData;
-		this.colCnt = colData.length;
+		this.colDates = colDates;
+		this.colCnt = colDates.length;
 		this.rowCnt = Math.ceil((this.maxTime - this.minTime) / this.snapDuration); // # of vertical snaps
 	},
 
 
 	// Given a cell object, generates its start date. Returns a reference-free copy.
 	computeCellDate: function(cell) {
+		var date = this.colDates[cell.col];
 		var time = this.computeSnapTime(cell.row);
 
-		return this.view.calendar.rezoneDate(cell.day).time(time);
+		date = this.view.calendar.rezoneDate(date); // give it a 00:00 time
+		date.time(time);
+
+		return date;
 	},
 
 
@@ -222,7 +226,7 @@ var TimeGrid = Grid.extend({
 		};
 
 		for (col = 0; col < colCnt; col++) {
-			colDate = this.colData[col].day; // will be ambig time/timezone
+			colDate = this.colDates[col]; // will be ambig time/timezone
 			colRange = {
 				start: colDate.clone().time(this.minTime),
 				end: colDate.clone().time(this.maxTime)
@@ -472,7 +476,7 @@ var TimeGrid = Grid.extend({
 
 				if (colSegs.length) {
 					containerEl = $('<div class="fc-' + className + '-container"/>').appendTo(tdEl);
-					dayDate = this.colData[col].day;
+					dayDate = this.colDates[col];
 
 					for (i = 0; i < colSegs.length; i++) {
 						seg = colSegs[i];