mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX get TreeMultiselectField working with an array of items, rather than a relation. (from r100525)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@105594 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
81d26a26c0
commit
4e87fb5713
@ -29,12 +29,21 @@ class TreeMultiselectField extends TreeDropdownField {
|
|||||||
return $items;
|
return $items;
|
||||||
|
|
||||||
// Otherwise, look data up from the linked relation
|
// 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) {
|
} else if($this->form) {
|
||||||
$fieldName = $this->name;
|
$fieldName = $this->name;
|
||||||
$record = $this->form->getRecord();
|
$record = $this->form->getRecord();
|
||||||
if(is_object($record) && $record->hasMethod($fieldName))
|
if(is_object($record) && $record->hasMethod($fieldName))
|
||||||
return $record->$fieldName();
|
return $record->$fieldName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* We overwrite the field attribute to add our hidden fields, as this
|
* We overwrite the field attribute to add our hidden fields, as this
|
||||||
@ -54,25 +63,15 @@ class TreeMultiselectField extends TreeDropdownField {
|
|||||||
Requirements::javascript(SAPPHIRE_DIR . '/javascript/LeftAndMain.js');
|
Requirements::javascript(SAPPHIRE_DIR . '/javascript/LeftAndMain.js');
|
||||||
Requirements::javascript(SAPPHIRE_DIR . "/javascript/TreeSelectorField.js");
|
Requirements::javascript(SAPPHIRE_DIR . "/javascript/TreeSelectorField.js");
|
||||||
|
|
||||||
// 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()) {
|
$items = $this->getItems();
|
||||||
foreach($items as $item) {
|
|
||||||
$titleArray[] =$item->Title;
|
if($items && count($items)) {
|
||||||
|
foreach($items as $id => $item) {
|
||||||
|
$titleArray[] = $item->Title;
|
||||||
$idArray[] = $item->ID;
|
$idArray[] = $item->ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($titleArray)) {
|
if(isset($titleArray)) {
|
||||||
$itemList = implode(", ", $titleArray);
|
$itemList = implode(", ", $titleArray);
|
||||||
$value = implode(",", $idArray);
|
$value = implode(",", $idArray);
|
||||||
|
@ -209,8 +209,6 @@ TreeDropdownField.prototype = {
|
|||||||
* Called once the tree has been delivered from ajax
|
* Called once the tree has been delivered from ajax
|
||||||
*/
|
*/
|
||||||
newTreeReady: function (response, keepTreeHidden) {
|
newTreeReady: function (response, keepTreeHidden) {
|
||||||
// alert('newTreeReady');
|
|
||||||
|
|
||||||
this.itemTree.innerHTML = response.responseText;
|
this.itemTree.innerHTML = response.responseText;
|
||||||
// HACK IE6: see http://www.hedgerwow.com/360/bugs/css-select-free.html
|
// HACK IE6: see http://www.hedgerwow.com/360/bugs/css-select-free.html
|
||||||
this.itemTree.appendChild(document.createElement('iframe'));
|
this.itemTree.appendChild(document.createElement('iframe'));
|
||||||
@ -378,10 +376,13 @@ TreeMultiselectField.prototype = {
|
|||||||
var selectedItems = this.inputTag.value.split(/ *, */);
|
var selectedItems = this.inputTag.value.split(/ *, */);
|
||||||
var i, isSelected = {};
|
var i, isSelected = {};
|
||||||
for(i=0;i<selectedItems.length;i++) isSelected[selectedItems[i]] = true;
|
for(i=0;i<selectedItems.length;i++) isSelected[selectedItems[i]] = true;
|
||||||
|
|
||||||
var allNodes = this.tree.getElementsByTagName('li');
|
var allNodes = this.tree.getElementsByTagName('li');
|
||||||
|
|
||||||
for(i=0;i<allNodes.length;i++) {
|
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]);
|
this.tree.selectNode(allNodes[i]);
|
||||||
allNodes[i].expose();
|
allNodes[i].expose();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user