/
EmployeeView.js
79 lines (70 loc) · 2.39 KB
/
EmployeeView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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);
};
this.render = function () {
this.el.html(EmployeeView.template(employee));
return this;
};
this.addLocation = function(event) {
event.preventDefault();
console.log('addLocation');
navigator.geolocation.getCurrentPosition(
function(position) {
$('.location', this.el).html(position.coords.latitude + ',' +position.coords.longitude);
},
function() {
alert('Error getting location');
});
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');
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(
function() {app.showAlert('save success')},
function(error) {app.showAlert('save failed: '+error.code)}
);
return false;
};
this.initialize();
}
EmployeeView.template = Handlebars.compile($("#employee-tpl").html());