显示PopupPanel

时间:2013-10-10 17:17:52

标签: google-apps-script popuppanel

三个问题:

  1. 为什么我的popupPanel无法正确显示?
  2. 如果多次点击,我怎么才能让它出现一次?
  3. 如何向popupPanel添加“关闭”按钮?

  4. function showPassword(e){
      var app = UiApp.getActiveApplication();
      var vrtPanel = app.getElementById("vrtPanel");
      //Create Spreadsheet Source
    
      var spSheet = SpreadsheetApp.openById('0Aur3owCpuUY-dF92dGp3c2RORGNkY011dGFnMjBXbXc');
      var spTeacherList = spSheet.getSheetByName('TeacherList');
    
      //Create the form elements
      var hdlTeacherName = app.createServerHandler('getTeacherName').addCallbackElement(vrtPanel);
      var lbxTeacherName = app.createListBox().setId('lbxTeacherName').setName('lbxTeacherName').addChangeHandler(hdlTeacherName);
      var lstTeacherNames = spTeacherList.getRange(1,1,spTeacherList.getLastRow(),1).getValues();
      lstTeacherNames.sort();
    
      for (var l = 0; l < lstTeacherNames.length; l++) {
        lbxTeacherName.addItem(lstTeacherNames[l],l);
      }
    
      var lblTeacherName = app.createLabel('Teacher Name:');
      var txtTeacherName = app.createTextBox().setName('txtTeacherName').setId('txtTeacherName').setVisible(false);
    
      var lblExt = app.createLabel('Ext:');
      var txtExt = app.createTextBox().setName('txtExt').setId('txtExt');
    
      var lblEmail = app.createLabel('Email:');
      var txtEmail = app.createTextBox().setName('txtEmail').setId('txtEmail');
    
      var lblSchool = app.createLabel('School:');
      var txtSchool = app.createTextBox().setName('txtSchool').setId('txtSchool');
    
      var btnCreate = app.createButton('Create Event');
    
      //Create validation handler
      var valSubmit = app.createServerClickHandler('valSubmit');
      valSubmit.addCallbackElement(vrtPanel);
    
      //Add this handler to the button
      btnCreate.addClickHandler(valSubmit);
    
      //Add all the elemnts to the panel
      var formTable = app.createFlexTable().setCellPadding(3);
      vrtPanel.add(formTable);
      formTable
      .setWidget(0,0,lbxTeacherName)
      .setWidget(0,1,txtExt)
      .setWidget(0,2,txtTeacherName)
      .setWidget(1,0,txtEmail)
      .setWidget(2,0,btnCreate);
    
      //Add all the panel to the popup
      var popPassword = app.createDecoratedPopupPanel(false, true).setId("popPassword");
      popPassword.add(vrtPanel);
    
      app.add(vrtPanel);
      app.add(popPassword);
      return app;
    }
    

1 个答案:

答案 0 :(得分:0)

使用popupPanel的方式存在一些混乱,您必须将其添加到主面板并将要显示的表添加到弹出窗口中。 您还应该决定要显示它的位置。 以下是您的代码的相关部分:

  //Add all the elemnts to the panel
  var formTable = app.createFlexTable().setCellPadding(3);
  formTable
  .setWidget(0,0,lbxTeacherName)
  .setWidget(0,1,txtExt)
  .setWidget(0,2,txtTeacherName)
  .setWidget(1,0,txtEmail)
  .setWidget(2,0,btnCreate);

  var popPassword = app.createDecoratedPopupPanel(false, true).setPopupPosition(150,300).setId("popPassword");

  vrtPanel.add(popPassword.add(formTable));

  popPassword.show();
  return app;
} 

回答第二点:il不会出现多次,只有一次。

第3点:如果你想用一个按钮关闭它,你将不得不添加一个按钮和一个服务器处理程序来关闭它(通过使用ID获取它就像任何其他小部件一样)但它会更容易和用户友好利用自动隐藏功能,只需更改定义参数,如下所示:

  var popPassword = app.createDecoratedPopupPanel(true).setPopupPosition(150,300).setId("popPassword");

上例中的

编辑也可以使用

app.getElementById('popPassword').hide() 

在你的'valSubmit'函数中(由按钮调用),即使没有自动隐藏,弹出窗口也会在处理函数执行时隐藏。