0

我的代码如下。它将接受来自输入文本的数据;然后它将从谷歌电子表格中的stackoverflow(基于输入)获取最新的提要。

我已经(想要)设置一个外部 gif 图像以在获取 rss 提要及其处理过程中显示为进度指示器。

问题是:当我删除评论部分时;该 gif 图像将永远不会对用户可见,并且当它保留为评论时;该 gif 图像在该过程完成后由应用程序加载,然后在.

我希望它仅在进程(获取 rss 和处理它)正在进行时才可见。那么有没有办法让它成为可能呢?

function stackoverflow(){   
    var app =UiApp.createApplication().setHeight(380).setWidth(800);   
    app.setTitle("Enter tag name");
    var mydoc=SpreadsheetApp.getActiveSpreadsheet();    
    var txtBox = app.createTextBox().setFocus(true).setWidth("150").setId("ticker").setName("ticker");
    var mainpanel = app.createHorizontalPanel().setId('mainpanel');
    mainpanel.add(txtBox);
    var subbtn = app.createButton("Get posts!").setId("tick").setWidth("80");
    mainpanel.add(subbtn);
    var myloadingimg=app.createImage("http://schedule.msu.edu/img/InProgress.gif").setHeight("26").setWidth("26").setId("loadingimg");
    mainpanel.add(myloadingimg.setVisible(false));
    app.add(mainpanel);
    var panel = app.createVerticalPanel().setId('panel');    
    var submitHandler = app.createServerHandler("clicker").addCallbackElement(mainpanel);
    subbtn.addClickHandler(submitHandler);
    app.add(panel);
    mydoc.show(app);
}
function clicker(e){
   var app = UiApp.getActiveApplication();
   var txtBox = app.getElementById("ticker");
   app.getElementById("loadingimg").setVisible(true);
   var panel=app.getElementById("panel");
   app.remove(1);
   var panel = app.createVerticalPanel().setId('panel');    
   var stackurl = "http://stackoverflow.com/feeds/tag?tagnames="+e.parameter.ticker+"&sort=newest";
   var stackXML = UrlFetchApp.fetch(stackurl).getContentText();
   var stackDOC = Xml.parse(stackXML, false);
   var stackentry = stackDOC.getElement().getElements('entry');

   for (var i = 0; i < stackentry.length; i++) {    
       var result = stackentry[i];
       panel.add(app.createHTML("<br><b>Post Title: </b>"+ result.getElement('title').getText()+"<br>"));
       panel.add(app.createAnchor('', '') .setText("Post URL").setHref(result.getElement('link').getAttribute('href').getValue()));       
       panel.add(app.createHTML("<br>"));
      }

   var scroll = app.createScrollPanel().setPixelSize(760, 280);
   scroll.add(panel);
   app.add(scroll);
   //app.getElementById("loadingimg").setVisible(false);
   return app;
}

function onOpen() 
{  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [];
  menuEntries.push({name:'stackoverflow',functionName:'stackoverflow'});
  ss.addMenu("f2", menuEntries);
}
4

1 回答 1

2

您可以使用专门针对此类情况的 clientHandlers。

function stackoverflow(){   
    ...   
    var clientHandler = app.createClientHandler().forTargets(myloadingimg).setVisible(true); 
    var submitHandler = app.createServerHandler("clicker").addCallbackElement(mainpanel);
    subbtn.addClickHandler(submitHandler).addClickHandler(clientHandler); 
    ...
}
function clicker(e){
   var app = UiApp.getActiveApplication();
   ....
   app.getElementById("loadingimg").setVisible(false);
   return app;
}
于 2013-05-05T06:30:05.753 回答