Sample ASP Page for an Object/Task Selector Page (2)
The following code example shows a sample ASP page code for an Object/Task Selector page that implements sorting.
<%@ Language=VBScript %>
<% Option Explicit %>
<%
'----------------------------------------------------------------------
' OTS Area Page Template
'---------------------------------------------------------------------
%>
<!-- Framework include file path is two levels up relative to this sample
which is <WebRoot>/sample/ots
---------------------------------------------------------------------->
<!-- #include virtual="/admin/inc_framework.asp" -->
<!-- #include virtual="/admin/ots_main.asp" -->
<%
'-------------------------------------------------------------------
' Global Constants
'-------------------------------------------------------------------
Dim SOURCE_FILE
SOURCE_FILE = SA_GetScriptFileName()
'-------------------------------------------------------------------
' Global Variables
'-------------------------------------------------------------------
Dim g_iSortCol
Dim g_sSortSequence
'======================================================
'
' E N T R Y P O I N T
'
' The following few lines implement the mainline entry point for this Web Page.
' Basically we create an Area page (PT_AREA) and then ask the Web Framework
' to start processing events for this page.
'
'======================================================
Dim L_PAGETITLE
Dim page
L_PAGETITLE = "Sorting Example"
'
' Create Page
Call SA_CreatePage( L_PAGETITLE, "images/users_32x32.gif", PT_AREA, page )
'
' Show page
Call SA_ShowPage( page )
'======================================================
'
' E V E N T H A N D L E R S
'
' All of the Public functions that follow implement event handler functions that
' are called by the Web Framework in response to state changes on this web
' page.
'
'======================================================
'---------------------------------------------------------------------
' Function: OnInitPage
'
' Synopsis: Called to signal first time processing for this page. Use this method
' to do first time initialization tasks.
'
' Arguments: [in] oPageIn Page on which this event has been fired.
' [in] oEventArg Event argument for this event.
'
' Returns: Always returns TRUE
'
'---------------------------------------------------------------------
Public Function OnInitPage(ByRef oPageIn, ByRef oEventArg)
OnInitPage = TRUE
'
' Set default values
'
' Sort first column in ascending sequence
g_iSortCol = 0
g_sSortSequence = "A"
End Function
'---------------------------------------------------------------------
' Function: OnServeAreaPage
'
' Synopsis: Called when the page needs to be served. Use this method to
' serve content.
'
' Arguments: [in] oPageIn Page on which this event has been fired.
' [in] oEventArg Event argument for this event.
'
' Returns: Always returns TRUE
'
'---------------------------------------------------------------------
Public Function OnServeAreaPage(ByRef oPageIn, ByRef oEventArg)
Dim table
Dim colFlags
'
' Create the table
table = OTS_CreateTable("", "This sample shows how to use the sorting feature of the Object Task Selector.")
'
' Create Name column
colFlags = (OTS_COL_KEY OR OTS_COL_SORT)
Call OTS_AddTableColumn(table, OTS_CreateColumnEx( "Name", "left", colFlags, 15 ))
'
' Create Description column
colFlags = (OTS_COL_SORT)
Call OTS_AddTableColumn(table, OTS_CreateColumnEx( "Description", "left", colFlags, 40))
'
' Set Tasks section title
Call OTS_SetTableTasksTitle(table, "Tasks")
'
' Add the tasks associated with User objects
'
'
' New user Task is always available (OTS_TaskAlways)
Call OTS_AddTableTask( table, OTS_CreateTaskEx("New", _
"Create a new user's profile", _
"sample/ots/sample_new.asp",_
OTS_PT_PROPERTY,_
"OTS_TaskAlways") )
'
' Delete user Task is available if any task is selected (OTS_TaskAny)
Call OTS_AddTableTask( table, OTS_CreateTaskEx("Delete", _
"Delete one or more users", _
"sample/ots/sample_delete.asp",_
OTS_PT_TABBED_PROPERTY,_
"OTS_TaskAny") )
'
' Properties user Task is available if one task is selected (OTS_TaskOne)
Call OTS_AddTableTask( table, OTS_CreateTaskEx("Properties", _
"Change the properties of a user", _
"sample/ots/sample_change.asp",_
OTS_PT_WIZARD,_
"OTS_TaskOne") )
'
' Add Local Users to the table
Call AddItemsToTable(table)
'
' Enable table multiselection
Call OTS_SetTableMultiSelection(Table, TRUE)
'
' Sort the table
Call OTS_SortTable(table, g_iSortCol, g_sSortSequence, SA_RESERVED)
'
' Send table to the Response stream
Call OTS_ServeTable(table)
'
' All done...
OnServeAreaPage = TRUE
End Function
'---------------------------------------------------------------------
' Function: OnSortNotify()
'
' Synopsis: Sorting notification event handler. This event is triggered in one of
' the following scenarios:
'
' 1) The user presses the search Go button.
' 2) The user presses either the page next or page previous buttons
' 3) The user requests a table column sort
'
' The oEventArg indicates the source of this notification event which can
' be either a sorting change event (scenario 1) or a post back event
' (scenarios 2 or 3)
'
' The sortCol argument indicated which column the user would like to sort
' and the sortSeq argument indicates the desired sort sequence which can
' be either ascending or descending.
'
' Arguments: [in] oPageIn Page on which this event has been fired.
' [in] oEventArg Event argument for this event.
' [in] iSortCol Column number of the column that is to be sorted.
' [in] sSortSeq Sequence that the column is to be sorted. "A" for ascending,
' "D" for descending.
'
' Returns: Always returns TRUE
'
'---------------------------------------------------------------------
Public Function OnSortNotify(ByRef oPageIn, _
ByRef oEventArg, _
ByVal iSortCol, _
ByVal sSortSeq )
OnSortNotify = TRUE
g_iSortCol = iSortCol
g_sSortSequence = sSortSeq
End Function
Private Function AddItemsToTable(ByRef Table)
on error resume next
err.clear
'
' Fetch the list of users and add them to the table
'
Dim oContainer
Dim oUser
'
' ADSI call to get the local computer object
Set oContainer = GetObject("WinNT://" + GetComputerName() )
'
' ADSI call to get the collection of local users
oContainer.Filter = Array("User")
For Each oUser in oContainer
Call OTS_AddTableRow( Table, Array(oUser.Name, oUser.Description))
Next
Set oContainer = Nothing
End Function
Private Function GetComputerName()
on error resume next
err.clear
Dim oSysInfo
Set oSysInfo = CreateObject("WinNTSystemInfo")
GetComputerName = oSysInfo.ComputerName
Set oSysInfo = Nothing
End Function
%>