Good morning guys,I followed this tutorial: https://developers.google.com/apps-script/guides/dialogs#file-open_dialogs and I can open a Google Picker after clicking a button inside my addon sidebar.I want to do 2 things for better UX for my users:- The first thing is when the Google Picker is open, I want to show a loading indicator inside my addon sidebar (to prevent users from interacting with the sidebar), so that users can only interact with the Google Picker until it's closed- Immediately after users choose a document or directly close the Google Picker, the loading indicator in the addon sidebar will be disappeared, and users can interact with the addon sidebar normallyFrom the backend developers point of view, I think there must be some kinds of "socket" or "event" so that these 2 things can talk to each other.But because the addon sidebar and the Google Picker dialog are 2 separated html files, I can't figure out how. So how can I do that?Thanks.
function getOAuthToken() {
//Start spinner here
google.script.run.withSuccessHandler(createPicker)
.withFailureHandler(showError).getOAuthToken();
}
createPicker
In the function named
createPicker
you must stop the spinner.
There are probably many different systems for a spinner. I have my own system, which has an empty DIV with a class name. The code needs to find that DIV element, and change the class name, which causes the CSS to start an animation.
function createPicker(token) {
try{
//Stop the spinner here
if (!token) {
throw new Error('No token for picker');
}
//Build the picker
}catch(e){
myFuncForClientSideErrorHandling(e);
}
}
Thank you for your solution. But maybe my question is not clear.What I want to achieve is:1. When the Google Picker is open, there is a loading indicator inside the addon sidebar (not inside the picker dialog)2. When user closes the dialog or select a document (both make the dialog disappears), then the loading indicator inside the addon side is also disappeared.Because the function createPicker you said above is inside the html file of the picker dialog, so it can't control the sidebar html? Am I correct?
There are probably many different systems for a spinner. I have my own system, which has an empty DIV with a class name. The code needs to find that DIV element, and change the class name, which causes the CSS to start an animation.
function openPicker() {
// Show spinner here
// For example, showSpinner()
google.script.run
.withSuccessHandler(function() { console.log('ok') })
.showPicker()
}
function showPicker() {
var html = HtmlService.createHtmlOutputFromFile('picker.html')
.setWidth(800)
.setHeight(600)
FormApp.getUi().showModalDialog(html, 'Select a file')
}
function pickerCallback(data) {
var action = data[google.picker.Response.ACTION]
if (action === google.picker.Action.PICKED) {
var doc = data[google.picker.Response.DOCUMENTS][0]
var id = doc[google.picker.Document.ID]
var url = doc[google.picker.Document.URL]
var title = doc[google.picker.Document.NAME]
document.getElementById('result').innerHTML =
'<b>You chose:</b><br>Name: <a href="' + url + '">' + title + '</a><br>ID: ' + id
} else if (action === google.picker.Action.CANCEL) {
google.script.host.close()
}
// This is a good place to hide the spinner,
// but this is picker.html, so it can not control code in sidebar.html to hide the spinner
}
hideSpinner()
pickerCallback runs
window.thePickerIsOpen = false;//Set to false
Your setInterval code checks window.thePickerIsOpen