Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic valid/invalid state of record button on tab0 #2

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions frontend/app/zh-forms/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class ZhFormMapComponent implements OnInit, AfterViewInit {
@Output() draw = new EventEmitter<any>();
@Output() edit = new EventEmitter<any>();
@Output() endDraw = new EventEmitter<any>();
@Output() delete = new EventEmitter<any>();

constructor(private _mapService: MapService) {}

Expand All @@ -38,8 +39,6 @@ export class ZhFormMapComponent implements OnInit, AfterViewInit {
this._mapService.currentExtend.zoom
);
}
console.log(L.Draw);

this._mapService.map.off(L.Draw.Event.DRAWSTART);
this._mapService.map.on(L.Draw.Event.CREATED, (e) => {
this.onDrawStop(e);
Expand All @@ -51,6 +50,9 @@ export class ZhFormMapComponent implements OnInit, AfterViewInit {
this._mapService.map.on(L.Draw.Event.EDITED, (e) => {
this.onEdit(e);
});
this._mapService.map.on(L.Draw.Event.DELETED, (e) => {
this.onEdit(e);
});
}

onDrawn(e) {
Expand All @@ -68,4 +70,8 @@ export class ZhFormMapComponent implements OnInit, AfterViewInit {
onDrawStop(e) {
this.endDraw.emit(e);
}

onDeleted(e) {
this.delete.emit(e);
}
}
3 changes: 2 additions & 1 deletion frontend/app/zh-forms/tabs/tab0/zh-form-tab0.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
(draw)="updateGeom($event)"
(endDraw)="onNewGeom($event)"
(edit)="updateGeom($event)"
(delete)="updateGeom(null)"
></zh-form-map>
</div>
<div class="col-xl-6 col-lg-5 col-sm-6">
Expand Down Expand Up @@ -116,7 +117,7 @@ <h5 class="section-title">Champs obligatoires</h5>
mat-raised-button
color="primary"
class="ml-3"
[disabled]="posted"
[disabled]="posted || form.invalid || !isGeometryDefined"
(click)="onFormSubmit(form.value)"
>
<mat-icon *ngIf="!posted">save_outline</mat-icon>
Expand Down
8 changes: 7 additions & 1 deletion frontend/app/zh-forms/tabs/tab0/zh-form-tab0.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { PbfService } from '../../../services/pbf.service';

const GEOM_CONTAINED_ID = 1;

const EMPTY_GEOMETRY = { geojson: null };

@Component({
selector: 'zh-form-tab0',
templateUrl: './zh-form-tab0.component.html',
Expand All @@ -31,7 +33,7 @@ export class ZhFormTab0Component implements OnInit {
public idOrg: any;
public $_geojsonSub: Subscription;
public $_currentZhSub: Subscription;
private geometry: any;
private geometry: any = EMPTY_GEOMETRY;
private currentLayer: any;
public submitted = false;
public posted = false;
Expand Down Expand Up @@ -82,6 +84,9 @@ export class ZhFormTab0Component implements OnInit {
});
this._pbfService.setPaneBackground(this._mapService.map);
}
get isGeometryDefined(): boolean {
return this.geometry && this.geometry != EMPTY_GEOMETRY;
}

intiTab() {
this.$_currentZhSub = this._dataService.currentZh.subscribe((zh: any) => {
Expand Down Expand Up @@ -254,6 +259,7 @@ export class ZhFormTab0Component implements OnInit {
updateGeom(newGeometry: any) {
this.canChangeTab.emit(false);
this.geometry = newGeometry;
console.log(newGeometry);
}

onCancel() {
Expand Down