From bd7ae8282d56132c6d75f5ceec54cb0b8b78ea85 Mon Sep 17 00:00:00 2001 From: Tom Rix Date: Tue, 17 Nov 2009 00:16:29 +0000 Subject: [PATCH] MINOR added stubs to allow widgets to use treedropdown fields git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@91850 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- javascript/TreeSelectorField.js | 18 ++++++++++++------ widgets/Widget.php | 9 +++++++-- widgets/WidgetArea.php | 13 +++++++++++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/javascript/TreeSelectorField.js b/javascript/TreeSelectorField.js index a16bf2a1c..8623d5bd0 100755 --- a/javascript/TreeSelectorField.js +++ b/javascript/TreeSelectorField.js @@ -35,6 +35,10 @@ TreeDropdownField.prototype = { } }, + getName: function() { + return this.inputTag.name; + }, + refresh: function() { this.createTreeNode(); @@ -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; @@ -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 }); @@ -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 @@ -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'); @@ -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(); @@ -306,7 +312,7 @@ TreeMultiselectField.prototype = { var innerHTML = ''; var selectedItems = this.inputTag.value.split(/ *, */); for(i=0;i \ No newline at end of file diff --git a/widgets/WidgetArea.php b/widgets/WidgetArea.php index 1b35084d2..8c194f43e 100644 --- a/widgets/WidgetArea.php +++ b/widgets/WidgetArea.php @@ -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) { @@ -39,10 +40,18 @@ class WidgetArea extends DataObject { $controller->init(); $controllers->push($controller); } - + return $controllers; } + function Items() { + return $this->Widgets(); + } + + function ItemsToRender() { + return $this->Items(); + } + function forTemplate() { return $this->renderWith($this->class); }