From b2247e1dd27812b393c380f4dacac6836555b3e9 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 25 Jun 2006 04:35:11 +0000 Subject: [PATCH] Fixes #66, Need a function to get typeID given typeName - Added methods getID(idOrName) and getName(idOrName) to Scholar.CreatorTypes and Scholar.ItemTypes to take either typeID or typeName - Removed getTypeName() in each and changed references accordingly - Streamlined both classes to be as similar as possible --- .../content/scholar/ingester/browser.js | 2 +- .../chromeFiles/content/scholar/itemPane.js | 2 +- .../content/scholar/itemTreeView.js | 6 +- .../content/scholar/xpcom/data_access.js | 110 +++++++++++++----- 4 files changed, 83 insertions(+), 37 deletions(-) diff --git a/chrome/chromeFiles/content/scholar/ingester/browser.js b/chrome/chromeFiles/content/scholar/ingester/browser.js index 7a4c3d496f..647d0ef5ab 100644 --- a/chrome/chromeFiles/content/scholar/ingester/browser.js +++ b/chrome/chromeFiles/content/scholar/ingester/browser.js @@ -236,7 +236,7 @@ Scholar_Ingester_Interface._finishScraping = function(obj, returnValue) { if(creators) { for(var i=0; i typeB) ? -1 : (typeA < typeB) ? 1 : 0; } diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js index 25f5e66945..0a770f89f9 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/data_access.js +++ b/chrome/chromeFiles/content/scholar/xpcom/data_access.js @@ -1777,38 +1777,61 @@ Scholar.Creators = new function(){ Scholar.CreatorTypes = new function(){ - var _creatorTypes = new Array(); - var _creatorTypesLoaded; + var _types = new Array(); + var _typesLoaded; var self = this; + this.getName = getName; + this.getID = getID; this.getTypes = getTypes; - this.getTypeName = getTypeName; + + + function getName(idOrName){ + if (!_typesLoaded){ + _load(); + } + + if (!_types[idOrName]){ + Scholar.debug('Invalid creator type ' + idOrName, 1); + } + + return _types[idOrName]['name']; + } + + + function getID(idOrName){ + if (!_typesLoaded){ + _load(); + } + + if (!_types[idOrName]){ + Scholar.debug('Invalid creator type ' + idOrName, 1); + } + + return _types[idOrName]['id']; + } + function getTypes(){ return Scholar.DB.query('SELECT creatorTypeID AS id, ' + 'creatorType AS name FROM creatorTypes order BY creatorType'); } - function getTypeName(creatorTypeID){ - if (!_creatorTypesLoaded){ - _load(); - } - - if (!_creatorTypes[creatorTypeID]){ - Scholar.debug('Invalid creator type ' + creatorTypeID, 1); - } - - return _creatorTypes[creatorTypeID]; - } function _load(){ var types = self.getTypes(); for (i in types){ - _creatorTypes[types[i]['id']] = types[i]['name']; + // Store as both id and name for access by either + var typeData = { + id: types[i]['id'], + name: types[i]['name'] + } + _types[types[i]['id']] = typeData; + _types[types[i]['name']] = _types[types[i]['id']]; } - _creatorTypesLoaded = true; + _typesLoaded = true; } } @@ -1816,38 +1839,61 @@ Scholar.CreatorTypes = new function(){ Scholar.ItemTypes = new function(){ - var _itemTypes = new Array(); - var _itemTypesLoaded; + var _types = new Array(); + var _typesLoaded; var self = this; + this.getName = getName; + this.getID = getID; this.getTypes = getTypes; - this.getTypeName = getTypeName; + + + function getName(idOrName){ + if (!_typesLoaded){ + _load(); + } + + if (!_types[idOrName]){ + Scholar.debug('Invalid item type ' + idOrName, 1); + } + + return _types[idOrName]['name']; + } + + + function getID(idOrName){ + if (!_typesLoaded){ + _load(); + } + + if (!_types[idOrName]){ + Scholar.debug('Invalid item type ' + idOrName, 1); + } + + return _types[idOrName]['id']; + } + function getTypes(){ return Scholar.DB.query('SELECT itemTypeID AS id, typeName AS name ' + 'FROM itemTypes order BY typeName'); } - function getTypeName(itemTypeID){ - if (!_itemTypesLoaded){ - _load(); - } - - if (!_itemTypes[itemTypeID]){ - Scholar.debug('Invalid item type ' + itemTypeID, 1); - } - - return _itemTypes[itemTypeID]; - } function _load(){ var types = self.getTypes(); for (i in types){ - _itemTypes[types[i]['id']] = types[i]['name']; + // Store as both id and name for access by either + var typeData = { + id: types[i]['id'], + name: types[i]['name'] + } + _types[types[i]['id']] = typeData; + _types[types[i]['name']] = _types[types[i]['id']]; } - _itemTypesLoaded = true; + _typesLoaded = true; } }