public void Displayable_CanBeRegistered()
        {
            registration.Add(new DisplayableTokensAttribute {
                Name = "Hello"
            });

            var definition = registration.Finalize();

            var displayable = definition.Displayables.Single(d => d.Name == "Hello");

            Assert.That(displayable, Is.InstanceOf <DisplayableTokensAttribute>());
            Assert.That(displayable.Name, Is.EqualTo("Hello"));
        }
Example #2
0
        public static ContentRegistration FieldSet(this ContentRegistration re, string containerName, string legend, Action <ContentRegistration> registration, int?sortOrder = null)
        {
            if (re == null)
            {
                return(re);
            }

            re.Add(new N2.Web.UI.FieldSetContainerAttribute(containerName, legend, re.Context.NextSortOrder(sortOrder)));

            if (registration != null)
            {
                using (re.Context.BeginContainer(containerName))
                {
                    registration(re);
                }
            }

            return(re);
        }
Example #3
0
        //// containables

        public static ContentRegistration Tab(this ContentRegistration re, string containerName, string tabText, Action <ContentRegistration> registration, int?sortOrder = null)
        {
            if (re == null)
            {
                return(re);
            }

            re.Add(new N2.Web.UI.TabContainerAttribute(containerName, tabText, re.Context.NextSortOrder(sortOrder)));

            string previousContainerName = re.Context.ContainerName;

            re.Context.ContainerName = containerName;
            if (registration != null)
            {
                registration(re);
                re.Context.ContainerName = previousContainerName;
            }

            return(re);
        }
Example #4
0
        public static ContentRegistration FieldSet(this ContentRegistration re, string containerName, string legend, Action <ContentRegistration> registration, int?sortOrder = null)
        {
            if (re == null)
            {
                return(re);
            }

            re.Add(new N2.Web.UI.FieldSetContainerAttribute(containerName, legend, re.NextSortOrder(sortOrder)));

            string previousContainerName = re.ContainerName;

            re.ContainerName = containerName;
            if (registration != null)
            {
                registration(re);
                re.ContainerName = previousContainerName;
            }

            return(re);
        }
		private ContentRegistration RegisterPart(PartDefinitionPage pd)
		{
			var def = DefinitionMap.Instance.GetOrCreateDefinition(typeof(ContentPart), pd.Title); // no extensions

			// registration - compare Dinamico views  @{ Content.Define(re => ... ) }
			var re = new ContentRegistration(def)
			    {
			        Definition = {TemplateKey = pd.Name, Description = pd.Description},
			        Context = {GlobalSortOffset = pd.PartSortOrder},
			        ContentType = def.ItemType,
			        Title = pd.Title,
			        IconUrl = pd.IconUrl
			    };

		    //if (!string.IsNullOrEmpty(pd.Definition))
			//{
			//    var jsd = new JavaScriptRegistration();
			//    jsd.Eval(re, pd.Definition);
			//}

			foreach (var attrDef in pd.Attributes)
			{
				AbstractEditableAttribute attr = null;
				var name = RemoveSpecialCharacters(attrDef.Title);
				switch (attrDef.PartType)
				{
					case PartDefinitionPage.AttributePart.AttributePartTypeEnum.RichText:
						attr = new EditableTextAttribute { TextMode = TextBoxMode.MultiLine, Name = name, Title = attrDef.Title };
						break;

					case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Number:
						attr = new EditableNumberAttribute { Name = name, Title = attrDef.Title };
						break;

					case PartDefinitionPage.AttributePart.AttributePartTypeEnum.CheckBox:
						attr = new EditableCheckBoxAttribute { Name = name, Title = attrDef.Title };
						break;

					case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Url:
						attr = new EditableUrlAttribute { Name = name, Title = attrDef.Title };
						break;

					case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Image:
						attr = new EditableImageAttribute { Name = name, Title = attrDef.Title };
						break;

#if TODO // use a better mechanism to find available types/attrs
                    case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Category:
                        attr = new EditableCategorySelectionAttribute("ID:" + name) { Name = name, Title = attrDef.Title };
                        break;

                    case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Product:
                        attr = new EditableProductMultiSelectionAttribute("Id:" + name) { Name = name, Title = attrDef.Title };
                        break;
#endif
                    case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Text:
                    default:
                        attr = new EditableTextAttribute { TextMode = TextBoxMode.SingleLine, Name = name, Title = attrDef.Title };
                        break;
                    //throw new ArgumentOutOfRangeException();
				}
				if (!string.IsNullOrEmpty(attrDef.DefaultValue))
					attr.DefaultValue = attrDef.DefaultValue;

				attr.HelpText = attrDef.HelpText;

				re.Add(attr);
			}

			re.IsDefined = true;
			re.Finalize();
			return re; 
		}
Example #6
0
        private ContentRegistration RegisterPart(PartDefinitionPage pd)
        {
            var def = DefinitionMap.Instance.GetOrCreateDefinition(typeof(ContentPart), pd.Title);             // no extensions

            // registration - compare Dinamico views  @{ Content.Define(re => ... ) }
            var re = new ContentRegistration(def)
            {
                Definition  = { TemplateKey = pd.Name, Description = pd.Description },
                Context     = { GlobalSortOffset = pd.PartSortOrder },
                ContentType = def.ItemType,
                Title       = pd.Title,
                IconUrl     = pd.IconUrl
            };

            //if (!string.IsNullOrEmpty(pd.Definition))
            //{
            //    var jsd = new JavaScriptRegistration();
            //    jsd.Eval(re, pd.Definition);
            //}

            foreach (var attrDef in pd.Attributes)
            {
                AbstractEditableAttribute attr = null;
                var name = RemoveSpecialCharacters(attrDef.Title);
                switch (attrDef.PartType)
                {
                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.RichText:
                    attr = new EditableTextAttribute {
                        TextMode = TextBoxMode.MultiLine, Name = name, Title = attrDef.Title
                    };
                    break;

                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Number:
                    attr = new EditableNumberAttribute {
                        Name = name, Title = attrDef.Title
                    };
                    break;

                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.CheckBox:
                    attr = new EditableCheckBoxAttribute {
                        Name = name, Title = attrDef.Title
                    };
                    break;

                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Url:
                    attr = new EditableUrlAttribute {
                        Name = name, Title = attrDef.Title
                    };
                    break;

                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Image:
                    attr = new EditableImageAttribute {
                        Name = name, Title = attrDef.Title
                    };
                    break;

#if TODO // use a better mechanism to find available types/attrs
                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Category:
                    attr = new EditableCategorySelectionAttribute("ID:" + name)
                    {
                        Name = name, Title = attrDef.Title
                    };
                    break;

                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Product:
                    attr = new EditableProductMultiSelectionAttribute("Id:" + name)
                    {
                        Name = name, Title = attrDef.Title
                    };
                    break;
#endif
                case PartDefinitionPage.AttributePart.AttributePartTypeEnum.Text:
                default:
                    attr = new EditableTextAttribute {
                        TextMode = TextBoxMode.SingleLine, Name = name, Title = attrDef.Title
                    };
                    break;
                    //throw new ArgumentOutOfRangeException();
                }
                if (!string.IsNullOrEmpty(attrDef.DefaultValue))
                {
                    attr.DefaultValue = attrDef.DefaultValue;
                }

                attr.HelpText = attrDef.HelpText;

                re.Add(attr);
            }

            re.IsDefined = true;
            re.Finalize();
            return(re);
        }