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
This commit is contained in:
Dan Stillman 2006-07-31 06:05:19 +00:00
parent 9234aa8b9b
commit 40ef9f669d

View file

@ -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);