【发布时间】:2014-03-20 19:43:40
【问题描述】:
我想在我的脚本处理过程中以某种方式让用户处于忙碌状态。我似乎无法让它工作。事情只有在搜索完成后才会发生。这是一个网络应用脚本。
我有一个特定的搜索(仅限使用 GDrive 搜索子文件夹),在处理过程中,我想反馈一下。这需要相当长的时间,所以我也可以加快速度,但除此之外,我希望有一个忙碌的代码,提示,更改按钮标签 - 任何东西。此脚本位于我们应用程序域的 GSite 页面中。
我这样定义入口和按钮:
// set text boxes for second column
grid.setWidget(1, 1, app.createTextBox().setId("search")
.setName("search").setWidth(500));
// create button and handler
grid.setWidget(1, 2, app.createButton("Search")
.addClickHandler(app.createServerHandler("findFiles").addCallbackElement(grid))
.setId('button'));
...
var msg = app.createLabel().setId('msg');
app.add(msg);
用户界面如下所示:
然后我这样处理:
//
// [ initiate the find process ]
//
function findFiles(e) {
var app = UiApp.getActiveApplication();
var msg = app.getElementById('msg');
//----> doesn't appear until search is complete?!
showMsg("...searching, please wait...");
//
// NOTE: This is hardcoded to look in folders that
// have "! Portal !" in their name ONLY
//
var folders = DriveApp.searchFolders('title contains "! Portal !"');
while (folders.hasNext()) {
var folder = folders.next();
showItems(folder, e.parameter.search);
}
if(!g_found) {
msg.setText("Sorry, nothing found. Refresh this page to try again");
} else {
msg.setText("Search is complete. Click file names to open documents.");
}
return app;
}
function showMsg(text) {
var app = UiApp.getActiveApplication();
app.getElementById('msg').setText(text);
return app;
}
//
// [ nested search ]
//
function showItems(folder, search) {
var app = UiApp.getActiveApplication();
var files = folder.searchFiles('fullText contains "' + search + '"');
while(files.hasNext()) {
g_found = true;
var file = files.next();
var link = app.createAnchor(file.getName(), file.getUrl()); // ...URL of file found
app.add(link);
var lf = app.createHTML(''); // ...add a break between URLs found
app.add(lf);
}
var subFldrs = folder.getFolders();
while (subFldrs.hasNext()) {
var fldr = subFldrs.next();
showItems(fldr, search); // ...recursive searching
}
return app;
}
我已经尝试过获取按钮 ID 和更改其文本等。没有任何效果。 我错过了什么?
【问题讨论】:
标签: google-apps-script google-drive-api google-sites