{{!
  Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.

  WSO2 Inc. 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.
}}
{{#if controlOperations}}
    <div class="wr-operations" style="height: 87px; display: block;"
         xmlns="http://www.w3.org/1999/html">
        <style>
            ::-webkit-input-placeholder {
                color: #B8B8B8;
            }

            ::-moz-placeholder {
                color: #B8B8B8;
            }

            :-ms-input-placeholder {
                color: #B8B8B8;
            }

            input:-moz-placeholder {
                color: #B8B8B8;
            }
        </style>
        {{#each controlOperations}}
            <a {{#unless isDisabled}} href="javascript:operationSelect('{{operation}}')" {{else}} href="javascript:void(0)" class="op-disabled" title="{{disabledText}}" data-toggle="tooltip" {{/unless}}>
                {{#if iconFont}}
                    <i class="fw {{iconFont}}"></i>
                {{else}}
                    {{#if icon}}
                        <img src="{{@app.context}}/{{icon}}" style="width: 48px;"/>
                    {{else}}
                        <i class="fw fw-service"></i>
                    {{/if}}
                {{/if}}
                <span>{{name}}</span>
            </a>

            <div class="operation" data-operation-code="{{operation}}">
                <div class="content">

                    <div class="row">
                        <div class="col-lg-5 col-md-6 col-centered">
                            <h3>
                        <span class="fw-stack">
                            <i class="fw fw-circle-outline fw-stack-2x"></i>
                            <i class="fw {{iconFont}} fw-stack-1x"></i>
                        </span>
                                {{name}}
                                <br>
                            </h3>
                            <h4>
                                {{description}}
                                <br>
                            </h4>

                            <div id="operation-error-msg" class="alert alert-danger hidden" role="alert">
                                <i class="icon fw fw-error"></i><span></span>
                            </div>

                            <div id="operation-warn-msg" class="info alert-info hidden" role="alert">
                                <i class="icon fw fw-info"></i><span></span>
                            </div>

                            <div id="operation-form">
                                <form id="form-{{operation}}" action="{{params.0.uri}}" method="{{params.0.method}}"
                                      style="padding-bottom: 20px;"
                                      data-payload="{{payload}}"
                                      data-device-id="{{../device.deviceIdentifier}}"
                                      data-content-type="{{params.0.contentType}}"
                                      data-operation-code="{{operation}}">
                                    {{#each params.0.pathParams}}
                                        <input type="{{type}}" id="{{name}}" placeholder="{{name}}" class="form-control"
                                               data-param-type="path" value="{{value}}"/>
                                        <br/>
                                    {{/each}}
                                    {{#each params.0.formParams}}
                                        <input type="{{type}}" id="{{name}}" name="{{name}}" placeholder="{{name}}"
                                               class="form-control" data-param-type="form" value="{{value}}"/>
                                        <br/>
                                    {{/each}}
                                    {{#each params.0.queryParams}}
                                        <input type="{{type}}" id="{{name}}" placeholder="{{name}}" class="form-control"
                                               data-param-type="query" value="{{value}}"/>
                                        <br/>
                                    {{/each}}
                                    {{#each uiParams}}
                                        {{#equal this.type "select"}}
                                            <div class="form-group">
                                                <select class="form-control" id="{{this.id}}">
                                                    {{#each this.value}}
                                                        <option>{{this}}</option>
                                                    {{/each}}
                                                </select>
                                            </div>
                                        {{/equal}}
                                        {{#equal this.type "radio"}}
                                            <input type="radio" id="{{this.id}}"
                                                   name="{{this.name}}"
                                                   value="{{this.value}}"
                                                   class="radio"
                                                   checked="checked"
                                                   data-param-type="form"/>
                                            {{this.value}}
                                        {{/equal}}
                                        {{#equal this.type "checkbox"}}
                                            <input type="{{this.type}}" id="{{this.id}}"
                                                   class="checkbox"
                                                   placeholder="{{this.label}}"
                                                   data-param-type="form"
                                                   data-toggle="tooltip"
                                                   title="{{this.helper}}"/>
                                            {{this.label}}
                                            <br/>
                                        {{/equal}}
                                        {{#equal this.type "password"}}
                                            <input type="{{this.type}}" id="{{this.id}}"
                                                   placeholder="{{this.label}}" class="form-control"
                                                   data-param-type="form" value=""/>
                                            <br/>
                                        {{/equal}}
                                        {{#equal this.type "text"}}
                                            <input type="{{this.type}}" id="{{this.id}}"
                                                   placeholder="{{this.label}}" class="form-control"
                                                   data-param-type="form" value=""/>
                                            <br/>
                                        {{/equal}}
                                        {{#equal this.type "info"}}
                                            <div class="form-group" id="{{this.id}}">
                                                <span class="help-block">
                                                    {{this.value}}
                                                </span>
                                            </div>
                                        {{/equal}}
                                    {{/each}}
                                    <button type="button" onclick="submitForm('form-{{operation}}')"
                                            class="btn btn-default btnSend">Send
                                        to Device</button>
                                    <label class="wr-input-label hidden"><i
                                            class="fw fw-lifecycle fw-spin fw-2x lblSending"></i> Sending..</label>
                                    <label class="wr-input-label hidden"><i
                                            class="fw fw-check fw-2x lblSent"></i> Sent</label>
                                    <i class="fw fw-wso2-logo fw-pulse fw-2x hidden lbl-execution"> Executing Operation </i>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        {{/each}}
    </div>
{{/if}}

<div id="operation-response-template" style="display: none">
    <div class="content">
        <div class="row">
            <div class="col-lg-5 col-md-6 col-centered">
                <h3>
                    <span class="fw-stack center-block">
                        <i class="fw fw-circle-outline fw-stack-2x"></i>
                        <i id="status-icon" class="fw fw-error fw-stack-1x"></i>
                    </span>
                    <br>
                </h3>
                <h4>
                    <span id="title"></span>
                    <br>
                </h4>
                <span id="description"></span>
            </div>
        </div>
    </div>
</div>

{{#zone "bottomJs"}}
    {{js "js/operation-bar.js"}}
{{/zone}}
