123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- import { ActivatedRoute, Params } from '@angular/router';
- import { Location } from '@angular/common';
- import { DashboardService } from './../../../shared/dashboard.service';
- import { AuthServiceService } from './../../../shared/auth-service.service';
- import { FormGroup, NgForm } from '@angular/forms';
- import { Component, OnInit, ViewChild } from '@angular/core';
- import { UserService } from '../../../shared/user.service';
- import { ToastrService } from 'ngx-toastr';
- import { NgxSpinnerService } from 'ngx-spinner';
- @Component({
- selector: 'app-supervisor-add',
- templateUrl: './supervisor-add.component.html',
- styleUrls: ['./supervisor-add.component.css']
- })
- export class SupervisorAddComponent implements OnInit {
- constructor(private userSer: UserService,
- private dashboardService: DashboardService,
- private toastr: ToastrService,
- private location: Location,
- private spinner: NgxSpinnerService,
- private route: ActivatedRoute,
- public authSer: AuthServiceService) { }
- formData: any;
- checkSaveClick: boolean = false;
- superDeaprt = {
- email: '',
- phone: '',
- switch_phone: '',
- department_id: '',
- supervisor_id: '',
- }
- departments = []; //all departments list view
- department = []; //department for edit
- supervisorList = [];
- departmentData = [];
- supervisorId: number;
- departmentName: string = '';
- checkSaveDisabled: boolean = false;
- typeLink: string = '';
- ngOnInit() {
- //show / hide notification search in header
- this.authSer.notificationLogin = true;
- this.authSer.showSearchHeader = false;
- this.authSer.showHeaderLogin = false;
- this.authSer.showHeaderDashBoard = true;
- this.authSer.internalHeader = false;
-
- //get user departments
- this.userSer.getTrainningServiceDepartments().subscribe(
- (responce) => {
- console.log(responce);
- this.departments = responce['departments'];
- if(this.departments.length == 0) {
- this.toastr.warning('جميع الأقسام لديها مشرفين !');
- }
- },
- (error) => {
- console.log(error);
- }
- );
- this.route.params.subscribe(
- (params: Params) => {
- this.supervisorId = +params['superEditId'];
- }
- );
- if(this.supervisorId) {
- this.spinner.show();
- this.typeLink = 'تعديل';
- this.dashboardService.getItemData(this.supervisorId, 'supervisor').subscribe(
- (responce) =>{
- console.log('get data of one', responce);
- this.department = responce['department'];
- this.superDeaprt.email = this.department['email'];
- this.superDeaprt.phone = this.department['phone'];
- this.superDeaprt.switch_phone = this.department['switch_phone'];
- this.superDeaprt.department_id = this.department['id'];
- this.superDeaprt.supervisor_id = this.department['supervisor_id'];
- this.getSupervisors(this.department['id']);
- this.departmentName = this.department['name'];
- console.log(this.superDeaprt.department_id);
- this.spinner.hide();
- },
- (error) => {
- console.log(error);
- }
- )
- } else {
- this.typeLink = 'إضافه';
- }
- }
- getSupervisors(departmentId: number) {
- this.userSer.getSupervisorsList(departmentId).subscribe(
- (responce) => {
- console.log(responce);
- this.supervisorList = responce['users'];
- if(this.supervisorList.length == 0) {
- this.toastr.warning(' القسم ليس لديه مشرفين !');
- }
- },
- (error) => {
- console.log(error);
- }
- );
- }
- changeDepartment(event) {
- console.log(event.target.value);
- this.getSupervisors(event.target.value);
- this.userSer.getDepartmentData(event.target.value).subscribe(
- (responce) => {
- this.departmentData = responce['department'];
- this.superDeaprt.email = this.departmentData['email'];
- this.superDeaprt.phone = this.departmentData['phone'];
- this.superDeaprt.switch_phone = this.departmentData['switch_phone'];
- this.superDeaprt.supervisor_id = this.departmentData['supervisor_id'];
- console.log(this.superDeaprt.supervisor_id);
- console.log(this.departmentData);
- },
- (error) => {
- console.log(error);
- }
- )
- }
- onSubmitted(form: NgForm) {
- this.formData = form.value;
- this.checkSaveClick = true;
- if(this.supervisorId){
- this.formData['department_id'] = this.superDeaprt.department_id;
- }
- console.log(this.formData);
- this.dashboardService.addItem(this.formData, 'supervisor').subscribe(
- (responce) => {
- console.log(responce);
- this.checkSaveClick = false;
- if(this.supervisorId) {
- this.toastr.success('تمت التعديل بنجاح');
- } else {
- this.toastr.success('تمت الاضافه بنجاح');
- }
- this.location.back();
- },
- (error) => {
- console.log(error);
- this.checkSaveClick = false;
- this.toastr.error('خطأ في الحفظ !');
- }
- );
- }
- }
|