Permalink
Browse files

part12

  • Loading branch information...
d4kris
d4kris committed Nov 6, 2012
1 parent 1741c6a commit a7bb6da41a28347868300c13dc2247b537418d7e
Showing with 40 additions and 8 deletions.
  1. +1 −1 index.html
  2. +39 −7 js/EmployeeView.js
View
@@ -30,7 +30,7 @@ <h2>{{title}}</h2>
<li><a href="tel:{{officePhone}}">Call Office<br/>{{officePhone}}</a></li>
<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="change-pic-btn">Change Picture</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>
</ul>
View
@@ -3,6 +3,7 @@ var EmployeeView = function (employee) {
this.initialize = function () {
this.el = $('<div/>');
this.el.on('click', '.add-location-btn', this.addLocation);
+ this.el.on('click', '.change-pic-btn', this.changePicture);
this.el.on('click', '.add-contact-btn', this.addToContacts);
};
@@ -24,6 +25,31 @@ var EmployeeView = function (employee) {
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.addToContacts = function(event) {
event.preventDefault();
console.log('addToContacts');
@@ -32,13 +58,19 @@ var EmployeeView = function (employee) {
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;
+ 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(
+ function() {app.showAlert('save success')},
+ function(error) {app.showAlert('save failed: '+error.code)}
+ );
+ return false;
};
this.initialize();

0 comments on commit a7bb6da

Please sign in to comment.