Beispiel #1
0
        //=== Initialization

        /// <summary> Inits a new field for the specified type. </summary>
        /// <param name="languageId"> This is needed for the calender field. </param>
        public static FormElement InitField(FormElementType Type, int?languageId = null, int?id = null, string label = null, string description = null, bool?required = null, bool applyBasicSettings = false)
        {
            switch (Type)
            {
            case Enums.FormElementType.Calendar:
                Calendar c = Calendar.Init(languageId: languageId, id: id, label: label, description: description, required: required);
                ;

                if (applyBasicSettings)
                {
                    c.AdvancedMode = false;
                    c.DefaultDate  = "*|DATETIME:NOW|*";
                }

                return(c);

            case Enums.FormElementType.Checkbox:
                Checkbox cb = Checkbox.Init(id: id, label: label, description: description);

                if (applyBasicSettings)
                {
                    cb.Min = required.GetValueOrDefault() ? 1 : 0;
                    cb.Max = 1;
                }

                return(cb);

            case Enums.FormElementType.Dropdown:
                Dropdown dd = Dropdown.Init(id: id, label: label, description: description, required: required);

                if (applyBasicSettings)
                {
                    dd.Multiple = false;
                }

                return(dd);

            //case Enums.FormElementType.FileUpload:
            //    return FileUpload.Init(id: id, label: label, description: description, required: required);

            case Enums.FormElementType.Html:
                HtmlElement html = HtmlElement.Init(id: id, label: label, description: description);

                if (applyBasicSettings)
                {
                    html.Editable      = true;
                    html.EditorProfile = HtmlElement.EEditorProfile.Basic;
                    html.Required      = required.GetValueOrDefault();
                }

                return(html);

            case Enums.FormElementType.Input:
                Input input = Input.Init(id: id, label: label, description: description, required: required);

                if (applyBasicSettings)
                {
                    input.MaxLength = 255;
                    input.MinLength = 0;
                }

                return(input);

            case Enums.FormElementType.Radiobutton:
                Radiobutton rb = Radiobutton.Init(id: id, label: label, description: description, required: required);

                //if (applyBasicSettings)
                //{
                //    None available
                //}

                return(rb);

            case Enums.FormElementType.Textarea:
                Textarea ta = Textarea.Init(id: id, label: label, description: description, required: required);

                //if (applyBasicSettings)
                //{
                //    None available
                //}

                return(ta);

            case Enums.FormElementType.Link:
                Link link = Link.Init(id: id, label: label, description: description, required: required);

                //if (applyBasicSettings)
                //{
                //    None available
                //}

                return(link);

            case Enums.FormElementType.Label:
                Label l = Label.Init(id: id, label: label, description: description);

                //if (applyBasicSettings)
                //{
                //    None available
                //}

                return(l);


            case Enums.FormElementType.List:
                ListElement list = ListElement.Init(id: id, label: label, description: description);

                //if (applyBasicSettings)
                //{
                //    None available
                //}

                return(list);

            default:
                throw new Exception("Init: Field type is not supported.");
                // Hidden, Tagging, etc.
            }
        }