-
Notifications
You must be signed in to change notification settings - Fork 4
/
JobController.js
168 lines (142 loc) · 3.86 KB
/
JobController.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
*
*/
'use strict';
app.controller('JobController', [
'$scope',
'JobService','UserService',
'$location',
'$rootScope',
function($scope, JobService, $location, $rootScope) {
console.log("JobController...")
var self = this; // self is alias name instead directly use this
self.job = { // initialization
job_id : '',
user_id:'',
job_title : '',
creation_date : '',
expiry_date:'',
status : '',
details : '',
company:'',
errorCode:'',
errorMessage:''
};
self.jobs = [];
/*APPLY FOR JOB*/
self.applyForJob=applyForJob
function applyForJob(jobID){
console.log("calling method applyForJob");
var currentUser=$rootScope.currentUser
console.log("currentUser.user_id:" + currentUser.user_id)
if(typeof currentUser=='undefined')
{
alert("Please login to apply for job")
console.log("User not logged in.Cannot apply")
$location.path('/login');
}
JobService
.applyForJob(jobID)
.then(
function(d){
self.job=d;
alert("You have successfully applied for job")
},
function(errResponse){
console.error('Error while applying')
});
}
/*GET SELECTED JOB DETAILS*/
self.getSelectedJob = getJob
function getJob(job_id) {
console.log("getting job! " + job_id)
JobService.getJob(job_id).then(function(d) {
self.job = d;
$location.path('/view_job');
}, function(errResponse) {
console.error('Error while fetching jobs');
});
};
/* GET LIST OF ALL JOBS */
self.fetchAllJobs = function() {
console.log("getting list of jobs")
JobService.fetchAllJobs()
.then(function(d) {
self.jobs = d;
}, function(errResponse) {
console.error('Error while fetching Jobs');
});
};
self.fetchAllJobs();
/* CREATE A JOB */
self.createJob = function(job) {
console.log('submit a new job',self.job);
JobService.createJob(job)
.then(function(d){
self.job=d;
},
function(errResponse) {
console.error('Error while creating Jobs');
});
};
/* UPDATE A JOB */
self.updateJob = function(job) {
JobService.updateJob(job).then(self.fetchAllJobs,
function(errResponse) {
console.error('Error while updating Jobs');
});
};
/* GET MY APPLIED JOBS*/
self.getMyAppliedJobs = function(){
console.log('calling the method getMyAppliedJobs');
JobService.getMyAppliedJobs().then(function(d){
self.jobs=d;
/*$location.path('list_job'); */
},function(errResponse) {
console.error('Error while applying Job');
});
};
/* REJECT JOB APPLICATION */
self.rejectJobApplication = function(userID){
console.log('calling rejectJobApplication');
JobService.rejectJobApplication().then(function(d){
self.jobs=d;
},function(errResponse) {
console.error('Error while applying Job');
});
};
/* SELECT A CANDIDATE */
self.selectUser = function(userID) {
console.log('Calling selectUser method:',userID);
JobService.selectUser(userID,selectedJobID)
.then(function(d){
self.job=d;
alert('Application status changed to selected')
},function(errResponse) {
console.error('Error while selecting candidate');
});
};
self.submit = function() {
//self.job.user_id = $rootScope.currentUser.user_id;
console.log('Saving New Job', self.job);
self.createJob(self.job);
self.reset();
};
self.reset=function(){
console.log('resetting the job',self.job);
self.job={
job_id : '',
user_id:'',
job_title : '',
creation_date : '',
expiry_date:'',
status : '',
details : '',
company:'',
errorCode:'',
errorMessage:''
};
$scope.myForm.$setPristine(); //reset Form
/* END OF ALL */
};
} ]);