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:
parent
9234aa8b9b
commit
40ef9f669d
|
@ -1278,7 +1278,7 @@ Scholar.Item.prototype.getSeeAlso = function(){
|
||||||
/**
|
/**
|
||||||
* Delete item from database and clear from Scholar.Items internal array
|
* 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()){
|
if (!this.getID()){
|
||||||
return false;
|
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
|
// Notes
|
||||||
var sql = "SELECT itemID FROM itemNotes WHERE sourceItemID=" + this.getID();
|
var sql = "SELECT itemID FROM itemNotes WHERE sourceItemID=" + this.getID();
|
||||||
var childNotes = Scholar.DB.columnQuery(sql);
|
var childNotes = Scholar.DB.columnQuery(sql);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user