-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
121 lines (114 loc) · 2.97 KB
/
app.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* Created with Node Primer.
* User: bhalperin
* Date: 2014-05-02
* Time: 06:58 AM
* To change this template use Tools | Templates.
*/
define([
"hello", "templates",
"profileModel", "contactsStatsModel", "contactModel",
"contactsCollection", "contactsFilterCollection",
"profileView", "contactsTitleView", "contactsView", "contactsFilterView"
], function(hello, Templates,
Profile, ContactsStatsModel, Contact,
Contacts, ContactsFilterCollection,
ProfileView, ContactsTitleView, ContactsView, ContactsFilterView) {
var myProfile = new Profile(),
myContacts = new Contacts([
new Contact({
name: "Benny",
title: "Web/Mobile Expert"
}),
new Contact({
name: "Judy",
title: "Owner @ JudyArt"
}),
new Contact({
name: "Ori Halperin",
title: "A Skilled Artist"
})
]),
myProfileView,
myContactsTitleView,
myContactsView,
filterView;
function init() {
Templates.init();
hello.on("auth.login", function(auth) {
hello(auth.network).api("/me").success(function(response) {
myProfileView = new ProfileView({
model: new Profile({
name: response.formattedName,
imageUrl: response.thumbnail
})
});
renderProfile();
});
hello(auth.network).api("/me/friends", { limit: 100 }).success(function(response) {
var contactsStatsData,
contactsByIndustry,
collectionData;
contactsStatsData = new ContactsStatsModel({
total: response._total,
count: response._count
});
collectionData = _(response.data).map(function(o) {
var profileUrl = o.siteStandardProfileRequest ? o.siteStandardProfileRequest.url : "";
return {
id: o.id,
firstName: o.firstName,
lastName: o.lastName,
name: o.name,
title: o.headline,
industry: o.industry,
pictureUrl: o.pictureUrl,
profileUrl: profileUrl
};
});
collectionData = _(collectionData).sortBy(function(o) {
return (o.lastName + o.firstName).toLowerCase();
});
myContactsTitleView = new ContactsTitleView({
model: contactsStatsData
});
myContactsView = new ContactsView({
collection: new Contacts(collectionData)
});
contactsByIndustry = _(collectionData).groupBy(function(o) {
return o.industry;
});
contactsByIndustry = _(contactsByIndustry).map(function(industry, i) {
return {
name: i,
count: industry.length,
contacts: _(industry).map(function(contact) {
return {
id: contact.id
};
})
}
});
contactsByIndustry = _(contactsByIndustry).sortBy(function(o) {
return -o.count
});
filterView = new ContactsFilterView({
collection: new ContactsFilterCollection(contactsByIndustry)
});
renderContacts();
});
});
}
function renderProfile() {
myProfileView.render();
}
function renderContacts() {
myContactsTitleView.render();
myContactsView.render();
filterView.render();
}
return {
contactView: myContactsView,
init: init
};
});