blob: e4267d4ba2db17b9d0417c705007c069fb6d3715 [file] [log] [blame]
/*
Post
<ussd>
<action/> <!-1: start session 2: end session 3: send indication response-->
<ussd_param/><!-only make sense when action is 1 or 3, should be encoded by UCS2-->
</ussd>
Get
<ussd>
<ussd_type/><!-0: USSD notify 1: USSD-request 2: session terminated by network 3: other local client had responded 4:operation not supported 5: network timeout-->
<ussd_str/><!-USSD string encoded by UCS2-->
</ussd>
*/
(function ($) {
$.fn.objussd = function (InIt) {
var timeoutCount = 0;
var action = 1;//1: start session 2: end session 3: send indication response
this.onLoad = function (flag) {
LoadWebPage("html/stk/ussd.html");
$("#lt_ussd_btnDial").click(function() {
UssdDialUp();
});
$("#lt_ussd_btnCancel").click(function() {
CanCelUssdService();
});
$("#lt_ussd_btnSend").click(function() {
SendIndicationResponse();
});
InitUssdStatus();
}
function InitUssdStatus() {
var retXml = PostXml("ussd","get_ussd_ind");
var ussdType = $(retXml).find("ussd_type").text();
if("0" == ussdType || "1" == ussdType) {
$("#txtIndicationResponse").val("");
$("#lt_ussd_txtRecvContent").text(UniDecode($(retXml).find("ussd_str").text()));
$("#divUssdInteract").show();
if("1" == ussdType ) {
$("#divIndicationResponse").show();
$("#lt_ussd_btnSend").show();
} else {
$("#divIndicationResponse").hide();
$("#lt_ussd_btnSend").hide();
}
}
}
function validRspParam(param) {
var regex = /[0-9]{1}/;
if (!regex.test(param))
return false;
else
return true;
}
function SendIndicationResponse() {
action = 3;
var mapData = new Map();
var param = $("#txtIndicationResponse").val();
if (!validRspParam(param)) {
$("#dialParamError").show().text(jQuery.i18n.prop('lrspParamError'));
return;
}
mapData.put("RGW/ussd/action", action);
mapData.put("RGW/ussd/param", param);
PostXml("ussd","send_ussd",mapData);
sm("PleaseWait",150,100);
$("#lPleaseWait").text(jQuery.i18n.prop("h1PleaseWait"));
timeoutCount = 0;
setTimeout(QueryUssdNetworkStatus,10000);
}
function CanCelUssdService() {
action = 2;
var mapData = new Map();
mapData.put("RGW/ussd/action",action);
PostXml("ussd","send_ussd",mapData);
$("#lt_ussd_btnDial").attr("disabled",false);
$("#divUssdInteract").hide();
//setTimeout(QueryUssdNetworkStatus,1000);
}
function validDialParam(param) {
var regex = /[*]{1}[0-9]{2,10}[#]{1}/;
if (!regex.test(param))
return false;
else
return true;
}
function UssdDialUp() {
action = 1;
var mapData = new Map();
var param = $("#txtUssdServiceNumber").val();
if (!validDialParam(param)) {
$("#dialParamError").show().text(jQuery.i18n.prop('ldialParamError'));
return;
}
mapData.put("RGW/ussd/action", action);
mapData.put("RGW/ussd/param", param);
PostXml("ussd","send_ussd",mapData);
sm("PleaseWait",150,100);
$("#lPleaseWait").text(jQuery.i18n.prop("h1PleaseWait"));
$("#lt_ussd_btnDial").attr("disabled",true);
timeoutCount = 0;
setTimeout(QueryUssdNetworkStatus,10000);
}
function QueryUssdNetworkStatus() {
var retXml = PostXml("ussd","get_ussd_ind");
var ussdType = $(retXml).find("ussd_type").text();
if(timeoutCount > 15) {
hm();
}
if("" == ussdType) {
++timeoutCount;
setTimeout(QueryUssdNetworkStatus,1000);
} else if("0" == ussdType || "1" == ussdType) {
hm();
$("#lt_ussd_txtRecvContent").text(UniDecode($(retXml).find("ussd_str").text()));
$("#divUssdInteract").show();
if("1" == ussdType ) {
$("#divIndicationResponse").show();
$("#lt_ussd_btnSend").show();
} else {
$("#divIndicationResponse").hide();
$("#lt_ussd_btnSend").hide();
}
} else {
$("#lt_ussd_btnDial").attr("disabled",false);
$("#divUssdInteract").hide();
if("2" == ussdType) {
showAlert("lsessionTerminate");
} else if("3" == ussdType) {
showAlert("lsessionResponded");
} else if("4" == ussdType) {
showAlert("lsessionOpertionNotSupport");
} else if("5" == ussdType) {
showAlert("lsessionTimeout");
} else {
showAlert("lsessioUnkown");
}
}
}
return this;
}
})(jQuery);