Skip to content

Commit

Permalink
fix(gridfield): set toggle button to disabled if no childre
Browse files Browse the repository at this point in the history
  • Loading branch information
flxqr2 committed Mar 4, 2018
1 parent ed5fadc commit 61ba4d8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
8 changes: 6 additions & 2 deletions code/GridFieldPageSectionsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function getHTMLFragments($field) {
$moduleDir = self::getModuleDir();
Requirements::css($moduleDir . "/css/GridFieldPageSectionsExtension.css");
Requirements::javascript($moduleDir . "/javascript/GridFieldPageSectionsExtension.js");
Requirements::add_i18n_javascript($moduleDir . '/javascript/lang', false, true);

$id = rand(1000000, 9999999);
$field->addExtraClass("ss-gridfield-pagesections");
Expand Down Expand Up @@ -87,8 +88,7 @@ public function augmentColumns($gridField, &$columns) {
$newList = $gridField->getManipulatedList();
while (count($list) < count($newList)) {
foreach ($newList as $item) {
//var_dump($item->Children());die;
if ($item->isOpenByDefault() && $item->Children()->Count) {
if ($item->isOpenByDefault() && $item->Children()->Count()) {
$this->openElement($state, $item);
}
}
Expand Down Expand Up @@ -185,6 +185,10 @@ public function getColumnContent($gridField, $record, $columnName) {
array("element" => $record)
);
$field->addExtraClass("level".$level . ($open ? " is-open" : " is-closed"));
if (!$record->Children()->Count()) {
$field->addExtraClass(" is-end");
$field->setDisabled(true);
}
$field->setButtonContent($icon);
$field->setForm($gridField->getForm());

Expand Down
14 changes: 14 additions & 0 deletions css/GridFieldPageSectionsExtension.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@
position: relative;
}

.cms table.ss-gridfield-table tbody td.col-treenav button.ui-state-disabled {
opacity: 1;
filter: Alpha(Opacity=100);
background-image: none;
background: none;
box-shadow: none;
}

.cms table.ss-gridfield-table tbody td.col-treenav button.ui-state-disabled:active {
border: none;
background: none;
box-shadow: none;
}

.cms table.ss-gridfield-table tbody td.col-treenav button svg {
position: absolute;
left: 50%;
Expand Down
4 changes: 2 additions & 2 deletions javascript/GridFieldPageSectionsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}
if ($parent != null) {
parentId = $parent.data("id");
parentName = $parent.find(".col-treenav > span").html();
parentName = $parent.find(".col-treenav .col-treenav__title").html();
}
}

Expand All @@ -86,7 +86,7 @@
rowId: rowId,
parentId: parentId,
});
$menu.append("<li class='header'>Add a child</li>");
$menu.append("<li class='header'>" + ss.i18n._t('PageSections.GridField.AddAChild','Add a child') + "</li>");
$.each(elems, function(key, value) {
$menu.append("<li data-type='" + key + "'>" + value + "</li>");
});
Expand Down
9 changes: 9 additions & 0 deletions javascript/lang/de.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if (typeof(ss) === 'undefined' || typeof(ss.i18n) === 'undefined') {
if (typeof(console) !== 'undefined') { // eslint-disable-line no-console
console.error('Class ss.i18n not defined'); // eslint-disable-line no-console
}
} else {
ss.i18n.addDictionary('en', {
"GridField.AddAChild": "Unterelement hinzufügen",
});
}
9 changes: 9 additions & 0 deletions javascript/lang/en.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if (typeof(ss) === 'undefined' || typeof(ss.i18n) === 'undefined') {
if (typeof(console) !== 'undefined') { // eslint-disable-line no-console
console.error('Class ss.i18n not defined'); // eslint-disable-line no-console
}
} else {
ss.i18n.addDictionary('en', {
"PageSections.GridField.AddAChild": "Add a child",
});
}

0 comments on commit 61ba4d8

Please sign in to comment.