function createEditCard(prevResults, opt_status) {
  if (prevResults) {
    var prefills = objToArray(prevResults, FIELDNAMES.slice(0, FIELDNAMES.length - 1));
  }
  var card = CardService.newCardBuilder();
  card.setHeader(CardService.newCardHeader().setTitle('Edit Your Expense'));

  var clearEditForm = CardService.newAction()
    .setFunctionName('clearEditForm')
    .setParameters({'Status': opt_status ? opt_status : ''});
  var clearAction = CardService.newCardAction()
    .setText('Clear form')
    .setOnClickAction(clearEditForm);
  card.addCardAction(clearAction);

  if (opt_status) {
    if (opt_status.indexOf('Error: ') == 0) {
      opt_status = '<font color=\'#FF0000\'>' + opt_status + '</font>';
    } else {
      opt_status = '<font color=\'#228B22\'>' + opt_status + '</font>';
    }
    var statusSection = CardService.newCardSection();
    statusSection.addWidget(CardService.newTextParagraph()
      .setText('<b>' + opt_status + '</b>'));
    card.addSection(statusSection);
  }

  var id = (parseInt(PropertiesService.getUserProperties().getProperty('EXPENSE_ID')) - 1)
    .toString();
  var idLabel = CardService.newTextParagraph().setText('Expense ID #' + id);
  var baseSection = CardService.newCardSection().addWidget(idLabel);
  var formSection = createFormSection(baseSection,
                                      FIELDNAMES.slice(0, FIELDNAMES.length - 1), prefills);
  var editForm = CardService.newAction().setFunctionName('editForm');
  var editButton = CardService.newTextButton()
    .setText('Edit')
    .setOnClickAction(editForm);
  formSection.addWidget(CardService.newButtonSet().addButton(editButton));

  var url = PropertiesService.getUserProperties().getProperty('SPREADSHEET_URL');
  var openSpreadsheetButton = CardService.newTextButton()
    .setText('Open Spreadsheet')
    .setOpenLink(CardService.newOpenLink().setUrl(url));
  var openSpreadsheetSection = CardService.newCardSection()
    .addWidget(CardService.newButtonSet().addButton(openSpreadsheetButton));

  card.addSection(formSection);
  card.addSection(openSpreadsheetSection);

  return card;
}
/**
 * Creates a card letting users edit the most recent expense.
 * Form can be prefilled with values.
 *
 * @param {String[]} prevResults Default values for each input field.
 * @param {String} opt_status Optional status displayed at top of card.
 * @returns {Card}
 */
Creates a card letting users edit the most recent expense.
Form can be prefilled with values.

@param {String[]} prevResults Default values for each input field.
@param {String} opt_status Optional status displayed at top of card.
@returns {Card}
Creates a card letting users edit the most recent expense . Form can be prefilled with values . @param { String [] } prevResults Default values for each input field . @param { String } opt_status Optional status displayed at top of card . @returns { Card }
function createEditCard(prevResults, opt_status) {
  if (prevResults) {
    var prefills = objToArray(prevResults, FIELDNAMES.slice(0, FIELDNAMES.length - 1));
  }
  var card = CardService.newCardBuilder();
  card.setHeader(CardService.newCardHeader().setTitle('Edit Your Expense'));
  var clearEditForm = CardService.newAction()
    .setFunctionName('clearEditForm')
    .setParameters({'Status': opt_status ? opt_status : ''});
  var clearAction = CardService.newCardAction()
    .setText('Clear form')
    .setOnClickAction(clearEditForm);
  card.addCardAction(clearAction);
  if (opt_status) {
    if (opt_status.indexOf('Error: ') == 0) {
      opt_status = '<font color=\'#FF0000\'>' + opt_status + '</font>';
    } else {
      opt_status = '<font color=\'#228B22\'>' + opt_status + '</font>';
    }
    var statusSection = CardService.newCardSection();
    statusSection.addWidget(CardService.newTextParagraph()
      .setText('<b>' + opt_status + '</b>'));
    card.addSection(statusSection);
  }
  var id = (parseInt(PropertiesService.getUserProperties().getProperty('EXPENSE_ID')) - 1)
    .toString();
  var idLabel = CardService.newTextParagraph().setText('Expense ID #' + id);
  var baseSection = CardService.newCardSection().addWidget(idLabel);
  var formSection = createFormSection(baseSection,
                                      FIELDNAMES.slice(0, FIELDNAMES.length - 1), prefills);
  var editForm = CardService.newAction().setFunctionName('editForm');
  var editButton = CardService.newTextButton()
    .setText('Edit')
    .setOnClickAction(editForm);
  formSection.addWidget(CardService.newButtonSet().addButton(editButton));
  var url = PropertiesService.getUserProperties().getProperty('SPREADSHEET_URL');
  var openSpreadsheetButton = CardService.newTextButton()
    .setText('Open Spreadsheet')
    .setOpenLink(CardService.newOpenLink().setUrl(url));
  var openSpreadsheetSection = CardService.newCardSection()
    .addWidget(CardService.newButtonSet().addButton(openSpreadsheetButton));
  card.addSection(formSection);
  card.addSection(openSpreadsheetSection);
  return card;
}
function createEditCard ( prevResults , opt_status ) { if ( prevResults ) { var prefills = objToArray ( prevResults , FIELDNAMES . slice ( 0 , FIELDNAMES . length - 1 ) ) ; } var card = CardService . newCardBuilder ( ) ; card . setHeader ( CardService . newCardHeader ( ) . setTitle ( 'Edit Your Expense' ) ) ; var clearEditForm = CardService . newAction ( ) . setFunctionName ( 'clearEditForm' ) . setParameters ( { 'Status' : opt_status ? opt_status : '' } ) ; var clearAction = CardService . newCardAction ( ) . setText ( 'Clear form' ) . setOnClickAction ( clearEditForm ) ; card . addCardAction ( clearAction ) ; if ( opt_status ) { if ( opt_status . indexOf ( 'Error: ' ) == 0 ) { opt_status = '<font color=\'#FF0000\'>' + opt_status + '</font>' ; } else { opt_status = '<font color=\'#228B22\'>' + opt_status + '</font>' ; } var statusSection = CardService . newCardSection ( ) ; statusSection . addWidget ( CardService . newTextParagraph ( ) . setText ( '<b>' + opt_status + '</b>' ) ) ; card . addSection ( statusSection ) ; } var id = ( parseInt ( PropertiesService . getUserProperties ( ) . getProperty ( 'EXPENSE_ID' ) ) - 1 ) . toString ( ) ; var idLabel = CardService . newTextParagraph ( ) . setText ( 'Expense ID #' + id ) ; var baseSection = CardService . newCardSection ( ) . addWidget ( idLabel ) ; var formSection = createFormSection ( baseSection , FIELDNAMES . slice ( 0 , FIELDNAMES . length - 1 ) , prefills ) ; var editForm = CardService . newAction ( ) . setFunctionName ( 'editForm' ) ; var editButton = CardService . newTextButton ( ) . setText ( 'Edit' ) . setOnClickAction ( editForm ) ; formSection . addWidget ( CardService . newButtonSet ( ) . addButton ( editButton ) ) ; var url = PropertiesService . getUserProperties ( ) . getProperty ( 'SPREADSHEET_URL' ) ; var openSpreadsheetButton = CardService . newTextButton ( ) . setText ( 'Open Spreadsheet' ) . setOpenLink ( CardService . newOpenLink ( ) . setUrl ( url ) ) ; var openSpreadsheetSection = CardService . newCardSection ( ) . addWidget ( CardService . newButtonSet ( ) . addButton ( openSpreadsheetButton ) ) ; card . addSection ( formSection ) ; card . addSection ( openSpreadsheetSection ) ; return card ; }
Creates a card letting users edit the most recent expense.
Creates a card letting users edit the most recent expense .