go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/server/portal/internal/assets/pages/page.html (about)

     1  {{define "title"}}Admin - {{.Title}}{{end}}
     2  
     3  {{define "style"}}
     4  <style>
     5  .action-div {
     6    border-radius: 10px;
     7    border: 1px solid #e0e0e0;
     8    padding: 10px;
     9  }
    10  .action-div p {
    11    margin: 10px;
    12  }
    13  </style>
    14  {{end}}
    15  
    16  {{define "content"}}
    17  <div class="row">
    18  <div class="col-md-offset-2 col-md-8">
    19  
    20  <h2>{{.Title}}</h2>
    21  <hr>
    22  
    23  <form class="form-horizontal" method="POST">
    24    {{.XsrfTokenField}}
    25  
    26    {{if .Overview}}
    27    <div class="form-group">
    28      <div class="col-sm-9">{{.Overview}}</div>
    29    </div>
    30    <hr>
    31    {{end}}
    32  
    33    {{range $field := .Fields}}
    34    <div class="form-group">
    35      <label for="{{$field.ID}}" class="col-sm-3 control-label">{{$field.Title}}</label>
    36      <div class="col-sm-9">
    37        {{if or (eq $field.Type "text") (eq $field.Type "password")}}
    38          <input
    39            type="{{$field.Type}}" class="form-control" aria-describedby="help-{{$field.ID}}"
    40            {{if $field.Placeholder}}
    41            placeholder="{{$field.Placeholder}}"
    42            {{end}}
    43            name="{{$field.ID}}" value="{{$field.Value}}"
    44            {{if $field.ReadOnly}}readonly{{end}}>
    45        {{else if eq .Type "choice"}}
    46          <select class="form-control" aria-describedby="help-{{$field.ID}}"
    47            name="{{$field.ID}}" value="{{$field.Value}}" {{if $field.ReadOnly}}disabled{{end}}>
    48            {{range $choice := $field.ChoiceVariants}}
    49              <option
    50                {{if eq $field.Value $choice}}selected{{end}}
    51                {{if $field.ReadOnly}}disabled{{end}}>
    52                {{$choice}}
    53              </option>
    54            {{end}}
    55          </select>
    56        {{else if eq $field.Type "static"}}
    57          <p class="form-control-static">{{$field.Value}}</p>
    58        {{end}}
    59        {{if $field.Help}}
    60          <span id="help-{{$field.ID}}" class="help-block">{{$field.Help}}</span>
    61        {{end}}
    62      </div>
    63    </div>
    64    {{end}}
    65  
    66    {{if and .Actions .Fields}}
    67    <hr>
    68    {{end}}
    69  
    70    {{range $action := .Actions}}
    71    <div class="form-group">
    72      <div class="col-sm-12 action-div">
    73        {{if $action.Help}}
    74        <p>{{$action.Help}}</p>
    75        {{end}}
    76        <button
    77          type="button"
    78          {{if $action.Confirmation}}
    79          class="btn btn-danger btn-block action-button"
    80          {{else}}
    81          class="btn btn-default btn-block action-button"
    82          {{end}}
    83          data-action-no-side-effects="{{$action.NoSideEffects}}"
    84          data-action-id="{{$action.ID}}"
    85          data-confirmation="{{$action.Confirmation}}">{{$action.Title}}</button>
    86      </div>
    87    </div>
    88    {{end}}
    89  
    90    <hr>
    91    <div class="form-group">
    92      {{if and .Fields .ShowSaveButton}}
    93      <div class="col-sm-2">
    94        <button type="submit" class="btn btn-primary">Save settings</button>
    95      </div>
    96      {{end}}
    97      <div class="col-sm-2">
    98        <a href="/admin/portal" class="btn btn-default">Back</a>
    99      </div>
   100    </div>
   101  </form>
   102  
   103  </div>
   104  </div>
   105  
   106  {{if .Actions}}
   107  <form id="form-action" method="POST" style="display:none">
   108    {{.XsrfTokenField}}
   109  </form>
   110  
   111  <script>
   112  window.onload = function () {
   113    'use strict';
   114  
   115    let actionLaunched = false;
   116  
   117    function launchAction(actionID, noSideEffects) {
   118      if (actionLaunched) {
   119        return
   120      }
   121      actionLaunched = true;
   122  
   123      const actionRef = './{{.ID}}/' + actionID;
   124      if (noSideEffects) {
   125        // Just go to the action page directly, no need to involve forms.
   126        window.location.href = actionRef;
   127      } else {
   128        // Navigate through a POST form with the XSRF token.
   129        const form = document.getElementById('form-action');
   130        form.setAttribute('action', actionRef);
   131        form.submit();
   132      }
   133    }
   134  
   135    for (const btn of document.getElementsByClassName('action-button')) {
   136      btn.onclick = function() {
   137        const actionID = this.getAttribute('data-action-id');
   138        const confirmation = this.getAttribute('data-confirmation');
   139        const noSideEffects = this.getAttribute('data-action-no-side-effects') == 'true';
   140        if (confirmation) {
   141          const dialog = Modal.confirm('Are you sure?', {content: confirmation});
   142          dialog.show().once('dismiss', (modal, ev, button) => {
   143            if (button && button.value) {
   144              launchAction(actionID, noSideEffects);
   145            }
   146          });
   147        } else {
   148          launchAction(actionID, noSideEffects);
   149        }
   150      }
   151    }
   152  };
   153  </script>
   154  {{end}}
   155  
   156  {{end}}