SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2004
    Location
    MidWest, USA
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Prototype and Help

    I'm working on file management system, but its code taken from on older script called relay. I've modified the code heavily for view and use, but have one more requirement that I just can't figure out. I'm new to prototype and do better with small projects.

    Heres the situation:

    The site lists folders, and then within those folders, it continues to list files. The files show name, date, and ability to download or delete. I need to add in the file size argument which is stored in a database.


    We are using a create class and then CreateFile: function ()...

    The code used to load the date information, which works is:

    Code:
    this.date = document.createElement('span');
    this.date.innerHTML = this.fileDate;
    Element.addClassName(this.date, 'date');
    But I can't figure out how to load the size information. I've got it listed showing undefined at this point. I guess I was just interested in finding out how I might go about loading the database file size information into this system.

    Also, if this is to vague, but you think you can help, please let me know and I can also compensate for it.
    Web Consultant: Web Design, Development, Optimization.

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,345
    Mentioned
    192 Post(s)
    Tagged
    5 Thread(s)
    This snippet does not show enough to deduce what is currently contained in "this".
    Can you post a little more?
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Member
    Join Date
    Aug 2004
    Location
    MidWest, USA
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the main.js file (just part):

    Code:
    var File = Class.create();
    File.prototype = {
    
            initialize: function (id, name, flag, parentElement, date, size) {
                    this.type = 'file';
                    this.fileDate = date;
                    this.fileSize = size;
                    this.name = name;
                    this.id = id;
                    this.flag = flag;
                    this.selected = false;
                    this.timer = null;
                    this.interval = 1000;
                    this.parentElement = parentElement;
                    this.parentObject = parentElement.object;
                    this.readonly = this.parentObject.readonly;
                    this.parentElement.id == 'searchresults' ? this.search = true : this.search = false;
                    this.createFile();
            },
    
            createFile: function () {
                    this.element = document.createElement('div');
                    this.span =    document.createElement('span');
                    this.link =    document.createElement('a');
                    this.icon = document.createElement('img');
                    this.handle = document.createElement('div');
                    Element.addClassName(this.handle, 'handle');
    
                    this.flag != 'normal' ? this.icon.src = "images/"+this.flag+".png" : this.icon.src= fileIcon;
                    Element.addClassName(this.icon, 'icon');
                    this.link.title = "DOUBLE CLICK TO DOWNLOAD";
                    this.link.innerHTML = this.name;
                    Element.addClassName(this.link, this.flag);
                    Element.addClassName(this.link, 'link');
    
                    this.date = document.createElement('span');
                    this.date.innerHTML = this.fileDate;
                    Element.addClassName(this.date, 'date');
    
                    this.size = document.createElement('span');
                    this.size.innerHTML = "";
                    Element.addClassName(this.size, 'size');
    
                    this.dl = document.createElement('a');
                    this.dl.href = "javascript:download()";
                    this.dl.style.display = "none";
                    this.dl.title = "Want to download "+this.name+"? Click HERE";
                    this.dl.innerHTML = ""; // download this file
                    Element.addClassName(this.dl, 'add');
    
                    this.del = document.createElement('a');
                    this.del.href = "javascript:go()"
                    this.del.style.display = "none";
                    this.del.title = "Delete "+this.name;
                    this.del.innerHTML = "delete";
                    Element.addClassName(this.del, 'del');
    
                    this.span.onmousedown = this.select.bind(this);
                    this.link.onmousedown = this.select.bindAsEventListener(this);
                    this.icon.onmousedown = this.select.bind(this);
                    this.link.ondblclick = this.download.bindAsEventListener(this);
                    this.icon.ondblclick = this.download.bindAsEventListener(this);
                    this.dl.onclick = this.addDl.bind(this);
                    this.del.onclick = this.unlink.bind(this);
    
                    this.handle.appendChild(this.icon);
                    this.handle.appendChild(this.link);
                    this.span.appendChild(this.handle);
                    this.span.appendChild(this.date);
                    this.span.appendChild(this.size); // sie added by jason
                    if(!this.readonly) {
                            this.span.appendChild(this.del);
                    }
                    this.span.appendChild(this.dl);
                    this.element.appendChild(this.span);
    
                    this.search ? this.element.id = 'sid'+this.id : this.element.id = 'fid'+this.id;
                    this.element.object = this;
    
                    Element.addClassName(this.element, 'file');
                    this.parentElement.appendChild(this.element);
                    //!this.readonly ? new Draggable(this.element.id, {revert:true, handle:'handle'}) : null;
    
            },
    There is a lot more code in the js file. Also there is a php file with code that is called:

    Code:
            if(getUserAuth('view',$path)){
                    logAction('list',$path);
                    $fullpath = getUserPath($path).$path;
    
                    databaseSync($fullpath,$path);
    
                    if (is_dir($fullpath)) {
                            if ($dh = opendir($fullpath)) {
                               while (($file = readdir($dh)) !== false) {
                                 #echo "$file";
                                 if($file != '.' && $file != '..' && filetype($fullpath . '/' . $file) == 'dir'){
                                   jsonAdd("\"type\": \"directory\", \"name\": \"$file\", \"path\": \"$path/$file\"");
                                         }
                               }
                               closedir($dh);
                            }
                    }else{
                          error("directory doesnt exist $fullpath");
                    }
                    $query = "select *,date_format(`date`,\"$dateFormat\") as `dateformatted` from $GLOBALS[tablePrefix]filesystem where path=\"$fullpath\" and status=\"found\" order by `date` desc";
                    $result = mysql_query($query,$database);
                    while($files = mysql_fetch_assoc($result)) {
                            jsonAdd("\"type\": \"file\", \"name\": \"$files[filename]\",\"date\":\"$files[dateformatted]\", \"id\": \"$files[id]\",\"flags\": \"$files[flags]\"");
                    }
                    $output .= jsonReturn('getFolder');
    If this is to little, I'm willing to compensate someone to help resolve this issue (and a couple more).
    Web Consultant: Web Design, Development, Optimization.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •