Explorar o código

own file for EventInstanceRepo

Adam Shaw %!s(int64=8) %!d(string=hai) anos
pai
achega
9f8be1ad10
Modificáronse 3 ficheiros con 119 adicións e 119 borrados
  1. 1 0
      src.json
  2. 0 119
      src/models/EventInstanceChangeset.js
  3. 118 0
      src/models/EventInstanceRepo.js

+ 1 - 0
src.json

@@ -59,6 +59,7 @@
     "models/EventManager.js",
     "models/EventInstanceDataSource.js",
     "models/EventPeriod.js",
+    "models/EventInstanceRepo.js",
     "models/EventInstanceChangeset.js",
     "models/BusinessHourGenerator.js",
     "models/event/EventDefParser.js",

+ 0 - 119
src/models/EventInstanceChangeset.js

@@ -1,123 +1,4 @@
 
-var EventInstanceRepo = Class.extend({
-
-	byDefId: null,
-	cnt: 0,
-
-
-	constructor: function(eventInstances) {
-		this.byDefId = {};
-
-		(eventInstances || []).forEach(this.addEventInstance.bind(this));
-	},
-
-
-	getEventInstancesForDef: function(eventDef) {
-		return (this.byDefId[eventDef.id] || []).filter(function(eventInstance) {
-			return eventInstance.def === eventDef;
-		});
-	},
-
-
-	getEventInstances: function() {
-		var byDefId = this.byDefId;
-		var a = [];
-		var id;
-
-		for (id in byDefId) {
-			a.push.apply(a, byDefId[id]);
-		}
-
-		return a;
-	},
-
-
-	iterEventInstances: function(func) {
-		var byDefId = this.byDefId;
-		var defId, instances;
-		var i;
-
-		for (defId in byDefId) {
-			instances = byDefId[defId];
-
-			for (i = 0; i < instances.length; i++) {
-				func(instances[i]);
-			}
-		}
-	},
-
-
-	getEventInstancesWithId: function(eventDefId) {
-		var bucket = this.byDefId[eventDefId];
-
-		if (bucket) {
-			return bucket.slice(); // clone
-		}
-
-		return [];
-	},
-
-
-	getEventInstancesWithoutId: function(eventDefId) {
-		var byDefId = this.byDefId;
-		var a = [];
-		var id;
-
-		for (id in byDefId) {
-			if (id !== eventDefId) {
-				a.push.apply(a, byDefId[id]);
-			}
-		}
-
-		return a;
-	},
-
-
-	addEventInstance: function(eventInstance) {
-		this._addEventInstance(eventInstance.def.id, eventInstance);
-	},
-
-
-	removeEventInstance: function(eventInstance) {
-		return this._removeEventInstance(eventInstance.def.id, eventInstance);
-	},
-
-
-	_addEventInstance: function(id, eventInstance) {
-		(this.byDefId[id] || (this.byDefId[id] = []))
-			.push(eventInstance);
-
-		this.cnt++;
-	},
-
-
-	_removeEventInstance: function(id, eventInstance) {
-		var bucket = this.byDefId[id];
-
-		if (bucket && removeExact(bucket, eventInstance)) {
-
-			if (!bucket.length) {
-				delete this.byDefId[id];
-			}
-
-			this.cnt--;
-
-			return true;
-		}
-
-		return false;
-	},
-
-
-	clear: function() {
-		this.byDefId = {};
-		this.cnt = 0;
-	}
-
-
-});
-
-
 var EventInstanceChangeset = Class.extend({
 
 	isClear: false,

+ 118 - 0
src/models/EventInstanceRepo.js

@@ -0,0 +1,118 @@
+
+var EventInstanceRepo = Class.extend({
+
+	byDefId: null,
+	cnt: 0,
+
+
+	constructor: function(eventInstances) {
+		this.byDefId = {};
+
+		(eventInstances || []).forEach(this.addEventInstance.bind(this));
+	},
+
+
+	getEventInstancesForDef: function(eventDef) {
+		return (this.byDefId[eventDef.id] || []).filter(function(eventInstance) {
+			return eventInstance.def === eventDef;
+		});
+	},
+
+
+	getEventInstances: function() {
+		var byDefId = this.byDefId;
+		var a = [];
+		var id;
+
+		for (id in byDefId) {
+			a.push.apply(a, byDefId[id]);
+		}
+
+		return a;
+	},
+
+
+	iterEventInstances: function(func) {
+		var byDefId = this.byDefId;
+		var defId, instances;
+		var i;
+
+		for (defId in byDefId) {
+			instances = byDefId[defId];
+
+			for (i = 0; i < instances.length; i++) {
+				func(instances[i]);
+			}
+		}
+	},
+
+
+	getEventInstancesWithId: function(eventDefId) {
+		var bucket = this.byDefId[eventDefId];
+
+		if (bucket) {
+			return bucket.slice(); // clone
+		}
+
+		return [];
+	},
+
+
+	getEventInstancesWithoutId: function(eventDefId) {
+		var byDefId = this.byDefId;
+		var a = [];
+		var id;
+
+		for (id in byDefId) {
+			if (id !== eventDefId) {
+				a.push.apply(a, byDefId[id]);
+			}
+		}
+
+		return a;
+	},
+
+
+	addEventInstance: function(eventInstance) {
+		this._addEventInstance(eventInstance.def.id, eventInstance);
+	},
+
+
+	removeEventInstance: function(eventInstance) {
+		return this._removeEventInstance(eventInstance.def.id, eventInstance);
+	},
+
+
+	_addEventInstance: function(id, eventInstance) {
+		(this.byDefId[id] || (this.byDefId[id] = []))
+			.push(eventInstance);
+
+		this.cnt++;
+	},
+
+
+	_removeEventInstance: function(id, eventInstance) {
+		var bucket = this.byDefId[id];
+
+		if (bucket && removeExact(bucket, eventInstance)) {
+
+			if (!bucket.length) {
+				delete this.byDefId[id];
+			}
+
+			this.cnt--;
+
+			return true;
+		}
+
+		return false;
+	},
+
+
+	clear: function() {
+		this.byDefId = {};
+		this.cnt = 0;
+	}
+
+
+});