<?php

$form=$this->beginWidget('ext.PlGrid.PlActiveForm', array(
        'id'=>'routing_queue-form',
        'gridId'=>'routing_queue-grid',
        'action'=> $model->isNewRecord ? array('create') : array()
    ));

    $this->widget('bootstrap.widgets.TbTabs', array(
    		//'type' => 'tabs', // Menu type. Valid values are tabs, pills and list.
    		'tabs'=>$this->getTabularFormTabs($form, $model,$tier,$availableUsers,$availableExternalAgents),
    		'htmlOptions' =>array('data-translation-target'=>'QUEUE_TAB_MENU_HEADER_TRANSLATION'),
    ));
   echo $form->errorSummary($model); 

   
if (Yii::app()->user->translateMode) {
    echo '<i data-translation-target="QUEUE_TAB_MENU_HEADER_TRANSLATION" data-translation-id="QUEUE_MODEL_TAB_MENU_GENERAL_DATA"></i>';
    echo '<i data-translation-target="QUEUE_TAB_MENU_HEADER_TRANSLATION" data-translation-id="QUEUE_MODEL_TAB_MENU_ADDITIONAL_DATA"></i>';
    echo '<i data-translation-target="QUEUE_TAB_MENU_HEADER_TRANSLATION" data-translation-id="QUEUE_MODEL_TAB_MENU_USERS"></i>';
    echo '<i data-translation-target="QUEUE_TAB_MENU_HEADER_TRANSLATION" data-translation-id="QUEUE_MODEL_TAB_MENU_EXTERNAL_AGENTS"></i>';
    
    echo '<i data-translation-target="TIERS_MODEL_USER_ID_TRANSLATIONS" data-translation-id="TIERS_MODEL_USER_ID"></i>';
    echo '<i data-translation-target="TIERS_MODEL_USER_ID_TRANSLATIONS" data-translation-id="TIERS_MODEL_USER_ID_CHOOSE_QUEUE_MEMBER"></i>';

    echo "<i data-translation-target='TARGET_ON_TIMEOUT_DROPDOWN' data-translation-id='USERS'></i>";
    echo "<i data-translation-target='TARGET_ON_TIMEOUT_DROPDOWN' data-translation-id='GROUPS'></i>";
    echo "<i data-translation-target='TARGET_ON_TIMEOUT_DROPDOWN' data-translation-id='IVRS'></i>";
    echo "<i data-translation-target='TARGET_ON_TIMEOUT_DROPDOWN' data-translation-id='QUEUES'></i>";
        
    echo "<i data-translation-target='TARGET_ON_TIMEOUT_DROPDOWN' data-translation-id='USER_VOICE_MAILS'></i>";
    echo "<i data-translation-target='TARGET_ON_TIMEOUT_DROPDOWN' data-translation-id='GROUP_VOICE_MAILS'></i>";
    echo "<i data-translation-target='TARGET_ON_TIMEOUT_DROPDOWN' data-translation-id='VOICE_MAIL_SUFFIX'></i>";
    echo "<i data-translation-target='TARGET_ON_TIMEOUT_DROPDOWN' data-translation-id='ANNOUNCEMENT'></i>";

}

$this->endWidget();
?>
<script>

$('#queue-external-agent-grid').on('change', 'input[type=text]', function(e){
    if ($(this).val() <= 0) {
        $(this).val(1);
    }
});

$('#queue-member-grid').on('change', 'input[type=text]', function(e){
    if ($(this).val() <= 0) {
        $(this).val(1);
    }
});

$('#queue-external-agent-grid').on('keypress', 'input[type=text]', function(e){
    return validateUserInput(e);
});


$('#queue-member-grid').on('keypress', 'input[type=text]', function(e){
    return validateUserInput(e);
});
    
function validateUserInput(e) {
   

    var k = e.keyCode || e.charCode;
    var c = e.charCode;
    var isArrow = (c == 0 && k >= 37 && k <= 40);
    var isSpecial = ((k == 8) || (k == 9) || (k == 127)) || isArrow;   // backspace, tab, delete
    var isOK = (k >= 48 && k <= 57) ;  // numbers
    return isOK || isSpecial;
}
</script>