<div class="row">
    <div class="col-sm-7">
        <h1 class="pagetitle"><span translate lib="web">detailsfor</span> {{ctrl.model.name}}</h1>
    </div>
</div>
<style type="text/css">
    .list-group-item:hover {
        color: #337ab7;
        text-shadow: 0 0 1em #337ab7;
        cursor: pointer;
    }

    .listgroupitemselected {
        border: 6px;
        border-color: black;
        background-color: #337ab7;
        color: white;
        cursor: pointer;
    }

    textarea {
        border: 0 none white;
        overflow: hidden;
        padding: 0;
        outline: none;
        background-color: #D0D0D0;
    }
</style>

<div class="form-inline">
    <label for="add" class="col-sm-1 control-label" translate lib="web">add</label>
    <div class="col-sm-6 input-group">
        <input type="text" name="user" id="user" ng-model="ctrl.searchtext" ng-keyup="ctrl.setkey($event)"
            class="form-control" ng-model-options="{ debounce: 500 }" ng-change="ctrl.handlefilter()"
            ng-keypress="ctrl.restrictInput($event)" autocomplete="off" />
        <button ng-click="ctrl.adduser()" type="button"
            ng-disabled="ctrl.loading==true || ctrl.searchSelectedItem==null" class="btn btn-success " translate
            lib="web">add</button>
    </div>
</div>
<div>
    <div class="col-sm-2"></div>
    <div class="col-sm-6">
        <ul class="list-group">
            <li class="list-group-item" ng-repeat="item in ctrl.searchFilteredList"
                ng-click="ctrl.fillTextbox(item.name)"
                ng-class="{listgroupitemselected: ctrl.searchSelectedItem._id==item._id}">
                ({{item._type}}) {{item.name}} <span ng-show="item.name != item.username">{{" " + item.username}}</span>
            </li>
        </ul>
    </div>
</div>


<section ng-repeat="ace in ctrl.model._acl" ng-show="ctrl.collection!='files'">
    <div class="form-inline">
        <label class="col-sm-4 control-label">{{ace.name}}: </label>
        <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace.rights, 1)"
            ng-click="ctrl.toogleBit(ace, 1)" value="1" id="{{ace._id}}" /> create
        <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace.rights, 2)"
            ng-click="ctrl.toogleBit(ace, 2)" value="2" id="{{ace._id}}" /> read
        <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace.rights, 3)"
            ng-click="ctrl.toogleBit(ace, 3)" value="3" id="{{ace._id}}" /> update
        <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace.rights, 4)"
            ng-click="ctrl.toogleBit(ace, 4)" value="4" id="{{ace._id}}" /> delete
        <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace.rights, 5)"
            ng-click="ctrl.toogleBit(ace, 5)" value="5" id="{{ace._id}}" /> invoke
        <button type="button" ng-click="ctrl.removeuser(ace._id)" ng-disabled="ctrl.loading" translate
            lib="web">delete</button>
    </div>
</section>
<section ng-repeat="ace in ctrl.model.metadata._acl" ng-show="ctrl.collection=='files'">
    <div class="form-group">
        <div class="col-sm-9 input-group">
            <label class="col-sm-3 control-label">{{ace.name}}: </label>
            <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace.rights, 1)"
                ng-click="ctrl.toogleBit(ace, 1)" value="1" id="{{ace._id}}" /> create
            <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace.rights, 2)"
                ng-click="ctrl.toogleBit(ace, 2)" value="2" id="{{ace._id}}" /> read
            <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace.rights, 3)"
                ng-click="ctrl.toogleBit(ace, 3)" value="3" id="{{ace._id}}" /> update
            <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace.rights, 4)"
                ng-click="ctrl.toogleBit(ace, 4)" value="4" id="{{ace._id}}" /> delete
            <input ng-disabled="ctrl.loading==true" type="checkbox" ng-checked="ctrl.isBitSet(ace.rights, 5)"
                ng-click="ctrl.toogleBit(ace, 5)" value="5" id="{{ace._id}}" /> invoke
            <button type="button" ng-click="ctrl.removeuser(ace._id)" ng-disabled="ctrl.loading" translate
                lib="web">delete</button>
        </div>
    </div>
</section>


<pre ng-show="ErrorMessage!=null" class=" alert alert-danger" role="alert">{{ ErrorMessage }}</pre>
<div ng-show="ctrl.errormessage != ''"" class=" alert alert-danger" role="alert">{{ctrl.errormessage}}</div>
<pre>{{ctrl.message}}</pre>
<a href="" ng-hide="ctrl.showjson==true" ng-click="ctrl.togglejson()" translate lib="web">showjson</a>
<a href="" ng-hide="ctrl.showjson==false" ng-click="ctrl.togglejson()" translate lib="web">showproperties</a>
<form ng-submit="ctrl.submit()" class="form-horizontal" role="form" autocomplete="off" ng-hide="ctrl.showjson==true">
    <section ng-repeat="key in ctrl.keys">
        <div class="form-group" ng-show="ctrl.model._encrypt.indexOf(key) == -1">
            <label class="col-sm-3 control-label"><span translate lib="web">{{ key }}</span>: <a href=""
                    ng-click="ctrl.removekey(key)" translate lib="web">delete</a></label>
            <div class="col-sm-9">
                <textarea class='form-control' rows='1' data-min-rows='1' ng-model="ctrl.model[key]"></textarea>
                <!-- 
                <input ng-model="ctrl.model[key]" class="form-control input-md" ng-disabled="ctrl.loading==true" />
                -->
            </div>
        </div>
        <div class="form-group" ng-show="ctrl.model._encrypt.indexOf(key) > -1">
            <label class="col-sm-3 control-label"><span translate lib="web">{{ key }}</span>: <a href=""
                    ng-click="ctrl.removekey(key)" translate lib="web">delete</a></label>
            <div class="col-sm-9">
                <input type="password" class='form-control' rows='1' data-min-rows='1'
                    ng-model="ctrl.model[key]"></input>
                <!-- 
                <input ng-model="ctrl.model[key]" class="form-control input-md" ng-disabled="ctrl.loading==true" />
                -->
            </div>
        </div>

    </section>


    <div class="form-inline">
        <label class="col-sm-2 control-label" translate lib="web">add key</label>
        <div class="col-sm-4">
            <input type="text" class='form-control' ng-model="ctrl.newkey"></input>
        </div>
        <div class="col-sm-2">
            <button ng-click="ctrl.addkey()" type="button" ng-disabled="ctrl.loading==true" class="btn btn-success"
                translate lib="web">add</button>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" ng-disabled="ctrl.loading==true" class="btn btn-success" translate
                lib="web">save</button>
        </div>
    </div>
</form>

<form ng-submit="ctrl.submit()" class="form-horizontal" role="form" autocomplete="off" ng-hide="ctrl.showjson==false">
    <div ng-hide="ctrl.showjson==false" class="form-group" style="width: 100%;">
        <div class="form-group">
            <div class="col-sm-offset-3 col-sm-9">
                <button type="submit" ng-disabled="ctrl.loading==true" class="btn btn-success" translate
                    lib="web">save</button>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label" translate lib="web">json</label>
            <div class="col-sm-9">
                <!-- <textarea class="form-control" rows="5" ng-model="ctrl.jsonmodel" style="max-width: 100%;"></textarea> -->

                <textarea class=' form-control' rows='3' data-min-rows='3' ng-model="ctrl.jsonmodel"></textarea>

                <!-- <textarea msd-elastic  class="form-control" ></textarea> -->
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-3 col-sm-9">
                <button type="submit" ng-disabled="ctrl.loading==true" class="btn btn-success" translate
                    lib="web">save</button>
            </div>
        </div>
    </div>
</form>