aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/directives/sdc-tabs/sdc-tabs-directive.ts
blob: 1567bfba5385b6672e1c43fc2105d66f7eb73926 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * Created by obarda on 7/28/2016.
 */
'use strict';
import {Tab} from "app/models";

export interface ISdcTabsDirectiveScope extends ng.IScope {
    tabs:Array<Tab>;
    selectedTab:Tab;
    isActive:boolean;
    onTabSelected(selectedTab:Tab);
}

export class SdcTabsDirective implements ng.IDirective {

    constructor() {
    }

    scope = {
        tabs: "=",
        selectedTab: "=?",
        isViewOnly: "="
    };

    replace = true;
    restrict = 'E';
    template = ():string => {
        return require('./sdc-tabs-directive-view.html');
    };

    link = (scope:ISdcTabsDirectiveScope) => {
        scope.isActive = true;

        if (!scope.selectedTab) {
            scope.selectedTab = scope.tabs[0];
        }

        scope.onTabSelected = (selectedTab:Tab) => {
            scope.selectedTab = selectedTab;
        }
    };

    public static factory = ()=> {
        return new SdcTabsDirective();
    };
}

SdcTabsDirective.factory.$inject = [];