in public/src/js/utils/drag-dispatcher.js [221:292]
function persist (sourceItem, newItems, sourceContext, sourceGroup, targetContext, targetGroup, position, isAfter) {
if (sourceItem.type === vars.CONST.draggableTypes.configCollection) {
if (!findFirstById(newItems[0].parents, targetGroup.parent.id())) {
newItems[0].parents.push(targetGroup.parent.opts);
}
return targetGroup.parent.saveProps();
} else {
var id = newItems[0].id(),
itemMeta,
supporting,
update,
remove,
returnValue;
if (!targetGroup || !targetGroup.parent) {
return;
} else if (targetGroup.parentType === 'Article') {
supporting = targetGroup.parent.meta.supporting.items;
_.each(newItems.slice(1), function(item) {
supporting.remove(function (supp) { return supp.id() === item.id(); });
supporting.push(item);
});
returnValue = capi.decorateItems(supporting());
remove = remover(sourceContext, sourceGroup, id);
} else if (targetGroup.parentType === 'Collection') {
itemMeta = serializeArticleMeta(newItems[0]) || {};
if (deepGet(targetGroup, '.parent.groups.length') > 1) {
itemMeta.group = targetGroup.index + '';
} else {
delete itemMeta.group;
}
update = {
collection: targetGroup.parent,
item: id,
position: position,
after: isAfter,
mode: targetContext.mode(),
itemMeta: _.isEmpty(itemMeta) ? undefined : itemMeta
};
remove = sourceGroup && sourceGroup.parentType === 'Collection' && (deepGet(sourceGroup, '.parent.id') && deepGet(sourceGroup, '.parent.id') !== targetGroup.parent.id);
remove = remove ? remover(sourceContext, sourceGroup, id) : undefined;
}
if (sourceContext !== targetContext) {
remove = false;
}
if (update || remove) {
returnValue = authedAjax.updateCollections({
update: update,
remove: remove ? remove : undefined
})
.then(function () {
if (targetContext.mode() === 'live') {
mediator.emit('presser:detectfailures', targetContext.front());
}
});
}
if (remove !== false && sourceGroup && !sourceGroup.keepCopy && sourceGroup !== targetGroup && sourceGroup.items) {
removeById(sourceGroup.items, id); // for immediate UI effect
}
return returnValue;
}
}