unserver-unify
Version:
304 lines (291 loc) • 9.05 kB
JavaScript
;
angular.module('bamboo.course').controller('MyResumeCtrl', function($scope, ApiService, Lightbox, loginService, $uibModal, CommonService, $sce,$translate) {
var self = this;
this.tab = "intro";
this.resume = {};
this.tmpResume = {};
this.resumePath = ApiService.SHOST + "/resume/" + loginService.user._id + "/";
this.category = [];
for (var key in ApiService.projectcategory) {
this.category.push(key);
}
this.imagePicUrl = ApiService.PSURL + "/avatar/";
this.showTab = "profile";
$scope.editProfile = function() {
self.showTab = "editProfile";
};
$scope.profile = function() {
self.showTab = "profile";
};
function loadResumeData() {
ApiService.post('/job', {
action: 'getmyresume'
}).then(function(result) {
if (result.data.success) {
self.resume = result.data.data || {};
console.log(result.data.data)
self.tmpResume = angular.copy(self.resume)
if (!self.tmpResume.history) {
self.tmpResume.history = []
}
if (!self.tmpResume.history[0]) {
self.tmpResume.history[0] = {};
}
if (self.tmpResume.history.length < 1) {
self.tmpResume.history.push({});
} else {
angular.forEach(self.tmpResume.history, function(company) {
if (company.start) {
company.start = new Date(company.start);
}
if (company.end) {
company.end = new Date(company.end);
}
})
}
if (!self.tmpResume.educations) {
self.tmpResume.educations = []
}
if (!self.tmpResume.educations[0]) {
self.tmpResume.educations[0] = {};
}
if (self.tmpResume.educations.length < 1) {
self.tmpResume.educations.push({});
} else {
angular.forEach(self.tmpResume.educations, function(company) {
if (company.start) {
company.start = new Date(company.start);
}
if (company.end) {
company.end = new Date(company.end);
}
})
}
console.log(self.tmpResume);
// self.detectedFileType = detectFileType();
if (!self.tmpResume.fullname) {
self.tmpResume.fullname = loginService.user.fullname;
}
if (!self.tmpResume.loginname) {
self.tmpResume.loginname = loginService.user.name;
}
}
})
}
loadResumeData();
self.detectedFileType=function(file) {
var list = ['pdf','doc','docx','docm','dotm','xls','xlsx','xlsb','xlsm','ppt','pptx','ppsx','pps','pptm','potm','ppam','potx','ppsm'];
return file && (list.indexOf(file.split('.').pop().toLowerCase()) !== -1);
};
function getFileSuffix(file) {
return file.split('.').pop().toLowerCase();
}
this.previewCV = function(file) {
console.log(file);
var fileType = getFileSuffix(file);
var conf = {
file:file,
type:fileType,
absURL:self.resumePath + encodeURI(file)
}
/*$scope.preview = !$scope.preview;
var fullurl = self.resumePath + encodeURI(file);
if(file.split('.').pop().toLowerCase()!='pdf')
{
fullurl = "https://view.officeapps.live.com/op/embed.aspx?src=" + self.resumePath + encodeURI(file);
}
$scope.pdfUrl = $sce.trustAsResourceUrl(fullurl);*/
var modalInstance = $uibModal.open({
animation: true,
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
templateUrl: 'components/dialog/cvpreview-dlg.html',
controller: 'cvPreviewModalCtrl',
controllerAs: 'ctrl',
size: 'lg',
resolve: {
config: function() {
return conf;
}
}
});
modalInstance.result.then(function(selectedItem) {
//$ctrl.selected = selectedItem;
console.log("---success");
}, function() {
console.log('Modal dismissed at: ' + new Date());
});
};
//console.log(loginService.user);
var documentSetting = {
promise: true,
accept: ".pdf,.doc,.docx,.xls",
s3: true,
title: "Document",
randomFlag: true,
maxSize: 50000,
resPath: "resume/" + loginService.user._id + "/",
};
//videoresumeSetting.resPath=resumeSetting.resPath = "resume/" + loginService.user._id + "/";
this.uploadDocument = function() {
CommonService.uploadFile(documentSetting).then(function(result) {
var files=self.resume.files||[];
files.push(result.fileName);
var info = {
object: {
files:files
// file: result.fileName,
},
action: 'savemyresume',
}
ApiService.post('/job', info).then(function(result) {
if (result.data.success) {
CommonService.showNoBlockInfo('Update Successful!');
loadResumeData();
}
});
});
};
var resumeSetting = {
promise: true,
accept: ".pdf,.doc,.docx,.xls",
s3: true,
title: "Resume",
randomFlag: true,
maxSize: 50000,
resPath: "resume/" + loginService.user._id + "/",
};
//videoresumeSetting.resPath=resumeSetting.resPath = "resume/" + loginService.user._id + "/";
this.uploadResume = function() {
CommonService.uploadFile(resumeSetting).then(function(result) {
var info = {
object: {
file: result.fileName,
},
action: 'savemyresume',
}
ApiService.post('/job', info).then(function(result) {
if (result.data.success) {
CommonService.showNoBlockInfo('Update Successful!');
loadResumeData();
}
});
});
};
this.removeDocument=function(index){
if(!self.resume.files||self.resume.files.length<(index+1)){
return;
}
self.resume.files.splice(index,1);
var info = {
object: {
files:self.resume.files
// file: result.fileName,
},
action: 'savemyresume',
}
console.log(info);
ApiService.post('/job', info).then(function(result) {
if (result.data.success) {
CommonService.showNoBlockInfo('Update Successful!');
loadResumeData();
}
});
}
this.removeResume=function(){
var info = {
object: {
file: '',
},
action: 'savemyresume',
}
console.log(info);
ApiService.post('/job', info).then(function(result) {
if (result.data.success) {
CommonService.showNoBlockInfo('Update Successful!');
loadResumeData();
}
});
}
var videoresumeSetting = {
promise: true,
accept: ".mp4",
title: "Video Resume",
videorecord: true,
randomFlag: true,
maxSize: 204800,
convert: true,
resPath: "resume/" + loginService.user._id + "/",
};
this.showVideoResume = function() {
var fullurl = self.resumePath + encodeURI(self.tmpResume.video);
Lightbox.openModal([{
'type': 'video',
url: fullurl
}], 0);
};
this.uploadVideoResume = function() {
CommonService.uploadFile(videoresumeSetting).then(function(result) {
var info = {
object: {
video: result.fileName,
},
action: 'savemyresume',
}
ApiService.post('/job', info).then(function(result) {
if (result.data.success) {
loadResumeData();
CommonService.showNoBlockInfo('Update Successful!');
loadResumeData();
}
});
});
};
this.addHistory = function() {
self.tmpResume.history.push({});
}
this.delHistory = function(index) {
self.tmpResume.history.splice(index, 1);
}
this.addEducation = function() {
self.tmpResume.educations.push({});
}
this.delEducation = function(index) {
self.tmpResume.educations.splice(index, 1);
}
this.update = function() {
var toSave = {};
// console.log(self.tmpResume);
// console.log(self.tmpResume);
for (var key in self.tmpResume) {
if (self.tmpResume[key] != self.resume[key]) {
toSave[key] = self.tmpResume[key];
}
}
console.log(toSave);
var edus = toSave.educations || [];
var eduLen = edus.length || 0;
var firstEdu = edus[0] || {};
if (eduLen === 1 && (!firstEdu.school || !firstEdu.certificate)) {
CommonService.showNoBlockErr('School and certificate are required!');
return;
}
ApiService.post('/job', {
action: 'savemyresume',
object: toSave,
}).then(function(result) {
if (result.data.success) {
CommonService.showNoBlockInfo('Update Successful!');
loadResumeData();
};
});
}
$scope.tags = [{
text: $translate.instant('English')
}, {
text: $translate.instant('Chinese')
}];
$scope.loadTags = function(query) {
return $scope.tags;
};
});