<?php
Yii::import('zii.widgets.grid.CButtonColumn');

class DemandsColumn extends CButtonColumn
{
    public $header;

    public $buttons = array(
        'cancel' => array(
            'label' => '取消',
            'url' => 'Yii::app()->controller->createUrl("/admin/demands/cancel",array("id"=>$data->id))',
            'type' => 'raw',
    		'visible' => '$data->status == 0',
        ),
        'complete' => array(
            'label' => '上架',
            'url' => 'Yii::app()->controller->createUrl("/admin/demands/complete",array("id"=>$data->id))',
            'type' => 'raw',
            'visible' => '$data->status == 0',
        ),
    );
    
    protected function initDefaultButtons()
    {
        $confirmation="if(!confirm(".CJavaScript::encode(Yii::t('zii','确定要取消?')).")) return false;";
        $this->buttons['cancel']['click']=<<<EOD
function() {
	$confirmation
	$.fn.yiiGridView.update('{$this->grid->id}', {
		type:'POST',
		url:$(this).attr('href'),
		success:function() {
			$.fn.yiiGridView.update('{$this->grid->id}');
		}
	});
	return false;
}
EOD;

        $confirmation="if(!confirm(".CJavaScript::encode(Yii::t('zii','确定要上架?')).")) return false;";
        $this->buttons['complete']['click']=<<<EOD
function() {
	$confirmation
	$.fn.yiiGridView.update('{$this->grid->id}', {
		type:'POST',
		url:$(this).attr('href'),
		success:function() {
			$.fn.yiiGridView.update('{$this->grid->id}');
		}
	});
	return false;
}
EOD;
    }
}