var smartpos = new Smartpos(); /* setTimeout( function() { var pos = new Smartpos({}); if ( http.getGetParameter( 'pos' ) ) { pos = { pos: http.getGetParameter( 'pos' ) ,emp: http.getGetParameter( 'emp' ) ,sessao: http.getGetParameter( 'pos_sessao' ) ,adiquirente: http.getGetParameter( 'pos_adquirente' ) ,webview: http.getGetParameter( '_wv' ) ,gecko: http.getGetParameter( '_gk' ) ,pay: http.getGetParameter( '_pay' ) ,barcode: http.getGetParameter( '_bar' ) ,print: http.getGetParameter( '_prt' ) ,header: !(http.getGetParameter( '_noheader' )) }; pos = new Smartpos(pos); } if ( (!pos.pos) && ("JSInterface" in window) && (window.JSInterface.getEmp)) // TODO - tirar isso quando a LIO estiver pronta { pos.pos = window.JSInterface.getPos(); var x = window.JSInterface.getEmp(); pos.emp = http.getGetParameter( 'emp' ); if (!pos.emp) { pos.emp = x; } if ( (pos.emp) && (x!=pos.emp) ) { window.alert( pos.emp + '!=' + x); } pos.webview = 1; pos.pay = !!(window.JSInterface.pay); pos.payAvailable = !!(window.JSInterface.pay); // TODO pos.barcode = !!(window.JSInterface.barcode); pos.print = !!(window.JSInterface.print); // TODO pos.printAvailable = !!(window.JSInterface.print); pos.header = !(http.getGetParameter( '_noheader' )); pos.sessao = 'xyz'; // TODO } if (pos.pos) { console.error(pos); window.alert(JSON.stringify(pos)); http.setCookie('pos', pos); pos.config = pos.getPos(); console.log(pos.config); } smartpos = pos; }, 10); */ setTimeout('smartpos.init(0)', 10 ); function Smartpos() { this.initiated = false; this.init = function(n) { if (typeof http === 'undefined') { setTimeout('smartpos.init(' + n+1 + ')', (n>100 ? 1000 : (n>10 ? 100 : 10) ) ); return; } this.wv2 = ("SmartPOSJSInterface" in window) ? true : false; this.wv1 = ("JSInterface" in window) ? true : false; var j = {}; if ( http.getGetParameter( 'pos' ) ) { j = { pos: http.getGetParameter( 'pos' ) ,emp: http.getGetParameter( 'emp' ) ,sessao: http.getGetParameter( 'pos_sessao' ) ,adiquirente: http.getGetParameter( 'pos_adquirente' ) ,webview: http.getGetParameter( '_wv' ) ,gecko: http.getGetParameter( '_gk' ) ,pay: http.getGetParameter( '_pay' ) ,barcode: http.getGetParameter( '_bar' ) ,print: http.getGetParameter( '_prt' ) ,header: !(http.getGetParameter( '_noheader' )) }; } if ( (!j.pos) && ("JSInterface" in window) && (window.JSInterface.getEmp)) // TODO - tirar isso quando a LIO estiver pronta { j.pos = window.JSInterface.getPos(); var emp = window.JSInterface.getEmp(); j.emp = http.getGetParameter( 'emp' ); if (!j.emp) { j.emp = emp; } if ( (j.emp) && (emp!=j.emp) ) { window.alert( j.emp + '!=' + emp); } j.webview = 1; j.pay = !!(window.JSInterface.pay); j.payAvailable = !!(window.JSInterface.pay); // TODO j.barcode = !!(window.JSInterface.barcode); j.print = !!(window.JSInterface.print); // TODO j.printAvailable = !!(window.JSInterface.print); j.header = !(http.getGetParameter( '_noheader' )); j.sessao = 'xyz'; // TODO } if (j.pos) { console.error(j); // window.alert(JSON.stringify(pos)); http.setCookie('pos', j); j.config = this.getPos(); } var xx = Object.keys(j); for(var i=0; i < xx.length; i++) { this[xx[i]] = j[xx[i]]; } this.initiated = true; console.log( "smartpos:", j ); setTimeout('smartpos.readFPGs()',1000); } this.readFPGs = function() { if ( ( (typeof index)==='undefined') || (!index) || (!index.emp) ) { return; } var url = http.getUrl('contahub.a.PosCmd', 'getFPGs') + "?emp=" + index.emp + "&pos=" + smartpos.pos + "&pos_sessao=" + smartpos.sessao ; http.callHTTP( url, function( dados ) { console.error('getFPGs',dados); smartpos.fpgs = dados.list; } , http.alert ); } this.getPos = function() { if (this.wv2) { result = window.SmartPOSJSInterface.pos('getPos', ''); } else if (this.wv1) { result = {erro:"comandoInvalido"}; } else if (this.gecko) { result = window.prompt("pos:getPos", ''); } else { result = null; } return result; } this.status = function() { if (this.wv2) { return window.SmartPOSJSInterface.pos('status', ''); } return ''; } this.getLog = function() { if (this.wv2) { result = window.SmartPOSJSInterface.pos('getLog', ''); } else if (this.wv1) { result = {erro:"comandoInvalido"}; } else if (this.gecko) { result = window.prompt("pos:getLog", ''); } else { result = null; } return result; } this.getResult = function() { if (this.wv2) { result = window.SmartPOSJSInterface.pos('result', ''); } else if (this.wv1) { result = {erro:"comandoInvalido"}; } else { result = window.prompt("pos:result", ''); } return result; } this.getBarcode = function() { if (this.wv2) { result = window.SmartPOSJSInterface.pos('barcode', ''); } else if (this.wv1) { result = {erro:"comandoInvalido"}; } else { result = window.prompt("pos:barcode", ''); } return result; } this.doPrint = function(dados) { if (this.gecko) { // window.alert(JSON.stringify(this)); result = window.SmartPOSJSInterface.pos('print', JSON.stringify(dados)); } else if (this.wv2) { result = window.SmartPOSJSInterface.pos('print', JSON.stringify(dados)); } else if (this.wv1) { result = {erro:"comandoInvalido"}; window.alert("comando inválido"); } else { window.alert("???"); result = window.prompt("pos:print", JSON.stringify(dados)); } return result; } this.doFicha = function(dados) { if (this.wv2) { result = window.SmartPOSJSInterface.pos('print', JSON.stringify(dados)); } else if (this.wv1) { result = {erro:"comandoInvalido"}; } else { result = window.prompt("pos:print", JSON.stringify(dados)); } return result; } this.doPay = function(dados) { if (this.wv2) { result = window.SmartPOSJSInterface.pos('pay', JSON.stringify(dados)); } else if (this.wv1) { result = {erro:"comandoInvalido"}; } else { result = window.prompt("pos:pay", JSON.stringify(dados)); } return result; } this.goFullScreen = function() { if (this.wv2) { result = window.SmartPOSJSInterface.pos('fullScreen', ''); } else if (this.wv1) { result = {erro:"comandoInvalido"}; } else { result = window.prompt("pos:fullScreen", ''); } return result; } this.mifare = function(dados) { if (this.gecko) { result = window.SmartPOSJSInterface.pos('mifare', JSON.stringify(dados)); } else if (this.wv2) { result = window.SmartPOSJSInterface.pos('mifare', JSON.stringify(dados)); } else if (this.wv1) { // result = {erro:"comandoInvalido"}; // window.alert("comando inválido"); } else { // window.alert("???"); // result = window.prompt("pos:mifare", JSON.stringify(dados)); result = "pos:mifare"; } return result; } }