2015-10-22 20:52:03 +03:00
|
|
|
'use strict';
|
|
|
|
|
2016-02-03 17:47:20 +03:00
|
|
|
import {Component, View, EventEmitter} from 'angular2/core';
|
2015-12-14 18:20:40 +03:00
|
|
|
import {CORE_DIRECTIVES} from 'angular2/common';
|
2015-10-22 20:52:03 +03:00
|
|
|
|
|
|
|
@Component({
|
2016-02-03 17:47:20 +03:00
|
|
|
selector: 'tabs',
|
|
|
|
events: ['change']
|
2015-10-22 20:52:03 +03:00
|
|
|
})
|
|
|
|
@View({
|
|
|
|
template: `
|
|
|
|
<ul>
|
2015-12-14 18:20:40 +03:00
|
|
|
<li *ngFor="#tab of tabs" [ngClass]="{active: tab.active}" (click)="selectTab(tab)"
|
2016-01-09 23:30:55 +03:00
|
|
|
class="tab-{{tab.tabStatus}}">{{tab.tabTitle}}</li>
|
2015-10-22 20:52:03 +03:00
|
|
|
</ul>
|
|
|
|
<ng-content></ng-content>
|
|
|
|
`,
|
|
|
|
directives: [CORE_DIRECTIVES],
|
2015-11-23 22:54:20 +03:00
|
|
|
styleUrls: ['./lib/common/components/Tabs/tabs.css']
|
2015-10-22 20:52:03 +03:00
|
|
|
})
|
|
|
|
export class Tabs {
|
|
|
|
constructor() {
|
|
|
|
this.tabs = [];
|
2016-02-03 17:47:20 +03:00
|
|
|
this.change = new EventEmitter();
|
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-02-03 17:47:20 +03:00
|
|
|
notify && this.change.next(tab.tabTitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
notify && this.change.next(tabTitle);
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'tab',
|
2015-12-14 18:20:40 +03:00
|
|
|
inputs: ['tabTitle', 'tabStatus']
|
2015-10-22 20:52:03 +03:00
|
|
|
})
|
|
|
|
@View({
|
|
|
|
template: `
|
|
|
|
<div class="tab-wrap" [hidden]="!active">
|
|
|
|
<ng-content></ng-content>
|
|
|
|
</div>
|
2015-10-30 11:26:23 +03:00
|
|
|
`
|
2015-10-22 20:52:03 +03:00
|
|
|
})
|
|
|
|
export class Tab {
|
|
|
|
constructor(tabs) {
|
2015-12-19 16:30:49 +03:00
|
|
|
this.active = false;
|
2015-10-22 20:52:03 +03:00
|
|
|
tabs.addTab(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Tab.parameters = [ [ Tabs ] ];
|