local-notification.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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} notifications
  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. * @param {Object?} args
  52. * skipPermission:true schedules the notifications immediatly without
  53. * registering or checking for permission
  54. */
  55. exports.schedule = function (notifications, callback, scope, args) {
  56. this.core.schedule(notifications, callback, scope, args);
  57. };
  58. /**
  59. * Update existing notifications specified by IDs in options.
  60. *
  61. * @param {Object} notifications
  62. * The notification properties to update
  63. * @param {Function} callback
  64. * A function to be called after the notification has been updated
  65. * @param {Object?} scope
  66. * The scope for the callback function
  67. * @param {Object?} args
  68. * skipPermission:true schedules the notifications immediatly without
  69. * registering or checking for permission
  70. */
  71. exports.update = function (notifications, callback, scope, args) {
  72. this.core.update(notifications, callback, scope, args);
  73. };
  74. /**
  75. * Clear the specified notification.
  76. *
  77. * @param {String} id
  78. * The ID of the notification
  79. * @param {Function} callback
  80. * A function to be called after the notification has been cleared
  81. * @param {Object?} scope
  82. * The scope for the callback function
  83. */
  84. exports.clear = function (ids, callback, scope) {
  85. this.core.clear(ids, callback, scope);
  86. };
  87. /**
  88. * Clear all previously sheduled notifications.
  89. *
  90. * @param {Function} callback
  91. * A function to be called after all notifications have been cleared
  92. * @param {Object?} scope
  93. * The scope for the callback function
  94. */
  95. exports.clearAll = function (callback, scope) {
  96. this.core.clearAll(callback, scope);
  97. };
  98. /**
  99. * Cancel the specified notifications.
  100. *
  101. * @param {String[]} ids
  102. * The IDs of the notifications
  103. * @param {Function} callback
  104. * A function to be called after the notifications has been canceled
  105. * @param {Object?} scope
  106. * The scope for the callback function
  107. */
  108. exports.cancel = function (ids, callback, scope) {
  109. this.core.cancel(ids, callback, scope);
  110. };
  111. /**
  112. * Remove all previously registered notifications.
  113. *
  114. * @param {Function} callback
  115. * A function to be called after all notifications have been canceled
  116. * @param {Object?} scope
  117. * The scope for the callback function
  118. */
  119. exports.cancelAll = function (callback, scope) {
  120. this.core.cancelAll(callback, scope);
  121. };
  122. /**
  123. * Check if a notification with an ID is present.
  124. *
  125. * @param {String} id
  126. * The ID of the notification
  127. * @param {Function} callback
  128. * A callback function to be called with the list
  129. * @param {Object?} scope
  130. * The scope for the callback function
  131. */
  132. exports.isPresent = function (id, callback, scope) {
  133. this.core.isPresent(id, callback, scope);
  134. };
  135. /**
  136. * Check if a notification with an ID is scheduled.
  137. *
  138. * @param {String} id
  139. * The ID of the notification
  140. * @param {Function} callback
  141. * A callback function to be called with the list
  142. * @param {Object?} scope
  143. * The scope for the callback function
  144. */
  145. exports.isScheduled = function (id, callback, scope) {
  146. this.core.isScheduled(id, callback, scope);
  147. };
  148. /**
  149. * Check if a notification with an ID was triggered.
  150. *
  151. * @param {String} id
  152. * The ID of the notification
  153. * @param {Function} callback
  154. * A callback function to be called with the list
  155. * @param {Object?} scope
  156. * The scope for the callback function
  157. */
  158. exports.isTriggered = function (id, callback, scope) {
  159. this.core.isTriggered(id, callback, scope);
  160. };
  161. /**
  162. * List all local notification IDs.
  163. *
  164. * @param {Function} callback
  165. * A callback function to be called with the list
  166. * @param {Object?} scope
  167. * The scope for the callback function
  168. */
  169. exports.getAllIds = function (callback, scope) {
  170. this.core.getAllIds(callback, scope);
  171. };
  172. /**
  173. * Alias for `getAllIds`.
  174. */
  175. exports.getIds = function () {
  176. this.getAllIds.apply(this, arguments);
  177. };
  178. /**
  179. * List all scheduled notification IDs.
  180. *
  181. * @param {Function} callback
  182. * A callback function to be called with the list
  183. * @param {Object?} scope
  184. * The scope for the callback function
  185. */
  186. exports.getScheduledIds = function (callback, scope) {
  187. this.core.getScheduledIds(callback, scope);
  188. };
  189. /**
  190. * List all triggered notification IDs.
  191. *
  192. * @param {Function} callback
  193. * A callback function to be called with the list
  194. * @param {Object?} scope
  195. * The scope for the callback function
  196. */
  197. exports.getTriggeredIds = function (callback, scope) {
  198. this.core.getTriggeredIds(callback, scope);
  199. };
  200. /**
  201. * Property list for given local notifications.
  202. * If called without IDs, all notification will be returned.
  203. *
  204. * @param {Number[]?} ids
  205. * Set of notification IDs
  206. * @param {Function} callback
  207. * A callback function to be called with the list
  208. * @param {Object?} scope
  209. * The scope for the callback function
  210. */
  211. exports.get = function () {
  212. this.core.get.apply(this.core, arguments);
  213. };
  214. /**
  215. * Property list for all local notifications.
  216. *
  217. * @param {Function} callback
  218. * A callback function to be called with the list
  219. * @param {Object?} scope
  220. * The scope for the callback function
  221. */
  222. exports.getAll = function (callback, scope) {
  223. this.core.getAll(callback, scope);
  224. };
  225. /**
  226. * Property list for given scheduled notifications.
  227. * If called without IDs, all notification will be returned.
  228. *
  229. * @param {Number[]?} ids
  230. * Set of notification IDs
  231. * @param {Function} callback
  232. * A callback function to be called with the list
  233. * @param {Object?} scope
  234. * The scope for the callback function
  235. */
  236. exports.getScheduled = function () {
  237. this.core.getScheduled.apply(this.core, arguments);
  238. };
  239. /**
  240. * Property list for all scheduled notifications.
  241. *
  242. * @param {Function} callback
  243. * A callback function to be called with the list
  244. * @param {Object?} scope
  245. * The scope for the callback function
  246. */
  247. exports.getAllScheduled = function (callback, scope) {
  248. this.core.getAllScheduled(callback, scope);
  249. };
  250. /**
  251. * Property list for given triggered notifications.
  252. * If called without IDs, all notification will be returned.
  253. *
  254. * @param {Number[]?} ids
  255. * Set of notification IDs
  256. * @param {Function} callback
  257. * A callback function to be called with the list
  258. * @param {Object?} scope
  259. * The scope for the callback function
  260. */
  261. exports.getTriggered = function () {
  262. this.core.getTriggered.apply(this.core, arguments);
  263. };
  264. /**
  265. * Property list for all triggered notifications.
  266. *
  267. * @param {Function} callback
  268. * A callback function to be called with the list
  269. * @param {Object?} scope
  270. * The scope for the callback function
  271. */
  272. exports.getAllTriggered = function (callback, scope) {
  273. this.core.getAllTriggered(callback, scope);
  274. };
  275. /**
  276. * Informs if the app has the permission to show notifications.
  277. *
  278. * @param {Function} callback
  279. * The function to be exec as the callback
  280. * @param {Object?} scope
  281. * The callback function's scope
  282. */
  283. exports.hasPermission = function (callback, scope) {
  284. this.core.hasPermission(callback, scope);
  285. };
  286. /**
  287. * Register permission to show notifications if not already granted.
  288. *
  289. * @param {Function} callback
  290. * The function to be exec as the callback
  291. * @param {Object?} scope
  292. * The callback function's scope
  293. */
  294. exports.registerPermission = function (callback, scope) {
  295. this.core.registerPermission(callback, scope);
  296. };
  297. /****************
  298. * DEPRECATIONS *
  299. ****************/
  300. /**
  301. * Schedule a new local notification.
  302. */
  303. exports.add = function () {
  304. console.warn('Depreated: Please use `notification.local.schedule` instead.');
  305. this.schedule.apply(this, arguments);
  306. };
  307. /**
  308. * Register permission to show notifications
  309. * if not already granted.
  310. */
  311. exports.promptForPermission = function () {
  312. console.warn('Depreated: Please use `notification.local.registerPermission` instead.');
  313. this.registerPermission.apply(this, arguments);
  314. };
  315. /**********
  316. * EVENTS *
  317. **********/
  318. /**
  319. * Register callback for given event.
  320. *
  321. * @param {String} event
  322. * The event's name
  323. * @param {Function} callback
  324. * The function to be exec as callback
  325. * @param {Object?} scope
  326. * The callback function's scope
  327. */
  328. exports.on = function (event, callback, scope) {
  329. this.core.on(event, callback, scope);
  330. };
  331. /**
  332. * Unregister callback for given event.
  333. *
  334. * @param {String} event
  335. * The event's name
  336. * @param {Function} callback
  337. * The function to be exec as callback
  338. */
  339. exports.un = function (event, callback) {
  340. this.core.un(event, callback);
  341. };