document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2.  
  3. class sfWidgetFormInputAjaxDelete extends sfWidgetFormInput {
  4.  
  5.     protected function configure($options = array(), $attributes = array()) {
  6.         $this->addRequiredOption(\'url\');
  7.         $this->addRequiredOption(\'model_id\');
  8.         $this->addRequiredOption(\'update\');
  9.         $this->addOption(\'confirm\', null);
  10.         $this->addOption(\'icon\', null);
  11.         $this->addOption(\'selector\', \'#\');
  12.         parent::configure($options, $attributes);
  13.     }
  14.  
  15.     public function render($name, $value = null, $attributes = array(), $errors = array()) {
  16.         sfLoader::loadHelpers(\'ysJQueryRevolutions\');
  17.  
  18.         $ctx = sfContext::getInstance();
  19.         $request = $ctx->getRequest();
  20.         $controller = $ctx->getController();
  21.  
  22.         if (is_null($this->getOption(\'confirm\'))) {
  23.             $this->setOption(\'confirm\', __(\'Are you sure you want to delete this item?\'));
  24.         }
  25.  
  26.         if (is_null($this->getOption(\'icon\'))) {
  27.             $this->setOption(\'icon\', sprintf(\'http://%s%s/sfPropelPlugin/images/delete.png\', $request->getHost(), $request->getRelativeUrlRoot()));
  28.         } else {
  29.             $this->setOption(\'icon\', sprintf(\'http://%s%s/images/%s\', $request->getHost(), $request->getRelativeUrlRoot(), $this->getOption(\'icon\')));
  30.         }
  31.  
  32.         $html = parent::render($name, $value, $attributes, $errors);
  33.  
  34.         $img = $this->renderTag(\'img\',
  35.                 array(\'src\' => $this->getOption(\'icon\'),
  36.                 \'id\' => \'img_\'.$this->getOption(\'update\')
  37.                 )
  38.         );
  39.  
  40.         $link = jquery_load(
  41.                 $this->getOption(\'selector\').$this->getOption(\'update\'),
  42.                 array(
  43.                 \'listener\' => array(
  44.                         \'selector\' => \'#img_\'.$this->getOption(\'update\'),
  45.                         \'event\'    => \'click\'),
  46.                 \'url\' => $controller->genUrl($this->getOption(\'url\')).\'?id=\'.$this->getOption(\'model_id\'),
  47.                 )
  48.         );
  49.  
  50.         $html .= $img.$link;
  51.         return $html;
  52.  
  53.     }
  54.  
  55. }
');