//=== Radiobutton /// <summary> Renders the forms the schema radiobutton. </summary> public static MvcHtmlString FormSchemaRadiobutton(this HtmlHelper helper, Radiobutton radiobutton) { StringBuilder sb = new StringBuilder(); foreach (var item in radiobutton.Items) { sb.Append(FormSchemaRadiobuttonItem(helper, radiobutton, item)); } return(new MvcHtmlString(sb.ToString())); }
public AntwortRadioButtons_Model FillRadioButtonsTextModel(int inhalt_id) { Antwort_radiobutton antwortRadioButtonObject = main_db.Antwort_radiobutton.Single(x => x.AntwortContentID == inhalt_id); var antwortRadioButtons_Model = new AntwortRadioButtons_Model(); antwortRadioButtons_Model.RadioButtons = Randomize(main_db.Radiobutton .Where(x => x.Antwort_radiobutton.AntwortContentID == antwortRadioButtonObject.AntwortContentID) .ToList()); Radiobutton rb_rightVal = main_db.Radiobutton.Where(x => x.Antwort_radiobutton.AntwortContentID == antwortRadioButtonObject.AntwortContentID).Single(x => x.ErwartungsWert); antwortRadioButtons_Model.RadioButton_rightVal = rb_rightVal; return(antwortRadioButtons_Model); }
public void Select(Radiobutton button) { if (selected == button) { return; } if (selected != null) { selected.OnDeselect(); } selected = button; selected.OnSelect(); }
public bool CheckAntwortRadioButtons(string rbValue) { int id_antwort = UserData.Aufgabe.Antwort.AntwortContentID; Antwort_radiobutton antwortRadioButtonObject = main_db.Antwort_radiobutton.Single(x => x.AntwortContentID == id_antwort); Radiobutton rb = main_db.Radiobutton.Where(x => x.Antwort_radiobutton.AntwortContentID == antwortRadioButtonObject.AntwortContentID).Single(x => x.ErwartungsWert); if (rb.Content.Equals(rbValue)) { UserData.lastPracticeAufgabeCorrect = true; return(true); } else { return(false); } }
/// <summary> Renders the forms the schema single radiobutton item. </summary> public static string FormSchemaRadiobuttonItem(HtmlHelper helper, Radiobutton radiobutton, RadiobuttonItem buttonItem) { string id = string.Format("{0}_{1}", radiobutton.Name, buttonItem.Id); string name = string.Format("{0}", radiobutton.Name); //Dictionary<string, object> attributes = radiobutton.Attributes; //attributes.Add("class", "radioLabel"); bool isDisabled = (radiobutton.Disabled == true); MvcHtmlString radio = helper.SimpleHtmlInput("radio", name, id, buttonItem.Value, buttonItem.Selected, isDisabled: isDisabled); MvcHtmlString label = helper.Label(id, buttonItem.Label, new Dictionary <string, object> { { "class", "radioLabel" } }); return(radiobutton.Direction == RepeatDirection.Vertical ? string.Concat("<div>", radio, label, "</div>") : string.Concat(radio, label)); }
private void InitializeControls() { string[] sources = new string[] { ConvertToBlob, ConvertToFile }; foreach (var source in sources) { Radiobutton button = new Radiobutton { ID = Control.GetUniqueID("Radiobutton"), Header = source, Value = source.ToLowerInvariant(), Checked = source == sources[0] }; button.Click = "ConvertTargetClick(\"" + button.ID + "\")"; this.TargetGroup.Controls.Add(button); } this.TargetGroup.Value = sources[0].ToLowerInvariant(); }
/// <summary> Validates the radiobutton. </summary> private IEnumerable <ValidationInfo> Validate(Radiobutton radiobutton) { List <ValidationInfo> errors = new List <ValidationInfo>(); if (radiobutton.Required && string.IsNullOrEmpty(radiobutton.Value)) { ValidationInfo validationInfo = Mapper.Map <ValidationInfo>(radiobutton); validationInfo.ErrorType = ValidationErrorType.Required; errors.Add(validationInfo); } if (!string.IsNullOrWhiteSpace(radiobutton.Value) && !radiobutton.Items.IsNullOrEmpty()) { if (!radiobutton.Items.Any(x => x.Value == radiobutton.Value)) { ValidationInfo validationInfo = Mapper.Map <ValidationInfo>(radiobutton); validationInfo.ErrorType = ValidationErrorType.InvalidFormat; errors.Add(validationInfo); } } return(errors); }
private void InitializeControls() { string[] sources = new string[] { ConvertToBlob, ConvertToFile }; foreach (var source in sources) { Radiobutton button = new Radiobutton { ID = Control.GetUniqueID("Radiobutton"), Header = source, Value = source.ToLowerInvariant(), Checked = source == sources[0] }; button.Click = "ConvertTargetClick(\"" + button.ID + "\")"; this.TargetGroup.Controls.Add(button); } this.TargetGroup.Value = sources[0].ToLowerInvariant(); }
/// <summary> Parses the form object to a json object (for client-side code). </summary> public static string JsonRegistration(this Form form) { JObject jForm = new JObject(); jForm.Add(new JProperty("id", form.Name)); jForm.Add(new JProperty("action", form.Action)); JObject jMeta = new JObject(); jForm.Add(new JProperty("metadata", jMeta)); foreach (string key in form.Metadata.Keys) { jMeta.Add(new JProperty(key, form.Metadata[key])); } #region Fields JArray jFields = new JArray(); jForm.Add(new JProperty("fields", jFields)); IEnumerable <FormElement> elements = form.GetAllElements(); List <Calendar> calendarFields = elements.Where(x => x is Calendar).Select(x => x as Calendar).ToList(); foreach (FormElement element in elements) { if (element.Type == FormElementType.Block) { // Nothing } else if (element.Type == FormElementType.Html) { if ((element as HtmlElement).Editable) { jFields.Add(new JObject( new JProperty("id", element.Name), new JProperty("type", "html"), new JProperty("value", null), new JProperty("initialvalue", null))); } } else if (element.Type == FormElementType.Input) { jFields.Add(new JObject( new JProperty("id", element.Name), new JProperty("type", "input"), new JProperty("value", null), new JProperty("isValid", true), new JProperty("initialValue", null))); } else if (element.Type == FormElementType.Textarea) { jFields.Add(new JObject( new JProperty("id", element.Name), new JProperty("type", "textarea"), new JProperty("value", null), new JProperty("initialValue", null))); } else if (element.Type == FormElementType.Dropdown) { jFields.Add(new JObject( new JProperty("id", element.Name), new JProperty("type", "dropdown"), new JProperty("value", null), new JProperty("initialValue", null))); } else if (element.Type == FormElementType.Radiobutton) { Radiobutton radioGroup = element as Radiobutton; if (radioGroup.Items != null && radioGroup.Items.Any()) { foreach (RadiobuttonItem item in radioGroup.Items) { string id = string.Format("{0}_{1}", radioGroup.Name, item.Id); jFields.Add(new JObject( new JProperty("id", id), new JProperty("type", "radiobutton"), new JProperty("value", null), new JProperty("initialValue", null))); } } } else if (element.Type == FormElementType.Checkbox) { Checkbox checkboxGroup = element as Checkbox; if (checkboxGroup.Items != null && checkboxGroup.Items.Any()) { foreach (CheckboxItem item in checkboxGroup.Items) { string id = string.Format("{0}_{1}", checkboxGroup.Name, item.Id); jFields.Add(new JObject( new JProperty("id", id), new JProperty("type", "checkbox"), new JProperty("value", null), new JProperty("initialValue", null))); } } } else if (element.Type == FormElementType.Calendar) { Calendar calendar = element as Calendar; string refStart = null; string refEnd = null; if (calendar.IsStartDate && calendarFields.Count(x => x.IsEndDate) == 1) // Must be exact { // Find Matching End Date Calendar opposition = calendarFields.FirstOrDefault(x => x.IsEndDate); refEnd = opposition.Name; } else if (calendar.IsEndDate && calendarFields.Count(x => x.IsStartDate) == 1) // Must be exact { // Find Matching Start Date Calendar opposition = calendarFields.FirstOrDefault(x => x.IsStartDate); refStart = opposition.Name; } jFields.Add(new JObject( new JProperty("id", element.Name), new JProperty("type", "calendar"), new JProperty("value", null), new JProperty("initialValue", null), new JProperty("isStartDate", calendar.IsStartDate), new JProperty("isEndDate", calendar.IsEndDate), new JProperty("refStart", refStart), new JProperty("refDate", refEnd))); } else if (element.Type == FormElementType.Hidden) { jFields.Add(new JObject( new JProperty("id", element.Name), new JProperty("type", "hidden"), new JProperty("value", null), new JProperty("initialValue", null))); } else if (element.Type == FormElementType.Tagging) { jFields.Add(new JObject( new JProperty("id", element.Name), new JProperty("type", "tagging"), new JProperty("value", null), new JProperty("initialValue", null))); } else if (element.Type == FormElementType.Link) { jFields.Add(new JObject( new JProperty("id", element.Name), new JProperty("type", "link"), new JProperty("value", null), new JProperty("initialValue", null))); } else if (element.Type == FormElementType.List) { jFields.Add(new JObject( new JProperty("id", element.Name), new JProperty("type", "list"), new JProperty("value", null), new JProperty("initialValue", null))); } } #endregion #region Buttons JArray jButtons = new JArray(); jForm.Add(new JProperty("buttons", jButtons)); if (form.CancelButton != null) { jButtons.Add( new JObject( new JProperty("id", form.CancelButton.Name), new JProperty("type", "cancel"))); } if (form.SaveButton != null) { jButtons.Add( new JObject( new JProperty("id", form.SaveButton.Name), new JProperty("type", "save"))); } if (form.LinkButtons != null && form.LinkButtons.Any()) { foreach (Button button in form.LinkButtons) { jButtons.Add( new JObject( new JProperty("id", button.Name), new JProperty("type", "link"))); } } #endregion return(jForm.ToString()); }
private Control GetVariableEditor(IDictionary variable) { var value = variable["Value"]; var name = (string) variable["Name"]; var editor = variable["Editor"] as string; var type = value.GetType(); if (type == typeof (DateTime) || (!string.IsNullOrEmpty(editor) && (editor.IndexOf("date", StringComparison.OrdinalIgnoreCase) > -1 || editor.IndexOf("time", StringComparison.OrdinalIgnoreCase) > -1))) { var dateTimePicker = new DateTimePicker { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), ShowTime = (variable["ShowTime"] != null && (bool) variable["ShowTime"]) || (!string.IsNullOrEmpty(editor) && editor.IndexOf("time", StringComparison.OrdinalIgnoreCase) > -1) }; if (value is DateTime) { var date = (DateTime) value; if (date != DateTime.MinValue && date != DateTime.MaxValue) { dateTimePicker.Value = (date.Kind != DateTimeKind.Utc) ? DateUtil.ToIsoDate(TypeResolver.Resolve<IDateConverter>("IDateConverter").ToServerTime(date)) : DateUtil.ToIsoDate(date); } } else { dateTimePicker.Value = value as string ?? string.Empty; } return dateTimePicker; } if (!string.IsNullOrEmpty(editor) && editor.IndexOf("rule", StringComparison.OrdinalIgnoreCase) > -1) { string editorId = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name+"_"); Sitecore.Context.ClientPage.ServerProperties[editorId] = value; var rulesBorder = new Border { Class = "rulesWrapper", ID = editorId }; Button rulesEditButton = new Button { Header = "Edit rule", Class = "scButton edit-button rules-edit-button", Click = "EditConditionClick(\\\"" + editorId + "\\\")" }; rulesBorder.Controls.Add(rulesEditButton); var rulesRender = new Literal { ID = editorId + "_renderer", Text = GetRuleConditionsHtml( string.IsNullOrEmpty(value as string) ? "<ruleset />" : value as string) }; rulesRender.Class = rulesRender.Class + " varRule"; rulesBorder.Controls.Add(rulesRender); return rulesBorder; } if (!string.IsNullOrEmpty(editor) && (editor.IndexOf("treelist", StringComparison.OrdinalIgnoreCase) > -1 || (editor.IndexOf("multilist", StringComparison.OrdinalIgnoreCase) > -1) || (editor.IndexOf("droplist", StringComparison.OrdinalIgnoreCase) > -1))) { Item item = null; var strValue = string.Empty; if (value is Item) { item = (Item) value; strValue = item.ID.ToString(); } else if (value is IEnumerable<object>) { List<Item> items = (value as IEnumerable<object>).Cast<Item>().ToList(); item = items.FirstOrDefault(); strValue = string.Join("|", items.Select(i => i.ID.ToString()).ToArray()); } var dbName = item == null ? Sitecore.Context.ContentDatabase.Name : item.Database.Name; if (editor.IndexOf("multilist", StringComparison.OrdinalIgnoreCase) > -1) { var multiList = new MultilistExtended { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Value = strValue, Database = dbName, ItemID = "{11111111-1111-1111-1111-111111111111}", Source = variable["Source"] as string ?? "/sitecore", }; multiList.SetLanguage(Sitecore.Context.Language.Name); multiList.Class += " treePicker"; return multiList; } if (editor.IndexOf("droplist", StringComparison.OrdinalIgnoreCase) > -1) { var lookup = new LookupEx { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Database = dbName, ItemID = (item != null ? item.ID.ToString() : "{11111111-1111-1111-1111-111111111111}"), Source = variable["Source"] as string ?? "/sitecore", ItemLanguage = Sitecore.Context.Language.Name, Value = (item != null ? item.ID.ToString() : "{11111111-1111-1111-1111-111111111111}") }; lookup.Class += " textEdit"; return lookup; } var treeList = new TreeList { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Value = strValue, AllowMultipleSelection = true, DatabaseName = dbName, Database = dbName, Source = variable["Source"] as string ?? "/sitecore", DisplayFieldName = variable["DisplayFieldName"] as string ?? "__DisplayName" }; treeList.Class += " treePicker"; return treeList; } if (type == typeof (Item) || (!string.IsNullOrEmpty(editor) && (editor.IndexOf("item", StringComparison.OrdinalIgnoreCase) > -1))) { var item = value as Item; var source = variable["Source"] as string; var root = variable["Root"] as string; var sourceRoot = string.IsNullOrEmpty(source) ? "/sitecore" : StringUtil.ExtractParameter("DataSource", source); var dataContext = item != null ? new DataContext { DefaultItem = item.Paths.Path, ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("dataContext"), Parameters = string.IsNullOrEmpty(source) ? "databasename=" + item.Database.Name : source, DataViewName = "Master", Root = string.IsNullOrEmpty(root) ? sourceRoot : root, Database = item.Database.Name, Selected = new[] {new DataUri(item.ID, item.Language, item.Version)}, Folder = item.ID.ToString(), Language = item.Language, Version = item.Version } : new DataContext { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("dataContext"), Parameters = string.IsNullOrEmpty(source) ? "databasename=master" : source, DataViewName = "Master", Root = string.IsNullOrEmpty(root) ? sourceRoot : root }; DataContextPanel.Controls.Add(dataContext); var treePicker = new TreePicker { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Value = item != null ? item.ID.ToString() : string.Empty, DataContext = dataContext.ID, AllowNone = !string.IsNullOrEmpty(editor) && (editor.IndexOf("allownone", StringComparison.OrdinalIgnoreCase) > -1) }; treePicker.Class += " treePicker"; return treePicker; } if (type == typeof (bool) || (!string.IsNullOrEmpty(editor) && (editor.IndexOf("bool", StringComparison.OrdinalIgnoreCase) > -1))) { var checkboxBorder = new Border { Class = "checkBoxWrapper", ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_") }; var checkBox = new Checkbox { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Header = (string) variable["Title"], HeaderStyle = "display:inline-block;", Checked = (bool) value, Class = "varCheckbox" }; checkboxBorder.Controls.Add(checkBox); return checkboxBorder; } if (!string.IsNullOrEmpty(editor)) { var showRoles = editor.IndexOf("role", StringComparison.OrdinalIgnoreCase) > -1; var showUsers = editor.IndexOf("user", StringComparison.OrdinalIgnoreCase) > -1; var multiple = editor.IndexOf("multiple", StringComparison.OrdinalIgnoreCase) > -1; if (showRoles || showUsers) { var picker = new UserPicker(); picker.Style.Add("float", "left"); picker.ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"); picker.Class += " scContentControl textEdit clr" + value.GetType().Name; picker.Value = (value is IEnumerable<object>) ? String.Join("|", ((IEnumerable<object>)value).Select(x => x.ToString()).ToArray()) : value.ToString(); picker.ExcludeRoles = !showRoles; picker.ExcludeUsers = !showUsers; picker.DomainName = variable["Domain"] as string ?? variable["DomainName"] as string; picker.Multiple = multiple; picker.Click = "UserPickerClick(" + picker.ID + ")"; return picker; } } Sitecore.Web.UI.HtmlControls.Control edit; if (!string.IsNullOrEmpty(editor) && editor.IndexOf("info", StringComparison.OrdinalIgnoreCase) > -1) { return new Literal {Text = value.ToString(), Class = "varHint"}; } if (variable["lines"] != null && ((int) variable["lines"] > 1)) { edit = new Memo(); edit.Attributes.Add("rows", variable["lines"].ToString()); } else if (variable["Options"] != null) { var psOptions = variable["Options"].BaseObject(); var options = new OrderedDictionary(); if (psOptions is OrderedDictionary) { options = psOptions as OrderedDictionary; } else if (psOptions is string) { var strOptions = ((string) variable["Options"]).Split('|'); var i = 0; while (i < strOptions.Length) { options.Add(strOptions[i++], strOptions[i++]); } } else if (psOptions is Hashtable) { var hashOptions = variable["Options"] as Hashtable; foreach (var key in hashOptions.Keys) { options.Add(key, hashOptions[key]); } } else { throw new Exception("Checklist options format unrecognized."); } if (!string.IsNullOrEmpty(editor)) { if (editor.IndexOf("radio", StringComparison.OrdinalIgnoreCase) > -1) { var radioList = new Groupbox { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), // Header = (string) variable["Title"], Class = "scRadioGroup" }; foreach (var option in options.Keys) { var optionName = option.ToString(); var optionValue = options[optionName].ToString(); var item = new Radiobutton { Header = optionName, Value = optionValue, ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID(radioList.ID), Name = radioList.ID, Checked = optionValue == value.ToString() }; radioList.Controls.Add(item); radioList.Controls.Add(new Literal("<br/>")); } return radioList; } if (editor.IndexOf("check", StringComparison.OrdinalIgnoreCase) > -1) { var checkList = new PSCheckList { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), HeaderStyle = "margin-top:20px; display:inline-block;", ItemID = "{11111111-1111-1111-1111-111111111111}" }; checkList.SetItemLanguage(Sitecore.Context.Language.Name); string[] values; if (value is string) { values = value.ToString().Split('|'); } else if (value is IEnumerable) { values = ((value as IEnumerable).Cast<object>().Select(s => s == null ? "" : s.ToString())).ToArray(); } else { values = new[] {value.ToString()}; } foreach (var item in from object option in options.Keys select option.ToString() into optionName let optionValue = options[optionName].ToString() select new ChecklistItem { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID(checkList.ID), Header = optionName, Value = optionValue, Checked = values.Contains(optionValue, StringComparer.OrdinalIgnoreCase) }) { checkList.Controls.Add(item); } checkList.TrackModified = false; checkList.Disabled = false; return checkList; } } edit = new Combobox(); var placeholder = variable["Placeholder"]; if (placeholder is string) { var option = new ListItem { Header = placeholder.ToString(), Value = "", Selected = true }; edit.Controls.Add(option); } foreach (var option in options.Keys) { var optionName = option.ToString(); var optionValue = options[optionName].ToString(); var item = new ListItem { Header = optionName, Value = optionValue }; edit.Controls.Add(item); } } else { var placeholder = variable["Placeholder"]; if (!string.IsNullOrEmpty(editor) && editor.IndexOf("pass", StringComparison.OrdinalIgnoreCase) > -1) { edit = new PasswordExtended(); if (placeholder is string) { ((PasswordExtended)edit).PlaceholderText = placeholder.ToString(); } } else { edit = new EditExtended(); if (placeholder is string) { ((EditExtended)edit).PlaceholderText = placeholder.ToString(); } } } var tip = (variable["Tooltip"] as string); if (!String.IsNullOrEmpty(tip)) { edit.ToolTip = tip.RemoveHtmlTags(); } edit.Style.Add("float", "left"); edit.ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"); edit.Class += " scContentControl textEdit clr" + value.GetType().Name; edit.Value = value.ToString(); return edit; }
private Control GetVariableEditor(IDictionary variable) { var value = variable["Value"]; var name = (string)variable["Name"]; var editor = variable["Editor"] as string; var type = value.GetType(); if (type == typeof(DateTime) || (!string.IsNullOrEmpty(editor) && (editor.IndexOf("date", StringComparison.OrdinalIgnoreCase) > -1 || editor.IndexOf("time", StringComparison.OrdinalIgnoreCase) > -1))) { var dateTimePicker = new DateTimePicker { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), ShowTime = (variable["ShowTime"] != null && (bool)variable["ShowTime"]) || (!string.IsNullOrEmpty(editor) && editor.IndexOf("time", StringComparison.OrdinalIgnoreCase) > -1) }; if (value is DateTime) { var date = (DateTime)value; if (date != DateTime.MinValue && date != DateTime.MaxValue) { dateTimePicker.Value = date.Kind != DateTimeKind.Utc ? DateUtil.ToIsoDate(TypeResolver.Resolve <IDateConverter>().ToServerTime(date)) : DateUtil.ToIsoDate(date); } } else { dateTimePicker.Value = value as string ?? string.Empty; } return(dateTimePicker); } if (!string.IsNullOrEmpty(editor) && editor.IndexOf("rule", StringComparison.OrdinalIgnoreCase) > -1) { var editorId = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"); Sitecore.Context.ClientPage.ServerProperties[editorId] = value; var rulesBorder = new Border { Class = "rulesWrapper", ID = editorId }; var rulesEditButton = new Button { Header = Texts.PowerShellMultiValuePrompt_GetVariableEditor_Edit_rule, Class = "scButton edit-button rules-edit-button", Click = "EditConditionClick(\\\"" + editorId + "\\\")" }; rulesBorder.Controls.Add(rulesEditButton); var rulesRender = new Literal { ID = editorId + "_renderer", Text = GetRuleConditionsHtml( string.IsNullOrEmpty(value as string) ? "<ruleset />" : value as string) }; rulesRender.Class = rulesRender.Class + " varRule"; rulesBorder.Controls.Add(rulesRender); return(rulesBorder); } if (!string.IsNullOrEmpty(editor) && (editor.IndexOf("treelist", StringComparison.OrdinalIgnoreCase) > -1 || (editor.IndexOf("multilist", StringComparison.OrdinalIgnoreCase) > -1) || (editor.IndexOf("droplist", StringComparison.OrdinalIgnoreCase) > -1) || (editor.IndexOf("droptree", StringComparison.OrdinalIgnoreCase) > -1))) { Item item = null; var strValue = string.Empty; if (value is Item) { item = (Item)value; strValue = item.ID.ToString(); } else if (value is IEnumerable <object> ) { var items = (value as IEnumerable <object>).Cast <Item>().ToList(); item = items.FirstOrDefault(); strValue = string.Join("|", items.Select(i => i.ID.ToString()).ToArray()); } var dbName = item == null ? Sitecore.Context.ContentDatabase.Name : item.Database.Name; if (editor.IndexOf("multilist", StringComparison.OrdinalIgnoreCase) > -1) { var multiList = new MultilistExtended { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Value = strValue, Database = dbName, ItemID = ItemIDs.RootID.ToString(), Source = variable["Source"] as string ?? "/sitecore", }; multiList.SetLanguage(Sitecore.Context.Language.Name); multiList.Class += " treePicker"; return(multiList); } if (editor.IndexOf("droplist", StringComparison.OrdinalIgnoreCase) > -1) { if (Sitecore.Context.ContentDatabase?.Name != dbName) { // this control will crash if if content database is different than the items fed to it. return(new Literal { Text = "<span style='color: red'>" + Translate.Text( Texts .PowerShellMultiValuePrompt_GetVariableEditor_DropList_control_cannot_render_items_from_the_database___0___because_it_its_not_the_same_as___1___which_is_the_current_content_database__, dbName, Sitecore.Context.ContentDatabase?.Name) + "</span>", Class = "varHint" }); } var lookup = new LookupEx { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Database = dbName, ItemID = item?.ID.ToString() ?? ItemIDs.RootID.ToString(), Source = variable["Source"] as string ?? "/sitecore", ItemLanguage = Sitecore.Context.Language.Name, Value = item?.ID.ToString() ?? ItemIDs.RootID.ToString() }; lookup.Class += " textEdit"; return(lookup); } if (editor.IndexOf("droptree", StringComparison.OrdinalIgnoreCase) > -1) { var tree = new Tree { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Database = dbName, ItemID = item?.ID.ToString() ?? ItemIDs.Null.ToString(), Source = variable["Source"] as string ?? "", ItemLanguage = Sitecore.Context.Language.Name, Value = item?.ID.ToString() ?? "" }; tree.Class += " textEdit"; return(tree); } var treeList = new TreeList { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Value = strValue, AllowMultipleSelection = true, DatabaseName = dbName, Database = dbName, Source = variable["Source"] as string ?? "/sitecore", DisplayFieldName = variable["DisplayFieldName"] as string ?? "__DisplayName" }; treeList.Class += " treePicker"; return(treeList); } if (type == typeof(Item) || (!string.IsNullOrEmpty(editor) && (editor.IndexOf("item", StringComparison.OrdinalIgnoreCase) > -1))) { var item = value as Item; var source = variable["Source"] as string; var root = variable["Root"] as string; var sourceRoot = string.IsNullOrEmpty(source) ? "/sitecore" : StringUtil.ExtractParameter("DataSource", source); var dataContext = item != null ? new DataContext { DefaultItem = item.Paths.Path, ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("dataContext"), Parameters = string.IsNullOrEmpty(source) ? "databasename=" + item.Database.Name : source, DataViewName = "Master", Root = string.IsNullOrEmpty(root) ? sourceRoot : root, Database = item.Database.Name, Selected = new[] { new DataUri(item.ID, item.Language, item.Version) }, Folder = item.ID.ToString(), Language = item.Language, Version = item.Version } : new DataContext { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("dataContext"), Parameters = string.IsNullOrEmpty(source) ? "databasename=master" : source, DataViewName = "Master", Root = string.IsNullOrEmpty(root) ? sourceRoot : root }; DataContextPanel.Controls.Add(dataContext); var treePicker = new TreePicker { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Value = item != null?item.ID.ToString() : string.Empty, DataContext = dataContext.ID, AllowNone = !string.IsNullOrEmpty(editor) && (editor.IndexOf("allownone", StringComparison.OrdinalIgnoreCase) > -1) }; treePicker.Class += " treePicker"; return(treePicker); } if (type == typeof(bool) || (!string.IsNullOrEmpty(editor) && (editor.IndexOf("bool", StringComparison.OrdinalIgnoreCase) > -1))) { var checkboxBorder = new Border { Class = "checkBoxWrapper", ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_") }; var checkBox = new Checkbox { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), Header = (string)variable["Title"], HeaderStyle = "display:inline-block;", Checked = (bool)value, Class = "varCheckbox" }; checkboxBorder.Controls.Add(checkBox); return(checkboxBorder); } if (!string.IsNullOrEmpty(editor)) { var showRoles = editor.IndexOf("role", StringComparison.OrdinalIgnoreCase) > -1; var showUsers = editor.IndexOf("user", StringComparison.OrdinalIgnoreCase) > -1; var multiple = editor.IndexOf("multiple", StringComparison.OrdinalIgnoreCase) > -1; if (showRoles || showUsers) { var picker = new UserPicker(); picker.Style.Add("float", "left"); picker.ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"); picker.Class += " scContentControl textEdit clr" + value.GetType().Name; picker.Value = value is IEnumerable <object> ?string.Join("|", ((IEnumerable <object>)value).Select(x => x.ToString()).ToArray()) : value.ToString(); picker.ExcludeRoles = !showRoles; picker.ExcludeUsers = !showUsers; picker.DomainName = variable["Domain"] as string ?? variable["DomainName"] as string; picker.Multiple = multiple; picker.Click = "UserPickerClick(" + picker.ID + ")"; return(picker); } } Sitecore.Web.UI.HtmlControls.Control edit; if (!string.IsNullOrEmpty(editor) && editor.IndexOf("info", StringComparison.OrdinalIgnoreCase) > -1) { return(new Literal { Text = value.ToString(), Class = "varHint" }); } if (variable["lines"] != null && ((int)variable["lines"] > 1)) { edit = new Memo(); edit.Attributes.Add("rows", variable["lines"].ToString()); var placeholder = variable["Placeholder"]; if (placeholder is string) { edit.Attributes.Add("Placeholder", placeholder.ToString()); } } else if (variable["Options"] != null) { var psOptions = variable["Options"].BaseObject(); var options = new OrderedDictionary(); if (psOptions is OrderedDictionary) { options = psOptions as OrderedDictionary; } else if (psOptions is string) { var strOptions = ((string)variable["Options"]).Split('|'); var i = 0; while (i < strOptions.Length) { options.Add(strOptions[i++], strOptions[i++]); } } else if (psOptions is Hashtable) { var hashOptions = variable["Options"] as Hashtable; foreach (var key in hashOptions.Keys) { options.Add(key, hashOptions[key]); } } else { throw new Exception("Checklist options format unrecognized."); } if (!string.IsNullOrEmpty(editor)) { if (editor.IndexOf("radio", StringComparison.OrdinalIgnoreCase) > -1) { var radioList = new Groupbox { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"), // Header = (string) variable["Title"], Class = "scRadioGroup" }; foreach (var option in options.Keys) { var optionName = option.ToString(); var optionValue = options[optionName].ToString(); var item = new Radiobutton { Header = optionName, Value = optionValue, ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID(radioList.ID), Name = radioList.ID, Checked = optionValue == value.ToString() }; radioList.Controls.Add(item); radioList.Controls.Add(new Literal("<br/>")); } return(radioList); } if (editor.IndexOf("check", StringComparison.OrdinalIgnoreCase) > -1) { var checkBorder = new Border { Class = "checkListWrapper", ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_") }; var editorId = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"); var link = new Literal( @"<div class='checkListActions'>" + @"<a href='#' class='scContentButton' onclick=""javascript:return scForm.postEvent(this,event,'checklist:checkall(id=" + editorId + @")')"">" + Translate.Text("Select all") + "</a> | " + @"<a href='#' class='scContentButton' onclick=""javascript:return scForm.postEvent(this,event,'checklist:uncheckall(id=" + editorId + @")')"">" + Translate.Text("Unselect all") + "</a> | " + @"<a href='#' class='scContentButton' onclick=""javascript:return scForm.postEvent(this,event,'checklist:invert(id=" + editorId + @")')"">" + Translate.Text("Invert selection") + "</a>" + @"</div>"); checkBorder.Controls.Add(link); var checkList = new PSCheckList { ID = editorId, HeaderStyle = "margin-top:20px; display:inline-block;", ItemID = ItemIDs.RootID.ToString() }; checkList.SetItemLanguage(Sitecore.Context.Language.Name); string[] values; if (value is string) { values = value.ToString().Split('|'); } else if (value is IEnumerable) { values = (value as IEnumerable).Cast <object>() .Select(s => s == null ? "" : s.ToString()) .ToArray(); } else { values = new[] { value.ToString() }; } foreach (var item in from object option in options.Keys select option.ToString() into optionName let optionValue = options[optionName].ToString() select new ChecklistItem { ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID(checkList.ID), Header = optionName, Value = optionValue, Checked = values.Contains(optionValue, StringComparer.OrdinalIgnoreCase) }) { checkList.Controls.Add(item); } checkList.TrackModified = false; checkList.Disabled = false; checkBorder.Controls.Add(checkList); return(checkBorder); } } edit = new Combobox(); var placeholder = variable["Placeholder"]; if (placeholder is string) { var option = new ListItem { Header = placeholder.ToString(), Value = "", Selected = true }; edit.Controls.Add(option); } foreach (var option in options.Keys) { var optionName = option.ToString(); var optionValue = options[optionName].ToString(); var item = new ListItem { Header = optionName, Value = optionValue }; edit.Controls.Add(item); } } else { var placeholder = variable["Placeholder"]; if (!string.IsNullOrEmpty(editor) && editor.IndexOf("pass", StringComparison.OrdinalIgnoreCase) > -1) { edit = new PasswordExtended(); if (placeholder is string) { ((PasswordExtended)edit).PlaceholderText = placeholder.ToString(); } } else { edit = new EditExtended(); if (placeholder is string) { ((EditExtended)edit).PlaceholderText = placeholder.ToString(); } } } var tip = variable["Tooltip"] as string; if (!string.IsNullOrEmpty(tip)) { edit.ToolTip = tip.RemoveHtmlTags(); } edit.Style.Add("float", "left"); edit.ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"); edit.Class += " scContentControl textEdit clr" + value.GetType().Name; edit.Value = value.ToString(); return(edit); }
//=== Initialization /// <summary> Inits a new field for the specified type. </summary> /// <param name="languageId"> This is needed for the calender field. </param> public static FormElement InitField(FormElementType Type, int?languageId = null, int?id = null, string label = null, string description = null, bool?required = null, bool applyBasicSettings = false) { switch (Type) { case Enums.FormElementType.Calendar: Calendar c = Calendar.Init(languageId: languageId, id: id, label: label, description: description, required: required); ; if (applyBasicSettings) { c.AdvancedMode = false; c.DefaultDate = "*|DATETIME:NOW|*"; } return(c); case Enums.FormElementType.Checkbox: Checkbox cb = Checkbox.Init(id: id, label: label, description: description); if (applyBasicSettings) { cb.Min = required.GetValueOrDefault() ? 1 : 0; cb.Max = 1; } return(cb); case Enums.FormElementType.Dropdown: Dropdown dd = Dropdown.Init(id: id, label: label, description: description, required: required); if (applyBasicSettings) { dd.Multiple = false; } return(dd); //case Enums.FormElementType.FileUpload: // return FileUpload.Init(id: id, label: label, description: description, required: required); case Enums.FormElementType.Html: HtmlElement html = HtmlElement.Init(id: id, label: label, description: description); if (applyBasicSettings) { html.Editable = true; html.EditorProfile = HtmlElement.EEditorProfile.Basic; html.Required = required.GetValueOrDefault(); } return(html); case Enums.FormElementType.Input: Input input = Input.Init(id: id, label: label, description: description, required: required); if (applyBasicSettings) { input.MaxLength = 255; input.MinLength = 0; } return(input); case Enums.FormElementType.Radiobutton: Radiobutton rb = Radiobutton.Init(id: id, label: label, description: description, required: required); //if (applyBasicSettings) //{ // None available //} return(rb); case Enums.FormElementType.Textarea: Textarea ta = Textarea.Init(id: id, label: label, description: description, required: required); //if (applyBasicSettings) //{ // None available //} return(ta); case Enums.FormElementType.Link: Link link = Link.Init(id: id, label: label, description: description, required: required); //if (applyBasicSettings) //{ // None available //} return(link); case Enums.FormElementType.Label: Label l = Label.Init(id: id, label: label, description: description); //if (applyBasicSettings) //{ // None available //} return(l); case Enums.FormElementType.List: ListElement list = ListElement.Init(id: id, label: label, description: description); //if (applyBasicSettings) //{ // None available //} return(list); default: throw new Exception("Init: Field type is not supported."); // Hidden, Tagging, etc. } }