<?php
$this->PageTitle = 'Produtos';

$botoes = (User::canUpdate()) ? '{valoresAdd} {valoresUpdate} {view} {update}' : '{view}';

if (User::isAdmin()) {
	$botoes .= ' {delete}';
}

$imagem = (User::canCreate() ) ? FaHtml::iconNovo() : FaHtml::iconBlank();

$this->menu = array(
	array('label'=> $imagem, 'url'=>array('create'), 'linkOptions'=>array('target' => '_blank', 'class' => 'novo')),
	array('label'=>FaHtml::iconSetaClose(), 'url'=>'#', 'linkOptions'=>array('class' => 'search-button')),
	array('label' => FaHtml::iconRefresh(), 'url' => 'javascript:void(0);', 'linkOptions' => array('onclick' => 'reloadFrame();', 'class' => 'refresh-button')),
);
?>

<?php
$dataProvider = $model->search();
?>
<div class="search-form" style="display:<?php echo ($dataProvider->totalItemCount > 0) ? 'none' : 'block'; ?>" >
<?php $this->renderPartial('_search', array(
	'model' => $model,
)); ?>
</div><!-- search-form -->

<?php $this->widget('ext.Utils.widgets.CrmGridView', array(
	'id' => 'admin-grid',
	'dataProvider' => $dataProvider,
	'afterAjaxUpdate'=>'updated',
	'selectableRows'=>1,
	'pager' => Util::getPagerDefaultConfig(),
	'columns' => array(
		'MOD_IDMODULO',
		'MOD_DESCRICAO',
		array(
			'name' => 'MOD_TIPO',
			'value' => '$data->MOD_TIPO == "1" ? "Sistema" : "Comercial"',
			),
		array(
			'name' => 'Valor.VAL_VLRIMPLANTACAO',
			'value' => '($data->Valor) ? Util::verMoeda($data->Valor->VAL_VLRIMPLANTACAO) : "Não informado"',
			),
		array(
			'name' => 'Valor.VAL_VLRMENSAL',
			'value' => '($data->Valor) ? Util::verMoeda($data->Valor->VAL_VLRMENSAL) : "Não informado"',
			),
		array(
			'name' => 'MOD_SITUACAO',
			'value' => '$data->MOD_SITUACAO == "A" ? "Ativo" : "Inativo"',
			),
		array(
			'class' => 'CButtonColumn',
			'template'=>$botoes,
			'viewButtonOptions'=>array('target'=>'_blank'),
			'updateButtonOptions'=>array('target'=>'_blank'),			
			'buttons'=>array(
				'valoresUpdate' => array(
					'label'=>'Atualizar tabela de Valores',
					'url'=>'Yii::app()->createUrl("modulos/valores", array("id"=>$data->MOD_IDVALOR,"modulo" => $data->MOD_IDMODULO))',
					'options' => array('target' => '_blank'),
					'imageUrl' => FaHtml::getImgUrl('ico-dinheiro.png'),
					'visible' => '$data->Valor'
				),
				'valoresAdd' => array(
					'label'=>'Cadastrar tabela de Valores',
					'url'=>'Yii::app()->createUrl("modulos/valores", array("modulo" => $data->MOD_IDMODULO))',
					'options' => array('target' => '_blank'),
					'imageUrl' => FaHtml::getImgUrl('ico-dinheiro-add.png'),
					'visible' => '!$data->Valor'
				),
				'view' => array(
					'label'=>'Exibir',
					'url'=>'Yii::app()->createUrl("modulos/view", array("id"=>$data->MOD_IDMODULO))',
				),
				'update' => array(
					'label'=>'Editar',
					'url'=>'Yii::app()->createUrl("modulos/update", array("id"=>$data->MOD_IDMODULO))',
				),
				'delete' => array(
					'label'=>'Excluir',
					'url'=>'Yii::app()->createUrl("modulos/delete", array("id"=>$data->MOD_IDMODULO))',
				),
			),			
		),
	),
));