<?
/**
 * Copyright © 2012 Alcatel-Lucent.
 *
 * See the NOTICE file distributed with this work for additional information regarding copyright ownership. Licensed 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.
 */

$policies = $this->policies;
$auths = $this->auths;
$apis = $this->apis;

$addButtonTip = $this->translate("Click to add a new Policy");
$editLinkTip = $this->translate("Select to edit Policy");
$deleteConfirmTitle = $this->translate("Are you sure?");
$deleteConfirmMessage = $this->translate("Click again to confirm");
$deleteConfirmOk = $this->translate("OK");
$deleteConfirmCancel = $this->translate("Cancel");

?>
<div class="container">
    <div class="hero-unit">
        <h1><? echo $this->translate("Policies")?></h1>
        <p><? echo $this->translate("Choose a Policy from the list below to edit")?></p>
    </div>
    <? if(!empty($this->messages)): ?>
    <div class="control-group success">
            <span class="help-block">
                <? foreach ($this->messages as $message): ?>
                <?=$message?>
                <? endforeach ?>
            </span>
    </div>
    <? endif ?>
    <div class="well">
        <div id="list">
            <div class="listItem">
                <div class="item-div pull-left"><label class="item1"><strong><? echo $this->translate("Policy ID")?></strong></label></div>
                <div class="item-div pull-left"><span class="item2"><strong><? echo $this->translate("APIs")?></strong></span></div>
                <div class="item-div pull-left"><span class="item3"><strong><? echo $this->translate("Auths")?></strong></span></div>
                <div class="item-div pull-left"><span class="item4">
                    <a href="/policy/create" class="btn btn-success" rel="tooltip" title="<?=$addButtonTip?>" data-placement="right"><i class="icon-plus icon-white"></i></a></div>
                <span class="clearfix"></span>
            </div>
            <?
            /**
             * @var Policy $policy
             */
            foreach($policies as $policy){?>
                <div class="listItem">
                    <div class="item-div pull-left"><label class="item1" rel="tooltip" title="<?=$editLinkTip?>"><p>
                        <a href="/policy/<?=$policy->id?>"><strong><?if(strlen($policy->id) > 15){ echo substr($policy->id, 0, 15) . "...";}else{ echo $policy->id;} ;?></strong></a></p></label></div>
                    <div class="item-div pull-left"><span class="item2"><p>
                       <?= empty($policy->apiIds)?$this->translate("None"):""?>
                       <? foreach($policy->apiIds as $apiId):
                        /** @var Api $api */
                        $api = $apis[$apiId]; ?>
                        <?= $api->displayName; ?> ( <?=$api->endpoint ?> )<br/>
                        <? endforeach;?>
                    </p>
                    </span></div>
                    <div class="item-div pull-left">
                        <span class="item3"><p>
                        <? if(empty($policy->authIds)): echo $this->translate("None");
                            else:
                                foreach($policy->authIds[0]->authIds as $authId):
                                /** @var Auth $auth */
                                $auth = $auths[$authId]; ?>
                                <?= $auth->type ?>
                                <?endforeach?>
                         <? endif ?>
                        </p></span>
                    </div>
                    <div class="item-div pull-left">
                        <span class="item4"><p>
                        <a href="/policy/<?=$policy->id?>/delete" id="policy-<?=$policy->id?>-delete" class="btn btn-danger delete"
                           confirm-title="<?=$deleteConfirmTitle?>" confirm-content="<?=$deleteConfirmMessage?>"
                            confirm-ok="<?=$deleteConfirmOk?>" confirm-cancel="<?=$deleteConfirmCancel?>"><? echo $this->translate("Delete")?></a>
                        </p></span>
                    </div>
                    <span class="clearfix"></span>
                </div>
                <?}?>
        </div>
    </div>
</div> <!-- /container -->