BUGFIX get TreeMultiselectField working with an array of items, rather than a relation.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@100525 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Tom Rix 2010-03-04 22:51:44 +00:00 committed by Sam Minnee
parent 138e8c5df4
commit 908d3ebbe9
2 changed files with 21 additions and 21 deletions

View File

@ -28,12 +28,21 @@ class TreeMultiselectField extends TreeDropdownField {
return $items;
// Otherwise, look data up from the linked relation
} if($this->value != 'unchanged' && is_string($this->value)) {
$items = new DataObjectSet();
$ids = explode(',', $this->value);
foreach($ids as $id) {
if(!is_numeric($id)) continue;
$item = DataObject::get_by_id($this->sourceObject, $id);
if($item) $items->push($item);
}
return $items;
} else if($this->form) {
$fieldName = $this->name;
$record = $this->form->getRecord();
if(is_object($record) && $record->hasMethod($fieldName))
return $record->$fieldName();
}
}
}
/**
* We overwrite the field attribute to add our hidden fields, as this
@ -55,25 +64,15 @@ class TreeMultiselectField extends TreeDropdownField {
Requirements::css(SAPPHIRE_DIR . '/javascript/tree/tree.css');
Requirements::css(SAPPHIRE_DIR . '/css/TreeDropdownField.css');
// Any field values have priority over the relation getters
if($this->value) {
$items = new DataObjectSet();
$ids = explode(',', $this->value);
foreach($ids as $id) {
if(!is_numeric($id)) continue;
$item = DataObject::get_by_id($this->sourceObject, $id);
if($item) $items->push($item);
}
} else {
$items = $this->getItems();
}
if($items && $items->Count()) {
foreach($items as $item) {
$titleArray[] =$item->Title;
$items = $this->getItems();
if($items && count($items)) {
foreach($items as $id => $item) {
$titleArray[] = $item->Title;
$idArray[] = $item->ID;
}
if(isset($titleArray)) {
$itemList = implode(", ", $titleArray);
$value = implode(",", $idArray);

View File

@ -211,8 +211,6 @@ TreeDropdownField.prototype = {
* Called once the tree has been delivered from ajax
*/
newTreeReady: function (response, keepTreeHidden) {
// alert('newTreeReady');
this.itemTree.innerHTML = response.responseText;
// HACK IE6: see http://www.hedgerwow.com/360/bugs/css-select-free.html
this.itemTree.appendChild(document.createElement('iframe'));
@ -377,10 +375,13 @@ TreeMultiselectField.prototype = {
var selectedItems = this.inputTag.value.split(/ *, */);
var i, isSelected = {};
for(i=0;i<selectedItems.length;i++) isSelected[selectedItems[i]] = true;
var allNodes = this.tree.getElementsByTagName('li');
for(i=0;i<allNodes.length;i++) {
if(isSelected[allNodes[i].getIdx()]) {
allNodes[i].id.match(/([^-]+)-(\d+)$/);
var idx = RegExp.$2
if(isSelected[idx]) {
this.tree.selectNode(allNodes[i]);
allNodes[i].expose();
}