2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-01-09 05:18:36 +01:00
|
|
|
/**
|
|
|
|
* @deprecated Use {@link TreeDropdownField} or {@link TreeMultiselectField}
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-relational
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class TreeSelectorField extends FormField {
|
|
|
|
protected $sourceObject;
|
|
|
|
|
|
|
|
function __construct($name, $title, $sourceObject = "Group") {
|
|
|
|
$this->sourceObject = $sourceObject;
|
|
|
|
parent::__construct($name, $title);
|
|
|
|
}
|
|
|
|
|
|
|
|
function Field() {
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
Requirements::javascript(SAPPHIRE_DIR . "/javascript/TreeSelectorField.js");
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
$fieldName = $this->name;
|
|
|
|
if($this->form) {
|
|
|
|
$record = $this->form->getRecord();
|
|
|
|
if($record && $record->hasMethod($fieldName)) $items = $record->$fieldName();
|
|
|
|
}
|
|
|
|
if($items) {
|
|
|
|
foreach($items as $item) {
|
|
|
|
$titleArray[] =$item->Title;
|
|
|
|
$idArray[] = $item->ID;
|
|
|
|
}
|
|
|
|
if($titleArray) {
|
|
|
|
$itemList = implode(", ", $titleArray);
|
|
|
|
$value = implode(",", $idArray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = $this->id();
|
|
|
|
|
|
|
|
return <<<HTML
|
|
|
|
<div class="TreeSelectorField">
|
|
|
|
<input type="hidden" name="$this->name" value="$value" />
|
|
|
|
<input type="button" class="edit" value="edit" />
|
|
|
|
<span class="items">$itemList</span>
|
|
|
|
</div>
|
|
|
|
HTML;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the results into the form
|
|
|
|
*/
|
|
|
|
function saveInto(DataObject $record) {
|
|
|
|
$fieldName = $this->name;
|
|
|
|
$saveDest = $record->$fieldName();
|
|
|
|
|
|
|
|
if($this->value) {
|
|
|
|
$items = split(" *, *", trim($this->value));
|
|
|
|
}
|
|
|
|
|
|
|
|
$saveDest->setByIDList($items);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the site tree
|
|
|
|
*/
|
|
|
|
function gettree() {
|
|
|
|
echo "<div class=\"actions\">
|
2008-01-10 04:28:13 +01:00
|
|
|
<input type=\"button\" name=\"save\" value=\""._t('TreeSelectorField.SAVE', 'save')."\" />
|
|
|
|
<input type=\"button\" name=\"cancel\" value=\""._t('TreeSelectorField.CANCEL', 'cancel')."\" />
|
2007-07-19 12:40:28 +02:00
|
|
|
</div>";
|
|
|
|
|
|
|
|
|
|
|
|
$obj = singleton($this->sourceObject);
|
|
|
|
$obj->markPartialTree(10);
|
|
|
|
|
|
|
|
$eval = '"<li id=\"selector-' . $this->name . '-$child->ID\" class=\"$child->class closed" . ($child->isExpanded() ? "" : " unexpanded") . "\"><a>" . $child->Title . "</a>"';
|
|
|
|
echo $obj->getChildrenAsUL("class=\"tree\"", $eval, null, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|