cross-posted on the Google Sites forum
http://www.google.com/support/forum/p/sites/thread?tid=7ddd5033742337d7&hl=en&fid=7ddd5033742337d70004a1a9fe4d5f87
It was suggested that I cross-post here, I'm hoping someone if familiar enough with the API, or has some sort of other ideas!
I'm attempting to generate a list of site pages into a UiApp Listbox. I'm able to generate a full list but this process is both too slow and returns too many items to be usable. I tried implementing a search box, but the .search() method of the Site object continues to return null values.
I hesitate to post my complete code, but in the spirit of completeness:
function doGet(e) {
var app = UiApp.createApplication();
//gotta retrieve the site name from a script property, cause the SitesApp API is buggy
var siteName = ScriptProperties.getProperty('Site name');
var sites = SitesApp.getSites();
var listBox = app.createListBox().setName('selectedSite');
listBox.addItem(siteName ? siteName : '');
for(var i = 0; i < sites.length; i++)
listBox.addItem(sites[i].getName())
var lhandler = app.createServerClickHandler('onSelectedSite');
lhandler.addCallbackElement(listBox);
listBox.addChangeHandler(lhandler);
//search for pages
var searchit = app.createTextBox().setName("searchit").setText("search").setWidth("100px");
//where we will stick the page names being searched for
var pagelist = app.createListBox().setSize("200px","100%").setId("pagelist").setName("pagelist").setVisibleItemCount(8);
//search button
var sbutton = app.createButton("Search page listing").setId("sbutton");
var shandler = app.createServerClickHandler('searchpages');
shandler.addCallbackElement(searchit);
sbutton.addClickHandler(shandler);
var grid = app.createGrid(3, 2);
//convert button
var convertbutton = app.createButton("Convert HTML").setId("convertbutton");
var chandler = app.createServerClickHandler('convert');
chandler.addCallbackElement(grid);
convertbutton.addClickHandler(chandler);
grid.setWidget(0, 0, listBox);
grid.setWidget(0, 1, searchit);
grid.setWidget(1, 1, sbutton);
grid.setWidget(2, 0, pagelist);
//squish everything to the top
var squish = app.createAbsolutePanel().setHeight("100%");
app.add(grid);
app.add(squish);
return app;
}
//this isn't currently working
function searchpages(e) {
var app = UiApp.getActiveApplication();
var site = SitesApp.getSite(ScriptProperties.getProperty('Site name'));
var pagelist = app.getElementById('pagelist');
Logger.log('a');
//the .search method confuses and frightens me. Can't find any reference on the correct usage. Maybe I'm not building the query string correctly?
var pageresults = site.search(e.parameter.searchit);
Logger.log(pageresults.length);
var pathstring = '';
for (var i = 0; i < pageresults.length; i++) {
Logger.log(pageresults[i].getName());
var trackbackpage = pageresults[i];
while (trackbackpage.getParent() != 'NULL') {
Logger.log(pathstring);
pathstring = '/' + trackbackpage.getName() + pathstring;
trackbackpage = trackbackpage.getParent();
}
pagelist.addItem(pathstring).setName(pageresults[i]);
}
app.close();
return app;
}
function onSelectedSite(e)
{
var app = UiApp.getActiveApplication();
if(e.parameter.selectedSite != '')
ScriptProperties.setProperty('Site name', e.parameter.selectedSite);
return app;
}
The log reads like so:
a
null