AppPreferences.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. var define;
  2. if (typeof define === "undefined")
  3. define = function (classInstance) {
  4. classInstance (require, exports, module);
  5. }
  6. define (function (require, exports, module) {
  7. var dataflows = require ('dataflo.ws');
  8. var taskBase = dataflows.task ('base');
  9. var AppPreferenceTask = module.exports = function (config) {
  10. // there is no options to netinfo class
  11. this.init (config);
  12. };
  13. util.inherits (AppPreferenceTask, taskBase);
  14. util.extend (AppPreferenceTask.prototype, {
  15. fetch: function () {
  16. var self = this;
  17. console.log('MOBRO PREFERENCE GET PREPARE');
  18. var successCallback = function (response) {
  19. var result;
  20. try {
  21. result = JSON.parse (response);
  22. } catch (e) {
  23. result = response;
  24. }
  25. var returnValue = {forKey: self.forKey};
  26. if (result) {
  27. returnValue.value = result;
  28. } else {
  29. returnValue.noValue = true;
  30. }
  31. console.log ('MOBRO PREFERENCE GET DONE');
  32. console.log (returnValue);
  33. self.completed (returnValue);
  34. };
  35. var errorCallback = function (error) {
  36. console.log (error);
  37. self.completed ({
  38. forKey: self.forKey,
  39. noValue: true
  40. });
  41. };
  42. // if (device.platform == "BlackBerry" && parseInt(device.version) == 10) {
  43. // self.completed ({
  44. // forKey: self.forKey,
  45. // noValue: true
  46. // });
  47. // return;
  48. // }
  49. var cordovaModule = cordova.require ('me.apla.cordova.app-preferences.apppreferences');
  50. cordovaModule.fetch (successCallback, errorCallback, this.forKey, this.inDict);
  51. },
  52. store: function () {
  53. var self = this;
  54. var args = {};
  55. args.key = this.forKey;
  56. args.dict = this.inDict;
  57. args.value = this.value;
  58. if (!this.forKey || !this.value) {
  59. self.completed ();
  60. return;
  61. }
  62. console.log ('MOBRO PREFERENCE SET PREPARE');
  63. console.log (this.value);
  64. var successCallback = function (response) {
  65. self.completed ();
  66. };
  67. var errorCallback = function (error) {
  68. self.failed ({'undefined': true});
  69. console.log (error);
  70. };
  71. if (device.platform == "BlackBerry" && parseInt(device.version) == 10) {
  72. self.completed ();
  73. return;
  74. }
  75. var cordovaModule = cordova.require ('me.apla.cordova.app-preferences.apppreferences');
  76. cordovaModule.store (successCallback, errorCallback, this.forKey, this.inDict, this.value);
  77. }
  78. });
  79. dataflows.register ('task', 'AppPreferences', AppPreferenceTask);
  80. return AppPreferenceTask;
  81. });