Reputation: 1770
I have a custom sidebar and I want to call a custom dialog. Is there a way of notifying the sidebar when the user closes the dialog?
From the sidebar I call a method in the code.gs file using google.script.run
google.script.run
.withSuccessHandler(editDone)
.withFailureHandler(errorHandler)
.showTemplatedDialog();
showTemplatedDialog is a function in code.gs which displays the dialog:
function showDialog() {
var htmlTemplate = HtmlService.createTemplateFromFile(dialogName);
htmlTemplate.dataFromServerTemplate = dialogData;
var html = htmlTemplate.evaluate()
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(width)
.setHeight(height);
var ui = SpreadsheetApp.getUi();
ui.showModalDialog(html, title);
}
}
The problem is that the withSuccessHandler function is called when the dialog is displayed, not when the user closes the dialog and there doesn't seem to be any way for the sidebar to be notified of the choice that the user made.
Is there a way for a dialog to communicate back to the sidebar?
Upvotes: 1
Views: 209
Reputation: 1770
Thanks to Sandy for the tip, I did use sessionStorage, but I used an event handler instead of polling.
In my sidebar I added:
$(window).on("storage", function(e) {
if (e.originalEvent.storageArea === sessionStorage) {
var message = sessionStorage.getItem('message');
$('#sample').html(message);
}
});
Then in my dialog, before closing, I write to the sessionStorage:
$('#btnClose').on("click", function() {
sessionStorage.setItem('message', 'This is the story' + new Date());
google.script.host.close();
});
Upvotes: 3