{{!
* 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="well-queue">
  <div class="row queue-heading-row">
    <div class="col-md-12">
      <h3>
        {{#if content.isNew}}
          <div class="input-group col-md-8">
            {{focus-input value=content.name length="250" class="form-control" classBinding="content.isValid::input-error" action="createQ" revert="delQ" placeholder="Enter Queue Name"}}
            <span class="input-group-btn">
              <button {{action "delQ" content target="controllers.queues"}} {{bind-attr class=":btn :btn-danger"}} type="button">Cancel</button>
              <button {{action "createQ" content target="controllers.queues"}} {{bind-attr class=":btn :btn-success content.isValid::disabled"}} type="button">Create</button>
            </span>
          </div>
        {{else}}
          {{#unless isRenaming}}
              {{content.name}}
              {{#unless isRoot}}
                {{#unless isNotOperator}}
                  <small>
                    <a href="#" {{action "renameQ" 'ask'}}>
                      <i class="fa fa-edit"></i>
                    </a>
                  </small>
                  <small>
                    {{confirm-delete action="delQ" param=content}}
                  </small>
                {{/unless}}
              {{/unless}}
            {{else}}
            <div class="input-group col-md-8">
              {{focus-input value=content.name length="250" class="form-control" action="renameQ" revert="renameQ" classBinding="content.isValid::input-error" placeholder="Enter Queue Name"}}
              <span class="input-group-btn">
                <button {{action "renameQ" 'cancel'}} {{bind-attr class=":btn :btn-danger"}} type="button">Cancel</button>
                <button {{action "renameQ" 'rename'}} {{bind-attr class=":btn :btn-success content.isValid::disabled"}} type="button">Rename</button>
              </span>
            </div>
          {{/unless}}
        {{/if}}
      </h3>
      {{#each pathErrors}}
        <p class="help-block red">{{this}}</p>
      {{/each}}
      <h4><small>{{content.path}}</small></h4>
    </div>
  </div>
  <div class="row queue-capacity-row">
    <div class="col-md-12">
      {{total-capacity 
        currentQueue=content 
        allQueues=allQueues 
        allQueuesArranged=allQueuesArranged 
        addQueue="addQ" 
        createQueue="createQ" 
        deleteQueue="delQ" 
        hasNew=controllers.queues.hasNewQueue
        isOperator=isOperator
      }}
    </div>
  </div>
  <div class="row queue-acl-row">
    <div class="col-md-6">
      <div class="panel panel-default panel-capacity">
        <div class="panel-heading">
          <div class="panel-title">
            Access Control and Status
          </div>
        </div>
        <div class="panel-body">
          <form class="form-horizontal form-acl" role="form">
          <div class="form-group row">
              <label class="col-lg-4 col-xs-4 control-label">State</label>
              <div class="col-lg-6 col-md-6 col-sm-8 col-xs-7 control-value">
                <div class="btn-group btn-group-xs" data-toggle="buttons" >
                  <label  {{action 'setState' 'running'}} {{bind-attr class=":btn isRunning:btn-success:btn-default isRunning:active isNotOperator:disabled" }}>
                    <input type="radio" name="options"> Running
                  </label>
                  <label  {{action 'setState' 'stopped'}} {{bind-attr class=":btn isRunning:btn-default:btn-danger isRunning::active isNotOperator:disabled" }}>
                    <input type="radio" name="options"> Stopped
                  </label>
               </div>
              </div>
          </div>
          
          {{#if isOperator}}

            <div class="form-group row">
              <label class="col-lg-4 col-xs-4 control-label">Administer Queue</label>
              <div class="col-lg-6 col-md-6 col-sm-8 col-xs-7 control-value">
                <div class="btn-group btn-group-xs" data-toggle="buttons">
                  {{radio-button label="Anyone" selectionBinding="acl_administer_queue" value="*"}}
                  {{radio-button label="Custom" selectionBinding="acl_administer_queue" value="custom"}}
                </div>
                {{#if aaq_dirty}}
                  <a {{action 'rollbackProp' 'acl_administer_queue'}} href="#"><i class="fa fa-undo"></i></a>
                {{/if}}
              </div>
            </div>
            {{#unless aaq_anyone}}
              {{user-group-input ug=content.acl_administer_queue disabled=aaq_anyone}}
            {{/unless}}

            <div class="form-group row">
              <label class="col-lg-4 col-xs-4 control-label">Submit Applications</label>
              <div class="col-lg-6 col-md-6 col-sm-8 col-xs-7 control-value">
                <div class="btn-group btn-group-xs" data-toggle="buttons">
                  {{radio-button label="Anyone" selectionBinding="acl_submit_applications" value="*"}}
                  {{radio-button label="Custom" selectionBinding="acl_submit_applications" value="custom"}}
                </div>
                {{#if asa_dirty}}
                  <a {{action 'rollbackProp' 'acl_submit_applications'}} href="#"><i class="fa fa-undo"></i></a>
                {{/if}}
              </div>
            </div>
            {{#unless asa_anyone}}
              {{user-group-input ug=content.acl_submit_applications disabled=asa_anyone}}
            {{/unless}}
            
          {{else}}
            <div class="form-group">
              <label class="col-lg-4 col-xs-4 control-label">Administer Queue</label>
              <div class="col-lg-8 col-xs-8 control-value">
               <p class="form-control-static">
                {{escapeACL content.acl_administer_queue}}
               </p> 
              </div>
            </div>

            <div class="form-group">
              <label class="col-lg-4 col-xs-4 control-label">Submit Applications</label>
              <div class="col-lg-8 col-xs-8 control-value">
               <p class="form-control-static">
                {{escapeACL content.acl_submit_applications}}
               </p> 
              </div>
            </div>
          {{/if}}
          </form>
        </div>
      </div>
    </div>

    <div class="col-md-6 queue-resources">
      <div class="panel panel-default panel-capacity">
        <div class="panel-heading">
          <div class="panel-title">
            Resources
          </div>
        </div>
        <div class="panel-body">
          <form class="form-horizontal" role="form">
            <div class="form-group">
              <label class="col-xs-6 control-label">User Limit Factor</label>
              {{#if isOperator}}
              <div class="col-xs-6 control-value">
                {{int-input value=content.user_limit_factor maxlength=10 class="input-sm input-int"}}
              {{else}}
              <div class="col-xs-6">
                <p class="form-control-static">{{content.user_limit_factor}}</p>
              {{/if}}
              </div>
            </div>
            <div class="form-group">
              <label class="col-xs-6 control-label">Minimum User Limit</label>
                {{#if isOperator}}  
              <div class="col-xs-6 control-value">
                  <div class="input-group input-percent">
                    {{int-input value=content.minimum_user_limit_percent class="input-sm" maxVal=100}}
                    <span class="input-group-addon">%</span>
                  </div>
                {{else}}
              <div class="col-xs-6">
                  {{#if content.minimum_user_limit_percent}}
                    <p class="form-control-static">{{content.minimum_user_limit_percent}} %</p>
                  {{else}}
                    <p class="form-control-static">-</p>
                  {{/if}}
                {{/if}}
              </div>
            </div>
            <div class="form-group">
              <label class="col-xs-6 control-label">Maximum Applications</label>
              {{#if isOperator}}
              <div class="col-xs-6 control-value">
                {{int-input placeholder="Inherited" maxlength=15 value=content.maximum_applications class="input-sm input-int"}}
              {{else}}
              <div class="col-xs-6">
                {{#if content.maximum_applications}}
                  <p class="form-control-static">{{content.maximum_applications}}</p>
              {{else}}
                  <p class="form-control-static">-</p>
                {{/if}}
              {{/if}}
              </div>
            </div>
            <div class="form-group">
              <label class="col-xs-6 control-label">Maximum AM Resource</label>
                {{#if isOperator}}
              <div class="col-xs-6 control-value">
                  <div class="input-group input-percent">
                    {{int-input placeholder="Inherited" value=content.maximum_am_resource_percent class="input-sm" maxVal=100}}
                    <span class="input-group-addon">%</span>
                  </div>
                {{else}}
              <div class="col-xs-6">
                  {{#if content.maximum_am_resource_percent}}
                    <p class="form-control-static">{{content.maximum_am_resource_percent}} %</p>
                  {{else}}
                    <p class="form-control-static">-</p>
                  {{/if}}
                {{/if}}
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
