Passed
Push — master ( 6f8171...7c2bcd )
by
unknown
48s
created

DashboardAPI.getApplicationsByUuserId   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 1
rs 10
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
7
8
var DashboardAPI = {};
9
10
DashboardAPI.yourApplications = {};
11
12
DashboardAPI.application = function(job_poster_id, job_poster_title, job_poster_close_date_time, user_id, user_manager_profile_id, department_details_name, application_status){
13
    this.job_poster_id = job_poster_id;
14
    this.job_poster_title = job_poster_title;
15
    this.job_poster_close_date_time = job_poster_close_date_time;
16
    this.user_id = user_id;
17
    this.user_manager_profile_id = user_manager_profile_id;
18
    this.department_details_name = department_details_name;
19
    this.application_status = application_status;
20
};
21
22
DashboardAPI.version = "v1";
23
//Live URL
24
DashboardAPI.baseURL = "/tc/api/"+DashboardAPI.version+"";
25
26
DashboardAPI.showDashboard = function(){
27
    var stateInfo = {pageInfo: 'dashboard', pageTitle: 'Talent Cloud: Dashboard'};
28
    document.title = stateInfo.pageTitle;
29
    history.pushState(stateInfo, stateInfo.pageInfo, '#Dashboard');
0 ignored issues
show
Bug introduced by
The variable history seems to be never declared. If this is a global, consider adding a /** global: history */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
30
31
    EventsAPI.hideAllLayouts();
0 ignored issues
show
Bug introduced by
The variable EventsAPI seems to be never declared. If this is a global, consider adding a /** global: EventsAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
32
    window.scrollTo(0,0);
33
    document.getElementById("skipNav").focus();
34
35
    var dashboardSection = document.getElementById("dashboardSection");
36
    dashboardSection.classList.remove("hidden");
37
38
    var active = document.getElementById("navigationDashboardLinkWrapper");
0 ignored issues
show
Unused Code introduced by
The variable active seems to be never used. Consider removing it.
Loading history...
39
    navigationDashboardLinkWrapper.classList.add("active");
0 ignored issues
show
Bug introduced by
The variable navigationDashboardLinkWrapper seems to be never declared. If this is a global, consider adding a /** global: navigationDashboardLinkWrapper */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
40
41
    var inactive = document.getElementById("navigationBrowseLinkWrapper");
0 ignored issues
show
Unused Code introduced by
The variable inactive seems to be never used. Consider removing it.
Loading history...
42
    navigationBrowseLinkWrapper.classList.remove("active");
0 ignored issues
show
Bug introduced by
The variable navigationBrowseLinkWrapper seems to be never declared. If this is a global, consider adding a /** global: navigationBrowseLinkWrapper */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
43
44
    DashboardAPI.getApplicationsByUuserId();
45
46
    // New Subpage Hero Scripts
47
48
    Utilities.getHeroElements();
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
49
50
    TalentCloudAPI.setNav("navigationDashboardLinkWrapper");
0 ignored issues
show
Bug introduced by
The variable TalentCloudAPI seems to be never declared. If this is a global, consider adding a /** global: TalentCloudAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
51
52
    var dashboardHeroTitle = document.getElementById("dashboardHeroTitle");
53
    dashboardHeroTitle.classList.remove("hidden");
54
    dashboardHeroTitle.setAttribute("aria-hidden", "false");
55
56
    // Mobile Menu Overflow Release
57
    document.body.style.overflowY = "auto";
58
59
    // Google Analytics
60
61
    ga('set', 'page', '/my-applications');
62
    ga('send', 'pageview');
63
64
};
65
66
/**
67
 *
68
 * @returns {undefined}
69
 */
70
DashboardAPI.getApplicationsByUuserId = function(){
71
72
    //does the request need to be secure?
73
74
    var user_id = "";
75
76
    if(UserAPI.hasSessionUser()){
0 ignored issues
show
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
77
        user_id = UserAPI.getSessionUserAsJSON().user_id;
78
    }
79
80
    //what url am I connecting to get the data? - see tc/.htaccess file
81
    var dashboard_url = DashboardAPI.baseURL + "/" + locale + "/dashboard/" + user_id;
0 ignored issues
show
Bug introduced by
The variable locale seems to be never declared. If this is a global, consider adding a /** global: locale */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
82
    DataAPI.sendRequest(dashboard_url, "GET", {'Content-type': 'application/json; charset=utf-8'}, null, function(request){
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
83
        DashboardAPI.dashboardDataLoaded(request.responseText);
84
    });
85
};
86
87
DashboardAPI.dashboardDataLoaded = function(response){
88
    var responseJSON = JSON.parse(response);
89
    DashboardAPI.populateDashboard(responseJSON);
90
};
91
92
/**
93
 *
94
 * @returns {undefined}
95
 */
96
DashboardAPI.transferFailed = function(){
97
    NetworkErrorMessage();
98
};
99
100
/**
101
 *
102
 * @returns {undefined}
103
 */
104
DashboardAPI.transferAborted = function(){
105
106
};
107
108
109
/**
110
 *
111
 * @param {type} evt
112
 * @returns {undefined}
113
 */
114
DashboardAPI.dashboardDataUpdateProgress = function(evt){
115
    Utilities.debug?console.log(evt):null;
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
116
    if(evt.lengthComputable){
117
        var total = evt.total;
118
        var value = evt.loaded;
119
120
        Utilities.debug?console.log(total + "=" + value):null;
0 ignored issues
show
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
121
122
        var percentComplete = Math.ceil((evt.loaded / evt.total) * 100);
0 ignored issues
show
Unused Code introduced by
The variable percentComplete seems to be never used. Consider removing it.
Loading history...
123
        //var loadingProgress = document.getElementById("loadingProgress");
124
        //loadingProgress.innerHTML = " " + percentComplete + "%";
125
    }
126
};
127
128
DashboardAPI.populateDashboard = function(dashboardJSON){
129
130
    //get yourApplications section from DOM
131
    var yourApplicationsSection = document.getElementById("yourApplications");
132
    yourApplicationsSection.setAttribute("tabIndex","0");
133
    yourApplicationsSection.innerHTML = "";
134
    for(var d = 0; d < dashboardJSON.length; d++){
135
        var application = dashboardJSON[d];
136
137
        var applicationRow = document.createElement("div");
138
        applicationRow.setAttribute("id","ya_job_poster_id_"+application.job_poster_id);
139
        applicationRow.setAttribute("tabIndex","0");
140
        if(d === (dashboardJSON.length - 1)){
141
            applicationRow.setAttribute("class","dashboardJobSummaryLast");
142
        }else{
143
            applicationRow.setAttribute("class","dashboardJobSummary");
144
        }
145
146
        var applicationTitleDept = document.createElement("div");
147
        applicationTitleDept.setAttribute("id","ya_title_dept_"+application.job_poster_id);
148
        applicationTitleDept.setAttribute("class","dashboardTitleDepartmentWrapper");
149
150
        var applicationTitle = document.createElement("div");
151
        applicationTitle.setAttribute("id","ya_title_"+application.job_poster_id);
152
        applicationTitle.setAttribute("class","dashboardJobSummaryTitle");
153
        applicationTitle.setAttribute("tabIndex","0");
154
        applicationTitle.innerHTML = application.job_poster_title;
155
        applicationTitleDept.appendChild(applicationTitle);
156
157
        var applicationDept = document.createElement("div");
158
        applicationDept.setAttribute("id","ya_dept_"+application.job_poster_id);
159
        applicationDept.setAttribute("class","dashboardJobSummaryDepartment");
160
        applicationDept.setAttribute("tabIndex","0");
161
        applicationDept.innerHTML = " - " + application.department_details_name;
162
        applicationTitleDept.appendChild(applicationDept);
163
164
        applicationRow.appendChild(applicationTitleDept);
165
166
        var applicationManager = document.createElement("a");
167
        applicationManager.setAttribute("id","ya_manager_"+application.job_poster_id);
168
        applicationManager.setAttribute("href","javascript:void(0)");
0 ignored issues
show
Coding Style introduced by
Script urls should not be used.
Loading history...
169
        applicationManager.setAttribute("onclick","ManagerProfileAPI.showManagerProfile('"+application.manager_user_id+"');");
170
        applicationManager.setAttribute("class","dashBoardHiringManagerWrapper");
171
172
        applicationRow.appendChild(applicationManager);
173
174
        var applicationSubmitted = document.createElement("div");
175
        applicationSubmitted.setAttribute("id","ya_submitted_"+application.job_poster_id);
176
        applicationSubmitted.setAttribute("class","dashboardJobSubmitted");
177
178
        var applicationStatus = document.createElement("p");
179
        applicationStatus.setAttribute("id","ya_status_"+application.job_poster_id);
180
        applicationStatus.setAttribute("class","dashboardJobStatus");
181
        applicationStatus.setAttribute("tabIndex","0");
182
        var statusInnerHTML = application.application_status;
183
184
        var closeStatus = document.createElement("span");
185
        closeStatus.setAttribute("id","ya_close_status_"+application.job_poster_id);
186
        closeStatus.setAttribute("class","dashboardJobCloseStatus");
187
        var closeInfo = Utilities.timeRemaining(application.job_poster_close_date_time);
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
188
        var closesIn = TalentCloudAPI.getLanguageFromCookie() === "en_CA"?"Closes in " : "Ferme dans ";
0 ignored issues
show
Bug introduced by
The variable TalentCloudAPI seems to be never declared. If this is a global, consider adding a /** global: TalentCloudAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
189
        var closed = TalentCloudAPI.getLanguageFromCookie() === "en_CA"?"Closed " : "Fermé ";
190
        var closeInnerHTML = closeInfo !== 0?closesIn + closeInfo:closed;
191
        closeStatus.innerHTML = closeInnerHTML;
192
193
        applicationStatus.innerHTML = statusInnerHTML + " - " + closeStatus.outerHTML;
194
195
        applicationSubmitted.appendChild(applicationStatus);
196
197
        applicationRow.appendChild(applicationSubmitted);
198
199
        yourApplicationsSection.appendChild(applicationRow);
200
201
        DashboardAPI.populateManagerProfile(application);
202
    }
203
};
204
205
DashboardAPI.populateManagerProfile = function(application){
206
    //console.log(application);
207
208
209
    var hiringManagerWidget = document.createElement("a")
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
210
    hiringManagerWidget.setAttribute("id","ya_manager_widget_"+application.job_poster_id);
211
    hiringManagerWidget.setAttribute("class","hiringManagerWidget");
212
213
    var hiringManagerProfilePicSmall = document.createElement("img");
214
    hiringManagerProfilePicSmall.setAttribute("id","ya_manager_profilepic_"+application.job_poster_id);
215
    hiringManagerProfilePicSmall.setAttribute("class","hiringManagerProfilePicSmall");
216
    hiringManagerProfilePicSmall.setAttribute("tabIndex","0");
217
    ProfilePicAPI.refreshProfilePic(application.manager_user_id, hiringManagerProfilePicSmall);
0 ignored issues
show
Bug introduced by
The variable ProfilePicAPI seems to be never declared. If this is a global, consider adding a /** global: ProfilePicAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
218
    hiringManagerWidget.appendChild(hiringManagerProfilePicSmall);
219
220
    var hiringManagerWidgetName = document.createElement("div")
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
221
    hiringManagerWidgetName.setAttribute("id","ya_manager_name_"+application.job_poster_id);
222
    hiringManagerWidgetName.setAttribute("class","hiringManagerName");
223
    hiringManagerWidgetName.setAttribute("tabIndex","0");
224
    hiringManagerWidget.appendChild(hiringManagerWidgetName);
225
226
    //Start requests for Hiring Manager data
227
    //Load Hiring Manager Name
228
    DataAPI.getManagerProfile(application.manager_user_id, function(response) {
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
229
       var managerProfile = JSON.parse(response);
230
       console.log(managerProfile);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
231
       document.getElementById("ya_manager_name_"+application.job_poster_id).innerHTML = managerProfile.user.name;
232
    });
233
234
    var ya_job_poster_manager_element = document.getElementById("ya_manager_"+application.job_poster_id);
235
    ya_job_poster_manager_element.appendChild(hiringManagerWidget);
236
237
};
238