Skip to content
Snippets Groups Projects
Commit 2c6f5144 authored by Pegane Nestor's avatar Pegane Nestor
Browse files

FEAT #8221 disable delete button if doctype level has children

parent befb865e
No related branches found
No related tags found
No related merge requests found
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
<div class="form-group"> <div class="form-group">
<div class="col-md-12 text-center" style="padding:10px;"> <div class="col-md-12 text-center" style="padding:10px;">
<button mat-raised-button [disabled]="!firstLevelForm.form.valid" color="primary" (click)="saveFirstLevel()">{{lang.save}}</button> <button mat-raised-button [disabled]="!firstLevelForm.form.valid" color="primary" (click)="saveFirstLevel()">{{lang.save}}</button>
<button type="button" mat-raised-button *ngIf="!creationMode" [disabled]="!firstLevelForm.form.valid" <button type="button" mat-raised-button *ngIf="!creationMode" [disabled]="!firstLevelForm.form.valid || currentFirstLevel.hasChildren"
color="warn" (click)="removeFirstLevel()">{{lang.delete}}</button> color="warn" (click)="removeFirstLevel()">{{lang.delete}}</button>
<button type="button" mat-raised-button *ngIf="creationMode" color="default" (click)="readMode()">{{lang.cancel}}</button> <button type="button" mat-raised-button *ngIf="creationMode" color="default" (click)="readMode()">{{lang.cancel}}</button>
</div> </div>
...@@ -152,7 +152,7 @@ ...@@ -152,7 +152,7 @@
<div class="form-group"> <div class="form-group">
<div class="col-md-12 text-center" style="padding:10px;"> <div class="col-md-12 text-center" style="padding:10px;">
<button mat-raised-button [disabled]="!secondLevelForm.form.valid" color="primary" (click)="saveSecondLevel()">{{lang.save}}</button> <button mat-raised-button [disabled]="!secondLevelForm.form.valid" color="primary" (click)="saveSecondLevel()">{{lang.save}}</button>
<button mat-raised-button *ngIf="!creationMode" [disabled]="!secondLevelForm.form.valid" <button mat-raised-button *ngIf="!creationMode" [disabled]="!secondLevelForm.form.valid || currentSecondLevel.hasChildren"
color="warn" (click)="removeSecondLevel()">{{lang.delete}}</button> color="warn" (click)="removeSecondLevel()">{{lang.delete}}</button>
<button mat-raised-button *ngIf="creationMode" color="default" (click)="readMode()">{{lang.cancel}}</button> <button mat-raised-button *ngIf="creationMode" color="default" (click)="readMode()">{{lang.cancel}}</button>
</div> </div>
......
...@@ -32,7 +32,7 @@ class SecondLevelController ...@@ -32,7 +32,7 @@ class SecondLevelController
} }
$obj['secondLevel'] = SecondLevelModel::getById(['id' => $aArgs['id']]); $obj['secondLevel'] = SecondLevelModel::getById(['id' => $aArgs['id']]);
if (!empty($obj['secondLevel'])) { if (!empty($obj['secondLevel'])) {
if ($obj['secondLevel']['enabled'] == 'Y') { if ($obj['secondLevel']['enabled'] == 'Y') {
$obj['secondLevel']['enabled'] = true; $obj['secondLevel']['enabled'] = true;
......
...@@ -44,13 +44,23 @@ class FirstLevelModelAbstract ...@@ -44,13 +44,23 @@ class FirstLevelModelAbstract
'where' => ['doctypes_first_level_id = ?'], 'where' => ['doctypes_first_level_id = ?'],
'data' => [$aArgs['id']] 'data' => [$aArgs['id']]
] ]
); );
if (empty($aReturn[0])) { if (empty($aReturn[0])) {
return []; return [];
} }
$children = DatabaseModel::select(
[
'select' => ['doctypes_second_level_id'],
'table' => ['doctypes_second_level'],
'where' => ['doctypes_first_level_id = ?'],
'data' => [$aArgs['id']]
]
);
$aReturn = $aReturn[0]; $aReturn = $aReturn[0];
$aReturn['hasChildren'] = count($children) > 0 ? true : false;
return $aReturn; return $aReturn;
} }
......
...@@ -45,12 +45,22 @@ class SecondLevelModelAbstract ...@@ -45,12 +45,22 @@ class SecondLevelModelAbstract
'data' => [$aArgs['id']] 'data' => [$aArgs['id']]
] ]
); );
if (empty($aReturn[0])) { if (empty($aReturn[0])) {
return []; return [];
} }
$children = DatabaseModel::select(
[
'select' => ['type_id'],
'table' => ['doctypes'],
'where' => ['doctypes_second_level_id = ?'],
'data' => [$aArgs['id']]
]
);
$aReturn = $aReturn[0]; $aReturn = $aReturn[0];
$aReturn['hasChildren'] = count($children) > 0 ? true : false;
return $aReturn; return $aReturn;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment