local-notification.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*
  2. * Copyright (c) 2013-2015 by appPlant UG. All rights reserved.
  3. *
  4. * @APPPLANT_LICENSE_HEADER_START@
  5. *
  6. * This file contains Original Code and/or Modifications of Original Code
  7. * as defined in and that are subject to the Apache License
  8. * Version 2.0 (the 'License'). You may not use this file except in
  9. * compliance with the License. Please obtain a copy of the License at
  10. * http://opensource.org/licenses/Apache-2.0/ and read it before using this
  11. * file.
  12. *
  13. * The Original Code and all software distributed under the License are
  14. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  15. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  16. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  18. * Please see the License for the specific language governing rights and
  19. * limitations under the License.
  20. *
  21. * @APPPLANT_LICENSE_HEADER_END@
  22. */
  23. /*************
  24. * INTERFACE *
  25. *************/
  26. /**
  27. * Returns the default settings.
  28. *
  29. * @return {Object}
  30. */
  31. exports.getDefaults = function () {
  32. return this.core.getDefaults();
  33. };
  34. /**
  35. * Overwrite default settings.
  36. *
  37. * @param {Object} defaults
  38. */
  39. exports.setDefaults = function (defaults) {
  40. this.core.setDefaults(defaults);
  41. };
  42. /**
  43. * Schedule a new local notification.
  44. *
  45. * @param {Object} opts
  46. * The notification properties
  47. * @param {Function} callback
  48. * A function to be called after the notification has been canceled
  49. * @param {Object?} scope
  50. * The scope for the callback function
  51. */
  52. exports.schedule = function (opts, callback, scope) {
  53. this.core.schedule(opts, callback, scope);
  54. };
  55. /**
  56. * Update existing notifications specified by IDs in options.
  57. *
  58. * @param {Object} options
  59. * The notification properties to update
  60. * @param {Function} callback
  61. * A function to be called after the notification has been updated
  62. * @param {Object?} scope
  63. * The scope for the callback function
  64. */
  65. exports.update = function (opts, callback, scope) {
  66. this.core.update(opts, callback, scope);
  67. };
  68. /**
  69. * Clear the specified notification.
  70. *
  71. * @param {String} id
  72. * The ID of the notification
  73. * @param {Function} callback
  74. * A function to be called after the notification has been cleared
  75. * @param {Object?} scope
  76. * The scope for the callback function
  77. */
  78. exports.clear = function (ids, callback, scope) {
  79. this.core.clear(ids, callback, scope);
  80. };
  81. /**
  82. * Clear all previously sheduled notifications.
  83. *
  84. * @param {Function} callback
  85. * A function to be called after all notifications have been cleared
  86. * @param {Object?} scope
  87. * The scope for the callback function
  88. */
  89. exports.clearAll = function (callback, scope) {
  90. this.core.clearAll(callback, scope);
  91. };
  92. /**
  93. * Cancel the specified notifications.
  94. *
  95. * @param {String[]} ids
  96. * The IDs of the notifications
  97. * @param {Function} callback
  98. * A function to be called after the notifications has been canceled
  99. * @param {Object?} scope
  100. * The scope for the callback function
  101. */
  102. exports.cancel = function (ids, callback, scope) {
  103. this.core.cancel(ids, callback, scope);
  104. };
  105. /**
  106. * Remove all previously registered notifications.
  107. *
  108. * @param {Function} callback
  109. * A function to be called after all notifications have been canceled
  110. * @param {Object?} scope
  111. * The scope for the callback function
  112. */
  113. exports.cancelAll = function (callback, scope) {
  114. this.core.cancelAll(callback, scope);
  115. };
  116. /**
  117. * Check if a notification with an ID is present.
  118. *
  119. * @param {String} id
  120. * The ID of the notification
  121. * @param {Function} callback
  122. * A callback function to be called with the list
  123. * @param {Object?} scope
  124. * The scope for the callback function
  125. */
  126. exports.isPresent = function (id, callback, scope) {
  127. this.core.isPresent(id, callback, scope);
  128. };
  129. /**
  130. * Check if a notification with an ID is scheduled.
  131. *
  132. * @param {String} id
  133. * The ID of the notification
  134. * @param {Function} callback
  135. * A callback function to be called with the list
  136. * @param {Object?} scope
  137. * The scope for the callback function
  138. */
  139. exports.isScheduled = function (id, callback, scope) {
  140. this.core.isScheduled(id, callback, scope);
  141. };
  142. /**
  143. * Check if a notification with an ID was triggered.
  144. *
  145. * @param {String} id
  146. * The ID of the notification
  147. * @param {Function} callback
  148. * A callback function to be called with the list
  149. * @param {Object?} scope
  150. * The scope for the callback function
  151. */
  152. exports.isTriggered = function (id, callback, scope) {
  153. this.core.isTriggered(id, callback, scope);
  154. };
  155. /**
  156. * List all local notification IDs.
  157. *
  158. * @param {Function} callback
  159. * A callback function to be called with the list
  160. * @param {Object?} scope
  161. * The scope for the callback function
  162. */
  163. exports.getAllIds = function (callback, scope) {
  164. this.core.getAllIds(callback, scope);
  165. };
  166. /**
  167. * Alias for `getAllIds`.
  168. */
  169. exports.getIds = function () {
  170. this.getAllIds.apply(this, arguments);
  171. };
  172. /**
  173. * List all scheduled notification IDs.
  174. *
  175. * @param {Function} callback
  176. * A callback function to be called with the list
  177. * @param {Object?} scope
  178. * The scope for the callback function
  179. */
  180. exports.getScheduledIds = function (callback, scope) {
  181. this.core.getScheduledIds(callback, scope);
  182. };
  183. /**
  184. * List all triggered notification IDs.
  185. *
  186. * @param {Function} callback
  187. * A callback function to be called with the list
  188. * @param {Object?} scope
  189. * The scope for the callback function
  190. */
  191. exports.getTriggeredIds = function (callback, scope) {
  192. this.core.getTriggeredIds(callback, scope);
  193. };
  194. /**
  195. * Property list for given local notifications.
  196. * If called without IDs, all notification will be returned.
  197. *
  198. * @param {Number[]?} ids
  199. * Set of notification IDs
  200. * @param {Function} callback
  201. * A callback function to be called with the list
  202. * @param {Object?} scope
  203. * The scope for the callback function
  204. */
  205. exports.get = function () {
  206. this.core.get.apply(this.core, arguments);
  207. };
  208. /**
  209. * Property list for all local notifications.
  210. *
  211. * @param {Function} callback
  212. * A callback function to be called with the list
  213. * @param {Object?} scope
  214. * The scope for the callback function
  215. */
  216. exports.getAll = function (callback, scope) {
  217. this.core.getAll(callback, scope);
  218. };
  219. /**
  220. * Property list for given scheduled notifications.
  221. * If called without IDs, all notification will be returned.
  222. *
  223. * @param {Number[]?} ids
  224. * Set of notification IDs
  225. * @param {Function} callback
  226. * A callback function to be called with the list
  227. * @param {Object?} scope
  228. * The scope for the callback function
  229. */
  230. exports.getScheduled = function () {
  231. this.core.getScheduled.apply(this.core, arguments);
  232. };
  233. /**
  234. * Property list for all scheduled notifications.
  235. *
  236. * @param {Function} callback
  237. * A callback function to be called with the list
  238. * @param {Object?} scope
  239. * The scope for the callback function
  240. */
  241. exports.getAllScheduled = function (callback, scope) {
  242. this.core.getAllScheduled(callback, scope);
  243. };
  244. /**
  245. * Property list for given triggered notifications.
  246. * If called without IDs, all notification will be returned.
  247. *
  248. * @param {Number[]?} ids
  249. * Set of notification IDs
  250. * @param {Function} callback
  251. * A callback function to be called with the list
  252. * @param {Object?} scope
  253. * The scope for the callback function
  254. */
  255. exports.getTriggered = function () {
  256. this.core.getTriggered.apply(this.core, arguments);
  257. };
  258. /**
  259. * Property list for all triggered notifications.
  260. *
  261. * @param {Function} callback
  262. * A callback function to be called with the list
  263. * @param {Object?} scope
  264. * The scope for the callback function
  265. */
  266. exports.getAllTriggered = function (callback, scope) {
  267. this.core.getAllTriggered(callback, scope);
  268. };
  269. /**
  270. * Informs if the app has the permission to show notifications.
  271. *
  272. * @param {Function} callback
  273. * The function to be exec as the callback
  274. * @param {Object?} scope
  275. * The callback function's scope
  276. */
  277. exports.hasPermission = function (callback, scope) {
  278. this.core.hasPermission(callback, scope);
  279. };
  280. /**
  281. * Register permission to show notifications if not already granted.
  282. *
  283. * @param {Function} callback
  284. * The function to be exec as the callback
  285. * @param {Object?} scope
  286. * The callback function's scope
  287. */
  288. exports.registerPermission = function (callback, scope) {
  289. this.core.registerPermission(callback, scope);
  290. };
  291. /****************
  292. * DEPRECATIONS *
  293. ****************/
  294. /**
  295. * Schedule a new local notification.
  296. */
  297. exports.add = function () {
  298. console.warn('Depreated: Please use `notification.local.schedule` instead.');
  299. this.schedule.apply(this, arguments);
  300. };
  301. /**
  302. * Register permission to show notifications
  303. * if not already granted.
  304. */
  305. exports.promptForPermission = function () {
  306. console.warn('Depreated: Please use `notification.local.registerPermission` instead.');
  307. this.registerPermission.apply(this, arguments);
  308. };
  309. /**********
  310. * EVENTS *
  311. **********/
  312. /**
  313. * Register callback for given event.
  314. *
  315. * @param {String} event
  316. * The event's name
  317. * @param {Function} callback
  318. * The function to be exec as callback
  319. * @param {Object?} scope
  320. * The callback function's scope
  321. */
  322. exports.on = function (event, callback, scope) {
  323. this.core.on(event, callback, scope);
  324. };
  325. /**
  326. * Unregister callback for given event.
  327. *
  328. * @param {String} event
  329. * The event's name
  330. * @param {Function} callback
  331. * The function to be exec as callback
  332. */
  333. exports.un = function (event, callback) {
  334. this.core.un(event, callback, scope);
  335. };