source: trunk/web/addons/job_monarch/lib/extjs/air/src/FileTreeLoader.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 2.5 KB
Line 
1/*
2 * Ext JS Library 0.30
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9Ext.tree.LocalTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
10    requestData : function(node, callback){
11        if(this.fireEvent("beforeload", this, node, callback) !== false){
12            var p = Ext.urlDecode(this.getParams(node));
13            var response = this.dataFn(node);
14            this.processResponse(response, node, callback);
15            this.fireEvent("load", this, node, response);                       
16        }else{
17            // if the load is cancelled, make sure we notify
18            // the node that we are done
19            if(typeof callback == "function"){
20                callback();
21            }
22        }
23    }, 
24    processResponse : function(o, node, callback){
25        try {
26            node.beginUpdate();
27            for(var i = 0, len = o.length; i < len; i++){
28                var n = this.createNode(o[i]);
29                if(n){
30                    node.appendChild(n);
31                }
32            }
33            node.endUpdate();
34            if(typeof callback == "function"){
35                callback(this, node);
36            }
37        }catch(e){
38            this.handleFailure(response);
39        }
40    },
41    load : function(node, callback){
42        if(this.clearOnLoad){
43            while(node.firstChild){
44                node.removeChild(node.firstChild);
45            }
46        }
47        if(this.doPreload(node)){ // preloaded json children
48            if(typeof callback == "function"){
49                callback();
50            }
51        }else if(this.dataFn||this.fn){
52            this.requestData(node, callback);
53        }
54    }           
55});
56
57/**
58 * @cfg {air.File} directory
59 * Initial directory to load the FileTree from
60 */
61Ext.air.FileTreeLoader = Ext.extend(Ext.tree.LocalTreeLoader, {
62    extensionFilter: false,
63    dataFn: function(currNode) {
64        var currDir;
65        if (currNode.attributes.url) {
66                currDir = this.directory.resolvePath(currNode.attributes.url);
67        } else {
68                currDir = this.directory;
69        }
70        var files = []; 
71        var c = currDir.getDirectoryListing();
72        for (i = 0; i < c.length; i++) {
73            if (c[i].isDirectory || this.extensionFilter === false || this.extensionFilter === c[i].extension)
74            files.push({
75                text: c[i].name,
76                url: c[i].url,
77                extension: c[i].extension,
78                leaf: !c[i].isDirectory
79            });
80        }
81        return files;                   
82    }
83});
Note: See TracBrowser for help on using the repository browser.