The Server Behavior API

 < Day Day Up > 

You can manage server behaviors with the following API functions.

analyzeServerBehavior()

Availability

Dreamweaver UltraDev 1

Description

Lets server behaviors set their incomplete and deleted properties.

After the findServerBehaviors() function is called for every server behavior on the page, an array of all the behaviors in the user's document appears. The analyzeServerBehavior() function is called for each JavaScript object in this array. For example, for a Dynamic Text behavior, Dreamweaver calls the analyzeServerBehavior() function in the DynamicText.htm (or DynamicText.js) file.

One purpose of the analyzeServerBehavior() function is to finish setting all the properties (incomplete, participants, selectedNode, and title) on the behavior object. Sometimes it's easier to perform this task after the findServerBehaviors() function generates the complete list of server behaviors in the user's document.

The other purpose of the analyzeServerBehavior() function is to notice when two or more behaviors refer to the same tag in the user's document. In this case, the deleted property removes all but one behavior from the array.

Suppose the Recordset1, DynamicText1, and DynamicText2 server behaviors are on a page. Both DynamicText server behaviors need Recordset1 to exist on the page. After the server behaviors are found with the findServerBehaviors() function, Dreamweaver calls the analyzeServerBehavior() function for the three server behaviors. When the analyzeServerBehavior() function is called for DynamicText1, the function searches the array of all the server behavior objects on the page, looking for the one that belongs to Recordset1. If a server behavior object that belongs to Recordset1 cannot be found, the incomplete property is set to the value true so that an exclamation point appears in the Server Behaviors panel, which alerts the user that a problem exists. Similarly, when the analyzeServerBehavior() function is called for DynamicText2, the function searches for the object that belongs to Recordset1. Because Recordset1 does not depend on other server behaviors, it does not need to define the analyzeServerBehavior() function in this example.

Arguments

 serverBehavior, [serverBehaviorArray] 

  • The serverBehavior argument is a JavaScript object that represents the behavior to analyze.

  • The [serverBehaviorArray] argument is an array of JavaScript objects that represents all the server behaviors that are found on a page.

Returns

Dreamweaver expects nothing.

applyServerBehavior()

Availability

Dreamweaver UltraDev 1.

Description

Reads values from the form elements in the dialog box and adds the behavior to the user's document. Dreamweaver calls this function when the user clicks OK in the Server Behaviors dialog box. If this function returns successfully, the Server Behaviors dialog box closes. If this function fails, it displays an error message without closing the Server Behaviors dialog box. This function can edit a user's document.

For more information, see "dwscripts.applySB()" on page 336.

Arguments

 serverBehavior 

  • The serverBehavior JavaScript object represents the server behavior; it is necessary to modify an existing behavior. If this is a new behavior, the argument is null.

Returns

Dreamweaver expects an empty string if successful or an error message if this function fails.

canApplyServerBehavior()

Availability

Dreamweaver UltraDev 1.

Description

Determines whether a behavior can be applied. Dreamweaver calls this function before the Server Behaviors dialog box appears. If this function returns a true value, the Server Behaviors dialog box appears. If this function returns a false value, the Server Behaviors dialog box does not appear and the attempt to add a server behavior stops.

Arguments

 serverBehavior 

  • The serverBehavior JavaScript object represents the behavior; it is necessary to modify an existing behavior. If this is a new behavior, the argument is null.

Returns

Dreamweaver expects a Boolean value: TRue if the behavior can be applied; false otherwise.

copyServerBehavior()

Availability

Dreamweaver UltraDev 1.

Description

Implementing the copyServerBehavior() function is optional. Users can copy instances of the specified server behavior. In the following example, this function is implemented for recordsets. If a user selects a recordset in the Server Behaviors panel or the Data Binding panel, using the Copy command copies the behavior to the Clipboard; using the Cut command cuts the behavior to the Clipboard. For server behaviors that do not implement this function, the Copy and Cut commands do nothing. For more information, see "How the Server Behavior API functions are called" on page 326.

The copyServerBehavior() function should rely only on behavior object properties that can be converted into strings to exchange information with the pasteServerBehavior() function. The Clipboard stores only raw text, so participant nodes in the document should be resolved and the resulting raw text should be saved into a secondary property.

NOTE

The pasteServerBehavior() function must also be implemented to let the user paste the behavior into any Dreamweaver document.


Arguments

 serverBehavior 

  • The serverBehavior JavaScript object represents the behavior.

Returns

Dreamweaver expects a Boolean value: TRue if the behavior copies successfully to the Clipboard; false otherwise.

deleteServerBehavior()

Availability

Dreamweaver UltraDev 1.

Description

Removes the behavior from the user's document. It is called when the user clicks the Minus (-) button on the Server Behaviors panel. It can edit a user's document.

For more information, see "dwscripts.deleteSB()" on page 337.

Arguments

 serverBehavior 

  • The serverBehavior JavaScript object represents the behavior.

Returns

Dreamweaver expects nothing.

displayHelp()

Description

If this function is defined, a Help button appears below the OK and Cancel buttons in the dialog box. This function is called when the user clicks the Help button.

Arguments

None.

Returns

Dreamweaver expects nothing.

Example

 // the following instance of displayHelp() opens // in a browser a file that explains how to use // the extension. function displayHelp(){   var myHelpFile = dw.getConfigurationPath() +     '/ExtensionsHelp/superDuperHelp.htm';   dw.browseDocument(myHelpFile); } 

findServerBehaviors()

Availability

Dreamweaver UltraDev 1.

Description

Searches the user's document for instances of itself. For each instance it finds, the findServerBehaviors() function creates a JavaScript object, and it attaches state information as JavaScript properties of the object.

The four required properties are incomplete, participants, title, and selectedNode. You can set additional properties as necessary.

For more information, see dwscripts.findSBs() and dreamweaver.getParticipants() in the Dreamweaver API Reference.

Arguments

None.

Returns

Dreamweaver expects an array of JavaScript objects; the length of the array is equal to the number of behavior instances that are found in the page.

inspectServerBehavior()

Availability

Dreamweaver UltraDev 1.

Description

Determines the settings for the Server Behavior dialog box, based on the specified behavior object. Dreamweaver calls the inspectServerBehavior() function when a user opens a Server Behavior dialog box. Dreamweaver calls this function only when a user edits an existing behavior.

Arguments

 serverBehavior 

  • The serverBehavior argument is a JavaScript object that represents the behavior. It is the same object that findServerBehaviors() returns.

Returns

Dreamweaver expects nothing.

pasteServerBehavior()

Availability

Dreamweaver UltraDev 1.

Description

If this function is implemented, users can paste instances of the specified server behavior using the pasteServerBehavior() function. When the user pastes the server behavior, Dreamweaver organizes the contents of the Clipboard and generates a new behavior object. The new object is identical to the original, except that it lacks pointer properties. Dreamweaver passes the new behavior object to the pasteServerBehavior() function. The pasteServerBehavior() function relies on the properties of the behavior object to determine what to add to the user's document. The pasteServerBehavior() function then adds the behavior to the user's document. After pasteServerBehavior() returns, Dreamweaver calls the findServerBehaviors() functions to get a new list of all the server behaviors in the user's document.

Implementing the pasteServerBehavior() function is optional. For more information, see "How the Server Behavior API functions are called" on page 326.

NOTE

If you implement this function, you must also implement the copyServerBehavior() function.


Arguments

 behavior 

  • The behavior JavaScript object represents the behavior.

Returns

Dreamweaver expects a Boolean value: TRue if the behavior pastes successfully from the Clipboard; false otherwise.

     < Day Day Up > 


    Developing Extensions for Macromedia Dreamweaver 8
    Developing Extensions for Macromedia Dreamweaver 8
    ISBN: 0321395409
    EAN: 2147483647
    Year: 2005
    Pages: 282

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net