Esempio n. 1
0
        /// <summary>Saves an item using values from the supplied item editor.</summary>
        /// <param name="item">The item to update.</param>
        /// <param name="addedEditors">The editors to update the item with.</param>
        /// <param name="versioningMode">How to treat the item beeing saved in respect to versioning.</param>
        /// <param name="user">The user that is performing the saving.</param>
        public virtual ContentItem Save(ContentItem item, IDictionary <string, Control> addedEditors,
                                        ItemEditorVersioningMode versioningMode, IPrincipal user)
        {
            // when an unpublished version is saved and published
            if (versioningMode == ItemEditorVersioningMode.SaveAsMaster)
            {
                return(SaveAsMaster(item, addedEditors, user));
            }

            // when an item is saved without any new version
            if (versioningMode == ItemEditorVersioningMode.SaveOnly)
            {
                return(SaveOnly(item, addedEditors, user));
            }

            // when an item is saved but a version is stored before the item is updated
            if (versioningMode == ItemEditorVersioningMode.VersionAndSave)
            {
                return(VersionAndSave(item, addedEditors, user));
            }

            // when making a version without publishing the item
            if (versioningMode == ItemEditorVersioningMode.VersionOnly)
            {
                return(VersionOnly(item, addedEditors, user));
            }

            throw new ArgumentException("Unexpected versioning mode.", "versioningMode");
        }
Esempio n. 2
0
 public OnPageItemEditor(ItemEditorVersioningMode versioningMode, string zoneName,
                         IDictionary <string, Control> addedEditors, ContentItem currentItem)
 {
     this.versioningMode = versioningMode;
     this.zoneName       = zoneName;
     this.addedEditors   = addedEditors;
     this.currentItem    = currentItem;
 }
			public OnPageItemEditor(ItemEditorVersioningMode versioningMode, string zoneName,
			                        IDictionary<string, Control> addedEditors, ContentItem currentItem)
			{
				this.versioningMode = versioningMode;
				this.zoneName = zoneName;
				this.addedEditors = addedEditors;
				this.currentItem = currentItem;
			}
Esempio n. 4
0
 public ContentItem Save(ContentItem item, ItemEditorVersioningMode mode)
 {
     EnsureChildControls();
     BinderContext = CreateCommandContext();
     item          = EditAdapter.SaveItem(item, AddedEditors, mode, Page.User);
     if (Saved != null)
     {
         Saved.Invoke(this, new ItemEventArgs(item));
     }
     return(item);
 }
Esempio n. 5
0
 /// <summary>Saves <see cref="CurrentItem"/> with the values entered in the form.</summary>
 public ContentItem Save(ContentItem item, ItemEditorVersioningMode mode)
 {
     EnsureChildControls();
     BinderContext = new CommandContext(GetDefinition(), item, "Unknown", Page.User, this, new N2.Edit.Web.PageValidator <CommandContext>(Page));
     item          = EditAdapter.SaveItem(item, AddedEditors, mode, Page.User);
     if (Saved != null)
     {
         Saved.Invoke(this, new ItemEventArgs(item));
     }
     return(item);
 }
Esempio n. 6
0
        public IEditableObject Save(ContentItem item, ItemEditorVersioningMode mode)
        {
            EnsureChildControls();

            // TODO- remove this because it won't work with DynamicContent
            item = Zeus.Context.AdminManager.Save(item, PropertyControls, mode, Page.User,
                c => OnSaving(new ItemViewEditableObjectEventArgs(c)));

            OnSaved(new ItemViewEditableObjectEventArgs(CurrentItem));

            return item;
        }
Esempio n. 7
0
        protected IItemEditor SimulateEditor(ContentItem item, ItemEditorVersioningMode versioningMode)
        {
            IItemEditor editor = mocks.StrictMock <IItemEditor>();

            Dictionary <string, Control> editors = CreateEditorsForComplexContainersItem();

            using (mocks.Record())
            {
                Expect.On(editor).Call(editor.CurrentItem).Return(item).Repeat.Any();
                Expect.On(editor).Call(editor.AddedEditors).Return(editors);
                Expect.On(editor).Call(editor.VersioningMode).Return(versioningMode).Repeat.Any();
            }
            return(editor);
        }
Esempio n. 8
0
		public virtual ContentItem SaveItem(ContentItem item, IDictionary<string, Control> addedEditors, ItemEditorVersioningMode versioningMode, IPrincipal user)
		{
			return EditManager.Save(item, addedEditors, versioningMode, user);
		}
Esempio n. 9
0
 /// <summary>Saves an item using values from the supplied item editor.</summary>
 /// <param name="item">The item to update.</param>
 /// <param name="addedEditors">The editors to update the item with.</param>
 /// <param name="versioningMode">How to treat the item beeing saved in respect to versioning.</param>
 /// <param name="user">The user that is performing the saving.</param>
 /// <returns>The item to continue using.</returns>
 public virtual ContentItem SaveItem(ContentItem item, IDictionary <string, Control> addedEditors, ItemEditorVersioningMode versioningMode, IPrincipal user)
 {
     return(EditManager.Save(item, addedEditors, versioningMode, user));
 }
Esempio n. 10
0
        protected IItemEditor SimulateEditor(ContentItem item, ItemEditorVersioningMode versioningMode)
        {
            IItemEditor editor = mocks.StrictMock<IItemEditor>();

            Dictionary<string, Control> editors = CreateEditorsForComplexContainersItem();

            using (mocks.Record())
            {
                Expect.On(editor).Call(editor.CurrentItem).Return(item).Repeat.Any();
                Expect.On(editor).Call(editor.AddedEditors).Return(editors);
                Expect.On(editor).Call(editor.VersioningMode).Return(versioningMode).Repeat.Any();
            }
            return editor;
        }
Esempio n. 11
0
        private ContentItem SaveVersion()
        {
            ItemEditorVersioningMode mode = (ie.CurrentItem.VersionOf == null) ? ItemEditorVersioningMode.VersionOnly : ItemEditorVersioningMode.SaveOnly;

            return(ie.Save(ie.CurrentItem, mode));
        }
Esempio n. 12
0
        /// <summary>Saves an item using values from the supplied item editor.</summary>
        /// <param name="item">The item to update.</param>
        /// <param name="addedEditors">The editors to update the item with.</param>
        /// <param name="versioningMode">How to treat the item beeing saved in respect to versioning.</param>
        /// <param name="user">The user that is performing the saving.</param>
        public virtual ContentItem Save(ContentItem item, IDictionary<string, Control> addedEditors, ItemEditorVersioningMode versioningMode, IPrincipal user,
			Action<ContentItem> onSavingCallback)
        {
            // when an unpublished version is saved and published
            if (versioningMode == ItemEditorVersioningMode.SaveAsMaster)
            {
                using (ITransaction tx = _persister.Repository.BeginTransaction())
                {
                    ContentItem itemToUpdate = item.VersionOf;
                    if (itemToUpdate == null) throw new ArgumentException("Expected the current item to be a version of another item.", "item");

                    if (ShouldStoreVersion(item))
                        SaveVersion(itemToUpdate);

                    DateTime? published = itemToUpdate.Published;
                    bool wasUpdated = UpdateItem(itemToUpdate, addedEditors, user);

                    if (wasUpdated || IsNew(itemToUpdate))
                    {
                        onSavingCallback(itemToUpdate);
                        itemToUpdate.Published = published ?? Utility.CurrentTime();
                        _persister.Save(itemToUpdate);

                        ContentItem theParent = itemToUpdate.Parent;
                        while (theParent.Parent != null)
                        {
                            //go up the tree updating - if a child has been changed, so effectively has the parent
                            theParent.Updated = DateTime.Now;
                            _persister.Save(theParent);
                            theParent = theParent.Parent;
                        }
                    }

                    tx.Commit();
                    return item.VersionOf;
                }
            }

            // when an item is saved without any new version
            if (versioningMode == ItemEditorVersioningMode.SaveOnly)
            {
                bool wasUpdated = UpdateItem(item, addedEditors, user);
                if (wasUpdated || IsNew(item))
                {
                    onSavingCallback(item);
                    _persister.Save(item);

                    ContentItem theParent = item.Parent;
                    while (theParent.Parent != null)
                    {
                        //go up the tree updating - if a child has been changed, so effectively has the parent
                        theParent.Updated = DateTime.Now;
                        _persister.Save(theParent);
                        theParent = theParent.Parent;
                    }
                }

                return item;
            }

            // when an item is saved but a version is stored before the item is updated
            if (versioningMode == ItemEditorVersioningMode.VersionAndSave)
            {
                using (ITransaction tx = _persister.Repository.BeginTransaction())
                {
                    if (ShouldStoreVersion(item))
                        SaveVersion(item);

                    DateTime? initialPublished = item.Published;
                    bool wasUpdated = UpdateItem(item, addedEditors, user);
                    DateTime? updatedPublished = item.Published;

                    // the item was the only version of an unpublished item - publish it
                    if (initialPublished == null && updatedPublished == null)
                    {
                        item.Published = Utility.CurrentTime();
                        wasUpdated = true;
                    }

                    IncrementVersion(item);

                    if (wasUpdated || IsNew(item))
                    {
                        onSavingCallback(item);
                        _persister.Save(item);
                    }

                    tx.Commit();

                    return item;
                }
            }

            // when making a version without saving the item
            if (versioningMode == ItemEditorVersioningMode.VersionOnly)
            {
                using (ITransaction tx = _persister.Repository.BeginTransaction())
                {
                    if (ShouldStoreVersion(item))
                        item = SaveVersion(item);

                    bool wasUpdated = UpdateItem(item, addedEditors, user);
                    if (wasUpdated || IsNew(item))
                    {
                        onSavingCallback(item);
                        item.Published = null;
                        _persister.Save(item);
                    }

                    IncrementVersion(item);

                    tx.Commit();
                    return item;
                }
            }

            throw new ArgumentException("Unexpected versioning mode.", "versioningMode");
        }