help-desk.ts 10 KB
Newer Older
1 2 3 4 5 6
import { Component, OnInit, OnDestroy } from "@angular/core";
import { Injectable } from "@angular/core";
import { VALID_EMAIL_PATTERN, VALID_NAMES_PATTERN } from '../../constants';
import {Router} from "@angular/router";
import { BehaviorSubject, Subscription, Observable } from 'rxjs/Rx';
import { HelperDataService } from '../../services/helper-data-service';
Open Source Developer's avatar
others  
Open Source Developer committed
7 8 9 10
import { ILoginInfo, ILoginInfoToken } from "../../store/logininfo/logininfo.types";
import { LOGININFO_INITIAL_STATE } from "../../store/logininfo/logininfo.initial-state";
import { NgRedux, select } from "ng2-redux";
import { IAppState } from "../../store/store";
11 12 13 14 15 16 17 18 19 20 21 22 23
import {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray,
    Validators,
} from '@angular/forms';



@Component({
    selector: 'helpdesk',
    template: `
Open Source Developer's avatar
others  
Open Source Developer committed
24
        <div class = "loading" *ngIf="(showLoader | async) === true"></div>
25 26 27 28 29 30 31 32 33 34 35
        <p align="left"><strong>Ηλεκτρονικές δηλώσεις προτίμησης ΕΠΑΛ για το νέο σχολικό έτος</strong></p>
        <p align="left">
        Σε περίπτωση που αντιμετωπίζετε οποιοδήποτε πρόβλημα με την καταχώριση της αίτησής σας, παρακαλούμε να 
         συμπληρώσετε την παρακάτω φόρμα.


      <p align="left"><strong> Φόρμα Επικοινωνίας </strong></p>

    <form [formGroup]="formGroup">

    <div class="form-group">
Open Source Developer's avatar
others  
Open Source Developer committed
36 37 38 39 40


  <div *ngFor="let loginInfoRow$ of loginInfo$ | async; let i=index;" style="margin-bottom: 20px;">
     <label for="userEmail">Email Επικοινωνίας(<span style="color: #ff0000;">*</span>)</label>
        <input #userEmail class="form-control" type="text" formControlName="userEmail" >
41 42 43 44 45 46 47 48 49 50
    </div>
    <div class="alert alert-danger" *ngIf="formGroup.get('userEmail').touched && formGroup.get('userEmail').hasError('required') ">
        Το πεδίο δεν μπορεί να αφεθεί κενό!
    </div>
    <div class="alert alert-danger" *ngIf="formGroup.get('userEmail').hasError('pattern')">
        Πληκτρολογήστε ένα σωστό συντακτικά email!
    </div>

    <div class="form-group">
        <label for="userName">Όνομα(<span style="color: #ff0000;">*</span>)</label>
Open Source Developer's avatar
others  
Open Source Developer committed
51
        <input class="form-control" type="text" formControlName="userName" >
52 53 54 55 56 57 58 59
        <div class="alert alert-danger" *ngIf="formGroup.get('userName').touched && formGroup.get('userName').hasError('required') ">
            Το πεδίο δεν μπορεί να αφεθεί κενό!
        </div>
        <div class="alert alert-danger" *ngIf="formGroup.get('userName').hasError('pattern')">
            Πληκτρολογήστε το όνομά σας!
        </div>
    </div>
    <div class="form-group">
Open Source Developer's avatar
others  
Open Source Developer committed
60 61
        <label for="userSurname">Επώνυμο(<span style="color: #ff0000;">*</span>)</label>
        <input class="form-control" type="text" formControlName="userSurname" >
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        <div class="alert alert-danger" *ngIf="formGroup.get('userSurname').touched && formGroup.get('userSurname').hasError('required') ">
            Το πεδίο δεν μπορεί να αφεθεί κενό!
        </div>
        <div class="alert alert-danger" *ngIf="formGroup.get('userSurname').hasError('pattern')">
            Πληκτρολογήστε το επώνυμό σας!
        </div>
    </div>

       <div class="form-group">
        <label for="userMessage">Μύνημα(<span style="color: #ff0000;">*</span>)</label>
        <textarea style="height: 150px;" class="form-control" type="text" formControlName="userMessage"></textarea>
        <div class="alert alert-danger" *ngIf="formGroup.get('userMessage').touched && formGroup.get('userMessage').hasError('required') ">
            Το πεδίο δεν μπορεί να αφεθεί κενό!
        </div>
        <div class="alert alert-danger" *ngIf="formGroup.get('userMessage').hasError('pattern')">
            Πληκτρολογήστε ενα μήνυμα!
        </div>
    </div>
Open Source Developer's avatar
others  
Open Source Developer committed
80
    </div>
81 82 83

    <div class="row">
        <div class="col-md-12">
Open Source Developer's avatar
others  
Open Source Developer committed
84 85
            <button type="button" class="btn-primary btn-lg pull-right isclickable" style="width: 10em;" (click)="sendmail()" >
                <span style="font-size: 0.9em; font-weight: bold;">Αποστολή email </span>
86 87 88 89 90
            </button>
        </div>
    </div>
        <br>
        <br>
Open Source Developer's avatar
others  
Open Source Developer committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
        <p align="left">
      <strong>Τηλ. Επικοινωνίας:</strong> 2103443014, 2103442231, 2103443359, 2103442034, 2103443309 (ώρες: 8:00 - 16:00)</p>


  <div id="mailsent" (onHidden)="onHidden('#mailsent')"
    class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
          <div class="modal-header modal-header-success">
            <h3 class="modal-title pull-left"><i class="fa fa-check-square-o"></i>&nbsp;&nbsp;To email έχει αποσταλλεί</h3>
            <button type="button" class="close pull-right" aria-label="Close" (click)="hideModal('#mailsent')">
              <span aria-hidden="true"><i class="fa fa-times"></i></span>
            </button>
          </div>
          <div class="modal-body">
            <p>Επιτυχής αποστόλη!</p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Κλείσιμο</button>
          </div>
        </div>
      </div>
    </div>
<div id="dangermodal" (onHidden)="onHidden('#dangermodal')"
    class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
          <div class="modal-header modal-header-danger">
            <h3 class="modal-title pull-left"><i class="fa fa-ban"></i>&nbsp;&nbsp;To email δεν έχει αποσταλλεί</h3>
            <button type="button" class="close pull-right" aria-label="Close" (click)="hideModal('#dangermodal')">
              <span aria-hidden="true"><i class="fa fa-times"></i></span>
            </button>
          </div>
          <div class="modal-body">
            <p>Παρακαλώ προσπαθήστε ξανα!</p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Κλείσιμο</button>
          </div>
        </div>
      </div>
    </div>

    <div id="fillfields" (onHidden)="onHidden('#fillfields')"
    class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
          <div class="modal-header modal-header-danger">
            <h3 class="modal-title pull-left"><i class="fa fa-ban"></i>&nbsp;&nbsp;To email δεν έχει αποσταλλεί</h3>
            <button type="button" class="close pull-right" aria-label="Close" (click)="hideModal('#fillfields')">
              <span aria-hidden="true"><i class="fa fa-times"></i></span>
            </button>
          </div>
          <div class="modal-body">
            <p>Παρακαλώ συμπληρώστε όλα τα υποχρεωτικά πεδία!</p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Κλείσιμο</button>
          </div>
        </div>
      </div>
    </div>

154 155 156 157 158 159 160 161

   `
})

@Injectable() export default class HelpDesk implements OnInit, OnDestroy {

 
  public formGroup: FormGroup;
Open Source Developer's avatar
others  
Open Source Developer committed
162 163 164 165
  private emailSent: BehaviorSubject<boolean>;
  private loginInfo$: BehaviorSubject<ILoginInfo>;
  private showLoader: BehaviorSubject<boolean>;
  
166
  constructor(private fb: FormBuilder,
Open Source Developer's avatar
others  
Open Source Developer committed
167 168
              private hds: HelperDataService,
              private _ngRedux: NgRedux<IAppState>)
169
      {
Open Source Developer's avatar
others  
Open Source Developer committed
170 171
          this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
          this.showLoader = new BehaviorSubject(false);
172 173 174 175 176 177 178 179 180 181
          this.formGroup = fb.group({
          userEmail: ['', [Validators.pattern(VALID_EMAIL_PATTERN),Validators.required]],
          userName: ['', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
          userSurname: ['', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
          userMessage: ['', [Validators.required]],
      
     })
     this.emailSent = new BehaviorSubject(false);
  }

Open Source Developer's avatar
others  
Open Source Developer committed
182 183 184
   public showModal(popupMsgId): void {
        (<any>$(popupMsgId)).modal('show');
    }
185

Open Source Developer's avatar
others  
Open Source Developer committed
186 187 188 189 190 191 192 193 194 195 196
    public hideModal(popupMsgId): void {

        (<any>$(popupMsgId)).modal('hide');
    }

    public onHidden(popupMsgId): void {

    }

    ngOnDestroy() {
      if (this.loginInfo$) this.loginInfo$.unsubscribe();
197 198 199
    }

    ngOnInit() {
Open Source Developer's avatar
others  
Open Source Developer committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
        (<any>$('#mailsent')).appendTo("body");
        (<any>$('#dangermodal')).appendTo("body");
        (<any>$('#fillfields')).appendTo("body");
      this._ngRedux.select(state => {
            if (state.loginInfo.size > 0) {
                state.loginInfo.reduce(({}, loginInfoToken) => {
                    
                    this.formGroup.controls['userEmail'].setValue(loginInfoToken.cu_email);
                    this.formGroup.controls['userName'].setValue(loginInfoToken.cu_name);
                    this.formGroup.controls['userSurname'].setValue(loginInfoToken.cu_surname);
                    return loginInfoToken;

                }, {});
            }
            return state.loginInfo;
        }).subscribe(this.loginInfo$);
216 217 218 219 220
    }



     sendmail() {
Open Source Developer's avatar
others  
Open Source Developer committed
221 222 223 224 225 226
       if (this.formGroup.invalid){
           this.showModal("#fillfields");
       }
       else
       {
       this.showLoader.next(true);
227 228 229
        this.hds.sendmail(this.formGroup.value.userEmail, this.formGroup.value.userName, this.formGroup.value.userSurname,this.formGroup.value.userMessage)
            .then(res => {
                this.emailSent.next(true);
Open Source Developer's avatar
others  
Open Source Developer committed
230 231
                this.showLoader.next(false);
                this.showModal("#mailsent");
232 233 234
            })
            .catch(err => {
                console.log(err);
Open Source Developer's avatar
others  
Open Source Developer committed
235 236
                this.showLoader.next(false);
                this.showModal("#dangermodal");
237
            });
Open Source Developer's avatar
others  
Open Source Developer committed
238
        }
239 240
    }
}