Newer
Older
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { MediaMatcher } from '@angular/cdk/layout';
import { HttpClient } from '@angular/common/http';
import { Router, ActivatedRoute } from '@angular/router';
import { LANG } from '../translate.component';
import { NotificationService } from '../notification.service';
declare function $j(selector: any): any;
declare var angularGlobals: any;
@Component({
templateUrl: "../../../../Views/contacts-group-administration.component.html",
providers: [NotificationService]
})
export class ContactsGroupAdministrationComponent implements OnInit {
mobileQuery: MediaQueryList;
private _mobileQueryListener: () => void;
lang: any = LANG;
coreUrl: string;
creationMode: boolean;
loading: boolean = false;
constructor(changeDetectorRef: ChangeDetectorRef, media: MediaMatcher, public http: HttpClient, private route: ActivatedRoute, private router: Router, private notify: NotificationService) {
$j("link[href='merged_css.php']").remove();
this.mobileQuery = media.matchMedia('(max-width: 768px)');
this._mobileQueryListener = () => changeDetectorRef.detectChanges();
this.mobileQuery.addListener(this._mobileQueryListener);
}
ngOnDestroy(): void {
this.mobileQuery.removeListener(this._mobileQueryListener);
}
ngOnInit(): void {
this.coreUrl = angularGlobals.coreUrl;
this.loading = true;
this.route.params.subscribe(params => {
if (typeof params['id'] != "undefined") {
this.http.get(this.coreUrl + 'rest/contactsGroups/' + params['id'])
this.contactsGroup = data.contactsGroup;
}
});
}
onSubmit() {
if (this.creationMode) {
this.http.post(this.coreUrl + 'rest/contactsGroups', this.contactsGroup)
this.router.navigate(['/administration/contacts-groups']);
this.notify.success(this.lang.contactsGroupAdded);
}, (err) => {
this.notify.error(err.error.errors);
});
} else {
this.http.put(this.coreUrl + 'rest/contactsGroups/' + this.contactsGroup.id, this.contactsGroup)
this.router.navigate(['/administration/contacts-groups']);
this.notify.success(this.lang.contactsGroupUpdated);
}, (err) => {
this.notify.error(err.error.errors);
});
}
}
}