Ejemplo n.º 1
0
        public static MvcHtmlString CheckBoxValue(this HtmlHelper html, string headerText, CheckBoxListItem item, int index)
        {
            var valueID = string.Format(ValID, Regex.Replace(headerText, @"\s+", ""), index);

            var builder = new StringBuilder();
            var tagBuilder = CreateHiddenTag(valueID, item.Value);
            builder.AppendLine(tagBuilder.ToString());

            return MvcHtmlString.Create(builder.ToString());
        }
Ejemplo n.º 2
0
        public static MvcHtmlString CheckBoxInputLabel(this HtmlHelper html, string headerText, CheckBoxListItem item, int index)
        {
            var lblFor = string.Format(ChkId, Regex.Replace(headerText, @"\s+", ""), index);
            var lblForHdn = string.Format(LblId, Regex.Replace(headerText, @"\s+", ""), index);

            var builder = new StringBuilder();

            var tagBuilder = new TagBuilder("label");
            tagBuilder.MergeAttribute("for", lblFor);
            tagBuilder.SetInnerText(item.Text);
            builder.AppendLine(tagBuilder.ToString());

            var hdnTagBuilder = CreateHiddenTag(lblForHdn, item.Text);
            builder.AppendLine(hdnTagBuilder.ToString());

            return MvcHtmlString.Create(builder.ToString());
        }
        public static CheckBoxListViewModel GetBrushesModel(string basePath, string selectedItems)
        {
            var currentList = selectedItems.Split('~').ToList();
            var checkBoxListViewModel = new CheckBoxListViewModel {HeaderText = "Select Brushes"};

            var items = new List<CheckBoxListItem>();
            var files = Directory.GetFiles(basePath, "shBrush*.js");
            files.ToList().ForEach(file =>
            {
                var r1 = new Regex(@"shBrush([A-Za-z0-9\-]+).js");
                var match = r1.Match(Path.GetFileName(file));
                var item = new CheckBoxListItem { Text = match.Groups[1].Value, Value = match.Groups[1].Value, IsChecked = currentList.Contains(match.Groups[1].Value) };
                items.Add(item);
            });

            checkBoxListViewModel.Items = items;

            return checkBoxListViewModel;
        }
Ejemplo n.º 4
0
        public static MvcHtmlString CheckBoxInput(this HtmlHelper html, string headerText, CheckBoxListItem item, int index)
        {
            var chkBoxID = string.Format(ChkId, Regex.Replace(headerText, @"\s+", ""), index);
            var hiddenFieldID = string.Format("hdnChk_{0}_{1}", Regex.Replace(headerText, @"\s+", ""), index);

            var builder = new StringBuilder();
            var tagBuilder = new TagBuilder("input");
            tagBuilder.MergeAttribute("type", "checkbox");
            tagBuilder.MergeAttribute("id", chkBoxID);
            tagBuilder.MergeAttribute("name", chkBoxID);
            tagBuilder.MergeAttribute("class", "chkClickable");
            tagBuilder.MergeAttribute("value", item.IsChecked.ToString().ToLower());
            if (item.IsChecked)
                tagBuilder.MergeAttribute("checked", "checked");
            builder.AppendLine(tagBuilder.ToString());

            var hdnTagBuilder1 = CreateHiddenTag(hiddenFieldID, item.IsChecked.ToString().ToLower(), "hdnStatus");
            builder.AppendLine(hdnTagBuilder1.ToString());

            return MvcHtmlString.Create(builder.ToString());
        }
Ejemplo n.º 5
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var models = new List<CheckBoxListViewModel>();
            var formKeys = controllerContext.HttpContext.Request.Form.AllKeys.ToArray();

            var rootItems = formKeys.Where(s => s.StartsWith("hdrTitle")).ToList();

            if (rootItems.Count == 0)
                return null;

            foreach (var item in rootItems)
            {
                var hdrValue = item.Split('_')[1];
                var txtValues = formKeys.Where(s => s.StartsWith("lblLabel_" + hdrValue)).ToArray();
                var valValues = formKeys.Where(s => s.StartsWith("valValue_" + hdrValue)).ToArray();
                var hdnValues = formKeys.Where(s => s.StartsWith("hdnChk_" + hdrValue)).ToArray();

                var model = new CheckBoxListViewModel
                                {
                                    HeaderText = Regex.Replace(hdrValue, "([a-z])([A-Z])", "$1 $2"),
                                    Items = new List<CheckBoxListItem>()
                                };
                for (var index = 0; index < txtValues.Count(); index++)
                {
                    var listItem = new CheckBoxListItem
                                    {
                                        Text = bindingContext.GetValue(txtValues[index]),
                                        Value = bindingContext.GetValue(valValues[index]),
                                        IsChecked = bool.Parse(bindingContext.GetValue(hdnValues[index]))
                                    };

                    model.Items.Add(listItem);
                }

                models.Add(model);
            }

            return rootItems.Count == 1 ? (object) models.First() : models;
        }
Ejemplo n.º 6
0
 private static CheckBoxListViewModel GetModel(List<CategoryEntity> baseList, IEnumerable<CategoryEntity> selectedCategories = null)
 {
     var model = new CheckBoxListViewModel {HeaderText = "select categories"};
     var checkItems = new List<CheckBoxListItem>();
     baseList.ForEach(category =>
     {
         var item = new CheckBoxListItem
         {
             Text = category.CategoryName,
             Value = category.CategoryID.ToString(),
             IsChecked = selectedCategories != null && selectedCategories.Any(c => c.CategoryID == category.CategoryID)
         };
         checkItems.Add(item);
     });
     
     if (selectedCategories == null)
     {
         var general = checkItems.SingleOrDefault(c => c.Text == "General");
         if (general != null)
         {
             general.IsChecked = true;
         }
     }
     
     model.Items = checkItems;
     return model;
 }