SelectedItemsManager.prototype._count = 0; SelectedItemsManager.prototype._items = null; SelectedItemsManager.prototype._firstItemID = null; SelectedItemsManager.prototype._currentView = null; SelectedItemsManager.prototype._callback = null; function SelectedItemsManager() { this._count = 0; this._firstItemID = null; this._items = new Array(); // initialise our map of items } SelectedItemsManager.prototype.AddItem = function(ItemID, Value) { // adds the item to our map (if it doesn't already exist) if (getTopAppWindow) { this._currentView = getTopAppWindow().gCurrentView; } if (Value == undefined) { Value = ItemID; // no map value specified so we'll make it the same as the key. } if (!this.ItemExists(ItemID)) { if (this._count == 0) { this._firstItemID = ItemID; } this._items[ItemID] = Value; this._count++; return 1; } return 0; }; SelectedItemsManager.prototype.GetItem = function(ItemID) { if (this.ItemExists(ItemID)) return this._items[ItemID]; return null; }; SelectedItemsManager.prototype.GetItems = function() { // returns an associative array return this._items; }; SelectedItemsManager.prototype.GetItemsArray = function() { // returns an array of all the items in our map var items = new Array(); for (var id in this._items) { items.push(this._items[id]); } return items; }; SelectedItemsManager.prototype.RemoveItem = function(ItemID) { if (!this.ItemExists(ItemID)) { return; // bail } delete this._items[ItemID]; if (this._count > 0) this._count--; }; SelectedItemsManager.prototype.ItemExists = function(ItemID) { var item = this._items[ItemID]; if (!item || item == undefined) return false; return true; }; SelectedItemsManager.prototype.Clear = function() { this._items = new Array(); this._firstItemID = null; this._count = 0; }; SelectedItemsManager.prototype.GetSize = function() { return this._count; }; SelectedItemsManager.prototype.GetFirstSelectedItem = function() { if (!this.ItemExists(this._firstItemID)) { return ""; } return this._items[this._firstItemID]; }; SelectedItemsManager.prototype.GetView = function() { return this._currentView; }; SelectedItemsManager.prototype.GetNumSelectedItems = function() { return this._count; }; SelectedItemsManager.prototype.SetCallback = function(CallbackFn) { this._callback = CallbackFn; }; SelectedItemsManager.prototype.GetCallback = function() { return this._callback; }; SelectedItemsManager.prototype.ExecuteCallback = function() { if (this._callback != null) this._callback(); }; SelectedItemsManager.prototype.CallbackExists = function() { if (this._callback != null) return true; return false; }; //SelectedItemsManager.prototype._iterator = null; //SelectedItemsManager.prototype.GetFirstNItems = function(MaxItems) { // // this function returns a string of the first N items in our map // // and stores the position of the iterator for the next batch // // request. // // note: the Iterator object is NOT supported in IE // var it = Iterator(this._items, true); // true; just iterate over the keys // return this.GetIteratorItems(it, MaxItems); //}; //SelectedItemsManager.prototype.GetNextNItems = function(MaxItems) { // return this.GetIteratorItems(this._iterator, MaxItems); //}; //SelectedItemsManager.prototype.GetIteratorItems = function(MyIterator, MaxItems) { // var it = MyIterator; // var items = ""; // var count = 0; // if (!it) // return ""; // for (var key in it) { // if (count > 0) // items += ","; // items += key; // count++; // if (count == MaxItems) { // // store our iterator // this._iterator = it; // break; // } // } //};