Ajax

The follow pages contain live running PowerShell scripts that have been enhanced to support ATPowerForm's web rendering ability. Since these script are running in a shared hosting environment normal administrative PowerShell functions will not be presented. This can be done via the Trial download, all sample are included with the product.

PowerShell - Ajax Demo

The Ajax Demo shows the ability of ATPowerForm to handle PowerShell processing via asynchronous Ajax executions. ATPowerForm allows any displayed field or operation to be Ajax enabled or not. The form below demonstrates three types or ATPowerForm Ajax field definitions. Non-blocking allow Ajax calls to be performed without blocking the user from updating another field (can cause potential issues on slower systems, causing the any PowerShell results to be lost since only one Ajax call can be made at a time). Field Blocking displays a progress bar only over the field that was updating (not blocking users from making other changes). Then lastly is Page blocking where the entire page is blocked until the update is completed.

Type anything then TAB or click off the control to see the response.


Ajax non-blocked Update
   

Ajax Field Update
   

Ajax Page Update
   

Non-Ajax Field
   

<#
.SYNOPSIS
    Ajax Demionstration
.DESCRIPTION
    The following Script demonstrates both Field amd Page level Ajax functionality.
.NOTES
    ATPowerForm compatible scripts can be designed to execute via command line
    without the requirement of a graphical interface.

    Script Name:        Ajax_DEmo
    Version:            1.0
      Author:           NuDigital Solutions
      Creation Date:    08/10/2014
      Purpose/Change:   Initial script development
#>
param(
    [string]$pfCMD = "",
    [int]$pfField,
    [hashtable]$pfFields = @{},
    [hashtable]$pfDetails = @{},
    [hashtable]$pfGlobals = @{},
    [string]$pfModPath = $Env:ATPowerForm
)

################################
# Load ATPowerForm Interfaces
$pfScriptPath = $MyInvocation.MyCommand.Path;
. $pfModPath\ATPowerForm.ps1;
################################

##########################################
# Custom variable and constant assignments
##########################################
#    ... code... 


<#
.SYNOPSIS
    Optional method to create ATPowerForm control definitions for rendoring in the UI 
.DESCRIPTION
    This method is only executed when the ATPowerForm is first initalized. 
    The pfPaint method is used to create controls and there default values.
#>
function pfPaint
{
    pfButton -GroupType CmdGroup -ButtonType Cancel -Field 100  -Text "Cancel" -Space 40;
    pfTextbox -Field 10 -Ajax NonBlocking -Label "Ajax non-blocked Update" -Help "Changing text and leaving this field will cause a 10 second sleep" -PSCall True -Width 200;
    pfLiteral -Field 11 -Ajax NonBlocking -Space 3;
    pfTextbox -Field 12 -Ajax FieldBlocking -Label "Ajax Field Update" -Help "Changing text and leaving this field will cause a 10 second sleep" -PSCall True -Width 200;
    pfLiteral -Field 13 -Ajax NonBlocking -Space 3;
    pfTextbox -Field 14 -Ajax PageBlocking -Label "Ajax Page Update" -Help "Changing text and leaving this field will cause a 10 second sleep" -PSCall True -Width 200;
    pfLiteral -Field 15  -Ajax NonBlocking -Space 3;
    pfTextbox -Field 16 -Label "Non-Ajax Field" -Help "Force Page repaint after 10 second sleep" -PSCall True -Width 200;
    pfLiteral -Field 17  -Ajax NonBlocking -Space 3;
}


<#
.SYNOPSIS
    Method for validation and processing of ATPowerForm control events 
.DESCRIPTION
    This method is executed when a control is changed (requiring parameter PSCall
    value of the control to be set to true). Any operation is available from 
    validating control data to changing the UI look and feel in real time.
#>
function pfEvent
{
    Switch ($pfField)
    {
        {10,12,14,16 -contains $_}    {# Sleep to 10 seconds
            sleep -Seconds 10
            pfdata -Field $($pfField + 1) -Value $pfFields[$pfField]
        }
            
    }
}

#########################
# Main Execution and Exit
#########################
if ($pfCMD -ne "") {
    #pfTrace -Type Both -Style Parameter;
    $pfSuccess = pfExecute; # ATPowerForm Execution function
    Return $pfReturnData;
}

#    ... code (non-graphical command line execution) ...