Skip to content

Commit

Permalink
camera
Browse files Browse the repository at this point in the history
  • Loading branch information
Hao Zhou committed Jul 22, 2014
1 parent fa9e6c2 commit 911a838
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ <h2>{{title}}</h2>
<li><a href="tel:{{cellPhone}}">Call Cell<br/>{{cellPhone}}</a></li>
<li><a href="sms:{{cellPhone}}">SMS<br/>{{cellPhone}}</a></li>
<li><a href="#" class="add-location-btn">Add Location</a></li>
<li><a href="#" class="add-contact-btn">Add to Contacts</a></li>
<li><a href="#" class="change-pic-btn">Change Picture</a></li>
</ul>
</div>
</script>
Expand Down
46 changes: 45 additions & 1 deletion js/EmployeeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var EmployeeView = function(employee) {
this.initialize = function() {
this.el = $('<div/>');
this.el.on('click', '.add-location-btn', this.addLocation);
this.el.on('click', '.add-contact-btn', this.addToContacts);
this.el.on('click', '.change-pic-btn', this.changePicture);
};

this.render = function() {
Expand All @@ -15,14 +17,56 @@ var EmployeeView = function(employee) {
console.log('addLocation');
navigator.geolocation.getCurrentPosition(
function(position) {
$('.location', this.el).html(position.coords.latitude + ',' +position.coords.longitude);
$('.location', this.el).html(position.coords.latitude + ',' + position.coords.longitude);
},
function() {
alert('Error getting location');
});
return false;
};

this.addToContacts = function(event) {
event.preventDefault();
console.log('addToContacts');
if (!navigator.contacts) {
app.showAlert("Contacts API not supported", "Error");
return;
}
var contact = navigator.contacts.create();
contact.name = {givenName: app.currentEmployee.firstName, familyName: app.currentEmployee.lastName};
var phoneNumbers = [];
phoneNumbers[0] = new ContactField('work', app.currentEmployee.officePhone, false);
phoneNumbers[1] = new ContactField('mobile', app.currentEmployee.cellPhone, true); // preferred number
contact.phoneNumbers = phoneNumbers;
contact.save();
return false;
};

this.changePicture = function(event) {
event.preventDefault();
console.log('changePicture');
if (!navigator.camera) {
app.showAlert("Camera API not supported", "Error");
return;
}
var options = { quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: 1, // 0:Photo Library, 1=Camera, 2=Saved Photo Album
encodingType: 0 // 0=JPG 1=PNG
};

navigator.camera.getPicture(
function(imageData) {
$('#image').attr('src', "data:image/jpeg;base64," + imageData);
},
function() {
alert('Error taking picture');
},
options);

return false;
};

this.initialize();

}
Expand Down

0 comments on commit 911a838

Please sign in to comment.