Allowing the User to Select Profiles
The following sample code creates a Web page that is displayed in the hosted browser window that is the custom user interface in the Microsoft Producer Publish Wizard. This sample illustrates how to enable the user to select a profile from a list of profiles. The code checks the Producer content and determines which profiles are valid. Be sure to replace any URLs with your server address.
<HTML>
<!--
**************************************************
** This is a sample of a custom user interface **
** HTML document. This sample creates a list **
** of profiles that are valid for the type of **
** content on the Producer presentation time- **
** line. The user can select one publishing **
** profile from the list. **
**************************************************
-->
<BODY onload = "OnLoad()">
This page allows the user to publish the presentation.<BR>
All the values are supplied in script, except <BR>
the name of the presentation and the publish profile, <BR>
which are supplied by the user.<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>
<!-- This SELECT element allows the user to choose a profile from
Producer's Profile Manager. -->
<SELECT id="selProfile" name="selProfile" onChange="" STYLE="WIDTH: 437px">
<OPTION VALUE = "a" SELECTED> -- Please select a profile from the list below -- </option>
</SELECT>
<BR><BR>
Publish Destination: http://MyServer/MyPath <BR>
Playback Address: http://MyServer/MyPath
<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";
// This function executes automatically when Producer loads the page.
function OnLoad(){
// Create two 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.");
// Retrieve a WebHost object that represents the current e-service.
WebHost = Application.Project.Properties.PublishWebHost;
// Create a Profile Manager object.
ProfileMgr = Application.ProfileManager;
// Create a Project object.
Project = Application.Project;
// Fill the selProfile SELECT element with a list of valid profiles.
PopulateListBox();
}
// This function executes when the user clicks Next in the Publish Wizard UI.
function MyOnWizardNext(){
// Test whether the user has entered a name for the presentation.
if (presName.value.length <= 0){
alert("Please enter a presentation name.");
return true;
}
// Test whether the user has selected a profile.
if (isNaN(parseInt(selProfile.value))){
alert("Please select a valid publishing profile.");
return true;
}
// Get the profile from Profile Manager that corresponds
// to the one the user selected.
var myProfile = ProfileMgr.Item(selProfile.value)
// Add the profile to the WebHost object.
WebHost.AddProfile(myProfile);
// Set the presentation name.
Application.Project.Properties.PublishName = presName.value;
// Set the presentation publish destination.
WebHost.PublishDestination = PublishDestination;
// Set the playback location.
WebHost.PlaybackAddress = PlaybackAddress;
// Call the function that publishes the presentation.
PublishMe();
return;
}
// This function executes when the user clicks Back in the Publish Wizard UI.
function MyOnWizardBack() {
// Navigate to the Publish Wizard first page.
return false;
}
// 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 Manaager.
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;
oOption.value = i;
selProfile.add(oOption);
}
}
// This function starts the publishing process.
function PublishMe(){
// Use try/catch error handling to verify publish validation.
try{
// Verify that a presentation doesn't exist with the same name.
var bDoesNotExist = Application.Publisher.ValidatePublishPresentation();
// Test whether ValidatePublishPresentation was successful.
if (bDoesNotExist == true){
// Publish the presentation.
Application.Publisher.PublishPresentation()
// Tell the user it is done.
alert("Publish complete.");
// Close the wizard.
ClosePubWiz();
}
else{
// Tell the user that there is a problem.
alert ("Cannot publish because the name exists.")
}
}
catch(e){
// Show an error message.
alert ("There were errors. Publish failed.");
}
}
// 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>
For more information about this sample, see the Working with Profiles section in the Programming Guide.
© 2001-2003 Microsoft Corporation. All rights reserved.