zotero/chrome/content/zotero/advancedSearch.js
Dan Stillman 91459f95f7 2.0b3 megacommit
- Support for group libraries
- General support for multiple libraries of different types
- Streamlined sync support
  - Using solely libraryID and key rather than itemID, and removed all itemID-changing code
  - Combined two requests for increased performance and decreased server load
  - Added warning on user account change
  - Provide explicit error message on SSL failure
- Removed snapshot and link toolbar buttons and changed browser context menu options and drags to create parent items + snapshots
- Closes #786, Add numPages field
- Fixes #1063, Duplicate item with tags broken in Sync Preview
- Added better purging of deleted tags
- Added local user key before first sync
- Add clientDateModified to all objects for more flexibility in syncing
- Added new triples-based Relation object type, currently used to store links between items copied between local and group libraries
- Updated zotero.org translator for groups
- Additional trigger-based consistency checks
- Fixed broken URL drag in Firefox 3.5
- Disabled zeroconf menu option (no longer functional)

Developer-specific changes:

- Overhauled data layer
  - Data object constructors no longer take arguments (return to 1.0-like API)
  - Existing objects can be retrieved by setting id or library/key properties
  - id/library/key must be set for new objects before other fields
- New methods:
  - ZoteroPane.getSelectedLibraryID()
  - ZoteroPane.getSelectedGroup(asID)
  - ZoteroPane.addItemFromDocument(doc, itemType, saveSnapshot)
  - ZoteroPane.addItemFromURL(url, itemType)
  - ZoteroPane.canEdit()
  - Zotero.CollectionTreeView.selectLibrary(libraryID)
  - New Zotero.URI methods
- Changed methods
  - Many data object methods now take a libraryID
  - ZoteroPane.addAttachmentFromPage(link, itemID)
- Removed saveItem and saveAttachments parameters from Zotero.Translate constructor
- translate() now takes a libraryID, null for local library, or false to not save items (previously on constructor)
- saveAttachments is now a translate() parameter
- Zotero.flattenArguments() better handles passed objects
- Zotero.File.getFileHash() (not currently used)
2009-05-14 18:23:40 +00:00

151 lines
3.8 KiB
JavaScript

var ZoteroAdvancedSearch = new function() {
this.onLoad = onLoad;
this.search = search;
this.clear = clear;
this.save = save;
this.onDblClick = onDblClick;
this.onUnload = onUnload;
this.itemsView = false;
var _searchBox;
function onLoad() {
_searchBox = document.getElementById('zotero-search-box');
// Set font size from pref
var sbc = document.getElementById('zotero-search-box-container');
Zotero.setFontSize(sbc);
var io = window.arguments[0];
_searchBox.search = io.dataIn.search;
}
function search() {
_searchBox.updateSearch();
// A minimal implementation of Zotero.CollectionTreeView
var itemGroup = {
isSearchMode: function() { return true; },
getChildItems: function () {
var search = _searchBox.search.clone();
// FIXME: Hack to exclude group libraries for now
var groups = Zotero.Groups.getAll();
for each(var group in groups) {
search.addCondition('libraryID', 'isNot', group.libraryID);
}
//var search = _searchBox.search;
var ids = search.search();
return Zotero.Items.get(ids);
},
isLibrary: function () { return false; },
isCollection: function () { return false; },
isSearch: function () { return true; },
isShare: function () { return true; },
isTrash: function () { return false; }
}
if (this.itemsView) {
this.itemsView.unregister();
}
this.itemsView = new Zotero.ItemTreeView(itemGroup, false);
document.getElementById('zotero-items-tree').view = this.itemsView;
}
function clear() {
if (this.itemsView) {
this.itemsView.unregister();
}
document.getElementById('zotero-items-tree').view = null;
var s = new Zotero.Search();
s.addCondition('title', 'contains', '');
_searchBox.search = s;
}
function save() {
_searchBox.updateSearch();
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var untitled = Zotero.DB.getNextName('collections', 'collectionName',
Zotero.getString('pane.collections.untitled'));
var name = { value: untitled };
var result = promptService.prompt(window,
Zotero.getString('pane.collections.newSavedSeach'),
Zotero.getString('pane.collections.savedSearchName'), name, "", {});
if (!result)
{
return;
}
if (!name.value)
{
newName.value = untitled;
}
var s = _searchBox.search.clone();
s.setName(name.value);
s.save();
}
// Adapted from: http://www.xulplanet.com/references/elemref/ref_tree.html#cmnote-9
function onDblClick(event, tree)
{
if (event && tree && event.type == "dblclick")
{
var row = {}, col = {}, obj = {};
tree.treeBoxObject.getCellAt(event.clientX, event.clientY, row, col, obj);
// obj.value == cell/text/image
// TODO: handle collection double-click
if (obj.value && this.itemsView && this.itemsView.selection.currentIndex > -1)
{
var item = this.itemsView.getSelectedItems()[0];
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var lastWin = wm.getMostRecentWindow("navigator:browser");
if (!lastWin) {
window.open();
var newWindow = wm.getMostRecentWindow("navigator:browser");
var b = newWindow.getBrowser();
return;
}
if (lastWin.document.getElementById('zotero-pane').getAttribute('hidden') == 'true') {
lastWin.ZoteroPane.toggleDisplay();
}
lastWin.ZoteroPane.selectItem(item.getID(), false, true);
lastWin.focus();
}
}
}
this.startDrag = function (event, element) {
if (Zotero.isFx2 || Zotero.isFx30) {
nsDragAndDrop.startDrag(event, element);
return;
}
element.onDragStart(event);
}
function onUnload() {
// Unregister search from Notifier
if (this.itemsView) {
this.itemsView.unregister();
}
}
}