<?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'phonesettings-tones',
    'enableAjaxValidation' => false,
    'action' => array('update'),
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));

$this->widget('ext.PlNavbar', array(
    'brand' => __('PHONESETTINGS_TONES_NAVBAR_TITLE'),
    'htmlOptions' => array(
        'data-translation-id' => 'PHONESETTINGS_TONES_NAVBAR_TITLE',
    ),
));

$this->widget('bootstrap.widgets.TbAlert', array(
    'block' => true, // display a larger alert block?
    'fade' => true, // use transitions?
    'closeText' => '&times;', // close link text - if set to false, no close link is displayed
    'alerts' => array(// configurations per alert type
        'error' => array(// success, info, warning, error or danger
            'block' => true,
            'fade' => true,
            'closeText' => '&times;'
        ),
    ),
));
?>
<div class="form">
    <?php
    $this->widget('bootstrap.widgets.TbGridView', array(
        'id' => 'phonesettings-tones-grid',
        'type' => 'striped bordered condensed',
        'itemsCssClass' => 'plTable',
        'dataProvider' => $this->phonesettingsTonesSearch(),
        'summaryText' => false,
        'hideHeader' => true,
        'columns' => array(
            array(
                'name' => 'short',
                'type' => 'raw',
                'header' => $model->getAttributeLabel('short'),
                'headerHtmlOptions' => array('data-translation-id' => 'PHONESETTINGS_USER_MODEL_SHORT'),
            ),
            array(
                'name' => 'value',
                'type' => 'raw',
                'value' => array($this, 'renderValue'),
                'header' => $model->getAttributeLabel('value'),
                'headerHtmlOptions' => array('data-translation-id' => 'PHONESETTINGS_USER_MODEL_VALUE')
            ),
            array(
                'name' => 'descr',
                'type' => 'raw',
                'header' => $model->getAttributeLabel('descr'),
                'headerHtmlOptions' => array('data-translation-id' => 'PHONESETTINGS_USER_MODEL_DESCRIPTION')
            ),
        ),
    ));

    echo CHtml::submitButton('save', array('id' => 'phonesettingsTonesAction', 'style' => 'display:none'));

    if (cfg('USER_RINGTONE_UPLOAD')) {
        $footerHtml = CHtml::activeFileField($ringtone, 'data', array('accept' => $acceptMimetype));
        $this->widget('bootstrap.widgets.TbGridView', array(
            'id' => 'phonesettings-user-tones-grid',
            'type' => 'striped bordered condensed',
            'itemsCssClass' => 'plTable items',
            'enableHistory' => false,
            'dataProvider' => $ringtone->userRingtonesSearch(),
            'summaryText' => false,
            'hideHeader' => false,
            'columns' => array(
                array(
                    'name' => 'fileName',
                    'header' => __('RINGTONE_MODEL_FILE_NAME'),
                    'headerHtmlOptions' => array('data-translation-id' => 'RINGTONE_MODEL_FILE_NAME'),
                    'footer' => $footerHtml, // FIXME !
                ),
                array(
                    'class' => 'bootstrap.widgets.TbButtonColumn',
                    'template' => '{delete}',
                    'htmlOptions' => array('class' => 'buttonColumnIcons'),
                    'buttons' => array(
                        'delete' => array(
                            'imageUrl' => false,
                            'url' => 'Yii::app()->createUrl('
                            . '         "phonesettingsTones/default/deleteRingtone",'
                            . '         array("id"=>$data->id)'
                            . ' )   ',
                        ),
                    ),
                    'afterDelete' => 'function(link,success,data){ refreshGrid(success); }',
                ),
            ),
                )
        );
    }


    $this->widget('bootstrap.widgets.TbButton', array(
        'buttonType' => 'button',
        'type' => 'primary',
        'label' => __('GLOBAL_SAVE_BUTTON'),
        'loadingText' => 'loading...',
        'htmlOptions' => array(
            'id' => 'savePhonesettingsTonesButton',
            'data-translation-id' => 'GLOBAL_SAVE_BUTTON',
        ),
    ));
    if (Yii::app()->user->translateMode) {

        $translationID = '<i data-translation-id';
        $eol = '</i><br />';
        $bellcoreDropdown = 'BELLCORE_DROPDOWN';
        $chooseBellchor = 'CHOOSE_BELLCHOR';
        $bellcore = 'BELLCORE';
        $bellcoreMute = 'BELLCORE_MUTE';
        $mimeTypeMessage = 'GLOBAL_FILE_UPLOAD_WRONG_MIME_TYPE_ERROR_MESSAGE';
        $mimeTypeMessageHtek = 'GLOBAL_FILE_UPLOAD_WRONG_MIME_TYPE_ERROR_MESSAGE_HTEK';
        $volume = 'PHONESETTINGS_TONES_VOLUME';
        $chooseVolume = 'PHONESETTINGS_TONES_CHOOSE_VOLUME';
        $ringtoneTypeSystem = 'RINGTONE_TYPE_SYSTEM';
        $ringtoneTypePrivat = 'RINGTONE_TYPE_PRIVAT';

        echo '<br />';
        echo $translationID . '="' . $chooseBellchor . '">' . $chooseBellchor . ': ' . __($chooseBellchor) . $eol;
        echo $translationID . '="' . $bellcore . '">' . $bellcore . ': ' . __($bellcore) . $eol;
        echo $translationID . '="' . $bellcoreMute . '">' . $bellcoreMute . ': ' . __($bellcoreMute) . $eol;
        echo $translationID . '="' . $chooseVolume . '">' . $chooseVolume . ': ' . __($chooseVolume) . $eol;
        echo $translationID . '="' . $volume . '">' . $volume . ': ' . __($volume) . $eol;

        echo $translationID . '="' . $mimeTypeMessage . '">' . $mimeTypeMessage . ': ' . __($mimeTypeMessage) . $eol;
        echo $translationID . '="' . $mimeTypeMessageHtek . '">' . $mimeTypeMessageHtek . ': ' . __($mimeTypeMessageHtek) . $eol;
        echo $translationID . '="' . $ringtoneTypeSystem . '">' . $ringtoneTypeSystem . ': ' . __($ringtoneTypeSystem) . $eol;
        echo $translationID . '="' . $ringtoneTypePrivat . '">' . $ringtoneTypePrivat . ': ' . __($ringtoneTypePrivat) . $eol;
    }
    ?>
    <script>
        $('#savePhonesettingsTonesButton').click(function () {
            var btn = $(this);
            btn.button('loading'); // call the loading function
            $("#phonesettingsTonesAction").click();
        });

        function refreshGrid(success) {
            if (success) {
                $.fn.yiiGridView.update("phonesettings-tones-grid");
            }
        }
    </script>

    <?php echo CHtml::endForm(); ?>

    <?php
    $this->endWidget();
    ?>
</div>
