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; 
		}
Exemple #2
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);
        }