Advertisement
zako

Untitled

Sep 5th, 2011
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 8.84 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2.         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3.  
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5.   <head>
  6.     <title>Simple Custom Element</title>
  7.  
  8.     <style type="text/css">
  9.     * { padding: 0; margin: 0; }
  10.     body { font-size: 10pt; font-family: Tahoma; }
  11.     #container
  12.     {
  13.         height: 150px;
  14.         overflow: auto;
  15.         width: 100%;
  16.         text-align: left;
  17.         align: left;
  18.         padding: 7px;
  19.     }
  20.     .controls
  21.     {
  22.         padding: 0 9px 1px 9px;
  23.         padding: 0 5px;
  24.         border: 1px solid #B9B9B4;
  25.         border-top-color: #DDDDD8;
  26.         border-bottom-color: #797975;
  27.         vertical-align: middle;
  28.         font-family: tahoma,verdana,arial,helvetica,sans-serif;
  29.         font-size: 100%; /* 11px @ Normal */
  30.         font-color: #000;
  31.         width: 100px;
  32.     }
  33.     </style>
  34.  
  35.     <script type="text/javascript">
  36.     var httpCgiPath = "http://" + document.location.hostname + "/cs/idcplg";
  37.     var soapRequest;   
  38.     var myRset = "QueryResult";
  39.     var myIDField = "CT2_ID";
  40.     var myDescField = "CT2_DESC_EN";
  41.     var myFieldName = "custom-content-type-level-2";
  42.    
  43.     // Function to get the values of the ResultSet and fill the combo.
  44.     function loadComboValues()
  45.     {
  46.         // if the XML document isn't ready, do nothing
  47.         if (!checkXMLDoc())
  48.             return;
  49.  
  50.         // get the first idc:document object, which contains all the
  51.         // name-value pairs for the response
  52.         var docNodes = getIdcElementsByTagName(soapRequest.responseXML,"document");
  53.         var localData = docNodes[0];
  54.         // get the SERVICE result set which has the metadata values.
  55.         var docInfo = getSoapResultSet(soapRequest.responseXML,myRset);
  56.            
  57.         //Load RS into combo
  58.         createOptionList(docInfo);
  59.     }
  60.    
  61.     function createOptionList(resultSet)
  62.     {
  63.         // Begin creating the select list
  64.         var htmlStr = "<select name='" + myFieldName + "' id='" + myFieldName + "'>";
  65.         htmlStr += "<option value=''></option>";
  66.        
  67.         // Iterate over resultset values
  68.         for (var i = 0; i < resultSet.childNodes.length; i++)
  69.         {
  70.             // only iterate over explicit XML node objects
  71.             var item = resultSet.childNodes[i];
  72.             if (item.nodeType == null || item.nodeType != 1)
  73.                 continue;
  74.  
  75.             // extract the title, type, and comments from the current row
  76.             var auxID = getSoapValue(item, myIDField);
  77.             var auxDesc = getSoapValue(item, myDescField);
  78.            
  79.             htmlStr += "<option value='" + auxID +"'";
  80.             htmlStr += " >";
  81.             htmlStr += auxDesc + "</option>";
  82.         }
  83.        
  84.         htmlStr += "</select>";
  85.         // insert the option list into the form
  86.         document.getElementById("schemaOutput").innerHTML = htmlStr;
  87.        
  88.         return;
  89.     }  
  90.    
  91.     // ------------------------------------------------------------------
  92.     //  Utility functions for running a SOAP request
  93.     // ------------------------------------------------------------------
  94.  
  95.     // This function creates a XMLHttpRequest object specific to the
  96.     // browser, runs the web service, and processes the result.
  97.     function loadXMLDoc(url, handleResponseFunction)
  98.     {
  99.         soapRequest = false;
  100.  
  101.         // try to create a native XMLHttpRequest object, works in
  102.         // Mozilla 1.0, Safari 1.2, Netscape 7, and Opera 7.60
  103.         if(window.XMLHttpRequest)
  104.         {
  105.             try
  106.             {
  107.                 soapRequest = new XMLHttpRequest();
  108.             }
  109.             catch(e)
  110.             {
  111.                 soapRequest = false;
  112.             }
  113.         }
  114.         // otherwise create an ActiveX object for Internet Explorer
  115.         else if(window.ActiveXObject)
  116.         {
  117.             try
  118.             {
  119.                 soapRequest = new ActiveXObject("Msxml2.XMLHTTP");
  120.             }
  121.             catch(e)
  122.             {
  123.                 try
  124.                 {
  125.                       soapRequest = new ActiveXObject("Microsoft.XMLHTTP");
  126.                 }
  127.                 catch(e)
  128.                 {
  129.                       soapRequest = false;
  130.                 }
  131.             }
  132.         }
  133.  
  134.         // if the object could be created, send a request
  135.         if(soapRequest)
  136.         {
  137.             // set the function to process state changes in the request
  138.             // so that the response will be drawn to the page only
  139.             // when its complete
  140.             soapRequest.onreadystatechange = handleResponseFunction;
  141.  
  142.             // open the URL, and send an empty string to finish
  143.             // the request
  144.             try
  145.             {
  146.                
  147.                 soapRequest.open("GET", url, true);
  148.                 if (soapRequest.readyState == 0)
  149.                 {
  150.                     throw 'Failed to open the connection';
  151.                 }
  152.                 soapRequest.send("");
  153.             }
  154.             catch (e)
  155.             {
  156.                 alert(e + "\nUnable to open the XMLHTTP request.\n" +
  157.                     "The server may be down, you may not have permission,\n" +
  158.                     "or else you attempted to connect to a server other\n" +
  159.                     "than the one hosting this page.");
  160.             }
  161.         }
  162.     }
  163.  
  164.     // check to make sure the XMl document is fully loaded, and no
  165.     // HTTP errors occurred.
  166.     function checkXMLDoc()
  167.     {
  168.         var isReady = false;
  169.         // only do something is the request state is "loaded"
  170.         if (soapRequest.readyState == 4)
  171.         {
  172.             // check the HTTP status for a successful connection
  173.             if (soapRequest.status == 200)
  174.             {
  175.                 isReady = true;
  176.             }
  177.             else
  178.             {
  179.                 // could be access denied, or a server error
  180.                 alert("There was a problem retrieving the XML data:\n" +
  181.                     soapRequest.statusText);
  182.             }
  183.         }
  184.         return isReady;
  185.     }
  186.  
  187.     // ------------------------------------------------------------------
  188.     //  Utility functions for extracting text from the SOAP response
  189.     // ------------------------------------------------------------------
  190.  
  191.     // pull out a node from the XML doc by its name. This is needed
  192.     // because of the different ways each browser handles XML namespaces
  193.     function getIdcElementsByTagName(xmlDoc, nodeName)
  194.     {
  195.         if (xmlDoc.getElementsByTagNameNS)
  196.         {
  197.             // for w3c compliant XML objects
  198.             return xmlDoc.getElementsByTagNameNS(
  199.                 "http://www.stellent.com/IdcService/",
  200.                 nodeName);
  201.         }
  202.         else
  203.         {
  204.             // for IE
  205.             return xmlDoc.getElementsByTagName("idc:" + nodeName);
  206.         }
  207.     }
  208.  
  209.     // a helper function to extract a ResultSet from a SOAP response
  210.     function getSoapResultSet(xmlDoc, rsetName)
  211.     {
  212.         var allResultSets = getIdcElementsByTagName(xmlDoc, "resultset");
  213.  
  214.         var rset = null;
  215.         for (var i=0; i<allResultSets.length; i++)
  216.         {
  217.             if (allResultSets[i].getAttribute("name") == rsetName)
  218.             {
  219.                 rset = allResultSets[i];
  220.                 break;
  221.             }
  222.         }
  223.         return rset;
  224.     }
  225.  
  226.     // a helper function to extract an attritbute or a value from
  227.     // an idc:field XML node
  228.     function getSoapValue(xmlNode, name)
  229.     {
  230.         // first, try pulling the value from the attributes
  231.         var value = xmlNode.getAttribute(name);
  232.         if (value == null)
  233.         {
  234.             // otherwise, loop over all the children looking for a
  235.             // node with the 'name' attribute set to the pased value
  236.             // for 'name'
  237.             for (var i=0; i<xmlNode.childNodes.length; i++)
  238.             {
  239.                 var subNode = xmlNode.childNodes[i];
  240.  
  241.                 // skip nodes that are not full xml elementss
  242.                 if (subNode.nodeType == null || subNode.nodeType != 1)
  243.                 {
  244.                     continue;
  245.                 }
  246.  
  247.                 if (subNode.getAttribute("name") == name)
  248.                 {
  249.                     if (subNode.text)
  250.                         value = subNode.text;  // IE
  251.                     else
  252.                         value = subNode.textContent; // Safari/Mozilla
  253.                 }
  254.  
  255.             }
  256.         }
  257.         return value;
  258.     }  
  259. </script>
  260.  
  261. <script type="text/javascript">
  262.     // The following script is what is processed by the Contribution Form
  263.     var Custom = {};
  264.  
  265.     Custom.originalData = null;
  266.  
  267.     Custom.Initialize = function()
  268.     {
  269.         var datafileDocName = ElementAPI.GetFormProperty('dDocName');
  270.         var datafileID = ElementAPI.GetFormProperty('dID');
  271.         ElementAPI.SetCallback('GetElementContent', function(callback)
  272.         {
  273.             callback(Custom.GetData());
  274.         });
  275.         ElementAPI.SetCallback('ActivateElement', function(callback){ $ID('content').focus(); callback(); });
  276.         ElementAPI.SetCallback('CanCloseElement', function(callback){ callback({canClose: true}); });
  277.         ElementAPI.SetCallback('Show', function(callback){ callback(); });
  278.         ElementAPI.SetCallback('Hide', function(callback){ callback(); });
  279.         ElementAPI.SetCallback('IsDirty', function()
  280.         {
  281.             return { isDirty: (Custom.originalData !== Custom.GetData()) };
  282.         });
  283.  
  284.         var height = '50px';
  285.         var flags = ElementAPI.GetElementConfigProperty('flags') || {};
  286.         var config = ElementAPI.GetElementConfiguration() || {};
  287.         if( flags.canSetHeight && config.height && ( config.height.length > 0 ) )
  288.         {
  289.             height = config.height;
  290.         }
  291.         height = ElementAPI.SetHostHeight(height);
  292.  
  293.         // I execute my own custom service to check the values of the metadata.
  294.         // Sample URL: http://myserver/cs/idcplg?IdcService=CUSTOM_CTN2&idN1=15&IsSoap=1
  295.         var requestUrl = httpCgiPath + "?IdcService=CUSTOM_CTN2&idN1=15&IsSoap=1";
  296.         // run the XMLHTTP request, and draw the response with
  297.         // the function 'loadComboValues'
  298.         loadXMLDoc(requestUrl, loadComboValues);
  299.  
  300.         WCM.DHTML.AddStyleSheet({path: WCM.path + './base/wcm.base.css', context: window});
  301.  
  302.         //Custom.originalData = Custom.GetData();
  303.  
  304.         ElementAPI.Ready();
  305.     };
  306.  
  307.     Custom.GetData = function()
  308.     {
  309.         return $ID(myFieldName).options[$ID(myFieldName).selectedIndex].value;
  310.     };
  311.  
  312.     try {
  313.         window.top.WCM.InitializeCustomElement(window, Custom.Initialize);
  314.     } catch(e) { }
  315.     </script>
  316.  
  317.   </head>
  318. <body>
  319.     <div id="container" nowrap>
  320.           <div id="schemaOutput"></div>
  321.     </div>
  322. </body>
  323. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement