-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.js
More file actions
149 lines (131 loc) · 3.46 KB
/
student.js
File metadata and controls
149 lines (131 loc) · 3.46 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const { log } = console;
const { coaches } = loadPGecom();
let listCoach = coaches || [];
const getCoach = async () => {
try {
const options = {
url,
};
const coaches = await $.ajax(options);
listCoach = coaches;
addCoachesToLocalStorage(coaches);
return {
isError: false,
coaches,
};
} catch (error) {
return {
isError: true,
coaches: [],
};
}
};
const getCoachById = async (id) => {
try {
const options = {
url: `${url}?id=${id}`,
};
const coach = await $.ajax(options);
return {
isError: false,
coach,
};
} catch (error) {
return {
isError: true,
coach: [],
};
}
};
const displayCoachExperience = (experiences) => {
const result = experiences.map((experience) => {
return `
<li>${experience}</li>
`;
});
return result;
};
const modalTemplate = (coach) => {
const {
fullName,
profilePictureUrl,
country,
experiences,
hubspotCalendarUrl,
} = coach;
const modalFooter = `
<a href="${hubspotCalendarUrl}" class="modal-close waves-effect waves-green btn">
Schedule
</a>
`;
const fullNameEl = $("<h4>").text(fullName);
const profileImgEl = $("<img>").attr("src", profilePictureUrl);
const countryEl = $(`<p><b>Country: </b> ${country}</p>`);
const experiencesList = $("<ul></ul>");
experiences.map((experience) => {
const currentList = $("<li>").text(experience);
currentList.css({
"list-style-type": "initial",
"margin-left": "25px",
});
experiencesList.append(currentList);
});
const experienceTitle = $("<b>Experiences: </b>");
const modalContent = $("<div>");
modalContent.append(fullNameEl);
modalContent.append(profileImgEl);
modalContent.append(countryEl);
modalContent.append(experienceTitle);
modalContent.append(experiencesList);
return {
modalFooter,
modalContent,
};
};
const profileTemplate = (coach) => {
const { _id, fullName, profilePictureUrl, country, hubspotCalendarUrl } =
coach;
return `
<li class="collection-item avatar">
<div class="profile-card" data-id="${_id}">
<img src="${profilePictureUrl}" data-target="coach-modal" alt="" class="circle modal-trigger">
<span class="title">${fullName}</span>
</p>
<a href="${hubspotCalendarUrl}" class="waves-effect waves-green btn">
Schedule
</a>
</div>
<a href="${hubspotCalendarUrl}" class="secondary-content"><i class="material-icons">schedule</i></a>
</li>
`;
};
const renderCoachProfiles = (coaches) => {
$('.profile-view').empty();
const result = coaches.map((coach) => {
return `
<ul class="collection">
${profileTemplate(coach)}
</ul>
`;
});
$(".profile-view").append(result);
return result;
};
// Initialize Coach
getCoach().then(({ coaches }) => {
log("New coaches loaded!!: ", coaches);
renderCoachProfiles(coaches);
});
if (coaches.length) {
renderCoachProfiles(listCoach);
}
$(document).on("click", ".profile-card", async function () {
const coachId = $(this).attr("data-id");
const { coach } = await getCoachById(coachId);
const { modalContent, modalFooter } = modalTemplate(coach);
$(".modal-content").html(modalContent);
$(".modal-footer").html(modalFooter);
});
$(document).ready(function () {
$(".modal").modal();
});