This repository was archived by the owner on Mar 26, 2020. It is now read-only.
forked from zendesk/support_sdk_metadata_app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
83 lines (60 loc) · 2.86 KB
/
app.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(function() {
return {
// REQUESTS ========================================================================
requests: {
fetchTicketAudits: function () {
return {
url: '/api/v2/tickets/' + this.ticket().id() + '/audits.json',
type: 'GET'
};
},
},
// EVENTS ==========================================================================
events: {
'app.activated':'init',
'fetchTicketAudits.done':'findSDKAudit',
'fetchTicketAudits.fail':'showErrorMessage',
'iframe.registered':'processSDKProperties'
},
// EVENT HANDLERS ==================================================================
init: function() {
this.switchTo('loading');
this.ajax('fetchTicketAudits');
},
findSDKAudit: function (data) {
var audits = data.audits;
// Check for a ticket audit completed through the mobile_sdk channel
this.sdk_audit = _.find(audits, function (audit) {
return audit.via.channel === 'mobile_sdk';
}, this);
if (typeof this.sdk_audit !== 'undefined') { this.parseClient(this.sdk_audit); } else { this.hide(); }
},
parseClient: function () {
// Prepare the client information for template
this.client = this.sdk_audit.metadata.system.client;
if(this.client.indexOf('iOS') > -1){ this.os = "iOS"; } else{ this.os = "Android"; }
if(this.client.indexOf('Unity') > -1){ this.unity = true; } else{ this.unity = false; }
if(this.unity){ this.sdk = "Unity Plugin for " + this.os; } else{ this.sdk = "Zendesk Support SDK for " + this.os; }
var regex = /(\d{1,2}\.\d{1,2}\.\d{1,2}\.\d{1,2})/;
var version = regex.exec(this.client);
if (version != null) { this.sdk += " v" + version[0]; }
// Unity 1.0 and 1.1 Plugins are the only SDKs that do not have a version number in the client metadata
else { this.unity = true; this.sdk += " Unity Plugin (v1.0, v1.1)"; }
this.loadView();
},
loadView: function () {
this.system = this.sdk_audit.metadata.system;
if (this.sdk_audit.metadata.custom.hasOwnProperty('sdk')) { this.device = this.sdk_audit.metadata.custom.sdk; }
// Display the core template that displays common metadata across all SDKs (sdk_audit.metadata.system)
this.switchTo('system', {system: this.system, sdk: this.sdk });
// Use renderTemplate(templateName, data) to load metadata into template then insert into system.hdbs
var template;
if (this.os === 'Android') { template = 'android-device'; } else { template = 'ios-device'; }
var deviceTemplate = this.renderTemplate(template, { device: this.device, isUnity: this.unity });
this.$('#device').html(deviceTemplate);
},
showErrorMessage: function () {
this.switchTo('error', 'message: There was an error or there were no mobile audits.');
}
};
}());