<!--
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->

<div class="clearfix">
  <ol class="breadcrumb pull-left">
    <li><a href="#/stackVersions">Versions</a></li>
    <li class="active" ng-if="editController">{{displayName}}&nbsp;<span class="sub-text">({{repoVersionFullName}})</span></li>
    <li class="active" ng-if="createController">Register Version</li>
  </ol>

  <div class="pull-right top-margin-4" ng-switch="deleteEnabled"  ng-if="editController">
    <button ng-switch-when="false" class="btn disabled btn-default" tooltip="Cannot delete version already installed.">Deregister
      Version
    </button>
    <button ng-switch-when="true" class="btn btn-danger" ng-click="delete()">Deregister Version
    </button>
  </div>
</div>
<hr>
<form class="form-horizontal register-version-form" role="form" name="repoRegForm" novalidate>
  <div class="panel panel-default" ng-if="createController">
    <div class="panel-heading">
      <h3 class="panel-title">Details</h3>
    </div>
    <div class="panel-body">
      <div class="form-inline repo-version-inline">
        <label class="control-label col-sm-2 repo-version-label">Name</label>
        <div class="col-sm-10">
          <select class="form-control repo-version-select"
                  ng-model="$parent.upgradeStack.selected"
                  ng-options="o as o.displayName for o in upgradeStack.options"
                  ng-change="afterStackVersionChange()">
          </select>
          <span class="bold-dot">.</span>
          <div class="form-group" ng-class="{'has-error' : repoRegForm.version.$error.pattern}">
            <input class="form-control" name="version" type="text" ng-model="$parent.repoSubversion" ng-pattern="subversionPattern"
                   placeholder="Version Name" ng-change="updateCurrentVersionInput()" required/>
            <span class="text-danger" ng-show="repoRegForm.version.$error.pattern">
              &nbsp{{currentVersionInput}} Invalid.
            </span>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h3 class="panel-title">Repositories</h3>
    </div>
    <div class="panel-body ">
      <div class="alert alert-info" role="alert">
        Provide Base URLs for the Operating Systems you are configuring. Uncheck all other Operating Systems.
      </div>
      <div class="alert alert-warning hide-soft" ng-class="{'visible' : hasValidationErrors()}" role="alert">
        Some of the repositories failed validation. Make changes to the base url or skip validation if you are sure that urls are correct
      </div>
      <div class="border-bottom bottom-margin clearfix">
        <div class="col-sm-2"><h5><label>OS</label></h5></div>
        <div class="name-label-adjust col-sm-2"><h5><label>Name</label></h5></div>
        <div class="col-sm-7"><h5><label>Base URL</label></h5></div>
      </div>
      <div class="clearfix border-bottom bottom-margin" ng-repeat="os in osList">
        <div class="col-sm-2">
          <div class="checkbox">
            <label>
              <input type="checkbox" ng-model="os.selected" ng-change="toggleOSSelect()"> {{os.OperatingSystems.os_type}}
            </label>
          </div>
        </div>
        <div class="col-sm-10">
          <div class="form-group" ng-class="{'has-error': repository.hasError }" ng-repeat="repository in os.repositories">
            <div class="col-sm-3"><label class="control-label">{{repository.Repositories.repo_name}}</label></div>
            <div class="col-sm-9"><input type="text" class="form-control" ng-model="repository.Repositories.base_url"
                                         ng-change="clearError()" ng-disabled="!os.selected"></div>
          </div>
        </div>
      </div>
      <div class="clearfix">
        <div class="col-sm-12">
          <div class="checkbox">
            <label>
              <input type="checkbox" ng-model="skipValidation" ng-change="clearErrors()">
              Skip Repository Base URL validation (Advanced) <span class="glyphicon glyphicon-question-sign" tooltip-html-unsafe="<b>Warning:</b> This is for advanced users only. Use this option if you want to skip validation for Repository Base URLs."></span>
            </label>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="col-sm-12">
    <button class="btn btn-primary pull-right left-margin" ng-click="save()"
            ng-disabled="(createController && repoRegForm.version.$invalid) || selectedOS === 0">Save</button>
    <button class="btn btn-default pull-right" ng-click="cancel()">Cancel</button>
  </div>
</form>
