blob: 037abb198a89c6d14ab740399a0bfad0e52099d0 [file] [log] [blame]
Matteo Scandolo6f45e262017-01-09 14:47:26 -08001export interface IXosAlertConfig {
2 type: string;
3 closeBtn?: boolean;
4 autoHide?: number;
5}
6
7class AlertCtrl {
8
9 static $inject = ['$timeout'];
10
Matteo Scandoloac8c8c22017-01-09 15:04:32 -080011 public config: IXosAlertConfig;
Matteo Scandolo6f45e262017-01-09 14:47:26 -080012 public show: boolean;
13 public dismiss: () => void;
14
15 constructor (
16 private $timeout: ng.ITimeoutService
17 ) {
18
19 }
20
21 $onInit() {
22 if (!angular.isDefined(this.config)) {
23 throw new Error('[xosAlert] Please provide a configuration via the "config" attribute');
24 }
25
26 // default the value to true
27 this.show = this.show !== false;
28
29 this.dismiss = () => {
30 this.show = false;
31 };
32
Matteo Scandolo6f45e262017-01-09 14:47:26 -080033 if (this.config.autoHide) {
34
35 let to = this.$timeout(() => {
36 this.dismiss();
37 this.$timeout.cancel(to);
38 }, this.config.autoHide);
39 }
40 }
41}
42
43export const xosAlert: angular.IComponentOptions = {
44 template: require('./alert.html'),
45 controllerAs: 'vm',
46 controller: AlertCtrl,
47 transclude: true,
48 bindings: {
49 config: '=',
50 show: '=',
51 }
52};