Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Structure field: adds sort & flip option, fix #722 #749

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/fields/structure/assets/css/structure.css
Expand Up @@ -80,8 +80,12 @@
overflow: hidden;
width: 100%;
text-overflow: ellipsis;
cursor: move;
}

.structure[data-sortable=true] .structure-table td a {
cursor: move;
}

.structure-table-options {
width: 3rem;
text-align: center;
Expand Down
26 changes: 25 additions & 1 deletion app/fields/structure/structure.php
Expand Up @@ -16,6 +16,8 @@ class StructureField extends BaseField {
public $structure = null;
public $style = 'items';
public $modalsize = 'medium';
public $sort = null;
public $flip = false;

public function routes() {

Expand Down Expand Up @@ -53,6 +55,19 @@ public function style() {
return in_array($this->style, $styles) ? $this->style : 'items';
}

public function sort() {
return $this->sort ? str::split($this->sort) : false;
}

public function flip() {
return $this->flip === true ? true : false;
}

public function sortable() {
return $this->readonly() or $this->sort() or $this->flip();
}


public function structure() {
if(!is_null($this->structure)) {
return $this->structure;
Expand All @@ -76,7 +91,16 @@ public function fields() {
}

public function entries() {
return $this->structure()->data();
$entries = $this->structure()->data();

if($sort = $this->sort()) {
$entries = call_user_func_array(array($entries, 'sortBy'), $sort);
}
if($this->flip()) {
$entries = $entries->flip();
}

return $entries;
}

public function result() {
Expand Down
2 changes: 1 addition & 1 deletion app/fields/structure/template.php
@@ -1,7 +1,7 @@
<div class="structure<?php e($field->readonly(), ' structure-readonly') ?>"
data-field="structure"
data-api="<?php __($field->url('sort')) ?>"
data-sortable="<?php e($field->readonly(), 'false', 'true') ?>"
data-sortable="<?php e($field->sortable(), 'false', 'true') ?>"
data-style="<?php echo $field->style() ?>">

<?php echo $field->headline() ?>
Expand Down
6 changes: 5 additions & 1 deletion assets/css/form.css
Expand Up @@ -100,8 +100,12 @@
overflow: hidden;
width: 100%;
text-overflow: ellipsis;
cursor: move;
}

.structure[data-sortable=true] .structure-table td a {
cursor: move;
}

.structure-table-options {
width: 3rem;
text-align: center;
Expand Down
2 changes: 1 addition & 1 deletion assets/css/form.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.