www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 406d1d695039041a58fbf0dcb683ce06267657f7
parent 77f8a4ad30728880f4a8742095d404ed37bb0bf1
Author: Simon Kornblith <simon@simonster.com>
Date:   Wed, 30 Aug 2006 00:43:09 +0000

references #232, library UI does not refresh after saving new item

now that the notifier issue is fixed, i'm switching this bug to deal with the University of Michigan issue


Diffstat:
Mchrome/chromeFiles/content/scholar/xpcom/translate.js | 269+++++++++++++++++++++++++++++++++++++++++--------------------------------------
1 file changed, 138 insertions(+), 131 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/xpcom/translate.js b/chrome/chromeFiles/content/scholar/xpcom/translate.js @@ -1003,161 +1003,168 @@ Scholar.Translate.prototype._itemDone = function(item) { Scholar.Notifier.disable(); } - // Get typeID, defaulting to "website" - var type = (item.itemType ? item.itemType : "website"); - - if(type == "note") { // handle notes differently - var myID = Scholar.Notes.add(item.note); - // re-retrieve the item - var newItem = Scholar.Items.get(myID); - } else if(type == "attachment") { - if(this.type == "import") { - var newItem = this._itemImportAttachment(item, null); - var myID = newItem.getID(); - } else { - Scholar.debug("discarding standalone attachment"); - return false; - } - } else { - if(!item.title) { - throw("item has no title"); - } - - // create new item - var typeID = Scholar.ItemTypes.getID(type); - var newItem = Scholar.Items.getNewItemByType(typeID); - - // makes looping through easier - item.itemType = item.complete = undefined; + try { // make sure notifier gets turned back on when done + // Get typeID, defaulting to "website" + var type = (item.itemType ? item.itemType : "website"); - var fieldID, field; - for(var i in item) { - // loop through item fields - data = item[i]; + if(type == "note") { // handle notes differently + var myID = Scholar.Notes.add(item.note); + // re-retrieve the item + var newItem = Scholar.Items.get(myID); + } else if(type == "attachment") { + if(this.type == "import") { + var newItem = this._itemImportAttachment(item, null); + var myID = newItem.getID(); + } else { + Scholar.debug("discarding standalone attachment"); + return false; + } + } else { + if(!item.title) { + throw("item has no title"); + } + + // create new item + var typeID = Scholar.ItemTypes.getID(type); + var newItem = Scholar.Items.getNewItemByType(typeID); - if(data) { // if field has content - if(i == "creators") { // creators are a special case - for(var j in data) { - var creatorType = 1; - // try to assign correct creator type - if(data[j].creatorType) { - try { - var creatorType = Scholar.CreatorTypes.getID(data[j].creatorType); - } catch(e) { - Scholar.debug("invalid creator type "+data[j].creatorType+" for creator index "+j); + // makes looping through easier + item.itemType = item.complete = undefined; + + var fieldID, field; + for(var i in item) { + // loop through item fields + data = item[i]; + + if(data) { // if field has content + if(i == "creators") { // creators are a special case + for(var j in data) { + var creatorType = 1; + // try to assign correct creator type + if(data[j].creatorType) { + try { + var creatorType = Scholar.CreatorTypes.getID(data[j].creatorType); + } catch(e) { + Scholar.debug("invalid creator type "+data[j].creatorType+" for creator index "+j); + } } + + newItem.setCreator(j, data[j].firstName, data[j].lastName, creatorType); } - - newItem.setCreator(j, data[j].firstName, data[j].lastName, creatorType); - } - } else if(i == "title") { // skip checks for title - newItem.setField(i, data); - } else if(i == "seeAlso") { - newItem.translateSeeAlso = data; - } else if(i != "note" && i != "notes" && i != "itemID" && - i != "attachments" && i != "tags" && - (fieldID = Scholar.ItemFields.getID(i))) { - // if field is in db - if(Scholar.ItemFields.isValidForType(fieldID, typeID)) { - // if field is valid for this type - // add field + } else if(i == "title") { // skip checks for title newItem.setField(i, data); + } else if(i == "seeAlso") { + newItem.translateSeeAlso = data; + } else if(i != "note" && i != "notes" && i != "itemID" && + i != "attachments" && i != "tags" && + (fieldID = Scholar.ItemFields.getID(i))) { + // if field is in db + if(Scholar.ItemFields.isValidForType(fieldID, typeID)) { + // if field is valid for this type + // add field + newItem.setField(i, data); + } else { + Scholar.debug("discarded field "+i+" for item: field not valid for type "+type); + } } else { - Scholar.debug("discarded field "+i+" for item: field not valid for type "+type); + Scholar.debug("discarded field "+i+" for item: field does not exist"); } - } else { - Scholar.debug("discarded field "+i+" for item: field does not exist"); } } - } - - // save item - var myID = newItem.save(); - if(myID == true) { - myID = newItem.getID(); - } - - // handle notes - if(item.notes) { - for each(var note in item.notes) { - var noteID = Scholar.Notes.add(note.note, myID); - - // handle see also - var myNote = Scholar.Items.get(noteID); - this._itemTagsAndSeeAlso(note, myNote); + + // save item + var myID = newItem.save(); + if(myID == true) { + myID = newItem.getID(); } - } - - // handle attachments - if(item.attachments) { - for each(var attachment in item.attachments) { - if(this.type == "web") { - if(!attachment.url && !attachment.document) { - Scholar.debug("not adding attachment: no URL specified"); - } + + // handle notes + if(item.notes) { + for each(var note in item.notes) { + var noteID = Scholar.Notes.add(note.note, myID); - if(attachment.downloadable && this._downloadAssociatedFiles) { - if(attachment.document) { - attachmentID = Scholar.Attachments.importFromDocument(attachment.document, myID); - - // change title, if a different one was specified - if(attachment.title && (!attachment.document.title - || attachment.title != attachment.document.title)) { - var attachmentItem = Scholar.Items.get(attachmentID); - attachmentItem.setField("title", attachment.title); - } - } else { - Scholar.Attachments.importFromURL(attachment.url, myID, - (attachment.mimeType ? attachment.mimeType : attachment.document.contentType), - (attachment.title ? attachment.title : attachment.document.title)); + // handle see also + var myNote = Scholar.Items.get(noteID); + this._itemTagsAndSeeAlso(note, myNote); + } + } + + // handle attachments + if(item.attachments) { + for each(var attachment in item.attachments) { + if(this.type == "web") { + if(!attachment.url && !attachment.document) { + Scholar.debug("not adding attachment: no URL specified"); } - } else { - if(attachment.document) { - attachmentID = Scholar.Attachments.linkFromURL(attachment.document.location.href, myID, - (attachment.mimeType ? attachment.mimeType : attachment.document.contentType), - (attachment.title ? attachment.title : attachment.document.title)); + + if(attachment.downloadable && this._downloadAssociatedFiles) { + if(attachment.document) { + attachmentID = Scholar.Attachments.importFromDocument(attachment.document, myID); + + // change title, if a different one was specified + if(attachment.title && (!attachment.document.title + || attachment.title != attachment.document.title)) { + var attachmentItem = Scholar.Items.get(attachmentID); + attachmentItem.setField("title", attachment.title); + } + } else { + Scholar.Attachments.importFromURL(attachment.url, myID, + (attachment.mimeType ? attachment.mimeType : attachment.document.contentType), + (attachment.title ? attachment.title : attachment.document.title)); + } } else { - if(!attachment.mimeType || attachment.title) { - Scholar.debug("notice: either mimeType or title is missing; attaching file will be slower"); + if(attachment.document) { + attachmentID = Scholar.Attachments.linkFromURL(attachment.document.location.href, myID, + (attachment.mimeType ? attachment.mimeType : attachment.document.contentType), + (attachment.title ? attachment.title : attachment.document.title)); + } else { + if(!attachment.mimeType || attachment.title) { + Scholar.debug("notice: either mimeType or title is missing; attaching file will be slower"); + } + + attachmentID = Scholar.Attachments.linkFromURL(attachment.url, myID, + (attachment.mimeType ? attachment.mimeType : undefined), + (attachment.title ? attachment.title : undefined)); } - - attachmentID = Scholar.Attachments.linkFromURL(attachment.url, myID, - (attachment.mimeType ? attachment.mimeType : undefined), - (attachment.title ? attachment.title : undefined)); } - } - } else if(this.type == "import") { - var attachmentItem = this._itemImportAttachment(attachment, myID); - if(attachmentItem) { - this._itemTagsAndSeeAlso(attachment, attachmentItem); + } else if(this.type == "import") { + var attachmentItem = this._itemImportAttachment(attachment, myID); + if(attachmentItem) { + this._itemTagsAndSeeAlso(attachment, attachmentItem); + } } } } } - } - - if(item.itemID) { - this._IDMap[item.itemID] = myID; - } - this.newItems.push(myID); - - // handle see also - if(item.seeAlso) { - for each(var seeAlso in item.seeAlso) { - if(this._IDMap[seeAlso]) { - newItem.addSeeAlso(this._IDMap[seeAlso]); + + if(item.itemID) { + this._IDMap[item.itemID] = myID; + } + this.newItems.push(myID); + + // handle see also + if(item.seeAlso) { + for each(var seeAlso in item.seeAlso) { + if(this._IDMap[seeAlso]) { + newItem.addSeeAlso(this._IDMap[seeAlso]); + } } } - } - - if(item.tags) { - for each(var tag in item.tags) { - newItem.addTag(tag); + + if(item.tags) { + for each(var tag in item.tags) { + newItem.addTag(tag); + } } + + delete item; + } catch(e) { + if(notifierStatus) { + Scholar.Notifier.enable(); + } + throw(e); } - delete item; - // only re-enable if notifier was enabled at the beginning of scraping if(notifierStatus) { Scholar.Notifier.enable();