local-notification-util.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * This file contains Original Code and/or Modifications of Original Code
  3. * as defined in and that are subject to the Apache License
  4. * Version 2.0 (the 'License'). You may not use this file except in
  5. * compliance with the License. Please obtain a copy of the License at
  6. * http://opensource.org/licenses/Apache-2.0/ and read it before using this
  7. * file.
  8. *
  9. * The Original Code and all software distributed under the License are
  10. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  11. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  12. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  13. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  14. * Please see the License for the specific language governing rights and
  15. * limitations under the License.
  16. */
  17. // var exec = require('cordova/exec'),
  18. // channel = require('cordova/channel');
  19. // /***********
  20. // * MEMBERS *
  21. // ***********/
  22. // // Default values
  23. // exports._defaults = {
  24. // text: '',
  25. // title: '',
  26. // sound: 'res://platform_default',
  27. // badge: 0,
  28. // id: 0,
  29. // data: undefined,
  30. // every: undefined,
  31. // at: undefined
  32. // };
  33. // // listener
  34. // exports._listener = {};
  35. // /********
  36. // * UTIL *
  37. // ********/
  38. // /**
  39. // * Merge platform specific properties into the default ones.
  40. // *
  41. // * @return {Object}
  42. // * The default properties for the platform
  43. // */
  44. // exports.applyPlatformSpecificOptions = function () {
  45. // var defaults = this._defaults;
  46. // switch (device.platform) {
  47. // case 'Android':
  48. // defaults.icon = 'res://ic_popup_reminder';
  49. // defaults.smallIcon = undefined;
  50. // defaults.ongoing = false;
  51. // defaults.autoClear = true;
  52. // defaults.led = undefined;
  53. // defaults.color = undefined;
  54. // break;
  55. // }
  56. // return defaults;
  57. // };
  58. // /**
  59. // * Merge custom properties with the default values.
  60. // *
  61. // * @param {Object} options
  62. // * Set of custom values
  63. // *
  64. // * @retrun {Object}
  65. // * The merged property list
  66. // */
  67. // exports.mergeWithDefaults = function (options) {
  68. // var defaults = this.getDefaults();
  69. // options.at = this.getValueFor(options, 'at', 'firstAt', 'date');
  70. // options.text = this.getValueFor(options, 'text', 'message');
  71. // options.data = this.getValueFor(options, 'data', 'json');
  72. // if (defaults.hasOwnProperty('autoClear')) {
  73. // options.autoClear = this.getValueFor(options, 'autoClear', 'autoCancel');
  74. // }
  75. // if (options.autoClear !== true && options.ongoing) {
  76. // options.autoClear = false;
  77. // }
  78. // if (options.at === undefined || options.at === null) {
  79. // options.at = new Date();
  80. // }
  81. // for (var key in defaults) {
  82. // if (options[key] === null || options[key] === undefined) {
  83. // if (options.hasOwnProperty(key) && ['data','sound'].indexOf(key) > -1) {
  84. // options[key] = undefined;
  85. // } else {
  86. // options[key] = defaults[key];
  87. // }
  88. // }
  89. // }
  90. // for (key in options) {
  91. // if (!defaults.hasOwnProperty(key)) {
  92. // delete options[key];
  93. // console.warn('Unknown property: ' + key);
  94. // }
  95. // }
  96. // return options;
  97. // };
  98. // /**
  99. // * Convert the passed values to their required type.
  100. // *
  101. // * @param {Object} options
  102. // * Set of custom values
  103. // *
  104. // * @retrun {Object}
  105. // * The converted property list
  106. // */
  107. // exports.convertProperties = function (options) {
  108. // if (options.id) {
  109. // if (isNaN(options.id)) {
  110. // options.id = this.getDefaults().id;
  111. // console.warn('Id is not a number: ' + options.id);
  112. // } else {
  113. // options.id = Number(options.id);
  114. // }
  115. // }
  116. // if (options.title) {
  117. // options.title = options.title.toString();
  118. // }
  119. // if (options.text) {
  120. // options.text = options.text.toString();
  121. // }
  122. // if (options.badge) {
  123. // if (isNaN(options.badge)) {
  124. // options.badge = this.getDefaults().badge;
  125. // console.warn('Badge number is not a number: ' + options.id);
  126. // } else {
  127. // options.badge = Number(options.badge);
  128. // }
  129. // }
  130. // if (options.at) {
  131. // if (typeof options.at == 'object') {
  132. // options.at = options.at.getTime();
  133. // }
  134. // options.at = Math.round(options.at/1000);
  135. // }
  136. // if (typeof options.data == 'object') {
  137. // options.data = JSON.stringify(options.data);
  138. // }
  139. // if (options.every) {
  140. // if (device.platform == 'iOS' && typeof options.every != 'string') {
  141. // options.every = this.getDefaults().every;
  142. // var warning = 'Every option is not a string: ' + options.id;
  143. // warning += '. Expects one of: second, minute, hour, day, week, ';
  144. // warning += 'month, year on iOS.';
  145. // console.warn(warning);
  146. // }
  147. // }
  148. // return options;
  149. // };
  150. /**
  151. * Create a callback function to get executed within a specific scope.
  152. *
  153. * @param [ Function ] fn The function to be exec as the callback.
  154. * @param [ Object ] scope The callback function's scope.
  155. *
  156. * @return [ Function ]
  157. */
  158. exports.createCallbackFn = function (fn, scope) {
  159. if (typeof fn != 'function')
  160. return;
  161. return function () {
  162. fn.apply(scope || this, arguments);
  163. };
  164. };
  165. // /**
  166. // * Convert the IDs to numbers.
  167. // *
  168. // * @param {String/Number[]} ids
  169. // *
  170. // * @return Array of Numbers
  171. // */
  172. // exports.convertIds = function (ids) {
  173. // var convertedIds = [];
  174. // for (var i = 0; i < ids.length; i++) {
  175. // convertedIds.push(Number(ids[i]));
  176. // }
  177. // return convertedIds;
  178. // };
  179. // /**
  180. // * First found value for the given keys.
  181. // *
  182. // * @param {Object} options
  183. // * Object with key-value properties
  184. // * @param {String[]} keys*
  185. // * Key list
  186. // */
  187. // exports.getValueFor = function (options) {
  188. // var keys = Array.apply(null, arguments).slice(1);
  189. // for (var i = 0; i < keys.length; i++) {
  190. // var key = keys[i];
  191. // if (options.hasOwnProperty(key)) {
  192. // return options[key];
  193. // }
  194. // }
  195. // };
  196. // /**
  197. // * Fire event with given arguments.
  198. // *
  199. // * @param {String} event
  200. // * The event's name
  201. // * @param {args*}
  202. // * The callback's arguments
  203. // */
  204. // exports.fireEvent = function (event) {
  205. // var args = Array.apply(null, arguments).slice(1),
  206. // listener = this._listener[event];
  207. // if (!listener)
  208. // return;
  209. // for (var i = 0; i < listener.length; i++) {
  210. // var fn = listener[i][0],
  211. // scope = listener[i][1];
  212. // fn.apply(scope, args);
  213. // }
  214. // };
  215. // /**
  216. // * Execute the native counterpart.
  217. // *
  218. // * @param {String} action
  219. // * The name of the action
  220. // * @param args[]
  221. // * Array of arguments
  222. // * @param {Function} callback
  223. // * The callback function
  224. // * @param {Object} scope
  225. // * The scope for the function
  226. // */
  227. // exports.exec = function (action, args, callback, scope) {
  228. // var fn = this.createCallbackFn(callback, scope),
  229. // params = [];
  230. // if (Array.isArray(args)) {
  231. // params = args;
  232. // } else if (args) {
  233. // params.push(args);
  234. // }
  235. // exec(fn, null, 'LocalNotification', action, params);
  236. // };
  237. // /*********
  238. // * HOOKS *
  239. // *********/
  240. // // Called after 'deviceready' event
  241. // channel.deviceready.subscribe(function () {
  242. // // Device is ready now, the listeners are registered
  243. // // and all queued events can be executed.
  244. // exec(null, null, 'LocalNotification', 'deviceready', []);
  245. // });
  246. // // Called before 'deviceready' event
  247. // channel.onCordovaReady.subscribe(function () {
  248. // // Device plugin is ready now
  249. // channel.onCordovaInfoReady.subscribe(function () {
  250. // // Merge platform specifics into defaults
  251. // exports.applyPlatformSpecificOptions();
  252. // });
  253. // });