User Tools

Site Tools


sample_code:folder_picker

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
sample_code:folder_picker [2014/11/26 12:25]
stevegarman created
sample_code:folder_picker [2015/02/19 23:17] (current)
Line 4: Line 4:
 See also [[sample_code:file_picker|Sample File Picker]] See also [[sample_code:file_picker|Sample File Picker]]
 ===== The code ===== ===== The code =====
- 
 <code javascript folderpicker.js> <code javascript folderpicker.js>
  
Line 19: Line 18:
     //Add layout to app.         //Add layout to app.    
     app.AddLayout( lay );     app.AddLayout( lay );
 +    pick = new FolderPicker(mycallback);
 +    // don't show hidden files
 +    pick.SetHideFiles(true);
 }//function Onstart() }//function Onstart()
  
  
 function btn_OnTouch(){ function btn_OnTouch(){
-    pick = new FolderPicker(mycallback); 
     pick.SetFolder("/sdcard");     pick.SetFolder("/sdcard");
     pick.Show();         pick.Show();    
Line 37: Line 38:
   this.callback = Callback || function(){};   this.callback = Callback || function(){};
   this.FolderPath = this.basePath;   this.FolderPath = this.basePath;
 +  this.hideHiddenFiles = false;
   this.dlg = app.CreateDialog(this.basePath);   this.dlg = app.CreateDialog(this.basePath);
   this.lay = app.CreateLayout( "linear", "horizontal,fillxy" );   this.lay = app.CreateLayout( "linear", "horizontal,fillxy" );
Line 61: Line 63:
   this.Show = function(){   this.Show = function(){
     self.dlg.Show();     self.dlg.Show();
 +  }
 +  this.SetHideFiles=function(val){
 +    if(val == undefined) val = true;
 +    self.hideHiddenFiles = val;
   }   }
   this.Hide = function(){   this.Hide = function(){
Line 74: Line 80:
     var lst = app.ListFolder(folderPath);     var lst = app.ListFolder(folderPath);
     lst.sort(function(x,y){return (x.toLowerCase() > y.toLowerCase())?1:-1});     lst.sort(function(x,y){return (x.toLowerCase() > y.toLowerCase())?1:-1});
-    var dirlist=[]+    self.lstFolds.SetList("")
-    if( self.FolderPath != self.basePath ) dirlist = [".."]; +    if( self.FolderPath != self.basePath ) 
 +      self.lstFolds.AddItem("..",null,"folder");
     var ths = lst.shift();     var ths = lst.shift();
     while (undefined != ths) {     while (undefined != ths) {
-      var pth = folderPath + "/" + ths; +      if ((! self.hideHiddenFiles) || (ths.indexOf(".") != 0)){ 
-      if (app.IsFolder(pth))dirlist.push(ths);+        var pth = folderPath + "/" + ths; 
 +        if (app.IsFolder(pth)) 
 +           self.lstFolds.AddItem(ths,null,"folder") 
 +      }
       ths = lst.shift();       ths = lst.shift();
     }     }
          
-    self.lstFolds.SetList(dirlist.join(",")); 
     app.HideProgress();     app.HideProgress();
   }     }  
sample_code/folder_picker.1417004744.txt.gz · Last modified: 2014/11/26 20:25 (external edit)