2019-11-19 10:36:53 +01:00
|
|
|
import {ChangeDetectorRef, Component, Inject, OnInit} from '@angular/core';
|
2019-08-10 16:20:59 +02:00
|
|
|
import {ConfigService} from '../../config.service';
|
2019-08-10 16:57:36 +02:00
|
|
|
import {BaseComponent} from '../base-page/base.component';
|
2019-11-19 10:36:53 +01:00
|
|
|
import {DOCUMENT} from '@angular/common';
|
2019-08-10 16:20:59 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'framadate-dates',
|
|
|
|
templateUrl: './dates.component.html',
|
|
|
|
styleUrls: ['./dates.component.scss']
|
|
|
|
})
|
2019-08-10 16:57:36 +02:00
|
|
|
export class DatesComponent extends BaseComponent implements OnInit {
|
2019-11-19 10:36:53 +01:00
|
|
|
constructor(public config: ConfigService,
|
|
|
|
private cd: ChangeDetectorRef,
|
|
|
|
@Inject(DOCUMENT) private document: any
|
|
|
|
) {
|
2019-08-10 16:20:59 +02:00
|
|
|
super(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
}
|
|
|
|
|
|
|
|
addDate() {
|
2019-11-19 10:36:53 +01:00
|
|
|
this.config.dateList.push({literal: '', timeList: []});
|
2019-11-15 15:19:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
addtime() {
|
2019-11-19 10:36:53 +01:00
|
|
|
this.config.timeList.push({literal: '', timeList: []});
|
2019-11-15 15:19:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add a time period to a specific date choice,
|
|
|
|
* focus on the new input
|
|
|
|
* @param config
|
|
|
|
* @param id
|
|
|
|
*/
|
|
|
|
addTimetoDate(config: any, id: number) {
|
|
|
|
config.timeList.push({literal: ''});
|
|
|
|
let selector = '[ng-reflect-name="dateTime_' + id + '_Choices_' + (config.timeList.length - 1) + '"]';
|
|
|
|
console.log('selector', selector);
|
|
|
|
this.cd.detectChanges();
|
2019-11-19 10:36:53 +01:00
|
|
|
const elem = this.document.querySelector(selector);
|
2019-11-18 11:36:34 +01:00
|
|
|
if (elem) {
|
2019-11-19 10:36:53 +01:00
|
|
|
elem.focus();
|
2019-11-15 15:19:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
emptyAll() {
|
|
|
|
this.config.dateList.forEach(element => {
|
|
|
|
element.literal = '';
|
2019-11-19 10:36:53 +01:00
|
|
|
element.timeList = ['', '', ''];
|
|
|
|
});
|
|
|
|
this.config.timeList.forEach(element => {
|
|
|
|
element.literal = '';
|
2019-11-15 15:19:42 +01:00
|
|
|
});
|
2019-08-10 16:20:59 +02:00
|
|
|
}
|
|
|
|
}
|