Ejemplo n.º 1
0
        private string MoveItem(NameValueCollection request)
        {
            var         path = PartsExtensions.EnsureDraft(versions, versionRepository, navigator, request);
            ContentItem item = path.CurrentItem;
            ContentItem page = path.CurrentPage;

            item.ZoneName = request["zone"];

            var         beforeItem = PartsExtensions.GetBeforeItem(navigator, request, page);
            ContentItem parent;

            if (beforeItem != null)
            {
                parent = beforeItem.Parent;
                int newIndex = parent.Children.IndexOf(beforeItem);
                ValidateLocation(item, parent);
                Utility.Insert(item, parent, newIndex);
            }
            else
            {
                parent = PartsExtensions.GetBelowItem(navigator, request, page);
                ValidateLocation(item, parent);
                Utility.Insert(item, parent, parent.Children.Count);
            }

            Utility.UpdateSortOrder(parent.Children);
            versionRepository.Save(page);

            return(page.Url.ToUrl().SetQueryParameter("edit", "drag"));
        }
        // find the target item and index
        protected ContentItem GetParentAndIndex(NameValueCollection request, ContentItem page, out int newIndex)
        {
            var         beforeItem = PartsExtensions.GetBeforeItem(navigator, request, page);
            ContentItem parent;

            if (beforeItem != null)
            {
                parent   = beforeItem.Parent;
                newIndex = parent.Children.IndexOf(beforeItem);
            }
            else
            {
                parent   = PartsExtensions.GetBelowItem(navigator, request, page);
                newIndex = parent == null ? 0 : parent.Children.Count;
            }
            return(parent);
        }
Ejemplo n.º 3
0
        private string CopyItem(NameValueCollection request)
        {
            var         path = PartsExtensions.EnsureDraft(versions, versionRepository, navigator, request);
            ContentItem item = path.CurrentItem;
            ContentItem page = path.CurrentPage;

            item          = item.Clone(true);
            item.Name     = null;
            item.ZoneName = request["zone"];
            foreach (var child in Find.EnumerateChildren(item, true, false))
            {
                child.SetVersionKey(Guid.NewGuid().ToString());
            }

            var         beforeItem = PartsExtensions.GetBeforeItem(navigator, request, page);
            ContentItem parent;

            if (beforeItem != null)
            {
                parent = beforeItem.Parent;
                int newIndex = parent.Children.IndexOf(beforeItem);
                ValidateLocation(item, parent);
                Utility.Insert(item, parent, newIndex);
            }
            else
            {
                parent = PartsExtensions.GetBelowItem(navigator, request, page);
                ValidateLocation(item, parent);
                Utility.Insert(item, parent, parent.Children.Count);
            }

            Utility.UpdateSortOrder(parent.Children);
            versionRepository.Save(page);

            return(page.Url.ToUrl().SetQueryParameter("edit", "drag"));
        }
        public override NameValueCollection HandleRequest(NameValueCollection request)
        {
            bool isNew    = false;
            var  response = new NameValueCollection();

            try
            {
                // locate the item to be modified
                var original = FindItem(versions, versionRepository, navigator, request);

                var disc = request["discriminator"];
                if (definitionManager != null && !string.IsNullOrEmpty(disc) && !definitionManager.GetDefinition(original).Discriminator.Equals(disc))
                {
                    throw new Exception("unexpected part type for " + original);
                }
#if DEBUG2
                origPage = Find.ClosestPage(original);
                Dump(origPage);
                Logger.DebugFormat("AJAX found item {0} on page {1}", original, origPage);
#endif
                // get or create a draft to work with
                var path = PartsExtensions.EnsureDraft(original, versions, versionRepository, out isNew);
                var item = path.CurrentItem;
                if (definitionManager != null && !string.IsNullOrEmpty(disc) && !definitionManager.GetDefinition(item).Discriminator.Equals(disc))
                {
                    throw new Exception("unexpected part type for " + item);
                }

                Page = path.CurrentPage;
#if DEBUG2
                if (isNew || page != origPage)
                {
                    Logger.DebugFormat("AJAX changing item {0} on page {1}", item, page);
                }
#endif
                // perform action on item
                if (UpdateItem(request, item))
                {
                    // ensure proper user name
                    if (Principal != null)
                    {
                        Page.SavedBy = item.SavedBy = Principal.Identity.Name;
                    }
                    versionRepository.Save(Page);
                    Logger.DebugFormat("AJAX saved page {0} by {1}", Page, Page.SavedBy);
#if DEBUG
                    Dump(Page);
#endif
                }
                //response["redirect"] = isNew ? (string) Page.Url.ToUrl().SetQueryParameter("edit", "drag") : "#";
                response["redirect"] = (string)Page.Url.ToUrl().SetQueryParameter("edit", "drag").SetQueryParameter("random", Guid.NewGuid().ToString());
            }
            catch (Exception ex)
            {
                if (isNew)
                {
                    Logger.ErrorFormat("TODO Rollback Draft {0} after {1}", Page, ex.Message);
                    // TODO
                }

                throw;
            }
            return(response);
        }