Classes _asp class class for generating directory tree structure under ASP

Source: Internet
Author: User
About classes that generate a directory tree structure

This program has two files test.asp and tree.asp and some icon files
1. The test.asp call class generates the tree code as follows
<%@ Language=vbscript%>
<link rel= "stylesheet" href= "Tree.css" >
<title>tree</title>
<!--#include file= "tree.asp"-->
<%

'========================================
' Building A Tree programatically
'========================================
' This approach would is best suited for building
' Dynamic trees using for.. Next loops and such.

Set MyTree2 = New Tree
Mytree2.top = 10
Mytree2.left = 10
Mytree2.expandimage = "Plus.gif"
Mytree2.collapseimage = "Minus.gif"
Mytree2.leafimage = "Webpage.gif"

' Notice the indentation used to reprensent the hierarchy
Set Node1 = mytree2.createchild ("script")
Set SubNode1 = node1.createchild ("server")
Set secSubNode1 = subnode1.createchild ("html")
Secsubnode1.createchild "<a href=" "HTTP://127.0.0.1/" ">asp</A>"
Secsubnode1.createchild "<a href=" "HTTP://127.0.0.1/" ">php</A>"
Secsubnode1.createchild "<a href=" "HTTP://127.0.0.1/" ">jsp</A>"

Set SubNode2 = node1.createchild ("OS")
Subnode2.createchild "<a href=" "#" ">winnt</A>"
Subnode2.createchild "<a href=" "#" ">win2000</A>"

Set Node2 = Mytree2.createchild ("Desktop")
Node2.createchild "<a href=" "#" ">area Code lookup</a>"
Node2.createchild "<a href=" "#" ">arin Based Whois search</a>"
Node2.createchild "<a href=" "#" ">world Time Zone map</a>"

Mytree2.draw ()

Set MyTree2 = Nothing

%>

</BODY>
</HTML>
2. The definition code for the Tree.asp class is as follows
<%
'******************************************************
' Author:jacob Gilley
' Email:avis7@airmail.net
' My terms:you can-control ' anyway for you
' Cause I have no means to enforce any guidelines
' or BS that most developers to they can get
' You'll agree to by spouting out words like
' Intellectual property ' and ' The Code Gods '.
'-Viva la microsoft!
'******************************************************

Dim Gbltreenodecount:gbltreenodecount = 1

Class TreeNode

Public Value
Public Expandimage
Public Collapseimage
Public Leafimage
Public Expanded
Private Mszname
Private Mcolchildren
Private mbchildreninitialized

Public Property Get ChildCount ()
ChildCount = Mcolchildren.count
End Property

Private Sub Class_Initialize ()
Mszname = "Node" & CStr (Gbltreenodecount)
Gbltreenodecount = Gbltreenodecount + 1

mbchildreninitialized = False
Expanded = False
End Sub

Private Sub Class_Terminate ()
If mbchildreninitialized and IsObject (Mcolchildren) Then
Mcolchildren.removeall ()
Set Mcolchildren = Nothing
End If
End Sub

Private Sub initchildlist ()
Set Mcolchildren = Server.CreateObject ("Scripting.Dictionary")
mbchildreninitialized = True
End Sub

Private Sub LoadState ()
If request (Mszname) = "1" Or Request ("togglenode") = Mszname Then
Expanded = True
End If
End Sub

Public Function Createchild (szvalue)

If not mbchildreninitialized Then initchildlist ()

Set createchild = New TreeNode
Createchild.value = Szvalue
Createchild.expandimage = Expandimage
Createchild.collapseimage = Collapseimage
Createchild.leafimage = Leafimage

Mcolchildren.add Mcolchildren.count + 1, createchild

End Function

Public Sub Draw ()

LoadState ()

Response.Write "<table border=" "0" ">" & vbCrLf
Response.Write "<tr><td>" & VbCrLf

If Expanded Then
Response.Write "<a href=" "Javascript:collapsenode ('" & Mszname & ")" "></a>" & VbCrLf
ElseIf not mbchildreninitialized Then
Response.Write "Else
Response.Write "<a href=" "Javascript:expandnode ('" & Mszname & ")" "></a>" & VbCrLf
End If

Response.Write "</td>" & VbCrLf
Response.Write "<td>" & Value & "</td></tr>" & VbCrLf

If Expanded Then
Response.Write "<input type=" "Hidden" "Name=" "" & Mszname & "" "Value=" "1" ">" & vbCrLf

If mbchildreninitialized Then
Response.Write "<tr><td> </td>" & vbCrLf
Response.Write "<td>" & VbCrLf

For each childnode in Mcolchildren.items
Childnode.draw ()
Next

Response.Write "</td>" & VbCrLf
Response.Write "</tr>" & VbCrLf
End If
End If

Response.Write "</table>" & VbCrLf

End Sub

End Class


Class Tree

Public top
Public left
Public Expandimage
Public Collapseimage
Public Leafimage
Private mszposition
Private Mcolchildren

Public Property Let Absolute (Bdata)
If bdata Then mszposition = "Absolute" Else mszposition = "relative"
End Property

Public Property Get Absolute ()
Absolute = CBool (mszposition = "Absolute")
End Property

Private Sub Class_Initialize ()
Set Mcolchildren = Server.CreateObject ("Scripting.Dictionary")
Mntop = 0
Mnleft = 0
Mszposition = "Absolute"
End Sub

Private Sub Class_Terminate ()
Mcolchildren.removeall ()
Set Mcolchildren = Nothing
End Sub

Public Function Createchild (szvalue)

Set createchild = New TreeNode

Createchild.value = Szvalue
Createchild.expandimage = Expandimage
Createchild.collapseimage = Collapseimage
Createchild.leafimage = Leafimage

Mcolchildren.add Mcolchildren.count + 1, createchild

End Function

Public Sub loadtemplate (szFileName)
Dim Objworkingnode
Dim Colnodestack
Dim Fsobj, Tsobj
Dim Szline
Dim Ncurrdepth, Nnextdepth

Set colnodestack = Server.CreateObject ("Scripting.Dictionary")
Set fsobj = CreateObject ("Scripting.FileSystemObject")
Set tsobj = Fsobj.opentextfile (szFileName, 1)

ncurrdepth = 0
While not tsobj.atendofline
Nnextdepth = 1
Szline = Tsobj.readline ()

If ncurrdepth = 0 Then
Set Objworkingnode = Createchild (Trim (szline))
Ncurrdepth = 1
Else
While Mid (szline,nnextdepth,1) = VbTab Or Mid (szline,nnextdepth,1) = ""
nnextdepth = nnextdepth + 1
Wend

If nnextdepth > 1 Then szline = Trim (Mid (szline,nnextdepth))

If szline <> "" Then
If nnextdepth > Ncurrdepth Then
If colnodestack.exists (ncurrdepth) Then
Set Colnodestack.item (ncurrdepth) = Objworkingnode
Else
Colnodestack.add Ncurrdepth, Objworkingnode
End If

Set Objworkingnode = Objworkingnode.createchild (szline)

ncurrdepth = ncurrdepth + 1
ElseIf nnextdepth <= ncurrdepth Then

If nnextdepth > 1 Then

Nnextdepth = nNextDepth-1
While not colnodestack.exists (nnextdepth) and nnextdepth > 1
Nnextdepth = nNextDepth-1
Wend

Set Objworkingnode = Colnodestack.item (nnextdepth)
Set Objworkingnode = Objworkingnode.createchild (szline)

nnextdepth = nnextdepth + 1
Else
Set Objworkingnode = Createchild (szline)
End If

Ncurrdepth = nnextdepth
End If
End If

End If
Wend

Tsobj.close ()
Set tsobj = Nothing
Set fsobj = Nothing

Colnodestack.removeall ()
Set Colnodestack = Nothing

End Sub


Public Sub Draw ()

Addclientscript ()

Response.Write "<div id=" "Treectrl" "style=" "Left: & Left &" PX; Top: "& top &" PX; Position: "& mszposition &"; "" > "& vbCrLf
Response.Write "<form name=" "Treectrlfrm" "action=" "" & Request.ServerVariables ("Script_name") & "" = "" Get "" > "& vbCrLf
Response.Write "<table border=" "0" ">" & vbCrLf
Response.Write "<tr><td>" & VbCrLf

For each childnode in Mcolchildren.items
Childnode.draw ()
Next

Response.Write "</td></tr>" & VbCrLf
Response.Write "</table>" & VbCrLf

Response.Write "<input type=" "Hidden" "name=" "Togglenode" "value=" "" ">" & vbCrLf
Response.Write "</form>" & VbCrLf
Response.Write "</div>" & VbCrLf

End Sub

Private Sub Addclientscript ()
%>
<script language= "JavaScript" >

function Expandnode (sznodename)
{
if (document.layers!= null) {
Document.treectrl.document.treectrlfrm.togglenode.value = Sznodename;
Document.treectrl.document.treectrlfrm.submit ();
}
else {
document.all["treectrlfrm"].togglenode.value = Sznodename;
document.all["Treectrlfrm"].submit ();
}
}

function Collapsenode (sznodename)
{
if (document.layers!= null) {
Document.treectrl.document.treectrlfrm.elements[sznodename].value =-1;
Document.treectrl.document.treectrlfrm.submit ();
}
else {
Document.treectrlfrm.elements[sznodename].value =-1;
Document.treectrlfrm.submit ();
}
}

</script>
<%
End Sub

End Class

%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.