I've refactored my procedural javascript into an object/class and now... I hesitate to say it's broken because I'm not getting any errors but it's (sigh) broken.
In the following code, camera.js: 71 is the last "report" I get from the module. No errors, no barfs, everything proceeds as normal except nothing happens.
I can call either camera.capturePhoto or camera.choosePhoto() and:
- I get the camera or the photo library as expected
- this.cameraOnSuccess gets called
- I get a photo URI back
- I get access to the filesystem and at this point either the this.resolveOnSuccess or the anon fuction should handle the error and nothing... nada... zip... zilch. There is no output to the console in either an emulator or within my app.
What did I do wrong (or what lesson am I learning today? ;-)
var camera = new Photo();
function Photo()
{
var self = this; // this DOES NOT WORK!
var element_id = null;
var dirty_flag = false; // false if clean and no save needed, 1 if save needed
var callback = null;
// id is element getting photo
this.init = function(id, callback) {
this.element_id = id;
this.callback = callback;
this.self = this; // this works on phonegap / cordova apps
}
this.capturePhoto = function()
{
// the cameraOnFail will never get called with parameters
// use the method for the self.cameraOnSuccess
navigator.camera.getPicture(function(entry) {
self.cameraOnSuccess(entry);
}, self.cameraOnFail, { quality: 100,
destinationType: Camera.DestinationType.FILE_URI
});
}
this.cameraOnSuccess = function(imageData) {
console.log("camera on success");
this.cleanup(); // this can be called using this as it's a direct call
}
this.cameraOnFail = function(message) {
// trap permission and cancel messages
console.log("failed because: " +message);
}
this.cleanup = function()
{
navigator.camera.cleanup(function() {
console.log("camera.js: 151 = camera cleanup successful");
}, function(message) {
console.log("camera cleanup failed because: " +message);
});
}
}