]> git.proxmox.com Git - extjs.git/blame - extjs/packages/legacy/modern/src/device/push/Abstract.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / legacy / modern / src / device / push / Abstract.js
CommitLineData
6527f429
DM
1/**\r
2 * @private\r
3 */\r
4Ext.define('Ext.device.push.Abstract', {\r
5 /**\r
6 * @property\r
7 * Notification type: alert.\r
8 */\r
9 ALERT: 1,\r
10 /**\r
11 * @property\r
12 * Notification type: badge.\r
13 */\r
14 BADGE: 2,\r
15 /**\r
16 * @property\r
17 * Notification type: sound.\r
18 */\r
19 SOUND: 4,\r
20\r
21 /**\r
22 * @method getInitialConfig\r
23 * @hide\r
24 */\r
25\r
26 /**\r
27 * Registers a push notification.\r
28 *\r
29 * Ext.device.Push.register({\r
30 * type: Ext.device.Push.ALERT|Ext.device.Push.BADGE|Ext.device.Push.SOUND,\r
31 * success: function(token) {\r
32 * console.log('# Push notification registration successful:');\r
33 * console.log(' token: ' + token);\r
34 * },\r
35 * failure: function(error) {\r
36 * console.log('# Push notification registration unsuccessful:');\r
37 * console.log(' error: ' + error);\r
38 * },\r
39 * received: function(notifications) {\r
40 * console.log('# Push notification received:');\r
41 * console.log(' ' + JSON.stringify(notifications));\r
42 * }\r
43 * });\r
44 *\r
45 * @param {Object} config\r
46 * The configuration for to pass when registering this push notification service.\r
47 *\r
48 * @param {Number} config.type\r
49 * The type(s) of notifications to enable. Available options are:\r
50 *\r
51 * - {@link Ext.device.Push#ALERT}\r
52 * - {@link Ext.device.Push#BADGE}\r
53 * - {@link Ext.device.Push#SOUND}\r
54 *\r
55 * **Usage**\r
56 *\r
57 * Enable alerts and badges:\r
58 *\r
59 * Ext.device.Push.register({\r
60 * type: Ext.device.Push.ALERT|Ext.device.Push.BADGE\r
61 * // ...\r
62 * });\r
63 *\r
64 * Enable alerts, badges and sounds:\r
65 *\r
66 * Ext.device.Push.register({\r
67 * type: Ext.device.Push.ALERT|Ext.device.Push.BADGE|Ext.device.Push.SOUND\r
68 * // ...\r
69 * });\r
70 *\r
71 * Enable only sounds:\r
72 *\r
73 * Ext.device.Push.register({\r
74 * type: Ext.device.Push.SOUND\r
75 * // ...\r
76 * });\r
77 *\r
78 * @param {Function} config.success\r
79 * The callback to be called when registration is complete.\r
80 *\r
81 * @param {String} config.success.token\r
82 * A unique token for this push notification service.\r
83 *\r
84 * @param {Function} config.failure\r
85 * The callback to be called when registration fails.\r
86 *\r
87 * @param {String} config.failure.error\r
88 * The error message.\r
89 *\r
90 * @param {Function} config.received\r
91 * The callback to be called when a push notification is received on this device.\r
92 *\r
93 * @param {Object} config.received.notifications\r
94 * The notifications that have been received.\r
95 */\r
96 register: function(config) {\r
97 var me = this;\r
98\r
99 if (!config.received) {\r
100 Ext.Logger.error('Failed to pass a received callback. This is required.');\r
101 }\r
102\r
103 if (config.type == null) {\r
104 Ext.Logger.error('Failed to pass a type. This is required.');\r
105 }\r
106\r
107 return {\r
108 success: function(token) {\r
109 me.onSuccess(token, config.success, config.scope || me);\r
110 },\r
111 failure: function(error) {\r
112 me.onFailure(error, config.failure, config.scope || me);\r
113 },\r
114 received: function(notifications) {\r
115 me.onReceived(notifications, config.received, config.scope || me);\r
116 },\r
117 type: config.type\r
118 };\r
119 },\r
120\r
121 onSuccess: function(token, callback, scope) {\r
122 if (callback) {\r
123 callback.call(scope, token);\r
124 }\r
125 },\r
126\r
127 onFailure: function(error, callback, scope) {\r
128 if (callback) {\r
129 callback.call(scope, error);\r
130 }\r
131 },\r
132\r
133 onReceived: function(notifications, callback, scope) {\r
134 if (callback) {\r
135 callback.call(scope, notifications);\r
136 }\r
137 }\r
138});\r