<?php $__env->startSection('content'); ?>
    <div class="row">
        <div class="col-xs-10">
            <h1>Manage User</h1>
        </div> 
        <?php if($canView): ?>
            <div class="col-xs-2">
                <a href="<?php echo url('/admin/admin_users');; ?>" class="back-btn btn btn-default" type="button" data-toggle="tooltip" data-placement="bottom" title="" class="btn btn-default pull-right" data-original-title="Go back to list">
                    <span class="icon glyphicon glyphicon-th-list"></span>
                </a>
            </div>
        <?php endif; ?>
    </div>
    <div id="edit_user_form" class="user-form">
        <?php echo Form::model($user); ?>

            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group <?=$errors->first('username', 'has-error')?>">
                        <label class="control-label" for="username_input">Username</label>
                        <?php echo Form::text('username', null, array( 
                            'id' => 'username_input',
                            'class' => 'form-control', 
                            'maxlength' => '20',
                            'data-toggle' => ($errors->has('username') ? 'tooltip': null),
                            'title' => ($errors->has('username') ? $errors->first('username'): null),
                            'disabled' => $canEdit ? null : 'disabled')); ?>

                    </div>
                    <div class="form-group <?=$errors->first('email', 'has-error')?>">
                        <label class="control-label" for="email_input">Email</label>
                        <?php echo Form::text('email', null, array(
                            'id' => 'email_input',
                            'class' => 'form-control', 
                            'maxlength' => '100',
                            'data-toggle' => ($errors->has('email') ? 'tooltip': null),
                            'title' => ($errors->has('email') ? $errors->first('email'): null),
                            'disabled' => $canManage ? null : 'disabled')); ?>

                    </div>
                    <div class="form-group <?=$errors->first('first_name', 'has-error')?>">
                        <label class="control-label" for="first_name_input">First Name</label>
                        <?php echo Form::text('first_name', null, array( 
                            'id' => 'first_name_input',
                            'class' => 'form-control', 
                            'maxlength' => '50',
                            'data-toggle' => ($errors->has('first_name') ? 'tooltip': null),
                            'title' => ($errors->has('first_name') ? $errors->first('first_name'): null),
                            'disabled' => $canManage ? null : 'disabled')); ?>

                    </div>
                    
                    <div class="form-group <?=$errors->first('last_name', 'has-error')?>">
                        <label class="control-label" for="last_name_input">Last Name</label>
                        <?php echo Form::text('last_name', null, array( 
                            'id' => 'last_name_input',
                            'class' => 'form-control', 
                            'maxlength' => '50',
                            'data-toggle' => ($errors->has('last_name') ? 'tooltip': null),
                            'title' => ($errors->has('last_name') ? $errors->first('last_name'): null),
                            'disabled' => $canManage ? null : 'disabled')); ?>

                    </div>
                    <?php if($canEdit): ?>
                    <div class="form-group <?=$errors->first('password', 'has-error')?>">
                        <label class="control-label" for="password_input"><?php echo Lang::get('backend.password'); ?></label>
                        <span class="icon glyphicon glyphicon-question-sign pull-right" data-toggle="tooltip" title="<?php echo $user->exists ? Lang::get('backend.password_leave_empty') : '6 to 12 alpha-numeric characters'; ?>" class="btn btn-default pull-right"></span>
                        <?php echo Form::password('password', array( 
                            'id' => 'password_input', 
                            'class' => 'form-control', 
                            'maxlength' => '20',
                            'data-toggle' => ($errors->has('password') ? 'tooltip': null),
                            'title' => ($errors->has('password') ? $errors->first('password'): null))); ?>

                       
                    </div>
                    
                    <div class="form-group <?=$errors->first('password_confirmation', 'has-error')?>">
                        <label class="control-label" for="password_conf_input"><?php echo Lang::get('backend.password_confirm'); ?></label>
                        <?php echo Form::password('password_confirmation', array( 
                            'id' => 'password_conf_input', 
                            'class' => 'form-control', 
                            'maxlength' => '20')); ?>

                    </div>
                    <?php endif; ?>
                </div>
                <div class="col-xs-6">
                    <div class="form-group <?=$errors->first('location', 'has-error')?>">
                        <label class="control-label" for="location_input">Location</label>
                        <?php echo Form::text('location', null, array( 
                            'id' => 'location_input',
                            'class' => 'form-control', 
                            'maxlength' => '100',
                            'data-toggle' => ($errors->has('location') ? 'tooltip': null),
                            'title' => ($errors->has('location') ? $errors->first('location'): null),
                            'disabled' => $canManage ? null : 'disabled')); ?>

                    </div>
                    <div class="form-group <?=$errors->first('contact_1', 'has-error')?>">
                        <label class="control-label" for="contact_1_input">Contact 1</label>
                        <?php echo Form::text('contact_1', null, array( 
                            'id' => 'contact_1_input',
                            'class' => 'form-control', 
                            'maxlength' => '40',
                            'data-toggle' => ($errors->has('contact_1') ? 'tooltip': null),
                            'title' => ($errors->has('contact_1') ? $errors->first('contact_1'): null),
                            'disabled' => $canManage ? null : 'disabled')); ?>

                    </div>
                    <div class="form-group <?=$errors->first('contact_2', 'has-error')?>">
                        <label class="control-label" for="contact_2_input">Contact 2</label>
                        <?php echo Form::text('contact_2', null, array( 
                            'id' => 'contact_2_input',
                            'class' => 'form-control', 
                            'maxlength' => '40',
                            'data-toggle' => ($errors->has('contact_2') ? 'tooltip': null),
                            'title' => ($errors->has('contact_2') ? $errors->first('contact_2'): null),
                            'disabled' => $canManage ? null : 'disabled')); ?>

                    </div>
                    <div class="form-group <?=$errors->first('role', 'has-error')?>">
                        <label class="control-label" for="role_input">Role</label>
                        <?php echo Form::text('role', null, array( 
                            'id' => 'role_input',
                            'class' => 'form-control', 
                            'maxlength' => '50',
                            'data-toggle' => ($errors->has('role') ? 'tooltip': null),
                            'title' => ($errors->has('role') ? $errors->first('role'): null),
                            'disabled' => $canManage ? null : 'disabled')); ?>

                    </div> 
                    
                    <div class="form-group <?=$errors->first('type_id', 'has-error')?>">
                        <label class="control-label" for="type_id_input">Type</label>
                        <?php echo Form::select('type_id', $userTypes, null, array( 
                            'id' => 'type_id_input',
                            'class' => 'form-control',
                            'data-toggle' => ($errors->has('type_id') ? 'tooltip': null),
                            'title' => ($errors->has('type_id') ? $errors->first('type_id'): null),
                            'disabled' => $canManage ? null : 'disabled')); ?>

                    </div> 
                </div>
            </div>
            <div class="row user-permissions-wrapper">
                <div class="col-sm-12">
                    <div class="well">
                        <h2>User Permissions</h2>
                        <?php foreach($permissions as $permissionGroup): ?>
                            <div class="col-sm-6 permission-group-wrapper">
                                <h3><?php echo $permissionGroup->name; ?></h3>
                                <?php if($canManage): ?>
                                    <span class="select-all-permissions">
                                        <a href="#" data-permission-group-id="<?php echo $permissionGroup->id; ?>">
                                            select/unselect all
                                        </a>
                                    </span>    
                                <?php endif; ?>
                                <div class="clear"></div>
                                <div class="permission-wrapper">
                                    <?php foreach($permissionGroup->permissions as $permission): ?>
                                        <div class="permission-picker">
                                            <label class="checkbox-inline">
                                                <?php echo Form::checkbox(
                                                    "user_permissions[]", 
                                                    $permission->id,
                                                    $user->permissions->contains($permission->id),
                                                    array(
                                                        "id" => "user_permission_{$permission->id}",
                                                        'disabled' => $canManage ? null : 'disabled',
                                                        'data-permission-group-id' => $permissionGroup->id
                                                    )); ?>

                                                <b><?php echo ucfirst($permission->display_name); ?></b>
                                            </label>
                                        </div>
                                    <?php endforeach; ?>
                                </div>
                            </div>
                        <?php endforeach; ?>
                        <div class="clear"></div>
                    </div>
                </div>
            </div>
            <?php if($canEdit): ?>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group pull-right">
                            <?php echo Form::submit(Lang::get('backend.save'), array('class' => 'btn btn-primary')); ?>

                        </div>
                    </div>
                </div>
            <?php endif; ?>
        <?php echo Form::close(); ?>

    </div>
    
    <script>
        $(function() {
            var manageUsersView = new Eae.View.BackendUserForm({
                el : $('#edit_user_form')
            });
        });  
    </script>
<?php $__env->stopSection(); ?>



<?php echo $__env->make('admin.layouts.main',array(
    'scripts' => array(
        Config::get('path.backoffice.js_path') . '/view/user/backend-user-form.js'
    )
), array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>