Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. import {Component} from 'angular2/core';
  2. import {CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/common';
  3. import {DATEPICKER_DIRECTIVES} from 'ng2-bootstrap/ng2-bootstrap';
  4. import {calendar} from "~moment/moment";
  5. import * as moment from 'moment';
  6.  
  7.  
  8. let template = 'components/calendar/calendar.html';
  9.  
  10. @Component({
  11. selector: 'calendar-demo',
  12. templateUrl: template,
  13. directives: [DATEPICKER_DIRECTIVES, CORE_DIRECTIVES, FORM_DIRECTIVES]
  14. })
  15. export class CalendarComponent {
  16. public dt:Date = new Date();
  17. public minDate:Date = void 0;
  18. public events:Array<any>;
  19. public tomorrow:Date;
  20. public afterTomorrow:Date;
  21. public formats:Array<string> = ['DD-MM-YYYY', 'YYYY/MM/DD', 'DD.MM.YYYY', 'shortDate'];
  22. public format:string = this.formats[0];
  23. public dateOptions:any = {
  24. formatYear: 'YY',
  25. startingDay: 1
  26. };
  27. private opened:boolean = false;
  28.  
  29. public constructor() {
  30. (this.tomorrow = new Date()).setDate(this.tomorrow.getDate() + 1);
  31. (this.afterTomorrow = new Date()).setDate(this.tomorrow.getDate() + 2);
  32. (this.minDate = new Date()).setDate(this.minDate.getDate() - 1000);
  33. this.events = [
  34. {date: this.tomorrow, status: 'full'},
  35. {date: this.afterTomorrow, status: 'partially'}
  36. ];
  37. }
  38. public getDate():number {
  39. return this.dt && this.dt.getTime() || new Date().getTime();
  40. }
  41. public today():void {
  42. this.dt = new Date();
  43. }
  44.  
  45. public d20090824():void {
  46. this.dt = moment('2009-08-24', 'YYYY-MM-DD').toDate();
  47. }
  48.  
  49. // todo: implement custom class cases
  50. public getDayClass(date:any, mode:string):string {
  51. if (mode === 'day') {
  52. let dayToCheck = new Date(date).setHours(0, 0, 0, 0);
  53.  
  54. for (let i = 0; i < this.events.length; i++) {
  55. let currentDay = new Date(this.events[i].date).setHours(0, 0, 0, 0);
  56.  
  57. if (dayToCheck === currentDay) {
  58. return this.events[i].status;
  59. }
  60. }
  61. }
  62.  
  63. return '';
  64. }
  65.  
  66. public disabled(date:Date, mode:string):boolean {
  67. return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
  68. }
  69.  
  70. public open():void {
  71. this.opened = !this.opened;
  72. }
  73.  
  74. public clear():void {
  75. this.dt = void 0;
  76. }
  77.  
  78. public toggleMin():void {
  79. this.dt = new Date(this.minDate.valueOf());
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement