Помогите с добавлением документа на HD. У меня есть готовое дерево которое описывает структуру каталога. Мне необходимо при нажатию на кнопку, добавлять новый документ в дерево каталогов (оно загружается в левый фрейм) а также в этой папке создавать новую ссылку на нужный документ на диске (для упрощения новая папка уже скопирована в корневой каталог). На Java script статическая структура дерева организована. Заранее благодарю. Вот примерный код:
<HTML>
<HEAD>
<link rel="stylesheet" href="style.css" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=windows-1251">
<title>Материалы к ИИ</title>
<script language="JavaScript">
<!--
function thetext(txt) {
document.theform.thetext.value = txt
return true;
}
//-->
</script><script language="JavaScript"><!--
function atext(txt) {
document.aform.atext.value = txt
return true;
}
//--></script>
<script LANGUAGE="JavaScript">
//each node in the tree is an Array with 4+n positions
// node[0] is 0/1 when the node is closed/open
// node[1] is 0/1 when the folder is closed/open
// node[2] number of children that are documents
// node[3] is the name of the folder
// node[4]...node[4+n] are the n children nodes
// ***************
// Building the data in the tree
function generateTree()
{
var aux1, aux2, aux3, aux4
USETEXTLINKS = 0
foldersTree = gFld("Материалы к ИИ")
//Описание каталога Case&UML - Начало
aux1 = insFld(foldersTree, gFld("case и UML"))
aux2 = insFld(aux1, gFld("CASE-Технологии Вендров"))
insDoc(aux2, gLnk(0, "CASE-технологии", "c:/Материал к ИИ/case и UML/CASE-Технологии Вендров/index.htm"))
...... и.т.д каждый каталог.
clickOnFolderRec(foldersTree, "Материалы к ИИ")
}
// Auxiliary function to build the node
function gFld(name)
{
var arrayAux
arrayAux = new Array
arrayAux[0] = 0
arrayAux[1] = 0
arrayAux[2] = 0
arrayAux[3] = name
return arrayAux
}
//Append Child of type Folder
function insFld(parent, child)
{
parent[parent.length] = child
return child
}
//Append Child of type Doc
function insDoc(parent, child)
{
parent[2] = parent[2] + 1
parent[parent.length] = child
return child
}
//these are the last entries in the hierarchy, the local and remote links to html documents (gLnk=generateLinkEntry)
function gLnk(icon, docDescription, link)
{
if (USETEXTLINKS)
return daveLnk(icon, docDescription, link)
var retString =""
if (icon==0)
{
retString = "<A href='"+link+"' target=folderFrame><img src='doc.gif' alt='Opens in right frame'"
}
else
{
if (icon==1)
retString = "<A href='"+link+"' target=_blank><img src='link.gif' alt='Opens in new window'"
else
retString = "<A href='"+link+"' target=folderFrame><img src='link.gif' alt='Opens in right frame'"
}
retString = retString + " border=0></a><td nowrap><font size=-1 face='Arial, Helvetica'>" + docDescription + "</font>"
return retString
}
// This function by davespeed
function daveLnk(icon, docDescription, link)
{
var retString =""
var l1=""
var l2="folderFrame"
var l3="doc"
var l4="right frame"
if (icon!=0) {
l1="http://"
l2="_blank"
l3="link"
l4="new window"
}
if (icon==2) {
l2="folderFrame"
l4="right frame"
}
retString = "<A href='"+l1+link+"' target="+l2+"><img src='"+l3+".gif' alt='Opens in " +l4+ "' border=0></a><td nowrap><A href='"+l1+link+"' target="+l2+"><font size=-1 face='Arial, Helvetica'>" + docDescription + "</font></a>"
return retString
}
// **********************
// display functions
//redraws the left frame
function redrawTree()
{
var doc = top.treeFrame.window.document
doc.clear()
doc.write("<body bgcolor='white'>\n")
redrawNode(foldersTree, doc, 0, 1, "")
doc.close()
}
//recursive function over the tree structure called by redrawTree
function redrawNode(foldersNode, doc, level, lastNode, leftSide)
{
var j=0
var i=0
var numberOfFolders
var numberOfDocs
doc.write("<table border=0 cellspacing=0 cellpadding=0>\n")
doc.write("<tr>\n<td valign = middle nowrap>\n")
doc.write(leftSide)
if (level>0)
if (lastNode) //the last 'brother' in the children array
{
doc.write("<img src='lastnode.gif' width=16 height=22>")
leftSide = leftSide + "<img src='blank.gif' width=16 height=22>"
}
else
{
doc.write("<img src='node.gif' width=16 height=22>")
leftSide = leftSide + "<img src='vertline.gif' width=16 height=22>"
}
displayIconAndLabel(foldersNode, doc)
doc.write("</table>\n\n")
if (foldersNode.length > 4 && foldersNode[0]) //there are sub-nodes and the folder is open
{
numberOfFolders = foldersNode.length - 4 - foldersNode[2]
// display the folders
level = level + 1
for (i=4 ; i < 4 + numberOfFolders; i++)
{
if (i == (foldersNode.length - 1))
redrawNode(foldersNode[i], doc, level, 1, leftSide)
else
redrawNode(foldersNode[i], doc, level, 0, leftSide)
}
// display the documents
for ( i = 4 + numberOfFolders; i < foldersNode.length ; i++ )
{
doc.write("<table border=0 cellspacing=0 cellpadding=0 valign=middle>")
doc.write("<tr><td nowrap>")
doc.write(leftSide)
if (i == foldersNode.length - 1)
doc.write("<img src='lastnode.gif' width=16 height=22>")
else
doc.write("<img src='node.gif' width=16 height=22>")
doc.write("</td><td>")
doc.write(foldersNode[i])
doc.write("</tr>")
doc.write("</table>")
}
}
}
//builds the html code to display a folder and its label
function displayIconAndLabel(foldersNode, doc)
{
doc.write("<A href='javascript:top.openBranch(\"" + foldersNode[3] + "\")'")
if (foldersNode[1])
{
doc.write(" onMouseOver=\'window.status=\"Close folder\"; return true\'><img src=")
doc.write("openfolder.gif width=24 height=22 border=noborder></a>")
}
else
{
doc.write("onMouseOver='window.status=\"Open folder\"; return true'><img src=")
doc.write("closedfolder.gif width=24 height=22 border=noborder></a>")
}
doc.write("<td valign=middle align=left nowrap>")
doc.write("<font size=-1 face='Arial, Helvetica'>"+foldersNode[3]+"</font>")
}
//**********************
// Recursive functions
//when a parent is closed all children also are
function closeFolders(foldersNode)
{
var i=0
for (i=4; i< foldersNode.length - foldersNode[2]; i++)
closeFolders(foldersNode[i])
foldersNode[0] = 0
foldersNode[1] = 0
}
//recursive over the tree structure
//called by openbranch
function clickOnFolderRec(foldersNode, folderName)
{
var i=0
if (foldersNode[3] == folderName)
{
if (foldersNode[0])
closeFolders(foldersNode)
else
{
foldersNode[0] = 1
foldersNode[1] = 1
}
}
else
{
for (i = 4 ; i < foldersNode.length - foldersNode[2]; i++)
clickOnFolderRec(foldersNode[i], folderName)
}
}
// ********************
// Event handlers
//called when the user clicks on a folder
function openBranch(branchName)
{
clickOnFolderRec(foldersTree, branchName)
if (branchName==foldersTree[3] && foldersTree[0]==0)
top.folderFrame.location="basefolder.html" //closing the root folder
//makes the welcome page to show
timeOutId = setTimeout("redrawTree()",100)
}
//called after this html file is loaded
function initializeTree()
{
generateTree()
redrawTree()
}
var foldersTree = 0
var timeOutId = 0
var USETEXTLINKS = 0
generateTree() //sometimes when the user reloads the document Netscape 3.01 does not trigger the onLoad event (!!)
</script>
</HEAD>
<FRAMESET cols="35%, 65%" onLoad='initializeTree()'>
<FRAME src="basetree.html" name="treeFrame" scrolling="auto">
<FRAMESET rows="10%,90%">
<FRAME src="menu.htm" name="telo" scrolling="auto">
<FRAME src="index1-1.html" name="name" scrolling="auto">
</frameset>
</HTML>