Permalink
Browse files

#Sitecore.XA.WorkaroundFactory

LookupNameLookupValue
  • Loading branch information...
alan-null committed Apr 24, 2017
1 parent 5f459ff commit 09fb9160afc03d951b8b203482eba54f5cbd8ce2
View
@@ -1,12 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
-VisualStudioVersion = 14.0.25123.0
+VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sitecore.Playground", "src\Playground\code\Sitecore.Playground.csproj", "{BB935824-0A1C-4F29-A656-0F9EA85C419E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sitecore.Playground.Serialization", "src\Serialization\code\Sitecore.Playground.Serialization.csproj", "{58999F11-DC76-4F3A-A81C-091EFCC465C7}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Foundation", "Foundation", "{07D3FC7F-CA34-4A46-90C7-DCC7A3980324}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "XA.WorkaroundFactory", "XA.WorkaroundFactory", "{007460C8-6D36-4AED-B94F-546AD30EAFBE}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LookupNameLookupValue", "LookupNameLookupValue", "{99577126-D720-4D7B-8FC4-6984619FDB96}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sitecore.XA.WorkaroundFactory.LookupNameLookupValue", "src\Foundation\XA.WorkaroundFactory\LookupNameLookupValue\code\Sitecore.XA.WorkaroundFactory.LookupNameLookupValue.csproj", "{66999F11-DC76-4F3A-A81C-091EFCC465C7}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -21,8 +29,17 @@ Global
{58999F11-DC76-4F3A-A81C-091EFCC465C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58999F11-DC76-4F3A-A81C-091EFCC465C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58999F11-DC76-4F3A-A81C-091EFCC465C7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {66999F11-DC76-4F3A-A81C-091EFCC465C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {66999F11-DC76-4F3A-A81C-091EFCC465C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {66999F11-DC76-4F3A-A81C-091EFCC465C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {66999F11-DC76-4F3A-A81C-091EFCC465C7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {007460C8-6D36-4AED-B94F-546AD30EAFBE} = {07D3FC7F-CA34-4A46-90C7-DCC7A3980324}
+ {99577126-D720-4D7B-8FC4-6984619FDB96} = {007460C8-6D36-4AED-B94F-546AD30EAFBE}
+ {66999F11-DC76-4F3A-A81C-091EFCC465C7} = {99577126-D720-4D7B-8FC4-6984619FDB96}
+ EndGlobalSection
EndGlobal
@@ -0,0 +1,16 @@
+<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
+ <sitecore>
+ <unicorn>
+ <configurations>
+ <configuration name="Sitecore.XA.WorkaroundFactory.LookupNameLookupValue" description="Sitecore.XA.WorkaroundFactory.LookupNameLookupValue" dependencies="XA.Foundation.Serialization" patch:after="configuration[@name='Foundation.Serialization']">
+ <targetDataStore physicalRootPath="$(sourceFolder)\Foundation\XA.WorkaroundFactory\LookupNameLookupValue\serialization" type="Rainbow.Storage.SerializationFileSystemDataStore, Rainbow" useDataCache="false" singleInstance="true" />
+ <predicate type="Unicorn.Predicates.SerializationPresetPredicate, Unicorn" singleInstance="true">
+
+ <include name="LookupNameLookupValue" database="core" path="/sitecore/system/Field types/List Types/Lookup Name Lookup Value List"/>
+
+ </predicate>
+ </configuration>
+ </configurations>
+ </unicorn>
+ </sitecore>
+</configuration>
@@ -0,0 +1,7 @@
+<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
+ <sitecore>
+ <controlSources>
+ <source patch:before="*[@namespace='Sitecore.Shell.Applications.ContentEditor']" mode="on" namespace="Sitecore.Playground.XA.WorkaroundFactory.LookupNameLookupValue" assembly="Sitecore.Playground.XA.WorkaroundFactory.LookupNameLookupValue" prefix="content"/>
+ </controlSources>
+ </sitecore>
+</configuration>
@@ -0,0 +1,242 @@
+using System;
+using System.Collections.Specialized;
+using System.IO;
+using System.Web;
+using System.Web.UI;
+using Sitecore.Data.Items;
+using Sitecore.Diagnostics;
+using Sitecore.Text;
+using Sitecore.Web.UI.HtmlControls;
+using Sitecore.Web.UI.HtmlControls.Data;
+using Sitecore.Web.UI.Sheer;
+using Sitecore.XA.Foundation.TokenResolution;
+using Page = System.Web.UI.Page;
+
+namespace Sitecore.Playground.XA.WorkaroundFactory.LookupNameLookupValue
+{
+ [UsedImplicitly]
+ public class LookupNameLookupValue12 : Input
+ {
+ public string FieldName
+ {
+ get
+ {
+ return GetViewStateString("FieldName");
+ }
+ set
+ {
+ Assert.ArgumentNotNull(value, "value");
+ SetViewStateString("FieldName", value);
+ }
+ }
+
+ public string ItemId
+ {
+ get
+ {
+ return GetViewStateString("ItemID");
+ }
+ set
+ {
+ Assert.ArgumentNotNull(value, "value");
+ SetViewStateString("ItemID", value);
+ }
+ }
+
+ public string Source
+ {
+ get
+ {
+ return GetViewStateString("Source");
+ }
+ set
+ {
+ Assert.ArgumentNotNull(value, "value");
+ SetViewStateString("Source", value);
+ }
+ }
+
+ public LookupNameLookupValue12()
+ {
+ Activation = true;
+ Class = "scContentControl";
+ }
+
+ protected override void OnLoad(EventArgs e)
+ {
+ Assert.ArgumentNotNull(e, "e");
+ base.OnLoad(e);
+ if (Sitecore.Context.ClientPage.IsEvent)
+ {
+ LoadValue();
+ }
+ else
+ {
+ BuildControl();
+ }
+ }
+
+ protected virtual void LoadValue()
+ {
+ if (!ReadOnly && !Disabled)
+ {
+ NameValueCollection form;
+ Page handler = HttpContext.Current.Handler as Page;
+ form = handler != null ? handler.Request.Form : new NameValueCollection();
+ UrlString map = new UrlString();
+ foreach (string id in form.Keys)
+ {
+ if ((!string.IsNullOrEmpty(id) && id.StartsWith(ID + "_Param")) && !id.EndsWith("_value"))
+ {
+ string key = form[id];
+ string value = form[id + "_value"];
+ if (!string.IsNullOrEmpty(key))
+ {
+ map[key] = value ?? string.Empty;
+ }
+ }
+ }
+ if (Value != map.ToString())
+ {
+ Value = map.ToString();
+ SetModified();
+ }
+ }
+ }
+
+ protected override void SetModified()
+ {
+ base.SetModified();
+ if (TrackModified)
+ {
+ Sitecore.Context.ClientPage.Modified = true;
+ }
+ }
+
+ protected virtual void BuildControl()
+ {
+ UrlString str = new UrlString(Value);
+ foreach (string str2 in str.Parameters.Keys)
+ {
+ if (str2.Length > 0)
+ {
+ Controls.Add(new LiteralControl(BuildParameterKeyValue(str2, str.Parameters[str2])));
+ }
+ }
+ Controls.Add(new LiteralControl(BuildParameterKeyValue(string.Empty, string.Empty)));
+ }
+
+ protected virtual string BuildParameterKeyValue(string key, string value)
+ {
+ Assert.ArgumentNotNull(key, "key");
+ Assert.ArgumentNotNull(value, "value");
+
+ string uniqueId = GetUniqueID(ID + "_Param");
+ Sitecore.Context.ClientPage.ServerProperties[ID + "_LastParameterID"] = uniqueId;
+ string clientEvent = Sitecore.Context.ClientPage.GetClientEvent(ID + ".ParameterChange");
+ string readOnly = ReadOnly ? " readonly=\"readonly\"" : string.Empty;
+ string disabled = Disabled ? " disabled=\"disabled\"" : string.Empty;
+ string keyHtmlControl = GetKeyHtmlControl(uniqueId, StringUtil.EscapeQuote(HttpUtility.UrlDecode(key)), readOnly, disabled, clientEvent);
+ string valueHtmlControl = GetValueHtmlControl(uniqueId, StringUtil.EscapeQuote(HttpUtility.UrlDecode(value)));
+ return $"<table width=\"100%\" cellpadding=\"4\" cellspacing=\"0\" border=\"0\"><tr><td width=\"50%\">{keyHtmlControl}</td><td width=\"50%\">{valueHtmlControl}</td></tr></table>";
+ }
+
+ protected virtual string GetKeyHtmlControl(string id, string key, string readOnly, string disabled, string clientEvent)
+ {
+ HtmlTextWriter writer = new HtmlTextWriter(new StringWriter());
+ Item current = Sitecore.Context.ContentDatabase.GetItem(ItemId);
+ Item[] items = LookupSources.GetItems(current, SourcePart(0, current));
+ writer.Write("<select id=\"" + id + "\" name=\"" + id + "\"" + readOnly + disabled + " style=\"width:100%\" onchange=\"" + clientEvent + "\"" + GetControlAttributes() + ">");
+ writer.Write("<option" + (string.IsNullOrEmpty(key) ? " selected=\"selected\"" : string.Empty) + " value=\"\"></option>");
+ foreach (Item item2 in items)
+ {
+ string itemHeader = GetItemHeader(item2);
+ bool flag = item2.ID.ToString() == key;
+ writer.Write("<option value=\"" + item2.ID + "\"" + (flag ? " selected=\"selected\"" : string.Empty) + ">" + itemHeader + "</option>");
+ }
+ writer.Write("</select>");
+ return writer.InnerWriter.ToString();
+ }
+
+ protected virtual string GetValueHtmlControl(string id, string value)
+ {
+ HtmlTextWriter writer = new HtmlTextWriter(new StringWriter());
+ Item current = Sitecore.Context.ContentDatabase.GetItem(ItemId);
+ Item[] items = LookupSources.GetItems(current, SourcePart(1, current));
+ writer.Write("<select id=\"" + id + "_value\" name=\"" + id + "_value\" style=\"width:100%\"" + GetControlAttributes() + ">");
+ writer.Write("<option" + (string.IsNullOrEmpty(value) ? " selected=\"selected\"" : string.Empty) + " value=\"\"></option>");
+ foreach (Item item2 in items)
+ {
+ string itemHeader = GetItemHeader(item2);
+ bool flag = item2.ID.ToString() == value;
+ writer.Write("<option value=\"" + item2.ID + "\"" + (flag ? " selected=\"selected\"" : string.Empty) + ">" + itemHeader + "</option>");
+ }
+ writer.Write("</select>");
+ return writer.InnerWriter.ToString();
+ }
+
+ protected virtual string GetItemHeader(Item item)
+ {
+ Assert.ArgumentNotNull(item, "item");
+ string str2 = StringUtil.GetString(new[] { FieldName });
+ if (str2.StartsWith("@"))
+ {
+ return item[str2.Substring(1)];
+ }
+ if (str2.Length > 0)
+ {
+ return item[FieldName];
+ }
+ return item.DisplayName;
+ }
+
+ protected override void DoRender(HtmlTextWriter output)
+ {
+ Assert.ArgumentNotNull(output, "output");
+ SetWidthAndHeightStyle();
+ output.Write("<div" + ControlAttributes + ">");
+ RenderChildren(output);
+ output.Write("</div>");
+ }
+
+ [UsedImplicitly]
+ protected virtual void ParameterChange()
+ {
+ ClientPage clientPage = Sitecore.Context.ClientPage;
+ if (clientPage.ClientRequest.Source == StringUtil.GetString(clientPage.ServerProperties[ID + "_LastParameterID"]))
+ {
+ string str = clientPage.ClientRequest.Form[clientPage.ClientRequest.Source];
+ if (!string.IsNullOrEmpty(str))
+ {
+ string str2 = BuildParameterKeyValue(string.Empty, string.Empty);
+ clientPage.ClientResponse.Insert(ID, "beforeEnd", str2);
+ }
+ }
+ NameValueCollection form = null;
+ Page handler = HttpContext.Current.Handler as Page;
+ if (handler != null)
+ {
+ form = handler.Request.Form;
+ }
+ if (form != null)
+ {
+ clientPage.ClientResponse.SetReturnValue(true);
+ }
+ }
+
+ protected virtual string SourcePart(int index, Item item)
+ {
+ string[] sources = Source.Split(new[] { "||" }, StringSplitOptions.RemoveEmptyEntries);
+ if (sources.Length > index)
+ {
+ string source = sources[index].Trim();
+ if (source.Contains("$"))
+ {
+ source = TokenResolver.Resolve(source, item);
+ }
+ return source;
+ }
+ return "";
+ }
+ }
+}
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Sitecore.XA.WorkaroundFactory.LookupNameLookupValue")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Sitecore.XA.WorkaroundFactory.LookupNameLookupValue")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("58999f11-dc76-4f3a-a81c-091efcc465c7")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
Oops, something went wrong.

0 comments on commit 09fb916

Please sign in to comment.