コード例 #1
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);
        }
コード例 #2
0
        public async Task <ActionResult> Create()
        {
            var availableRoles = await _roleManager.Roles.Where(r => r.Name != SYSTEM_ADMIN_ROLE_NAME).ToListAsync();

            if (availableRoles == null || !availableRoles.Any())
            {
                RegisterAlert("failed", "There is no available roles. Please add a role.");
                return(RedirectToAction("Index"));
            }

            var checkboxListItems = new List <CheckBoxListItem>();

            foreach (var role in availableRoles.ToList())
            {
                if (role.Name.Equals(SYSTEM_ADMIN_ROLE_NAME))
                {
                    continue;
                }
                var item = CheckBoxListItem.ToCheckboxlistItem(role, false);
                item.IsChecked = role.Name.Equals(USER_ROLE_NAME);
                checkboxListItems.Add(item);
            }

            return(View(new UserViewModel {
                AvailableRoles = checkboxListItems.OrderBy(cb => cb.Display)
            }));
        }
コード例 #3
0
    void onSchemeInfoSent(string schemeName)
    {
        PackedScene      scene = (PackedScene)ResourceLoader.Load("Scenes/AdvancedComponents/CheckBoxListItem.tscn");
        CheckBoxListItem field = (CheckBoxListItem)scene.Instance();

        field.Initialize(schemeName);

        schemesList.AddChild(field);
    }
コード例 #4
0
 void onSchemeFieldChecked(CheckBoxListItem sender)
 {
     for (int i = 0; i < schemesList.GetChildCount(); i++)
     {
         CheckBoxListItem field = (CheckBoxListItem)schemesList.GetChild(i);
         if (field != sender)
         {
             field.SetChecked(false);
         }
     }
 }
コード例 #5
0
    string getSelectedSchemeName()
    {
        for (int i = 0; i < schemesList.GetChildCount(); i++)
        {
            CheckBoxListItem field = (CheckBoxListItem)schemesList.GetChild(i);
            if (field.IsChecked())
            {
                return(field.GetItemName());
            }
        }

        return("\0");
    }
コード例 #6
0
    bool controlSchemeCorrectness()
    {
        for (int i = 0; i < schemesList.GetChildCount(); i++)
        {
            CheckBoxListItem field = (CheckBoxListItem)schemesList.GetChild(i);
            if (field.IsChecked())
            {
                return(true);
            }
        }

        errorInfo.Text = ERROR_NO_SCHEMA_TEXT;
        return(false);
    }
コード例 #7
0
        // Show comics in the subscribed list
        private void FillAvailableComics()
        {
            _availableComics.Clear();

            foreach (ComicInfo ci in SingletonComicsUpdater.Instance.AvailableComics)
            {
                CheckBoxListItem item = new CheckBoxListItem(ci.DisplayName, ci);
                item.CheckBoxChanged += new EventHandler(OnCheckBoxClickEvent);
                item.CheckBox.Checked = ci.Subscribed;
                _availableComics.AddItem(item);
            }

            return;
        }
コード例 #8
0
        // Handle mouse clicks
        private void OnCheckBoxClickEvent(object sender, EventArgs args)
        {
            CheckBoxListItem item = _availableComics.Items[_availableComics.SelectedIndex] as CheckBoxListItem;

            if (item == null)
            {
                return;
            }

            ComicInfo ci = (ComicInfo)item.Value;

            SingletonComicsUpdater.Instance.Subscribe(ci.DisplayName, item.CheckBox.Checked);
            return;
        }
コード例 #9
0
        // Click the checkbox to subscribe or unsubscribe
        private void OnItemActivated(object sender, ItemActivatedArgs args)
        {
            CheckBoxListItem item = _availableComics.Items[args.ActivatedIndex] as CheckBoxListItem;

            if (item == null)
            {
                return;
            }

            item.CheckBox.Checked = !item.CheckBox.Checked;
            ComicInfo ci = (ComicInfo)item.Value;

            SingletonComicsUpdater.Instance.Subscribe(ci.DisplayName, item.CheckBox.Checked);
            return;
        }
コード例 #10
0
ファイル: Extensions.cs プロジェクト: lurienanofab/lnf
        public static IHtmlString CheckBoxList <T>(this HtmlHelper helper, string name, IEnumerable <T> items, Expression <Func <T, object> > valueExpression, Expression <Func <T, object> > textExpression, CheckBoxListOptions options = null)
        {
            List <CheckBoxListItem> cbliList = new List <CheckBoxListItem>();

            foreach (T item in items)
            {
                CheckBoxListItem cbli = new CheckBoxListItem
                {
                    Value = valueExpression.Compile().Invoke(item).ToString(),
                    Text  = textExpression.Compile().Invoke(item).ToString()
                };
                cbliList.Add(cbli);
            }

            CheckBoxList cbl = new CheckBoxList(cbliList, options);

            return(new HtmlString(cbl.Render(name)));
        }
コード例 #11
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);
        }
コード例 #12
0
        private List <CheckBoxListItem> QueryCheckList(string queryString)
        {
            List <CheckBoxListItem> result = new List <CheckBoxListItem>();

            using (SqlConnection connection = new SqlConnection(Helpers.Helpers.GetAppConnectionString()))
            {
                SqlCommand command = new SqlCommand(queryString, connection); // Create the Command and Parameter objects
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read()) // Read each result row and extract the data
                {
                    CheckBoxListItem row = new CheckBoxListItem();
                    row.ID      = int.Parse(reader[0].ToString());
                    row.Display = reader[1].ToString();
                    result.Add(row);
                }
                reader.Close();
                connection.Close();
            }
            return(result);
        }
コード例 #13
0
        public async Task <ActionResult> Update(string id)
        {
            var user = await _userManager.FindByIdAsync(id);

            if (user == null)
            {
                RegisterAlert("failed", "User not found.");
                return(RedirectToAction("Index"));
            }

            var availableRoles = await _roleManager.Roles.Where(r => r.Name != SYSTEM_ADMIN_ROLE_NAME).ToListAsync();

            if (availableRoles == null || !availableRoles.Any())
            {
                RegisterAlert("failed", "There is no available roles. Please add a role.");
                return(RedirectToAction("Index"));
            }

            var checkboxListItems = new List <CheckBoxListItem>();

            foreach (var role in availableRoles.ToList())
            {
                if (role.Name.Equals(SYSTEM_ADMIN_ROLE_NAME))
                {
                    continue;
                }
                var item = CheckBoxListItem.ToCheckboxlistItem(role, false);
                item.IsChecked = role.Name.Equals(USER_ROLE_NAME);
                checkboxListItems.Add(item);
            }

            var isUserSysAdmin = await _userManager.IsInRoleAsync(user, SYSTEM_ADMIN_ROLE_NAME);

            var isCurrentUserSysAdmin = User.IsInRole(SYSTEM_ADMIN_ROLE_NAME);

            // admin cannot remove himself && only system admin can remove other system admins
            ViewBag.HasDeleteAccess = user.Id != _userManager.GetUserId(User) && (!isUserSysAdmin || isCurrentUserSysAdmin);

            return(View(UserUpdateViewModel.ToViewModel(user)));
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        // Show comics in the subscribed list
        private void FillAvailableComics()
        {
            _availableComics.Clear();

            foreach( ComicInfo ci in SingletonComicsUpdater.Instance.AvailableComics )
            {
                CheckBoxListItem item = new CheckBoxListItem( ci.DisplayName, ci );
                item.CheckBoxChanged += new EventHandler( OnCheckBoxClickEvent );
                item.CheckBox.Checked = ci.Subscribed;
                _availableComics.AddItem( item );
            }

            return;
        }
コード例 #16
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()));
        }
コード例 #17
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()));
        }
コード例 #18
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()));
        }
コード例 #19
0
ファイル: CheckBoxList.cs プロジェクト: nomada2/MvcKompAppGit
        public void ImportFromModel(object model, params object[] context)
        {
            IEnumerable   input = model as IEnumerable;
            List <TValue> inputList;

            if (input == null)
            {
                inputList = new List <TValue>();
            }
            else
            {
                inputList = EnumerableHelper.CreateFrom <TValue>(typeof(List <TValue>), input, 0) as List <TValue>;

                inputList.Sort();

                ChoiceList <TChoiceItem, TValue, TDisplay> choiceList = context[0] as ChoiceList <TChoiceItem, TValue, TDisplay>;

                List <CheckBoxListItem <TValue> > items   = new List <CheckBoxListItem <TValue> >();
                List <OrderItem <TValue> >        orderer = new List <OrderItem <TValue> >();

                int index = 0;

                foreach (TChoiceItem item in choiceList.Items)
                {
                    CheckBoxListItem <TValue> checkBoxListItem = new CheckBoxListItem <TValue>();
                    OrderItem <TValue>        orderItem        = new OrderItem <TValue>();
                    checkBoxListItem.Code  = choiceList.ValueSelector(item);
                    checkBoxListItem.Label = choiceList.DisplaySelector(item).ToString();

                    if (choiceList.LabelAttributesSelector != null)
                    {
                        checkBoxListItem.LabelAttributes = choiceList.LabelAttributesSelector(item);
                    }
                    else
                    {
                        checkBoxListItem.LabelAttributes = new { }
                    };
                    if (choiceList.DisplayAttributesSelector != null)
                    {
                        checkBoxListItem.DisplayAttributes = choiceList.DisplayAttributesSelector(item);
                    }
                    else
                    {
                        checkBoxListItem.DisplayAttributes = new { }
                    };
                    items.Add(checkBoxListItem);

                    orderItem.Value = checkBoxListItem.Code;
                    orderItem.Place = index;
                    orderer.Add(orderItem);
                    index++;
                }
                Items = items.ToArray();
                orderer.Sort();
                IEnumerator <OrderItem <TValue> > ordererIterator = (orderer as IEnumerable <OrderItem <TValue> >).GetEnumerator();
                ordererIterator.Reset();
                ordererIterator.MoveNext();
                foreach (TValue selectedValue in inputList)
                {
                    while (((IComparable)selectedValue).CompareTo(ordererIterator.Current.Value) > 0)
                    {
                        ordererIterator.MoveNext();
                    }
                    if (((IComparable)selectedValue).CompareTo(ordererIterator.Current.Value) == 0)
                    {
                        Items[ordererIterator.Current.Place].Selected = true;
                    }
                }
            }
        }
    }
コード例 #20
0
 /// <summary>Initializes a new instance of the <see cref="CheckBoxListItemCheckStateChangedEventArgs"/> class.</summary>
 /// <param name="item">The item.</param>
 /// <param name="index">The index.</param>
 public CheckBoxListItemCheckStateChangedEventArgs(CheckBoxListItem item, int index)
 {
     Item      = item;
     ItemIndex = index;
 }
コード例 #21
0
        public bool HasCommunity(CheckBoxListItem item)
        {
            int i = Convert.ToInt32(item.Value);

            return((Communities & i) > 0);
        }
コード例 #22
0
        public bool HasPriv(CheckBoxListItem item)
        {
            int i = Convert.ToInt32(item.Value);

            return((PrivFlag & i) > 0);
        }