Skip to content
Snippets Groups Projects
activate-user.component.ts 1.67 KiB
Newer Older
  • Learn to ignore specific revisions
  • Damien's avatar
    Damien committed
    import { Component, OnInit, ChangeDetectorRef} from '@angular/core';
    
    import { HttpClient } from '@angular/common/http';
    import { MediaMatcher } from '@angular/cdk/layout';
    import { NotificationService } from './notification.service';
    import { LANG } from './translate.component';
    
    declare var angularGlobals: any;
    
    Pegane Nestor's avatar
    Pegane Nestor committed
    declare function $j(selector: any): any;
    
    
    @Component({
    
        templateUrl: "activate-user.component.html",
    
        providers: [NotificationService],
    })
    
    export class ActivateUserComponent implements OnInit {
    
    Damien's avatar
    Damien committed
    
        private _mobileQueryListener    : () => void;
        mobileQuery                     : MediaQueryList;
    
    
        coreUrl     : string;
        lang        : any       = LANG;
        loading     : boolean   = false;
    
    
        constructor( media: MediaMatcher, changeDetectorRef: ChangeDetectorRef, public http: HttpClient, private notify: NotificationService){
    
    Pegane Nestor's avatar
    Pegane Nestor committed
            $j("link[href='merged_css.php']").remove();
    
            this.mobileQuery = media.matchMedia('(max-width: 768px)');
            this._mobileQueryListener = () => changeDetectorRef.detectChanges();
            this.mobileQuery.addListener(this._mobileQueryListener);
        }
    
        ngOnInit() : void {
            this.coreUrl = angularGlobals.coreUrl;
    
    Damien's avatar
    Damien committed
            this.loading = false;
    
    Damien's avatar
    Damien committed
        activateUser() : void {
            this.http.put(this.coreUrl + 'rest/users/' + angularGlobals.user.id + '/status', {'status' : 'OK'})
    
                .subscribe(() => {
    
    Damien's avatar
    Damien committed
                    this.notify.success(this.lang.absOff);
    
                    location.href = "index.php";
    
    Damien's avatar
    Damien committed
                }, (err : any) => {
    
                    this.notify.error(err.error.errors);
                });
        }
    
        logout() {
            location.href = "index.php?display=true&page=logout&logout=true";
        }