PageSourceSearch

https://www.mysubaru.com/asset/_js/alertComponents.js

js mysubaru.com collected 2026-10-02 15:10:35 UTC 6,353 bytes, 185 lines download raw bytes

1"use strict";
2//Alert Component Objects
3// var dialogObject = {
4//     alertId: null,
5//     active: false,
6//     startDate: null,
7//     expireDate: null,
8//     seenDate: null,
9//     platforms: ['app','cwp'],
10//     frequency: 1,
11//     options: {
12//         alertType: 'dialog',
13//         heading: 'COVID-19 Update: Retailer Hours',
14//         content: 'The health and safety of our customers and communities is always our top priority. Please check your retailer\'s website for the latest updates on their response to COVID-19, including safety efforts and impacts to hours of operation. Keeping your vehicle maintained and running is an essential service, particularly for those on the front lines in healthcare and other critical areas. Now and always, we are here to help. For additional resources, contact our Customer Advocacy Department at 1(800) 782-2783.',
15//         button: 'Dismiss',
16//         pagesShown: {
17//           app: ['home'],
18//           cwp: ['home']
19//         }
20//     }
21// }
22
23// var overlayObject = {
24//     alertId: null,
25//     active: false,
26//     startDate: null,
27//     expireDate: null,
28//     seenDate: null,
29//     platforms: ['app'],
30//     frequency: 1,
31//     options: {
32//        alertType: 'overlay',
33//        heading: '',
34//        content: '',
35//        button: '',
36//        pagesShown: {
37//          app: ['home']
38//        }
39//     }
40// }
41
42// var alertBannerObject = {
43//     alertId: null,
44//     active: false,
45//     startDate: null,
46//     expireDate: null,
47//     seenDate: null,
48//     platforms: ['cwp'],
49//     frequency: 1,
50//     options: {
51//        alertType: 'overlay',
52//        heading: '',
53//        content: '',
54//        button: '',
55//        pagesShown: {
56//          app: ['home'],
57//          cwp: ['home']
58//        }
59//     }
60// }
61
62
63function AlertComponents() {
64  var _alertComponent = this;
65
66  //GMC-4847 this is dead code. no one calls it 
67  this.createAlert = function(alertObj) {
68    var sessionAlerts = store.get('newAlertComponents'),
69        duplicate = $.grep(sessionAlerts, function(e){ return e.alertId == alertObj.alertId; });
70
71    if (duplicate.length > 0) {
72        return false;
73    } else {
74      sessionAlerts.push(alertObj);
75      store.set('newAlertComponents',sessionAlerts);
76    }
77
78  };
79  
80  this.getActiveAlerts = function(){
81       //GMC-4847 
82       //this is not getting called on login and even if it is 
83       //this gets stored once and lasts forever, changes in database do not get updated reflected in browser
84       //commenting out if 
85       //	  if(store.get('newAlertComponents') == null || store.get('newAlertComponents').length == 0){		  
86          $.ajax({
87              type: 'GET',
88              url: '/account/mysAlerts.json',
89              async : false   //GMC-4847 setting this to wait for set result. otherwise further calls look at old data
90          }).done(function (json) {
91                if (json.success && json.data) {
92                    store.set('newAlertComponents',json.data);
93                }                
94	  });
95      //}
96  };
97
98  this.findActiveAlerts = function(){
99    //GMC-4847 add called below 
100    _alertComponent.getActiveAlerts();
101    var sessionAlerts = store.get('newAlertComponents');
102    if(sessionAlerts){
103		for (var i = 0; i < sessionAlerts.length; i++) {
104	        if(sessionAlerts[i].active) {
105	            _alertComponent.executeAlert(sessionAlerts[i].alertId);
106	        }
107	    }
108    }
109  };
110
111  this.executeAlert = function(alertObjId) {
112        var sessionAlerts = store.get('newAlertComponents'),
113            alertObjArray = $.grep(sessionAlerts, function(e){ return e.alertId == alertObjId; }),
114            completedAlerts = store.get('completedAlertComponents'),
115            completedObjArray = completedAlerts ? $.grep(completedAlerts, function(e){ return e.alertId == alertObjId; }) : [],
116            currentDate = new Date();
117        
118        //AlertObjArray is an array with the same alertObjId
119        //completedObjArray is an array of the completed alerts that have the same alertObjId as the alert we are trying to execute
120        try {
121        if (alertObjArray.length === 1) {
122          //This is to make sure there is only one unique command to make sure UI doesn't prompt multiple times or duplicates alerts
123          if(completedObjArray.length < 1) {
124            //This is to make sure it wasn't already executed
125            var alertObj = alertObjArray[0];
126            var	optionsObj = JSON.parse(alertObj.options);
127            var pageUrl = window.location.pathname;
128
129            if($.inArray(pageUrl,optionsObj.pagesShown) > -1) {
130                if(optionsObj.alertType == 'dialog'){
131                    _alertComponent.showDialog(alertObj);
132                } else if (optionsObj.alertType == 'alertBanner') {
133                    _alertComponent.showAlertBanner(alertObj);
134                } else {
135                    return false;
136                }
137            }
138          } else {
139            return false;
140          }
141        } else {
142          return false;
143        }
144        } catch (error) {
145             console.error(error);
146        }
147  };
148
149  this.setAlertSeen = function(alertObj) {
150        var completedAlerts = store.get('completedAlertComponents'),
151            currentDate = new Date();
152
153            completedAlerts = completedAlerts ?  $.grep(completedAlerts, function(e){ return e.alertId != alertObj.alertId; }) : [];
154
155            alertObj.seenDate = currentDate.toString();
156
157            completedAlerts.push(alertObj);
158
159            store.set('completedAlertComponents',completedAlerts);
160
161  };
162
163  this.showDialog = function(nativeDialogObject) {
164	  var optionsObj = JSON.parse(nativeDialogObject.options);  
165	  if(nativeDialogObject.frequency > 0){
166		  _alertComponent.setAlertSeen(nativeDialogObject);
167	  }
168    commonModal(optionsObj.heading, optionsObj.content, optionsObj.button, null);
169  };
170
171  this.showAlertBanner = function(alertObj){
172	  var optionsObj = JSON.parse(alertObj.options);  
173	  if(alertObj.frequency > 0){
174		  _alertComponent.setAlertSeen(alertObj);
175	  }
176    $('.alertComponent').html('<div class="alert alert-warning text-gray-dark mb-0 boder-radius--0">' +
177        '<div class="max-container">' +
178            '<strong>' + optionsObj.heading + '</strong><br>' +
179            optionsObj.content +
180        '</div>' +
181      '</div>'
182    );
183  }
184
185}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.