コード例 #1
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();
        }
コード例 #2
0
		public ActionResult ControlPropertiesEdit(WidgetProperties model) {
			cmsHelper.OverrideKey(model.Widget.Root_ContentID);

			Widget w = (from aw in cmsHelper.cmsAdminWidget
						where aw.Root_WidgetID == model.Widget.Root_WidgetID
						orderby aw.WidgetOrder, aw.EditDate
						select aw).FirstOrDefault();

			var props = new List<WidgetProps>();

			foreach (var itm in model.Properties) {
				var p = new WidgetProps();
				p.KeyName = itm.Name;

				switch (itm.FieldMode) {
					case WidgetAttribute.FieldMode.CheckBoxList:
						//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 (var v in itm.Options) {
							if (v.Selected) {
								var pp = new WidgetProps();
								pp.KeyName = String.Format("{0}|{1}", itm.Name, checkedPosition);
								pp.KeyValue = v.Key.ToString();
								props.Add(pp);
								checkedPosition++;
							}
						}

						break;

					case WidgetAttribute.FieldMode.DropDownList:
					case WidgetAttribute.FieldMode.TextBox:
					case WidgetAttribute.FieldMode.MultiLineTextBox:
					case WidgetAttribute.FieldMode.RichHTMLTextBox:
						p.KeyValue = itm.TextValue;
						break;

					case WidgetAttribute.FieldMode.CheckBox:
						p.KeyValue = itm.CheckBoxState.ToString();
						break;

					default:
						break;
				}

				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 == w.Root_WidgetID);
			lstPageWidgets.Add(w);
			cmsHelper.cmsAdminWidget = lstPageWidgets;

			SetSaved();

			return RedirectToAction("ControlPropertiesEdit", new { @id = w.Root_WidgetID, @pageid = w.Root_ContentID });
		}