using Microsoft.SharePoint.Utilities; using Microsoft.SharePoint.WebControls; using SPSolutions.Web; using System; using System.Globalization; using System.Reflection; using System.Web; namespace SPSolutions.SharePoint.WebControls { public abstract class ContextSelectorEntityEditorAdapter : ContextSelector { public abstract Type PickerDialogType { get; } public bool UseCookieInitialization { get { return this.ViewState["Microsoft.SharePoint.SPAlertTemplate"] == null || (bool)this.ViewState["Microsoft.SharePoint.SPAlertTemplate"]; } set { this.ViewState["Microsoft.SharePoint.SPAlertTemplate"] = value; } } internal static string CookieCurrentId { get { PropertyInfo property = typeof(ContextSelector).GetProperty("CookieCurrentId", BindingFlags.Static | BindingFlags.NonPublic); return (string)property.GetValue(null, null); } set { PropertyInfo property = typeof(ContextSelector).GetProperty("CookieCurrentId", BindingFlags.Static | BindingFlags.NonPublic); property.SetValue(null, value, null); } } protected override string NavigateUrl { get { return string.Format("/_layouts/15/picker.aspx?PickerDialogType={0}", HttpUtility.UrlEncode(this.PickerDialogType.AssemblyQualifiedName)); } } protected override void OnInit(EventArgs e) { base.OnInit(e); } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (base.AllowChange) { string text = "SelectContext_" + this.ID; string text2 = "CallbackWrapper_" + this.ID; string text3; if (base.CurrentItem == null) { text3 = this.NavigateUrl; } else { text3 = HttpUtil.AppendUrlQueryString(this.NavigateUrl, string.Format("{0}={1}", this.Key, base.CurrentId)); } string script = string.Concat(new string[] { "" }); this.Page.ClientScript.RegisterClientScriptBlock(typeof(ContextSelectorEntityEditorAdapter), text, script); string script2 = string.Concat(new string[] { "" }); this.Page.ClientScript.RegisterClientScriptBlock(typeof(ContextSelectorEntityEditorAdapter), text2, script2); string text4 = string.Format(CultureInfo.InvariantCulture, "commonShowModalDialog('{0}','resizable: yes; status: no; scroll: no; help: no; center: yes; dialogWidth : {1}pt; dialogHeight : {2}pt;',{3});", new object[] { SPHttpUtility.EcmaScriptStringLiteralEncode(text3), base.DialogWidth, base.DialogHeight, SPHttpUtility.EcmaScriptStringLiteralEncode(text2) }); this.ChangeItem.ClientOnClickScript = (SPHttpUtility.NoEncode(text4)); PickerDialog.RegisterPickerReturnValueHiddenFields(this.Page); } } protected override void OnLoad(EventArgs e) { if (!this.Page.IsPostBack) { if (base.CurrentItem != null) { T currentItem = base.CurrentItem; if (!currentItem.Equals(default(T))) { return; } } string idFromQueryString = this.IdFromQueryString; if (idFromQueryString == null) { if (string.IsNullOrEmpty(base.ClearSelectionText)) { if (this.UseCookieInitialization) { base.CurrentId = (ContextSelectorEntityEditorAdapter.CookieCurrentId); return; } if (base.CurrentItem != null) { T currentItem2 = base.CurrentItem; if (!currentItem2.Equals(default(T))) { return; } } base.CurrentId = (this.DefaultSelectionId()); return; } } else { base.CurrentId = (idFromQueryString); } } } } }