|
@@ -6,13 +6,14 @@ import { ActivatedRoute, Params } from '@angular/router';
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
|
import { NgForm } from '@angular/forms';
|
|
|
import { ToastrService } from 'ngx-toastr';
|
|
|
-import { Location } from '@angular/common';
|
|
|
+import { Location, formatDate } from '@angular/common';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-add-request',
|
|
|
templateUrl: './add-request.component.html',
|
|
|
styleUrls: ['./add-request.component.css']
|
|
|
})
|
|
|
+
|
|
|
export class AddRequestComponent implements OnInit {
|
|
|
|
|
|
constructor(private route: ActivatedRoute,
|
|
@@ -31,6 +32,11 @@ export class AddRequestComponent implements OnInit {
|
|
|
requestId: number;
|
|
|
statusType: string = '';
|
|
|
|
|
|
+ attachments_ids = []; //for edit mode;
|
|
|
+ disabledInput:boolean = false; //disabled button of row in edit mode
|
|
|
+ editButtonShow:boolean = false; //show edit button in edit mode
|
|
|
+ saveButtonShow:boolean = true; //show save button in edit mode
|
|
|
+
|
|
|
@ViewChild('f') addRequestFrom: NgForm;
|
|
|
|
|
|
|
|
@@ -49,6 +55,7 @@ export class AddRequestComponent implements OnInit {
|
|
|
department1: '',
|
|
|
department2: '',
|
|
|
department3: '',
|
|
|
+ department: '',
|
|
|
};
|
|
|
|
|
|
files = [{
|
|
@@ -61,11 +68,6 @@ export class AddRequestComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
|
|
- attachments_ids = []; //for edit mode;
|
|
|
- departmentsIds = []; //attachemnts id edit
|
|
|
- disabledInput:boolean = false; //disabled button of row in edit mode
|
|
|
- editButtonShow:boolean = false; //show edit button in edit mode
|
|
|
- saveButtonShow:boolean = false; //show save button in edit mode
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
@@ -90,14 +92,25 @@ export class AddRequestComponent implements OnInit {
|
|
|
this.route.params.subscribe(
|
|
|
(params: Params) => {
|
|
|
this.requestId = params['requestId'];
|
|
|
+
|
|
|
+ //edit mode in all requests component
|
|
|
if(this.requestId) {
|
|
|
+
|
|
|
+ //get status of this user request
|
|
|
this.statusType = localStorage.getItem('requestStatus');
|
|
|
+ if(this.statusType == 'pending') {
|
|
|
+ this.saveButtonShow = true;
|
|
|
+ this.disabledInput = false;
|
|
|
+ } else {
|
|
|
+ this.saveButtonShow = false;
|
|
|
+ this.disabledInput = true;
|
|
|
+ }
|
|
|
|
|
|
this.spiner.show();
|
|
|
this.files = [];
|
|
|
this.editButtonShow = true;
|
|
|
- this.disabledInput = true;
|
|
|
this.editMode = true;
|
|
|
+
|
|
|
this.http.get(this.authService.pathApi + '/get_request/' + this.requestId).subscribe(
|
|
|
(responce) => {
|
|
|
console.log(responce);
|
|
@@ -117,6 +130,11 @@ export class AddRequestComponent implements OnInit {
|
|
|
//add departmrnts ids
|
|
|
if(responce['data']['request'].departments.length > 0) {
|
|
|
for(let i = 0; i < responce['data']['request'].departments.length; i++) {
|
|
|
+
|
|
|
+ if(responce['data']['request'].departments[i].is_confirmed == '1') {
|
|
|
+ this.dataForm.department = responce['data']['request'].departments[i].department_id;
|
|
|
+ }
|
|
|
+
|
|
|
if(i == 0) {
|
|
|
this.dataForm.department1 = responce['data']['request'].departments[0].department_id;
|
|
|
this.departmentsId[i] = responce['data']['request'].departments[i].department_id;
|
|
@@ -146,6 +164,8 @@ export class AddRequestComponent implements OnInit {
|
|
|
console.log('no attachements user add !');
|
|
|
}
|
|
|
|
|
|
+ console.log('filessss', this.files);
|
|
|
+
|
|
|
this.spiner.hide();
|
|
|
},
|
|
|
(error) => {
|
|
@@ -156,6 +176,7 @@ export class AddRequestComponent implements OnInit {
|
|
|
}
|
|
|
);
|
|
|
|
|
|
+ //get departments data
|
|
|
this.http.get(this.authService.pathApi + '/training_adminstration_departments').subscribe(
|
|
|
(responce) => {
|
|
|
this.departments = responce['departments'];
|
|
@@ -169,7 +190,7 @@ export class AddRequestComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+//add file in table
|
|
|
plusImage() {
|
|
|
this.files.push({
|
|
|
title: '',
|
|
@@ -181,6 +202,8 @@ export class AddRequestComponent implements OnInit {
|
|
|
console.log('files after plus ', this.files);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //on file change
|
|
|
onFileChanges(event, index:number) {
|
|
|
console.log(event);
|
|
|
console.log(index);
|
|
@@ -188,6 +211,7 @@ export class AddRequestComponent implements OnInit {
|
|
|
this.files[index].file = event[0].base64;
|
|
|
this.files[index].file_type = event[0].type.split('/')[1];
|
|
|
if(this.editMode) {
|
|
|
+
|
|
|
//validate in pdf type file in edit mode
|
|
|
if(this.files[index].file_type != '') {
|
|
|
if(this.files[index].file_type != 'pdf') {
|
|
@@ -211,7 +235,7 @@ export class AddRequestComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+//change department
|
|
|
changeDepartment(event, typeSelect) {
|
|
|
console.log(event.target.value);
|
|
|
if(typeSelect == 1) {
|
|
@@ -221,19 +245,16 @@ export class AddRequestComponent implements OnInit {
|
|
|
} else if(typeSelect == 3) {
|
|
|
this.departmentsId[2] = event.target.value;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- console.log(this.departmentsId);
|
|
|
- for(let i = 0; i < this.departmentsId.length; i++) {
|
|
|
- if(this.departmentsId[i] == this.departmentsId[i+1]) {
|
|
|
- this.toastr.warning('يوجد أقسام متشابهه ، يجب أن تكون جميه الاقسام مختلفه');
|
|
|
- this.checkSaveClick = true;
|
|
|
- break;
|
|
|
- } else {
|
|
|
- this.checkSaveClick = false;
|
|
|
- }
|
|
|
+ console.log(this.departmentsId);
|
|
|
+ for(let i = 0; i < this.departmentsId.length; i++) {
|
|
|
+ if(this.departmentsId[i] == this.departmentsId[i+1]) {
|
|
|
+ this.toastr.warning('يوجد أقسام متشابهه ، يجب أن تكون جميه الاقسام مختلفه');
|
|
|
+ this.checkSaveClick = true;
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ this.checkSaveClick = false;
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
changeType(event) {
|
|
@@ -256,15 +277,20 @@ export class AddRequestComponent implements OnInit {
|
|
|
onSubmitted() {
|
|
|
|
|
|
this.addRequestFrom.value['departments_ids'] = [];
|
|
|
+ const attachements = [];
|
|
|
|
|
|
for(let i = 0; i < this.departmentsId.length; i++) {
|
|
|
this.addRequestFrom.value['departments_ids'][i] = this.departmentsId[i];
|
|
|
}
|
|
|
+
|
|
|
+ this.checkSaveClick = true;
|
|
|
|
|
|
const editAttachements = [];
|
|
|
|
|
|
if(this.editMode) {
|
|
|
|
|
|
+ console.log('edit mode');
|
|
|
+
|
|
|
for(let i = 0; i < this.files.length; i++) {
|
|
|
for(let j = 0; j < this.attachments_ids.length; j++) {
|
|
|
if(this.files[i].id == this.attachments_ids[j]) {
|
|
@@ -273,54 +299,46 @@ export class AddRequestComponent implements OnInit {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
} else {
|
|
|
+ console.log('add mode');
|
|
|
+ console.log('files length before loop', this.files.length);
|
|
|
+
|
|
|
//remove fileName from files and remove file is empty
|
|
|
for(let i = 0; i < this.files.length; i++) {
|
|
|
//delete this.files[i].nameFile;
|
|
|
if(this.files[i].file_type){
|
|
|
this.files[i].file_type = this.files[i].file_type.toLowerCase();
|
|
|
}
|
|
|
- if(this.files[i].file == '') {
|
|
|
- //this.files.splice(this.files.indexOf(this.files[i], 1));
|
|
|
- console.log('empty number ' , i);
|
|
|
- this.files.splice(i , 1);
|
|
|
+ if(this.files[i].file != '') {
|
|
|
+ attachements.push(this.files[i]);
|
|
|
}
|
|
|
}
|
|
|
- console.log('after submitted form ', this.files);
|
|
|
- this.addRequestFrom.value['attachments'] = this.files; //add files to form json
|
|
|
+ this.addRequestFrom.value['attachments'] = attachements; //add files to form json
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
if(this.requestId) {
|
|
|
+
|
|
|
console.log('attachements ids after submitted' , this.attachments_ids);
|
|
|
|
|
|
//edit mode
|
|
|
if(this.departmentsId.length == 0) {
|
|
|
this.toastr.warning('من فضلك ، قم بإختيار قسم كحد أدني !');
|
|
|
+ this.checkSaveClick = false;
|
|
|
} else if(this.addRequestFrom.value['type'] == 'fellowship' && this.addRequestFrom.value['registration_number'] == '') {
|
|
|
this.toastr.warning('قم بإختيار رقم التسجيل !');
|
|
|
+ this.checkSaveClick = false;
|
|
|
} else if(this.addRequestFrom.value['type'] == 'fellowship' && this.addRequestFrom.value['authority_card_number'] == '') {
|
|
|
this.toastr.warning('قم بإختيار رقم البطاقه الهنيه !');
|
|
|
+ this.checkSaveClick = false;
|
|
|
} else if(this.addRequestFrom.value['type'] == 'fellowship' && this.addRequestFrom.value['functional_number'] == '') {
|
|
|
this.toastr.warning('قم بإختيار الرقم الوظيفي!');
|
|
|
+ this.checkSaveClick = false;
|
|
|
} else if(this.addRequestFrom.value['type'] == 'fellowship' && this.addRequestFrom.value['contract_type'] == '') {
|
|
|
this.toastr.warning('قم بإختيار نوع العقد !');
|
|
|
+ this.checkSaveClick = false;
|
|
|
} else if(this.addRequestFrom.value['type'] == 'fellowship' && this.addRequestFrom.value['organization_affiliated_with'] == '') {
|
|
|
this.toastr.warning('الجهه التابع لها المتدرب !');
|
|
|
+ this.checkSaveClick = false;
|
|
|
} else {
|
|
|
//store departments in object save
|
|
|
delete this.addRequestFrom.value['department1'];
|
|
@@ -337,6 +355,7 @@ export class AddRequestComponent implements OnInit {
|
|
|
for(let i = 0; i < editAttachements.length; i++) {
|
|
|
delete editAttachements[i].nameFile;
|
|
|
}
|
|
|
+
|
|
|
this.addRequestFrom.value['editable_attachments'] = editAttachements;
|
|
|
for(let i = 0; i < editAttachements.length; i++) {
|
|
|
for(let j = 0; j < this.files.length; j++) {
|
|
@@ -345,8 +364,22 @@ export class AddRequestComponent implements OnInit {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
this.addRequestFrom.value['editable_attachments'] = editAttachements;
|
|
|
- this.addRequestFrom.value['attachments'] = this.files;
|
|
|
+
|
|
|
+ const attach = [];//to add new attachements in edit mode
|
|
|
+ //remove fileName from files and remove file is empty
|
|
|
+ for(let i = 0; i < this.files.length; i++) {
|
|
|
+ //delete this.files[i].nameFile;
|
|
|
+ if(this.files[i].file_type){
|
|
|
+ this.files[i].file_type = this.files[i].file_type.toLowerCase();
|
|
|
+ }
|
|
|
+ if(this.files[i].file != '') {
|
|
|
+ attach.push(this.files[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.addRequestFrom.value['attachments'] = attach;
|
|
|
this.addRequestFrom.value['attachments_ids'] = this.attachments_ids;
|
|
|
|
|
|
console.log('attachements ids', this.attachments_ids);
|
|
@@ -357,24 +390,26 @@ export class AddRequestComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
|
|
- this.dashBoardSer.editItem(this.requestId, this.addRequestFrom.value,'request').subscribe(
|
|
|
- (responce) => {
|
|
|
- console.log(responce);
|
|
|
- this.toastr.success('تم التعديل بنحاج');
|
|
|
+ this.dashBoardSer.editItem(this.requestId, this.addRequestFrom.value,'request').subscribe(
|
|
|
+ (responce) => {
|
|
|
+ console.log(responce);
|
|
|
+ this.toastr.success('تم التعديل بنحاج');
|
|
|
+ this.location.back();
|
|
|
+ },
|
|
|
+ (error) => {
|
|
|
+ console.log(error);
|
|
|
+ console.log(error.error['error']);
|
|
|
+ if(error.error['error'] == 'can not add new request untill old one done') {
|
|
|
+ this.toastr.warning('لا يمكن التعديل طلب جديد ، حتي يتم إجراءات علي الطلب السابق ، شكراً');
|
|
|
+ this.checkSaveClick = false;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ this.toastr.error('يوجد مشكله في الحفظ ، سيتم معالجتها لاحقاً');
|
|
|
this.location.back();
|
|
|
- },
|
|
|
- (error) => {
|
|
|
- console.log(error);
|
|
|
- console.log(error.error['error']);
|
|
|
- if(error.error['error'] == 'can not add new request untill old one done') {
|
|
|
- this.toastr.warning('لا يمكن التعديل طلب جديد ، حتي يتم إجراءات علي الطلب السابق ، شكراً');
|
|
|
-
|
|
|
- } else {
|
|
|
- this.toastr.error('يوجد مشكله في السرفر ، سيتم معالجتها لاحقاً');
|
|
|
- this.location.back();
|
|
|
- }
|
|
|
+ this.checkSaveClick = false;
|
|
|
}
|
|
|
- );
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
} else {
|
|
|
|
|
@@ -382,51 +417,52 @@ export class AddRequestComponent implements OnInit {
|
|
|
//add mode
|
|
|
if(this.departmentsId.length == 0) {
|
|
|
this.toastr.warning('من فضلك ، قم بإختيار قسم كحد أدني !');
|
|
|
+ this.checkSaveClick = false;
|
|
|
} else if(this.addRequestFrom.value['type'] == 'fellowship' && this.addRequestFrom.value['registration_number'] == '') {
|
|
|
this.toastr.warning('قم بإختيار رقم التسجيل !');
|
|
|
+ this.checkSaveClick = false;
|
|
|
} else if(this.addRequestFrom.value['type'] == 'fellowship' && this.addRequestFrom.value['authority_card_number'] == '') {
|
|
|
this.toastr.warning('قم بإختيار رقم البطاقه الهنيه !');
|
|
|
+ this.checkSaveClick = false;
|
|
|
} else if(this.addRequestFrom.value['type'] == 'fellowship' && this.addRequestFrom.value['functional_number'] == '') {
|
|
|
this.toastr.warning('قم بإختيار الرقم الوظيفي!');
|
|
|
+ this.checkSaveClick = false;
|
|
|
} else if(this.addRequestFrom.value['type'] == 'fellowship' && this.addRequestFrom.value['contract_type'] == '') {
|
|
|
this.toastr.warning('قم بإختيار نوع العقد !');
|
|
|
+ this.checkSaveClick = false;
|
|
|
} else if(this.addRequestFrom.value['type'] == 'fellowship' && this.addRequestFrom.value['organization_affiliated_with'] == '') {
|
|
|
this.toastr.warning('الجهه التابع لها المتدرب !');
|
|
|
+ this.checkSaveClick = false;
|
|
|
} else {
|
|
|
|
|
|
+
|
|
|
//store departments in object save
|
|
|
- delete this.addRequestFrom.value['department1'];
|
|
|
- delete this.addRequestFrom.value['department2'];
|
|
|
- delete this.addRequestFrom.value['department3'];
|
|
|
- console.log('successsss save ' , this.addRequestFrom.value);
|
|
|
- this.dashBoardSer.addItem(this.addRequestFrom.value,'request').subscribe(
|
|
|
- (responce) => {
|
|
|
- console.log(responce);
|
|
|
- this.toastr.success('تم الإضافه بنحاج');
|
|
|
- this.addRequestFrom.reset();
|
|
|
- this.location.back();
|
|
|
- },
|
|
|
- (error) => {
|
|
|
- console.log(error);
|
|
|
- console.log(error.error['error']);
|
|
|
- if(error.error['error'] == 'can not add new request untill old one done') {
|
|
|
- this.toastr.warning('لا يمكن إضافه طلب جديد ، حتي يتم إجراءات علي الطلب السابق ، شكراً');
|
|
|
- } else {
|
|
|
- this.toastr.error('يوجد مشكله في السرفر ، سيتم معالجتها لاحقاً');
|
|
|
- }
|
|
|
+ delete this.addRequestFrom.value['department1'];
|
|
|
+ delete this.addRequestFrom.value['department2'];
|
|
|
+ delete this.addRequestFrom.value['department3'];
|
|
|
+ console.log('successsss save ' , this.addRequestFrom.value);
|
|
|
+ this.dashBoardSer.addItem(this.addRequestFrom.value,'request').subscribe(
|
|
|
+ (responce) => {
|
|
|
+ console.log(responce);
|
|
|
+ this.toastr.success('تم الإضافه بنحاج');
|
|
|
+ this.addRequestFrom.reset();
|
|
|
+ this.location.back();
|
|
|
+ },
|
|
|
+ (error) => {
|
|
|
+ console.log(error);
|
|
|
+ console.log(error.error['error']);
|
|
|
+ if(error.error['error'] == 'can not add new request untill old one done') {
|
|
|
+ this.toastr.warning('لا يمكن إضافه طلب جديد ، حتي يتم إجراءات علي الطلب السابق ، شكراً');
|
|
|
+ this.checkSaveClick = false;
|
|
|
+ } else {
|
|
|
+ this.toastr.error('يوجد مشكله في الحفظ ، سيتم معالجتها لاحقاً');
|
|
|
+ this.checkSaveClick = false;
|
|
|
}
|
|
|
- );
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- onKeyPress(event) {
|
|
|
- console.log(event.target.value);
|
|
|
- if(event.target.value < 0) {
|
|
|
- event.target.value = null;
|
|
|
- event.preventDefault();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|