Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.0k views
in Technique[技术] by (71.8m points)

Update Google Calendar UI after changing visability setting via Workspace Add-On

I have a very basic Google Workspace Add-on that uses the CalendarApp class to toggle the visabilty of a calendar when a button is pressed, using the setSelected() method

The visabilty toggling works, but the change in only reflected in the UI when the page is refreshed. Toggling the checkbox manually in the UI reflects the change immediately without needing to refresh the page.

Is there a method to replicate this immediate update behaviour via my Workspace Add-On?

A mwe is below.

function onDefaultHomePageOpen() {

  // create button
  var action = CardService.newAction().setFunctionName('toggleCalVis')
  var button = CardService.newTextButton()
    .setText("TOGGLE CAL VIS")
    .setOnClickAction(action)
    .setTextButtonStyle(CardService.TextButtonStyle.FILLED)
  var buttonSet = CardService.newButtonSet().addButton(button)

  // create CardSection
  var section = CardService.newCardSection()
    .addWidget(buttonSet)

  // create card
  var card = CardService.newCardBuilder().addSection(section)

  // call CardBuilder.call() and return card
  return card.build()

}

function toggleCalVis() {
  // fetch calendar with UI name "foo"
  var calendarName = "foo"
  var calendarsByName = CalendarApp.getCalendarsByName(calendarName)
  var namedCalendar = calendarsByName[0]

  // Toggle calendar visabilty in the UI
  if (namedCalendar.isSelected()) {
    namedCalendar.setSelected(false)
  }
  else {
    namedCalendar.setSelected(true)
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...