rejetto forum

Rewriting a file table built client-side

raybob · 6 · 2565

0 Members and 1 Guest are viewing this topic.

Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
So, I had this really cool idea.  I have a plan to rewrite a least the %list% part of HFS into a javscript object that is built client-side.

This would take a while to write but the benefits are that it would make it orders of magnitude easier to create a more interactive webpage, with better ajax functions and easier jquery.  Basically rather than HFS building all the HTML, it would simply insert the data for each file into this javascript object below, and then it would be built clientside.  To change something on the page would only require setting the new value in the JS object (since all the data is already in the javascript space) and then just running a function to rebuild everything.  It would also potentially save some build-time server side.

Here's a very simple draft of how it could work.

Code: [Select]

<html><body onload="content.build();" ><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<style type="text/css"> td { padding:8px; } </style>

<script type="text/javascript">

/* There is the main containing object, inside there are two arrays, one for folders, one for files,
each part of each array contains one object per file with the specific properties within that object.
So it's one big object containing 2 arrays each containing x number of objects each with properties.
Also inside the big main object is the function 'build' that puts everything together on the page. */

content = {

    folders: [{
        "name": "documents",
        "size": 27928338,
        "hits": 27,
        "modified": "6/13/2012 10:41:35 PM"
    }, {
        "name": "music",
        "size": 48929338,
        "hits": 52,
        "modified": "6/13/2012 10:41:35 PM"
    }],

    files: [{
        "name": "file.mp3",
        "size": 10384171,
        "hits": 2,
        "modified": "6/13/2012 10:41:35 PM"
    }, {
        "name": "fun.docx",
        "size": 502858,
        "hits": 5,
        "modified": "6/13/2012 10:41:35 PM"
    }, {
        "name": "anotherfile.pdf",
        "size": 2411725,
        "hits": 5,
        "modified": "6/13/2012 10:41:35 PM"
    }],

    build: function () {

        for (var n = 0; n < content.folders.length; n++) {

            var name = content.folders[n].name;
            var size = content.folders[n].size;
            var hits = content.folders[n].hits;
            var modified = content.folders[n].modified;

            var thehtml = '<tr><td>Folder</td><td>' + name + '</td><td>' + size + '</td><td>' + hits + '</td><td>' + modified + '</td></tr>';

            $('#filetable').append(thehtml);

        }

        for (var n = 0; n < content.files.length; n++) {

            var name = content.files[n].name;
            var size = content.files[n].size;
            var hits = content.files[n].hits;
            var modified = content.files[n].modified;

            var thehtml = '<tr><td>File</td><td>' + name + '</td><td>' + size + '</td><td>' + hits + '</td><td>' + modified + '</td></tr>';

            $('#filetable').append(thehtml);

        }
    }
}

</script>

<table id="filetable"></table>

</body></html>


Let me know what you think.


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
yes, it's possible.
HFS 3 does it, but more hardcore: it never reloads the page, it just asks the server for the listings. The page is loaded only at first access.

are having fun with javascript?
consider helping with hfs3 ;)


Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
yes, it's possible.
HFS 3 does it, but more hardcore: it never reloads the page, it just asks the server for the listings. The page is loaded only at first access.

are having fun with javascript?
consider helping with hfs3 ;)


Lol yes Javascript is fun as I learn more :D  I didn't even understand how to use an array until like two days ago.

I suppose I could help with hfs3.... maybe I could help write the template once you decide how it will function.

Unforunately I don't think this JS-based idea will make it into my next version of FHFS.  (By the way FHFS 1.x works very badly overall, wait until you see 2.0!)


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
there are many things that need to be done for HFS 3.
Some don't even need programming skills.


Offline raybob

  • Tireless poster
  • ****
    • Posts: 454
    • View Profile
    • FileSplat.com
Well let me know what needs to be done, and if I can do it, I'll do it.  :)


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile