| 1 |
<?php |
| 2 |
class Element_Checksort extends Element_Sort { |
| 3 |
protected $attributes = array("type" => "checkbox"); |
| 4 |
protected $inline; |
| 5 |
protected $maxheight; |
| 6 |
|
| 7 |
public function jQueryDocumentReady() { |
| 8 |
parent::jQueryDocumentReady(); |
| 9 |
if(!empty($this->inline)) |
| 10 |
echo 'jQuery("#', $this->attributes["id"], ' .pfbc-checkbox:last").css("margin-right", "0");'; |
| 11 |
else |
| 12 |
echo 'jQuery("#', $this->attributes["id"], ' .pfbc-checkbox:last").css({ "padding-bottom": "0", "border-bottom": "none" });'; |
| 13 |
|
| 14 |
if(!empty($this->maxheight) && is_numeric($this->maxheight)) { |
| 15 |
echo <<<JS |
| 16 |
var checkboxes = jQuery("#{$this->attributes["id"]} .pfbc-checkboxes"); |
| 17 |
if(checkboxes.outerHeight() > {$this->maxheight}) { |
| 18 |
checkboxes.css({ |
| 19 |
"height": "{$this->maxheight}px", |
| 20 |
"overflow": "auto", |
| 21 |
"overflow-x": "hidden" |
| 22 |
}); |
| 23 |
} |
| 24 |
JS; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
public function render() { |
| 29 |
if(isset($this->attributes["value"])) { |
| 30 |
if(!is_array($this->attributes["value"])) |
| 31 |
$this->attributes["value"] = array($this->attributes["value"]); |
| 32 |
} |
| 33 |
else |
| 34 |
$this->attributes["value"] = array(); |
| 35 |
|
| 36 |
if(substr($this->attributes["name"], -2) != "[]") |
| 37 |
$this->attributes["name"] .= "[]"; |
| 38 |
|
| 39 |
$count = 0; |
| 40 |
$existing = ""; |
| 41 |
echo '<div id="', $this->attributes["id"], '"><div class="pfbc-checkboxes">'; |
| 42 |
foreach($this->options as $value => $text) { |
| 43 |
$value = $this->getOptionValue($value); |
| 44 |
echo '<div class="pfbc-checkbox"><table cellpadding="0" cellspacing="0"><tr><td valign="top"><input id="', $this->attributes["id"], "-", $count, '"', $this->getAttributes(array("id", "value", "checked", "name", "onclick")), ' value="', $this->filter($value), '"'; |
| 45 |
if(in_array($value, $this->attributes["value"])) |
| 46 |
echo ' checked="checked"'; |
| 47 |
echo ' onclick="updateChecksort(this, \'', $this->filter($text), '\');"/></td><td><label for="', $this->attributes["id"], "-", $count, '">', $text, '</label></td></tr></table></div>'; |
| 48 |
|
| 49 |
if(in_array($value, $this->attributes["value"])) |
| 50 |
$existing .= '<li id="' . $this->attributes["id"] . "-sort-" . $count . '" class="ui-state-default"><input type="hidden" name="' . $this->attributes["name"] . '" value="' . $value . '"/>' . $text . '</li>'; |
| 51 |
|
| 52 |
++$count; |
| 53 |
} |
| 54 |
echo '</div>'; |
| 55 |
|
| 56 |
if(!empty($this->inline)) |
| 57 |
echo '<div style="clear: both;"></div>'; |
| 58 |
|
| 59 |
echo '<ul>', $existing, '</ul></div>'; |
| 60 |
} |
| 61 |
|
| 62 |
function renderJS() { |
| 63 |
echo <<<JS |
| 64 |
if(typeof updateChecksort != "function") { |
| 65 |
function updateChecksort(element, text) { |
| 66 |
var position = element.id.lastIndexOf("-"); |
| 67 |
var id = element.id.substr(0, position); |
| 68 |
var index = element.id.substr(position + 1); |
| 69 |
if(element.checked) |
| 70 |
jQuery("#" + id + " ul").append('<li id="' + id + '-sort-' + index + '" class="ui-state-default"><input type="hidden" name="{$this->attributes["name"]}" value="' + element.value + '"/>' + text + '</li>'); |
| 71 |
else |
| 72 |
jQuery("#" + id + "-sort-" + index).remove(); |
| 73 |
} |
| 74 |
} |
| 75 |
JS; |
| 76 |
} |
| 77 |
|
| 78 |
function renderCSS() { |
| 79 |
if(!empty($this->inline)) |
| 80 |
echo '#', $this->attributes["id"], ' .pfbc-checkbox { float: left; margin-right: 0.5em; }'; |
| 81 |
else |
| 82 |
echo '#', $this->attributes["id"], ' .pfbc-checkbox { padding: 0.5em 0; border-bottom: 1px solid #f4f4f4; }'; |
| 83 |
parent::renderCSS(); |
| 84 |
} |
| 85 |
} |
| 86 |
|