Skip to content

Commit

Permalink
working fix for #105 (logic needs to be moved)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendy committed Jun 28, 2015
1 parent e3b8332 commit 1b41844
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
38 changes: 36 additions & 2 deletions source/nuPickers/Shared/RelationMapping/RelationMappingEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,46 @@ private void Saved(IService sender, IEnumerable<IContentBase> savedEntities)

if (!string.IsNullOrWhiteSpace(picker.RelationTypeAlias))
{
int[] pickedIds;
bool isRelationsOnly = picker.GetDataTypePreValue("saveFormat").Value == "relationsOnly";

if (isRelationsOnly)
{
pickedIds = picker.SavedValue != null // special case - read saved value
? picker.SavedValue.ToString().Split(',').Select(x => int.Parse(x)).ToArray()
: new int[]{};

if (pickedIds.Any())
{
// delete saved value
savedEntity.SetValue(propertyType.Alias, null);

if (sender is IContentService)
{
((IContentService)sender).Save((IContent)savedEntity, 0, false);
}
else if (sender is IMediaService)
{
((IMediaService)sender).Save((IMedia)savedEntity, 0, false);
}
else if (sender is IMemberService)
{
((IMemberService)sender).Save((IMember)savedEntity, false);
}
}
}
else
{
// read current saved value
pickedIds = picker.PickedIds.ToArray();
}

RelationMapping.UpdateRelationMapping(
picker.ContextId, // savedEntity.Id
picker.PropertyAlias, // propertyType.Alias
picker.RelationTypeAlias,
picker.GetDataTypePreValue("saveFormat").Value == "relationsOnly",
picker.PickedIds.ToArray());
isRelationsOnly,
pickedIds);
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion source/nuPickers/Shared/SaveFormat/SaveFormatResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ angular.module('umbraco.resources')
return xml;
break;

case 'relationsOnly': // when saving to relations only
case 'relationsOnly':
// special case - so server-side relation-mapping can read these values and then delete them
// (relations must be set server side, as new items do not have an id available client-side)

var ids = [];
for (var i = 0; i < pickedOptions.length; i++) {
if (parseInt(Number(pickedOptions[i].key)), 10) {
ids.push(pickedOptions[i].key);
}
}

return ids.join();

default:
return null;
break;
Expand Down

0 comments on commit 1b41844

Please sign in to comment.