kpiplus
Version:
KPI+
1 lines • 1.28 kB
JavaScript
var model=require("../../models/mailsent"),Account=require("../../models/mailaccount"),controller=require("../../controllers/controller"),schedule=require("../../libs/schedule"),arr=require("../../libs/array-funcs");module.exports=function(e){this.contr=new controller(e,model,"mailsent",{sort:{date_created:-1},notNeedRight:!0,onFinding:function(e,l,t){l.user_created=e.email,t(null,l)},onView:function(e,l,t){l.joinModel(e.current_id_app,Account,[{where:{_id:"account_id"},fields:[{name:"from_name",value:"fullname"},{name:"from_address",value:"username"}]}],function(e){l.forEach(function(e){e.from=[{name:e.from_name,address:e.from_address}]}),t(null,l)})},onCreating:function(e,l,t){if(l.mail&&l.mail.html){var n=l.mail.html.replace(/<(?:.|\n)*/gm,"");l.mail.text=n,l.mail.text.length>128?l.small_text=l.mail.text.substring(0,128)+"...":l.small_text=l.mail.text}t(null,l)},onCreated:function(e,l,t){schedule.createMailJob(l),t(null,l)},onUpdating:function(e,l,t,n){if(t.send)return n("Bạn không thể cập nhật email này vì nó đã được gửi");if(l.mail&&l.mail.html){var a=l.mail.html.replace(/<(?:.|\n)*/gm,"");l.mail.text=a,l.mail.text.length>128?l.small_text=l.mail.text.substring(0,128)+"...":l.small_text=l.mail.text}n(null,l,t)}}),this.contr.route()};