<?xml version="1.0" standalone="yes"?>
<!DOCTYPE container>
<container
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:var="http://www.skyrix.com/od/binding"
    xmlns:const="http://www.skyrix.com/od/constant"
    xmlns:label="OGo:label"
    >
  <md-dialog flex="50" flex-sm="80" flex-xs="100">
    <md-toolbar>
      <div class="md-toolbar-tools">
        <md-icon class="material-icons sg-icon-toolbar-bg">folder_shared</md-icon>
        <div class="pseudo-input-container md-flex">
          <label class="pseudo-input-label"><var:string label:value="Access Rights"/></label>
          <div layout="row" layout-align="start center">
            <div class="sg-color-chip"
                 ng-show="::acl.folderClassName()" ng-class="::acl.folderClassName()"><!-- color --></div>
            <div class="sg-md-title" ng-bind="::acl.folder.name"><!-- calendar --></div>
          </div>
        </div>
        <md-button class="md-icon-button" ng-click="acl.closeModal()">
          <md-icon aria-label="Close dialog">close</md-icon>
        </md-button>
      </div>
    </md-toolbar>
    <md-dialog-content class="md-padding">
      <div layout="row">
        <md-icon>search</md-icon>
        <md-autocomplete
            class="md-flex sg-input-no-message"
            md-input-name="addUser"
            md-search-text="acl.searchText"
            md-selected-item="acl.userToAdd"
            md-selected-item-change="acl.addUser(user)"
            md-items="user in acl.userFilter(acl.searchText)"
            md-item-text="user.empty"
            var:md-min-length="minimumSearchLength"
            md-delay="300"
            md-no-cache="true"
            label:md-floating-label="Add User">
          <md-item-template>
            <span class="md-contact-suggestion">
              <span class="md-contact-name"
                    md-highlight-text="acl.searchText"
                    md-highlight-flags="^i">{{ user.$fullname() }}</span>
              <span class="md-contact-email"
                    md-highlight-text="acl.searchText"
                    md-highlight-flags="^i">{{ user.c_email }}</span>
            </span>
          </md-item-template>
        </md-autocomplete>
      </div>
      <md-card ng-repeat="user in acl.users | orderBy:['userClass', 'cn']"
               class="sg-collapsed"
               ng-class="{ 'sg-expanded': user.uid == acl.selectedUid }">
        <a class="md-flex md-button" ng-click="acl.selectUser(user, $event)">
          <div layout="row" layout-align="start center">
            <div class="card-picture">
              <sg-avatar-image class="md-avatar"
                               sg-email="user.c_email"
                               ng-disabled="user.inactive"
                               size="40">{{ ::user.$avatarIcon }}</sg-avatar-image>
            </div>
            <div class="sg-tile-content">
              <div class="sg-md-subhead"><div ng-bind="::user.$fullname()"><!-- username --></div></div>
              <div class="sg-md-body"><div ng-bind="::user.c_email"><!-- email --></div></div>
            </div>
	    <md-button class="md-icon-button md-secondary" type="button"
                       ng-click="acl.toggleAllRights(user)"
                       ng-hide="!acl.showRights(user) || user.$isSpecial()">
              <md-icon>select_all</md-icon>
            </md-button>
            <md-button class="md-icon-button" type="button"
                       ng-click="acl.removeUser(user)"
                       ng-hide="user.uid != acl.selectedUid || user.$isSpecial()">
              <md-icon>delete</md-icon>
            </md-button>
            <md-icon ng-class="{ 'md-rotate-180': acl.showRights(user) }">expand_more</md-icon>
          </div>
        </a>
        <md-card-content id="AccessRightList" ng-show="acl.showRights(user)">
          <var:if condition="canSubscribeUsers">
            <md-checkbox ng-model="user.isSubscribed"
                         label:arial-label="Subscribe User"
                         ng-disabled="user.wasSubscribed || acl.hasNoRight(user)"
                         ng-true-value="1"
                         ng-false-value="0"
                         ng-hide="user.$isSpecial()">
              <var:string label:value="Subscribe User"/>
            </md-checkbox>
          </var:if>
          <div ng-include="acl.templateName(user)">
            <!--
                Load ng-template #UIxUserRightsEditor from main module wox. Inner wox templates are:
                - UI/Templates/ContactsUI/UIxContactsUserRightsEditor.wox
                - UI/Templates/MailerUI/UIxMailUserRightsEditor.wox
                - UI/Templates/SchedulerUI/UIxCalUserRightsEditor.wox
            -->
          </div>
        </md-card-content>
      </md-card>
    </md-dialog-content>

    <md-dialog-actions ng-hide="acl.confirmation.showing">
      <md-button class="md-primary" ng-click="acl.saveModal()"><var:string label:value="Save"/></md-button>
    </md-dialog-actions>

    <md-dialog-content class="md-default-theme md-bg md-warn md-padding sg-dialog-message ng-hide"
                       ng-show="acl.confirmation.showing">
      <div ng-bind="acl.confirmation.message"><!-- message --></div>
    </md-dialog-content>
    <md-dialog-actions ng-show="acl.confirmation.showing">
      <md-button ng-click="acl.selectedUser.$resetRights(true); acl.confirmation.showing = false">
        <var:string label:value="Keep Private"/>
      </md-button>
      <md-button class="md-warn" ng-click="acl.confirmation.showing = false">
        <var:string label:value="Give Access"/>
      </md-button>
    </md-dialog-actions>
  </md-dialog>

</container>
