Skip to content

Commit 4a63936

Browse files
committed
Added pivot treeview
1 parent 1c437d1 commit 4a63936

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/Controllers/BaseController.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,34 @@ private function getModelDataColumns($column, $opt)
458458
return $response;
459459
}
460460

461+
private function pivot_walk($columnId, $column, $data, $parent = 0, $depth = 0)
462+
{
463+
$response = '';
464+
foreach ($data[$parent] as $opt) {
465+
$response .= $this->pivot_label($columnId, $column, $opt);
466+
if (isset($data[$opt->id])) {
467+
$response .= '<div class="pivot-depth ' . ($depth + 1) . '">' . $this->pivot_walk($columnId, $column, $data, $opt->id, $depth + 1) . '</div>';
468+
}
469+
}
470+
return $response;
471+
}
472+
473+
private function pivot_label($columnId, $column, $opt)
474+
{
475+
return '<label class="pivot' . (($column['treeview'] ?? false) ? ' treeview' : '') . (!empty($column['active']) && !$opt[$column['active']] ? ' inactive' : '') . '"><input type="checkbox" class="pivot-' . $columnId . '" name="' . $columnId . '[]" value="' . $opt->id . '"><span>' . $this->getModelDataColumns($column, $opt) . '</span></label>';
476+
}
477+
461478
// Return all labels for a many to many (pivot) relationship
462479
public function pivot($columnId, $column)
463480
{
464-
$data = $this->getModelData($column);
465481
$response = '';
466-
foreach ($data->get() as $opt) {
467-
$response .= '<label class="pivot' . (!empty($column['active']) && !$opt[$column['active']] ? ' inactive' : '') . '"><input type="checkbox" class="pivot-'.$columnId.'" name="'.$columnId.'[]" value="'.$opt->id.'"><span>'.$this->getModelDataColumns($column, $opt).'</span></label>';
482+
$data = $this->getModelData($column);
483+
if ($column['treeview'] ?? false) {
484+
return $this->pivot_walk($columnId, $column, $data);
485+
} else {
486+
foreach ($data->get() as $opt) {
487+
$response .= $this->pivot_label($columnId, $column, $opt);
488+
}
468489
}
469490
return $response;
470491
}

src/css/base.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ nav li:hover > ul > li {max-height:40px}
122122
#listview .table UL > LI > SPAN:first-of-type {font-weight:400;color:#000;font-size:1em}
123123
#listview .table UL > LI > SPAN:last-of-type {width:100%}
124124

125-
#editview .content LABEL.pivot.inactive SPAN,
125+
#editview .content LABEL.pivot.inactive:not(.treeview) SPAN,
126126
#listview .table UL LI.inactive > SPAN,
127127
#listview LI.inactive > DIV > SPAN {text-decoration:line-through;color:rgba(0,0,0,0.3)}
128128

@@ -144,11 +144,13 @@ nav li:hover > ul > li {max-height:40px}
144144
#editview .content LABEL:first-of-type {padding-top:0}
145145
#editview .content LABEL.radio {display:inline-block;padding-right:10px}
146146
#editview .content LABEL.pivot {display:inline-block;padding:0 5px 5px 0}
147-
#editview .content LABEL.pivot SPAN {background-color:rgba(0,0,0,0.1);padding:4px 10px;border-radius:4px;display:inline-block}
147+
#editview .content LABEL.pivot:not(.treeview.inactive) SPAN {background-color:rgba(0,0,0,0.1);padding:4px 10px;border-radius:4px;display:inline-block}
148148
#editview .content LABEL.pivot:hover SPAN {background-color:#0cb;cursor:pointer}
149149
#editview .content LABEL.pivot INPUT[type=checkbox] {display:none}
150150
#editview .content LABEL.pivot INPUT[type=checkbox]:checked ~ SPAN {background-color:#178;color:#fff}
151151
#editview .content LABEL.pivot:hover INPUT[type=checkbox]:checked ~ SPAN {background-color:#178;opacity:0.7}
152+
#editview .content LABEL.pivot.treeview.inactive:after {content:':'}
153+
#editview .content DIV.pivot-depth {padding-left:20px}
152154
#editview .content SELECT,
153155
#editview .content TEXTAREA,
154156
#editview .content INPUT[type=password],

0 commit comments

Comments
 (0)