Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

google apps script - How can I create a progress spinner using HtmlService?

In scriptUi I was able to follow these instructions to create a simple progress spinner for long waits: https://sites.google.com/site/scriptsexamples/learn-by-example/uiapp-examples-code-snippets/progress-indicators

I am now using HtmlService to create the Ui and I don't see how I can set up the spinner as I did before.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

I found a method. The trick was to call an internal function that both starts the spinner and runs the other function.

html

<script>
  function onSuccess() {
    var div = document.getElementById('result');
    div.innerHTML = '<div>Sucess!</div>';
  }

    function onFailure() {
    var div = document.getElementById('result');
    div.innerHTML = '<div>Fail!</div>';
  }
  function clickAction(){
    var div = document.getElementById('result');
    div.innerHTML = '<div> Copying...<br><img src="https://c4a54d10381f750e81dcc323aed21e2c95725815.googledrive.com/host/0Bwyqwd2fAHMMallsNkNOV0RfcTg/wait_progress.gif"></div>';
  google.script.run
  .withSuccessHandler(onSuccess)
  .withFailureHandler(onFailure)
  .testSpinner();
  }

</script>

<button class="action" onclick="clickAction()"> Copy</button>
<button onclick="google.script.host.close()"> Close</button>
<div id='result'></div>

gs file

function testSpinner(){
 SpreadsheetApp.getActiveSpreadsheet().toast("Copying...","",-1);
  Utilities.sleep(5000);
 SpreadsheetApp.getActiveSpreadsheet().toast("Done.");
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...