home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Audio / Office2010 / Office.en-us / OfficeLR.cab / COLLECTSIGNATURES_INIT.XSN_1033 / script.js < prev    next >
Text File  |  2009-07-06  |  5KB  |  144 lines

  1. /*
  2.  * This file contains functions for data validation and form-level events.
  3.  * Because the functions are referenced in the form definition (.xsf) file, 
  4.  * it is recommended that you do not modify the name of the function,
  5.  * or the name and number of arguments.
  6.  *
  7. */
  8.  
  9. // The following line is created by Microsoft InfoPath to define the prefixes
  10. // for all the known namespaces in the main XML data file.
  11. // Any modification to the form files made outside of Microsoft InfoPath
  12. // will not be automatically updated.
  13. //<namespacesDefinition>
  14. XDocument.DOM.setProperty("SelectionNamespaces", ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:o12="http://schemas.microsoft.com/office/2004/7/core" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w12="http://schemas.microsoft.com/office/word/2004/6/wordml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
  15. //</namespacesDefinition>
  16.  
  17.  
  18. function AddSigSpotNode(sigspotId, suggSigner, suggSignerEmail)
  19. {
  20.     var sigSpotsNode = XDocument.DOM.selectSingleNode("//my:myFields/my:SignatureSpots");
  21.  
  22.     var elemSigSpot = XDocument.DOM.createNode(1, "my:SignatureSpot", "http://schemas.microsoft.com/office/infopath/2003/myXSD");
  23.  
  24.     var attribSigSpotID = XDocument.DOM.createNode(2, "my:SignatureSpotID", "http://schemas.microsoft.com/office/infopath/2003/myXSD");
  25.     attribSigSpotID.text = sigspotId;
  26.  
  27.     var attribSuggSigner = XDocument.DOM.createNode(2, "my:SuggestedSigner", "http://schemas.microsoft.com/office/infopath/2003/myXSD");
  28.     attribSuggSigner.text = suggSigner;
  29.     
  30.     elemSigSpot.setAttributeNode(attribSigSpotID);
  31.     elemSigSpot.setAttributeNode(attribSuggSigner);
  32.  
  33.     var elemAssignee = XDocument.DOM.createNode(1, "my:Assignee", "http://schemas.microsoft.com/office/infopath/2003/myXSD");
  34.  
  35.     if (suggSignerEmail)
  36.         {
  37.         var elemPerson = XDocument.DOM.createNode(1, "my:Person", "http://schemas.microsoft.com/office/infopath/2003/myXSD");
  38.         var elemPersonName = XDocument.DOM.createNode(1, "my:DisplayName", "http://schemas.microsoft.com/office/infopath/2003/myXSD");
  39.  
  40.         elemPersonName.text = suggSignerEmail;
  41.  
  42.         elemPerson.appendChild(elemPersonName);
  43.         elemAssignee.appendChild(elemPerson);
  44.         }
  45.  
  46.     elemSigSpot.appendChild(elemAssignee);
  47.     
  48.     sigSpotsNode.appendChild(elemSigSpot);
  49. }
  50.  
  51. function compareSpots(a, b) { return a.SortHint - b.SortHint} 
  52.  
  53. function AddSigSpotNodes()
  54. {
  55.     var sigSpotsNode = XDocument.DOM.selectSingleNode("//my:myFields/my:SignatureSpots");
  56.     var sigSpotNode = XDocument.DOM.selectSingleNode("//my:myFields/my:SignatureSpots/my:SignatureSpot");
  57.     sigSpotsNode.removeChild(sigSpotNode);
  58.  
  59.     var thisDoc = XDocument.Host;
  60.  
  61.     var arrSigLines = null;
  62.     var cSigLines = 0;
  63.     var iSigLine = 0;
  64.     var bIsInfopath = false;
  65.  
  66.     // Word / Excel
  67.     if (thisDoc.Signatures)
  68.         {
  69.         thisDoc.Signatures.Subset = 2; //msoSignatureSubsetSignatureLines;
  70.  
  71.         // Copy all the signature lines into an array.
  72.         cSigLines = thisDoc.Signatures.Count;
  73.         
  74.         arrSigLines = new Array(cSigLines);
  75.  
  76.         for (iSigLine = 1; iSigLine <= cSigLines; iSigLine++)
  77.             {
  78.             arrSigLines[iSigLine] = thisDoc.Signatures(iSigLine);
  79.             }
  80.  
  81.         // Now sort the array based on the sort hint
  82.         arrSigLines.sort(compareSpots);
  83.         }
  84.     // InfoPath
  85.     else if (thisDoc.View && thisDoc.View.SignatureLines)
  86.         {
  87.         bIsInfopath = true;
  88.         cSigLines = thisDoc.View.SignatureLines.Count;
  89.         arrSigLines = new Array(cSigLines);
  90.         for (iSigLine = 0; iSigLine < cSigLines; iSigLine++)
  91.             {
  92.             arrSigLines[iSigLine] = thisDoc.View.SignatureLines[iSigLine];
  93.             }
  94.         }
  95.  
  96.     for (iSigLine = 0; iSigLine < cSigLines; iSigLine++)
  97.         {
  98.         var sigspotId;
  99.         var suggSigner;
  100.         var suggSignerEmail;
  101.         var thisSigLine = arrSigLines[iSigLine];
  102.  
  103.         // Word / Excel
  104.         if (!bIsInfopath)
  105.             {
  106.             if (!thisSigLine.IsSignatureLine || (thisSigLine.IsSigned && thisSigLine.IsValid))
  107.                 continue;
  108.             sigspotId = thisSigLine.Setup.Id;
  109.             suggSigner = thisSigLine.Setup.SuggestedSigner;
  110.             suggSignerEmail = thisSigLine.Setup.SuggestedSignerEmail;
  111.             }
  112.         // InfoPath
  113.         else
  114.             {
  115.             if (thisSigLine.Signature && thisSigLine.Signature.Status == 1 /* XdSignatureStatus.Valid */)
  116.                 continue;
  117.             sigspotId = iSigLine;
  118.             suggSigner = thisSigLine.SuggestedSigner;
  119.             suggSignerEmail = thisSigLine.SuggestedSignerEmailAddress;
  120.             }
  121.  
  122.         AddSigSpotNode(sigspotId, suggSigner, suggSignerEmail);
  123.         }
  124. }
  125.  
  126. //=======
  127. // The following function handler is created by Microsoft InfoPath.
  128. // Do not modify the name of the function, or the name and number of arguments.
  129. // This function is associated with the following field or group (XPath): /my:myFields/my:CC
  130. // Note: Information in this comment is not updated after the function handler is created.
  131. //=======
  132. function XDocument::OnLoad(eventObj)
  133. {
  134.     try
  135.     {
  136.     AddSigSpotNodes();
  137.     }
  138.     catch (e)
  139.     {
  140.     XDocument.UI.Alert(e.message);
  141.     }
  142. }
  143.  
  144.