inst/hbcdtlfb/www/R/observe/edit_routine_modal.R

showModal(
  if(length(input$table_substance_routine_rows_selected) == 1) {
    
    # edit_routine_modal.R and edit_routine_confirmed.R should match
    id_to_edit <- table_substance_routine_data()[input$table_substance_routine_rows_selected, ] |> 
      pull(Id)
    
    # Existing values
    edited_row <- table_substance_routine_data() |> filter(Id == id_to_edit)
    days <- edited_row$Days
    substance <- edited_row$Substance
    frequency <- edited_row$Frequency
    
    if(input$all_substances) {
      choices <- substances |> 
        prepare_choices(name_short_html, name_short_html, group)
    }
    if(! input$all_substances) {
      choices <- substances_names_grouped()
    }
    
    modalDialog(
      title = "Edit Record",
      
      virtualSelectInput(
        "edit_routine_days", 
        "Days of the Week:",
        choices = days_of_the_week,
        selected = stringr::str_split(days, ", ")[[1]],
        multiple = TRUE
      ),
      
      virtualSelectInput(
        "edit_routine_substance", 
        "Substance:",
        choices = choices, 
        selected = substance,
        disableOptionGroupCheckbox = TRUE,
        optionsCount = 8,
        html = TRUE
      ),
      
      virtualSelectInput(
        "edit_routine_frequency", 
        "Frequency:",
        choices = 1:100,
        selected = frequency
      ),
      
      footer = tagList(
        modalButton("Cancel"),
        actionButton("edit_routine_confirmed", "Confirm")
      ), 
      easyClose = TRUE)
  } else
  {
    modalDialog(
      title = "Warning",
      "Select a row that you want to edit", 
      easyClose = TRUE
    )
  }
)
ucsd-dsm/hbcd-tlfb documentation built on July 10, 2022, 5:46 p.m.