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
This commit is contained in:
parent
22eebc6cdf
commit
b2247e1dd2
4 changed files with 83 additions and 37 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue