Kaynağa Gözat

have event AND event source models use ParsableModelMixin

Adam Shaw 8 yıl önce
ebeveyn
işleme
30338810ec

+ 0 - 9
src/common/ParsableModelMixin.js

@@ -35,15 +35,6 @@ var ParsableModelMixin = {
 	If subclasses override, they must call this supermethod and return the boolean response.
 	*/
 	applyManualRawProps: function(rawProps) {
-		this.id = EventSource.normalizeId(rawProps.id);
-
-		if ($.isArray(rawProps.className)) {
-			this.className = rawProps.className;
-		}
-		if (typeof rawProps.className === 'string') {
-			this.className = rawProps.className.split(/\s+/);
-		}
-
 		return true;
 	},
 

+ 24 - 1
src/models/event-source/EventSource.js

@@ -3,7 +3,7 @@ var EventSource = Class.extend(ParsableModelMixin, {
 
 	calendar: null,
 
-	id: null,
+	id: null, // can stay null
 	uid: null,
 	color: null,
 	backgroundColor: null,
@@ -63,6 +63,24 @@ var EventSource = Class.extend(ParsableModelMixin, {
 		}
 
 		return eventDefs;
+	},
+
+
+	applyManualRawProps: function(rawProps) {
+
+		if (rawProps.id != null) {
+			this.id = EventSource.normalizeId(rawProps.id);
+		}
+
+		// TODO: converge with EventDef
+		if ($.isArray(rawProps.className)) {
+			this.className = rawProps.className;
+		}
+		else if (typeof rawProps.className === 'string') {
+			this.className = rawProps.className.split(/\s+/);
+		}
+
+		return true;
 	}
 
 });
@@ -72,6 +90,11 @@ var EventSource = Class.extend(ParsableModelMixin, {
 EventSource.allowRawProps = ParsableModelMixin_allowRawProps;
 
 
+// IDs
+// ---------------------------------------------------------------------------------------------------------------------
+// TODO: converge with EventDef
+
+
 EventSource.uuid = 0;
 
 

+ 39 - 86
src/models/event/EventDef.js

@@ -1,5 +1,5 @@
 
-var EventDef = FC.EventDef = Class.extend({
+var EventDef = FC.EventDef = Class.extend(ParsableModelMixin, {
 
 	source: null, // required
 
@@ -124,56 +124,41 @@ var EventDef = FC.EventDef = Class.extend({
 	},
 
 
-	// Standard Prop Parsing System, for the INSTANCE
-	// -----------------------------------------------------------------------------------------------------------------
+	applyManualRawProps: function(rawProps) {
 
-	standardPropMap: {}, // ::defineStandardProps will always clone
-
-
-	/*
-	returns false on failure
-	*/
-	applyRawProps: function(rawProps) {
-		var standardPropMap = this.standardPropMap;
-		var miscProps = {};
-		var propName;
-
-		if (rawProps.id == null) {
-			this.id = EventDef.generateId();
+		if (rawProps.id != null) {
+			this.id = EventDef.normalizeId((this.rawId = rawProps.id));
 		}
 		else {
-			this.id = EventDef.normalizeId((this.rawId = rawProps.id));
+			this.id = EventDef.generateId();
 		}
 
-		// can make DRY with EventSource
+		// TODO: converge with EventSource
 		if ($.isArray(rawProps.className)) {
 			this.className = rawProps.className;
 		}
-		else if (typeof rawProps.className === 'string') {
+		if (typeof rawProps.className === 'string') {
 			this.className = rawProps.className.split(/\s+/);
 		}
 
-		for (propName in rawProps) {
-			if (propName in standardPropMap) {
-				if (standardPropMap[propName] === true) { // copy verbatim?
-					this[propName] = rawProps[propName];
-				}
-			}
-			else {
-				miscProps[propName] = rawProps[propName];
-			}
-		}
+		return true;
+	},
 
-		this.miscProps = miscProps;
 
-		return true;
+	applyOtherRawProps: function(rawProps) {
+		this.miscProps = rawProps;
 	}
 
 });
 
+// finish initializing the mixin
+EventDef.allowRawProps = ParsableModelMixin_allowRawProps;
+EventDef.copyVerbatimStandardProps = ParsableModelMixin_copyVerbatimStandardProps;
+
 
-// ID
+// IDs
 // ---------------------------------------------------------------------------------------------------------------------
+// TODO: converge with EventSource
 
 
 EventDef.uuid = 0;
@@ -189,63 +174,11 @@ EventDef.generateId = function() {
 };
 
 
-// Standard Prop *Parsing* System, for class self-definition
-// ---------------------------------------------------------------------------------------------------------------------
-
-
-EventDef.defineStandardProps = function(propDefs) {
-	var proto = this.prototype;
-
-	proto.standardPropMap = Object.create(proto.standardPropMap);
-
-	copyOwnProps(propDefs, proto.standardPropMap);
-};
-
-
-EventDef.copyVerbatimStandardProps = function(src, dest) {
-	var map = this.prototype.standardPropMap;
-	var propName;
-
-	for (propName in map) {
-		if (
-			src[propName] != null && // in the src object?
-			map[propName] === true // false means "copy verbatim"
-		) {
-			dest[propName] = src[propName];
-		}
-	}
-};
-
-
 // Parsing
 // ---------------------------------------------------------------------------------------------------------------------
 
 
-EventDef.parse = function(rawInput, source) {
-	var def = new this(source);
-	var calendarTransform = source.calendar.opt('eventDataTransform');
-	var sourceTransform = source.eventDataTransform;
-
-	if (calendarTransform) {
-		rawInput = calendarTransform(rawInput);
-	}
-	if (sourceTransform) {
-		rawInput = sourceTransform(rawInput);
-	}
-
-	if (def.applyRawProps(rawInput) === false) {
-		return false;
-	}
-
-	return def;
-};
-
-
-// Definitions for this abstract EventDef class
-// ---------------------------------------------------------------------------------------------------------------------
-
-
-EventDef.defineStandardProps({
+EventDef.allowRawProps({
 	// not automatically assigned (`false`)
 	id: false,
 	className: false,
@@ -260,9 +193,29 @@ EventDef.defineStandardProps({
 	editable: true,
 	startEditable: true,
 	durationEditable: true,
-	resourceEditable: true,
+	//resourceEditable: true,
 	color: true,
 	backgroundColor: true,
 	borderColor: true,
 	textColor: true
 });
+
+
+EventDef.parse = function(rawInput, source) {
+	var def = new this(source);
+	var calendarTransform = source.calendar.opt('eventDataTransform');
+	var sourceTransform = source.eventDataTransform;
+
+	if (calendarTransform) {
+		rawInput = calendarTransform(rawInput);
+	}
+	if (sourceTransform) {
+		rawInput = sourceTransform(rawInput);
+	}
+
+	if (def.applyRawProps(rawInput)) {
+		return def;
+	}
+
+	return false;
+};

+ 1 - 1
src/models/event/RecurringEventDef.js

@@ -110,7 +110,7 @@ var RecurringEventDef = EventDef.extend({
 // ---------------------------------------------------------------------------------------------------------------------
 
 
-RecurringEventDef.defineStandardProps({
+RecurringEventDef.allowRawProps({ // false = manually process
 	start: false,
 	end: false,
 	dow: false

+ 3 - 3
src/models/event/SingleEventDef.js

@@ -49,8 +49,8 @@ var SingleEventDef = EventDef.extend({
 	/*
 	NOTE: if super-method fails, should still attempt to apply
 	*/
-	applyRawProps: function(rawProps) {
-		var superSuccess = EventDef.prototype.applyRawProps.apply(this, arguments);
+	applyManualRawProps: function(rawProps) {
+		var superSuccess = EventDef.prototype.applyManualRawProps.apply(this, arguments);
 		var dateProfile = EventDateProfile.parse(rawProps, this.source); // returns null on failure
 
 		if (dateProfile) {
@@ -70,7 +70,7 @@ var SingleEventDef = EventDef.extend({
 // ---------------------------------------------------------------------------------------------------------------------
 
 
-SingleEventDef.defineStandardProps({
+SingleEventDef.allowRawProps({ // false = manually process
 	start: false,
 	date: false, // alias for 'start'
 	end: false,