DocsListDialog
Deprecated. The UI service was
deprecated on December 11, 2014. To create user interfaces, use the
HTML service instead.
A "file-open" dialog for Google Drive. Unlike most UiApp
objects, DocsListDialog
should not be added to the UiInstance
. The
example below shows how to display a DocsListDialog
in the
new version of Google Sheets.
Note that HTML service offers a similar but superior
feature, Google Picker. In almost all
cases, using Google Picker is preferable.
function onOpen() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.createMenu('Custom Menu')
.addItem('Select file', 'showDialog')
.addToUi();
}
function showDialog() {
// Dummy call to DriveApp to ensure the OAuth dialog requests Google Drive scope, so that the
// getOAuthToken() call below returns a token with the necessary permissions.
DriveApp.getRootFolder();
var app = UiApp.createApplication()
.setWidth(570)
.setHeight(352);
var serverHandler = app.createServerHandler('pickerHandler');
app.createDocsListDialog()
.addCloseHandler(serverHandler)
.addSelectionHandler(serverHandler)
.setOAuthToken(ScriptApp.getOAuthToken())
.showDocsPicker();
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog(app,' ');
}
function pickerHandler(e) {
var action = e.parameter.eventType;
var app = UiApp.getActiveApplication();
if (action == 'selection') {
var doc = e.parameter.items[0];
var id = doc.id;
var name = doc.name;
var url = doc.url;
app.add(app.createLabel('You picked '));
app.add(app.createAnchor(name, url));
app.add(app.createLabel('(ID: ' + id + ').'));
} else if (action == 'close') {
app.add(app.createLabel('You clicked "Cancel".'));
}
return app;
}
Deprecated methods
addCloseHandler(handler)
Deprecated. This function is deprecated and should not be used in new scripts.
Add a handler for close events.
Note that you can have multiple handlers for the same event on the same widget. They will be
called in the order that they were added to the widget, although
ServerHandler
s may
appear to happen simultaneously.
The handler passes back some information to the server about what happened. This information
can be accessed as follows:
function doGet() {
var app = UiApp.createApplication();
var item1 = app.createTreeItem("item1");
item1.addItem(app.createTreeItem("item2"));
var tree = app.createTree();
tree.addItem(item1);
var handler = app.createServerHandler("handlerFunction");
tree.addCloseHandler(handler)
app.add(tree);
return app;
}
function handlerFunction(eventInfo) {
var parameter = eventInfo.parameter;
// the type of event, in this case "close".
var eventType = parameter.eventType;
// the id of the widget that fired this event.
var source = parameter.source;
}
In addition, the values of certain widgets can be sent up with the event as well as "callback
elements." See the documentation of
ServerHandler
for more information.
Parameters
Return
DocsListDialog
— the DocsListDialog
itself, useful for chaining.
addSelectionHandler(handler)
Deprecated. This function is deprecated and should not be used in new scripts.
Add a handler for selection events.
Note that you can have multiple handlers for the same event on the same widget. They will be
called in the order that they were added to the widget, although
ServerHandler
s may
appear to happen simultaneously.
The handler passes back some information to the server about what happened. This information
can be accessed as follows:
function doGet() {
var app = UiApp.createApplication();
var item1 = app.createTreeItem("item1");
item1.addItem(app.createTreeItem("item2"));
var tree = app.createTree();
tree.addItem(item1);
var handler = app.createServerHandler("handlerFunction");
tree.addSelectionHandler(handler)
app.add(tree);
return app;
}
function handlerFunction(eventInfo) {
var parameter = eventInfo.parameter;
// the type of event, in this case "selection".
var eventType = parameter.eventType;
// the id of the widget that fired this event.
var source = parameter.source;
}
In addition, the values of certain widgets can be sent up with the event as well as "callback
elements." See the documentation of
ServerHandler
for more information.
Parameters
Return
DocsListDialog
— the DocsListDialog
itself, useful for chaining.
addView(fileType)
Deprecated. This function is deprecated and should not be used in new scripts.
Add a type of file that this DocsListDialog
will show.
Parameters
Name | Type | Description |
fileType | FileType
| the type of file to add. |
Return
DocsListDialog
— the DocsListDialog
itself, useful for chaining.
getId()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the id that has been assigned to this object.
This can be used in conjunction with app.getElementById() to retrieve a reference to this
object.
Return
String
— the id that has been assigned to this object
getType()
Deprecated. This function is deprecated and should not be used in new scripts.
Gets the type of this object.
Return
String
— the object type
setDialogTitle(title)
Deprecated. This function is deprecated and should not be used in new scripts.
Set the title of this DocsListDialog
.
Parameters
Name | Type | Description |
title | String | the new title. |
Return
DocsListDialog
— the DocsListDialog
itself, useful for chaining.
setHeight(height)
Deprecated. This function is deprecated and should not be used in new scripts.
Set the height of this DocsListDialog
.
Parameters
Name | Type | Description |
height | Integer | the new height, in pixels. |
Return
DocsListDialog
— the DocsListDialog
itself, useful for chaining.
setInitialView(fileType)
Deprecated. This function is deprecated and should not be used in new scripts.
Set the initial type of file that this DocsListDialog
will show.
Parameters
Name | Type | Description |
fileType | FileType
| the type of file to show. |
Return
DocsListDialog
— the DocsListDialog
itself, useful for chaining.
setMultiSelectEnabled(multiSelectEnabled)
Deprecated. This function is deprecated and should not be used in new scripts.
Set whether multiple items can be selected.
Parameters
Name | Type | Description |
multiSelectEnabled | Boolean | whether multiple items can be selected. |
Return
DocsListDialog
— the DocsListDialog
itself, useful for chaining.
setOAuthToken(oAuthToken)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets an OAuth token to use when fetching data for the dialog. This token must be on behalf
of the user whose content should be shown.
It is mandatory to call this method before calling showDocsPicker()
.
If the script is running as the same user, this method can be used in combination with
ScriptApp.getOAuthToken()
.
If you need to obtain an OAuth token manually, see
ScriptApp.newStateToken()
.
The scopes for the token should include the scopes specified in the
Picker Reference Documentation
.
If the only scope needed is for Google Drive, using
DriveApp
anywhere in the script
will automatically set up the correct scope.
Parameters
Name | Type | Description |
oAuthToken | String | the OAuth token. |
Return
DocsListDialog
— the DocsListDialog
itself, useful for chaining.
setWidth(width)
Deprecated. This function is deprecated and should not be used in new scripts.
Set the width of this DocsListDialog
.
Parameters
Name | Type | Description |
width | Integer | the new width, in pixels. |
Return
DocsListDialog
— the DocsListDialog
itself, useful for chaining.