<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:st="jelly:stapler">
  <l:layout norefresh="true" type="one-column" title="${%Configuration as Code}">
  <l:main-panel>
  <st:adjunct includes="io.jenkins.plugins.casc.assets.index"/>

  <div class="container-fluid">
  <div class="row">
  <div class="col-md-24">
    <h1>${%Configuration as Code}</h1>

    <j:choose>
      <j:when test="${empty it.sources}">
        <p>${%Controller has no configuration as code file set.}</p>
      </j:when>
      <j:otherwise>
        ${%Configuration loaded from :}
        <ul>
          <j:forEach var="source" items="${it.sources}">
            <li>${source}</li>
          </j:forEach>
        </ul>

        <p>${%Last time applied :} <i:formatDate value="${it.lastTimeLoaded}" type="both" dateStyle="medium" timeStyle="long"/></p>

      </j:otherwise>
    </j:choose>

    <l:isAdmin>
      <f:form method="post" action="replace" name="replace">
          <h2>${%Replace configuration source with:}</h2>
          <f:entry title="${%Path or URL}" field="newSource" >
              <f:textbox checkUrl="'checkNewSource?newSource='+escape(this.value)" checkMethod="post" />
          </f:entry>
          <f:block>
            <f:submit name="replace" value="${%Apply new configuration}"/>
          </f:block>
      </f:form>
    </l:isAdmin>
    <h2>${%Actions}</h2>

    <l:isAdmin>
      <f:form method="post" action="reload" name="reload">
        <f:submit name="reload" value="${%Reload existing configuration}"/>
      </f:form>
    </l:isAdmin>
    <f:form method="post" action="export" name="export">
      <f:submit name="export" value="${%Download Configuration}"/>
    </f:form>
    <f:form method="post" action="viewExport" name="viewExport">
      <f:submit name="viewExport" value="${%View Configuration}"/>
    </f:form>
    <div class="alert alert-warning clear-action-forms">
      <img src="${rootURL}/images/16x16/warning.png"/>
      ${%exportWarning}
    </div>

    <h2>${%Reference}</h2>
    <dt>
      <dl><a href="reference">${%Documentation}</a></dl>
      <dl><a href="schema">${%JSON schema}</a></dl>
    </dt>

  </div>
  </div>
  </div>
  </l:main-panel>
  </l:layout>

</j:jelly>
