<?php
$renderNot = array(
    'tcp_transport',
    'allowed_codecs',
    'register_state',
    'state',
    'device_name',
    'last_contact',
    'expires',
    'current_ip',
    'role',
    'scriptExtension'
);
$bool = array('active');
$dropdown = array('role', 'type');

foreach ($model->attributes as $attributeName => $attributeValue) {
    if (in_array($attributeName, $renderNot)) {
        continue;
    }
    $htmlOptions['data-translation-id'] = 'EXTERNAL_HOST_MODEL_' . strtoupper($attributeName);
    if (in_array($attributeName, $bool)) {
        echo $form->CheckBoxRow($model, $attributeName, $htmlOptions);
    } else if (in_array($attributeName, $dropdown)) {

        echo $this->renderDropDown($model, $attributeName, $form);
    } else {
        if ($attributeName == 'username') {
            $htmlOptions['data-translation-target'] = 'AUTHNAME_ATTRIBUTE';
        } else {
            unset($htmlOptions['data-translation-target']);
        }
        echo $form->textFieldRow($model, $attributeName, $htmlOptions);
    }
}
if (Yii::app()->user->translateMode) {
    $this->renderPartial('translationTags');
}
?>
<script>
    var label = $('#ExternalHost_host').parent().parent().find('label');
    $('<span />').text(' *').addClass('required').appendTo(label);
    $('#ExternalHost_host').parent().parent().addClass('required');

    if ($('#ExternalHost_type').find(':selected').val() == '<?php echo ExternalHostTypes::typeRegisteredInbound ?>') {
        $('#ExternalHost_host').parent().parent().hide();
        $('#ExternalHost_host').parent().parent().val('');
    } else {
        $('#ExternalHost_host').parent().parent().show();
    }


    $('#ExternalHost_type').on('change', function () {
        if ($(this).find(':selected').val() == '<?php echo ExternalHostTypes::typeRegisteredInbound ?>') {

            $('#ExternalHost_host').parent().parent().hide();
            $('#ExternalHost_host').parent().parent().val('');
        } else {
            $('#ExternalHost_host').parent().parent().show();
        }
    });
</script>
