Skip to content

Commit

Permalink
zaaTable and TableBlock update
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Aug 4, 2015
1 parent 8b41891 commit 48d2b9d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 106 deletions.
29 changes: 22 additions & 7 deletions modules/admin/resources/js/directives/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,29 +337,44 @@ zaa.directive('zaaTable', function() {
$scope.model = [{}];
}

$scope.addColumn = function(name) {
$scope.columnName = null;
$scope.addColumn = function() {
var len = 0;
for (var o in $scope.model[0]) {
len++;
}

for(var i in $scope.model) {
$scope.model[i][name] = '';
$scope.model[i][len] = '';
}
}

$scope.addRow = function() {
var elmn = $scope.model[0];
console.log(elmn);
var ins = {};
for (var i in elmn) {
ins[i] = '';
}

$scope.model.push(ins);
}

$scope.removeColumn = function(key) {
for (var i in $scope.model) {
var item = $scope.model[i];
item.splice(key, 1);
}
}

$scope.removeRow = function(key) {
$scope.model.splice(key, 1);
}
},
template : function() {
return '<div>' +
'<table class="bordered">'+
'<thead><tr><td width="90"><b>Spalten:</b></td><td data-ng-repeat="(hk, hr) in model[0]"><strong>{{hk}}</strong></td><td width="240"><input type="text" ng-model="columnName" style="width:140px;" /><button ng-click="addColumn(columnName)" type="button">Anfügen</button></td></tr></thead>' +
'<tr data-ng-repeat="(key, row) in model"><td>#{{key+1}}</td><td style="background-color:#e1e1e1;" data-ng-repeat="(field,value) in row"><input type="text" ng-model="model[key][field]" /></td></tr>'+
'<button ng-click="addColumn()" type="button" style="float:right;">Spalte Rechts einfügen</button>'+
'<table>'+
'<thead><tr><td width="90"></td><td data-ng-repeat="(hk, hr) in model[0] track by hk"><strong>#{{hk+1}} <button type="button" ng-click="removeColumn(hk)" class="btn-floating"><i class="mdi-action-delete"></i></button></strong></td></tr></thead>' +
'<tr data-ng-repeat="(key, row) in model track by key"><td>#{{key+1}} <button type="button" class="btn-floating" ng-click="removeRow(key)"><i class="mdi-action-delete"></i></button></td><td data-ng-repeat="(field,value) in row track by field"><input type="text" ng-model="model[key][field]" /></td></tr>'+
'</table><button ng-click="addRow()" type="button">Neue Zeile einfügen</button>'+
'</div>';
}
Expand Down
122 changes: 23 additions & 99 deletions modules/cmsadmin/blocks/TableBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,129 +23,53 @@ public function config()
['var' => 'table', 'label' => 'Text', 'type' => 'zaa-table'],
],
'cfgs' => [
['var' => 'header', 'label' => 'Erste Zeile als Tabellenkopf verwenden(Ja/Nein)', 'type' => 'zaa-text'],
['var' => 'stripe', 'label' => 'Jede Zeile abwechselnd hervorheben (Zebramuster)(Ja/Nein)', 'type' => 'zaa-text'],
['var' => 'border', 'label' => 'Rand zu jeder Seite der Tabelle hinzufügen(Ja/Nein)', 'type' => 'zaa-text'],
['var' => 'header', 'label' => 'Erste Zeile als Tabellenkopf verwenden', 'type' => 'zaa-checkbox'],
['var' => 'stripe', 'label' => 'Jede Zeile abwechselnd hervorheben (Zebramuster)', 'type' => 'zaa-checkbox'],
['var' => 'border', 'label' => 'Rand zu jeder Seite der Tabelle hinzufügen', 'type' => 'zaa-checkbox'],
]
];
}

public function getTableData()
{
$tdata = $this->getVarValue('table');

$tableData = [];

if(!empty($tdata)) {

// skip first row if already used as header
if($this->useHeader()) {
$i1 = 0;
} else {
$i1 = 1;
}

foreach($tdata as $row) {
if($i1++ > 0) {
$rowData = [];

$i = 0;
foreach($row as $column) {
if($i++ > 0 ) {
array_push($rowData, $column);
}
}
array_push($tableData, $rowData);
}
$table = [];
$i = 0;
foreach($this->getVarValue('table', []) as $key => $row) {
$i++;

if ($this->getCfgValue('header', 0) == 1 && $i == 1) {
continue;
}

$table[] = $row;
}

return $tableData;
return $table;
}

public function getHeaderRow()
{
$tdata = $this->getVarValue('table');

$headerRow = [];

if(!empty($tdata)) {
$i = 0;
foreach($tdata[0] as $column) {
// skip first entry
if($i++ > 0) {
array_push($headerRow, $column);
}
}
}

return $headerRow;
}

/**
* @return bool
* @todo: delete function if checkbox type is available
*/
public function useHeader()
{
$useHeader = $this->getCfgValue('header', 'Ja');

if($useHeader == 'Ja') {
return true;
} else {
return false;
}
}

/**
* @return bool
* @todo: delete function if checkbox type is available
*/
public function useStripe()
{
$useStripe = $this->getCfgValue('stripe', 'Nein');

if($useStripe == 'Ja') {
return true;
} else {
return false;
}
}

/**
* @return bool
* @todo: delete function if checkbox type is available
*/
public function useBorder()
{
$useBorder = $this->getCfgValue('border', 'Nein');

if($useBorder == 'Ja') {
return true;
} else {
return false;
}
$data = $this->getVarValue('table', []);

return (count($data) > 0) ? array_values($data)[0] : [];
}

public function extraVars()
{
return [
'table' => $this->getTableData(),
'header' => $this->getHeaderRow(),
'useHeader' => $this->useHeader(),
'useStripe' => $this->useStripe(),
'useBorder' => $this->useBorder(),
'headerData' => $this->getHeaderRow(),
];
}

public function twigFrontend()
{
return '{% if extras.table is not empty %}'.
'<table class="table{% if extras.useStripe%} table-striped{% endif %}{% if extras.useBorder%} table-bordered{% endif %}">'.
'{% if extras.useHeader %}'.
'<table class="table{% if cfgs.stripe %} table-striped{% endif %}{% if cfgs.border %} table-bordered{% endif %}">'.
'{% if cfgs.header %}'.
'<thead>'.
'<tr>'.
'{% for column in extras.header %}'.
'{% for column in extras.headerData %}'.
'<th>{{ column }}</th>{% endfor %}'.
'</tr>'.
'</thead>'.
Expand All @@ -167,10 +91,10 @@ public function twigAdmin()
{
return '<p>{% if extras.table is empty %}<span class="block__empty-text">Es wurde noch keine Tabelle angelegt.</span>{% else %}'.
'<table>'.
'{% if extras.useHeader %}'.
'{% if cfgs.header %}'.
'<thead>'.
'<tr>'.
'{% for column in extras.header %}'.
'{% for column in extras.headerData %}'.
'<th>{{ column }}</th>{% endfor %}'.
'</tr>'.
'</thead>'.
Expand Down

0 comments on commit 48d2b9d

Please sign in to comment.