Przeglądaj źródła

Grid::cellDuration

Adam Shaw 11 lat temu
rodzic
commit
5b1d6ecb0d
3 zmienionych plików z 32 dodań i 11 usunięć
  1. 10 5
      src/common/DayGrid.js
  2. 18 1
      src/common/Grid.js
  3. 4 5
      src/common/TimeGrid.js

+ 10 - 5
src/common/DayGrid.js

@@ -16,6 +16,13 @@ var DayGrid = Grid.extend({
 	helperEls: null, // set of cell skeleton elements for rendering the mock event "helper"
 	helperEls: null, // set of cell skeleton elements for rendering the mock event "helper"
 
 
 
 
+	constructor: function() {
+		Grid.apply(this, arguments);
+
+		this.cellDuration = moment.duration(1, 'day'); // for Grid system
+	},
+
+
 	// Renders the rows and columns into the component's `this.el`, which should already be assigned.
 	// Renders the rows and columns into the component's `this.el`, which should already be assigned.
 	// isRigid determins whether the individual rows should ignore the contents and be a constant height.
 	// isRigid determins whether the individual rows should ignore the contents and be a constant height.
 	// Relies on the view's colCnt and rowCnt. In the future, this component should probably be self-sufficient.
 	// Relies on the view's colCnt and rowCnt. In the future, this component should probably be self-sufficient.
@@ -184,14 +191,12 @@ var DayGrid = Grid.extend({
 	},
 	},
 
 
 
 
-	// Given a cell object, generates a range object
-	computeCellRange: function(cell) {
+	// Given a cell object, generates its start date. Returns a reference-free copy.
+	computeCellDate: function(cell) {
 		var colCnt = this.colCnt;
 		var colCnt = this.colCnt;
 		var index = cell.row * colCnt + (this.isRTL ? colCnt - cell.col - 1 : cell.col);
 		var index = cell.row * colCnt + (this.isRTL ? colCnt - cell.col - 1 : cell.col);
-		var start = this.cellDates[index].clone();
-		var end = start.clone().add(1, 'day');
 
 
-		return { start: start, end: end };
+		return this.cellDates[index].clone();
 	},
 	},
 
 
 
 

+ 18 - 1
src/common/Grid.js

@@ -23,6 +23,10 @@ var Grid = fc.Grid = RowRenderer.extend({
 	eventTimeFormat: null,
 	eventTimeFormat: null,
 	displayEventEnd: null,
 	displayEventEnd: null,
 
 
+	// if all cells are the same length of time, the duration they all share. optional.
+	// when defined, allows the computeCellRange shortcut, as well as improved resizing behavior.
+	cellDuration: null,
+
 	// if defined, holds the unit identified (ex: "year" or "month") that determines the level of granularity
 	// if defined, holds the unit identified (ex: "year" or "month") that determines the level of granularity
 	// of the date cells. if not defined, assumes to be day and time granularity.
 	// of the date cells. if not defined, assumes to be day and time granularity.
 	largeUnit: null,
 	largeUnit: null,
@@ -139,8 +143,21 @@ var Grid = fc.Grid = RowRenderer.extend({
 
 
 
 
 	// Given a cell object with index and misc data, generates a range object
 	// Given a cell object with index and misc data, generates a range object
+	// If the grid is leveraging cellDuration, this doesn't need to be defined. Only computeCellDate does.
+	// If being overridden, should return a range with reference-free date copies.
 	computeCellRange: function(cell) {
 	computeCellRange: function(cell) {
-		// subclasses must implement
+		var date = this.computeCellDate(cell);
+
+		return {
+			start: date,
+			end: date.clone().add(this.cellDuration)
+		};
+	},
+
+
+	// Given a cell, returns its start date. Should return a reference-free date copy.
+	computeCellDate: function(cell) {
+		// subclasses can implement
 	},
 	},
 
 
 
 

+ 4 - 5
src/common/TimeGrid.js

@@ -121,6 +121,7 @@ var TimeGrid = Grid.extend({
 
 
 		this.slotDuration = slotDuration;
 		this.slotDuration = slotDuration;
 		this.snapDuration = snapDuration;
 		this.snapDuration = snapDuration;
+		this.cellDuration = snapDuration; // for Grid system
 
 
 		this.minTime = moment.duration(view.opt('minTime'));
 		this.minTime = moment.duration(view.opt('minTime'));
 		this.maxTime = moment.duration(view.opt('maxTime'));
 		this.maxTime = moment.duration(view.opt('maxTime'));
@@ -181,13 +182,11 @@ var TimeGrid = Grid.extend({
 	},
 	},
 
 
 
 
-	// Given a cell object, generates a range object
-	computeCellRange: function(cell) {
+	// Given a cell object, generates its start date. Returns a reference-free copy.
+	computeCellDate: function(cell) {
 		var time = this.computeSnapTime(cell.row);
 		var time = this.computeSnapTime(cell.row);
-		var start = this.view.calendar.rezoneDate(cell.day).time(time);
-		var end = start.clone().add(this.snapDuration);
 
 
-		return { start: start, end: end };
+		return this.view.calendar.rezoneDate(cell.day).time(time);
 	},
 	},