Refresh content object before duplicating item
This commit is contained in:
@@ -55,6 +55,13 @@ class Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshContentObject() {
|
||||||
|
// Before an item can be duplicated or cloned, we must update this.content (if it is an object) with the object's
|
||||||
|
// current physical properties, because updateFromJSON, which is what all new items must go through,
|
||||||
|
// will call this.mapContentToLocalProperties(this.contentObject), which may have stale values if not explicitly updated.
|
||||||
|
|
||||||
|
this.content = this.structureParams();
|
||||||
|
}
|
||||||
|
|
||||||
/* Allows the item to handle the case where the item is deleted and the content is null */
|
/* Allows the item to handle the case where the item is deleted and the content is null */
|
||||||
handleDeletedContent() {
|
handleDeletedContent() {
|
||||||
|
|||||||
@@ -44,7 +44,11 @@ class ModelManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
alternateUUIDForItem(item, callback, removeOriginal) {
|
alternateUUIDForItem(item, callback, removeOriginal) {
|
||||||
// we need to clone this item and give it a new uuid, then delete item with old uuid from db (you can't mofidy uuid's in our indexeddb setup)
|
// We need to clone this item and give it a new uuid, then delete item with old uuid from db (you can't modify uuid's in our indexeddb setup)
|
||||||
|
|
||||||
|
// Collapse in memory properties to item's content object, as the new item will be created based on the content object, and not the physical properties. (like note.text or note.title)
|
||||||
|
item.refreshContentObject();
|
||||||
|
|
||||||
var newItem = this.createItem(item);
|
var newItem = this.createItem(item);
|
||||||
|
|
||||||
newItem.uuid = SFJS.crypto.generateUUID();
|
newItem.uuid = SFJS.crypto.generateUUID();
|
||||||
@@ -54,6 +58,7 @@ class ModelManager {
|
|||||||
|
|
||||||
this.informModelsOfUUIDChangeForItem(newItem, item.uuid, newItem.uuid);
|
this.informModelsOfUUIDChangeForItem(newItem, item.uuid, newItem.uuid);
|
||||||
|
|
||||||
|
|
||||||
console.log(item.uuid, "-->", newItem.uuid);
|
console.log(item.uuid, "-->", newItem.uuid);
|
||||||
|
|
||||||
var block = () => {
|
var block = () => {
|
||||||
@@ -261,7 +266,14 @@ class ModelManager {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
createDuplicateItem(itemResponse, sourceItem) {
|
/*
|
||||||
|
Be sure itemResponse is a generic Javascript object, and not an Item.
|
||||||
|
An Item needs to collapse its properties into its content object before it can be duplicated.
|
||||||
|
Note: the reason we need this function is specificallty for the call to resolveReferencesForItem.
|
||||||
|
This method creates but does not add the item to the global inventory. It's used by syncManager
|
||||||
|
to check if this prospective duplicate item is identical to another item, including the references.
|
||||||
|
*/
|
||||||
|
createDuplicateItem(itemResponse) {
|
||||||
var dup = this.createItem(itemResponse, true);
|
var dup = this.createItem(itemResponse, true);
|
||||||
this.resolveReferencesForItem(dup);
|
this.resolveReferencesForItem(dup);
|
||||||
return dup;
|
return dup;
|
||||||
|
|||||||
@@ -475,7 +475,7 @@ class SyncManager {
|
|||||||
// We want a new uuid for the new item. Note that this won't neccessarily adjust references.
|
// We want a new uuid for the new item. Note that this won't neccessarily adjust references.
|
||||||
itemResponse.uuid = null;
|
itemResponse.uuid = null;
|
||||||
|
|
||||||
var dup = this.modelManager.createDuplicateItem(itemResponse, item);
|
var dup = this.modelManager.createDuplicateItem(itemResponse);
|
||||||
if(!itemResponse.deleted && !item.isItemContentEqualWith(dup)) {
|
if(!itemResponse.deleted && !item.isItemContentEqualWith(dup)) {
|
||||||
this.modelManager.addItem(dup);
|
this.modelManager.addItem(dup);
|
||||||
dup.conflict_of = item.uuid;
|
dup.conflict_of = item.uuid;
|
||||||
|
|||||||
Reference in New Issue
Block a user