Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Simple Custom Element</title>
- <style type="text/css">
- * { padding: 0; margin: 0; }
- body { font-size: 10pt; font-family: Tahoma; }
- #container
- {
- height: 150px;
- overflow: auto;
- width: 100%;
- text-align: left;
- align: left;
- padding: 7px;
- }
- .controls
- {
- padding: 0 9px 1px 9px;
- padding: 0 5px;
- border: 1px solid #B9B9B4;
- border-top-color: #DDDDD8;
- border-bottom-color: #797975;
- vertical-align: middle;
- font-family: tahoma,verdana,arial,helvetica,sans-serif;
- font-size: 100%; /* 11px @ Normal */
- font-color: #000;
- width: 100px;
- }
- </style>
- <script type="text/javascript">
- var httpCgiPath = "http://" + document.location.hostname + "/cs/idcplg";
- var soapRequest;
- var myRset = "QueryResult";
- var myIDField = "CT2_ID";
- var myDescField = "CT2_DESC_EN";
- var myFieldName = "custom-content-type-level-2";
- // Function to get the values of the ResultSet and fill the combo.
- function loadComboValues()
- {
- // if the XML document isn't ready, do nothing
- if (!checkXMLDoc())
- return;
- // get the first idc:document object, which contains all the
- // name-value pairs for the response
- var docNodes = getIdcElementsByTagName(soapRequest.responseXML,"document");
- var localData = docNodes[0];
- // get the SERVICE result set which has the metadata values.
- var docInfo = getSoapResultSet(soapRequest.responseXML,myRset);
- //Load RS into combo
- createOptionList(docInfo);
- }
- function createOptionList(resultSet)
- {
- // Begin creating the select list
- var htmlStr = "<select name='" + myFieldName + "' id='" + myFieldName + "'>";
- htmlStr += "<option value=''></option>";
- // Iterate over resultset values
- for (var i = 0; i < resultSet.childNodes.length; i++)
- {
- // only iterate over explicit XML node objects
- var item = resultSet.childNodes[i];
- if (item.nodeType == null || item.nodeType != 1)
- continue;
- // extract the title, type, and comments from the current row
- var auxID = getSoapValue(item, myIDField);
- var auxDesc = getSoapValue(item, myDescField);
- htmlStr += "<option value='" + auxID +"'";
- htmlStr += " >";
- htmlStr += auxDesc + "</option>";
- }
- htmlStr += "</select>";
- // insert the option list into the form
- document.getElementById("schemaOutput").innerHTML = htmlStr;
- return;
- }
- // ------------------------------------------------------------------
- // Utility functions for running a SOAP request
- // ------------------------------------------------------------------
- // This function creates a XMLHttpRequest object specific to the
- // browser, runs the web service, and processes the result.
- function loadXMLDoc(url, handleResponseFunction)
- {
- soapRequest = false;
- // try to create a native XMLHttpRequest object, works in
- // Mozilla 1.0, Safari 1.2, Netscape 7, and Opera 7.60
- if(window.XMLHttpRequest)
- {
- try
- {
- soapRequest = new XMLHttpRequest();
- }
- catch(e)
- {
- soapRequest = false;
- }
- }
- // otherwise create an ActiveX object for Internet Explorer
- else if(window.ActiveXObject)
- {
- try
- {
- soapRequest = new ActiveXObject("Msxml2.XMLHTTP");
- }
- catch(e)
- {
- try
- {
- soapRequest = new ActiveXObject("Microsoft.XMLHTTP");
- }
- catch(e)
- {
- soapRequest = false;
- }
- }
- }
- // if the object could be created, send a request
- if(soapRequest)
- {
- // set the function to process state changes in the request
- // so that the response will be drawn to the page only
- // when its complete
- soapRequest.onreadystatechange = handleResponseFunction;
- // open the URL, and send an empty string to finish
- // the request
- try
- {
- soapRequest.open("GET", url, true);
- if (soapRequest.readyState == 0)
- {
- throw 'Failed to open the connection';
- }
- soapRequest.send("");
- }
- catch (e)
- {
- alert(e + "\nUnable to open the XMLHTTP request.\n" +
- "The server may be down, you may not have permission,\n" +
- "or else you attempted to connect to a server other\n" +
- "than the one hosting this page.");
- }
- }
- }
- // check to make sure the XMl document is fully loaded, and no
- // HTTP errors occurred.
- function checkXMLDoc()
- {
- var isReady = false;
- // only do something is the request state is "loaded"
- if (soapRequest.readyState == 4)
- {
- // check the HTTP status for a successful connection
- if (soapRequest.status == 200)
- {
- isReady = true;
- }
- else
- {
- // could be access denied, or a server error
- alert("There was a problem retrieving the XML data:\n" +
- soapRequest.statusText);
- }
- }
- return isReady;
- }
- // ------------------------------------------------------------------
- // Utility functions for extracting text from the SOAP response
- // ------------------------------------------------------------------
- // pull out a node from the XML doc by its name. This is needed
- // because of the different ways each browser handles XML namespaces
- function getIdcElementsByTagName(xmlDoc, nodeName)
- {
- if (xmlDoc.getElementsByTagNameNS)
- {
- // for w3c compliant XML objects
- return xmlDoc.getElementsByTagNameNS(
- "http://www.stellent.com/IdcService/",
- nodeName);
- }
- else
- {
- // for IE
- return xmlDoc.getElementsByTagName("idc:" + nodeName);
- }
- }
- // a helper function to extract a ResultSet from a SOAP response
- function getSoapResultSet(xmlDoc, rsetName)
- {
- var allResultSets = getIdcElementsByTagName(xmlDoc, "resultset");
- var rset = null;
- for (var i=0; i<allResultSets.length; i++)
- {
- if (allResultSets[i].getAttribute("name") == rsetName)
- {
- rset = allResultSets[i];
- break;
- }
- }
- return rset;
- }
- // a helper function to extract an attritbute or a value from
- // an idc:field XML node
- function getSoapValue(xmlNode, name)
- {
- // first, try pulling the value from the attributes
- var value = xmlNode.getAttribute(name);
- if (value == null)
- {
- // otherwise, loop over all the children looking for a
- // node with the 'name' attribute set to the pased value
- // for 'name'
- for (var i=0; i<xmlNode.childNodes.length; i++)
- {
- var subNode = xmlNode.childNodes[i];
- // skip nodes that are not full xml elementss
- if (subNode.nodeType == null || subNode.nodeType != 1)
- {
- continue;
- }
- if (subNode.getAttribute("name") == name)
- {
- if (subNode.text)
- value = subNode.text; // IE
- else
- value = subNode.textContent; // Safari/Mozilla
- }
- }
- }
- return value;
- }
- </script>
- <script type="text/javascript">
- // The following script is what is processed by the Contribution Form
- var Custom = {};
- Custom.originalData = null;
- Custom.Initialize = function()
- {
- var datafileDocName = ElementAPI.GetFormProperty('dDocName');
- var datafileID = ElementAPI.GetFormProperty('dID');
- ElementAPI.SetCallback('GetElementContent', function(callback)
- {
- callback(Custom.GetData());
- });
- ElementAPI.SetCallback('ActivateElement', function(callback){ $ID('content').focus(); callback(); });
- ElementAPI.SetCallback('CanCloseElement', function(callback){ callback({canClose: true}); });
- ElementAPI.SetCallback('Show', function(callback){ callback(); });
- ElementAPI.SetCallback('Hide', function(callback){ callback(); });
- ElementAPI.SetCallback('IsDirty', function()
- {
- return { isDirty: (Custom.originalData !== Custom.GetData()) };
- });
- var height = '50px';
- var flags = ElementAPI.GetElementConfigProperty('flags') || {};
- var config = ElementAPI.GetElementConfiguration() || {};
- if( flags.canSetHeight && config.height && ( config.height.length > 0 ) )
- {
- height = config.height;
- }
- height = ElementAPI.SetHostHeight(height);
- // I execute my own custom service to check the values of the metadata.
- // Sample URL: http://myserver/cs/idcplg?IdcService=CUSTOM_CTN2&idN1=15&IsSoap=1
- var requestUrl = httpCgiPath + "?IdcService=CUSTOM_CTN2&idN1=15&IsSoap=1";
- // run the XMLHTTP request, and draw the response with
- // the function 'loadComboValues'
- loadXMLDoc(requestUrl, loadComboValues);
- WCM.DHTML.AddStyleSheet({path: WCM.path + './base/wcm.base.css', context: window});
- //Custom.originalData = Custom.GetData();
- ElementAPI.Ready();
- };
- Custom.GetData = function()
- {
- return $ID(myFieldName).options[$ID(myFieldName).selectedIndex].value;
- };
- try {
- window.top.WCM.InitializeCustomElement(window, Custom.Initialize);
- } catch(e) { }
- </script>
- </head>
- <body>
- <div id="container" nowrap>
- <div id="schemaOutput"></div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement