224 lines
8.2 KiB
JavaScript
224 lines
8.2 KiB
JavaScript
var CmsMailEngine = (function() {
|
|
|
|
function CmsMailEngine(){
|
|
var _this = this;
|
|
|
|
_this.oTable = new CTable("data");
|
|
_this.oTable.loadTableData();
|
|
}
|
|
|
|
CmsMailEngine.prototype.oTinyMceController = {};
|
|
|
|
// Save blank data callback function
|
|
CBlank.prototype.saveBlankViewCallback = function(d){
|
|
var _this = this;
|
|
if($.isDefined(d.jsonok) && $.isDefined(d.reloadList) && d.reloadList){
|
|
CBase.message.hide();
|
|
if(_this.isModiffied){
|
|
CBase.oTable.filterTableData(true);
|
|
}else{
|
|
CBase.oTable.show();
|
|
}
|
|
}
|
|
};
|
|
|
|
// Ajax load view call back on object append - if needed then to rewrite
|
|
CBlank.prototype.viewCallbackAfterAppend = function(jqObj){
|
|
//var _this = this;
|
|
|
|
var vAdditionalCfg = {
|
|
convert_urls : false,
|
|
relative_urls : true,
|
|
remove_script_host : false,
|
|
|
|
valid_elements: 'p[*],strong,em,span[*],a[href|class|*],ul,ol,li,img[*],div[*|class],br,h1[*],b[*],li[style],table[*],tr[*],td[*],',
|
|
valid_styles: {'*': 'position,float,right,top,cursor,display,box-sizing,border-radius,box-shadow,font-size,text-decoration,text-align,padding,padding-left,margin,margin-bottom,height,min-height,font-family,font-weight,color,width,background,background-color,padding-top,max-width'},
|
|
valid_children: "+a[div|span|img],+div[figure],+span[img]",
|
|
extended_valid_elements:"style,link[href|rel],meta[name|content]",
|
|
custom_elements:"style,link,~link,meta"
|
|
};
|
|
|
|
CBase.jsModule.oTinyMceController = new TinyMceController(jqObj, vAdditionalCfg);
|
|
};
|
|
|
|
// Rewrite CTable object callback
|
|
CTable.prototype.tableObjectCallback = function(oTable, o){
|
|
var _this = this;
|
|
oTable.find("a#lsend, a#qsenddx").click(function(){
|
|
_this.sendAjaxAction('send', _this.getSelectedTableRows(this), function(){
|
|
_this.filterTableData(true);
|
|
});
|
|
});
|
|
oTable.find("a#inewmail").click(function(){
|
|
_this.loadRecord(true);
|
|
});
|
|
oTable.find("a#istopall").click(function(){
|
|
CBase.jsModule.sendTableAjaxAction("istopall");
|
|
});
|
|
oTable.find("a#iresumeall").click(function(){
|
|
CBase.jsModule.sendTableAjaxAction("iresumeall");
|
|
});
|
|
|
|
// Update cron timer
|
|
if(_this.headers){
|
|
let nCallObj = _this.jqTable.find(".nCall span");
|
|
if(nCallObj.length){
|
|
CBase.jsModule.timeOut = 1000;
|
|
CBase.jsModule.nCall = parseInt(nCallObj.attr("id"));
|
|
CBase.jsModule.startExpTimer();
|
|
}
|
|
}
|
|
};
|
|
|
|
// Rewrite CBase form callback
|
|
CBlank.prototype.viewCallback = function(obj, d){
|
|
var _this = this;
|
|
|
|
obj.find("#settings, #userlinks").click(function(){
|
|
var oCnt = $(this).parent().next();
|
|
var noskip = oCnt.hasClass("noskip") ? true : false;
|
|
if(oCnt.is(":visible")){
|
|
$(this).addClass("show").removeClass("hide");
|
|
oCnt.stop(true, true).fadeOut("fast", function(){
|
|
CBase.resizeLeftMenu(true);
|
|
if(!noskip)
|
|
oCnt.find("input").addClass("skip");
|
|
});
|
|
}else{
|
|
$(this).addClass("hide").removeClass("show");
|
|
oCnt.stop(true, true).fadeIn("fast", function(){
|
|
CBase.resizeLeftMenu(true);
|
|
if(!noskip)
|
|
oCnt.find("input").removeClass("skip");
|
|
});
|
|
}
|
|
});
|
|
|
|
this.oBtnPan.find("#fcancel").click(function(){
|
|
CBase.message.hide();
|
|
if(_this.isModiffied){
|
|
CBase.oTable.filterTableData(true);
|
|
}else{
|
|
CBase.oTable.show();
|
|
}
|
|
});
|
|
|
|
|
|
this.oBtnPan.find("#fsave").click(function(){
|
|
_this.saveBlankView();
|
|
});
|
|
|
|
if(d && d.vMailTypeData && d.iDefLang) {
|
|
|
|
_this.vMailTypeData = d.vMailTypeData;
|
|
|
|
// Select first type from box
|
|
var itype = obj.find("#selMailType").val();
|
|
if(itype && _this.vMailTypeData[itype]){
|
|
for(var x in _this.vMailTypeData[itype]){
|
|
obj.find("textarea#WYSIWYG-" + x).html(_this.vMailTypeData[itype][x].mail_data);
|
|
obj.find("input#title-" + x).val(_this.vMailTypeData[itype][x].mail_title);
|
|
}
|
|
}
|
|
|
|
|
|
obj.find("#selMailType").change(function () {
|
|
var itype = $(this).val();
|
|
if(itype && _this.vMailTypeData[itype]){
|
|
for(var x in _this.vMailTypeData[itype]){
|
|
obj.find("textarea#WYSIWYG-" + x).val(_this.vMailTypeData[itype][x].mail_data);
|
|
tinymce.get("WYSIWYG-" + x).setContent(_this.vMailTypeData[itype][x].mail_data, {format: 'html'});
|
|
obj.find("input#title-" + x).val(_this.vMailTypeData[itype][x].mail_title);
|
|
}
|
|
}else{
|
|
// Clear data
|
|
$("#translations > div input:text").val("");
|
|
$("#translations > div textarea.tinymce").each(function(){
|
|
$(this).val("");
|
|
tinymce.get($(this).attr("id")).setContent("", {format: 'html'});
|
|
});
|
|
}
|
|
});
|
|
|
|
obj.find("input[id^='def-html-content-']").change(function () {
|
|
$(this).closest(".tabs").find("input[id^='def-html-content-']").not($(this)).val("").parent().find(".sw-on").removeClass("sw-on");
|
|
});
|
|
|
|
_this.tabs = new Tabs(obj.find(".tabs"));
|
|
}
|
|
obj.find("#newsletter_mails, #system_mails").change(function(){
|
|
$(this).closest("#checkboxes").find("#newsletter_mails, #system_mails").not($(this)).val("").parent().find(".sw-on").removeClass("sw-on");
|
|
if($(this).val()){
|
|
$("input#to").attr("disabled", true).addClass("skip").closest(".validate").removeClass("v-error v-ok").find(".errMsg").remove();
|
|
}else{
|
|
$("input#to").attr("disabled", false).removeClass("skip");
|
|
}
|
|
});
|
|
|
|
this.bindBlankActions(obj);
|
|
};
|
|
|
|
// Disable all outgoing emails
|
|
CmsMailEngine.prototype.sendTableAjaxAction = function(key){
|
|
CBase.ajax({action : key}, false, function(d){
|
|
if(d && d.jsonok){
|
|
CBase.oTable.filterTableData(true);
|
|
if(d.msg){
|
|
CBase.message.show(false, true, d.msg);
|
|
}
|
|
}
|
|
})
|
|
};
|
|
|
|
// Recalculate next cron time exec
|
|
CmsMailEngine.prototype.recalculateTime = function () {
|
|
let _this = this;
|
|
let sep = '';
|
|
let stime = '';
|
|
let itime = _this.nCall;
|
|
let data = {"day": 86400, "hour": 3600, "minute": 60, "second": 1};
|
|
|
|
for ($k in data) {
|
|
$num = Math.floor(itime / data[$k]);
|
|
itime -= ($num * data[$k]);
|
|
|
|
if ($k !== "day" && $k !== "hour" && ($num + "").length < 2) {
|
|
$num = "0" + $num;
|
|
}
|
|
|
|
if ($k === "day") {
|
|
_this.daysl = $num;
|
|
} else if ($k === "hour") {
|
|
|
|
} else {
|
|
stime += ':' + $num + sep; // + (0 && $num>1?"s":"");
|
|
}
|
|
}
|
|
return stime.trim().substring(1); //trim(substr($time, 1));
|
|
};
|
|
|
|
CmsMailEngine.prototype.updateExpTimer = function () {
|
|
let _this = this;
|
|
_this.nCall -= _this.timeOut / 1000;
|
|
$(".nCall span").html(_this.recalculateTime());
|
|
|
|
_this.startExpTimer();
|
|
};
|
|
|
|
CmsMailEngine.prototype.startExpTimer = function () {
|
|
let _this = this;
|
|
if (_this.nCall && _this.nCall - _this.timeOut / 1000 >= 0) {
|
|
setTimeout(function () {
|
|
_this.updateExpTimer();
|
|
}, _this.timeOut);
|
|
} else {
|
|
// Reset timer back to start 2:00
|
|
_this.nCall = parseInt($(".nCall span").data("cron-interval"));
|
|
_this.updateExpTimer();
|
|
}
|
|
};
|
|
|
|
return CmsMailEngine;
|
|
|
|
})();
|