-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcontroller.js
More file actions
97 lines (80 loc) · 3.04 KB
/
controller.js
File metadata and controls
97 lines (80 loc) · 3.04 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"use-strict";
const
model = require("./model");
function makeContacts(people, menu, prompt, table) {
var _contacts = {
people: people,
menu: menu,
prompt: prompt,
table: table,
add: function () {
console.log('Add a contact:');
prompt.get(['firstname',
'lastname',
'email',
'telephone',
'gender',
'birthDate',
'birthPlace'],
function (err, input) {
var person = model.makePerson(input.firstname,
input.lastname,
input.email,
input.telephone,
input.gender,
input.birthDate,
input.birthPlace);
// confirm entry //
console.log('You entered:');
console.log(person);
var properties = [
{
name: 'input',
validator: /^[yn]/,
message: 'Is this ok?: (y/n)',
required: true
}
];
prompt.get(properties, function (err, result) {
if (err) { return onErr(err); }
switch(result.input) {
case "y":
people.add(person);
console.log('%s was added to your contacts', person.name());
break;
case "n":
console.log('% was not added to your contacts, try again', person.ame());
break;
}
menu.show();
});
});
}
};
// OTHER INITIALIZATION //
// TODO 12 : create the onUserInput event listener //
// TODO 13 : on the menu object, listen for the userInput event //
// TODO : 14 on the people object, listen for the loaded event //
// TODO 15 : call the load method on the people object //
return _contacts;
}
module.exports.makeContacts = makeContacts;
function prepareValues(values) {
var prepared = [];
var contact;
for (var i = 0; i < values.length; i++) {
contact = values[i];
prepared.push([i+1,
contact.name(),
contact.email,
contact.telephone,
contact.gender,
contact.birthDate,
contact.birthPlace]);
}
return prepared;
}
function onErr(err) {
console.log(err);
return 1;
}