<?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 type="one-column" title="${%Configuration as Code}" permissions="${app.MANAGE_AND_SYSTEM_READ}">
  <l:main-panel>
    <st:adjunct includes="io.jenkins.plugins.casc.assets.index"/>
    <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" checkDependsOn="newSource"/>
          </f:entry>
          <f:block>
            <f:submit name="replace" value="${%Apply new configuration}"/>
          </f:block>
      </f:form>
    </l:isAdmin>
    <h2>${%Actions}</h2>

    <l:hasAdministerOrManage>
      <f:form method="post" action="reload" name="reload">
        <f:submit name="reload" value="${%Reload existing configuration}"/>
      </f:form>
    </l:hasAdministerOrManage>
    <l:hasPermission permission="${app.SYSTEM_READ}">
      <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">
        <l:icon class="icon-warning icon-sm"/>
        ${%exportWarning}
      </div>

      <h2>${%Reference}</h2>
      <dt>
        <dl><a href="reference">${%Documentation}</a></dl>
        <dl><a href="schema">${%JSON schema}</a></dl>
      </dt>
    </l:hasPermission>
  </l:main-panel>
  </l:layout>
</j:jelly>
