2015-10-22 20:52:03 +03:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-15 21:48:04 +03:00
|
|
|
import { Component, EventEmitter, Input, Output, OnInit } from '@angular/core';
|
2016-05-18 16:59:54 +03:00
|
|
|
import { ChangeDetectorRef, ChangeDetectionStrategy } from '@angular/core';
|
2015-10-22 20:52:03 +03:00
|
|
|
|
|
|
|
@Component({
|
2016-02-03 17:47:20 +03:00
|
|
|
selector: 'tabs',
|
2017-01-07 19:23:08 +03:00
|
|
|
templateUrl: 'tabs.html',
|
2016-05-25 18:34:31 +03:00
|
|
|
styleUrls: ['tabs.css'],
|
2016-05-18 16:59:54 +03:00
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2015-10-22 20:52:03 +03:00
|
|
|
})
|
2016-06-15 21:48:04 +03:00
|
|
|
export class Tabs implements OnInit {
|
2016-05-25 18:34:31 +03:00
|
|
|
@Input() selected: any;
|
|
|
|
@Output() change = new EventEmitter();
|
|
|
|
tabs: Tab[] = [];
|
|
|
|
constructor(private changeDetector:ChangeDetectorRef) {}
|
2015-10-22 20:52:03 +03:00
|
|
|
|
2016-02-03 17:47:20 +03:00
|
|
|
selectTab(tab, notify = true) {
|
|
|
|
if (tab.active) return;
|
2015-10-22 20:52:03 +03:00
|
|
|
this.tabs.forEach((tab) => {
|
|
|
|
tab.active = false;
|
|
|
|
});
|
|
|
|
tab.active = true;
|
2016-06-13 20:54:24 +03:00
|
|
|
if (notify) this.change.next(tab.tabTitle);
|
2016-02-03 17:47:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
selectyByTitle(tabTitle, notify = false) {
|
|
|
|
let prevActive;
|
|
|
|
let newActive;
|
|
|
|
this.tabs.forEach((tab) => {
|
|
|
|
if (tab.active) prevActive = tab;
|
|
|
|
tab.active = false;
|
|
|
|
if (tab.tabTitle === tabTitle) {
|
|
|
|
newActive = tab;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (newActive) {
|
|
|
|
newActive.active = true;
|
|
|
|
} else {
|
|
|
|
prevActive.active = true;
|
|
|
|
}
|
2016-06-13 20:54:24 +03:00
|
|
|
if (notify) this.change.next(tabTitle);
|
2016-05-18 16:59:54 +03:00
|
|
|
this.changeDetector.markForCheck();
|
2015-10-22 20:52:03 +03:00
|
|
|
}
|
|
|
|
|
2015-12-13 13:38:39 +03:00
|
|
|
addTab(tab) {
|
2015-10-22 20:52:03 +03:00
|
|
|
if (this.tabs.length === 0) {
|
|
|
|
tab.active = true;
|
|
|
|
}
|
|
|
|
this.tabs.push(tab);
|
|
|
|
}
|
2016-05-18 16:59:54 +03:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
if (this.selected) this.selected.subscribe(title => this.selectyByTitle(title));
|
|
|
|
}
|
2015-10-22 20:52:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'tab',
|
2017-01-07 19:23:08 +03:00
|
|
|
templateUrl: 'tab.html',
|
|
|
|
styleUrls: ['tab.css']
|
2015-10-22 20:52:03 +03:00
|
|
|
})
|
|
|
|
export class Tab {
|
2016-05-25 18:34:31 +03:00
|
|
|
@Input() active: boolean = false;
|
|
|
|
@Input() tabTitle: string;
|
|
|
|
@Input() tabStatus: string;
|
|
|
|
constructor(tabs: Tabs) {
|
2015-10-22 20:52:03 +03:00
|
|
|
tabs.addTab(this);
|
|
|
|
}
|
|
|
|
}
|