commit 40ef9f669d4c8f5dfe7e47f0861509abcfc0104c
parent 9234aa8b9b14c9a8c726edbf54f616e222966377
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 31 Jul 2006 06:05:19 +0000
Closes #90, Add flag to delete child notes when a source is deleted
Item.erase(true) deletes child items as well instead of just unlinking
Diffstat:
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js
@@ -1278,7 +1278,7 @@ Scholar.Item.prototype.getSeeAlso = function(){
/**
* Delete item from database and clear from Scholar.Items internal array
**/
-Scholar.Item.prototype.erase = function(){
+Scholar.Item.prototype.erase = function(deleteChildren){
if (!this.getID()){
return false;
}
@@ -1332,10 +1332,25 @@ Scholar.Item.prototype.erase = function(){
}
}
}
- // If regular item, unassociate any notes or files for which this is a source
- else {
- // TODO: option for deleting child notes instead of unlinking
+
+ // Regular item
+
+ // Delete child notes and files
+ else if (deleteChildren){
+ var sql = "SELECT itemID FROM itemNotes WHERE sourceItemID=?1 UNION "
+ + "SELECT itemID FROM itemFiles WHERE sourceItemID=?1";
+ var toDelete = Scholar.DB.columnQuery(sql, [this.getID()]);
+ if (toDelete){
+ for (var i in toDelete){
+ var obj = Scholar.Items.get(toDelete[i]);
+ obj.erase(true);
+ }
+ }
+ }
+
+ // Just unlink any child notes or files without deleting
+ else {
// Notes
var sql = "SELECT itemID FROM itemNotes WHERE sourceItemID=" + this.getID();
var childNotes = Scholar.DB.columnQuery(sql);