*/ class saWidgetFrormRegionChoice extends sfWidgetFormDoctrineChoice { const SRC = '/widgets/saWidgetFormRegionChoice/'; const MAP_HEIGHT = 197; const MAP_WIDTH = 312; /** * @see sfWidget */ public function __construct($options = array(), $attributes = array()) { if(!isset($options['model'])) { $options['model'] = 'Region'; } parent::__construct($options, $attributes); } public function getStylesheets() { $styles = parent::getStylesheets(); $styles[self::SRC.'map.css'] = 'screen'; return $styles; } public function render($name, $value = null, $attributes = array(), $errors = array()) { $choices = '
'.parent::render($name, $value, $attributes, $errors).'
'; if($this->getOption('multiple') == false) { return $choices; } $regions = Doctrine::getTable($this->getOption('model'))->findAll(); $imagesPath = self::SRC.'maps/middle/'; $layer_id = $this->generateId($name).'_layer-'; $area_id = $this->generateId($name).'_area-'; $title_id = $this->generateId($name).'_title-'; $input_id = $this->generateId($name).'_'; $map = '
'; $map .= 'region_all'; foreach($regions as $i => $region) { $map .= ''.$region->getName().''; $map .= ''.$region->getName().''; } $map .= ''; foreach($regions as $region) { $map .= ''.$region->getName().''; } $map .= ''; $map .= '
'; $script = << $(function(){ $(".layer").hide(); $(".area").click(function(){ tmp = this.id.split("-"); id = tmp[tmp.length - 1]; if($("#{$input_id}"+id).attr("checked")) { $("#{$input_id}"+id).attr("checked", false); $("#{$layer_id}"+id).hide(); } else { $("#{$input_id}"+id).attr("checked", true); $("#{$layer_id}"+id).show(); } return false; }); $(".regionChoices input").click(function(){ regionListInputListener(this); }); $(".regionChoices input").each(function(){ regionListInputListener(this); }); function regionListInputListener(input) { tmp = input.id.split("_"); id = tmp[tmp.length - 1]; if($(input).attr("checked")) { $("#{$layer_id}"+id).show(); } else { $("#{$layer_id}"+id).hide(); } } $(".area").mouseover(function(){ tmp = this.id.split("-"); id = tmp[tmp.length - 1]; $(".regionMap span").hide(); $("#{$title_id}"+id).show(); }); $(".area").mouseout(function(){ $(".regionMap span").hide(); }); }); EOF; return $map.$script.$choices; } }