-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathplot.js
More file actions
150 lines (125 loc) · 5.72 KB
/
plot.js
File metadata and controls
150 lines (125 loc) · 5.72 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
cordova.define("cordova/plugin/plot", function (require, exports, module) {
plot = {};
plot.exampleConfiguration = {"publicKey": "", "cooldownPeriod": -1, "enableOnFirstRun": true};
/*
Notification: {id: …, message: …, data: …}
*/
function identityFilterCallback(notifications) {
return notifications;
}
function defaultNotificationHandler(notification, data) {
cordova.exec(undefined, undefined, "PlotCordovaPlugin", "defaultNotificationHandler", [notification, data]);
}
function logError(errorMessage) {
if (errorMessage && console && console.error) {
console.error("Plot Error: " + errorMessage);
}
}
//only works on IOS
plot.filterCallback = identityFilterCallback;
plot.notificationHandler = defaultNotificationHandler;
plot._runNotificationHandler = function (notification) {
plot.notificationHandler(notification, notification.data);
};
plot._runFilterCallback = function (notifications) {
var result = plot.filterCallback(notifications);
cordova.exec(undefined, undefined, "PlotCordovaPlugin", "filterCallbackComplete", [result]);
};
plot.init = function (configuration, successCallback, failureCallback) {
if (configuration === undefined || configuration === null) {
configuration = {};
}
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "initPlot", [configuration]);
};
plot.enable = function (successCallback, failureCallback) {
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "enable", []);
};
plot.disable = function (successCallback, failureCallback) {
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "disable", []);
};
plot.isEnabled = function (successCallback, failureCallback) {
if (!successCallback) {
logError("No resultCallback specified for isEnabled");
}
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "isEnabled", []);
};
plot.getVersion = function (successCallback, failureCallback) {
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "getVersion", []);
};
plot.loadedNotifications = function (successCallback, failureCallback) {
if (!successCallback) {
logError("No resultCallback specified for loadedNotifications");
}
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "loadedNotifications", []);
};
plot.loadedGeotriggers = function (successCallback, failureCallback) {
if (!successCallback) {
logError("No resultCallback specified for loadedGeotriggers");
}
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "loadedGeotriggers", []);
};
plot.setStringSegmentationProperty = function (property, value, successCallback, failureCallback) {
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "setStringSegmentationProperty", [property, value]);
};
plot.setBooleanSegmentationProperty = function (property, value, successCallback, failureCallback) {
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "setBooleanSegmentationProperty", [property, value]);
};
plot.setIntegerSegmentationProperty = function (property, value, successCallback, failureCallback) {
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "setIntegerSegmentationProperty", [property, value]);
};
plot.setDoubleSegmentationProperty = function (property, value, successCallback, failureCallback) {
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "setDoubleSegmentationProperty", [property, value]);
};
plot.setDateSegmentationProperty = function (property, value, successCallback, failureCallback) {
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "setDateSegmentationProperty", [property, value]);
};
function replaceDateField(fields, fieldName) {
if (Array.isArray(fields)) {
for (var i = 0; i < fields.length; i++) {
replaceDateField(fields[i], fieldName);
}
return;
}
var value = fields[fieldName];
if (value === undefined || value < 0) {
fields[fieldName] = null;
} else {
var newDate = new Date();
newDate.setTime(value);
fields[fieldName] = newDate;
}
}
plot.sentNotifications = function (successCallback, failureCallback) {
if (!successCallback) {
logError("No resultCallback specified for sentNotifications");
}
var callback = function (result) {
replaceDateField(result, "dateSent");
replaceDateField(result, "dateOpened");
successCallback(result);
};
cordova.exec(callback, failureCallback, "PlotCordovaPlugin", "sentNotifications", []);
};
plot.sentGeotriggers = function (successCallback, failureCallback) {
if (!successCallback) {
logError("No resultCallback specified for sentGeotriggers");
}
var callback = function (result) {
replaceDateField(result, "dateSent");
replaceDateField(result, "dateHandled");
successCallback(result);
};
cordova.exec(callback, failureCallback, "PlotCordovaPlugin", "sentGeotriggers", []);
};
plot.clearSentNotifications = function (successCallback, failureCallback) {
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "clearSentNotifications", []);
};
plot.clearSentGeotriggers = function (successCallback, failureCallback) {
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "clearSentGeotriggers", []);
};
//The data for the debug log on iOS is only collected when the DEBUG preprocessor macro is set.
plot.mailDebugLog = function (successCallback, failureCallback) {
cordova.exec(successCallback, failureCallback, "PlotCordovaPlugin", "mailDebugLog", []);
};
module.exports = plot;
});