1: <?php
  2: 
  3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21: 
 22: 
 23: namespace picon;
 24: 
 25:  26:  27:  28:  29:  30:  31:  32:  33:  34: 
 35: class DefaultJQueryUIBehaviour extends AbstractJQueryUIBehaviour
 36: {
 37:     private $function;
 38:     private $options;
 39:     
 40:     public function __construct($function, $options = null)
 41:     {
 42:         parent::__construct();
 43:         $this->function = $function;
 44:         
 45:         if($options!=null)
 46:         {
 47:             if($options instanceof Options)
 48:             {
 49:                 $this->options = $options;
 50:             }
 51:             else
 52:             {
 53:                 throw new \InvalidArgumentException('DefaultJQueryUIBehaviour::__construct expected argument 2 to be an an Options object');
 54:             }
 55:         }
 56:         else
 57:         {
 58:             $this->options = new Options();
 59:         }
 60:     }
 61:     
 62:     public function getOptions()
 63:     {
 64:         return $this->options;
 65:     }
 66:     
 67:     public function setOptions(Options $options)
 68:     {
 69:         $this->options = $options;
 70:     }
 71:     
 72:     public function bind(Component &$component)
 73:     {
 74:         parent::bind($component);
 75:         $component->setOutputMarkupId(true);
 76:     }
 77:     
 78:     public function renderHead(Component &$component, HeaderContainer $headerContainer, HeaderResponse $headerResponse)
 79:     {
 80:         parent::renderHead($component, $headerContainer, $headerResponse);
 81:         $headerResponse->renderScript(sprintf("\$(document).ready(function(){\$('#%s').%s(%s);});", $this->getComponent()->getMarkupId(), $this->function, $this->getOptions()->render($this)));
 82:     }
 83:     
 84:     public function onEvent()
 85:     {
 86:         $property = RequestCycle::get()->getRequest()->getParameter('property');
 87:         
 88:         if($property!=null)
 89:         {
 90:             $callbackOption = $this->getOptions()->getOption($property);
 91:             
 92:             if($callbackOption!=null && $callbackOption instanceof AbstractCallableOption)
 93:             {
 94:                 $target = new AjaxRequestTarget();
 95:                 $this->getComponent()->getRequestCycle()->addTarget($target);
 96:                 $callbackOption->call($target);
 97:             }
 98:         }
 99:     }
100: }
101: 
102: ?>
103: