
/**
* Determine contexts that are dirty
*/
var Dirty = Class.create();

Dirty.prototype = {
	initialize: function() {
		this.dirt = new Object();
	},

	getDirty: function(context) {
		return this.dirt[context];
	},

	add: function(context, entityID) {
		if (entityID == undefined || entityID == null || entityID.length == 0) entityID = -1;
		this.dirt[context] = entityID;
	},

	remove: function(context) {
		delete this.dirt[context];
	},

	removeAll: function() {
		this.dirt = new Object();
	},
	
	toString: function() {
		var str = '';
		for (context in this.dirt) {
			str += this.dirt[context] + ',';
		}
		return str;
	}

};



/**
* Used to filter a list of entities so that there only contain instances defined by the filter
* Example 1: used to filter categories by both collection and product instances
* Example 2: use <table_name>-<field_name> combination when applying search filters
* Defines a WHERE clause with AND operators
*/
var ListFilters = Class.create();
ListFilters.prototype = {
	initialize: function() {
		this.filters = new Array();
	},

	addFilter: function(filterName, filterID) {
		this.filters.push(filterName + "=" + filterID);
	},

	serialize: function() {
		var queryString = "";
		for (i = 0; i < this.filters.length; i++) {
			if (i < (this.filters.length - 1)) queryString += 'filter_' + this.filters[i] + '&';
			else queryString += 'filter_' + this.filters[i];
		}
		return queryString;
	}
};

/**
* Used to filter a list of entities so that there only contain instances related to the entity instance defined by the filter
* Example: used to filter collections by product instance
* Defines a simple WHERE clause
*/
var ListFilter = Class.create();
ListFilter.prototype = {
	initialize: function(filterName, filterID, filterOption) {
		this.filterName = filterName;
		this.filterID = filterID;
		if (filterOption != undefined && filterOption != null) this.filterOption = filterOption;
		else this.filterOption = '';
	},

	serialize: function() {
		return $H({'filterName': this.filterName, 'filterID': this.filterID, 'filterOption': this.filterOption}).toQueryString();
	}
};

/**
* Used to select items in a list
*/
var Selection = Class.create();
Selection.prototype = {
	initialize: function(selectionName, selectionID, selectionOption) {
		this.selectionName = selectionName;
		this.selectionID = selectionID;
		if (selectionOption == undefined && selectionOption == null) this.selectionOption = '';
		else this.selectionOption = selectionOption;
	},

	serialize: function() {
		return $H({'selectionName': this.selectionName, 'selectionID': this.selectionID, 'selectionOption': this.selectionOption}).toQueryString();
	}
};

/**
* Used to exclude items from a list
*/
var Exclusions = Class.create();
Exclusions.prototype = {
	initialize: function(items) {
		this.items = items;
	},

	serialize: function() {
		var queryString = "";
		for (i = 0; i < this.items; i++) {
			if (i < (this.items.length - 1)) queryString += this.items[i] + Service.ID_SEPARATOR;
			else queryString += this.items[i];
		}
		return 'exclusions=' + queryString;
	}
};

