private static DataFieldDescriptor CreateReferenceDataFieldDescriptor(DataTypeDescriptor targetDataTypeDescriptor, out string foreignKeyFieldName, string fieldName = null)
        {
            var targetType         = TypeManager.GetType(targetDataTypeDescriptor.TypeManagerTypeName);
            var targetKeyFieldName = targetDataTypeDescriptor.KeyPropertyNames.First();

            var targetKeyDataFieldDescriptor = targetDataTypeDescriptor.Fields[targetKeyFieldName];

            foreignKeyFieldName = fieldName ?? $"{targetDataTypeDescriptor.Name}{targetKeyFieldName}ForeignKey";

            var widgetFunctionProvider = StandardWidgetFunctions.GetDataReferenceWidget(targetType);

            return(new DataFieldDescriptor(Guid.NewGuid(), foreignKeyFieldName, targetKeyDataFieldDescriptor.StoreType, targetKeyDataFieldDescriptor.InstanceType)
            {
                IsNullable = targetKeyDataFieldDescriptor.IsNullable,
                DefaultValue = targetKeyDataFieldDescriptor.DefaultValue,
                ValidationFunctionMarkup = targetKeyDataFieldDescriptor.ValidationFunctionMarkup,
                ForeignKeyReferenceTypeName = targetDataTypeDescriptor.TypeManagerTypeName,
                FormRenderingProfile = new DataFieldFormRenderingProfile
                {
                    Label = foreignKeyFieldName,
                    HelpText = foreignKeyFieldName,
                    WidgetFunctionMarkup = widgetFunctionProvider.SerializedWidgetFunction.ToString(SaveOptions.DisableFormatting)
                }
            });
        }
        private string GetDefaultWidgetFunctionMarkup(DataFieldDescriptor fieldDescriptor)
        {
            // Auto generating a widget for not code generated data types
            Type fieldType;

            if (!fieldDescriptor.ForeignKeyReferenceTypeName.IsNullOrEmpty())
            {
                string referenceTypeName = fieldDescriptor.ForeignKeyReferenceTypeName;
                Type   foreignKeyType    = TypeManager.GetType(referenceTypeName);
                Verify.IsNotNull(foreignKeyType, "Failed to find type '{0}'".FormatWith(referenceTypeName));

                var referenceTemplateType = fieldDescriptor.IsNullable ? typeof(NullableDataReference <>) : typeof(DataReference <>);

                fieldType = referenceTemplateType.MakeGenericType(foreignKeyType);
            }
            else
            {
                fieldType = fieldDescriptor.InstanceType;
            }

            var widgetFunctionProvider = StandardWidgetFunctions.GetDefaultWidgetFunctionProviderByType(fieldType);

            if (widgetFunctionProvider != null)
            {
                return(widgetFunctionProvider.SerializedWidgetFunction.ToString());
            }

            return(null);
        }
        internal static IEnumerable <ParameterProfile> BuildInlineXhtmlEditorParameters()
        {
            // TODO: localize
            var templateSelectorWidget = StandardWidgetFunctions.DropDownList(
                typeof(VisualXhtmlEditorFuntion), StaticReflection.GetMethodInfo(() => PageTemplates()).Name, "Key", "Value", false, false);

            yield return(new ParameterProfile(PreviewTemplateIdParameterName,
                                              typeof(Guid), false,
                                              new ConstantValueProvider(Guid.Empty),
                                              templateSelectorWidget,
                                              null,
                                              "Page template for preview",
                                              new HelpDefinition("Page template to be used while generating preview images for the C1 functions calls.")));

            yield return(new ParameterProfile(PreviewPlaceholderParameterName,
                                              typeof(string), false,
                                              new ConstantValueProvider(null), StandardWidgetFunctions.TextBoxWidget, null,
                                              "Page placeholder for preview",
                                              new HelpDefinition("Page placeholder to be used while generating preview images for the C1 functions calls. If not specified, the default placeholder for the selected template will be used.")
                                              ));

            yield return(new ParameterProfile(PreviewPageIdParameterName,
                                              typeof(Guid), false,
                                              new ConstantValueProvider(Guid.Empty),
                                              StandardWidgetFunctions.GetDataReferenceWidget <IPage>(),
                                              null,
                                              "Page for preview",
                                              new HelpDefinition("Page template to be used while generating preview images. Certain fuctions may require page information for previewing.")));
        }
示例#4
0
        public MediaFileSelectorWidgetFunction(EntityTokenFactory entityTokenFactory)
            : base(CompositeName, typeof(NullableDataReference <IMediaFile>), entityTokenFactory)
        {
            var widget = new WidgetFunctionProvider(MediaFileFolderSelectorWidget.CompositeName);

            base.AddParameterProfile(
                new ParameterProfile("MediaFileFolderReference", typeof(DataReference <IMediaFileFolder>), false,
                                     new ConstantValueProvider(new DataReference <IMediaFileFolder>()), widget, new Dictionary <string, object>(),
                                     "Media Folder", new HelpDefinition("Select a media folder to choose files from. Default is all media files.")));

            base.AddParameterProfile(
                new ParameterProfile("FileExtensionFilter", typeof(string), false,
                                     new ConstantValueProvider(""), StandardWidgetFunctions.TextBoxWidget, null,
                                     "File Extension Filter", new HelpDefinition("Limit the list to files which have the specified extension. Default is no filter.")));

            base.AddParameterProfile(
                new ParameterProfile("IncludeSubfolders", typeof(bool), false,
                                     new ConstantValueProvider(true), StandardWidgetFunctions.GetBoolSelectorWidget("Include files from subfolders", "Only show files from the specified Media folder"), null,
                                     "Include Subfolders", new HelpDefinition("When false files from subfolders will no be included.")));

            var requiredWidget = StandardWidgetFunctions.GetBoolSelectorWidget("Yes, require selection", "No, optional");

            base.AddParameterProfile(
                new ParameterProfile(RequiredParameterName, typeof(bool), false,
                                     new ConstantValueProvider(true), requiredWidget, new Dictionary <string, object>(),
                                     "Selection required", new HelpDefinition("Specify if selecting a media file should be required."))
                );
        }
        public ImageSelectorWidgetFunction(EntityTokenFactory entityTokenFactory)
            : base(CompositeName, typeof(NullableDataReference <IImageFile>), entityTokenFactory)
        {
            var mediaFolderSelectorWidget = new WidgetFunctionProvider(MediaFileFolderSelectorWidget.CompositeName);

            base.AddParameterProfile(
                new ParameterProfile(MediaFileFolderReferenceParameterName,
                                     typeof(DataReference <IMediaFileFolder>),
                                     false,
                                     new ConstantValueProvider(new DataReference <IMediaFileFolder>()),
                                     mediaFolderSelectorWidget,
                                     new Dictionary <string, object>(),
                                     "Image folder",
                                     new HelpDefinition("Select a media folder to choose images from. Default is 'all media'."))
                );

            var requiredWidget = StandardWidgetFunctions.GetBoolSelectorWidget("Yes, require selection", "No, optional");

            base.AddParameterProfile(
                new ParameterProfile(RequiredParameterName,
                                     typeof(bool),
                                     false,
                                     new ConstantValueProvider(true),
                                     requiredWidget,
                                     new Dictionary <string, object>(),
                                     "Selection required",
                                     new HelpDefinition("Specify if selecting an image should be required."))
                );
        }
示例#6
0
        private void SetParameterProfiles()
        {
            base.AddParameterProfile(
                new ParameterProfile("Options",
                                     typeof(IEnumerable),
                                     true,
                                     new NoValueValueProvider(),
                                     null,
                                     null,
                                     "Options", new HelpDefinition("A list of elements to use as options. Expected types are IEnumerable (simple lists) and Dictionary.")));

            base.AddParameterProfile(
                new ParameterProfile("KeyFieldName",
                                     typeof(string),
                                     false,
                                     new ConstantValueProvider(null),
                                     StandardWidgetFunctions.TextBoxWidget,
                                     null,
                                     "Source key field name", new HelpDefinition("If your option source returns a list of objects or XElements, use this field to specify the name of the field (property) to use for key values. Leave this empty to use the source option value as a string.")));

            base.AddParameterProfile(
                new ParameterProfile("LabelFieldName",
                                     typeof(string),
                                     false,
                                     new ConstantValueProvider(null),
                                     StandardWidgetFunctions.TextBoxWidget,
                                     null,
                                     "Source label field name", new HelpDefinition("If your option source returns a list of objects or XElements, use this field to specify the name of the field (property) to use for labels. Leave this empty to use the source option value as a string.")));

            base.AddParameterProfile(
                new ParameterProfile("Required",
                                     typeof(bool),
                                     false,
                                     new ConstantValueProvider(true),
                                     StandardWidgetFunctions.GetBoolSelectorWidget("Yes, selection is required", "No, a 'none' selection is allowed."),
                                     null,
                                     "Selection required", new HelpDefinition("When true the user is forced to make a selection. This feature is not available when 'multiple selection' is enabled.")));

            base.AddParameterProfile(
                new ParameterProfile("Multiple",
                                     typeof(bool),
                                     false,
                                     new ConstantValueProvider(false),
                                     StandardWidgetFunctions.GetBoolSelectorWidget("Yes, allow multiple selections.", "No, allow only one selection."),
                                     null,
                                     "Multiple selection", new HelpDefinition("When true the user can select zero, one or more values. The selected values will be joined in a comma seperated string like 'A,B,C'.")));

            base.AddParameterProfile(
                new ParameterProfile("Compact",
                                     typeof(bool),
                                     false,
                                     new ConstantValueProvider(false),
                                     StandardWidgetFunctions.GetBoolSelectorWidget("Yes, use compact/popup UI.", "No, show all options."),
                                     null,
                                     "Compact mode", new HelpDefinition("When true the UI element will be compact.")));
        }
        private void SetParameterProfiles()
        {
            base.AddParameterProfile(
                new ParameterProfile("ElementProvider",
                                     typeof(string),
                                     true,
                                     new ConstantValueProvider(string.Empty),
                                     StandardWidgetFunctions.TextBoxWidget,
                                     null,
                                     "Element Provider", new HelpDefinition("The name of a tree element provider (as defined in Composite.config)")));

            base.AddParameterProfile(
                new ParameterProfile("SelectableElementReturnValue",
                                     typeof(string),
                                     true,
                                     new ConstantValueProvider("EntityToken"),
                                     StandardWidgetFunctions.TextBoxWidget,
                                     null,
                                     "Element field to return", new HelpDefinition("The name of the element field whose value to return for selection. Typical values here can be DataId (for data trees), Uri (for linkable elements), or EntityToken (for any element). Element providers may provide more fields.")));

            base.AddParameterProfile(
                new ParameterProfile("SelectableElementPropertyName",
                                     typeof(string),
                                     false,
                                     new ConstantValueProvider(string.Empty),
                                     StandardWidgetFunctions.TextBoxWidget,
                                     null,
                                     "Selection filter, Property Name", new HelpDefinition("An element must have this field to be selectable.")));

            base.AddParameterProfile(
                new ParameterProfile("SelectableElementPropertyValue",
                                     typeof(string),
                                     false,
                                     new ConstantValueProvider(string.Empty),
                                     StandardWidgetFunctions.TextBoxWidget,
                                     null,
                                     "Selection filter, Property Value", new HelpDefinition("The value of the property optionally used (if provided) to further identify a selectable tree element by. Seperate multiple values with spaces.")));

            base.AddParameterProfile(
                new ParameterProfile("SerializedSearchToken",
                                     typeof(string),
                                     false,
                                     new ConstantValueProvider(string.Empty),
                                     StandardWidgetFunctions.TextBoxWidget,
                                     null,
                                     "Search Token", new HelpDefinition("A search token, seriallized, to filter which tree elements is shown. To filter what is selectable, use the 'Selection filter' properties.")));
            base.AddParameterProfile(
                new ParameterProfile("Required",
                                     typeof(bool),
                                     false,
                                     new ConstantValueProvider(true),
                                     StandardWidgetFunctions.GetBoolSelectorWidget("Yes, selection is required", "No, a 'none' selection is allowed."),
                                     null,
                                     "Required", new HelpDefinition("An option that indicates whether the user is required to make a selection")));
        }
        public override XElement GetWidgetMarkup(ParameterList parameters, string label, HelpDefinition helpDefinition, string bindingSourceName)
        {
            BaseRuntimeTreeNode runtimeTreeNode;

            if (!parameters.TryGetParameterRuntimeTreeNode(Parameter_Options, out runtimeTreeNode))
            {
                throw new InvalidOperationException("Could not get BaseRuntimeTreeNode for parameter 'Options'.");
            }

            const string selectorName = "KeySelector";

            IEnumerable options           = runtimeTreeNode.GetValue <IEnumerable>();
            IDictionary dictionaryOptions = options as IDictionary;

            XElement treeNodeElement = runtimeTreeNode.Serialize().Elements().First();

            XElement functionMarkup = treeNodeElement;


            XElement selector = StandardWidgetFunctions.BuildBasicFormsMarkup(
                Namespaces.BindingFormsStdUiControls10,
                selectorName,
                "Selected",
                label,
                helpDefinition,
                bindingSourceName);

            if (dictionaryOptions != null)
            {
                selector.Add(new XAttribute("OptionsKeyField", "Key"));
                selector.Add(new XAttribute("OptionsLabelField", "Value"));
            }
            else
            {
                string keyFieldName = parameters.GetParameter <string>(Parameter_KeyFieldName);
                if (keyFieldName != null)
                {
                    selector.Add(new XAttribute("OptionsKeyField", keyFieldName));
                }

                string labelFieldName = parameters.GetParameter <string>(Parameter_LabelFieldName);
                if (labelFieldName != null)
                {
                    selector.Add(new XAttribute("OptionsLabelField", labelFieldName));
                }
            }

            bool required = parameters.GetParameter <bool>(Parameter_Required);

            selector.Add(new XAttribute("Required", required));

            selector.Add(new XElement(selector.Name.Namespace + (selectorName + ".Options"), functionMarkup));

            return(selector);
        }
        public TextBoxWidgetFuntion(EntityTokenFactory entityTokenFactory)
            : base(CompositeName, typeof(string), entityTokenFactory)
        {
            ParameterProfile spellCheckPP =
                new ParameterProfile(TextBoxWidgetFuntion.SpellCheckParameterName,
                                     typeof(bool), false,
                                     new ConstantValueProvider(true), StandardWidgetFunctions.GetBoolSelectorWidget("Allow spell checking", "Do not allow spell checking"), null,
                                     "Spell check", new HelpDefinition("By default text will be spell checked (when available). You should explicitly disable spell checking on fields that contain e-mails, code values etc. not suitable for spell checking. "));

            base.AddParameterProfile(spellCheckPP);
        }
示例#10
0
        private XElement BuildFormMarkUp(
            ParameterList parameters,
            string label,
            HelpDefinition helpDefinition,
            string bindingSourceName,
            Type optionsGeneratingStaticType,
            string optionsGeneratingStaticMethodName,
            object optionsGeneratingStaticMethodParameterValue,
            string optionsObjectKeyPropertyName,
            string optionsObjectLabelPropertyName,
            bool required)
        {
            if (!parameters.TryGetParameter(nameof(SitemapScope), out SitemapScope sitemapScope))
            {
                throw new ArgumentException(nameof(SitemapScope));
            }

            string
                keySelTag    = "KeySelector",
                statMethTag  = "StaticMethodCall",
                compFuncName = $"{Constants.SerializeFuncNamespace}.{Resources.default_text.SerializeMarkupParamsFuncName}";

            XNamespace
                uc = Namespaces.BindingFormsStdUiControls10,
                f  = Namespaces.BindingFormsStdFuncLib10,
                bf = Namespaces.BindingForms10,
                ft = Namespaces.Function10;

            XElement keySelector = StandardWidgetFunctions.BuildBasicFormsMarkup(uc, keySelTag, "Selected", label, helpDefinition, bindingSourceName);

            XElement keySelectorOptions = new XElement(uc + $"{keySelTag}.Options",
                                                       new XElement(f + statMethTag,
                                                                    new XAttribute("Type", TypeManager.SerializeType(optionsGeneratingStaticType)),
                                                                    new XAttribute("Method", optionsGeneratingStaticMethodName),
                                                                    new XElement(uc + $"{statMethTag}.Parameters",
                                                                                 new XElement(ft + "function",
                                                                                              new XAttribute("name", compFuncName),
                                                                                              new XElement(ft + "param",
                                                                                                           new XAttribute("name", Constants.TypeNameParamName),
                                                                                                           new XAttribute("value", optionsGeneratingStaticMethodParameterValue)),
                                                                                              new XElement(ft + "param", new XAttribute("name", Constants.PageIdParamName),
                                                                                                           new XElement(bf + "read", new XAttribute("source", "PageId"))),
                                                                                              new XElement(ft + "param",
                                                                                                           new XAttribute("name", Constants.SitemapScopeIdParamName),
                                                                                                           new XAttribute("value", (int)sitemapScope))))));

            keySelector.Add(
                new XAttribute("OptionsKeyField", optionsObjectKeyPropertyName),
                new XAttribute("OptionsLabelField", optionsObjectLabelPropertyName),
                new XAttribute("Required", required),
                keySelectorOptions);

            return(keySelector);
        }
示例#11
0
        private void SetParameterProfiles()
        {
            base.AddParameterProfile(
                new ParameterProfile("ElementProvider",
                                     typeof(string),
                                     true,
                                     new ConstantValueProvider(string.Empty),
                                     StandardWidgetFunctions.TextBoxWidget,
                                     null,
                                     "Element Provider", new HelpDefinition("The name of a tree element provider (as defined in Composite.config)")));

            base.AddParameterProfile(
                new ParameterProfile("SelectableElementPropertyName",
                                     typeof(string),
                                     true,
                                     new ConstantValueProvider(string.Empty),
                                     StandardWidgetFunctions.TextBoxWidget,
                                     null,
                                     "Selectable Element Property Name", new HelpDefinition("The name of a property used to identify a selectable tree element by")));

            base.AddParameterProfile(
                new ParameterProfile("SelectableElementPropertyValue",
                                     typeof(string),
                                     false,
                                     new ConstantValueProvider(string.Empty),
                                     StandardWidgetFunctions.TextBoxWidget,
                                     null,
                                     "Selectable Element Property Value", new HelpDefinition("The value of the property optionally used (if provided) to further identify a selectable tree element by")));

            base.AddParameterProfile(
                new ParameterProfile("SelectableElementReturnValue",
                                     typeof(string),
                                     false,
                                     new ConstantValueProvider(string.Empty),
                                     StandardWidgetFunctions.TextBoxWidget,
                                     null,
                                     "Selectable Element Return Value", new HelpDefinition("The value to return for the selected tree element")));
            base.AddParameterProfile(
                new ParameterProfile("SerializedSearchToken",
                                     typeof(string),
                                     false,
                                     new ConstantValueProvider(string.Empty),
                                     StandardWidgetFunctions.TextBoxWidget,
                                     null,
                                     "Selectable Element Return Value", new HelpDefinition("A search token to filter tree elements by")));
            base.AddParameterProfile(
                new ParameterProfile("Required",
                                     typeof(bool),
                                     false,
                                     new ConstantValueProvider(true),
                                     StandardWidgetFunctions.GetBoolSelectorWidget("Yes, selection is required", "No, a 'none' selection is allowed."),
                                     null,
                                     "Required", new HelpDefinition("An option that indicates whether the user is required to make a selection")));
        }
 public static WidgetFunctionProvider GetWidgetFunctionProvider(DataFieldDescriptor dataFieldDescriptor)
 {
     if ((dataFieldDescriptor.FormRenderingProfile != null) && (string.IsNullOrEmpty(dataFieldDescriptor.FormRenderingProfile.WidgetFunctionMarkup) == false))
     {
         WidgetFunctionProvider widgetFunctionProvider = new WidgetFunctionProvider(XElement.Parse(dataFieldDescriptor.FormRenderingProfile.WidgetFunctionMarkup));
         return(widgetFunctionProvider);
     }
     else
     {
         return(StandardWidgetFunctions.GetDefaultWidgetFunctionProviderByType(dataFieldDescriptor.InstanceType));
     }
 }
        public override XElement GetWidgetMarkup(ParameterList parameters, string label, HelpDefinition helpDefinition, string bindingSourceName)
        {
            string tagName = "TypeSelector";

            XElement   selector = StandardWidgetFunctions.BuildBasicFormsMarkup(Namespaces.BindingFormsStdUiControls10, tagName, "SelectedType", label, helpDefinition, bindingSourceName);
            XNamespace f        = Namespaces.BindingFormsStdFuncLib10;

            selector.Add(
                new XElement(selector.Name.Namespace + (tagName + ".TypeOptions"),
                             new XElement(f + "StaticMethodCall",
                                          new XAttribute("Type", TypeManager.SerializeType(this.GetType())),
                                          new XAttribute("Method", "GetOptions"))));

            return(selector);
        }
示例#14
0
        private void SetParameterProfiles()
        {
            WidgetFunctionProvider dropDown = StandardWidgetFunctions.DropDownList(GetType(), nameof(GetAssociationPageRestrictions), "Key", "Value", false, true);

            AddParameterProfile(
                new ParameterProfile(
                    typeof(SitemapScope).Name,
                    typeof(SitemapScope),
                    true,
                    new ConstantValueProvider(SitemapScope.Current),
                    dropDown,
                    null,
                    "Sitemap scope",
                    new HelpDefinition(Resources.default_text.SelectFilteredDataWidgetFuncSitescopeHelp)));
        }
示例#15
0
 /// <exclude />
 public override XElement GetWidgetMarkup(ParameterList parameters, string label, HelpDefinition helpDefinition, string bindingSourceName)
 {
     return(StandardWidgetFunctions.BuildStaticCallPopulatedSelectorFormsMarkup(
                parameters,
                label,
                helpDefinition,
                bindingSourceName,
                this.GetType(),
                "GetOptions",
                TypeManager.SerializeType(typeof(T)),
                "Key",
                "Label",
                false,
                true,
                false,
                false));
 }
 /// <exclude />
 public override XElement GetWidgetMarkup(ParameterList parameters, string label, HelpDefinition helpDefinition, string bindingSourceName)
 {
     return(StandardWidgetFunctions.BuildStaticCallPopulatedSelectorFormsMarkup(
                parameters: parameters,
                label: label,
                helpDefinition: helpDefinition,
                bindingSourceName: bindingSourceName,
                optionsGeneratingStaticType: typeof(HomePageSelectorWidgetFunction),
                optionsGeneratingStaticMethodName: nameof(GetHomePages),
                optionsGeneratingStaticMethodParameterValue: null,
                optionsObjectKeyPropertyName: "Key",
                optionsObjectLabelPropertyName: "Label",
                multiSelect: false,
                compactMode: true,
                required: true,
                bindToString: false));
 }
        private void ResetWidgetSelector()
        {
            string widgetFunctionMarkup = "";

            WidgetFunctionProvider widgetFunctionProvider = StandardWidgetFunctions.GetDefaultWidgetFunctionProviderByType(this.CurrentlySelectedWidgetReturnType);

            if (widgetFunctionProvider != null)
            {
                widgetFunctionMarkup = widgetFunctionProvider.SerializedWidgetFunction.ToString(SaveOptions.DisableFormatting);
            }

            btnWidgetFunctionMarkup.Value = widgetFunctionMarkup;

            if (widgetFunctionMarkup == "")
            {
                if (FunctionFacade.GetWidgetFunctionNamesByType(this.CurrentlySelectedWidgetReturnType).Any())
                {
                    Baloon(btnWidgetFunctionMarkup.ClientID, GetString("SpecifyWidgetTip"));
                }
            }
        }
        public MvcFunctionBuilder AddParameter(string name, Type type = null, bool?isRequired = null, BaseValueProvider defaultValueProvider = null, string label = null, string helpText = null, WidgetFunctionProvider widgetFunctionProvider = null, bool hideInSimpleView = false)
        {
            Verify.ArgumentNotNullOrEmpty(name, "name");

            var info          = _function.GetParameterInformation().FirstOrDefault(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase));
            var reflectedInfo = info != null?GetParameterDefaults(info) : null;


            if (type == null)
            {
                Verify.IsNotNull(reflectedInfo, "Failed to find the type of the parameter '{0}' through reflection", name);

                type = reflectedInfo.Type;
            }

            if (label == null)
            {
                label = name;
            }

            if (helpText == null)
            {
                helpText = String.Empty;
            }

            bool isRequired2 = isRequired ?? reflectedInfo?.IsRequired ?? false;

            if (defaultValueProvider == null)
            {
                defaultValueProvider = reflectedInfo != null
                    ? (BaseValueProvider) new ConstantValueProvider(reflectedInfo.DefaultValue)
                    : new NoValueValueProvider();
            }

            widgetFunctionProvider = widgetFunctionProvider ?? StandardWidgetFunctions.GetDefaultWidgetFunctionProviderByType(type, isRequired2);

            _function.AddParameter(new ParameterProfile(name, type, isRequired2, defaultValueProvider, widgetFunctionProvider,
                                                        label, new HelpDefinition(helpText), hideInSimpleView));
            return(this);
        }
示例#19
0
        private void SetParameterProfiles()
        {
            base.AddParameterProfile(
                new ParameterProfile("TreeNodes",
                                     typeof(IEnumerable <SelectionTreeNode>),
                                     true,
                                     new NoValueValueProvider(),
                                     null,
                                     null,
                                     "Tree Nodes", new HelpDefinition("The structure to use for building hierarchy for selection. Call a function that return IEnumerable<SelectionTreeNode>.")));

            base.AddParameterProfile(
                new ParameterProfile("Required",
                                     typeof(bool),
                                     false,
                                     new ConstantValueProvider(true),
                                     StandardWidgetFunctions.GetBoolSelectorWidget("Yes, selection is required", "No, a 'none' selection is allowed."),
                                     null,
                                     "Selection required", new HelpDefinition("When true the user is forced to make a selection. This feature is not available when 'multiple selection' is enabled.")));

            base.AddParameterProfile(
                new ParameterProfile("AutoSelectChildren",
                                     typeof(bool),
                                     false,
                                     new ConstantValueProvider(false),
                                     StandardWidgetFunctions.GetBoolSelectorWidget("Yes, auto select child elements.", "No, only one selection on click."),
                                     null,
                                     "Auto select children", new HelpDefinition("When true a selection will automatically select all descendant elements in the hierarchy.")));

            base.AddParameterProfile(
                new ParameterProfile("AutoSelectParents",
                                     typeof(bool),
                                     false,
                                     new ConstantValueProvider(false),
                                     StandardWidgetFunctions.GetBoolSelectorWidget("Yes, auto select parents.", "No, only one selection on click."),
                                     null,
                                     "Auto select parents", new HelpDefinition("When true a selection will automatically select all ancestor elements in the hierarchy.")));
        }
示例#20
0
        public override XElement GetWidgetMarkup(ParameterList parameters, string label, HelpDefinition helpDefinition, string bindingSourceName)
        {
            BaseRuntimeTreeNode runtimeTreeNode = null;

            if (parameters.TryGetParameterRuntimeTreeNode("Options", out runtimeTreeNode))
            {
                string keyFieldName   = parameters.GetParameter <string>("KeyFieldName");
                string labelFieldName = parameters.GetParameter <string>("LabelFieldName");
                bool   multiple       = parameters.GetParameter <bool>("Multiple");
                bool   required       = parameters.GetParameter <bool>("Required");
                bool   compact        = parameters.GetParameter <bool>("Compact");

                XElement optionsDescriptor = new XElement("SelectorOptionsSource",
                                                          new XAttribute("KeyFieldName", parameters.GetParameter <string>("KeyFieldName") ?? ""),
                                                          new XAttribute("LabelFieldName", parameters.GetParameter <string>("LabelFieldName") ?? ""),
                                                          new XElement("TreeNode",
                                                                       runtimeTreeNode.Serialize()));

                return(StandardWidgetFunctions.BuildStaticCallPopulatedSelectorFormsMarkup(
                           parameters,
                           label,
                           helpDefinition,
                           bindingSourceName,
                           this.GetType(),
                           "GetOptions",
                           optionsDescriptor.ToString(),
                           "Key",
                           "Label",
                           multiple,
                           compact,
                           required,
                           true));
            }
            else
            {
                throw new InvalidOperationException("Could not get BaseRuntimeTreeNode for parameter 'Options'.");
            }
        }
        private void SetParameterProfiles()
        {
            base.AddParameterProfile(
                new ParameterProfile(Parameter_Options,
                                     typeof(IEnumerable),
                                     true,
                                     new NoValueValueProvider(),
                                     null,
                                     null,
                                     "Options", new HelpDefinition("A list of elements to use as options. Expected types are IEnumerable (simple lists) and Dictionary.")));

            base.AddParameterProfile(
                new ParameterProfile(Parameter_KeyFieldName,
                                     typeof(string),
                                     false,
                                     new ConstantValueProvider(null),
                                     StandardWidgetFunctions.TextBoxWidget,
                                     null,
                                     "Source key field name", new HelpDefinition("If your option source returns a list of objects or XElements, use this field to specify the name of the field (property) to use for key values. Leave this empty to use the source option value as a string.")));

            base.AddParameterProfile(
                new ParameterProfile(Parameter_LabelFieldName,
                                     typeof(string),
                                     false,
                                     new ConstantValueProvider(null),
                                     StandardWidgetFunctions.TextBoxWidget,
                                     null,
                                     "Source label field name", new HelpDefinition("If your option source returns a list of objects or XElements, use this field to specify the name of the field (property) to use for labels. Leave this empty to use the source option value as a string.")));

            base.AddParameterProfile(
                new ParameterProfile("Required",
                                     typeof(bool),
                                     false,
                                     new ConstantValueProvider(true),
                                     StandardWidgetFunctions.GetBoolSelectorWidget("Yes, selection is required", "No, a 'none' selection is allowed."),
                                     null,
                                     "Selection required", new HelpDefinition("When true the user is forced to make a selection. This feature is not available when 'multiple selection' is enabled.")));
        }
        internal static ParameterProfile BuildParameterProfile(string name, Type type, FunctionParameterAttribute attribute, Type controllerType)
        {
            BaseValueProvider defaultValueProvider = new NoValueValueProvider();
            string            label    = name;
            string            helpText = String.Empty;

            if (!attribute.Label.IsNullOrEmpty())
            {
                label = attribute.Label;
            }

            if (!attribute.Help.IsNullOrEmpty())
            {
                helpText = attribute.Help;
            }

            bool isRequired = !attribute.HasDefaultValue;

            if (!isRequired)
            {
                defaultValueProvider = new ConstantValueProvider(attribute.DefaultValue);
            }

            WidgetFunctionProvider widgetProvider = attribute.GetWidgetFunctionProvider(controllerType, null);

            bool hideInSimpleView = attribute.HideInSimpleView;

            if (widgetProvider == null)
            {
                widgetProvider = StandardWidgetFunctions.GetDefaultWidgetFunctionProviderByType(type, isRequired);
            }

            return(new ParameterProfile(name, type, isRequired, defaultValueProvider, widgetProvider, label,
                                        new HelpDefinition(helpText),
                                        hideInSimpleView));
        }
 /// <exclude />
 protected XElement BuildBasicWidgetMarkup(string uiControlName, string bindingPropertyName, string label, HelpDefinition help, string bindingSourceName)
 {
     return(StandardWidgetFunctions.BuildBasicFormsMarkup(Namespaces.BindingFormsStdUiControls10, uiControlName, bindingPropertyName, label, help, bindingSourceName));
 }
示例#24
0
        private void GenerateForm()
        {
            var fieldNameToBindingNameMapper = new Dictionary <string, string>();

            _bindingsXml = new XElement(CmsBindingsElementTemplate);
            var layout = new XElement(CmsLayoutElementTemplate);

            if (!string.IsNullOrEmpty(LayoutIconHandle))
            {
                layout.Add(new XAttribute("iconhandle", LayoutIconHandle));
            }

            // Add a read binding as the layout label
            if (!string.IsNullOrEmpty(LayoutLabel))
            {
                var labelAttribute = new XAttribute("label", LayoutLabel);
                layout.Add(labelAttribute);
            }
            else if (!string.IsNullOrEmpty(_dataTypeDescriptor.LabelFieldName))
            {
                layout.Add((new XElement(CmsNamespace + "layout.label", new XElement(CmsNamespace + "read", new XAttribute("source", _dataTypeDescriptor.LabelFieldName)))));
            }


            _panelXml = new XElement(MainNamespace + "FieldGroup");

            string formLabel = !string.IsNullOrEmpty(FieldGroupLabel) ? FieldGroupLabel : _dataTypeDescriptor.Title;

            if (!string.IsNullOrEmpty(formLabel))
            {
                _panelXml.Add(new XAttribute("Label", formLabel));
            }

            layout.Add(_panelXml);

            foreach (var fieldDescriptor in _dataTypeDescriptor.Fields)
            {
                var bindingType = GetFieldBindingType(fieldDescriptor);
                var bindingName = GetBindingName(fieldDescriptor);

                fieldNameToBindingNameMapper.Add(fieldDescriptor.Name, bindingName);

                var binding = new XElement(CmsNamespace + FormKeyTagNames.Binding,
                                           new XAttribute("name", bindingName),
                                           new XAttribute("type", bindingType));

                if (fieldDescriptor.IsNullable)
                {
                    binding.Add(new XAttribute("optional", "true"));
                }

                _bindingsXml.Add(binding);

                if (!_readOnlyFields.Contains(fieldDescriptor.Name))
                {
                    XElement widgetFunctionMarkup;
                    var      label = fieldDescriptor.FormRenderingProfile.Label;
                    if (label.IsNullOrEmpty())
                    {
                        label = fieldDescriptor.Name;
                    }

                    var helptext = fieldDescriptor.FormRenderingProfile.HelpText ?? "";

                    if (!string.IsNullOrEmpty(fieldDescriptor.FormRenderingProfile.WidgetFunctionMarkup))
                    {
                        widgetFunctionMarkup = XElement.Parse(fieldDescriptor.FormRenderingProfile.WidgetFunctionMarkup);
                    }
                    else if (!DataTypeDescriptor.IsCodeGenerated && fieldDescriptor.FormRenderingProfile.WidgetFunctionMarkup == null)
                    {
                        // Auto generating a widget for not code generated data types
                        Type fieldType;

                        if (!fieldDescriptor.ForeignKeyReferenceTypeName.IsNullOrEmpty())
                        {
                            Type foreignKeyType;

                            try
                            {
                                foreignKeyType = Type.GetType(fieldDescriptor.ForeignKeyReferenceTypeName, true);
                            }
                            catch (Exception ex)
                            {
                                throw new InvalidOperationException("Failed to get referenced foreign key type '{0}'".FormatWith(fieldDescriptor.ForeignKeyReferenceTypeName), ex);
                            }

                            var referenceTemplateType = fieldDescriptor.IsNullable ? typeof(NullableDataReference <>) : typeof(DataReference <>);

                            fieldType = referenceTemplateType.MakeGenericType(foreignKeyType);
                        }
                        else
                        {
                            fieldType = fieldDescriptor.InstanceType;
                        }

                        var widgetFunctionProvider = StandardWidgetFunctions.GetDefaultWidgetFunctionProviderByType(fieldType);
                        if (widgetFunctionProvider != null)
                        {
                            widgetFunctionMarkup = widgetFunctionProvider.SerializedWidgetFunction;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }

                    var widgetRuntimeTreeNode = (WidgetFunctionRuntimeTreeNode)FunctionTreeBuilder.Build(widgetFunctionMarkup);
                    widgetRuntimeTreeNode.Label             = label;
                    widgetRuntimeTreeNode.HelpDefinition    = new HelpDefinition(helptext);
                    widgetRuntimeTreeNode.BindingSourceName = bindingName;

                    var element = (XElement)widgetRuntimeTreeNode.GetValue();
                    _panelXml.Add(element);
                }
            }

            if (_showPublicationStatusSelector && _dataTypeDescriptor.SuperInterfaces.Contains(typeof(IPublishControlled)))
            {
                var placeholder = new XElement(MainNamespace + "PlaceHolder");
                _panelXml.Remove();

                placeholder.Add(_panelXml);
                layout.Add(placeholder);

                var publishFieldsXml = new XElement(MainNamespace + "FieldGroup", new XAttribute("Label", Texts.PublicationSettings_FieldGroupLabel));
                placeholder.Add(publishFieldsXml);

                var publicationStatusOptionsBinding = new XElement(CmsNamespace + FormKeyTagNames.Binding,
                                                                   new XAttribute("name", PublicationStatusOptionsBindingName),
                                                                   new XAttribute("type", typeof(object)));

                _bindingsXml.Add(publicationStatusOptionsBinding);

                var element =
                    new XElement(MainNamespace + "KeySelector",
                                 new XAttribute("OptionsKeyField", "Key"),
                                 new XAttribute("OptionsLabelField", "Value"),
                                 new XAttribute("Label", Texts.PublicationStatus_Label),
                                 new XAttribute("Help", Texts.PublicationStatus_Help),
                                 new XElement(MainNamespace + "KeySelector.Selected",
                                              new XElement(CmsNamespace + "bind", new XAttribute("source", PublicationStatusBindingName))),
                                 new XElement(MainNamespace + "KeySelector.Options",
                                              new XElement(CmsNamespace + "read", new XAttribute("source", PublicationStatusOptionsBindingName)))
                                 );


                publishFieldsXml.Add(element);


                var publishDateBinding = new XElement(CmsNamespace + FormKeyTagNames.Binding,
                                                      new XAttribute("name", "PublishDate"),
                                                      new XAttribute("type", typeof(DateTime)),
                                                      new XAttribute("optional", "true"));

                _bindingsXml.Add(publishDateBinding);

                publishFieldsXml.Add(
                    new XElement(MainNamespace + "DateTimeSelector",
                                 new XAttribute("Label", Texts.PublishDate_Label),
                                 new XAttribute("Help", Texts.PublishDate_Help),
                                 new XElement(CmsNamespace + "bind",
                                              new XAttribute("source", "PublishDate"))));

                var unpublishDateBinding = new XElement(CmsNamespace + FormKeyTagNames.Binding,
                                                        new XAttribute("name", "UnpublishDate"),
                                                        new XAttribute("type", typeof(DateTime)),
                                                        new XAttribute("optional", "true"));

                _bindingsXml.Add(unpublishDateBinding);

                publishFieldsXml.Add(
                    new XElement(MainNamespace + "DateTimeSelector",
                                 new XAttribute("Label", Texts.UnpublishDate_Label),
                                 new XAttribute("Help", Texts.UnpublishDate_Help),
                                 new XElement(CmsNamespace + "bind",
                                              new XAttribute("source", "UnpublishDate"))));
            }

            var formDefinition = new XElement(CmsFormElementTemplate);

            formDefinition.Add(_bindingsXml);
            formDefinition.Add(layout);

            if (CustomFormDefinition == null)
            {
                _generatedForm = formDefinition.ToString();
            }
            else
            {
                if (_dataTypeDescriptor.SuperInterfaces.Contains(typeof(IPublishControlled)))
                {
                    fieldNameToBindingNameMapper.Add("PublishDate", "PublishDate");
                    fieldNameToBindingNameMapper.Add("UnpublishDate", "UnpublishDate");
                }

                Func <XElement, IEnumerable <XAttribute> > getBindingsFunc =
                    doc => doc.Descendants(CmsNamespace + "binding").Attributes("name")
                    .Concat(doc.Descendants(CmsNamespace + "bind").Attributes("source"))
                    .Concat(doc.Descendants(CmsNamespace + "read").Attributes("source"));

                // Validation
                foreach (var bindingNameAttribute in getBindingsFunc(CustomFormDefinition.Root))
                {
                    var bindingName = bindingNameAttribute.Value;

                    if (!IsNotFieldBinding(bindingName) && !fieldNameToBindingNameMapper.ContainsKey(bindingName))
                    {
                        throw new ParseDefinitionFileException("Invalid binding name '{0}'".FormatWith(bindingName), bindingNameAttribute);
                    }
                }

                var formDefinitionElement = new XElement(CustomFormDefinition.Root);

                foreach (var bindingNameAttribute in getBindingsFunc(formDefinitionElement).Where(attr => !IsNotFieldBinding(attr.Value)))
                {
                    bindingNameAttribute.Value = fieldNameToBindingNameMapper[bindingNameAttribute.Value];
                }

                if (!string.IsNullOrEmpty(FieldGroupLabel))
                {
                    foreach (var fieldGroupElement in formDefinitionElement.Descendants(MainNamespace + "FieldGroup"))
                    {
                        if (fieldGroupElement.Attribute("Label") == null)
                        {
                            fieldGroupElement.Add(new XAttribute("Label", FieldGroupLabel));
                        }
                    }
                }

                _generatedForm = formDefinitionElement.ToString();
                _panelXml      = formDefinitionElement.Elements().Last().Elements().LastOrDefault();
            }
        }
        private IList <ParameterProfile> InitializeParamteres()
        {
            ParameterInfo[] parameterInfos = this.MethodInfo.GetParameters();

            var defaultValues   = new Dictionary <string, object>();
            var labels          = new Dictionary <string, string>();
            var helpTexts       = new Dictionary <string, string>();
            var widgetProviders = new Dictionary <string, WidgetFunctionProvider>();
            var parametersToHideInSimpleView = new HashSet <string>();

            foreach (object obj in this.MethodInfo.GetCustomAttributes(typeof(MethodBasedDefaultValueAttribute), true))
            {
                MethodBasedDefaultValueAttribute attribute = (MethodBasedDefaultValueAttribute)obj;
                defaultValues.Add(attribute.ParameterName, attribute.DefaultValue);
            }

            // Run through obsolete FunctionParameterDescriptionAttribute
#pragma warning disable 612,618
            foreach (
                object obj in this.MethodInfo.GetCustomAttributes(typeof(FunctionParameterDescriptionAttribute), true))
            {
                FunctionParameterDescriptionAttribute attribute = (FunctionParameterDescriptionAttribute)obj;
                if (attribute.HasDefaultValue && !defaultValues.ContainsKey(attribute.ParameterName))
                {
                    defaultValues.Add(attribute.ParameterName, attribute.DefaultValue);
                }

                labels.Add(attribute.ParameterName, attribute.ParameterLabel);
                helpTexts.Add(attribute.ParameterName, attribute.ParameterHelpText);
            }
#pragma warning restore 612,618

            // Run trhough new and improved FunctionParameterAttribute. Many may exist for one parameter.
            foreach (object obj in this.MethodInfo.GetCustomAttributes(typeof(FunctionParameterAttribute), true))
            {
                var attribute = (FunctionParameterAttribute)obj;

                Verify.That(attribute.HasName,
                            "All [FunctionParameter(...)] definitions on the method '{0}' must have 'Name' specified.",
                            this.MethodInfo.Name);

                string parameterName = attribute.Name;

                if (attribute.HasDefaultValue && !defaultValues.ContainsKey(parameterName))
                {
                    defaultValues.Add(parameterName, attribute.DefaultValue);
                }

                if (attribute.HasLabel && !labels.ContainsKey(parameterName))
                {
                    labels.Add(parameterName, attribute.Label);
                }

                if (attribute.HasHelp && !helpTexts.ContainsKey(parameterName))
                {
                    helpTexts.Add(parameterName, attribute.Help);
                }

                if (attribute.HasWidgetMarkup && !widgetProviders.ContainsKey(parameterName))
                {
                    try
                    {
                        var widgetFunctionProvider = attribute.GetWidgetFunctionProvider(null, null);
                        widgetProviders.Add(parameterName, widgetFunctionProvider);
                    }
                    catch (Exception ex)
                    {
                        string errText = "Failed to set Widget Markup for parameter '{0}' on method '{1}'. {2}"
                                         .FormatWith(parameterName, this.MethodInfo.Name, ex.Message);
                        throw new InvalidOperationException(errText);
                    }
                }

                if (attribute.HideInSimpleView)
                {
                    parametersToHideInSimpleView.Add(parameterName);
                }
            }

            var result = new List <ParameterProfile>();

            foreach (ParameterInfo parameterInfo in parameterInfos)
            {
                string parameterName = parameterInfo.Name;

                BaseValueProvider valueProvider;
                object            defaultValue = null;
                if (defaultValues.TryGetValue(parameterName, out defaultValue))
                {
                    valueProvider = new ConstantValueProvider(defaultValue);
                }
                else
                {
                    valueProvider = new NoValueValueProvider();
                }

                bool isRequired = !defaultValues.ContainsKey(parameterName);

                string parameterLabel = parameterInfo.Name;
                if (labels.ContainsKey(parameterName))
                {
                    parameterLabel = labels[parameterName];
                }

                string parameterHelpText = "";
                if (helpTexts.ContainsKey(parameterName))
                {
                    parameterHelpText = helpTexts[parameterName];
                }

                WidgetFunctionProvider widgetFunctionProvider =
                    (widgetProviders.ContainsKey(parameterName)
                         ? widgetProviders[parameterName]
                         : StandardWidgetFunctions.GetDefaultWidgetFunctionProviderByType(parameterInfo.ParameterType));

                bool hideInSimpleView = parametersToHideInSimpleView.Contains(parameterName);

                result.Add(new ParameterProfile(parameterName, parameterInfo.ParameterType, isRequired,
                                                valueProvider, widgetFunctionProvider, parameterLabel,
                                                new HelpDefinition(parameterHelpText),
                                                hideInSimpleView));
            }

            return(result);
        }