unserver-unify
Version:
259 lines (247 loc) • 14.5 kB
JavaScript
;
angular.module('bamboo.common').service('CertificateModel', function(ApiService, $q, CertService, loginService, oopHelper,certBizModel,$filter) {
var self = this;
function getDate(time) {
var d = new Date(time);
var datestring = d.getDate() + " / " + (d.getMonth() + 1) + " / " + d.getFullYear();
if(loginService.subDomain=='sgpower'){
var datestring = $filter('date')(d,"dd-MMM-yyyy");
}
return datestring;
}
function formatDate(time){
return $filter('date')(new Date(time),'dd MMMM yyyy');
}
/**
* BaseCert class
*/
function BaseCert(certInfo) {
this.certInfo = certInfo;
}
BaseCert.prototype.getCertTemplate = function() {
var that = this;
var lang = this.certInfo.lang||'en_US';
var orientation = this.certInfo.orientation||'landscape';
var deferred = $q.defer();
var promise = deferred.promise;
certBizModel.getTplDataByConf(this.certInfo).then(function(data){
// console.log(data)
// console.log(lang)
var tplData;
// orientation = data.orientation.toLowerCase();
if(data.orientation){
orientation = data.orientation.toLowerCase();
}
console.log(orientation)
if (lang === 'en_US') {
if (orientation === 'landscape') {
tplData = that.getUSLandCertTemplate(data);
} else {
tplData = that.getUSPotrCertTemplate(data);
}
} else {
if (orientation === 'landscape') {
tplData = that.getCNLandCertTemplate(data);
} else {
tplData = that.getCNPotrCertTemplate(data);
}
}
// console.log(tplData)
data.certBase64Data = tplData;
deferred.resolve(data);
},function(){
deferred.reject('Get tpl data failed !');
console.error('Get tpl data failed !');
});
//this.certInfo.certBase64Data = tplData;
return promise;
}
BaseCert.prototype.getUSLandCertTemplate = function(certInfo) {
var USTplWithoutNo_landscape = '<svg xmlns="http://www.w3.org/2000/svg">'
+ '<foreignObject width="100%" height="100%">'
+ '<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:30px; width:100%; text-align:center; font-weight:500; font-family:arial; padding-top:100px">'
+ '<div style="margin-bottom:20px; font-size:30px;">This certifies that</div>'
+ '<div style="margin-bottom:20px; font-size:30px;">Name: <span style="border-bottom:solid 2px #555; font-size:35px; font-weight:600; padding:0 10px; text-transform:uppercase;">'
+ certInfo.userfullname + '</span></div>'
+ '<div style="margin:0 auto;text-align: center;margin-bottom:20px;">Has successfully completed the</div>'
+ '<div style="margin-bottom:20px; font-size:35px; text-transform:uppercase; font-weight:600;">'
+ certInfo.coursename + '</div>'
+ '<div style="margin-bottom:20px;">and is awarded this certificate by</div>'
+ '<div style="margin-bottom:20px; font-size:35px; text-transform:uppercase; font-weight:600;">'
+ certInfo.schoolname + '</div>'
+ '<div style="margin-bottom:20px;">Date: <span style="border-bottom:solid 2px #555; padding:0 10px;">'
+ getDate(certInfo.time)
+ '</span></div>'
+ '</div>'
+ '</foreignObject>'
+ '</svg>';
return USTplWithoutNo_landscape;
}
BaseCert.prototype.getCNLandCertTemplate = function() {}
BaseCert.prototype.getUSPotrCertTemplate = function(certInfo) {
var USTplWithoutNo_portrait = '<svg xmlns="http://www.w3.org/2000/svg">'
+ '<foreignObject width="100%" height="100%">'
+ '<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:40px; width:100%; text-align:center; font-weight:500; font-family:arial; padding-top:80px">'
+ '<div style="margin-top:250px;margin-bottom:50px; font-size:40px;">This certifies that</div>'
+ '<div style="margin-bottom:50px; font-size:40px;">Name: <span style="border-bottom:solid 2px #555; font-size:45px; font-weight:600; padding:0 10px; text-transform:uppercase;">'
+ certInfo.userfullname + '</span></div>'
+ '<div style="margin:0 auto;text-align: center; font-size:35px; margin-bottom:40px;">Has successfully completed the</div>'
+ '<div style="margin-bottom:50px; font-size:45px; text-transform:uppercase; font-weight:600;">'
+ certInfo.coursename + '</div>'
+ '<div style="margin-bottom:50px; font-size:35px;">and is awarded this certificate by</div>'
+ '<div style="margin-bottom:50px; font-size:50px; font-style:italic; font-weight:500; font-family:tahoma;">'
+ certInfo.schoolname + '</div>'
+ '<div style="margin-bottom:30px; font-size:35px;">Date: <span style="border-bottom:solid 2px #555; padding:0 10px;">'
+ getDate(certInfo.time)
+ '</span></div>'
+ '</div>'
+ '</foreignObject>'
+ '</svg>';
return USTplWithoutNo_portrait;
}
BaseCert.prototype.getCNPotrCertTemplate = function() {}
////////////////////////////////////////////
// child class //
///////////////////////////////////////////
function SgpowerCert(certInfo) {
SgpowerCert.uber.constructor.call(this, certInfo);
}
function CaregiverasiaCert(certInfo) {
CaregiverasiaCert.uber.constructor.call(this, certInfo);
}
function BambooCert(certInfo) {
BambooCert.uber.constructor.call(this, certInfo);
}
function HdbCert(certInfo) {
HdbCert.uber.constructor.call(this, certInfo);
}
oopHelper.extend(SgpowerCert, BaseCert);
oopHelper.extend(CaregiverasiaCert, BaseCert);
oopHelper.extend(BambooCert, BaseCert);
oopHelper.extend(HdbCert, BaseCert);
////////////////////////////////////////////
// override //
///////////////////////////////////////////
//sgpower override template
SgpowerCert.prototype.getUSLandCertTemplate = function(certInfo) {
var USTplWithNoSgpower_landscape = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">'
+ '<foreignObject width="100%" height="100%">'
+ '<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:40px; width:100%; text-align:center; font-weight:500; font-family:arial; padding-top:'
+ certInfo.paddingtop + 'px">'
+ '<div style="margin-top:0px; margin-bottom:20px; font-size:50px; font-style:italic; font-weight:600; text-transform:uppercase;">'
+ certInfo.userfullname + '</div>'
+ '<div style="margin-bottom:40px; text-align: center;">has successfully attended the course on</div>'
+ '<div style="margin-bottom:60px; font-size:45px; font-weight:600; text-transform:uppercase; font-weight:600;">'
+ certInfo.coursename + '</div>'
+ '<div style="margin-bottom:50px;">conducted by</div>'
+ '<div style="margin-bottom:50px; font-size:50px; font-style:italic; font-weight:500; font-family:tahoma;">Singapore Institute of Power and Gas Pte Ltd</div>'
+ '<div style="margin-bottom:250px; font-size:36px;">'
//+ getDate(certInfo.time)
+ ((certInfo.classStart&&certInfo.classStop)?(certInfo.classStart + '<span style="padding-left:8px;padding-right:8px">to</span>' + certInfo.classStop):getDate(certInfo.time))
+ '</div>'
//+ '<div style="margin-bottom:20px; font-size:30px; font-family:Times New Roman;">Peter Leong</div>'
//+ '<div style="margin-bottom:20px; font-size:30px; font-family:Times New Roman;">Principal</div>'
+ '</div>'
+ '</foreignObject>'
+ '</svg>';
return USTplWithNoSgpower_landscape;
}
SgpowerCert.prototype.getCNLandCertTemplate = function() {}
SgpowerCert.prototype.getUSPotrCertTemplate = function(certInfo) {
var USTplWithNoSgpower_portrait = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">'
+ '<foreignObject width="100%" height="100%">'
+ '<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:30px; width:100%; text-align:center; font-weight:500; font-family:Malgun Gothic; padding-top:'
+ certInfo.paddingtop + 'px">'
+ '<div style="margin-top:250px; margin-bottom:30px; text-align: center;">This is to certify that</div>'
+ '<div style="margin-bottom:20px; font-size:60px; font-family:Monotype Corsiva; font-weight:600;">'
+ certInfo.userfullname + '</div>'
+ '<div style="margin-bottom:30px; text-align: center;">has successfully attended the course on</div>'
+ '<div style="margin-bottom:60px; font-size:55px; font-family:Monotype Corsiva; font-weight:600;">'
+ certInfo.coursename + '</div>'
+ '<div style="margin-bottom:30px;">conducted by</div>'
+ '<div style="margin-bottom:50px; font-size:50px; font-weight:600; font-family:Monotype Corsiva;">Singapore Institute of Power and Gas Pte Ltd</div>'
// + '<div style="margin-bottom:20px;">Date of Course</div>'
+ '<div style="margin-bottom:250px; font-size:26px;">'
+ ((certInfo.classStart&&certInfo.classStop)?(certInfo.classStart + '<span style="padding-left:8px;padding-right:8px">to</span>' + certInfo.classStop):getDate(certInfo.time))
+ '</div>'
//+ '<div style="margin-bottom:20px; font-size:30px; font-family:Times New Roman;">Peter Leong</div>'
//+ '<div style="margin-bottom:20px; font-size:30px; font-family:Times New Roman;">Principal</div>'
+ '</div>'
+ '</foreignObject>'
+ '</svg>';
return USTplWithNoSgpower_portrait;
}
SgpowerCert.prototype.getCNPotrCertTemplate = function() {}
//caregivenasia override template
CaregiverasiaCert.prototype.getUSLandCertTemplate = function(certInfo) {
var USTplWithoutNo_caregivenasia_landscape = '<svg xmlns="http://www.w3.org/2000/svg">'
+ '<foreignObject width="100%" height="100%">'
+ '<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:30px; width:100%; text-align:left; font-weight:500; font-family:arial; padding:130px">'
+ '<div style="margin-bottom:20px; font-size:30px;">This certifies that</div>'
+ '<div style="margin-bottom:20px; font-size:30px;">Name: <span style="border-bottom:solid 2px #555; font-size:35px; font-weight:600; padding:0 10px; text-transform:uppercase;">'
+ certInfo.userfullname + '</span></div>'
+ '<div style="margin:0 auto;text-align: center;margin-bottom:20px;">Has successfully completed the</div>'
+ '<div style="margin-bottom:20px; font-size:35px; text-transform:uppercase; font-weight:600;">'
+ certInfo.coursename + '</div>'
+ '<div style="margin-bottom:20px;">and is awarded this certificate by</div>'
+ '<div style="margin-bottom:20px; font-size:35px; text-transform:uppercase; font-weight:600;">'
+ certInfo.schoolname + '</div>'
+ '<div style="margin-bottom:20px;">Date: <span style="border-bottom:solid 2px #555; padding:0 10px;">'
+ getDate(certInfo.time)
+ '</span></div>'
+ '</div>'
+ '</foreignObject>'
+ '</svg>';
return USTplWithoutNo_caregivenasia_landscape;
}
CaregiverasiaCert.prototype.getCNLandCertTemplate = function() {}
CaregiverasiaCert.prototype.getUSPotrCertTemplate = function(certInfo) {
var USTplWithoutNo_caregivenasia_portrait = '<svg xmlns="http://www.w3.org/2000/svg">'
+ '<foreignObject width="100%" height="100%">'
+ '<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:28px; width:100%; text-align:left; font-weight:500; font-family:arial; padding:620px 155px 30px">'
+ '<div style="margin-bottom:100px; font-weight:500;">'
+ certInfo.userfullname + '</div>'
+ '<div style="margin-bottom:95px; font-weight:500;">'
+ certInfo.coursename + '</div>'
// + '<div style="margin-bottom:80px; font-weight:500;">'
// + certInfo.schoolname + '</div>'
+ '<div style="margin-bottom:30px;">'
+ formatDate(certInfo.time)
+ '</div>'
+ '</div>'
+ '</foreignObject>'
+ '</svg>';
return USTplWithoutNo_caregivenasia_portrait;
}
CaregiverasiaCert.prototype.getCNPotrCertTemplate = function() {}
HdbCert.prototype.getUSLandCertTemplate = function(certInfo) {
var USTplWithoutNo_landscape = '<svg xmlns="http://www.w3.org/2000/svg">'
+ '<foreignObject width="100%" height="100%">'
+ '<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:30px; width:85%; padding-left:15%; text-align:center; font-weight:500; font-family:arial; padding-top:200px">'
+ '<div style="margin-bottom:40px; font-size:30px;">This certificate is awarded to</div>'
+ '<div style="margin-bottom:40px; font-size:30px;"><span style="border-bottom:solid 2px #555; font-size:35px; font-weight:600; padding:0 10px; text-transform:uppercase;">'
+ certInfo.userfullname + '</span></div>'
+ '<div style="margin:0 auto; text-align: center; margin-bottom:40px;">for the completion of</div>'
+ '<div style="margin-bottom:40px;"><span style="border-bottom:solid 2px #555; font-size:35px; font-weight:600; padding:0 10px; text-transform:uppercase;">'
+ certInfo.coursename + '</span></div>'
+ '</div>'
+ '</foreignObject>'
+ '</svg>';
return USTplWithoutNo_landscape;
}
HdbCert.prototype.getCNLandCertTemplate = function() {}
self.createCertModel = function(certInfo){
var subdomain = loginService.subDomain;
var className = s.capitalize(subdomain)+"Cert";
console.log(loginService.school);
//currentSchool.apiOptions.hdbftp
// console.log(eval(className));
if(className=='SgpowerCert'||className=='CaregiverasiaCert'){
return eval('new'+' '+className+'('+JSON.stringify(certInfo)+')');
} else if(loginService.school&&loginService.school.apiOptions&&loginService.school.apiOptions.hdbftp){
return new HdbCert(certInfo);
}else{
return new BambooCert(certInfo);
}
}
});