public virtual void SetProperties(Control editor, Sitecore.Shell.Applications.ContentManager.Editor.Field field, bool readOnly) { Assert.ArgumentNotNull(editor, "editor"); Assert.ArgumentNotNull(field, "field"); Sitecore.Reflection.ReflectionUtil.SetProperty(editor, "ID", field.ControlID); Sitecore.Reflection.ReflectionUtil.SetProperty(editor, "ItemID", field.ItemField.Item.ID.ToString()); Sitecore.Reflection.ReflectionUtil.SetProperty(editor, "ItemVersion", field.ItemField.Item.Version.ToString()); Sitecore.Reflection.ReflectionUtil.SetProperty(editor, "ItemLanguage", field.ItemField.Item.Language.ToString()); Sitecore.Reflection.ReflectionUtil.SetProperty(editor, "FieldID", field.ItemField.ID.ToString()); Sitecore.Reflection.ReflectionUtil.SetProperty(editor, "Source", GetFieldSource(field)); Sitecore.Reflection.ReflectionUtil.SetProperty(editor, "ReadOnly", readOnly); Sitecore.Reflection.ReflectionUtil.SetProperty(editor, "Disabled", readOnly); //if the control has the field type item id property string fieldTypeId = string.Empty; if (!string.IsNullOrEmpty(field.TemplateField.Type)) { //get field type by name Item fieldType = GetFieldType(field.TemplateField.Type); if (fieldType.IsNotNull()) { fieldTypeId = fieldType.ID.ToString(); } } Sitecore.Reflection.ReflectionUtil.SetProperty(editor, "FieldTypeItemId", fieldTypeId); }
public static void SetStyle(Control editor, Sitecore.Shell.Applications.ContentManager.Editor.Field field) { Assert.ArgumentNotNull(editor, "editor"); Assert.ArgumentNotNull(field, "field"); if (!string.IsNullOrEmpty(field.ItemField.Style)) { CssStyleCollection property = Sitecore.Reflection.ReflectionUtil.GetProperty(editor, "Style") as CssStyleCollection; if (property != null) { UIUtil.ParseStyle(property, field.ItemField.Style); } } }
/// <summary> /// This method will return the field source but will also check if the source is parameterized and if the datasource has a query. if so it will convert the query into an item path. /// </summary> /// <param name="field"></param> /// <returns></returns> public virtual string GetFieldSource(Sitecore.Shell.Applications.ContentManager.Editor.Field field) { if (field == null || field.ItemField == null || field.ItemField.Item == null || string.IsNullOrEmpty(field.ItemField.Source)) { return(string.Empty); } string rawSource = field.ItemField.Source; return((!string.IsNullOrEmpty(rawSource) && rawSource.IndexOf("datasource=query:", StringComparison.OrdinalIgnoreCase) >= 0) ? ReplaceQueriesInDataSource(rawSource, field.ItemField.Item) : rawSource); }
public virtual void RenderMenuButtons(Control parent, Sitecore.Shell.Applications.ContentManager.Editor.Field field, Item fieldType, bool readOnly) { Assert.ArgumentNotNull(parent, "parent"); Assert.ArgumentNotNull(field, "field"); Assert.ArgumentNotNull(fieldType, "fieldType"); if (this.Arguments.ShowInputBoxes && !UserOptions.ContentEditor.ShowRawValues) { Item menu = fieldType.Children["Menu"]; if ((menu != null) && menu.HasChildren) { this.AddLiteralControl(parent, this.RenderMenuButtons(field, menu, readOnly)); } } }
private void RenderResizable(Control parent, Sitecore.Shell.Applications.ContentManager.Editor.Field field) { string str = field.TemplateField.Type; if (!string.IsNullOrEmpty(str)) { FieldType fieldType = FieldTypeManager.GetFieldType(str); if ((fieldType != null) && fieldType.Resizable) { string text = string.Concat(new object[] { "<div style=\"cursor:row-resize\" onmousedown=\"scContent.fieldResizeDown(this, event)\" onmousemove=\"scContent.fieldResizeMove(this, event)\" onmouseup=\"scContent.fieldResizeUp(this, event, '" , field.TemplateField.ID.ToShortID(), "')\">", Images.GetSpacer(1, 4), "</div>" }); this.AddLiteralControl(parent, text); } } }
public virtual void RenderField(Control parent, Sitecore.Shell.Applications.ContentManager.Editor.Field field, Item fieldType, bool readOnly) { string str; Assert.ArgumentNotNull(parent, "parent"); Assert.ArgumentNotNull(field, "field"); Assert.ArgumentNotNull(fieldType, "fieldType"); if (field.ItemField.IsBlobField && !this.Arguments.ShowInputBoxes) { readOnly = true; str = Translate.Text("[Blob Value]"); } else { str = field.Value; } this.RenderField(parent, field, fieldType, readOnly, str); }
public virtual void RenderField(Control parent, Sitecore.Shell.Applications.ContentManager.Editor.Field field, bool readOnly) { Assert.ArgumentNotNull(parent, "parent"); Assert.ArgumentNotNull(field, "field"); Field itemField = field.ItemField; Item fieldType = this.GetFieldType(itemField); if (fieldType != null) { if (!itemField.CanWrite) { readOnly = true; } this.RenderMarkerBegin(parent, field.ControlID); this.RenderMenuButtons(parent, field, fieldType, readOnly); this.RenderLabel(parent, field, fieldType, readOnly); this.RenderField(parent, field, fieldType, readOnly); this.RenderMarkerEnd(parent); } }
// Methods public void AddEditorControl(Control parent, Control editor, Sitecore.Shell.Applications.ContentManager.Editor.Field field, bool hasRibbon, bool readOnly, string value) { Assert.ArgumentNotNull(parent, "parent"); Assert.ArgumentNotNull(editor, "editor"); Assert.ArgumentNotNull(field, "field"); Assert.ArgumentNotNull(value, "value"); SetProperties(editor, field, readOnly); this.SetValue(editor, value); EditorFieldContainer container = new EditorFieldContainer(editor) { ID = field.ControlID + "_container" }; Control control = container; Sitecore.Context.ClientPage.AddControl(parent, control); SetProperties(editor, field, readOnly); SetAttributes(editor, field, hasRibbon); SetStyle(editor, field); this.SetValue(editor, value); }
public static void SetAttributes(Control editor, Sitecore.Shell.Applications.ContentManager.Editor.Field field, bool hasRibbon) { Assert.ArgumentNotNull(editor, "editor"); Assert.ArgumentNotNull(field, "field"); AttributeCollection property = Sitecore.Reflection.ReflectionUtil.GetProperty(editor, "Attributes") as AttributeCollection; if (property != null) { string str = string.Concat(new object[] { field.ItemField.Item.Uri, "&fld=", field.ItemField.ID, "&ctl=", field.ControlID }); if (hasRibbon) { str = str + "&rib=1"; } property["onactivate"] = "javascript:return scContent.activate(this,event,'" + str + "')"; property["ondeactivate"] = "javascript:return scContent.deactivate(this,event,'" + str + "')"; if (!UIUtil.IsIE()) { property["onfocus"] = "javascript:return scContent.activate(this,event,'" + str + "')"; property["onblur"] = "javascript:return scContent.deactivate(this,event,'" + str + "')"; } } }
private string RenderMenuButtons(Sitecore.Shell.Applications.ContentManager.Editor.Field field, Item menu, bool readOnly) { Assert.ArgumentNotNull(field, "field"); Assert.ArgumentNotNull(menu, "menu"); HtmlTextWriter writer = new HtmlTextWriter(new StringWriter()); writer.Write("<div class=\"scContentButtons\">"); bool flag = true; foreach (Item item in menu.Children) { if (!this.IsFieldEditor || MainUtil.GetBool(item["Show In Field Editor"], false)) { if (!flag) { writer.Write("·"); } flag = false; string clickEvent = string.Empty; if (!string.IsNullOrEmpty(item["Message"])) { clickEvent = item["Message"]; } FieldPlaceholderArgs fieldPlaceholderArgs = new FieldPlaceholderArgs(); fieldPlaceholderArgs.FieldId = field.ControlID; if (this.CurrentItem != null) { fieldPlaceholderArgs.ItemId = this.CurrentItem.ID.ToString(); fieldPlaceholderArgs.InnerItem = CurrentItem; fieldPlaceholderArgs.TemplateItem = CurrentItem.Template; } fieldPlaceholderArgs.Source = GetFieldSource(field); fieldPlaceholderArgs.ClickEvent = item["Message"]; fieldPlaceholderArgs.FieldItem = menu; IFieldPlaceholderProcessor fieldPlaceholderProcessor = FieldPlaceholderProcessorFactory.GetProcessor(); if (fieldPlaceholderProcessor != null) { clickEvent = fieldPlaceholderProcessor.Process(fieldPlaceholderArgs); if (string.IsNullOrEmpty(clickEvent)) { clickEvent = string.Empty; } } //to send a message to the messaging system (handleMessage) if (item["Client Event"] == null || string.IsNullOrEmpty(item["Client Event"]) || item["Client Event"] == "0") { clickEvent = Sitecore.Context.ClientPage.GetClientEvent(clickEvent); } if (readOnly) { writer.Write("<span class=\"scContentButtonDisabled\">"); writer.Write(item["Display Name"]); writer.Write("</span>"); } else { string cssClass = "scContentButton"; if (!string.IsNullOrEmpty(item["CssClass"])) { cssClass = item["CssClass"]; } string innerHtml = item["Inner Html"]; if (string.IsNullOrEmpty(innerHtml)) { innerHtml = item["Display Name"]; } writer.Write("<a href=\"#\" class=\"" + cssClass + "\" onclick=\"" + clickEvent + "\">"); writer.Write(innerHtml); writer.Write("</a>"); } } } writer.Write("</div>"); return(writer.InnerWriter.ToString()); }
public void RenderLabel(Control parent, Sitecore.Shell.Applications.ContentManager.Editor.Field field, Item fieldType, bool readOnly) { Assert.ArgumentNotNull(parent, "parent"); Assert.ArgumentNotNull(field, "field"); Assert.ArgumentNotNull(fieldType, "fieldType"); Field itemField = field.ItemField; Language language = this.Arguments.Language; Assert.IsNotNull(language, "language"); if (itemField.Language != language) { Item item = ItemManager.GetItem(field.ItemField.Item.ID, language, Sitecore.Data.Version.Latest, field.ItemField.Item.Database); if (item != null) { itemField = item.Fields[itemField.ID]; } } string name = itemField.Name; if (!string.IsNullOrEmpty(itemField.DisplayName)) { name = itemField.DisplayName; } name = Translate.Text(name); string toolTip = itemField.ToolTip; if (!string.IsNullOrEmpty(toolTip)) { toolTip = Translate.Text(toolTip); if (toolTip.EndsWith(".")) { toolTip = StringUtil.Left(toolTip, toolTip.Length - 1); } name = name + " - " + toolTip; } name = HttpUtility.HtmlEncode(name); bool separator = false; StringBuilder attributes = new StringBuilder(200); if (this.Arguments.IsAdministrator && (itemField.Unversioned || itemField.Shared)) { attributes.Append("<span class=\"scEditorFieldLabelAdministrator\"> ["); if (itemField.Unversioned) { attributes.Append(Translate.Text("unversioned")); separator = true; } if (itemField.Shared) { if (separator) { attributes.Append(", "); } attributes.Append(Translate.Text("shared")); separator = true; } } Field field3 = field.ItemField; Action <string> action = delegate(string text) { attributes.Append(separator ? ", " : "<span class=\"scEditorFieldLabelAdministrator\"> ["); attributes.Append(Translate.Text(text)); }; if (field3.InheritsValueFromOtherItem) { action("original value"); } else if (field3.ContainsStandardValue) { action("standard value"); } if (attributes.Length > 0) { attributes.Append("]</span>"); } name = name + attributes.ToString() + ":"; if (readOnly) { name = "<span class=\"scEditorFieldLabelDisabled\">" + name + "</span>"; } string helpLink = itemField.HelpLink; if (helpLink.Length > 0) { name = "<a class=\"scEditorFieldLabelLink\" href=\"" + helpLink + "\" target=\"__help\">" + name + "</a>"; } string str4 = string.Empty; if (itemField.Description.Length > 0) { str4 = " title=\"" + itemField.Description + "\""; } string str5 = "scEditorFieldLabel"; if ((UserOptions.View.UseSmartTags && !readOnly) && !UserOptions.ContentEditor.ShowRawValues) { Item item2 = fieldType.Children["Menu"]; if (item2 != null) { ChildList children = item2.Children; int count = children.Count; if (count > 0) { string str6 = children[0]["Display Name"]; name = (string.Concat(new object[] { "<span id=\"SmartTag_", field.ControlID, "\" onmouseover='javascript:scContent.smartTag(this, event, \"", field.ControlID, "\", ", StringUtil.EscapeJavascriptString(str6), ",\"", count, "\")'>" }) + Images.GetImage("Images/SmartTag.png", 11, 11, "middle", "0px 4px 0px 0px")) + "</span>" + name; } } } name = "<div class=\"" + str5 + "\"" + str4 + ">" + name + "</div>"; this.AddLiteralControl(parent, name); }
public virtual void RenderField(Control parent, Sitecore.Shell.Applications.ContentManager.Editor.Field field, Item fieldType, bool readOnly, string value) { Assert.ArgumentNotNull(parent, "parent"); Assert.ArgumentNotNull(field, "field"); Assert.ArgumentNotNull(fieldType, "fieldType"); Assert.ArgumentNotNull(value, "value"); bool hasRibbon = false; string str = null; int count = 0; string text = string.Empty; Control editor = this.GetEditor(fieldType); if (this.Arguments.ShowInputBoxes) { ChildList children = fieldType.Children; hasRibbon = !UserOptions.ContentEditor.ShowRawValues && (children["Ribbon"] != null); switch (field.TemplateField.TypeKey) { case "rich text": case "html": hasRibbon = hasRibbon && (UserOptions.HtmlEditor.ContentEditorMode != UserOptions.HtmlEditor.Mode.Preview); break; } if (!UserOptions.ContentEditor.ShowRawValues) { Item item = children["Menu"]; if (((item != null) && item.HasChildren) && UserOptions.View.UseSmartTags) { str = item.Children[0]["Display Name"]; count = item.Children.Count; } } } string str4 = string.Empty; string str5 = string.Empty; int @int = Registry.GetInt("/Current_User/Content Editor/Field Size/" + field.TemplateField.ID.ToShortID(), -1); if (@int != -1) { str4 = string.Format(" height:{0}px", @int); Sitecore.Web.UI.HtmlControls.Control control2 = editor as Sitecore.Web.UI.HtmlControls.Control; if (control2 != null) { control2.Height = new Unit((double)@int, UnitType.Pixel); } else { WebControl control3 = editor as WebControl; if (control3 != null) { control3.Height = new Unit((double)@int, UnitType.Pixel); } } } else if (editor is Frame) { string style = field.ItemField.Style; if (string.IsNullOrEmpty(style) || !style.ToLowerInvariant().Contains("height")) { str5 = " class='defaultFieldEditorsFrameContainer'"; } } if (!string.IsNullOrEmpty(str)) { string str7 = string.Concat(new object[] { "<div onactivate='javascript:scContent.smartTag(this, event, \"", field.ControlID, "\", ", StringUtil.EscapeJavascriptString(str), ",\"", count, "\")' onmouseover='javascript:scContent.smartTag(this, event, \"", field.ControlID, "\", ", StringUtil.EscapeJavascriptString(str), ",\"", count, "\")'", str4, ">" }); this.AddLiteralControl(parent, str7); } else if (UserOptions.View.UseSmartTags) { string str8 = "<div onmouseover=\"javascript:scContent.smartTag(this, event)\" onactivate=\"javascript:scContent.smartTag(this, event)\"" + str4 + ">"; this.AddLiteralControl(parent, str8); } else { this.AddLiteralControl(parent, "<div style='overflow:hidden; " + str4 + "' " + str5 + ">"); } this.AddLiteralControl(parent, text); this.AddEditorControl(parent, editor, field, hasRibbon, readOnly, value); this.AddLiteralControl(parent, "</div>"); this.RenderResizable(parent, field); }