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
1 changed files with 19 additions and 4 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue