Ejemplo n.º 1
0
        private string CreateItem(TemplateDefinition template, NameValueCollection request)
        {
            var path = new PathData(navigator.Navigate(request["below"]));
            if (!versionRepository.TryParseVersion(request[PathData.VersionIndexQueryKey], request[PathData.VersionKeyQueryKey], path))
                path.CurrentItem = versions.AddVersion(path.CurrentItem, asPreviousVersion: false);
            var parent = path.CurrentItem;

            ContentItem item = activator.CreateInstance(template.Definition.ItemType, parent);
            item.ZoneName = request["zone"];
            item.TemplateKey = template.Name;

            string beforeVersionKey = request["beforeVersionKey"];
            string beforeSortOrder = request["beforeSortOrder"];
            string before = request["before"];
            if (string.IsNullOrEmpty(beforeSortOrder))
            {
                item.AddTo(parent);
            }
            else
            {
                int index = int.Parse(beforeSortOrder);
                parent.InsertChildBefore(item, index);
            }

            versionRepository.Save(parent);
            return request["returnUrl"].ToUrl().SetQueryParameter(PathData.VersionIndexQueryKey, parent.VersionIndex);
        }
Ejemplo n.º 2
0
        private void CreateItem(TemplateDefinition template, NameValueCollection request)
        {
            ContentItem parent = navigator.Navigate(request["below"]);

            ContentItem item = activator.CreateInstance(template.Definition.ItemType, parent);
            item.ZoneName = request["zone"];
            item.TemplateKey = template.Name;

            string before = request["before"];
            if (!string.IsNullOrEmpty(before))
            {
                ContentItem beforeItem = navigator.Navigate(before);
                int newIndex = parent.Children.IndexOf(beforeItem);
                Utility.Insert(item, parent, newIndex);

                foreach (var sibling in Utility.UpdateSortOrder(parent.Children))
                    persister.Repository.Save(sibling);
            }

            persister.Save(item);
        }
Ejemplo n.º 3
0
		private string GetRedirectUrl(TemplateDefinition template, NameValueCollection request)
		{
			string zone = request["zone"];

			string before = request["before"];
			string below = request["below"];

			Url url = null;
			if (!string.IsNullOrEmpty(before))
			{
                ContentItem beforeItem = navigator.Navigate(before);
				if (beforeItem != null)
					url = managementPaths.GetEditNewPageUrl(beforeItem, template.Definition, zone, CreationPosition.Before);
			}
			if (url == null)
			{
                ContentItem parent = navigator.Navigate(below);
				url = managementPaths.GetEditNewPageUrl(parent, template.Definition, zone, CreationPosition.Below);
			}
			string beforeSortOrder = request["beforeSortOrder"];
			url = url.SetQueryParameter("beforeSortOrder", beforeSortOrder);

			if (!string.IsNullOrEmpty(request[PathData.VersionIndexQueryKey]))
				url = url.SetQueryParameter(PathData.VersionIndexQueryKey, request[PathData.VersionIndexQueryKey]);
			
			//if (!string.IsNullOrEmpty(request["versionKey"]))
			//    url = url.SetQueryParameter("versionKey", request["versionKey"]);
			if (!string.IsNullOrEmpty(request["belowVersionKey"]))
				url = url.SetQueryParameter("versionKey", request["belowVersionKey"]);
			if (!string.IsNullOrEmpty(request["belowVersionKey"]))
				url = url.SetQueryParameter("versionKey", request["belowVersionKey"]);
			if (!string.IsNullOrEmpty(request["beforeVersionKey"]))
				url = url.SetQueryParameter("beforeVersionKey", request["beforeVersionKey"]);
	
			if (!string.IsNullOrEmpty(request["returnUrl"]))
				url = url.SetQueryParameter("returnUrl", request["returnUrl"]);

			url = url.SetQueryParameter("edit", "drag");
			return url;
		}
Ejemplo n.º 4
0
		private TemplateDefinition CreateTemplateInfo(ContentItem template)
		{
			var info = new TemplateDefinition
			{
				Name = template.Name,
				Title = template.Title,
				Description = template.GetDetail(TemplateDescription, ""),
				TemplateUrl = template.Url,
				Definition = map.GetOrCreateDefinition(template.GetContentType(), template.Name),
				TemplateFactory = () =>
				{
					var clone = template.Clone(true);
					clone.SetDetail(TemplateDescription, null, typeof(string));
					clone.Title = "";
					clone.Name = null;
					clone.TemplateKey = template.Name;
					return clone;
				},
				OriginalFactory = () => template
			};
			return info;
		}
Ejemplo n.º 5
0
        private LinkButton CreateButton(Control container, TemplateDefinition template)
        {
            var button = new LinkButton
            {
				ID = "iel" + ID + "_" + template.Definition.GetDiscriminatorWithTemplateKey().Replace('/', '_'),
				Text = string.IsNullOrEmpty(template.Definition.IconUrl)
                    ? string.Format("<b class='{0}'></b> {1}", template.Definition.IconClass, template.Definition.Title)
                    : string.Format("<img src='{0}' alt='ico'/>{1}", template.Definition.IconUrl, template.Definition.Title),
                ToolTip = template.Definition.ToolTip,
                CausesValidation = false,
                CssClass = "addButton"
            };
            var closureDefinition = template.Definition;
            button.Command += (s, a) =>
            {
                ContentItem item = CreateItem(closureDefinition);
                item.ZoneName = ZoneName;
                AddedDefinitions.Add(closureDefinition.GetDiscriminatorWithTemplateKey());
                CreateItemEditor(item);
            };
            container.Controls.Add(button);
            return button;
        }
Ejemplo n.º 6
0
        private string GetRedirectUrl(TemplateDefinition template, NameValueCollection request)
        {
            string zone = request["zone"];

            string before = request["before"];
            string below = request["below"];

            Url url;
            if (!string.IsNullOrEmpty(before))
            {
                ContentItem beforeItem = navigator.Navigate(before);
                url = managementPaths.GetEditNewPageUrl(beforeItem, template.Definition, zone, CreationPosition.Before);
            }
            else
            {
                ContentItem parent = navigator.Navigate(below);
                url = managementPaths.GetEditNewPageUrl(parent, template.Definition, zone, CreationPosition.Below);
            }

            if (!string.IsNullOrEmpty(request["returnUrl"]))
                url = url.AppendQuery("returnUrl", request["returnUrl"]);
            return url;
        }
Ejemplo n.º 7
0
 private TemplateDefinition CreateTemplateInfo(ContentItem template)
 {
     var clone = template.Clone(true);
     clone.SetDetail(TemplateDescription, null, typeof(string));
     clone.Title = "";
     clone.Name = null;
     clone["TemplateName"] = template.Name;
     var info = new TemplateDefinition
     {
         Name = template.Name,
         Title = template.Title,
         Description = template.GetDetail(TemplateDescription, ""),
         TemplateUrl = template.Url,
         Definition = definitions.GetDefinition(template.GetContentType()).Clone(),
         Template = clone,
         Original = template
     };
     info.Definition.Template = template.Name;
     return info;
 }
Ejemplo n.º 8
0
        private LinkButton CreateButton(Control container, TemplateDefinition template)
        {
            var button = new LinkButton
            {
				ID = "iel" + ID + "_" + template.Definition.GetDiscriminatorWithTemplateKey().Replace('/', '_'),
				Text = string.IsNullOrEmpty(template.Definition.IconUrl)
                    ? string.Format("<b class='{0}'></b> {1}", template.Definition.IconClass, template.Definition.Title)
                    : string.Format("<img src='{0}' alt='ico'/>{1}", template.Definition.IconUrl, template.Definition.Title),
                ToolTip = template.Definition.ToolTip,
                CausesValidation = false,
                CssClass = "addButton"
            };
            var closureDefinition = template.Definition;
            button.Command += (s, a) =>
            {
				var path = EnsureDraft(ParentItem);

				UpdateItemFromTopEditor(path);

				ContentItem item = CreateItem(closureDefinition);
				item.AddTo(path.CurrentItem, ZoneName);
				Utility.UpdateSortOrder(path.CurrentItem.Children).ToList();

				var cvr = Engine.Resolve<ContentVersionRepository>();
				cvr.Save(path.CurrentPage);

				RedirectToVersionOfSelf(path.CurrentPage);
			};
            container.Controls.Add(button);
            return button;
        }
		public IEnumerable<TemplateDefinition> GetTemplates(Type contentType)
		{
			return GetTemplateDefinitions().Where(d => d.ItemType == contentType).Select(d =>
			{
				var td = new TemplateDefinition
				{
					Definition = d,
					Description = d.Description,
					Name = d.TemplateKey,
					OriginalFactory = () => null,
					TemplateFactory = () => _activator.CreateInstance(d.ItemType, null, d.TemplateKey),
					TemplateUrl = null,
					Title = d.Title + '*',
                    ReplaceDefault = true // causes hiding of base class "ContentPart", see DefinitionManager.GetTemplates
				};
				return td;
			}).ToArray();
		}