<?php
/* @var $this OptionController */
/* @var $model Option */
$this->breadcrumbs = array(
    'Option' => array('admin'),
    'Manage',
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$('#option-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
");

?>
<div class="page-header"><h1>Manage Option</h1></div>
<?php
$this->widget('ext.widgets.FGridView', array(
    'id' => 'option-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        array(
            'name' => 'key',
            'value' => 'Yii::t("admin",$data->key)',
//	    'value' => "ucwords(strtolower(str_replace('_', ' ', \$data->key)))"
        )
        ,
        array(
            'class' => 'editable.EditableColumn',
            'name' => 'value',
            'headerHtmlOptions' => array('style' => 'width: 110px'),
            'editable' => array(//editable section
                'url' => $this->createUrl('quickUpdate'),
                'placement' => 'right',
                'inputclass' => 'col-md-12',
            ),
            'htmlOptions' => array('width' => '50%', 'class' => 'editable-fullwidth-input'),
        ),
        array(
            'name' => 'group',
            'filter' => CHtml::listData(OptionGroup::model()->findAll(), 'key', 'title'),
            'value' => '$data->optionGroup->title',
        ),
        array(
            'class' => 'CButtonColumn',
            'template' => '{update} {delete}',
        ),
    ),
));
?>

<script>
<?php ob_start(); ?>
    $.ajaxPrefilter(function(options, originalOptions, jqXHR) {
        var data = decodeURIComponent(options.data);
        var schemas = ['value=https://', 'value=http://'];
        schemas.forEach(function(schema) {
            if (data.indexOf(schema))
            {
                var protocol = schema.replace('value=', '').replace('://', '');
                data = data.replace(schema, 'striped_protocol=' + protocol + '&value=');
                encodeURIComponent(data);
                options.data = data;
                return options;
            }
        });
    });
<?php Yii::app()->clientScript->registerScript('ajax', ob_get_clean()); ?>
</script>
