Permalink
Browse files

FEATURE: Disable specific tree nodes in TreeDropdownField

DO NOT MERGE: to be reviewed.

This feature request was born out of wanting the ability to disable (for example) a top level page from being selected, while still being able to select a child page. Using setFilterFunction() simply removes the node and its children.

Extra styling for disabled nodes

Disable ability to select a disabled node for TreeDropdownField

Disable hover CSS changes

Fixing merge conflict during rebase

Return a boolean for nodeIsDisabled()
  • Loading branch information...
kinglozzer committed May 30, 2013
1 parent 92e98f0 commit 6b3b61873a3d514f073b970cedea014de454abd2
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -32,6 +32,10 @@
}
&.disabled > a {
color: #aaaaaa;
+ &:hover {
+ background: transparent;
+ cursor: default;
+ }
}
&.edit-disabled > a {
color: #aaaaaa;
@@ -438,7 +442,12 @@
> a, > a:link{
background-color: $color-cms-batchactions-menu-selected-background;
}
- }
+ }
+ &.disabled {
+ > a > .jstree-checkbox {
+ background-position: -57px -54px;
+ }
+ }
&.readonly {
color: $color-text-disabled;
padding-left: 18px;
@@ -53,7 +53,8 @@ class TreeDropdownField extends FormField {
/**
* @ignore
*/
- protected $sourceObject, $keyField, $labelField, $filterCallback, $searchCallback, $baseID = 0;
+ protected $sourceObject, $keyField, $labelField, $filterCallback,
+ $disableCallback, $searchCallback, $baseID = 0;
/**
* @var string default child method in Hierarcy->getChildrenAsUL
*/
@@ -122,6 +123,20 @@ public function setFilterFunction($callback) {
$this->filterCallback = $callback;
return $this;
}
+
+ /**
+ * Set a callback used to disable checkboxes for some items in the tree
+ *
+ * @param callback $callback
+ */
+ public function setDisableFunction($callback) {
+ if(!is_callable($callback, true)) {
+ throw new InvalidArgumentException('TreeDropdownField->setDisableFunction(): not passed a valid callback');
+ }
+
+ $this->disableCallback = $callback;
+ return $this;
+ }
/**
* Set a callback used to search the hierarchy globally, even before
@@ -181,11 +196,11 @@ public function Field($properties = array()) {
if($record) {
$title = $record->{$this->labelField};
} else {
- if($this->showSearch){
+ if($this->showSearch) {
$title = _t('DropdownField.CHOOSESEARCH', '(Choose or Search)', 'start value of a dropdown');
- }else{
- $title = _t('DropdownField.CHOOSE', '(Choose)', 'start value of a dropdown');
- }
+ } else {
+ $title = _t('DropdownField.CHOOSE', '(Choose)', 'start value of a dropdown');
+ }
}
// TODO Implement for TreeMultiSelectField
@@ -276,12 +291,13 @@ public function tree(SS_HTTPRequest $request) {
$keyField = $self->keyField;
$labelField = $self->labelField;
return sprintf(
- '<li id="selector-%s-%s" data-id="%s" class="class-%s %s"><a rel="%d">%s</a>',
+ '<li id="selector-%s-%s" data-id="%s" class="class-%s %s %s"><a rel="%d">%s</a>',
Convert::raw2xml($self->getName()),
Convert::raw2xml($child->$keyField),
Convert::raw2xml($child->$keyField),
Convert::raw2xml($child->class),
Convert::raw2xml($child->markingClasses()),
+ ($self->nodeIsDisabled($child)) ? 'disabled' : '',
(int)$child->ID,
$escapeLabelField ? Convert::raw2xml($child->$labelField) : $child->$labelField
);
@@ -351,6 +367,15 @@ public function filterMarking($node) {
return true;
}
+ /**
+ * Marking a specific node in the tree as disabled
+ * @param $node
+ * @return boolean
+ */
+ public function nodeIsDisabled($node) {
+ return ($this->disableCallback && call_user_func($this->disableCallback, $node));
+ }
+
/**
* @param String $field
*/
@@ -228,7 +228,25 @@
'themes': {
'theme': 'apple'
},
- 'plugins': ['html_data', 'ui', 'themes']
+ 'types' : {
+ 'types' : {
+ 'default': {
+ 'check_node': function(node) {
+ return ( ! node.hasClass('disabled'));
+ },
+ 'uncheck_node': function(node) {
+ return ( ! node.hasClass('disabled'));
+ },
+ 'select_node': function(node) {
+ return ( ! node.hasClass('disabled'));
+ },
+ 'deselect_node': function(node) {
+ return ( ! node.hasClass('disabled'));
+ }
+ }
+ }
+ },
+ 'plugins': ['html_data', 'ui', 'themes', 'types']
};
},
/**

0 comments on commit 6b3b618

Please sign in to comment.