Allow delimited entry of multiple authors or tags
This commit is contained in:
parent
e57658c5e2
commit
9285b0cfb1
3 changed files with 110 additions and 6 deletions
|
@ -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,79 @@
|
|||
|
||||
var otherFields = this.getCreatorFields(row);
|
||||
otherFields[creatorField] = value;
|
||||
var lastName = otherFields.lastName;
|
||||
|
||||
this.modifyCreator(creatorIndex, otherFields);
|
||||
|
||||
//Handle \n\r delimited entries
|
||||
if (lastName.search('\r') > -1 || lastName.search('\n') > -1) {
|
||||
lastName = lastName.replace('\r\n','\n');
|
||||
lastName = lastName.replace('\r','\n');
|
||||
var rawNameArray = lastName.split('\n');
|
||||
|
||||
//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 = new Array();
|
||||
var counter = 0;
|
||||
var tempName = '';
|
||||
for each(tempName in rawNameArray) {
|
||||
if (tempName.length > 0) {
|
||||
//Put further error checking of tempName here
|
||||
nameArray[counter] = tempName;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
//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<nameArray.length;i++) {
|
||||
this.modifyCreator(i+initNumCreators,otherFields);
|
||||
}
|
||||
|
||||
//Shift existing creators
|
||||
for (var i=initNumCreators-1; 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
|
||||
var tempFields=otherFields;
|
||||
for each(tempName in nameArray) {
|
||||
// Check for comma to determine creator name format
|
||||
tempFields.fieldMode = (tempName.indexOf('\t') == -1) ? 1 : 0;
|
||||
if (tempFields.fieldMode == 0) {
|
||||
tempFields.lastName=tempName.split('\t')[0];
|
||||
tempFields.firstName=tempName.split('\t')[1];
|
||||
}
|
||||
else {
|
||||
tempFields.lastName=tempName;
|
||||
}
|
||||
this.modifyCreator(creatorIndex,tempFields);
|
||||
creatorIndex++;
|
||||
}
|
||||
this._tabDirection = tabDirectionBuffer;
|
||||
this._addCreatorRow = (creatorsToShift==0) ? addCreatorRowBuffer : false;
|
||||
if (this._tabDirection == 1) {
|
||||
this._lastTabIndex = parseInt(tabIndexBuffer,10) + 2*(nameArray.length-1);
|
||||
if (tempFields.fieldMode == 0) {
|
||||
this._lastTabIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.modifyCreator(creatorIndex, otherFields);
|
||||
}
|
||||
|
||||
var val = this.item.getCreator(creatorIndex);
|
||||
val = val ? val.ref[creatorField] : null;
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
@ -481,8 +482,19 @@
|
|||
var focusMode = 'tags';
|
||||
var focusBox = tagsbox;
|
||||
|
||||
//Move at least one field even if no entry was added because of
|
||||
//the way bookkeeping is done above
|
||||
var fieldsToMove = 1;
|
||||
//Check if id is an array and, if so, how many new entries
|
||||
//were added at once
|
||||
if (Object.prototype.toString.call(id) === '[object Array]') {
|
||||
fieldsToMove = id.length;
|
||||
}
|
||||
|
||||
if (this._tabDirection) {
|
||||
this._focusNextField(focusBox, this._lastTabIndex, this._tabDirection == -1);
|
||||
for (var i = 0; i < fieldsToMove; i++) {
|
||||
this._focusNextField(focusBox, this._lastTabIndex, this._tabDirection == -1);
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</body>
|
||||
|
|
|
@ -1593,7 +1593,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));
|
||||
|
@ -3478,6 +3478,16 @@ Zotero.Item.prototype.addTag = function(name, type) {
|
|||
if (!this.id) {
|
||||
throw ('Cannot add tag to unsaved item in Item.addTag()');
|
||||
}
|
||||
|
||||
//Check for newlines or carriage returns used as delimiters
|
||||
//in a series of tags added at once. Add each tag
|
||||
//separately.
|
||||
if (name.search('\r') > -1 || name.search('\n') > -1) {
|
||||
name = name.replace('\r\n','\n');
|
||||
name = name.replace('\r','\n');
|
||||
var nameArray = name.split('\n');
|
||||
return this.addTags(nameArray,type);
|
||||
}
|
||||
|
||||
name = Zotero.Utilities.trim(name);
|
||||
|
||||
|
@ -3541,10 +3551,21 @@ 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 counter = 0;
|
||||
var tempID = false;
|
||||
for (var i = 0; i < tags.length; i++) {
|
||||
tempID = this.addTag(tags[i], type);
|
||||
if (tempID) {
|
||||
tagIDarray[counter] = tempID;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
tagIDarray = (tagIDarray.length>0) ? tagIDarray : false;
|
||||
|
||||
Zotero.DB.commitTransaction();
|
||||
return tagIDarray;
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.DB.rollbackTransaction();
|
||||
|
|
Loading…
Reference in a new issue