
<div class="btn-group active" style="margin:0">

<?php
    $userMobitorToggleStateClass = Yii::app()->user->userMonitor == 'true' ? 'icon-caret-right' : 'icon-caret-left';

    echo CHtml::ajaxLink(
      '<i class="'.$userMobitorToggleStateClass.'"></i>',
      Yii::app()->createUrl( 'UserSettings/set' ),
      array( // ajaxOptions
        'type' => 'POST',
        'beforeSend' => "function( request ){
            console.log(userMonitor);
            userMonitor = !userMonitor;
            if(userMonitor){
                $('#userMonitor').css('display','block');
                $('#userMonitor').css('right','0');
                $('#mainWrapper').css('margin-right','260px');
                $('#footer').css('margin-right','250px');
                $('#userMonitorToggleLink i').attr('class', 'icon-caret-right');
                
            }
            else{
                setTimeout(function(){
                    $('#userMonitor').hide();
                },200);
                
                $('#userMonitor').css('right','-250px');
                $('#mainWrapper').css('margin-right','');
                $('#footer').css('margin-right','');
                $('#userMonitorToggleLink i').attr('class', 'icon-caret-left');
            }
        }",
        'success' => "function( data )
                      {
                        // handle return data
                        //alert( data );
                      }",
        'data' => array(
            Yii::app()->request->csrfTokenName => Yii::app()->request->csrfToken,
            'UserSettings' => "js:{'userMonitor': !userMonitor}",
        )
      ),
      array(
        'id'=>'userMonitorToggleLink'
      )
    );
    
?>
</div>