public void RockSerializableList_UriEncodedString_CanRoundtrip()
        {
            var list = new List <string>();

            list.Add("Value1");
            list.Add(@"Value2|,/([!-/:-@[-`{-~]|\sand\s)+/i");
            list.Add("Value3");

            var sd1 = new RockSerializableList(list);

            var sd2 = RockSerializableList.FromUriEncodedString(sd1.ToUriEncodedString());

            Assert.AreEqual("Value1", sd2.List[0]);
            Assert.AreEqual(@"Value2|,/([!-/:-@[-`{-~]|\sand\s)+/i", sd2.List[1]);
            Assert.AreEqual("Value3", sd2.List[2]);
        }
Example #2
0
        /// <summary>
        /// Renders the base control.
        /// </summary>
        /// <param name="writer">The writer.</param>
        public virtual void RenderBaseControl(HtmlTextWriter writer)
        {
            Dictionary <string, string> definedValues = null;

            if (DefinedTypeId.HasValue)
            {
                definedValues = new Dictionary <string, string>();
                new DefinedValueService(new RockContext())
                .GetByDefinedTypeId(DefinedTypeId.Value)
                .ToList()
                .ForEach(v => definedValues.Add(v.Id.ToString(), v.Value));
            }
            else if (CustomValues != null)
            {
                definedValues = CustomValues;
            }

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "value-list");
            writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID);
            writer.RenderBeginTag(HtmlTextWriterTag.Span);
            writer.WriteLine();

            _hfValue.RenderControl(writer);
            _hfValueDisableVrm.RenderControl(writer);

            writer.WriteLine();

            StringBuilder valueHtml = new StringBuilder();

            valueHtml.Append(@"<div class=""controls controls-row form-control-group"">");
            if (definedValues != null && definedValues.Any())
            {
                valueHtml.Append(@"<select class=""form-control input-width-lg js-value-list-input"">");
                foreach (var definedValue in definedValues)
                {
                    valueHtml.AppendFormat(@"<option value=""{0}"">{1}</option>", definedValue.Key, definedValue.Value);
                }
                valueHtml.Append(@"</select>");
            }
            else
            {
                valueHtml.AppendFormat(@"<input class=""form-control input-width-lg js-value-list-input"" type=""text"" placeholder=""{0}""></input>", ValuePrompt);
            }
            valueHtml.Append(@"<a href=""#"" class=""btn btn-danger btn-square value-list-remove""><i class=""fa fa-times""></i></a></div>");

            var hfValueHtml = new HtmlInputHidden();

            hfValueHtml.AddCssClass("js-value-list-html");
            hfValueHtml.Value = valueHtml.ToString();
            hfValueHtml.RenderControl(writer);

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "value-list-rows");
            writer.RenderBeginTag(HtmlTextWriterTag.Span);
            writer.WriteLine();

            var values = RockSerializableList.FromUriEncodedString(this.Value);

            foreach (string value in values.List)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "controls controls-row form-control-group");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                writer.WriteLine();

                if (definedValues != null && definedValues.Any())
                {
                    DropDownList ddl = new DropDownList();
                    ddl.AddCssClass("form-control input-width-lg js-value-list-input");
                    ddl.DataTextField  = "Value";
                    ddl.DataValueField = "Key";
                    ddl.DataSource     = definedValues;
                    ddl.DataBind();
                    ddl.SelectedValue = value;
                    ddl.RenderControl(writer);
                }
                else
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "form-control input-width-lg js-value-list-input");
                    writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
                    writer.AddAttribute("placeholder", ValuePrompt);
                    writer.AddAttribute(HtmlTextWriterAttribute.Value, value);
                    writer.RenderBeginTag(HtmlTextWriterTag.Input);
                    writer.RenderEndTag();
                }

                writer.Write(" ");
                writer.WriteLine();

                // Write Remove Button
                writer.AddAttribute(HtmlTextWriterAttribute.Href, "#");
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "btn btn-sm btn-danger value-list-remove");
                writer.RenderBeginTag(HtmlTextWriterTag.A);
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "fa fa-times");
                writer.RenderBeginTag(HtmlTextWriterTag.I);
                writer.RenderEndTag();
                writer.RenderEndTag();
                writer.WriteLine();

                writer.RenderEndTag();
                writer.WriteLine();
            }

            writer.RenderEndTag();
            writer.WriteLine();

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "actions");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            var addButtonCssClass = "btn btn-action btn-xs btn-square value-list-add";

            if (!this.Enabled)
            {
                addButtonCssClass += " aspNetDisabled disabled";
            }

            writer.AddAttribute(HtmlTextWriterAttribute.Class, addButtonCssClass);

            writer.AddAttribute(HtmlTextWriterAttribute.Href, "#");
            writer.RenderBeginTag(HtmlTextWriterTag.A);
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "fa fa-plus-circle");
            writer.RenderBeginTag(HtmlTextWriterTag.I);

            writer.RenderEndTag();
            writer.RenderEndTag();
            writer.RenderEndTag();
            writer.WriteLine();

            writer.RenderEndTag();
            writer.WriteLine();
        }