Custom_JS.ASPX


Appendix. Custom_JS.ASPX

The following code is Custom_JS.aspx, which is used in Chapter 4. Custom_JS.aspx provides the necessary functionality to call the web service to retrieve the author information.

[View full width]

<!-- _lc _version="11.0.5510" _dal="1" --> <%@ Page language="C#" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <% bool loadCPS = false; string host = Request.ServerVariables["HTTP_HOST"]; string myContext = Request.QueryString["Context"]; string url = ""; string list = ""; string dialogview = ""; string location = ""; int idxQuery = myContext.IndexOf('?'); Hashtable hash = new Hashtable(); string[] nameValue; string[] param = myContext.Substring(idxQuery + 1).Split('&'); if (idxQuery>0) { for (int i=0;i<param.Length;i++){ if (param[i].IndexOf('=')>0) { nameValue = param[i].Split('='); hash.Add(nameValue[0], nameValue[1]); } } } dialogview = hash.ContainsKey("dialogview") ? hash ["dialogview"].ToString() : ""; location = hash.ContainsKey("location") ? hash ["location"].ToString() : "" ; if (dialogview == "SaveForm"){ location = location.Remove(location.ToLower().IndexOf("/"), location.Length -location .ToLower().IndexOf("/")); url = myContext.Remove(myContext.ToLower().LastIndexOf("/_vti_bin/owssvr.dll"), myContext.Length - myContext.ToLower().LastIndexOf("/_vti_bin/owssvr.dll")) + "/" + location; list = location; loadCPS = true; } if (myContext.ToLower().IndexOf("/forms/editform.aspx") > 0){ url = myContext.Remove(myContext.ToLower().LastIndexOf("/forms/editform.aspx"), myContext.Length - myContext.ToLower().LastIndexOf("/forms/editform.aspx") ); list = url.Substring(url.LastIndexOf('/') + 1).ToString(); loadCPS = true; } if (myContext.ToLower().IndexOf("/forms/upload.aspx") > 0){ url = myContext.Remove(myContext.ToLower().LastIndexOf("/forms/upload.aspx"), myContext .Length - myContext.ToLower().LastIndexOf("/forms/upload.aspx")); list = url.Substring(url.LastIndexOf('/') + 1).ToString(); loadCPS = true; } %> function getPageName(){ var sPath = window.location.pathname; var sPage = sPath.substring(sPath.lastIndexOf('/') + 1); return sPage; } if (<%=loadCPS.ToString().ToLower()%>){ // global variables - don't initialize if we don't // need them var url = '<%=Server.UrlEncode(url)%>' var count = 0; var hash = new hashtable(); if(typeof window.attachEvent != 'undefined'){ window.attachEvent('onload', doCustomFieldsDataEntry); if (window.onload !=null){ window.attachEvent('onload', window.onload); } } } function showModal(elemName, strField){ var retValue = window.showModalDialog('/_layouts/1033/cps /CustomPropertyDataManipulation.aspx?URL=' + url + '&DefaultValue=' + document .getElementById(elemName).value + '&DefaultDisplay=' + document.getElementById('disp' + elemName).value + '&InternalFieldName=' + strField + '','',''); document.getElementById(elemName).value = retValue[0]; document.getElementById('disp' + elemName).value = retValue[1]; } function doCustomFieldsDataEntry(){ var CustomFieldList = getCustomFieldList(); var strButton =""; var tmpElem; if (CustomFieldList != null){ var newText = document.createElement("<div onserviceavailable=\"serviceAvailable();\" onreadystatechange=\"doneloading();\" id=\"divWebServiceCaller\" style=\"behavior:url (< %=url%>/_layouts/1033/CPS/webservice.htc)\"></div>"); document.body.appendChild(newText); for(var i=0; i<=CustomFieldList.length-1; i++){ if (CustomFieldList[i][1] == 'AuthorLookup'){ tmpElem = document.getElementById(this.frm.stFieldPrefix + CustomFieldList[i][0]); if (tmpElem != null){ var idDisp = "disp" + this.frm.stFieldPrefix + CustomFieldList[i][0]; tmpElem.readOnly = true; tmpElem.onfocus = "document.getElementById('btn" + tmpElem.name + "') .focus(); document.getElementById('btn" + tmpElem.name + "').select();"; strButton = "<INPUT tabindex= \"" + tmpElem.tabIndex + "\" id=\"btn" + tmpElem.name + "\" name=\"btn" + tmpElem.name + "\" TYPE=\"BUTTON\" VALUE=\"Select Author \" ONCLICK=\"showModal('" + tmpElem.name + "','" + CustomFieldList[i][0] + "');\">"; strDisplay = "<textarea readonly class= \"" + tmpElem.className + " \"id=\"" + idDisp + "\" name=\"" + idDisp + "\"></textarea>"; tmpElem.outerHTML = strButton + '<BR>' + tmpElem.outerHTML + '<BR>' + strDisplay; } } } } } function serviceAvailable() { var CustomFieldList = getCustomFieldList(); if (CustomFieldList != null){ for(var i=0; i<=CustomFieldList.length-1; i++){ tmpElem = document.getElementById(this.frm.stFieldPrefix + CustomFieldList[i][0]); if (tmpElem != null){ if (CustomFieldList[i][1] == 'AuthorLookup'){ var idDisp = "disp" + this.frm.stFieldPrefix + CustomFieldList[i][0]; var idCall = document.getElementById("divWebServiceCaller").GetAuthor .callService(handleWebServiceResult, "ById", tmpElem.value); hash.add (idCall, document.getElementById(idDisp)); } } } } } function handleWebServiceResult(res) { if (!res.error) { var tmpElem = hash.get(res.id) tmpElem.value = res.value; } else { alert("Unsuccessful call. Error is " + res.errorDetail.string); } } function doneloading(){ if (document.getElementById("divWebServiceCaller").readyState=="complete"){ loadWebServices(); } } function getCustomFieldList(){ <% if (loadCPS){ try{ SharePointBook.SPCustomField spCustomField = new SharePointBook.SPCustomField(); int count = 0; string strOutput = ""; SPSite siteCollection = new SPSite(url); SPWeb spWeb = siteCollection.OpenWeb(); SPList spList = spWeb.Lists[list]; SPFieldCollection spFields = spList.Fields; foreach (SPField f in spFields) { if (f.Type.ToString() == "Text"){ if(spCustomField.isCustomField(f)){ strOutput += "CustomFields[" + count + "] = new Array(2);"; strOutput += "CustomFields[" + count + "][0] = '" + f.InternalName + "';"; strOutput += "CustomFields[" + count + "][1] = '" + spCustomField .GetAttributeValue(f,"Format") + "';"; count++; } } } if (strOutput !="") { strOutput = "CustomFields = new Array(" + count + ");" + strOutput; strOutput += "return CustomFields;"; } else { strOutput = "return null;"; } Response.Write (strOutput); } catch (Exception e) { Response.Write ("alert('!"+e.Message+"');"); } } %> return null; } function hashtable() { this.add = mAdd; this.get = mGet; } function mAdd(name, value) { this[name] = value; } function mGet(strKeyName) { return(this[strKeyName]); } function loadWebServices() { document.getElementById("divWebServiceCaller").useService("http://<%=host%>/_vti_bin /getAuthor.asmx?wsdl","GetAuthor"); }





SharePoint 2003 Advanced Concepts. Site Definitions, Custom Templates, and Global Customizations
SharePoint 2003 Advanced Concepts: Site Definitions, Custom Templates, and Global Customizations
ISBN: 0321336615
EAN: 2147483647
Year: 2006
Pages: 64

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net