I am trying to define where my file is to be saved to. I am starting out at the end user and moving inwards, so that means the start of the UI. I have the Label and the list
Here is a test code that seems to work. I didn't test it thoroughly but it seems to do what it has to do...
I left the textBox with ID visible to make it easier to debug but you should set it invisible in the final code.
There are probably a few improvements to add but it gives the general idea...
function doGet(){
var app = UiApp.createApplication();
var curFN = app.createTextBox().setText('MyDrive/').setName('curFN').setId('curFN').setWidth('400');
var curFID = app.createTextBox().setText('x').setName('curFID').setId('curFID').setWidth('400');
var list = app.createListBox().setName('list').setId('list').addItem('please select a folder','x');
var grid = app.createGrid(3,2).setText(0,0,'Choose a folder in your drive').setWidget(0,1,curFN).setWidget(2,1,curFID).setWidget(1,1,list);
var folders = DocsList.getRootFolder().getFolders();
for (var i = 0; i < folders.length; i++) {
list.addItem(folders[i].getName(),folders[i].getId())
}
var handler = app.createServerHandler('folderSelect').addCallbackElement(grid);
list.addChangeHandler(handler);
app.add(grid);
return app;
}
function folderSelect(e){
var app = UiApp.getActiveApplication();
var currentFN = e.parameter.curFN;
var currentFID = e.parameter.list;
Logger.log(currentFID);
var list = app.getElementById('list');
var curFN = app.getElementById('curFN');
var curFID = app.getElementById('curFID');
if(currentFID=='x'){currentFID=DocsList.getRootFolder().getId() ; curFN.setText('MyDrive/')};
var startFolder = DocsList.getFolderById(currentFID);
var folders = startFolder.getFolders();
list.clear().addItem('no other subFolder','x').addItem('Go back to Root','x');
if(folders.length>0){list.clear(); list.addItem('please select a subFolder','x')};
for (var i = 0; i < folders.length; i++) {
list.addItem(folders[i].getName(),folders[i].getId())
}
curFN.setText(currentFN+DocsList.getFolderById(currentFID).getName()+'/');
if(currentFID==DocsList.getRootFolder().getId()){curFN.setText('MyDrive/')};
curFID.setText(currentFID);
return app;
}
App online here, needs authorization for Docslist Service