commit 53d798c345abb24d7b89602679db5e3b52ea5b86
parent e0f1ef76461f394707552342fc950b16874e20d4
Author: Dan Stillman <dstillman@zotero.org>
Date: Wed, 27 May 2009 04:18:37 +0000
- Remove unused code from Zotero.Groups
- Adjust Zotero.Items.getAll(onlyTopLevel) to take a libraryID in the second parameter and only search local library otherwise -- this has the side effect of no longer exporting group items when using Export Library, which may or may not be what we want
Diffstat:
2 files changed, 13 insertions(+), 102 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/group.js b/chrome/content/zotero/xpcom/data/group.js
@@ -279,7 +279,7 @@ Zotero.Group.prototype.save = function () {
/**
* Deletes group and all descendant objects
**/
-Zotero.Group.prototype.erase = function(deleteItems) {
+Zotero.Group.prototype.erase = function() {
Zotero.DB.beginTransaction();
var sql, ids, obj;
@@ -357,105 +357,6 @@ Zotero.Group.prototype.serialize = function() {
}
-/**
- * Returns an array of descendent groups and items
- *
- * @param bool recursive Descend into subgroups
- * @param bool nested Return multidimensional array with 'children'
- * nodes instead of flat array
- * @param string type 'item', 'group', or FALSE for both
- * @return {Object[]} Array of objects with 'id', 'key',
- * 'type' ('item' or 'group'), 'parent',
- * and, if group, 'name' and the nesting 'level'
- */
-Zotero.Group.prototype.getChildren = function(recursive, nested, type, level) {
- if (!this.id) {
- throw ('Zotero.Group.getChildren() cannot be called on an unsaved item');
- }
-
- var toReturn = [];
-
- if (!level) {
- level = 1;
- }
-
- // 0 == group
- // 1 == item
- var children = Zotero.DB.query('SELECT groupID AS id, '
- + "0 AS type, groupName AS groupName, key "
- + 'FROM groups WHERE parentGroupID=?1'
- + ' UNION SELECT itemID AS id, 1 AS type, NULL AS groupName, key '
- + 'FROM groupItems JOIN items USING (itemID) WHERE groupID=?1', this.id);
-
- if (type) {
- switch (type) {
- case 'item':
- case 'group':
- break;
- default:
- throw ("Invalid type '" + type + "' in Group.getChildren()");
- }
- }
-
- for(var i=0, len=children.length; i<len; i++) {
- // This seems to not work without parseInt() even though
- // typeof children[i]['type'] == 'number' and
- // children[i]['type'] === parseInt(children[i]['type']),
- // which sure seems like a bug to me
- switch (parseInt(children[i].type)) {
- case 0:
- if (!type || type=='group') {
- toReturn.push({
- id: children[i].id,
- name: children[i].groupName,
- key: children[i].key,
- type: 'group',
- level: level,
- parent: this.id
- });
- }
-
- if (recursive) {
- var descendents =
- Zotero.Groups.get(children[i].id).
- getChildren(true, nested, type, level+1);
-
- if (nested) {
- toReturn[toReturn.length-1].children = descendents;
- }
- else {
- for (var j=0, len2=descendents.length; j<len2; j++) {
- toReturn.push(descendents[j]);
- }
- }
- }
- break;
-
- case 1:
- if (!type || type=='item') {
- toReturn.push({
- id: children[i].id,
- key: children[i].key,
- type: 'item',
- parent: this.id
- });
- }
- break;
- }
- }
-
- return toReturn;
-}
-
-
-/**
- * Alias for the recursive mode of getChildren()
- */
-Zotero.Group.prototype.getDescendents = function(nested, type, level) {
- return this.getChildren(true, nested, type);
-}
-
-
Zotero.Group.prototype._prepFieldChange = function (field) {
if (!this._changed) {
this._changed = {};
diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js
@@ -148,15 +148,25 @@ Zotero.Items = new function() {
*
* If |onlyTopLevel|, don't include child items
*/
- function getAll(onlyTopLevel) {
+ function getAll(onlyTopLevel, libraryID) {
var sql = 'SELECT A.itemID FROM items A';
if (onlyTopLevel) {
sql += ' LEFT JOIN itemNotes B USING (itemID) '
+ 'LEFT JOIN itemAttachments C ON (C.itemID=A.itemID) '
+ 'WHERE B.sourceItemID IS NULL AND C.sourceItemID IS NULL';
}
+ else {
+ sql += " WHERE 1";
+ }
+ if (libraryID) {
+ sql += " AND libraryID=?";
+ var ids = Zotero.DB.columnQuery(sql, libraryID);
+ }
+ else {
+ //sql += " AND libraryID IS NULL";
+ var ids = Zotero.DB.columnQuery(sql);
+ }
- var ids = Zotero.DB.columnQuery(sql);
return this.get(ids);
}