根据用户的回答显示弹出式UI

时间:2012-08-06 22:56:49

标签: google-apps-script

我目前有一个带下拉问题的用户界面。当用户在下拉列表中选择某个答案时,我想显示另一个允许用户回答更多问题的UI。然后,我想关闭此窗口并将用户返回到第一个UI并继续回答问题。

我试过popuppanel,将一个Ui的隐形设置为false,但似乎没有任何效果。

注意:由于我的第一个UI中的数据是动态的,因此我无法使用GUI构建器,因此请仅使用代码提供解决方案。

这些是我到目前为止的代码:

// when user select this drop down option, show another UI
case 'Move to a special meeting':
  displayActionItemsUI();
  cellStatus.offset(numOfRowsOffset,0).setValue(N);
  cellMeetingType.offset(numOfRowsOffset,0).setValue('Special Meeting');
  break;


function displayActionItemsUI() {

  var app = UiApp.getActiveApplication();

  var panelActionItems = app.createVerticalPanel();

  var gridActionItems = app.createGrid(3, 2).setId('gridActionItems')
      .setCellPadding(15);

  var lblTaskStatement = app.createLabel('Task Statement:');
  var lblOwner = app.createLabel('Owner:');
  var lblDeadline = app.createLabel('Deadline:');

  var tboxTask = app.createTextBox().setId('tboxTask').setName('tboxTask');
  var tboxOwner = app.createTextBox().setId('tboxOwner').setName('tboxOwner');
  var dboxDeadline = app.createDateBox()
      .setFormat(UiApp.DateTimeFormat.DATE_SHORT)
      .setId('dboxDeadline').setName('dboxDeadline');

  gridActionItems.setWidget(0, 0, lblTaskStatement);
  gridActionItems.setWidget(0, 1, tboxTask);

  gridActionItems.setWidget(1, 0, lblOwner);
  gridActionItems.setWidget(1, 1, tboxOwner);

  gridActionItems.setWidget(2, 0, lblDeadline);
  gridActionItems.setWidget(2, 1, dboxDeadline);

  var btnAdd = app.createButton('Add');

  var lblTest = app.createLabel().setId('lblTest').setVisible(false);

  panelActionItems.add(gridActionItems)
    .add(btnAdd).add(lblTest);

  app.add(panelActionItems);

  addHandler = app.createServerHandler('_responseToAdd')
    .addCallbackElement(panelActionItems);

  btnAdd.addClickHandler(addHandler);

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  ss.show(app);
}


// add response to a separate tab and close the UI
function _responseToAdd(e) {

  // store user's inputs;
  var actionItems = [];

  var actionObject = new Object();

  var taskStatement = e.parameter.tboxTask;
  var owner = e.parameter.tboxOwner;
  var deadline = e.parameter.dboxDeadline;

  actionObject['task'] = taskStatement;
  actionObject['owner'] = owner;
  actionObject['deadline'] = deadline;

  actionItems.push(actionObject);

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Action Items");

  var headers = ['task', 'owner', 'deadline'];

  var valuesR = ObjApp.objectToArray(headers, actionItems); //returns [[]]
  sheet.getRange(sheet.getLastRow()+1, 1, 1, valuesR[0].length).setValues([valuesR[0]]);

  var app = UiApp.getActiveApplication();

  var panelActionItems = app.getElementById('panelActionItems');
  panelActionItems.clear();

  return app;


}

1 个答案:

答案 0 :(得分:1)

我认为您可以使用this post answer中的多个面板来实现,您可以根据答案构建面板并更改其内容...