unserver-unify
Version:
136 lines (131 loc) • 4.09 kB
JavaScript
angular.module('bamboo.material').controller('ProjectDetailCtrl', function(ApiService, loginService, $state, CommonService, $sce, $stateParams) {
var _self = this;
this.id = $stateParams.id;
this.item = {};
this.editmode;
this.photoPath = ApiService.SHOST + '/project/' + this.id + "/";
this.jobphotoPath = ApiService.SHOST + '/job/';
this.companypath = ApiService.SHOST + '/company/';
this.defaultJobPhoto = "/assets/images/jobs.png";
this.defaultProjectPhoto = "/assets/images/project1.png";
this.defaultLogoPhoto = "/assets/images/company.png";
this.tab = 0;
this.edit = function() {
_self.editmode = true;
}
function getInfo() {
ApiService.get("/project/" + _self.id).then(function(result) {
// console.log(result);
if (result.data.success) {
console.log(result.data.data);
_self.item = result.data.data || {};
if (_self.item.audio) {
_self.item.audiourl = $sce.trustAsResourceUrl(_self.photoPath + encodeURI(_self.item.audio));
}
_self.imageUrl = _self.item.photo ? _self.photoPath + _self.item.photo : _self.defaultProjectPhoto;
if(_self.item.companyId){
getCompanyInfo(_self.item.companyId);
}
}
});
getAllProjectJobs();
}
function getCompanyInfo(id){
var info={
action:"getcompany",
id:id,
}
ApiService.post("/business", info).then(function(result) {
if (result.data.success) {
_self.company = result.data.data || {};
console.log(_self.company);
_self.companyUrl = _self.company.photo ? _self.companypath + _self.company._id + '/' + _self.company.photo : _self.defaultLogoPhoto;
}
});
}
function getAllProjectJobs() {
ApiService.get("/projectjobs/" + _self.id).then(function(result) {
console.log(result);
if (result.data.success) {
console.log(result.data.data);
_self.jobs = result.data.data;
}
});
}
getInfo();
this.application = {};
var filesetting = {
promise: true,
s3: true,
title: 'Select Resume',
maxSize: 50000,
randomFlag: true,
resPath: 'project/' + _self.id + '/',
};
this.upload = function() {
CommonService.uploadFile(filesetting).then(function(data) {
console.log(data);
if (data.result) {
_self.application.resume = data.fileName;
CommonService.showInfo("Upload Completed!");
}
});
}
this.updateapplication = function() {
var object = {
brief: _self.application.brief,
}
if (_self.application.resume) {
object.resume = _self.application.resume;
}
var info = {
object: object,
action: "createapplication",
pid: _self.id,
}
if (_self.application._id) {
info.action = "updateapplication";
info.id = _self.application._id;
}
ApiService.post("/project", info).then(function(result) {
if (result.data.success) {
$state.reload();
} else {
CommonService.showError(result.data.error);
}
})
}
function getMyApplication() {
var info = {
pid: _self.id,
action: 'getmyapplication'
};
ApiService.post("/project", info).then(function(result) {
if (result.data.success) {
console.log(result.data.data);
if (result.data.data) {
_self.application = result.data.data;
}
} else {
CommonService.showError(result.data.error);
}
})
}
this.enroll = function() {
if (loginService.user) {
var info = {
id: _self.id,
action: 'addrecord'
};
ApiService.post("/project", info).then(function(result) {
if (result.data.success) {
CommonService.showInfo('Enroll Application submitted!');
} else {
CommonService.showError(result.data.error);
}
})
} else {
CommonService.showError("Please Login!");
}
}
});