140 lines
4.7 KiB
C#
140 lines
4.7 KiB
C#
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<T> : ContextSelector<T>
|
|
{
|
|
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<T>).GetProperty("CookieCurrentId", BindingFlags.Static | BindingFlags.NonPublic);
|
|
return (string)property.GetValue(null, null);
|
|
}
|
|
set
|
|
{
|
|
PropertyInfo property = typeof(ContextSelector<T>).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[]
|
|
{
|
|
"<script language='javascript'>\r\n function ",
|
|
text,
|
|
"(returnValue)\r\n {\r\n if (typeof(returnValue)!= 'undefined' && returnValue != '",
|
|
SPHttpUtility.EcmaScriptStringLiteralEncode(base.CurrentId),
|
|
"' ) \r\n {\r\n STSNavigate(StURLSetVar2(window.location.href, '",
|
|
SPHttpUtility.EcmaScriptStringLiteralEncode(this.Key),
|
|
"' , returnValue));\r\n }\r\n }\r\n </script>"
|
|
});
|
|
this.Page.ClientScript.RegisterClientScriptBlock(typeof(ContextSelectorEntityEditorAdapter<T>), text, script);
|
|
string script2 = string.Concat(new string[]
|
|
{
|
|
"<script language='javascript'>\r\nfunction ",
|
|
text2,
|
|
"(xml)\r\n{\r\nvar xmlDoc;\r\nif(xml==null)\r\nreturn;\r\nif(document.implementation && document.implementation.createDocument)\r\n{\r\nxmlDoc=(new DOMParser()).parseFromString(xml, \"text/xml\");\r\n}\r\nelse\r\n{\r\nxmlDoc=new ActiveXObject(\"Microsoft.XMLDOM\");\r\nxmlDoc.async=false;\r\nxmlDoc.loadXML(xml);\r\n}\r\nvar entities=xmlDoc.documentElement;\r\nif(entities.childNodes.length == 0)\r\nreturn;\r\nvar entity = entities.childNodes[0];\r\n",
|
|
text,
|
|
"(entity.getAttribute(\"Key\"));\r\n}\r\n</script>"
|
|
});
|
|
this.Page.ClientScript.RegisterClientScriptBlock(typeof(ContextSelectorEntityEditorAdapter<T>), 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<T>.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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|