All files / src/fieldcontrols DateOnly.ts

100% Statements 15/15
100% Branches 2/2
100% Functions 4/4
100% Lines 13/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48          1x 1x   1x 1x 1x 1x                         1x   5x 5x             5x       1x     3x       1x    
/**
 * @module FieldControls
 * 
 */ /** */
 
import { autoinject, customElement, bindable } from 'aurelia-framework'
import { FieldBaseControl } from './FieldBaseControl';
import { FieldSettings } from 'sn-client-js';
import { LocaleService } from '../services';
import { MDCTextField } from '@material/textfield/dist/mdc.textfield';
import 'moment';
import * as moment from 'moment-timezone';
 
 
/**
 * Field control that represents a Date Picker. Formatting will be done based on the LocaleService
 * Usage:
 * 
 * ``` html
 * <date-only content.bind="content" settings.bind="myDateTimeFieldSettings"></date-only>
 * ```
 */
@autoinject
@customElement('date-only')
export class DateOnly extends FieldBaseControl<string, FieldSettings.DateTimeFieldSetting> {
 
    constructor(private localeService: LocaleService) {
        super();
    }
 
    datefield: HTMLElement;
    mdcDateField: MDCTextField;
 
    attached(){
        this.mdcDateField = new MDCTextField(this.datefield);
    }
 
    @bindable
    public dateValue: string;
 
    public dateValueChanged(newValue){
        this.value = newValue && moment(newValue).format('YYYY-MM-DDT00:00:00') + 'Z';
    }
 
    public valueChanged(newValue){
        this.dateValue = moment(this.value).format(this.localeService.DateFormat)
    }
}