<!--

    Copyright (C) 2015-2016 Jeeva Kandasamy (jkandasa@gmail.com)

    Licensed 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="container-fluid"> <!-- Container-fluid -->

  <!-- Loading icon disaplay -->
  <div ng-if="!types.$resolved">
    <div ng-include src="'partials/common-html/loading.html'"></div>
  </div>

  <div ng-if="types.$resolved"> <!-- Main Message -->

    <!-- Page Header -->
    <div ng-include src="'partials/common-html/header-add-update.html'"></div>

    <div>
      <form class="form-horizontal" name="mcForm">
        <div class="col-md-5">

          <div class="form-group">
            <label class="col-sm-2 control-label">{{ 'NAME' | translate }}</label>
            <div class="col-sm-10">
              <input class="form-control" ng-model="item.name" placeholder="{{ 'NAME' | translate }}" required />
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">{{ 'ENABLED' | translate }}</label>
            <div class="col-sm-10">
             <input type="checkbox" ng-model="item.enabled" checked>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">{{ 'TYPE' | translate }}</label>
            <div class="col-sm-5">
              <select class="form-control" pf-select ng-change="updateTypeChange()"
                ng-options="type.id as type.displayName for type in types  | orderBy:'displayName'" ng-model="item.type" required >
                <option value="" ng-hide="true"></option>
              </select>
            </div>
          </div>

          <!-- Emoncms.org Server -->
          <div ng-if="item.type === 'Emoncms.org'">
            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'URL' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'URL' | translate }}" ng-model="item.url" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">{{ 'TRUST_HOST' | translate }}</label>
            <div class="col-sm-5">
              <select class="form-control" pf-select ng-options="type.id as type.displayName for type in trustHostTypes  | orderBy:'displayName'" ng-model="item.trustHostType" required >
                <option value="" ng-hide="true"></option>
              </select>
            </div>
          </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'WRITE_API_KEY' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'WRITE_API_KEY' | translate }}" ng-model="item.writeApiKey" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'KEY_FORMAT' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'KEY_FORMAT' | translate }}" ng-model="item.keyFormat" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

          </div>

          <!-- Sparkfun [phant.io] server -->
          <div ng-if="item.type === 'Sparkfun [phant.io]'">
            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'URL' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'URL' | translate }}" ng-model="item.url" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">{{ 'TRUST_HOST' | translate }}</label>
            <div class="col-sm-5">
              <select class="form-control" pf-select ng-options="type.id as type.displayName for type in trustHostTypes  | orderBy:'displayName'" ng-model="item.trustHostType" required >
                <option value="" ng-hide="true"></option>
              </select>
            </div>
          </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'PUBLIC_KEY' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'PUBLIC_KEY' | translate }}" ng-model="item.publicKey" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'PRIVATE_KEY' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'PRIVATE_KEY' | translate }}" ng-model="item.privateKey" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'KEY_FORMAT' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'KEY_FORMAT' | translate }}" ng-model="item.keyFormat" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

          </div>

          <!-- Influxdb server -->
          <div ng-if="item.type === 'Influxdb'">
            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'URL' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'URL' | translate }}" ng-model="item.url" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">{{ 'TRUST_HOST' | translate }}</label>
            <div class="col-sm-5">
              <select class="form-control" pf-select ng-options="type.id as type.displayName for type in trustHostTypes  | orderBy:'displayName'" ng-model="item.trustHostType" required >
                <option value="" ng-hide="true"></option>
              </select>
            </div>
          </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'USERNAME' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'USERNAME' | translate }}" ng-model="item.username" pf-validation="cs.isContainsSpace(input)" />
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'PASSWORD' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'PASSWORD' | translate }}" ng-model="item.password" pf-validation="cs.isContainsSpace(input)" ng-required="item.username"/>
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'DATABASE' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'DATABASE' | translate }}" ng-model="item.database" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'MEASUREMENT' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'KEY_FORMAT' | translate }}" ng-model="item.keyFormat" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'TAGS' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'TAGS' | translate }}" ng-model="item.tags" pf-validation="cs.isContainsSpace(input)" />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

          </div>

          <!-- MQTT client server -->
          <div ng-if="item.type === 'MQTT'">
            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'BROKET_HOST' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'MQTT_BROKER_HOST_EXAMPLE' | translate }}" ng-model="item.url" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">{{ 'TRUST_HOST' | translate }}</label>
            <div class="col-sm-5">
              <select class="form-control" pf-select ng-options="type.id as type.displayName for type in trustHostTypes  | orderBy:'displayName'" ng-model="item.trustHostType" required >
                <option value="" ng-hide="true"></option>
              </select>
            </div>
          </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'USERNAME' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'USERNAME' | translate }}" ng-model="item.username" pf-validation="cs.isContainsSpace(input)" />
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'PASSWORD' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'PASSWORD' | translate }}" ng-model="item.password" pf-validation="cs.isContainsSpace(input)" ng-required="item.username"/>
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'TOPIC_PUBLISH' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'KEY_FORMAT' | translate }}" ng-model="item.keyFormat" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

          </div>

          <!-- WUnderground Server -->
          <div ng-if="item.type === 'WUnderground'">
            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'URL' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'URL' | translate }}" ng-model="item.url" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">{{ 'TRUST_HOST' | translate }}</label>
            <div class="col-sm-5">
              <select class="form-control" pf-select ng-options="type.id as type.displayName for type in trustHostTypes  | orderBy:'displayName'" ng-model="item.trustHostType" required >
                <option value="" ng-hide="true"></option>
              </select>
            </div>
          </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'STATION_ID' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'STATION_ID' | translate }}" ng-model="item.stationId" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'STATION_PASSWORD' | translate }}</label>
              <div class="col-sm-10">
                <input class="form-control" placeholder="{{ 'STATION_PASSWORD' | translate }}" ng-model="item.stationPassword" pf-validation="cs.isContainsSpace(input)" required />
                <span class="help-block">{{ 'VALIDATION_ERROR_NO_SPACE_ALLOWED' | translate }}</span>
              </div>
            </div>

          </div>

          <div ng-if="item.type !== 'WUnderground'">
            <div class="form-group">
              <label class="col-sm-2 control-label">{{ 'ALPHABETICAL_KEY_CASE' | translate }}</label>
              <div class="col-sm-5">
              <select class="form-control" pf-select ng-model="item.keyCase" required >
                <option value="" ng-hide="true"></option>
                <option value="DEFAULT">{{ 'DEFAULT' | translate }}</option>
                <option value="UPPER">{{ 'UPPER' | translate }}</option>
                <option value="LOWER">{{ 'LOWER' | translate }}</option>
              </select>
            </div>
            </div>
          </div>

          <!-- Include save form buttons -->
          <div ng-include src="'partials/common-html/save-form.html'"></div>

        </div>
      </form>
    </div>

  </div> <!-- Main Message -->
</div> <!-- container -->
