123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import { DashboardService } from './../../../shared/dashboard.service';
- import { AuthServiceService } from './../../../shared/auth-service.service';
- import { UserService } from './../../../shared/user.service';
- import { ActivatedRoute, Params } from '@angular/router';
- import { ToastrService } from 'ngx-toastr';
- import { Location } from '@angular/common';
- import { Component, OnInit, ViewChild } from '@angular/core';
- import { NgForm } from '@angular/forms';
- import { NgxSpinnerService } from 'ngx-spinner';
- @Component({
- selector: 'app-add-bar-event',
- templateUrl: './add-bar-event.component.html',
- styleUrls: ['./add-bar-event.component.css']
- })
- export class AddBarEventComponent implements OnInit {
- @ViewChild('f') dataForm: NgForm;
- constructor(private userSer:UserService,
- private authSer:AuthServiceService,
- private toastr: ToastrService,
- private spinner: NgxSpinnerService,
- private dashboardSer: DashboardService,
- private location: Location,
- private route:ActivatedRoute) { }
- typeMode:boolean = false; //default false for create page
- typeLink: string;
- barEventId:number;
- checkDisabledSave:boolean = false;
- barEvent = {
- name: '',
- name_en: '',
- description: '',
- description_en: '',
- status: 1,
- };
- higriDateVal = "";
- bindingDateSplit:any;
- ngOnInit() {
- this.route.params.subscribe(
- (params: Params) => {
- if(params['typeEventBar'] == 'add'){
- this.typeMode = false;
- this.typeLink = 'إنشاء حدث';
- } else if(params['typeEventBar'] == 'edit') {
- this.spinner.show();
- this.typeMode = true;
- this.barEventId = parseInt(localStorage.getItem('editbarEventIdStorage'));
- //alert(this.barEventId);
- this.typeLink = 'تعديل حدث';
- this.dashboardSer.getItemData(this.barEventId, 'barEvent').subscribe(
- (responce) => {
- console.log(responce);
- this.barEvent = responce['event'];
- console.log(this.barEvent);
- const date = responce['event'].event_time.split('-');
- this.bindingDateSplit = {
- year: parseInt(date[0]),
- month: parseInt(date[1]),
- day: parseInt(date[2])
- };
- this.higriDateVal = this.bindingDateSplit.year + '-' + this.bindingDateSplit.month + '-' + this.bindingDateSplit.day;
- this.spinner.hide();
- },
- (error) => {
- console.log(error);
- }
- );
- } else {
- this.toastr.warning('Catch Error Go To Home !');
- }
- }
- );
- }//ngOnInit
- //get value date from child component
- public getDate(date: any):void {
- console.log( date);
- this.higriDateVal = date.year + '-' + date.month + '-' + date.day;
- console.log('higrii date', this.higriDateVal);
- }
- onSubmitted() {
- this.checkDisabledSave = true;
- const dataFormEventBar = this.dataForm.value;
- dataFormEventBar['event_time'] = this.higriDateVal;
- console.log(dataFormEventBar);
- if(this.typeMode) {
- this.dashboardSer.editItem(dataFormEventBar, this.barEventId, 'barEvent').subscribe(
- (responce) => {
- console.log(responce);
- this.toastr.success('تم التعديل بنجاح ');
- this.checkDisabledSave = false;
- this.location.back();
- },
- (error) => {
- console.log(error);
- this.checkDisabledSave = false;
- this.toastr.error(' خطأ في التعديل !');
- }
- );
- } else {
- this.dashboardSer.addItem(dataFormEventBar,'barEvent').subscribe(
- (responce) => {
- this.toastr.success('تم الاضافه بنجاح');
- this.checkDisabledSave = false;
- console.log(responce);
- this.location.back();
- },
- (error) => {
- console.log(error);
- this.checkDisabledSave = false;
- this.toastr.error('خطأ في الاضافه');
- }
- );
- }
- }
- }
|