summaryrefslogtreecommitdiffstats
path: root/app/common/components/alert-banner.js
blob: 13f79dad804959188212a6347c29bcc6e520d3c4 (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
49
50
51
52
53
54
55
56
57
58
59
60
window.angular && (function(angular) {
  'use strict';

  /**
   * alertBanner Component
   */


  /**
   * alertBanner Component controller
   */
  const controller = function() {
    this.status;
    this.$onInit = () => {
      switch (this.type) {
        case 'warn':
        case 'error':
          this.status = this.type;
          break;
        case 'success':
          this.status = 'on';
          break;
        default:
      }
    };
  };

  /**
   * alertBanner Component template
   */
  const template = `
    <div  class="alert-banner"
          ng-class="{
            'alert-banner--info': $ctrl.type === 'info',
            'alert-banner--warn': $ctrl.type === 'warn',
            'alert-banner--error': $ctrl.type === 'error',
            'alert-banner--success': $ctrl.type === 'success'}">
      <status-icon
        ng-if="$ctrl.type !== 'info'"
        status="{{$ctrl.status}}"
        class="status-icon">
      </status-icon>
      <ng-bind-html
        ng-bind-html="$ctrl.bannerText || ''">
      </ng-bind-html>
    </div>
  `

  /**
   * Register alertBanner component
   */
  angular.module('app.common.components').component('alertBanner', {
    template,
    controller,
    bindings: {
      type: '@',       // string 'info', 'warn', 'error' or 'success'
      bannerText: '<'  // string, can include valid HTML
    }
  })
})(window.angular);
OpenPOWER on IntegriCloud