Microsoft Producer for PowerPoint 2003 SDK banner art
PreviousNext

A Complete E-service

The following sample code creates a complete custom user interface with multiple pages.

<HTML>
<!--
***************************************
* This is a full sample e-service.    *
* Be certain to change publishing and *
* playback address paths to match your*
* server address and path.            *
***************************************
-->

<BODY onload = "OnLoad()">

<!-- Create a DIV for the first page. -->
<DIV ID = "page0" NAME = "page0">

This page prompts the user for two property values.<BR>
Copyright is a built-in property. Speaker is a custom property.<BR>
<BR>
Please provide copyright info and the speaker's name.<BR>
<BR>

<!-- These two TEXT elements retrieve the property values. -->
Copyright: <INPUT TYPE = "TEXT" ID = "Copyright" NAME = "Copyright">
Speaker: <INPUT TYPE = "TEXT" ID = "Speaker" NAME = "Speaker">

<BR><BR>
Click <B>Next</B> to continue.
</DIV>

<!-- Create a hidden DIV for the second page. -->
<DIV ID = "page1" NAME = "page1" STYLE = "DISPLAY: none">
 
Please provide a name for the presentation.<BR>
<BR>
<BR>

<!-- This is the TEXT INPUT element that retrieves the name 
     of the presentation from the user. -->
Presentation name: 
<INPUT TYPE = "TEXT" ID = "presName" NAME = "presName">

<BR>
<BR>
<DIV ID = "Feedback" NAME = "Feedback" STYLE = "BACKGROUND: yellow"></DIV>

<BR>
Click <B>Next</B> to select profiles.

</DIV>
<BR>
<DIV ID = "page2" NAME = "page2" STYLE = "DISPLAY: none">
This page allows the user to select publishing profiles. <BR>
The user can select multiple profiles by holding CTRL <BR>
and clicking the profile names. <BR><BR>

<!-- This SELECT element allows the user to choose profiles from
     Producer's Profile Manager. -->
<SELECT id="selProfile" name="selProfile" size = 5 onChange="" MULTIPLE = "true" STYLE="WIDTH: 437px">
</SELECT>
<BR><BR>
Click <B>Next</B> to review publishing parameters.
</DIV>

<DIV ID = "page3" NAME = "page3" STYLE = "DISPLAY: none">
Publishing to: <BR> <BR>

<DIV ID = "Feedback2" NAME = "Feedback2" STYLE = "BACKGROUND: yellow"></DIV>
<BR><BR>
Click <B>Next</B> to publish the presentation.
<BR><BR>

<!-- This BUTTON element shows the file manifest in a dialog box. -->
<INPUT TYPE = "BUTTON" ID = "ShowFiles" VALUE = "List Files To Be Published" OnClick = "Application.Publisher.ShowManifest();
">
</DIV>

<DIV ID = "page4" STYLE = "DISPLAY: none">
You can preview the published presentation.<BR>
Select a profile and click <B>Preview Presentation</B>.<BR>

<SELECT id="selPreview" name="selPreview"  onChange="" STYLE="WIDTH: 437px">
</SELECT>

<INPUT TYPE = "BUTTON" ID = "pPreview" VALUE = "Preview Presentation" OnClick = "PreviewMe();">
<BR><BR><BR><BR><BR><BR><BR>
Click <B>Back</B> to publish again.<BR>
Click <B>Next</B> to finish.
</DIV>

<SCRIPT language = "JScript">

// Global variables that correspond to WebHost properties. 
var Application;
var WebHost;
var ProfileMgr;
var PublishDestination = "http://MyServer/MyPath";
var PlaybackAddress = "http://MyServer/MyPath";

// Other global variables.
var bDoesNotExist; // Stores whether a presentation exists with the same name.
var CurrentPage = 0; // Stores currently visible page number.

// Store the DIV elements in object variables.
var page0 = document.all.item("page0");
var page1 = document.all.item("page1"); 
var page2 = document.all.item("page2");
var page3 = document.all.item("page3");
var page4 = document.all.item("page4");

// This function executes automatically when Producer loads the page.
function OnLoad(){
   // Create the functions to handle the Next and Back button events
   // in the Publish Wizard. 
   window.document.OnWizardNext = MyOnWizardNext;
   window.document.OnWizardBack = MyOnWizardBack;

   // Set the value of the Producer object to window.external 
   // to gain access to the Producer object model.
   Application = window.external;

   // Check whether the Producer version is compatible with this WebHost.
   var AppVersion = Application.Version;
   if (AppVersion.substring(0,3) != "2.0")
      alert ("Warning: Producer version doesn't match.");

   // Create a Profile Manager object.
   ProfileMgr = Application.ProfileManager;

   // Create a Project object.
   Project = Application.Project;

   // Retrieve a Project.Properties object.
   ProjProp = Project.Properties;

   // Retrieve a WebHost object that represents the current e-service.
   WebHost = ProjProp.PublishWebHost;

   // Fill in the Copyright property value.
   Copyright.value = ProjProp.Copyright;

   // Fill in the Speaker property value, if it exists.
   // Loop through the list of custom properties.
   for (var i = 0; i < ProjProp.GetCustomPropertyCount(); i++){
      // Test whether the custom property is Speaker.
      if (ProjProp.GetCustomPropertyName(i) == "Speaker"){
         // Retrieve the value.
         Speaker.value = ProjProp.GetCustomProperty("Speaker");
         break;
      }  
   }     

   
}

// This function executes when the user clicks Next in the Publish Wizard UI.
function MyOnWizardNext(){

   switch (CurrentPage){

      case 0:
         // Store the property values the user entered.
         PersistPropertyValues();

         HidePage(0);
         ShowPage(1);
                      
         // Display the property values in the DIV.
         Feedback.innerHTML = "";
         Feedback.innerHTML += "Properties:<BR>";
         Feedback.innerHTML += "Copyright: " + ProjProp.Copyright + "<BR>";
         Feedback.innerHTML += "Speaker: " + ProjProp.GetCustomProperty("Speaker");

         return;
         break;
   

      case 1:
         // Test whether the user has entered a name for the presentation.
         if (presName.value.length <= 0){
            alert("Please enter a presentation name.");

            return;
         }
      
         try{
            // Set the presentation name.
            ProjProp.PublishName = presName.value;
         }
   
         catch(e){
            alert("Error. Please correct the name.");
            return;
         } 
        
         HidePage(1);
         ShowPage(2);

         // Fill in the profiles list.
         PopulateListBox();

         return;
         break;     
   
      case 2:
      
         // Call the function that retrieves and stores the user-selected profiles.
         GetSelectedProfiles();
 
         // Test whether the user selected a profile. 
         if (Application.Project.Properties.PublishWebHost.GetProfiles().Count == 0){
            alert("You must select at least one profile.")
            return;
         }

         HidePage(2);
         ShowPage(3);

         // Display the parameter values in the DIV.
         Feedback2.innerHTML = "";
         Feedback2.innerHTML += "Publish destination = " + PublishDestination + "<BR>";
         Feedback2.innerHTML += "Playback location = " + PlaybackAddress + "<BR>";

         return;
         break;
   
      case 3:
         // Publish it.
         PublishMe();
         return;
         break;
  
      case 4:
         // Close the window.
         ClosePubWiz();
        
         return;
         break;

      default:
         
         break;
   }
   
}

// This function executes when the user clicks Back in the Publish Wizard UI.
function MyOnWizardBack(){
   
   switch (CurrentPage){

      case 0:
         // Return to the first page of the Publish Wizard.
         return false;
         break;
   
      case 1:
         // Clear the Feedback DIV.
         Feedback.innerHTML = "";
 
         HidePage(1);
         ShowPage(0);
         return true;
         break;
    
      case 2:      
         HidePage(2);
         ShowPage(1);
         return true;
         break;
   
      case 3:    
         HidePage(3);
         ShowPage(2);
         return true;
         break;
  
      case 4:
         HidePage(4);
         ShowPage(0);
         return true;
         break;

      default:
         break;
   }   
}

// This function adds only valid profiles to the selProfile SELECT element list.
function PopulateListBox(){
   // Create a variable to hold a Boolean value
   // that represents whether content on the Producer timeline has video.
   var bHasVideo = Project.TimelineHasVideo;

   // Store the count of profiles contained in the Profile Manager.
   var nCount = ProfileMgr.Count;

   // Test whether the Profile Manager contains profiles.
   if (!nCount > 0){
      // No profiles, alert the user and exit the function.
      alert("Error: No profiles available!");
      return false;
   }

   // Iterate through the profiles in the Profile Manager collection.
   for (var i = 0; i < nCount; i++){
      // Retrieve the profile located at index i.
      var Profile = ProfileMgr.Item(i);

      // If the profile is incompatible with the content,
      // don't add it to the selProfile SELECT element list.
      if (!bHasVideo && Profile.IsVideoProfile)
      continue;

      if (bHasVideo && Profile.IsAudioProfile)
      continue;

      // Always exclude the profiles that are not publish profiles.
      if(!Profile.IsPublishProfile)
      continue;

      // Add the valid profile to the selProfile SELECT element.
      var oOption = document.createElement("OPTION");
      oOption.text = Profile.Name;
      // Store the index that matches the Profile Manager index for later use.
      oOption.value = i; 
      selProfile.add(oOption);
   }
}

function PersistPropertyValues(){
   
   // Persist the copyright information the user provided.
   ProjProp.Copyright = Copyright.value;
  
   // Create or set custom property for the speaker name.
   // Remember that custom properties persist with the project.
   ProjProp.SetCustomProperty("Speaker", Speaker.value);


return;
}

// This function specifies the property values to publish the presentation.
function PublishMe(){
   // Use try/catch error handling to verify publish validation.
   try{
      
      // Set the presentation publish destination.
      WebHost.PublishDestination = PublishDestination;
  
      // Set the playback location.
      WebHost.PlaybackAddress = PlaybackAddress;
  
      // Verify that a presentation doesn't exist with the same name.
      bDoesNotExist = Application.Publisher.ValidatePublishPresentation();
   
      // Test whether ValidatePublishPresentation was successful.
      if (bDoesNotExist == false){
   
         // Prompt the user for permission to overwrite the presentation.                
         var answer = window.confirm("Presentation name exists! OK to overwrite; Cancel to change.");
         
         switch(answer){

            case true:
               // Go ahead and publish.    
               break;
            
            case false:
               // Allow the user to change the presentation name. 
               HidePage(3);
               ShowPage(1);        
               return;
         }
      }
 
      // Publish the presentation.
      Application.Publisher.PublishPresentation();

      // Tell the user it is finished.
      alert ("Publish complete.");

      // Fill the profiles preview list box.
      PopulatePreviewList();

      HidePage(3);
      ShowPage(4);
   }
   
   catch(e){
      // Test whether the error is a Producer error.
      if (e.number == Application.Error.Number){
         // Display the Producer error.
         alert(Application.Error.Description);
      } 

      else {
         // Display the JScript error.
         alert(e.description);
      }
   }
   
   return;
}

// This function retrieves and stores the profiles selected by the user.
function GetSelectedProfiles(){

   // Remove all profiles from the WebHost.
   Application.Project.Properties.PublishWebHost.RemoveAllProfiles();

   // Get the count of options in the select control.
   var selCount = selProfile.options.length;
   
   // Loop through the options list.
   for (var i = 0; i < selCount; i++){
      // Test whether the option is selected.
      if (selProfile.options[i].selected){
         // Get the profile by index.
         var prof = Application.ProfileManager.Item(selProfile.options[i].value);

         // Add the profile to the WebHost.
         WebHost.AddProfile(prof);
      }
   }

   return;
}

// This function opens a browser window to preview the presentation.
function PreviewMe(){

   // Build the URL of the presentation to preview.
   // Start with the playback address.
   var URL = WebHost.PlaybackAddress;

   // Add the presentation name.
   URL += "/";
   URL += ProjProp.PublishName;

   // Add the file name extension and the #profile parameter name.
   URL += ".htm#profile=";

   // Add the index of the selected profile.
   URL += selPreview.value;

   // Launch the presentation in a separate window.
   window.open(URL);
}

// This function fills the selPreview list box.
function PopulatePreviewList(){
   // Remove existing options from the list.
   for (var i = selPreview.length; i >0 ; i--){
      selPreview.remove(i-1);
   }
   
   // Get an array of Profile objects from the WebHost.
   var whProfiles = WebHost.GetProfiles();
 
   // Loop through the array of profiles.
   for (var i=0; i < whProfiles.Count; i++){
      // Add each profile to the selPreview SELECT element.
      var oOption = document.createElement("OPTION");
      oOption.text = whProfiles.item(i).Name;
      // Use the index in the order it exists in the WebHost.
      oOption.value = i;
      selPreview.add(oOption);
   }
}

// This function shows the DIV page passed to the function.
function ShowPage(page){
   // Update the variable that stores the currently visible page number.
   CurrentPage = page;
   
   switch (page){
   
      case 0:
         page0.style.display = "";
         break;

      case 1:
         page1.style.display = "";
         break;
        
       case 2:
         page2.style.display = "";
         break;

      case 3:
         page3.style.display = "";
         break;
 
      case 4:
         page4.style.display = "";
         break;

      default:
         break;
   } 
}

// This function hides the DIV page passed to the function.
function HidePage(page){
   
   switch (page){

      case 0:
         page0.style.display = "none";
         break;

      case 1:
         page1.style.display = "none";
         break;

      case 2:
         page2.style.display = "none";
         break;

      case 3:
         page3.style.display = "none";
         break;
    
      case 4:
         page4.style.display = "none";
         break;

      default:
         break;
   }

}

// This function closes the Publish Wizard.
function ClosePubWiz(){
   // Get a window object that represents the Publish Wizard.
   var WizardWin = Application.Windows.FindByName("PublishWizard");
      
   // Close the Publish Wizard.
   Application.Windows(WizardWin).Close();
}
</SCRIPT>

</BODY>
</HTML>
PreviousNext


© 2001-2003 Microsoft Corporation. All rights reserved.