Browse Source

Add Button to set Date/DateTime to Today/Now #6

pull/65/head
Sebastian Stehle 9 years ago
parent
commit
abb8a9318c
  1. 6
      src/Squidex/app/framework/angular/date-time-editor.component.html
  2. 4
      src/Squidex/app/framework/angular/date-time-editor.component.scss
  3. 18
      src/Squidex/app/framework/angular/date-time-editor.component.ts

6
src/Squidex/app/framework/angular/date-time-editor.component.html

@ -6,6 +6,12 @@
<div class="form-group time-group" *ngIf="showTime">
<input type="text" class="form-control" [formControl]="timeControl" (blur)="touched()" />
</div>
<div class="form-group" *ngIf="showTime">
<button class="btn btn-secondary" (click)="writeNow()">Now</button>
</div>
<div class="form-group" *ngIf="!showTime">
<button class="btn btn-secondary" (click)="writeNow()">Today</button>
</div>
<div class="form-group" [class.hidden]="!hasValue">
<button class="btn btn-link clear" [disabled]="isDisabled" (click)="reset()">Clear</button>
</div>

4
src/Squidex/app/framework/angular/date-time-editor.component.scss

@ -35,6 +35,10 @@ $form-color: #fff;
}
.time-group {
& {
padding-right: .25rem;
}
.form-control {
width: 7.5rem;
}

18
src/Squidex/app/framework/angular/date-time-editor.component.ts

@ -31,10 +31,6 @@ export class DateTimeEditorComponent implements ControlValueAccessor, OnInit, Af
private changeCallback: (value: any) => void = NOOP;
private touchedCallback: () => void = NOOP;
public get showTime() {
return this.mode === 'DateTime';
}
public timeControl = new FormControl();
public dateControl = new FormControl();
@ -45,6 +41,10 @@ export class DateTimeEditorComponent implements ControlValueAccessor, OnInit, Af
@Input()
public enforceTime: boolean;
public get showTime() {
return this.mode === 'DateTime';
}
public get hasValue() {
return this.dateValue !== null;
}
@ -133,6 +133,16 @@ export class DateTimeEditorComponent implements ControlValueAccessor, OnInit, Af
this.touchedCallback();
}
public writeNow() {
this.writeValue(new Date().toUTCString());
this.updateControls();
this.updateValue();
this.touched();
return false;
}
public reset() {
this.timeControl.setValue(null, { emitEvent: false });
this.dateControl.setValue(null, { emitEvent: false });

Loading…
Cancel
Save