commit b2247e1dd27812b393c380f4dacac6836555b3e9
parent 22eebc6cdfb5f8fb837f65c4980397279c05e9d8
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 25 Jun 2006 04:35:11 +0000
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
Diffstat:
4 files changed, 77 insertions(+), 31 deletions(-)
diff --git 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<creators; i++) {
var creator = item1.getCreator(i);
- var label = Scholar.getString("creatorTypes."+Scholar.CreatorTypes.getTypeName(creator.creatorTypeID)) + ":";
+ var label = Scholar.getString("creatorTypes."+Scholar.CreatorTypes.getName(creator.creatorTypeID)) + ":";
var data = creator.firstName + ' ' + creator.lastName;
Scholar_Ingester_Interface.scrapeProgress.addResult(label, data);
}
diff --git a/chrome/chromeFiles/content/scholar/itemPane.js b/chrome/chromeFiles/content/scholar/itemPane.js
@@ -155,7 +155,7 @@ ScholarItemPane = new function()
if(!lastName)
lastName = "(last)";
var label = document.createElement("label");
- label.setAttribute("value",Scholar.getString('creatorTypes.'+Scholar.CreatorTypes.getTypeName(typeID))+":");
+ label.setAttribute("value",Scholar.getString('creatorTypes.'+Scholar.CreatorTypes.getName(typeID))+":");
label.setAttribute("popup","creatorTypeMenu");
label.setAttribute("fieldname",'creator-'+_creatorCount+'-typeID');
label.className = 'clicky';
diff --git a/chrome/chromeFiles/content/scholar/itemTreeView.js b/chrome/chromeFiles/content/scholar/itemTreeView.js
@@ -181,7 +181,7 @@ Scholar.ItemTreeView.prototype.getImageSrc = function(row, col)
{
if(col.id == 'typeIcon')
{
- var itemType = Scholar.ItemTypes.getTypeName(this._getItemAtRow(row).getType());
+ var itemType = Scholar.ItemTypes.getName(this._getItemAtRow(row).getType());
return "chrome://scholar/skin/treeitem-"+itemType+".png";
}
}
@@ -232,8 +232,8 @@ Scholar.ItemTreeView.prototype.sort = function()
{
function columnSort(a,b)
{
- var typeA = Scholar.getString('itemTypes.'+Scholar.ItemTypes.getTypeName(a.getType()));
- var typeB = Scholar.getString('itemTypes.'+Scholar.ItemTypes.getTypeName(b.getType()));
+ var typeA = Scholar.getString('itemTypes.'+Scholar.ItemTypes.getName(a.getType()));
+ var typeB = Scholar.getString('itemTypes.'+Scholar.ItemTypes.getName(b.getType()));
return (typeA > 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
@@ -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 getTypes(){
- return Scholar.DB.query('SELECT creatorTypeID AS id, '
- + 'creatorType AS name FROM creatorTypes order BY creatorType');
+
+ function getName(idOrName){
+ if (!_typesLoaded){
+ _load();
+ }
+
+ if (!_types[idOrName]){
+ Scholar.debug('Invalid creator type ' + idOrName, 1);
+ }
+
+ return _types[idOrName]['name'];
}
- function getTypeName(creatorTypeID){
- if (!_creatorTypesLoaded){
+
+ function getID(idOrName){
+ if (!_typesLoaded){
_load();
}
- if (!_creatorTypes[creatorTypeID]){
- Scholar.debug('Invalid creator type ' + creatorTypeID, 1);
+ if (!_types[idOrName]){
+ Scholar.debug('Invalid creator type ' + idOrName, 1);
}
- return _creatorTypes[creatorTypeID];
+ return _types[idOrName]['id'];
+ }
+
+
+ function getTypes(){
+ return Scholar.DB.query('SELECT creatorTypeID AS id, '
+ + 'creatorType AS name FROM creatorTypes order BY creatorType');
}
+
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 getTypes(){
- return Scholar.DB.query('SELECT itemTypeID AS id, typeName AS name '
- + 'FROM itemTypes order BY typeName');
+
+ function getName(idOrName){
+ if (!_typesLoaded){
+ _load();
+ }
+
+ if (!_types[idOrName]){
+ Scholar.debug('Invalid item type ' + idOrName, 1);
+ }
+
+ return _types[idOrName]['name'];
}
- function getTypeName(itemTypeID){
- if (!_itemTypesLoaded){
+
+ function getID(idOrName){
+ if (!_typesLoaded){
_load();
}
- if (!_itemTypes[itemTypeID]){
- Scholar.debug('Invalid item type ' + itemTypeID, 1);
+ if (!_types[idOrName]){
+ Scholar.debug('Invalid item type ' + idOrName, 1);
}
- return _itemTypes[itemTypeID];
+ return _types[idOrName]['id'];
+ }
+
+
+ function getTypes(){
+ return Scholar.DB.query('SELECT itemTypeID AS id, typeName AS name '
+ + 'FROM itemTypes order BY typeName');
}
+
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;
}
}