ID:1547476
 
(See the best response by Ter13.)
Problem description:

So, im back, this is with another issue which will most likely be my last one for a bit, so i have a verb that allows files to be sent to a directory such as /file/[createddirectory/ and i was wondering if someone could help me with;

1) downloading a file from the directory
2) using a input to search related tags (going to have 4 tags each on inputed)
3) I have 5 directories, and i am using an html popup with tables ( i can make this myself) how would i make it browse and fill in the tables its self

thanks in advanced
File() is what you should be looking at to reference a file from a directory. I'm not exactly sure what you mean by searching for tags, but you could probably accomplish it through looping use of findtext.

If players are downloading said file, you can use ftp to send them the file to be downloaded at their discretion.

src << ftp(file("/file/[createddirectory]/filename.txt"))


Browse() can be used with full HTML support, and you can create it right within your method. So, this:

var/HTML={"
<style>
body{
background: black;
}
table, td, th{
spacing: 0;
border: 1px solid white;
border-collapse: collapse;
color: white;
font-size: 15 px;
}
td,th{
padding:10px;
}
</style>
<center>
<table>
<tr>
<th>Table name!</th>
</tr>
<tr>
<td>Table value!</td>
</tr>
</table>
</body>
</center>
</html>"}

src<<browse(HTML)
In response to Crazah
Crazah wrote:
File() is what you should be looking at to reference a file from a directory. I'm not exactly sure what you mean by searching for tags, but you could probably accomplish it through looping use of findtext.

If players are downloading said file, you can use ftp to send them the file to be downloaded at their discretion.

> src << ftp(file("/file/[createddirectory]/filename.txt"))
>

Browse() can be used with full HTML support, and you can create it right within your method. So, this:

> var/HTML={"
> <style>
> body{
> background: black;
> }
> table, td, th{
> spacing: 0;
> border: 1px solid white;
> border-collapse: collapse;
> color: white;
> font-size: 15 px;
> }
> td,th{
> padding:10px;
> }
> </style>
> <center>
> <table>
> <tr>
> <th>Table name!</th>
> </tr>
> <tr>
> <td>Table value!</td>
> </tr>
> </table>
> </body>
> </center>
> </html>"}

> src<<browse(HTML)
>


Browse isnt exactly what im looking for, im trying to make something so you would have the tables headers then below it automatically fills in the space per upload made creating a new tr output, i seen a who that kinda used this, it used created a new tr column for each player in the game
You could add chunks of HTML using a loop, then output all of it to the user.

var/HTML={"
<style>
body{
background: black;
}
table, td, th{
spacing: 0;
border: 1px solid white;
border-collapse: collapse;
color: white;
font-size: 15 px;
}
td,th{
padding:10px;
}
</style>
<center>
<table>
<tr>
<th>Table name!</th>
</tr>"}

var/list/directories=flist("/file/[createddirectory]/")
for(var/i in directories)
HTML+={"<tr>
<td>
[i]</td>
</tr>"}

src<<browse(HTML+"</table></body></center></html>")
Best response
Do not generate the tables on the fly by creating HTML on the server-side.

Instead, pass them a pre-included html file with all the required CSS, HTML, and Javascript to run this.

The example HTML file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>

<STYLE type="text/css">

//YOUR STYLESHEET GOES HERE.

</STYLE>

</HEAD>
<BODY>
<DIV id="root">
</DIV>
</BODY>
</HTML>

<SCRIPT type="text/javascript">

var rootNode = null;
var tableRows = new Array();

function loadPage()
{
rootNode = document.getElementByID("root");
}

window.onload = loadPage;

function addTableRows(rownames)
{
rownames = rownames.split("&");
for(var name in rownames)
{
addTableRow(name);
}
}

function addTableRow(text)
{
var row = document.createElement("div");
row.className = "RowDiv";
row.appendChild(document.createTextNode(text));
tableRows.push(row);
rootNode.appendChild(row);
}

function clearTable()
{
for(var row in tableRows)
{
rootNode.removeChild(row);
}
}
</SCRIPT>


Save this file as an html file in your project directory.

Now, you can browse it to the user whenever you need to:

mob << browse('herpyderp.html',"window=somebrowser;")


You can then invoke javascript from the server to the client via the output function:

mob << output("This is a table","somebrowser:addTableRow")


Now, there's a trick to converting a list into the proper format. BYOND has a function called escapeText, which will get the values returned by paramslist properly escaped, so you can pass a list of values as a single argument, rather than having to split them up argument by argument.

url_encode(list2params(l),1)


Using javascript is pretty useful, and a lot better than building HTML documents on the fly. You'll find that you use less CPU on the server, and get a much more responsive game out of the deal.