Exemplo n.º 1
0
        public static BsSelectList <T> AllAsp <T>()
        {
            var list = new BsSelectList <T>();

            list.Items.Add(new BsSelectListItem()
            {
                Text = "MVC", Value = "1"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Razor", Value = "2"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Web Forms", Value = "3"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "SignalR", Value = "4"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Web Api", Value = "5"
            });

            return(list);
        }
Exemplo n.º 2
0
        public DefaultcontrolProperties()
        {
            Width = BsSelectList <ColumnWidth> .FromEnum(typeof(ColumnWidth));

            GlyphiconAddon = new BsSelectList <Glyphicon?>();

            var glyphiconList = new BsSelectList <Glyphicon>();

            glyphiconList.Items = Enum.GetValues(typeof(Glyphicon)).Cast <Glyphicon>()
                                  .Where(x => x != Glyphicon.Custom)
                                  .Select(x => new BsSelectListItem
            {
                Text  = x.ToString(),
                Value = x.GetDescription()
            }).ToList();

            GlyphiconAddon.Items = glyphiconList.Items;

            GlyphiconAddon.Items.Insert(0, new BsSelectListItem
            {
                Text  = "None",
                Value = String.Empty
            });

            Required = BsSelectList <YesNoValues> .FromEnum(typeof(YesNoValues));

            Width.SelectedValues    = ColumnWidth.Large;
            Required.SelectedValues = YesNoValues.No;
        }
Exemplo n.º 3
0
        public static BsSelectList <T> AllIde <T>()
        {
            var list = new BsSelectList <T>();

            list.Items.Add(new BsSelectListItem()
            {
                Text = "Visual Studio", Value = "Visual Studio"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "IntelliJ IDEA", Value = "IntelliJ IDEA"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Eclipse", Value = "Eclipse"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Xcode", Value = "Xcode"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "MonoDevelop", Value = "MonoDevelop"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "NetBeans", Value = "NetBeans"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Anjuta", Value = "Anjuta"
            });

            return(list);
        }
Exemplo n.º 4
0
        public static BsSelectList <T> AllJavascriptFrameworks <T>()
        {
            var list = new BsSelectList <T>();

            list.Items.Add(new BsSelectListItem()
            {
                Text = "Backbone.js", Value = "1"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "AngularJS", Value = "2"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Ember.js", Value = "3"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Knockout", Value = "4"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "CanJS", Value = "5"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "ExtJS", Value = "6"
            });

            return(list);
        }
Exemplo n.º 5
0
        public static BsSelectList <T> AllWebBrowsers <T>()
        {
            var list = new BsSelectList <T>();

            list.Items.Add(new BsSelectListItem()
            {
                Text = "Chrome", Value = "1", IsButton = true
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Firefox", Value = "2", IsButton = true
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Internet Explorer", Value = "3"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Safari", Value = "4"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Opera", Value = "5"
            });

            return(list);
        }
Exemplo n.º 6
0
        public static BsSelectList <T> AllTech <T>()
        {
            var list = new BsSelectList <T>();

            list.Items.Add(new BsSelectListItem()
            {
                Text = "IIS", Value = "1", GroupKey = "server", GroupName = "Windows"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "SQL Server", Value = "2", GroupKey = "server", GroupName = "Windows"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Azure", Value = "3", GroupKey = "server", GroupName = "Windows"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Apache", Value = "4", GroupKey = "client", GroupName = "Linux"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "SOLR", Value = "5", GroupKey = "client", GroupName = "Linux"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Lucene", Value = "6", GroupKey = "client", GroupName = "Linux"
            });

            return(list);
        }
Exemplo n.º 7
0
        public ContributorNewModel() : base()
        {
            IsEnabled = new BsSelectList <YesNoValueTypes?>();
            IsEnabled.ItemsFromEnum(typeof(YesNoValueTypes), YesNoValueTypes.Both);
            IsEnabled.SelectedValues = YesNoValueTypes.Yes;

            RoleList = new BsSelectList <ProjectRole?>();
            RoleList.ItemsFromEnum(typeof(ProjectRole));
            RoleList.SelectedValues = ProjectRole.Developer;
        }
Exemplo n.º 8
0
        public UserProfileEditableModel GetEditableUserProfile(long objId, PanelComponentsEnum componentId)
        {
            var model  = db.Users.FirstOrDefault(x => x.Id == objId);
            var result = new UserProfileEditableModel
            {
                Id      = model.Id,
                Contact = new UserProfileContactEditableModel
                {
                    Email = model.Email
                }
            };

            if (componentId == PanelComponentsEnum.Contact)
            {
                var profile = model.UsersProfiles.FirstOrDefault();
                if (profile != null && profile.Address != null)
                {
                    result.Contact.PhoneNumber     = profile.PhoneNumber;
                    result.Contact.PhysicalAddress = profile.Address.PhysicalAddress;
                }
            }
            else if (componentId == PanelComponentsEnum.UserInfo)
            {
                var profile = model.UsersProfiles.FirstOrDefault();
                if (profile != null)
                {
                    var states = new BsSelectList <int?>
                    {
                        Items = db.UsersStates.Select(x => new BsSelectListItem
                        {
                            Text  = x.Code,
                            Value = x.Id.ToString()
                        }).ToList(),
                        SelectedValues = profile.Id_State
                    };

                    result.UserInfo = new UserProfileInfoEditableModel
                    {
                        Firstname = model.Firstname,
                        Lastname  = model.Lastname,
                        BirthDay  = new BsDateTime
                        {
                            DateValue = profile.Birthday
                        },
                        Profession    = profile.Profession,
                        StateDropdown = states
                    };
                }
            }

            return(result);
        }
Exemplo n.º 9
0
        private RegisterModel InitRegisterModel()
        {
            var listWithSelected = Lists.AllAsp <List <int> >();

            listWithSelected.SelectedValues = new List <int> {
                1, 2
            };

            var enumWithSelected = BsSelectList <NotificationType?> .FromEnum(typeof(NotificationType));

            enumWithSelected.SelectedValues = NotificationType.Monthly;

            var ddlWithSelected = Lists.AllCounties <string>();

            ddlWithSelected.SelectedValues = "ROU";

            var ideListWithSelected = Lists.AllIde <string>();

            ideListWithSelected.SelectedValues = "Visual Studio";

            var langListWithSelected = Lists.AllLanguages <List <string> >();

            langListWithSelected.SelectedValues = new List <string> {
                "C#"
            };

            var from = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 10, 30, 0);
            var to   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.AddDays(12).Day, 20, 00, 0);

            return(new RegisterModel()
            {
                CountriesList = ddlWithSelected,
                NotificationList = enumWithSelected,
                TechnologiesList = Lists.AllTech <List <int> >(),
                TechnologiesCheckboxList = listWithSelected,
                LanguagesList = langListWithSelected,
                IdeList = ideListWithSelected,
                GenderList = Lists.AllGenders <int>().ToSelectList().ToList(),
                Birthday = new BsDateTime(),
                Interval = new BsRange <DateTime>
                {
                    From = new BsRangeItem <DateTime>
                    {
                        ItemValue = DateTime.Now
                    },
                    To = new BsRangeItem <DateTime>
                    {
                        ItemValue = DateTime.Now.AddDays(12)
                    }
                }
            });
        }
Exemplo n.º 10
0
        public InputControlModel() :
            base(FormBuilderControlType.Textbox)
        {
            Properties = new InputControlProperties
            {
                Type = BsSelectList <FormBuilderInputType> .FromEnum(typeof(FormBuilderInputType))
            };

            DefaultProperties = new DefaultcontrolProperties
            {
                Width = BsSelectList <ColumnWidth> .FromEnum(typeof(ColumnWidth))
            };
        }
Exemplo n.º 11
0
        public static BsSelectList <T> AllGenders <T>()
        {
            var list = new BsSelectList <T>();

            list.Items.Add(new BsSelectListItem()
            {
                Text = "Male", Value = "1"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Female", Value = "2"
            });

            return(list);
        }
Exemplo n.º 12
0
        public string RenderRadioButtonList <TFormModel>(FormControlPropertyMetadata propertyMetadata, TFormModel formModel, object value = null)
        {
            var controlValue = value ?? propertyMetadata.PropertyInfo.GetValue(formModel);

            var bsSelectlistItems = controlValue.GetType().GetProperty("Items").GetValue(controlValue, null) as List <BsSelectListItem>;

            var selectedValues = controlValue.GetType().GetProperty("SelectedValues").GetValue(controlValue, null) as string;

            var bsSelectList = new BsSelectList <string>
            {
                Items          = bsSelectlistItems,
                SelectedValues = selectedValues
            };

            return(_helper.BsRadioList <string>(bsSelectList, propertyMetadata.BsControlAttribute.ControlType, propertyMetadata.PropertyInfo.Name, null, false).ToString());
        }
Exemplo n.º 13
0
        public SelectControlBaseProperties()
        {
            Items = new BsSelectList <List <string> >();

            //Items.Items.Add(new BsSelectListItem
            //{
            //    Text = "A",
            //    Value = "A"
            //});

            //Items.Items.Add(new BsSelectListItem
            //{
            //    Text = "B",
            //    Value = "B"
            //});

            //Items.SelectedValues = Items.Items.Select(x => x.Value).ToList();
        }
Exemplo n.º 14
0
 public UserSearchModel()
 {
     AgeRange = new BsRange <int?>
     {
         From = new BsRangeItem <int?>
         {
             ItemValue = 1,
             MinValue  = 1,
             TextValue = "1"
         },
         To = new BsRangeItem <int?>
         {
             ItemValue = 2,
             MaxValue  = 120,
             TextValue = "2",
         },
         TextValue = Resource.Choose
     };
     CitizenshipDropdown = new BsSelectList <int?>();
 }
Exemplo n.º 15
0
        public static BsSelectList <T> AllCountries <T>(bool isoKey = true)
        {
            var countryList = new SortedDictionary <string, string>();

            // Iterate the Framework Cultures...
            foreach (var ci in CultureInfo.GetCultures(CultureTypes.FrameworkCultures))
            {
                RegionInfo ri = null;
                try
                {
                    ri = new RegionInfo(ci.Name);
                }
                catch
                {
                    // If a RegionInfo object could not be created we don't want to use the CultureInfo
                    //    for the country list.
                    continue;
                }
                // Create new country dictionary entry.
                var newKeyValuePair = new KeyValuePair <string, string>(ri.EnglishName, isoKey ? ri.TwoLetterISORegionName : ri.EnglishName);

                // If the country is not alreayd in the countryList add it...
                if (!(countryList.ContainsKey(ri.EnglishName)))
                {
                    countryList.Add(newKeyValuePair.Key, newKeyValuePair.Value);
                }
            }

            var list = new BsSelectList <T>();

            foreach (var item in countryList)
            {
                list.Items.Add(new BsSelectListItem()
                {
                    Text = item.Key, Value = item.Value
                });
            }

            return(list);
        }
Exemplo n.º 16
0
        public static BsSelectList <T> AllNotificationTypes <T>()
        {
            var list = new BsSelectList <T>();

            list.Items.Add(new BsSelectListItem()
            {
                Text = "Never", Value = "1"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Daily", Value = "2"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Weekly", Value = "3"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Monthly", Value = "4"
            });


            return(list);
        }
Exemplo n.º 17
0
        private static MvcHtmlString BsRadioListInternal <TKey>(this HtmlHelper htmlHelper, string name,
                                                                BsSelectList <TKey> radioList, IDictionary <string, object> htmlAttributes, bool allowMultiple, string bsCssClass, ModelMetadata metadata = null)
        {
            //TODO: refactoring
            //bind the selected values BsSelectList.SelectedValues
            name += ".SelectedValues";

            var fullName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name);
            var html     = new StringBuilder();
            var divTag   = new TagBuilder("div");

            divTag.AddCssClass(bsCssClass);
            divTag.AddCssClass("form-control");
            divTag.GenerateId(fullName);

            if (htmlAttributes != null)
            {
                divTag.MergeAttributes(htmlAttributes);
            }

            // Create a radio button temporary to get the common SelectListValidation (hack to preverv them)
            var commonRadioBuilder = new TagBuilder("input");

            if (radioList.Items.Any())
            {
                commonRadioBuilder.BsSelectListValidation(htmlHelper, name, metadata);
            }

            // Create a radio button for each item in the list
            foreach (var item in radioList.Items)
            {
                // Generate an id to be given to the radio button field
                var id = string.Format("{0}_{1}", divTag.Attributes["id"], item.Value);

                // Create and populate a radio button using the existing html htmlHelpers
                var label = htmlHelper.Label(id, HttpUtility.HtmlEncode(item.Text));

                var radioHtmlAttributes = new Dictionary <string, object> {
                    { "id", id }
                };

                if (htmlAttributes != null)
                {
                    htmlAttributes.ToList().ForEach(x =>
                    {
                        if (!radioHtmlAttributes.ContainsKey(x.Key))
                        {
                            radioHtmlAttributes.Add(x.Key, x.Value);
                        }
                    });
                }

                // build radio or checkbox input
                var input        = string.Empty;
                var radioBuilder = new TagBuilder("input");
                radioBuilder.MergeAttribute("name", fullName, true);
                radioBuilder.MergeAttributes(radioHtmlAttributes);
                if (item.Selected)
                {
                    radioBuilder.MergeAttribute("checked", "checked");
                }

                // merge common atributes
                radioBuilder.MergeAttributes(commonRadioBuilder.Attributes);

                if (allowMultiple)
                {
                    //render checkbox
                    radioBuilder.MergeAttribute("type", "checkbox");
                    radioBuilder.MergeAttribute("data-value", item.Value);

                    var inputItemBuilder = new StringBuilder();
                    inputItemBuilder.Append(radioBuilder.ToString(TagRenderMode.SelfClosing));

                    var hiddenInput = new TagBuilder("input");
                    hiddenInput.MergeAttribute("type", HtmlHelper.GetInputTypeString(InputType.Hidden));
                    hiddenInput.MergeAttribute("name", fullName);
                    hiddenInput.MergeAttribute("value", "false");
                    inputItemBuilder.Append(hiddenInput.ToString(TagRenderMode.SelfClosing));
                    input = inputItemBuilder.ToString();
                }
                else
                {
                    //render radio
                    radioBuilder.MergeAttribute("type", "radio");
                    radioBuilder.MergeAttribute("value", item.Value);
                    input = radioBuilder.ToString(TagRenderMode.SelfClosing);
                }

                // Create the html string
                // e.g. <input data-val="true" data-val-required="You must select an option" id="TestRadio_1" name="TestRadio" type="radio" value="1" /><label for="TestRadio_1">Line1</label>
                var innerDivTag = new TagBuilder("div");
                //innerDivTag.AddCssClass("RadioButton");
                html.Append(innerDivTag.ToString(TagRenderMode.StartTag));
                html.Append(input);
                html.Append(label);
                html.Append(innerDivTag.ToString(TagRenderMode.EndTag));
            }

            var buttonGroupContainer = new TagBuilder("div");

            buttonGroupContainer.AddCssClass("checkbox_replace form-control");
            buttonGroupContainer.MergeAttribute("id", divTag.Attributes["id"] + "_checkBox");
            buttonGroupContainer.MergeAttribute("tabindex", 0.ToString());

            var buttonGroupDiv = new TagBuilder("div");

            buttonGroupDiv.AddCssClass("btn-group-justified");

            foreach (var item in radioList.Items)
            {
                var buttonA = new TagBuilder("a");
                buttonA.AddCssClass("option bs-buttonGroupItem");
                buttonA.MergeAttribute("data-value", item.Value);

                if (item.Selected)
                {
                    buttonA.AddCssClass("selected");
                }

                buttonA.InnerHtml += HttpUtility.HtmlEncode(item.Text);

                buttonGroupDiv.InnerHtml += buttonA;
            }

            buttonGroupContainer.InnerHtml += buttonGroupDiv;

            divTag.InnerHtml = html.ToString();
            divTag.MergeAttribute("style", "display:none");

            return(MvcHtmlString.Create(divTag.ToString() + buttonGroupContainer.ToString()));
        }
Exemplo n.º 18
0
        private static MvcHtmlString BsHiddenInternal <TKey>(this HtmlHelper htmlHelper, string name,
                                                             BsSelectList <TKey> selectList, string optionLabel,
                                                             IDictionary <string, object> htmlAttributes, bool allowMultiple, string bsCssClass, ModelMetadata metadata = null)
        {
            name += ".SelectedValues";

            var fullName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name);

            if (String.IsNullOrEmpty(fullName))
            {
                throw new ArgumentException("Null Or Empty", "name");
            }

            var tagBuilder = new TagBuilder("input");

            tagBuilder.MergeAttribute("type", "hidden");
            tagBuilder.MergeAttributes(htmlAttributes);
            tagBuilder.MergeAttribute("class", bsCssClass + " form-control");
            tagBuilder.MergeAttribute("name", fullName, true);
            tagBuilder.MergeAttribute("placeholder", optionLabel);
            tagBuilder.GenerateId(fullName);

            if (selectList != null)
            {
                if (selectList.Items != null)
                {
                    if (allowMultiple)
                    {
                        var selectedItems = selectList.Items.Where(x => x.Selected).ToList();

                        if (selectedItems.Any())
                        {
                            tagBuilder.MergeAttribute("data-init", JsonConvert.SerializeObject(selectedItems.Select(x => new
                            {
                                id   = x.Value,
                                text = x.Text
                            })));
                        }
                    }
                    else
                    {
                        var selectedItem = selectList.Items.Where(x => x.Selected).FirstOrDefault();

                        if (selectedItem != null)
                        {
                            tagBuilder.MergeAttribute("data-init", JsonConvert.SerializeObject(new
                            {
                                id   = selectedItem.Value,
                                text = selectedItem.Text
                            }));
                        }
                    }
                }

                if (selectList.SelectedValues != null)
                {
                    var value = "";

                    if (ReflectionHelpers.IsList(selectList.SelectedValues))
                    {
                        var arr = new List <string>();

                        foreach (var item in selectList.SelectedValues as IEnumerable)
                        {
                            arr.Add(item.ToString());
                        }

                        value = string.Join(",", arr);
                    }
                    else
                    {
                        value = selectList.SelectedValues.ToString();
                    }

                    tagBuilder.MergeAttribute("value", value);
                }
            }

            if (allowMultiple)
            {
                tagBuilder.MergeAttribute("multiple", "multiple");
            }

            tagBuilder.BsSelectListValidation(htmlHelper, fullName, metadata);

            return(MvcHtmlString.Create(tagBuilder.ToString()));
        }
Exemplo n.º 19
0
        private RegisterModel InitRegisterModel()
        {
            var listWithSelected = Lists.AllAsp <List <int> >();

            listWithSelected.SelectedValues = new List <int> {
                1, 2
            };

            var enumWithSelected = BsSelectList <NotificationType?> .FromEnum(typeof(NotificationType));

            enumWithSelected.SelectedValues = NotificationType.Monthly;

            var countries       = Lists.AllCountries <string>();
            var ddlInitialValue = countries.Items.Where(x => x.Value == "RO").FirstOrDefault();

            ddlInitialValue.Selected = true;

            var ddlWithSelected = new BsSelectList <string>()
            {
                Items = new List <BsSelectListItem>
                {
                    ddlInitialValue
                },
                SelectedValues = "ROU"
            };

            var ideListWithSelected = Lists.AllIde <string>();

            ideListWithSelected.SelectedValues = "Visual Studio";

            var langListWithSelected = Lists.AllLanguages <List <string> >();

            langListWithSelected.SelectedValues = new List <string> {
                "C#"
            };

            var from = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 10, 30, 0);
            var to   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.AddDays(12).Day, 20, 00, 0);

            var javascriptMvcFrameworkWithSelected = Lists.AllJavascriptFrameworks <int>();

            javascriptMvcFrameworkWithSelected.SelectedValues = 2;

            var webBrowsers = Lists.AllWebBrowsers <int>();

            return(new RegisterModel()
            {
                CountriesList = ddlWithSelected,
                NotificationList = enumWithSelected,
                TechnologiesList = Lists.AllTech <List <int> >(),
                TechnologiesCheckboxList = listWithSelected,
                LanguagesList = langListWithSelected,
                IdeList = ideListWithSelected,
                GenderList = Lists.AllGenders <int>().ToSelectList().ToList(),
                Birthday = new BsDateTime(),
                Interval = new BsRange <DateTime>
                {
                    From = new BsRangeItem <DateTime>
                    {
                        ItemValue = DateTime.Now
                    },
                    To = new BsRangeItem <DateTime>
                    {
                        ItemValue = DateTime.Now.AddDays(12)
                    }
                },
                JavascriptMvcFramework = javascriptMvcFrameworkWithSelected,
                WebBrowsers = webBrowsers
            });
        }
Exemplo n.º 20
0
        private static MvcHtmlString BsTagListInternal <TKey>(this HtmlHelper htmlHelper, string name,
                                                              BsSelectList <TKey> selectList, string optionLabel,
                                                              IDictionary <string, object> htmlAttributes, string bsCssClass, ModelMetadata metadata = null)
        {
            //TODO: refactoring
            //bind the selected values BsSelectList.SelectedValues
            name += ".SelectedValues";

            name = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name);

            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Null Or Empty", "name");
            }

            bool usedViewData = false;

            // If we got a null selectList, try to use ViewData to get the list of items.
            if (selectList == null)
            {
                selectList   = htmlHelper.GetSelectData <TKey>(name);
                usedViewData = true;
            }
            bool   allowMultiple = true;
            object defaultValue  = (allowMultiple)
                ? htmlHelper.GetModelStateValue(name, typeof(string[]))
                : htmlHelper.GetModelStateValue(name, typeof(string));

            // If we haven't already used ViewData to get the entire list of items then we need to
            // use the ViewData-supplied value before using the parameter-supplied value.
            if (!usedViewData)
            {
                if (defaultValue == null)
                {
                    defaultValue = htmlHelper.ViewData.Eval(name);
                }
            }

            if (defaultValue != null)
            {
                var defaultValues = (allowMultiple) ? defaultValue as IEnumerable : new[] { defaultValue };
                var values        = from object value in defaultValues
                                    select Convert.ToString(value, CultureInfo.CurrentCulture);

                var selectedValues = new HashSet <string>(values, StringComparer.OrdinalIgnoreCase);
                var newSelectList  = new BsSelectList <TKey> {
                    SelectedValues = selectList.SelectedValues
                };

                foreach (var item in selectList.Items)
                {
                    item.Selected = (item.Value != null)
                        ? selectedValues.Contains(item.Value)
                        : selectedValues.Contains(item.Text);
                    newSelectList.Items.Add(item);
                }
                selectList = newSelectList;
            }

            // Convert each ListItem to an <option> tag
            var listItemBuilder = new StringBuilder();

            // Make optionLabel the first item that gets rendered.
            if (optionLabel != null)
            {
                listItemBuilder.AppendLine(
                    ListItemToOption(new BsSelectListItem
                {
                    Text     = optionLabel,
                    Value    = String.Empty,
                    Selected = false
                }));
            }

            //build options
            foreach (var item in selectList.Items)
            {
                listItemBuilder.AppendLine(ListItemToOption(item));
            }

            var tagBuilder = new TagBuilder("select")
            {
                InnerHtml = listItemBuilder.ToString()
            };

            tagBuilder.MergeAttributes(htmlAttributes);
            tagBuilder.MergeAttribute("name", name, true);
            tagBuilder.AddCssClass(bsCssClass);
            tagBuilder.AddCssClass("form-control");
            tagBuilder.GenerateId(name);
            if (allowMultiple)
            {
                tagBuilder.MergeAttribute("multiple", "multiple");
            }

            tagBuilder.BsSelectListValidation(htmlHelper, name, metadata);

            return(MvcHtmlString.Create(tagBuilder.ToString()));
        }
Exemplo n.º 21
0
        public string RenderControls(IEnumerable <FormBuilderControl> controls)
        {
            var controlsString = String.Empty;

            foreach (var control in controls)
            {
                var controlString = String.Empty;

                switch (control.Type)
                {
                case FormBuilderControlType.Textbox:
                {
                    var inputControl = control as InputControlModel;

                    controlString = _helper.BsTextBox(inputControl.Name, inputControl.Properties.InitialValue).ToString();

                    break;
                }

                case FormBuilderControlType.Textarea:
                {
                    var textareaControl = control as TextAreaControlModel;

                    controlString = _helper.BsTextBox(textareaControl.Name, String.Empty).ToString();

                    break;
                }

                case FormBuilderControlType.SingleSelect:
                {
                    var selectControl = control as SingleSelectControlModel;

                    var bsSelectList = new BsSelectList <string>
                    {
                        Items = selectControl.Properties.Items.SelectedValues.Select(x => new BsSelectListItem
                            {
                                Text  = x,
                                Value = x
                            }).ToList()
                    };

                    controlString = _helper.BsSelectList <string>(bsSelectList, BsControlType.DropDownList, selectControl.Name, false, null).ToString();

                    break;
                }

                case FormBuilderControlType.ListBox:
                {
                    var selectControl = control as ListBoxControlModel;

                    var bsSelectList = new BsSelectList <string>
                    {
                        Items = selectControl.Properties.Items.SelectedValues.Select(x => new BsSelectListItem
                            {
                                Text  = x,
                                Value = x
                            }).ToList()
                    };

                    controlString = _helper.BsSelectList <string>(bsSelectList, BsControlType.ListBox, selectControl.Name, true, null).ToString();

                    break;
                }

                case FormBuilderControlType.TagList:
                {
                    var selectControl = control as TagListControlModel;

                    var bsSelectList = new BsSelectList <string>
                    {
                        Items = selectControl.Properties.Items.SelectedValues.Select(x => new BsSelectListItem
                            {
                                Text  = x,
                                Value = x
                            }).ToList()
                    };

                    controlString = _helper.BsTagList <string>(bsSelectList, BsControlType.TagList, selectControl.Name, null).ToString();


                    break;
                }

                case FormBuilderControlType.RadioButtonList:
                {
                    var selectControl = control as RadioButtonListControlModel;

                    var bsSelectList = new BsSelectList <string>
                    {
                        Items = selectControl.Properties.Items.SelectedValues.Select(x => new BsSelectListItem
                            {
                                Text  = x,
                                Value = x
                            }).ToList()
                    };

                    controlString = _helper.BsRadioList <string>(bsSelectList, BsControlType.RadioButtonList, selectControl.Name, null, false).ToString();

                    break;
                }

                default:
                {
                    break;
                }
                }

                var formGroupString = RenderFormGroup(control, controlString);

                controlsString += formGroupString;
            }

            var buttons = new List <BsButtonModel>
            {
                new BsButtonModel("Save", BsComponentStatus.Default),
                new BsButtonModel("Reset", BsComponentStatus.Add)
            };

            var buttonsString = RenderFormButtons(buttons);

            controlsString += buttonsString;

            return(controlsString);
        }
Exemplo n.º 22
0
 public static MvcHtmlString BsRadioList <TKey>(this HtmlHelper htmlHelper, BsSelectList <TKey> radioList, BsControlType controlType, string name, IDictionary <string, object> htmlAttributes, bool allowMultiple, ModelMetadata metadata = null)
 {
     return(BsRadioListInternal(htmlHelper, name, radioList, htmlAttributes, allowMultiple, controlType.GetDescription(), metadata));
 }
Exemplo n.º 23
0
        public MultipleSelectControlProperties()
        {
            InitialValues = new BsSelectList<List<string>>();

            InitialValues.Items = new List<BsSelectListItem>(Items.Items);
        }
Exemplo n.º 24
0
        public DefaultcontrolProperties()
        {
            Width = BsSelectList<ColumnWidth>.FromEnum(typeof(ColumnWidth));

            GlyphiconAddon = new BsSelectList<Glyphicon?>();

            var glyphiconList = new BsSelectList<Glyphicon>();

            glyphiconList.Items = Enum.GetValues(typeof(Glyphicon)).Cast<Glyphicon>()
                .Where(x=> x != Glyphicon.Custom)
                .Select(x => new BsSelectListItem
                {
                    Text = x.ToString(),
                    Value = x.GetDescription()
                }).ToList();

            GlyphiconAddon.Items = glyphiconList.Items;

            GlyphiconAddon.Items.Insert(0, new BsSelectListItem
            {
                Text = "None",
                Value = String.Empty
            });

            Required = BsSelectList<YesNoValues>.FromEnum(typeof(YesNoValues));

            Width.SelectedValues = ColumnWidth.Large;
            Required.SelectedValues = YesNoValues.No;
        }
Exemplo n.º 25
0
        private RegisterModel InitRegisterModel()
        {
            var listWithSelected = Lists.AllAsp<List<int>>();
            listWithSelected.SelectedValues = new List<int> { 1, 2 };

            var enumWithSelected = BsSelectList<NotificationType?>.FromEnum(typeof(NotificationType));
            enumWithSelected.SelectedValues = NotificationType.Monthly;

            var countries = Lists.AllCounties<string>();
            var ddlInitialValue = countries.Items.Where(x => x.Value == "ROU").FirstOrDefault();
            ddlInitialValue.Selected = true;

            var ddlWithSelected = new BsSelectList<string>()
            {
                Items = new List<BsSelectListItem>
                {
                    ddlInitialValue
                },
                SelectedValues = "ROU"
            };

            var ideListWithSelected = Lists.AllIde<string>();
            ideListWithSelected.SelectedValues = "Visual Studio";

            var langListWithSelected = Lists.AllLanguages<List<string>>();
            langListWithSelected.SelectedValues = new List<string> { "C#" };

            var from = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 10, 30, 0);
            var to = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.AddDays(12).Day, 20, 00, 0);

            var javascriptMvcFrameworkWithSelected = Lists.AllJavascriptFrameworks<int>();
            javascriptMvcFrameworkWithSelected.SelectedValues = 2;

            var webBrowsers = Lists.AllWebBrowsers<int>();

            return new RegisterModel()
            {
                CountriesList = ddlWithSelected,
                NotificationList = enumWithSelected,
                TechnologiesList = Lists.AllTech<List<int>>(),
                TechnologiesCheckboxList = listWithSelected,
                LanguagesList = langListWithSelected,
                IdeList = ideListWithSelected,
                GenderList = Lists.AllGenders<int>().ToSelectList().ToList(),
                Birthday = new BsDateTime(),
                Interval = new BsRange<DateTime>
                {
                    From = new BsRangeItem<DateTime>
                    {
                        ItemValue = DateTime.Now
                    },
                    To = new BsRangeItem<DateTime>
                    {
                        ItemValue = DateTime.Now.AddDays(12)
                    }
                },
                JavascriptMvcFramework = javascriptMvcFrameworkWithSelected,
                WebBrowsers = webBrowsers
            };
        }
Exemplo n.º 26
0
        public RadioButtonListControlProperties()
        {
            InitialValue = new BsSelectList <int>();

            InitialValue.Items = new List <BsSelectListItem>(Items.Items);
        }
Exemplo n.º 27
0
 public UserComponentListModel()
 {
     UserComponentListBox  = new BsSelectList <List <string> >();
     UserComponentDropdown = new BsSelectList <int?>();
 }
Exemplo n.º 28
0
 public ContributorProjectEditableRelatedModel()
 {
     RoleList = new BsSelectList <ProjectRole?>();
     RoleList.ItemsFromEnum(typeof(ProjectRole));
 }
Exemplo n.º 29
0
        public RadioButtonListControlProperties()
        {
            InitialValue = new BsSelectList<int>();

            InitialValue.Items = new List<BsSelectListItem>(Items.Items);
        }
Exemplo n.º 30
0
        public static BsSelectList <T> AllLanguages <T>()
        {
            var list = new BsSelectList <T>();

            list.Items.Add(new BsSelectListItem()
            {
                Text = "C#", Value = "C#"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Java", Value = "Java"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "C++", Value = "C++"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Objective-C", Value = "Objective-C"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Javascript", Value = "Javascript"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Fortran", Value = "Fortran"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Ruby", Value = "Ruby"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "PHP", Value = "PHP"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Python", Value = "Python"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Scala", Value = "Scala"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Ada", Value = "Ada"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "ActionScript", Value = "ActionScript"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "Visual Basic", Value = "Visual Basic"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "CSS", Value = "CSS"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "HTML", Value = "HTML"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "SASS", Value = "SASS"
            });
            list.Items.Add(new BsSelectListItem()
            {
                Text = "SQL", Value = "SQL"
            });

            return(list);
        }
Exemplo n.º 31
0
        public SelectControlBaseProperties()
        {
            Items = new BsSelectList<List<string>>();

            //Items.Items.Add(new BsSelectListItem
            //{
            //    Text = "A",
            //    Value = "A"
            //});

            //Items.Items.Add(new BsSelectListItem
            //{
            //    Text = "B",
            //    Value = "B"
            //});

            //Items.SelectedValues = Items.Items.Select(x => x.Value).ToList();
        }
Exemplo n.º 32
0
 public static MvcHtmlString BsTagList <TKey>(this HtmlHelper helper, BsSelectList <TKey> selectList, BsControlType controlType, string name, Dictionary <string, object> htmlAttributes, ModelMetadata metadata = null)
 {
     return(BsTagListInternal(helper, name, selectList, null, htmlAttributes, controlType.GetDescription(), null));
 }
Exemplo n.º 33
0
        public SingleSelectControlProperties()
        {
            InitialValue = new BsSelectList<string>();

            InitialValue.Items = new List<BsSelectListItem>(Items.Items);
        }
Exemplo n.º 34
0
        public CheckBoxListControlProperties()
        {
            InitialValues = new BsSelectList <List <int> >();

            InitialValues.Items = new List <BsSelectListItem>(Items.Items);
        }
Exemplo n.º 35
0
        public CheckBoxListControlProperties()
        {
            InitialValues = new BsSelectList<List<int>>();

            InitialValues.Items = new List<BsSelectListItem>(Items.Items);
        }
Exemplo n.º 36
0
 public UserNewModel()
 {
     Countries   = new BsSelectList <int?>();
     Citizenship = new BsSelectList <int?>();
 }
Exemplo n.º 37
0
        private static MvcHtmlString BsMixedButtonGroupDropdownInternal <TKey>(this HtmlHelper htmlHelper, string name,
                                                                               BsSelectList <TKey> selectList, string optionLabel, IDictionary <string, object> htmlAttributes, string bsCssClass, ModelMetadata metadata = null)
        {
            name += ".SelectedValues";
            name  = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name);

            bool   usedViewData = false;
            object defaultValue = htmlHelper.GetModelStateValue(name, typeof(string));

            // If we haven't already used ViewData to get the entire list of items then we need to
            // use the ViewData-supplied value before using the parameter-supplied value.
            if (!usedViewData)
            {
                if (defaultValue == null)
                {
                    defaultValue = htmlHelper.ViewData.Eval(name);
                }
            }

            if (defaultValue != null)
            {
                var defaultValues = new[] { defaultValue };
                var values        = from object value in defaultValues
                                    select Convert.ToString(value, CultureInfo.CurrentCulture);

                var selectedValues = new HashSet <string>(values, StringComparer.OrdinalIgnoreCase);
                var newSelectList  = new BsSelectList <TKey> {
                    SelectedValues = selectList.SelectedValues
                };

                foreach (var item in selectList.Items)
                {
                    item.Selected = (item.Value != null)
                        ? selectedValues.Contains(item.Value)
                        : selectedValues.Contains(item.Text);
                    newSelectList.Items.Add(item);
                }
                selectList = newSelectList;
            }

            var listItemBuilder = new StringBuilder();

            // Make optionLabel the first item that gets rendered.
            if (optionLabel != null)
            {
                listItemBuilder.AppendLine(
                    ListItemToOption(new BsSelectListItem
                {
                    Text     = optionLabel,
                    Value    = String.Empty,
                    Selected = false
                }));
            }

            //build options
            foreach (var item in selectList.Items)
            {
                listItemBuilder.AppendLine(ListItemToOption(item));
            }

            var tagBuilder = new TagBuilder("select")
            {
                InnerHtml = listItemBuilder.ToString()
            };

            tagBuilder.MergeAttributes(htmlAttributes);
            tagBuilder.MergeAttribute("name", name, true);
            tagBuilder.AddCssClass(bsCssClass);
            tagBuilder.AddCssClass("form-control");
            tagBuilder.GenerateId(name);

            tagBuilder.BsSelectListValidation(htmlHelper, name, metadata);

            tagBuilder.MergeAttribute("style", "display:none");

            #region render button dropdown
            var buttonGroupContainer = new TagBuilder("div");

            buttonGroupContainer.AddCssClass("checkbox_replace bs-mixedButtonGroupDropdownContainer form-control");
            buttonGroupContainer.MergeAttribute("tabindex", 0.ToString());

            var btnGroup = new TagBuilder("div");
            btnGroup.AddCssClass("btn-group-justified bs-buttonsContainer");

            #region render buttons first
            foreach (var item in selectList.Items.Where(x => x.IsButton))
            {
                var buttonA = new TagBuilder("a");
                buttonA.AddCssClass("option bs-buttonGroupItem");
                buttonA.MergeAttribute("data-value", item.Value);

                if (item.Selected)
                {
                    buttonA.AddCssClass("selected");
                }

                buttonA.InnerHtml += HttpUtility.HtmlEncode(item.Text);

                btnGroup.InnerHtml += buttonA;
            }

            #endregion

            if (selectList.Items.Any(x => !x.IsButton))
            {
                var button = new TagBuilder("a");
                button.AddCssClass("option dropdown-toggle bs-buttonGroupDropdownToggle");
                button.MergeAttribute("href", "#");
                button.MergeAttribute("data-toggle", "dropdown");
                button.MergeAttribute("data-dropdown-for", tagBuilder.Attributes["id"]);

                if (optionLabel != null)
                {
                    button.MergeAttribute("data-placeholder", optionLabel + " ");
                }
                else
                {
                    optionLabel = selectList.Items.FirstOrDefault(x => !x.IsButton).Text;
                    button.MergeAttribute("data-placeholder", optionLabel + " ");
                }

                var selectedValue = selectList.Items.Where(x => !x.IsButton).FirstOrDefault(x => x.Selected);

                if (selectedValue != null)
                {
                    button.InnerHtml += selectedValue.Text + " ";
                    button.AddCssClass("selected");
                }
                else
                {
                    button.InnerHtml += optionLabel + " ";
                }

                var carretSpan = new TagBuilder("span");
                carretSpan.AddCssClass("caret");

                button.InnerHtml += carretSpan.ToString();

                btnGroup.InnerHtml += button;

                var dropdownUl = new TagBuilder("ul");
                dropdownUl.AddCssClass("dropdown-menu dropdown-menu-right bs-dropdownList");
                dropdownUl.MergeAttribute("role", "menu");

                var dropdownListItemBuilder = new StringBuilder();

                foreach (var item in selectList.Items.Where(x => !x.IsButton))
                {
                    dropdownListItemBuilder.AppendLine(ListItemToLi(item));
                }

                dropdownUl.InnerHtml += dropdownListItemBuilder.ToString();

                buttonGroupContainer.InnerHtml += btnGroup;

                buttonGroupContainer.InnerHtml += dropdownUl;
            }
            else
            {
                buttonGroupContainer.InnerHtml += btnGroup;
            }

            #endregion

            return(MvcHtmlString.Create(tagBuilder.ToString() + buttonGroupContainer.ToString()));
        }