コード例 #1
0
        Widget(string name, bool elementCanHaveFocus = false)
        {
            var elementProps = new RenderElementProps();
            var renderResult = new Mock <RenderElement <RenderElementProps> >(elementProps);

            renderResult.CallBase = true;
            renderResult.Setup(x => x.CanHaveFocus).Returns(elementCanHaveFocus);
            renderResult.Setup(x => x.Children).Returns(new List <IRenderElement>());

            var widgetProps = new WidgetProps {
                Name = name
            };
            Mock <Widget <WidgetProps, WidgetState> > widgetResult =
                new Mock <Widget <WidgetProps, WidgetState> >(widgetProps);

            widgetResult.CallBase = true;
            widgetResult.Setup(x => x.Render()).Returns(renderResult.Object);

            return(widgetResult, renderResult);
        }
コード例 #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Widget w = (from aw in cmsHelper.cmsAdminWidget
                        where aw.Root_WidgetID == guidWidget
                        orderby aw.WidgetOrder, aw.EditDate
                        select aw).FirstOrDefault();

            var props = new List <WidgetProps>();

            foreach (RepeaterItem r in rpProps.Items)
            {
                HiddenField  hdnName   = (HiddenField)r.FindControl("hdnName");
                TextBox      txtValue  = (TextBox)r.FindControl("txtValue");
                DropDownList ddlValue  = (DropDownList)r.FindControl("ddlValue");
                CheckBox     chkValue  = (CheckBox)r.FindControl("chkValue");
                CheckBoxList chkValues = (CheckBoxList)r.FindControl("chkValues");

                var p = new WidgetProps();
                p.KeyName = hdnName.Value;

                if (ddlValue.Visible)
                {
                    // drop down list detected, save the selected item
                    p.KeyValue = ddlValue.SelectedValue;
                }
                else if (chkValue.Visible)
                {
                    //boolean detected
                    p.KeyValue = chkValue.Checked.ToString();
                }
                else if (chkValues.Visible)
                {
                    //multiple selections are possible, since dictionary is used, insure key is unique by appending the ordinal with a | delimeter.
                    p = null;
                    int CheckedPosition = 0;
                    foreach (ListItem v in chkValues.Items)
                    {
                        if (v.Selected)
                        {
                            var pp = new WidgetProps();
                            pp.KeyName  = hdnName.Value + "|" + CheckedPosition.ToString();
                            pp.KeyValue = v.Value.ToString();
                            props.Add(pp);
                            CheckedPosition++;
                        }
                    }
                }
                else
                {
                    //default, free text field
                    p.KeyValue = txtValue.Text;
                }

                if (p != null)
                {
                    props.Add(p);
                }
            }

            w.SaveDefaultControlProperties(props);
            w.EditDate = SiteData.CurrentSite.Now;

            List <Widget> lstPageWidgets = cmsHelper.cmsAdminWidget;

            lstPageWidgets.RemoveAll(x => x.Root_WidgetID == guidWidget);
            lstPageWidgets.Add(w);

            cmsHelper.cmsAdminWidget = lstPageWidgets;

            Master.ShowSave();
        }