<?php if (!$this->isXhr) : ?>
<?php
$title = 'Roles';
$this->headTitle($title);

$this->inlineScript()->appendFile($this->basePath() . '/assets/js/jquery/jquery-ajaxform.js');
$this->inlineScript()->appendFile($this->basePath() . '/assets/js/jasny/jasny-rowlink.js');
$this->inlineScript()->appendFile($this->url('roles/js'));

?>
<div id="role-canvas">
<?php endif; ?>

<?php
$pagination = $this->paginationControl(
    $this->roles, 'sliding', array('partial/paginator.phtml', 'TdyAdmins'), array(
        'route' => 'users',
        'params' => array(),
        'q' => $this->q,
    )
);

$currentUser = $this->currentUser();
$isRoot = in_array('dev', $currentUser->role()->privileges());
?>

<?php
$successMessages = $this->flashMessenger()->setNamespace('roles');
if ($successMessages->hasSuccessMessages()) {
    $messages = $successMessages->getSuccessMessages();
    echo $this->alert($messages[0], 'alert-success', true);
}
?>
<div class="page-title page-header">
    <h1>Roles</h1>
</div>

<div class="section clearfix">
    <div class="pull-left row-options">
        <form method="get" action="<?php echo $this->url('roles'); ?>" class="form form-inline">
            Show <?php echo $this->showRowNumberOptions($this->l); ?>
        </form>
    </div>
    <div class="pull-left col-sm-3">
        <form method="get" action="<?php echo $this->url('roles'); ?>" class="form form-inline form-line-search">
            <div class="form-group">
                <div class="input-group">
                    <input type="text" class="form-control" name="q" placeholder="Search" value="<?php echo $this->q; ?>">
                <span class="input-group-btn">
                    <button class="btn btn-default" type="submit">
                        <span class="fa fa-search"></span>
                    </button>
                    <a class="btn btn-default btn-clear" href="<?php echo $this->url('users'); ?>">Clear</a>
                </span>
                </div>
            </div>
        </form>
    </div>
    <div class="pull-left">
        <a class="btn btn-primary" data-toggle="modal" href="<?php echo $this->url('roles/add'); ?>" data-target="#modal-add"><i class="fa fa-plus"></i> Add New</a>
    </div>
</div>

    <table class="table table-bordered table-striped table-hover table-roles">
    <thead>
        <tr>
            <th class="col1 id">Role ID</th>
            <th class="col2 name">Name</th>
            <th class="col3 actions">Actions</th>
        </tr>
    </thead>
    <tbody class="rowlink">
    <?php foreach ($this->roles as $role) : ?>
        <tr>
            <td class="col1 id"><?php echo $role->id; ?></td>
            <td class="col2 name"><a data-toggle="modal" data-target="#modal-edit" href="<?php echo $this->url('roles/manage', array('action' => 'edit', 'id' => $role->id)); ?>"><?php echo $role->name; ?></a></td>
            <td class="col3 actions rowlink-skip">
                <a data-toggle="modal" data-target="#modal-edit" href="<?php echo $this->url('roles/manage', array('action' => 'edit', 'id' => $role->id)); ?>" title="Edit" class="btn btn-xs btn-default"><i class="fa fa-pencil"></i></a>
                <?php if ($isRoot) : ?>
                    <?php if ($role->isCore === 1) : ?>
                        <span class="btn btn-xs disabled"><i class="fa fa-trash-o"></i></span>
                        <span class="btn btn-xs disabled"><i class="fa fa-fire"></i></span>
                    <?php else : ?>
                        <?php if ($role->isActive === 1) : ?>
                        <a data-toggle="modal" data-target="#modal-delete" href="<?php echo $this->url('roles/manage', array('action' => 'delete', 'id' => $role->id)); ?>" title="Delete" class="btn btn-xs btn-warning"><i class="fa fa-trash-o"></i></a>
                        <span class="btn btn-xs btn-danger disabled"><i class="fa fa-fire"></i></span>
                        <?php else : ?>
                        <a data-toggle="modal" data-target="#modal-restore" href="<?php echo $this->url('roles/manage', array('action' => 'restore', 'id' => $role->id)); ?>" title="Restore" class="btn btn-xs btn-info"><i class="fa fa-arrow-left"></i></a>
                        <a data-toggle="modal" data-target="#modal-burn"  href="<?php echo $this->url('roles/manage', array('action' => 'burn', 'id' => $role->id)); ?>" title="Burn" class="btn btn-xs btn-danger"><i class="fa fa-fire"></i></a>
                        <?php endif; ?>
                    <?php endif; ?>
                <?php else : ?>
                    <?php if ($role->isCore === 1) : ?>
                    <span class="btn btn-xs disabled"><i class="icon icon-trash"></i></span>
                    <?php else : ?>
                    <a href="<?php echo $this->url('roles/manage', array('action' => 'delete', 'id' => $role->id)); ?>" class="btn btn-xs btn-warning" title="Delete"><i class="icon icon-trash"></i></a>
                    <?php endif; ?>
                <?php endif; ?>
            </td>    
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>

<?php if (!$this->isXhr) : ?>
</div>

<div class="modal fade" id="modal-add" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<div class="modal fade" id="modal-edit" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<div class="modal fade" id="modal-reset" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<div class="modal fade" id="modal-delete" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<div class="modal fade" id="modal-restore" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<div class="modal fade" id="modal-burn" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php endif;