<?php
class sfWidgetFormInputAjaxDelete extends sfWidgetFormInput {
protected function configure($options = array(), $attributes = array()) {
$this->addRequiredOption(\'url\');
$this->addRequiredOption(\'model_id\');
$this->addRequiredOption(\'update\');
$this->addOption(\'confirm\', null);
$this->addOption(\'icon\', null);
$this->addOption(\'selector\', \'#\');
parent::configure($options, $attributes);
}
public function render($name, $value = null, $attributes = array(), $errors = array()) {
sfLoader::loadHelpers(\'ysJQueryRevolutions\');
$ctx = sfContext::getInstance();
$request = $ctx->getRequest();
$controller = $ctx->getController();
if (is_null($this->getOption(\'confirm\'))) {
$this->setOption(\'confirm\', __(\'Are you sure you want to delete this item?\'));
}
if (is_null($this->getOption(\'icon\'))) {
$this->setOption(\'icon\', sprintf(\'http://%s%s/sfPropelPlugin/images/delete.png\', $request->getHost(), $request->getRelativeUrlRoot()));
} else {
$this->setOption(\'icon\', sprintf(\'http://%s%s/images/%s\', $request->getHost(), $request->getRelativeUrlRoot(), $this->getOption(\'icon\')));
}
$html = parent::render($name, $value, $attributes, $errors);
$img = $this->renderTag(\'img\',
array(\'src\' => $this->getOption(\'icon\'),
\'id\' => \'img_\'.$this->getOption(\'update\')
)
);
$link = jquery_load(
$this->getOption(\'selector\').$this->getOption(\'update\'),
array(
\'listener\' => array(
\'selector\' => \'#img_\'.$this->getOption(\'update\'),
\'event\' => \'click\'),
\'url\' => $controller->genUrl($this->getOption(\'url\')).\'?id=\'.$this->getOption(\'model_id\'),
)
);
$html .= $img.$link;
return $html;
}
}