call($this->row, $this);
}
if ($color) {
$this->color($color);
}
if (! Arr::isAssoc($columns)) {
$labels = array_map('admin_trans_field', $columns);
$columns = array_combine($columns, $labels);
}
$html = [];
foreach ($columns as $column => $label) {
$html[] = $this->buildSwitch($column, $label);
}
return '
';
}
protected function buildSwitch($name, $label = '')
{
$class = 'grid-switch-group-'.$this->grid->getName();
$keys = collect(explode('.', $name));
if ($keys->isEmpty()) {
$elementName = $name;
} else {
$elementName = $keys->shift().$keys->reduce(function ($carry, $val) {
return "{$carry}[{$val}]";
});
}
$script = <<resource()}/" + id,
type: "POST",
data: data,
success: function (d) {
Dcat.NP.done();
if (d.status) {
Dcat.success(d.message);
} else {
Dcat.error(d.message);
}
}
});
});
})();
JS;
Admin::script($script);
$key = $this->getKey();
$checked = $this->row->$name ? 'checked' : '';
$color = $this->color ?: Admin::color()->primary();
return <<
{$label}: |
|
EOT;
}
}