utils.factory.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. angular.module('odoo')
  2. .factory('config', function (storage) {
  3. return function (success, error) {
  4. storage.get('user', function (users) {
  5. success(users);
  6. }, function (err) {
  7. error(err);
  8. });
  9. };
  10. })
  11. .factory('async', function () {
  12. return {
  13. loop: function (iterations, func, callback) {
  14. var index = 0;
  15. var done = false;
  16. var loop = {
  17. next: function () {
  18. if (done) {
  19. return;
  20. }
  21. if (index < iterations) {
  22. index++;
  23. func(loop);
  24. } else {
  25. done = true;
  26. callback();
  27. }
  28. },
  29. iteration: function() {
  30. return index - 1;
  31. },
  32. break: function() {
  33. done = true;
  34. callback();
  35. }
  36. };
  37. loop.next();
  38. return loop;
  39. }
  40. }
  41. })
  42. .factory('camera', function ($cordovaCamera) {
  43. return {
  44. takePicture: function (success, error) {
  45. var options = {
  46. quality: 75,
  47. destinationType: Camera.DestinationType.DATA_URL,
  48. sourceType: Camera.PictureSourceType.CAMERA,
  49. allowEdit: true,
  50. encodingType: Camera.EncodingType.JPEG,
  51. targetWidth: 300,
  52. targetHeight: 300,
  53. popoverOptions: CameraPopoverOptions,
  54. saveToPhotoAlbum: false,
  55. correctOrientation:true
  56. };
  57. $cordovaCamera.getPicture(options).then(function(imageData) {
  58. success(imageData);
  59. }, function(err) {
  60. error(err);
  61. });
  62. }
  63. }
  64. })
  65. .factory('contact', function ($cordovaContacts) {
  66. return {
  67. save: function (customer, success, error) {
  68. if(!customer.mobile && !customer.phone && !customer.email) {
  69. error();
  70. return;
  71. }
  72. var contact = {
  73. name: {
  74. givenName: customer.name,
  75. familyName: '',
  76. formatted: ''
  77. },
  78. nickname: '',
  79. phoneNumbers: [
  80. {
  81. value: customer.phone,
  82. type: 'phone'
  83. },
  84. {
  85. value: customer.mobile,
  86. type: 'mobile'
  87. }
  88. ],
  89. emails: [
  90. {
  91. value: customer.email,
  92. type: 'home'
  93. }
  94. ],
  95. addresses: [
  96. {
  97. type: 'home',
  98. formatted: '',
  99. streetAddress: customer.street,
  100. locality: customer.city,
  101. region: '',
  102. postalCode: '',
  103. country: 'Paraguay'
  104. }
  105. ],
  106. ims: null,
  107. organizations: null,
  108. birthday: null,
  109. note: null,
  110. photos: null,
  111. categories: null,
  112. urls: null
  113. };
  114. $cordovaContacts.save(contact).then(function (result) {
  115. success(result);
  116. }, function (err) {
  117. error(err);
  118. });
  119. }
  120. }
  121. });