123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- import { HttpClient } from '@angular/common/http';
- import { NgxSpinnerService } from 'ngx-spinner';
- import { ActivatedRoute, Params } from '@angular/router';
- import { Location } from '@angular/common';
- import { AuthServiceService } from './../../../shared/auth-service.service';
- import { ToastrService } from 'ngx-toastr';
- import { DashboardService } from './../../../shared/dashboard.service';
- import { Component, OnInit, ViewChild } from '@angular/core';
- import { NgForm } from '@angular/forms';
- @Component({
- selector: 'app-definition-of-covenants-add',
- templateUrl: './definition-of-covenants-add.component.html',
- styleUrls: ['./definition-of-covenants-add.component.css']
- })
- export class DefinitionOfCovenantsAddComponent implements OnInit {
- constructor(
- private dashBoardSer: DashboardService,
- private toastr: ToastrService,
- public authSer: AuthServiceService,
- private route: ActivatedRoute,
- private spinner: NgxSpinnerService,
- private location: Location,
- private http: HttpClient
- ) { }
- @ViewChild('f') definitionForm : NgForm;
- typePage: string = '';
- valueType: string = '';
- editPageId: number;
- locations =[];
- categories = [];
-
- checkSaveclick:boolean = false;
- check : boolean = false;
- isEdit: boolean = false;
- disable: boolean = false;
- formData = {
- name: '',
- category_id:'',
- amount:'',
- status: '1',
- }
- ngOnInit() {
- this.route.params.subscribe(
- (params: Params) => {
- this.editPageId = +params['listPageEditId'];;
- console.log(this.editPageId);
- }
- );
- this.http.get(this.authSer.pathApi + '/get_covenant_categories_list')
- .subscribe(
- res => {
- console.log('gg', res);
- this.categories = res[('covenant_categories')];
- },
- err =>{
- console.log(err);
-
- }
- );
- if (this.editPageId) {
- this.spinner.show();
- this.isEdit = true;
- this.typePage = 'تعديل';
- this.dashBoardSer.getItemData(this.editPageId, 'definitionOfCovenant' ).subscribe(
- res => {
- console.log('ssss', res);
- this.formData.name = res['covenant'].name;
- this.formData.category_id = res[('covenant')].category_id;
- this.formData.amount = res[('covenant')].amount;
- this.formData.status = res['covenant'].status;
- this.spinner.hide();
- },
- err => {
- console.log(err);
- }
- );
- }else {
- this.typePage = 'اضافة';
- }
-
- }
- onSubmitted(){
- this.disable = true;
- console.log('HERE',this.definitionForm.value);
- if(this.editPageId) {
- this.dashBoardSer.editItem(this.editPageId, this.definitionForm.value, 'definitionOfCovenant').subscribe(
- res => {
- console.log(res);
- this.disable = false;
- this.toastr.success('تم التعديل بنجاح');
- this.location.back();
- this.disable = false;
- },
- err => {
- console.log(err);
- this.toastr.error('خطأ في الخادم ، رجاء المحارله لاحقا');
- }
- )
- } else {
- this.dashBoardSer.addItem( this.definitionForm.value , 'definitionOfCovenant').subscribe(
- res => {
- console.log('ADD',res);
- this.disable = false;
- this.toastr.success('تم الإضافه بنجاح');
- this.checkSaveclick = false;
- this.location.back();
- },
- err => {
- console.log(err);
- this.checkSaveclick = false;
- this.toastr.error('خطأ في الخادم ، حاول لاحقا');
- this.disable = false;
- }
- );
- }
- }
- }
|