Skip to content

Commit

Permalink
fix(sortable): fix sorting of elements in a grid from pageElement ins…
Browse files Browse the repository at this point in the history
…tead of a Page
  • Loading branch information
flxqr2 committed Mar 4, 2018
1 parent 61ba4d8 commit 7d100cb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
24 changes: 12 additions & 12 deletions code/GridFieldPageSectionsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class GridFieldPageSectionsExtension implements
);


public function __construct($page, $allowedElementsOnPage = array(), $sortField = "SortOrder") {
public function __construct($page, $allowedParentElements = array(), $sortField = "SortOrder") {
$this->page = $page;
$this->allowedElementsOnPage = $allowedElementsOnPage;
$this->allowedParentElements = $allowedParentElements;
$this->sortField = $sortField;
}

Expand Down Expand Up @@ -130,20 +130,20 @@ public function getColumnAttributes($gridField, $record, $columnName) {
// if element has no parent we need to
// know the allowed elements of the page
if (!$record->_Parent) {
$pageClasses = $this->allowedElementsOnPage;
$pageElems = array();
foreach ($pageClasses as $class) {
$pageElems[$class] = $class::$singular_name;
$parentClasses = $this->allowedParentElements;
$parentElems = array();
foreach ($parentClasses as $class) {
$parentElems[$class] = $class::$singular_name;
}
}

return array(
"class" => "col-treenav",
"data-class" => $record->ClassName,
"data-level" => strval($record->_Level),
"data-parent" => $record->_Parent ? strval($record->_Parent->ID) : "",
"data-allowed-page-elements" => !$record->_Parent ? json_encode($pageElems, JSON_UNESCAPED_UNICODE) : "",
"data-allowed-elements" => json_encode($elems, JSON_UNESCAPED_UNICODE),
"class" => "col-treenav",
"data-class" => $record->ClassName,
"data-level" => strval($record->_Level),
"data-parent" => $record->_Parent ? strval($record->_Parent->ID) : "",
"data-allowed-parent-elements" => !$record->_Parent ? json_encode($parentElems, JSON_UNESCAPED_UNICODE) : "",
"data-allowed-elements" => json_encode($elems, JSON_UNESCAPED_UNICODE),
);
}

Expand Down
2 changes: 1 addition & 1 deletion code/PageElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getChildrenGridField() {
->addComponent($dataColumns = new GridFieldDataColumns())
->addComponent($autoCompl)
->addComponent($addNewButton)
->addComponent(new GridFieldPageSectionsExtension($this->owner))
->addComponent(new GridFieldPageSectionsExtension($this->owner, $this->owner->getAllowedPageElements()))
->addComponent(new GridFieldDetailForm())
->addComponent(new GridFieldFooter());
$dataColumns->setFieldCasting(array('GridFieldPreview' => 'HTMLText->RAW'));
Expand Down
14 changes: 7 additions & 7 deletions javascript/GridFieldPageSectionsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,6 @@
var newParent = type === "child" ? $this.data("id") : $treenav.data("parent");
var sort = type === "child" ? childOrder : $reorder.data("sort");

// we alter the state of the published / saved buttons
$('.cms-edit-form .Actions #Form_EditForm_action_publish').button({
showingAlternate: true
});

grid.reload({
url: grid.data("url-reorder"),
data: [{
Expand All @@ -194,6 +189,12 @@
value: sort,
}],
});
// we alter the state of the published / saved buttons
$('.cms-edit-form .Actions #Form_EditForm_action_publish').button({
showingAlternate: true
});
$('.cms-preview').entwine('.ss.preview').changeState('StageLink');

},
});
});
Expand Down Expand Up @@ -250,8 +251,7 @@
)
)
) {
var allowed = $treenav.data("allowed-page-elements");
console.log(allowed, element, $treenav)
var allowed = $treenav.data("allowed-parent-elements");
if (!allowed[element]) return;
}
// check our allowed children, or the allowed children of our parent row.
Expand Down

0 comments on commit 7d100cb

Please sign in to comment.