dj.module.CCS = {
init: function(cfg) {
this._cfg = dj.lang.cloneMixin(this.DEFAULT_CONFIG, cfg);
this.product = 'WSJ';
var prefixDtext = (typeof window.nSP != 'undefined') ? window.nSP : "";
this.dtext = [
'
'
];
var prefixAtext = (typeof window.nSP != 'undefined') ? window.nSP : "";
this.atext = [
'',
'You have an important message',
''
];
var prefixNtext = (typeof window.nSP != 'undefined') ? window.nSP : "";
this.ntext = [
'',
'You have a new message',
''
];
},
DEFAULT_CONFIG: {
product: null,
messageCenterRequest: null,
messageCenterTimeout: null,
displayedInterstitialRequest: null,
displayedInterstitialTimeout: null,
readRequest: null,
readTimeout: null,
getContentRequest: null,
getContentTimeout: null,
changeOrderRequest: null,
changeOrderTimeout: null,
dtext: null,
atext: null,
ntext: null,
VarX: null,
y: null,
z: null
},
changeStyle: function(httpRequest, msgid) {
var v = document.getElementById('m_'+msgid+'_f');
v.style.fontWeight='';
v = document.getElementById('m_'+msgid+'_s');
v.style.fontWeight='';
v = document.getElementById('m_'+msgid+'_r');
v.style.fontWeight='';
v = document.getElementById('m_'+msgid+'_e');
v.style.fontWeight='';
},
displayMessages: function(httpRequest) {
var m = document.getElementById("messages");
m.innerHTML = httpRequest.responseText;
},
closeMessage: function() {
this.y.style.display = 'none';
this.VarX.style.display = 'none';
},
checkAll: function() {
var f = document.getElementById("mform");
var num = f.elements.length;
for (var i=0; i < num; i++) {
var e = f.elements[i];
if (e.type == 'checkbox') {
e.checked = true;
}
}
},
uncheckAll: function() {
var f = document.getElementById("mform");
var num = f.elements.length;
for (var i=0; i < num; i++) {
var e = f.elements[i];
if (e.type == 'checkbox') {
e.checked = false;
}
}
},
displayDiv: function(content, mid, mname, isInterstitial) {
this.VarX = $('modal');
this.y = $('message');
this.z = $('messagecontent');
this.z.innerHTML = content;
this.y.style.zIndex = 1000000001;
this.y.style.display = 'block';
this.y.style.overflow = 'hidden';
this.VarX.style.zIndex = 1000000000;
this.VarX.style.display = 'block';
this.VarX.style.height = document.body.scrollHeight + 'px';
var s = s_gi(s_account);
s.events = "event30";
if (isInterstitial) {
s.eVar30 = 'WSJ Interstitial - ' + mname;
} else {
s.eVar30 = 'WSJ Message - ' + mname;
}
s.linkTrackVars = "eVar30,events";
s.linkTrackEvents = "event30";
if (isInterstitial) {
s.tl(true,'o','WSJ Interstitial - ' + mname);
} else {
s.tl(true,'o','WSJ Message - ' + mname);
}
},
showInterstitialContent: function(content, mid, uid, umid, mname) {
var tmp = '';
try {
tmp = (new XMLSerializer()).serializeToString(content);
} catch (e) {
tmp = content.xml;
}
tmp = tmp.replace(/&/g,'&');
/* var ccsuser = document.getElementById('CCS_USER');
if(ccsuser) {
dj.util.User.renderCallsign(ccsuser);
}*/
tmp = tmp.replace(//g, userName);
tmp = tmp.replace(/gotosite/g, 'WSJ.com');
tmp = tmp.replace(/myacctsite/g, 'https://commerce.wsj.com/myaccount/do/viewBillingInfo');
tmp = tmp.replace(/modvalue/g, 'mc_wsj_interstitial_' + mname);
tmp = tmp.replace(//g, 'WSJ.com');
tmp = tmp.replace(/site/g, 'wsj');
tmp = tmp.replace(/msgbg/g, '#364A92');
var d = new Date();
tmp = tmp.replace(//g, d.getFullYear());
tmp = tmp.substring(9, tmp.indexOf(""));
this.displayDiv(tmp, mid, mname, true);
this.sendDisplayedInterstitialRequest(uid, umid);
},
processTop: function(httpRequest) {
try {
var strDtext = this.dtext.join("");
var strAtext = this.atext.join("");
var strNtext = this.ntext.join("");
var message = httpRequest.responseXML.getElementsByTagName("message")[0];
if (message !== null) {
if (message.firstChild !== null) {
var mid = (message.getElementsByTagName("mid")[0]).firstChild.nodeValue;
var uid = (message.getElementsByTagName("uid")[0]).firstChild.nodeValue;
var umid = (message.getElementsByTagName("umid")[0]).firstChild.nodeValue;
var mname = (message.getElementsByTagName("messageid")[0]).firstChild.nodeValue;
var priority = message.getElementsByTagName("priority")[0];
var display = message.getElementsByTagName("display")[0];
if (display !== null) {
var dvalue = display.firstChild.nodeValue;
if (dvalue=='true') {
var content = message.getElementsByTagName("content")[0];
this.showInterstitialContent(content, mid, uid, umid, mname);
} else if (display == 'dontshow'){
if (priority !== null) {
var value = priority.firstChild.nodeValue;
if (value == 1) {
$('msgCenter').innerHTML = strAtext;
dj.util.Cookie.setCookie('CMCAlert', strAtext, 1);
} else {
$('msgCenter').innerHTML = strNtext;
dj.util.Cookie.setCookie('CMCAlert', strNtext, 1);
}
}
}
} else {
$('msgCenter').innerHTML = strDtext;
}
} else {
$('msgCenter').innerHTML = strDtext;
}
} else {
$('msgCenter').innerHTML = strDtext;
}
return true;
} catch(e){
//$('msgCenter').innerHTML = strDtext;
return false;
}
},
reloadMessageCenter: function() {
this.init();
var cmcalertcookie = dj.util.Cookie.getCookie("CMCAlert");
if (cmcalertcookie !== null) {
//$('msgCenter').innerHTML = cmcalertcookie;
}
var cmccookie = dj.util.Cookie.getCookie("CMC");
if (cmccookie === null) {
if (this.messageCenterRequest != null) {
//this.messageCenterRequest.abort();
this.messageCenterRequest = null;
}
dj.util.Cookie.setCookie('CMC', 'top', 1);
var processX;
var d = new Date();
var dataUrl = '/msgcenter/top_message.html';
var dataUrlParams = $H({product: this.product, d: d.getTime() });
var that = this;
this.messageCenterRequest = new Ajax.Request(dataUrl, {
method: 'GET',
parameters: dataUrlParams.toQueryString(),
onSuccess: function(transport){
//processX = that.processTop(transport);
},
onException: function(transport, exception){
console.error('Exception occured during Ajax Request to retrieve data: %o', exception);
}
} );
}
},
sendDisplayedInterstitialRequest: function(uid, umid) {
if (this.displayedInterstitialRequest !== null) {
//this.displayedInterstitialRequest.abort();
this.displayedInterstitialRequest = null;
}
var params = $H({uId: uid, umId: umid, product: this.product});
var postUrl= '/msgcenter/displayed_interstitial.html';
var that = this;
this.displayedInterstitialRequest = new Ajax.Request(postUrl, {
method: 'POST',
parameters: params.toQueryString(),
onComplete: function(transport, json){
that.reloadMessageCenter();
},
onException: function(transport, exception){
console.error('Exception occured while posting posting Ajax Request : ' + exception);
}
});
},
sendReadRequest: function(msgid, umid) {
if (this.readRequest !== null) {
//this.readRequest.abort();
this.readRequest = null;
}
var params = $H({umId: umid, product: this.product});
var postUrl = '/msgcenter/read_message.html';
var that = this;
this.readRequest = new Ajax.Request(postUrl, {
method: 'POST',
parameters: params.toQueryString(),
onComplete: function(transport, json){
that.changeStyle(transport, msgid);
that.reloadMessageCenter();
},
onException: function(transport, exception){
console.error('Exception occured while posting posting Ajax Request : ' + exception);
}
});
},
showMessage: function(httpRequest, msgid, umid, mname) {
var message = httpRequest.responseText.replace(/&/g,'&');
var ccsuser1 = document.getElementById('CCS_USER');
if(ccsuser1 ) {
dj.util.User.renderCallsign(ccsuser1);
}
message = message.replace(/gotosite/g, 'WSJ.com');
message = message.replace(/myacctsite/g, 'https://commerce.wsj.com/myaccount/do/viewBillingInfo');
message = message.replace(/modvalue/g, 'mc_wsj_message_' + mname);
var d = new Date();
message = message.replace(//g, d.getFullYear());
message = message.replace(//g, 'WSJ.com');
message = message.replace(/site/g, 'wsj');
message = message.replace(/msgbg/g, '#364A92');
dj.util.Cookie.setCookie('CMCAlert', '', -1);
this.displayDiv(message, msgid, mname, false);
this.sendReadRequest(msgid, umid);
},
loadMessageContent: function(msgid, uid, umid, read, mname) {
if (this.getContentRequest !== null) {
//this.getContentRequest.abort();
this.getContentRequest = null;
}
var dataUrl = '/msgcenter/get_message.html?messageId='+msgid+'&product='+this.product;
var that = this;
this.getContentRequest = new Ajax.Request(dataUrl, {
method: 'GET',
onSuccess: function(transport){
that.showMessage(transport, msgid, umid, mname);
},
onException: function(transport, exception){
console.error('Exception occured during Ajax Request to retrieve data: %o', exception);
}
});
},
sendChangeOrderRequest: function(order, product) {
if (this.changeOrderRequest !== null) {
//this.changeOrderRequest.abort();
this.changeOrderRequest = null;
}
var dataUrl = '/msgcenter/order_messages.html?order='+order+'&product='+product;
var that = this;
this.changeOrderRequest = new Ajax.Request(dataUrl, {
method: 'GET',
onSuccess: function(transport){
that.displayMessages(transport);
},
onException: function(transport, exception){
console.error('Exception occured during Ajax Request to retrieve data: %o', exception);
}
});
},
updateusermessagestatuscode: function() {
if (this.readRequest !== null) {
//this.readRequest.abort();
this.readRequest = null;
}
var params = $H({product: this.product});
var postUrl = '/umsl/user_messages/do_not_show';
var that = this;
this.readRequest = new Ajax.Request(postUrl, {
method: 'POST',
parameters: params.toQueryString(),
onComplete: function(transport, json){
that.reloadMessageCenter();
},
onException: function(transport, exception){
console.error('Exception occured while posting posting Ajax Request : ' + exception);
}
});
}
};