Addresses #401, Add keyboard shortcuts

- New creators can now be added via the keyboard with Shift-Enter
- Fixed bug in data layer that caused modified creators to not be fully reloaded
- Fixed error in Zotero.Items.add() example (ISBN field is capitalized)
This commit is contained in:
Dan Stillman 2007-08-14 21:24:24 +00:00
parent 1f4425fa2f
commit 9c436a331f
2 changed files with 46 additions and 7 deletions

View File

@ -37,6 +37,8 @@ var ZoteroItemPane = new function()
var _itemBeingEdited; var _itemBeingEdited;
var _activeScrollbox; var _activeScrollbox;
var _addCreatorRow;
var _lastTabIndex; var _lastTabIndex;
var _tabDirection; var _tabDirection;
var _tabIndexMinCreators = 10; var _tabIndexMinCreators = 10;
@ -344,11 +346,16 @@ var ZoteroItemPane = new function()
var creator = _itemBeingEdited.getCreator(i); var creator = _itemBeingEdited.getCreator(i);
addCreatorRow(creator['firstName'], creator['lastName'], creator['creatorTypeID'], creator['fieldMode']); addCreatorRow(creator['firstName'], creator['lastName'], creator['creatorTypeID'], creator['fieldMode']);
} }
if (_addCreatorRow) {
addCreatorRow('', '', false, Zotero.Prefs.get('lastCreatorFieldMode'), true, true);
_addCreatorRow = false;
}
} }
else else
{ {
// Add default row // Add default row
addCreatorRow('', '', false, Zotero.Prefs.get('lastCreatorFieldMode'), true, true); addCreatorRow('', '', false, Zotero.Prefs.get('lastCreatorFieldMode'), true, false);
} }
var focusMode = 'info'; var focusMode = 'info';
@ -1160,14 +1167,14 @@ var ZoteroItemPane = new function()
switch (event.keyCode) switch (event.keyCode)
{ {
case event.DOM_VK_RETURN: case event.DOM_VK_RETURN:
var fieldname = target.getAttribute('fieldname');
// Use shift-enter as the save action for the larger fields // Use shift-enter as the save action for the larger fields
if ((target.getAttribute('fieldname') == 'abstractNote' if ((fieldname == 'abstractNote' || fieldname == 'extra')
|| target.getAttribute('fieldname') == 'extra')
&& !event.shiftKey) && !event.shiftKey)
{ {
break; break;
} }
else if (target.getAttribute('fieldname')=='tag') else if (fieldname == 'tag')
{ {
// If last tag row, create new one // If last tag row, create new one
var row = target.parentNode.parentNode; var row = target.parentNode.parentNode;
@ -1177,6 +1184,27 @@ var ZoteroItemPane = new function()
var lastTag = true; var lastTag = true;
} }
} }
// Shift-enter adds new creator row
else if (fieldname.indexOf('creator-') == 0 && event.shiftKey) {
// Value hasn't changed
if (target.getAttribute('value') == target.value) {
Zotero.debug("Value hasn't changed");
// If + button is disabled, just focus next creator row
if (Zotero.getAncestorByTagName(target, 'row').lastChild.lastChild.disabled) {
_focusNextField('info', _dynamicFields, _lastTabIndex, false);
}
else {
ZoteroItemPane.addCreatorRow('', '', false, Zotero.Prefs.get('lastCreatorFieldMode'), true, false);
}
}
// Value has changed
else {
_tabDirection = 1;
_addCreatorRow = true;
focused.blur();
}
return false;
}
focused.blur(); focused.blur();
// Return focus to items pane // Return focus to items pane

View File

@ -152,6 +152,12 @@ Zotero.Item.prototype.loadFromRow = function(row, reload) {
this.setType(row['itemTypeID'], true); this.setType(row['itemTypeID'], true);
} }
// This is a quick hack to reset the creators on reload --
// there's probably a better place for this
this._creatorsLoaded = false;
this._changedCreators = new Zotero.Hash();
this._creators = [];
for (var col in row){ for (var col in row){
// Only accept primary field data through loadFromRow() // Only accept primary field data through loadFromRow()
if (this.isPrimaryField(col)){ if (this.isPrimaryField(col)){
@ -436,10 +442,15 @@ Zotero.Item.prototype.removeCreator = function(orderIndex){
} }
this._creators[orderIndex] = false; this._creators[orderIndex] = false;
// Go to length+1 so we clear the last one // Shift creator orderIndexes down, going to length+1 so we clear the last one
for (var i=orderIndex, max=this._creators.length+1; i<max; i++){ for (var i=orderIndex, max=this._creators.length+1; i<max; i++){
var next = this._creators[i+1] ? this._creators[i+1] : false; var next = this._creators[i+1] ? this._creators[i+1] : false;
if (next) {
this._creators[i] = next; this._creators[i] = next;
}
else {
delete this._creators[i];
}
this._changedCreators.set(i); this._changedCreators.set(i);
} }
return true; return true;
@ -2512,7 +2523,7 @@ Zotero.Items = new function(){
* title: "Shakespeare: The Invention of the Human", * title: "Shakespeare: The Invention of the Human",
* publisher: "Riverhead Hardcover", * publisher: "Riverhead Hardcover",
* date: '1998-10-26', * date: '1998-10-26',
* isbn: 1573221201, * ISBN: 1573221201,
* pages: 745, * pages: 745,
* creators: [ * creators: [
* ['Harold', 'Bloom', 'author'] * ['Harold', 'Bloom', 'author']