Exemple #1
0
        public override bool UpdateItem(ContentItem item, Control editor)
        {
            bool           updated    = false;
            ItemEditorList listEditor = (ItemEditorList)editor;

            for (int i = 0; i < listEditor.ItemEditors.Count; i++)
            {
                ItemEditor childEditor  = listEditor.ItemEditors[i];
                ItemEditor parentEditor = ItemUtility.FindInParents <ItemEditor>(editor.Parent);

                var childItem = childEditor.CurrentItem;
                if (childItem.ID != 0 && item.ID == 0 && !childItem.IsPage)
                {
                    // we may have initialized the editor with the published version but we want to use the draft here
                    childItem = item.FindPartVersion(childItem);
                }

                if (listEditor.DeletedIndexes.Contains(i))
                {
                    if (childItem.ID == 0)
                    {
                        childItem.AddTo(null);
                    }
                    else
                    {
                        Engine.Persister.Delete(childItem);
                    }
                }
                else
                {
                    if (parentEditor != null)
                    {
                        var subContext = parentEditor.BinderContext.CreateNestedContext(childEditor, childItem, childEditor.GetDefinition());
                        if (subContext.Binder.UpdateObject(subContext))
                        {
                            childItem.AddTo(item); // make sure it's on parent's child collection
                            parentEditor.BinderContext.RegisterItemToSave(childItem);
                            updated = true;
                        }
                    }
                    else
                    {
                        IItemEditor fallbackEditor = ItemUtility.FindInParents <IItemEditor>(editor.Parent);
                        if (fallbackEditor != null)
                        {
                            fallbackEditor.Saved += delegate
                            {
                                var cc = childEditor.CreateCommandContext();
                                Engine.Resolve <CommandDispatcher>().Publish(cc);
                            };
                        }
                    }
                }
            }
            return(updated || listEditor.DeletedIndexes.Count > 0 || listEditor.AddedDefinitions.Count > 0);
        }
Exemple #2
0
        public override bool UpdateItem(ContentItem item, Control editor)
        {
            bool           updated    = false;
            ItemEditorList listEditor = (ItemEditorList)editor;

            for (int i = 0; i < listEditor.ItemEditors.Count; i++)
            {
                if (listEditor.DeletedIndexes.Contains(i))
                {
                    var deletedChild = listEditor.ItemEditors[i].CurrentItem;
                    if (deletedChild.ID == 0)
                    {
                        deletedChild.AddTo(null);
                    }
                    else
                    {
                        Engine.Persister.Delete(deletedChild);
                    }
                }
                else
                {
                    ItemEditor childEditor  = listEditor.ItemEditors[i];
                    ItemEditor parentEditor = ItemUtility.FindInParents <ItemEditor>(editor.Parent);
                    if (parentEditor != null)
                    {
                        var subContext = parentEditor.BinderContext.CreateNestedContext(childEditor, childEditor.CurrentItem, childEditor.GetDefinition());
                        if (subContext.Binder.UpdateObject(subContext))
                        {
                            updated = true;
                        }
                    }
                    else
                    {
                        IItemEditor fallbackEditor = ItemUtility.FindInParents <IItemEditor>(editor.Parent);
                        if (fallbackEditor != null)
                        {
                            fallbackEditor.Saved += delegate
                            {
                                var cc = childEditor.CreateCommandContext();
                                Engine.Resolve <CommandDispatcher>().Publish(cc);
                            };
                        }
                    }
                }
            }
            return(updated || listEditor.DeletedIndexes.Count > 0 || listEditor.AddedDefinitions.Count > 0);
        }
        public override bool UpdateItem(ContentItem parentItem, Control editor)
        {
            ItemEditor childEditor  = editor as ItemEditor;
            ItemEditor parentEditor = ItemUtility.FindInParents <ItemEditor>(editor.Parent);

            var childItem = childEditor.CurrentItem;

            if (childItem.ID != 0 && parentItem.ID == 0)
            {
                // we may have initialized the editor with the published version but we want to use the draft here
                childItem = parentItem.FindPartVersion(childItem);
            }

            if (childEditor.UpdateObject(parentEditor.BinderContext.CreateNestedContext(childEditor, childItem, childEditor.GetDefinition())))
            {
                parentItem[Name] = childItem;
                return(true);
            }

            return(false);
        }
Exemple #4
0
        public override bool UpdateItem(ContentItem parentItem, Control editor)
        {
            ItemEditor itemEditor   = editor as ItemEditor;
            ItemEditor parentEditor = ItemUtility.FindInParents <ItemEditor>(editor.Parent);

            return(itemEditor.UpdateObject(parentEditor.BinderContext.CreateNestedContext(itemEditor, itemEditor.CurrentItem, itemEditor.GetDefinition())));
        }