@@ -12,32 +12,22 @@ import {Ng2Datetime} from './ng2-datetime';
12
12
13
13
declare var moment : any ;
14
14
15
- //@TODO
16
- // . display currently selected day
17
-
18
- /**
19
- * show a selected date in monthly calendar
20
- */
21
- @Component ( {
22
- providers : [ Ng2Datetime ] ,
23
- selector : 'ng2-datetime-picker' ,
24
- template : `
25
- <div class="closing-layer" (click)="close()" *ngIf="showCloseLayer" ></div>
26
- <div class="ng2-datetime-picker">
27
- <div class="close-button" *ngIf="showCloseButton" (click)="close()"></div>
28
-
29
- <!-- Month - Year -->
15
+ let monthYearHTML : string = `
30
16
<div class="month" *ngIf="!timeOnly">
31
17
<b class="prev_next prev year" (click)="updateMonthData(-12)">«</b>
32
18
<b class="prev_next prev month" (click)="updateMonthData(-1)">‹</b>
33
19
<span title="{{monthData?.fullName}}">
34
- {{monthData?.shortName}}
20
+ {{monthData?.shortName}}
21
+ </span>
22
+ <span (click)="showYearSelector = true">
23
+ {{monthData.year}}
35
24
</span>
36
- {{monthData.year}}
37
25
<b class="prev_next next year" (click)="updateMonthData(+12)">»</b>
38
26
<b class="prev_next next month" (click)="updateMonthData(+1)">›</b>
39
27
</div>
28
+ ` ;
40
29
30
+ let daysHTML : string = `
41
31
<div class="week-numbers-and-days"
42
32
[ngClass]="{'show-week-numbers': !timeOnly && showWeekNumbers}">
43
33
<!-- Week -->
@@ -90,12 +80,9 @@ declare var moment: any;
90
80
</div>
91
81
</div>
92
82
</div>
83
+ ` ;
93
84
94
- <div class="shortcuts" *ngIf="showTodayShortcut">
95
- <a href="#" (click)="selectToday()">Today</a>
96
- </div>
97
-
98
- <!-- Time -->
85
+ let timeHTML : string = `
99
86
<div class="time" id="time" *ngIf="!dateOnly">
100
87
<div class="select-current-time" (click)="selectCurrentTime()">{{locale.currentTime}}</div>
101
88
<label class="timeLabel">{{locale.time}}</label>
@@ -121,6 +108,50 @@ declare var moment: any;
121
108
type="range" min="0" max="59" range="10" [(ngModel)]="minute"/>
122
109
</div>
123
110
</div>
111
+ ` ;
112
+
113
+ let yearSelectorHTML : string = `
114
+ <div class="year-selector" *ngIf="showYearSelector">
115
+ <div class="locale">
116
+ <b>{{locale.year}}</b>
117
+ </div>
118
+ <span class="year"
119
+ *ngFor="let year of yearsSelectable"
120
+ (click)="selectYear(year)">
121
+ {{year}}
122
+ </span>
123
+ </div>
124
+ ` ;
125
+
126
+ //@TODO
127
+ // . display currently selected day
128
+
129
+ /**
130
+ * show a selected date in monthly calendar
131
+ */
132
+ @Component ( {
133
+ providers : [ Ng2Datetime ] ,
134
+ selector : 'ng2-datetime-picker' ,
135
+ template : `
136
+ <div class="closing-layer" (click)="close()" *ngIf="showCloseLayer" ></div>
137
+ <div class="ng2-datetime-picker">
138
+ <div class="close-button" *ngIf="showCloseButton" (click)="close()"></div>
139
+
140
+ <!-- Month - Year -->
141
+ ${ monthYearHTML }
142
+
143
+ <!-- Week number / Days -->
144
+ ${ daysHTML }
145
+
146
+ <div class="shortcuts" *ngIf="showTodayShortcut">
147
+ <a href="#" (click)="selectToday()">Today</a>
148
+ </div>
149
+
150
+ <!-- Hour Minute -->
151
+ ${ timeHTML }
152
+
153
+ <!-- Year Selector -->
154
+ ${ yearSelectorHTML }
124
155
</div>
125
156
` ,
126
157
styles : [
@@ -270,6 +301,27 @@ declare var moment: any;
270
301
padding: 10px;
271
302
text-transform: Capitalize;
272
303
}
304
+ .ng2-datetime-picker .year-selector {
305
+ position: absolute;
306
+ top: 0;
307
+ left: 0;
308
+ background: #fff;
309
+ height: 100%;
310
+ overflow: auto;
311
+ padding: 5px;
312
+ z-index: 2;
313
+ }
314
+ .ng2-datetime-picker .year-selector .locale{
315
+ text-align: center;
316
+ }
317
+ .ng2-datetime-picker .year-selector .year {
318
+ display: inline-block;
319
+ cursor: pointer;
320
+ padding: 2px 5px;
321
+ }
322
+ .ng2-datetime-picker .year-selector .year:hover {
323
+ background-color: #ddd;
324
+ }
273
325
.ng2-datetime-picker .select-current-time {
274
326
position: absolute;
275
327
top: 1em;
@@ -362,6 +414,8 @@ export class Ng2DatetimePickerComponent {
362
414
public el :HTMLElement ; // this component element
363
415
public disabledDatesInTime : number [ ] ;
364
416
public locale = Ng2Datetime . locale ;
417
+ public showYearSelector = false ;
418
+
365
419
private _monthData : any ;
366
420
367
421
public constructor (
@@ -372,6 +426,16 @@ export class Ng2DatetimePickerComponent {
372
426
this . el = elementRef . nativeElement ;
373
427
}
374
428
429
+ public get yearsSelectable ( ) : number [ ] {
430
+ let startYear = this . year - 100 ;
431
+ let endYear = this . year + 50 ;
432
+ let years : number [ ] = [ ] ;
433
+ for ( let year = startYear ; year < endYear ; year ++ ) {
434
+ years . push ( year ) ;
435
+ }
436
+ return years ;
437
+ }
438
+
375
439
public get year ( ) : number {
376
440
return this . selectedDate . getFullYear ( ) ;
377
441
}
@@ -397,21 +461,11 @@ export class Ng2DatetimePickerComponent {
397
461
return dt ;
398
462
}
399
463
400
- public isWeekend ( dayNum : number , month ?: number ) : boolean {
401
- if ( typeof month === 'undefined' ) {
402
- return Ng2Datetime . weekends . indexOf ( dayNum % 7 ) !== - 1 ; //weekday index
403
- } else {
404
- let weekday = this . toDate ( dayNum , month ) . getDay ( ) ;
405
- return Ng2Datetime . weekends . indexOf ( weekday ) !== - 1 ;
406
- }
407
- }
408
-
409
464
public set year ( year ) { }
410
465
public set month ( month ) { }
411
466
public set day ( day ) { }
412
467
public set today ( today ) { }
413
468
414
-
415
469
public ngOnInit ( ) {
416
470
if ( ! this . defaultValue || isNaN ( this . defaultValue . getTime ( ) ) ) {
417
471
this . defaultValue = new Date ( ) ;
@@ -431,6 +485,20 @@ export class Ng2DatetimePickerComponent {
431
485
this . _monthData = this . ng2Datetime . getMonthData ( this . year , this . month ) ;
432
486
}
433
487
488
+ public isWeekend ( dayNum : number , month ?: number ) : boolean {
489
+ if ( typeof month === 'undefined' ) {
490
+ return Ng2Datetime . weekends . indexOf ( dayNum % 7 ) !== - 1 ; //weekday index
491
+ } else {
492
+ let weekday = this . toDate ( dayNum , month ) . getDay ( ) ;
493
+ return Ng2Datetime . weekends . indexOf ( weekday ) !== - 1 ;
494
+ }
495
+ }
496
+
497
+ public selectYear ( year ) {
498
+ this . _monthData = this . ng2Datetime . getMonthData ( year , this . _monthData . month ) ;
499
+ this . showYearSelector = false ;
500
+ }
501
+
434
502
public toDate ( day :number , month ?: number ) :Date {
435
503
return new Date ( this . _monthData . year , month || this . _monthData . month , day ) ;
436
504
}
0 commit comments