angular.module('odoo') .factory('config', function (storage) { return function (success, error) { storage.get('user', function (users) { success(users); }, function (err) { error(err); }); }; }) .factory('async', function () { return { loop: function (iterations, func, callback) { var index = 0; var done = false; var loop = { next: function () { if (done) { return; } if (index < iterations) { index++; func(loop); } else { done = true; callback(); } }, iteration: function() { return index - 1; }, break: function() { done = true; callback(); } }; loop.next(); return loop; } } }) .factory('camera', function ($cordovaCamera) { return { takePicture: function (success, error) { var options = { quality: 75, destinationType: Camera.DestinationType.DATA_URL, sourceType: Camera.PictureSourceType.CAMERA, allowEdit: true, encodingType: Camera.EncodingType.JPEG, targetWidth: 300, targetHeight: 300, popoverOptions: CameraPopoverOptions, saveToPhotoAlbum: false, correctOrientation:true }; $cordovaCamera.getPicture(options).then(function(imageData) { success(imageData); }, function(err) { error(err); }); } } }) .factory('contact', function ($cordovaContacts) { return { save: function (customer, success, error) { if(!customer.mobile && !customer.phone && !customer.email) { error(); return; } var contact = { name: { givenName: customer.name, familyName: '', formatted: '' }, nickname: '', phoneNumbers: [ { value: customer.phone, type: 'phone' }, { value: customer.mobile, type: 'mobile' } ], emails: [ { value: customer.email, type: 'home' } ], addresses: [ { type: 'home', formatted: '', streetAddress: customer.street, locality: customer.city, region: '', postalCode: '', country: 'Paraguay' } ], ims: null, organizations: null, birthday: null, note: null, photos: null, categories: null, urls: null }; $cordovaContacts.save(contact).then(function (result) { success(result); }, function (err) { error(err); }); } } });