Ver Fonte

rename some View methods to make cleaner API

Adam Shaw há 11 anos atrás
pai
commit
e83fc43549

+ 7 - 7
src/Calendar.js

@@ -295,7 +295,7 @@ function Calendar(element, instanceOptions) {
 	function destroy() {
 
 		if (currentView) {
-			currentView.destroy();
+			currentView.destroyView();
 		}
 
 		header.destroy();
@@ -330,7 +330,7 @@ function Calendar(element, instanceOptions) {
 			header.deactivateButton(currentView.type);
 			freezeContentHeight(); // prevent a scroll jump when view element is removed
 			if (currentView.start) { // rendered before?
-				currentView.destroy();
+				currentView.destroyView();
 			}
 			currentView.el.remove();
 			currentView = null;
@@ -363,10 +363,10 @@ function Calendar(element, instanceOptions) {
 
 					freezeContentHeight();
 					if (currentView.start) { // rendered before?
-						currentView.destroy();
+						currentView.destroyView();
 					}
 					currentView.setDate(date);
-					currentView.render();
+					currentView.renderView();
 					unfreezeContentHeight();
 
 					// need to do this after View::render, so dates are calculated
@@ -551,8 +551,8 @@ function Calendar(element, instanceOptions) {
 	function renderEvents() { // destroys old events if previously rendered
 		if (elementVisible()) {
 			freezeContentHeight();
-			currentView.destroyEvents(); // no performance cost if never rendered
-			currentView.renderEvents(events);
+			currentView.destroyViewEvents(); // no performance cost if never rendered
+			currentView.renderViewEvents(events);
 			unfreezeContentHeight();
 		}
 	}
@@ -560,7 +560,7 @@ function Calendar(element, instanceOptions) {
 
 	function destroyEvents() {
 		freezeContentHeight();
-		currentView.destroyEvents();
+		currentView.destroyViewEvents();
 		unfreezeContentHeight();
 	}
 	

+ 6 - 15
src/agenda/AgendaView.js

@@ -30,9 +30,7 @@ var AgendaView = fcViews.agenda = View.extend({
 	bottomRuleHeight: null,
 
 
-	constructor: function() {
-		View.apply(this, arguments); // call the super-constructor
-
+	initialize: function() {
 		this.timeGrid = new TimeGrid(this);
 
 		if (this.opt('allDaySlot')) { // should we display the "all-day" area?
@@ -90,10 +88,6 @@ var AgendaView = fcViews.agenda = View.extend({
 		}
 
 		this.noScrollRowEls = this.el.find('.fc-row:not(.fc-scroller *)'); // fake rows not within the scroller
-
-		View.prototype.render.call(this); // call the super-method
-
-		this.resetScroll(); // do this after sizes have been set
 	},
 
 
@@ -277,8 +271,8 @@ var AgendaView = fcViews.agenda = View.extend({
 	},
 
 
-	// Sets the scroll value of the scroller to the intial pre-configured state prior to allowing the user to change it.
-	resetScroll: function() {
+	// Sets the scroll value of the scroller to the initial pre-configured state prior to allowing the user to change it
+	initializeScroll: function() {
 		var _this = this;
 		var scrollTime = moment.duration(this.opt('scrollTime'));
 		var top = this.timeGrid.computeTimeTop(scrollTime);
@@ -329,22 +323,19 @@ var AgendaView = fcViews.agenda = View.extend({
 
 		// the all-day area is flexible and might have a lot of events, so shift the height
 		this.updateHeight();
-
-		View.prototype.renderEvents.call(this, events); // call the super-method
 	},
 
 
 	// Retrieves all segment objects that are rendered in the view
-	getSegs: function() {
-		return this.timeGrid.getSegs().concat(
-			this.dayGrid ? this.dayGrid.getSegs() : []
+	getEventSegs: function() {
+		return this.timeGrid.getEventSegs().concat(
+			this.dayGrid ? this.dayGrid.getEventSegs() : []
 		);
 	},
 
 
 	// Unrenders all event elements and clears internal segment data
 	destroyEvents: function() {
-		View.prototype.destroyEvents.call(this); // do this before the grids' segs have been cleared
 
 		// if destroyEvents is being called as part of an event rerender, renderEvents will be called shortly
 		// after, so remember what the scroll value was so we can restore it.

+ 3 - 11
src/basic/BasicView.js

@@ -16,9 +16,7 @@ var BasicView = fcViews.basic = View.extend({
 	headRowEl: null, // the fake row element of the day-of-week header
 
 
-	constructor: function() {
-		View.apply(this, arguments); // call the super-constructor
-
+	initialize: function() {
 		this.dayGrid = new DayGrid(this);
 		this.coordMap = this.dayGrid.coordMap; // the view's date-to-cell mapping is identical to the subcomponent's
 	},
@@ -47,8 +45,6 @@ var BasicView = fcViews.basic = View.extend({
 
 		this.dayGrid.el = this.el.find('.fc-day-grid');
 		this.dayGrid.render(this.hasRigidRows());
-
-		View.prototype.render.call(this); // call the super-method
 	},
 
 
@@ -240,21 +236,17 @@ var BasicView = fcViews.basic = View.extend({
 		this.dayGrid.renderEvents(events);
 
 		this.updateHeight(); // must compensate for events that overflow the row
-
-		View.prototype.renderEvents.call(this, events); // call the super-method
 	},
 
 
 	// Retrieves all segment objects that are rendered in the view
-	getSegs: function() {
-		return this.dayGrid.getSegs();
+	getEventSegs: function() {
+		return this.dayGrid.getEventSegs();
 	},
 
 
 	// Unrenders all event elements and clears internal segment data
 	destroyEvents: function() {
-		View.prototype.destroyEvents.call(this); // do this before dayGrid's segs have been cleared
-
 		this.recordScroll(); // removing events will reduce height and mess with the scroll, so record beforehand
 		this.dayGrid.destroyEvents();
 

+ 2 - 2
src/common/DayGrid.events.js

@@ -15,8 +15,8 @@ DayGrid.mixin({
 
 
 	// Retrieves all rendered segment objects currently rendered on the grid
-	getSegs: function() {
-		return Grid.prototype.getSegs.call(this) // get the segments from the super-method
+	getEventSegs: function() {
+		return Grid.prototype.getEventSegs.call(this) // get the segments from the super-method
 			.concat(this.popoverSegs || []); // append the segments from the "more..." popover
 	},
 

+ 1 - 1
src/common/Grid.events.js

@@ -49,7 +49,7 @@ Grid.mixin({
 
 
 	// Retrieves all rendered segment objects currently rendered on the grid
-	getSegs: function() {
+	getEventSegs: function() {
 		return this.segs || [];
 	},
 

+ 64 - 21
src/common/View.js

@@ -53,6 +53,14 @@ var View = fc.View = Class.extend({
 		this.initHiddenDays();
 
 		this.documentMousedownProxy = $.proxy(this, 'documentMousedown');
+
+		this.initialize();
+	},
+
+
+	// A good place for subclasses to initialize member variables
+	initialize: function() {
+		// subclasses can implement
 	},
 
 
@@ -212,10 +220,11 @@ var View = fc.View = Class.extend({
 	------------------------------------------------------------------------------------------------------------------*/
 
 
-	// Renders the view inside an already-defined `this.el`.
-	// Subclasses should override this and then call the super method afterwards.
-	render: function() {
+	// Wraps the basic render() method with more View-specific logic. Called by the owner Calendar.
+	renderView: function() {
+		this.render();
 		this.updateSize();
+		this.initializeScroll();
 		this.trigger('viewRender', this, this, this.el);
 
 		// attach handlers to document. do it here to allow for destroy/rerender
@@ -223,17 +232,29 @@ var View = fc.View = Class.extend({
 	},
 
 
-	// Clears all view rendering, event elements, and unregisters handlers
-	destroy: function() {
+	// Renders the view inside an already-defined `this.el`
+	render: function() {
+		// subclasses should implement
+	},
+
+
+	// Wraps the basic destroy() method with more View-specific logic. Called by the owner Calendar.
+	destroyView: function() {
 		this.unselect();
+		this.destroyViewEvents();
+		this.destroy();
 		this.trigger('viewDestroy', this, this, this.el);
-		this.destroyEvents();
-		this.el.empty(); // removes inner contents but leaves the element intact
 
 		$(document).off('mousedown', this.documentMousedownProxy);
 	},
 
 
+	// Clears the view's rendering
+	destroy: function() {
+		this.el.empty(); // removes inner contents but leaves the element intact
+	},
+
+
 	// Initializes internal variables related to theming
 	initTheming: function() {
 		var tm = this.opt('theme') ? 'ui' : 'fc';
@@ -282,6 +303,10 @@ var View = fc.View = Class.extend({
 	},
 
 
+	/* Scroller
+	------------------------------------------------------------------------------------------------------------------*/
+
+
 	// Given the total height of the view, return the number of pixels that should be used for the scroller.
 	// By default, uses this.scrollerEl, but can pass this in as well.
 	// Utility for subclasses.
@@ -304,6 +329,11 @@ var View = fc.View = Class.extend({
 	},
 
 
+	// Sets the scroll value of the scroller to the initial pre-configured state prior to allowing the user to change it
+	initializeScroll: function() {
+	},
+
+
 	// Called for remembering the current scroll value of the scroller.
 	// Should be called before there is a destructive operation (like removing DOM elements) that might inadvertently
 	// change the scroll of the container.
@@ -328,22 +358,36 @@ var View = fc.View = Class.extend({
 	------------------------------------------------------------------------------------------------------------------*/
 
 
-	// Renders the events onto the view.
-	// Should be overriden by subclasses. Subclasses should call the super-method afterwards.
-	renderEvents: function(events) {
-		this.segEach(function(seg) {
+	// Wraps the basic renderEvents() method with more View-specific logic
+	renderViewEvents: function(events) {
+		this.renderEvents(events);
+
+		this.eventSegEach(function(seg) {
 			this.trigger('eventAfterRender', seg.event, seg.event, seg.el);
 		});
 		this.trigger('eventAfterAllRender');
 	},
 
 
-	// Removes event elements from the view.
-	// Should be overridden by subclasses. Should call this super-method FIRST, then subclass DOM destruction.
-	destroyEvents: function() {
-		this.segEach(function(seg) {
+	// Renders the events onto the view.
+	renderEvents: function() {
+		// subclasses should implement
+	},
+
+
+	// Wraps the basic destroyEvents() method with more View-specific logic
+	destroyViewEvents: function() {
+		this.eventSegEach(function(seg) {
 			this.trigger('eventDestroy', seg.event, seg.event, seg.el);
 		});
+
+		this.destroyEvents();
+	},
+
+
+	// Removes event elements from the view.
+	destroyEvents: function() {
+		// subclasses should implement
 	},
 
 
@@ -365,7 +409,7 @@ var View = fc.View = Class.extend({
 
 	// Hides all rendered event segments linked to the given event
 	showEvent: function(event) {
-		this.segEach(function(seg) {
+		this.eventSegEach(function(seg) {
 			seg.el.css('visibility', '');
 		}, event);
 	},
@@ -373,7 +417,7 @@ var View = fc.View = Class.extend({
 
 	// Shows all rendered event segments linked to the given event
 	hideEvent: function(event) {
-		this.segEach(function(seg) {
+		this.eventSegEach(function(seg) {
 			seg.el.css('visibility', 'hidden');
 		}, event);
 	},
@@ -382,8 +426,8 @@ var View = fc.View = Class.extend({
 	// Iterates through event segments. Goes through all by default.
 	// If the optional `event` argument is specified, only iterates through segments linked to that event.
 	// The `this` value of the callback function will be the view.
-	segEach: function(func, event) {
-		var segs = this.getSegs();
+	eventSegEach: function(func, event) {
+		var segs = this.getEventSegs();
 		var i;
 
 		for (i = 0; i < segs.length; i++) {
@@ -395,7 +439,7 @@ var View = fc.View = Class.extend({
 
 
 	// Retrieves all the rendered segment objects for the view
-	getSegs: function() {
+	getEventSegs: function() {
 		// subclasses must implement
 	},
 
@@ -530,7 +574,6 @@ var View = fc.View = Class.extend({
 	},
 
 
-
 	/* Selection
 	------------------------------------------------------------------------------------------------------------------*/