<?php
    // types:  primary, info, success, warning, danger, inverse and link.
    $this->widget('bootstrap.widgets.TbButton', array(
            'buttonType'=>'ajaxButton',
            'type'=>$data['status']=='loggedIn'?'danger':'success',
            'label'=>$data['status']=='loggedIn'?__('PHONESETTINGS_MY_PHONES_LOGOUT_BUTTON'):__('PHONESETTINGS_MY_PHONES_LOGIN_BUTTON'),
            'loadingText'=>'loading...',
            'url'=>url('phonesettingsMyPhones/default/authenticate'),
            'ajaxOptions'=>array(
                'dataType'=>'json',
                'type'=>'POST',
                'data'=>array(
                    'id'=>$data['phoneId'],
                    Yii::app()->request->csrfTokenName => Yii::app()->request->csrfToken,
                ),
                'beforeSend'=>'function(jqXHR, settings){
                    
                    settings.data += "&status=";
                    settings.data += $("#phoneId_'.$data['phoneId'].'").hasClass("btn-danger")?"loggedIn":"loggedOut";

                    settings.data += "&label=";
                    settings.data += $("#phoneId_'.$data['phoneId'].'").hasClass("btn-danger")?"'.__('PHONESETTINGS_MY_PHONES_LOGOUT_BUTTON').'":"'.__('PHONESETTINGS_MY_PHONES_LOGIN_BUTTON').'";
                }',
                'success'=>'function(data){
                    if (data.loggedOut) {
                        $("#phoneId_'.$data['phoneId'].'").addClass("btn-success").removeClass("btn-danger");
                    } else {
                        $("#phoneId_'.$data['phoneId'].'").addClass("btn-danger").removeClass("btn-success");
                    }
                    $("#phoneId_'.$data['phoneId'].'").text(data.label);
                }'
                
            ),
            'htmlOptions'=>array(
                 //   'class'=>'logginButton',
                    'id'=>'phoneId_'.$data['phoneId'],
                    'data-translation-target'=>'PHONESETTINGS_MY_PHONES_LOGIN_BUTTON_TARGET',
            ),

    ));
    
if (Yii::app()->user->translateMode) {
	echo '<i data-translation-target="PHONESETTINGS_MY_PHONES_LOGIN_BUTTON_TARGET" data-translation-id="PHONESETTINGS_MY_PHONES_LOGOUT_BUTTON"></i>';
	echo '<i data-translation-target="PHONESETTINGS_MY_PHONES_LOGIN_BUTTON_TARGET" data-translation-id="PHONESETTINGS_MY_PHONES_LOGIN_BUTTON"></i>';
}
?>

