Skip to content

Commit

Permalink
MINOR added stubs to allow widgets to use treedropdown fields (from r…
Browse files Browse the repository at this point in the history
…91850)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@92456 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu committed Nov 21, 2009
1 parent a21927e commit 1d3feb9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
18 changes: 12 additions & 6 deletions javascript/TreeSelectorField.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ TreeDropdownField.prototype = {
}
},

getName: function() {
return this.inputTag.name;
},

refresh: function() {
this.createTreeNode();

Expand All @@ -45,7 +49,7 @@ TreeDropdownField.prototype = {
},

helperURLBase: function() {
return this.ownerForm().action + '/field/' + this.inputTag.name + '/';
return this.ownerForm().action + '/field/' + this.getName() + '/';
},
ownerForm: function() {
var f =this.parentNode;
Expand Down Expand Up @@ -166,7 +170,7 @@ TreeDropdownField.prototype = {
getIdx: function() {
return this.getElementsByTagName('a')[0].getAttribute('rel');
},
idxBase : 'selector-' + this.inputTag.name + '-',
idxBase : 'selector-' + this.getName() + '-',
dropdownField : this,
onselect : this.tree_click
});
Expand Down Expand Up @@ -200,12 +204,14 @@ TreeDropdownField.prototype = {
},

setValue: function(val) {
this.inputTag = this.getElementsByTagName('input')[0];

if(this.inputTag.value != val) {
this.inputTag.value = val;
this.notify('Change', val);

// If the tree item is already downloaded, just update the label
if($('selector-' + this.inputTag.name + '-' + this.inputTag.value)) {
if($('selector-' + this.getName() + '-' + this.inputTag.value)) {
this.updateTreeLabel();

// Otherwise, update the tree with ajax
Expand All @@ -220,7 +226,7 @@ TreeDropdownField.prototype = {
},
updateTreeLabel: function() {
var treeNode;
if(treeNode = $('selector-' + this.inputTag.name + '-' + this.inputTag.value)) {
if(treeNode = $('selector-' + this.getName() + '-' + this.inputTag.value)) {
this.humanItems.innerHTML = treeNode.getTitle();

if(treeNode.tree.selected && treeNode.tree.selected.removeNodeClass) treeNode.tree.selected.removeNodeClass('current');
Expand All @@ -233,7 +239,7 @@ TreeDropdownField.prototype = {
},
setValueFromTree: function(treeID, title) {
this.humanItems.innerHTML = title;
this.inputTag.value = treeID.replace('selector-' + this.inputTag.name + '-','');
this.inputTag.value = treeID.replace('selector-' + this.getName() + '-','');
this.notify('Change', this.inputTag.value);

this.hideTree();
Expand Down Expand Up @@ -305,7 +311,7 @@ TreeMultiselectField.prototype = {
var innerHTML = '';
var selectedItems = this.inputTag.value.split(/ *, */);
for(i=0;i<selectedItems.length;i++) {
if(treeNode = $('selector-' + this.inputTag.name + '-' + selectedItems[i])) {
if(treeNode = $('selector-' + this.getName() + '-' + selectedItems[i])) {
innerHTML += (innerHTML?', ':'') + treeNode.getTitle();
} else {
innerHTML += selectedItems[i];
Expand Down
9 changes: 7 additions & 2 deletions widgets/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,12 @@ function editablesegment() {
user_error("Bad widget class: $className", E_USER_WARNING);
return "Bad widget class name given";
}
}

}
}

class Widget_TreeDropdownField extends TreeDropdownField {
function FieldHolder() {}
function Field() {}
}

?>
13 changes: 11 additions & 2 deletions widgets/WidgetArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class WidgetArea extends DataObject {
*/
function WidgetControllers() {
$controllers = new DataObjectSet();
foreach($this->Widgets() as $widget) {
// var_dump($this->Items());
foreach($this->ItemsToRender() as $widget) {
// find controller
$controllerClass = '';
foreach(array_reverse(ClassInfo::ancestry($widget->class)) as $widgetClass) {
Expand All @@ -39,10 +40,18 @@ function WidgetControllers() {
$controller->init();
$controllers->push($controller);
}

return $controllers;
}

function Items() {
return $this->Widgets();
}

function ItemsToRender() {
return $this->Items();
}

function forTemplate() {
return $this->renderWith($this->class);
}
Expand Down

0 comments on commit 1d3feb9

Please sign in to comment.