I have a view with a data-model="App.models.artifacts" view model for artifacts.html that handles capturing and getting photos. I'm using requirejs to include kendo for the datasource.
/**
* artifacts data-model
*/
define([
'kendo',
'app/api'],
function (kendo, api) {
var viewModel = kendo.observable({
dataSource: new kendo.data.DataSource({
transport: {
read: function (options) {
api.getArtifactsForCurrentUser()
.done(function (data) {
options.success(data);
});
}
}
}),
onUploadImage: function (e) {
getPhoto(pictureSource.SAVEDPHOTOALBUM);
},
onCaptureImage: function (e) {
capturePhoto();
},
onCaptureVideo: function (e) {
captureVideo();
},
onCaptureAudio: function (e) {
captureAudio();
},
uploadSuccess: function (e) {
viewModel.dataSource.read();
App.views.artifacts.refreshList();
}
});
at first tried creating the getPhoto method within the view model class, but it always performs a capture rather than a getPicture. After hours of pulling my hair out as to why this was, and playing with the cordova camera sample, I finally got it running correctly by placing the getPhoto function in a separate jscript file that didn't have the kendo reference in it. I changed nothing about the call, except moving it.
/* camera.js */
.....
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source
});
}
.....
Why doesn't the call within the view model work correctly?
/**
* artifacts data-model
*/
define([
'kendo',
'app/api'],
function (kendo, api) {
var viewModel = kendo.observable({
dataSource: new kendo.data.DataSource({
transport: {
read: function (options) {
api.getArtifactsForCurrentUser()
.done(function (data) {
options.success(data);
});
}
}
}),
onUploadImage: function (e) {
getPhoto(pictureSource.SAVEDPHOTOALBUM);
},
onCaptureImage: function (e) {
capturePhoto();
},
onCaptureVideo: function (e) {
captureVideo();
},
onCaptureAudio: function (e) {
captureAudio();
},
uploadSuccess: function (e) {
viewModel.dataSource.read();
App.views.artifacts.refreshList();
}
});
at first tried creating the getPhoto method within the view model class, but it always performs a capture rather than a getPicture. After hours of pulling my hair out as to why this was, and playing with the cordova camera sample, I finally got it running correctly by placing the getPhoto function in a separate jscript file that didn't have the kendo reference in it. I changed nothing about the call, except moving it.
/* camera.js */
.....
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source
});
}
.....
Why doesn't the call within the view model work correctly?