diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml index d976e33ca9..b892670d21 100644 --- a/chrome/content/zotero/bindings/itembox.xml +++ b/chrome/content/zotero/bindings/itembox.xml @@ -1421,6 +1421,7 @@ if (creatorField=='lastName') { t.setAttribute('fieldMode', elem.getAttribute('fieldMode')); + t.setAttribute('newlines','pasteintact'); } if (Zotero.ItemFields.isMultiline(fieldName) || Zotero.ItemFields.isLong(fieldName)) { @@ -1695,9 +1696,67 @@ var otherFields = this.getCreatorFields(row); otherFields[creatorField] = value; + var lastName = otherFields.lastName; - this.modifyCreator(creatorIndex, otherFields); - + //Handle \n\r and \n delimited entries + var rawNameArray = lastName.split(/\r\n?|\n/); + if (rawNameArray.length > 1) { + //Save tab direction and add creator flags since they are reset in the + //process of adding multiple authors + var tabDirectionBuffer = this._tabDirection; + var addCreatorRowBuffer = this._addCreatorRow; + var tabIndexBuffer = this._lastTabIndex; + this._tabDirection = false; + this._addCreatorRow = false; + + //Filter out bad names + var nameArray = [tempName for each(tempName in rawNameArray) if(tempName)]; + + //If not adding names at the end of the creator list, make new creator + //entries and then shift down existing creators. + var initNumCreators = this.item.numCreators(); + var creatorsToShift = initNumCreators - creatorIndex; + if (creatorsToShift > 0) { + //Add extra creators + for (var i=0;i=creatorIndex; i--) { + var shiftedCreator = this.item.getCreator(i); + this.item.setCreator(nameArray.length+i,shiftedCreator.ref,shiftedCreator.creatorTypeID); + } + } + + //Add the creators in lastNameArray one at a time + for each(tempName in nameArray) { + // Check for tab to determine creator name format + otherFields.fieldMode = (tempName.indexOf('\t') == -1) ? 1 : 0; + if (otherFields.fieldMode == 0) { + otherFields.lastName=tempName.split('\t')[0]; + otherFields.firstName=tempName.split('\t')[1]; + } + else { + otherFields.lastName=tempName; + otherFields.firstName=''; + } + this.modifyCreator(creatorIndex,otherFields); + creatorIndex++; + } + this._tabDirection = tabDirectionBuffer; + this._addCreatorRow = (creatorsToShift==0) ? addCreatorRowBuffer : false; + if (this._tabDirection == 1) { + this._lastTabIndex = parseInt(tabIndexBuffer,10) + 2*(nameArray.length-1); + if (otherFields.fieldMode == 0) { + this._lastTabIndex++; + } + } + } + else { + this.modifyCreator(creatorIndex, otherFields); + } + var val = this.item.getCreator(creatorIndex); val = val ? val.ref[creatorField] : null; diff --git a/chrome/content/zotero/bindings/tagsbox.xml b/chrome/content/zotero/bindings/tagsbox.xml index a859616cbd..50ef77e363 100644 --- a/chrome/content/zotero/bindings/tagsbox.xml +++ b/chrome/content/zotero/bindings/tagsbox.xml @@ -293,6 +293,7 @@ t.setAttribute('fieldname', fieldName); t.setAttribute('ztabindex', tabindex); t.setAttribute('flex', '1'); + t.setAttribute('newlines','pasteintact'); // Add auto-complete t.setAttribute('type', 'autocomplete'); @@ -410,12 +411,9 @@ var fieldName = 'tag'; var tabindex = textbox.getAttribute('ztabindex'); - - //var value = t.value; + var value = textbox.value; - var elem; - var tagsbox = Zotero.getAncestorByTagName(textbox, 'tagsbox'); if (!tagsbox) { @@ -429,38 +427,78 @@ // Tag id encoded as 'tag-1234' var id = row.getAttribute('id').split('-')[1]; + var tagArray = value.split(/\r\n?|\n/); + if (saveChanges) { - if (id) { + if (id && (tagArray.length < 2)) { if (value) { - // If trying to replace with another existing tag - // (which causes a delete of the row), - // clear the tab direction so we don't advance - // when the notifier kicks in - var existing = Zotero.Tags.getID(value, 0); - if (existing && id != existing) { - this._tabDirection = false; - } + var origTagIndex = this.item.getTagIndex(id); var changed = tagsbox.replace(id, value); if (changed) { - return; + var newTagIndex = this.item.getTagIndex(changed); + if (newTagIndex>origTagIndex) { + if (this._tabDirection == 1) { + this._lastTabIndex--; + } + } + else if (newTagIndex 1) { + var extremeTag = false; + var nextTag = false; + if (this._tabDirection == -1) { + if (this._lastTabIndex == 1) { + extremeTag = true; + } else { + nextTag = row.previousSibling.getAttribute('id').split('-')[1]; + } + } else if (this._tabDirection == 1) { + if (this._lastTabIndex >= this.item.getTags().length) { + extremeTag = true; + } else { + nextTag = row.nextSibling.getAttribute('id').split('-')[1]; + } + } + + id = this.item.addTags(tagArray); + + if (extremeTag) { + if (this._tabDirection == 1) { + this._lastTabIndex = this.item.getTags().length; + } else if (this._tabDirection == -1) { + this._lastTabIndex = 2; + } + } else { + this._lastTabIndex = this.item.getTagIndex(nextTag)+1-this._tabDirection; + } + } + else { + id = tagsbox.add(value); + } + if (!id && (this._tabDirection==1)) { this._lastTabIndex--; } } } if (id) { - elem = this.createValueElement( + var elem = this.createValueElement( value, tabindex ); @@ -478,7 +516,6 @@ catch (e) {} } - var focusMode = 'tags'; var focusBox = tagsbox; if (this._tabDirection) { diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index b60b1136ad..0bbe2a403d 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -1605,7 +1605,7 @@ Zotero.Item.prototype.save = function() { 'libraryID', 'key' ]; - for each(field in updateFields) { + for each(var field in updateFields) { if (this._changedPrimaryData && this._changedPrimaryData[field]) { sql += field + '=?, '; sqlValues.push(this.getField(field)); @@ -3553,10 +3553,19 @@ Zotero.Item.prototype.addTag = function(name, type) { Zotero.Item.prototype.addTags = function (tags, type) { Zotero.DB.beginTransaction(); try { - for each(var tag in tags) { - this.addTag(tag, type); + var tagIDArray = []; + var tempID = false; + for (var i = 0; i < tags.length; i++) { + tempID = this.addTag(tags[i], type); + if (tempID) { + tagIDArray.push(tempID); + } } + + tagIDArray = (tagIDArray.length>0) ? tagIDArray : false; + Zotero.DB.commitTransaction(); + return tagIDArray; } catch (e) { Zotero.DB.rollbackTransaction(); @@ -3638,6 +3647,21 @@ Zotero.Item.prototype.getTagIDs = function() { return Zotero.DB.columnQuery(sql, this.id); } +/** +* Return the index of tagID in the list of the item's tags sorted in alphabetical order. +*/ +Zotero.Item.prototype.getTagIndex = function(tagID) { + var tags = this.getTags(); + + for (var i=0;i