<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Test webovej služby</title>
<style>*,::after,::before{box-sizing:border-box}html,body{width:100%;font-family:"Segoe UI",Roboto,Arial,Helvetica,sans-serif}input,button{margin:0}.right{text-align:right}.tb td,.tb th{padding:4px}.tb{border:solid 1px gray;border-spacing:0}.tb thead tr{background-color:#e6e6e6;background-image:linear-gradient(top,#eeeeee,#dadada)}.resr,.resrh{margin-bottom:.3em}.resrh{font-size:1.3em}.reserr{color:firebrick}.resok{color:blue}.m3{margin-bottom:1rem!important}.frm,#resDSata{width:33.33%;background-color:#efefef;display:block;padding:1.5rem}#resData{background-color:#fefefe}.flbl{margin-bottom:.5rem;display:inline-block}.fctl{display:block;width:100%;padding:.375rem .75rem;font-size:1rem;line-height:1.5;color:#212529;background-color:#fff;background-clip:padding-box;border:1px solid #ced4da;border-radius:.375rem;transition:border-color .15s ease-in-out,box-shadow .15s ease-in-out}.fctl:focus{color:#212529;background-color:#fff;border-color:#81d4fa;outline:0;box-shadow:0 0 0 .25rem #0d6efd40}.btn{padding:.375rem .75rem;font-size:1rem;line-height:1.5;color:#fff;background-color:#0d6efd;border:1px solid #0d6efd;border-radius:.375rem;box-shadow:inset 0 1px 0 rgba(255,255,255,.15),0 1px 1px rgba(0,0,0,.075);display:inline-block;text-align:center;text-decoration:none;vertical-align:middle;cursor:pointer;transition:color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out}</style>
</head>
<body>
<div class="frm">
<div class="m3">
<label for="txtAddress" class="flbl">Adresa url:</label>
<input type="text" id="tAdd" class="fctl" placeholder="adresa" value="http://localhost:21001/" />
</div>
<div class="m3">
<label for="txtUserName" class="flbl">Meno používateľa:</label>
<input type="text" id="tUsrN" class="fctl" placeholder="meno" value="" />
</div>
<div class="m3">
<label for="settPassword" class="flbl">Heslo používateľa:</label>
<input type="text" id="tUsrP" class="fctl" placeholder="heslo" value="" />
</div>
<div class="bPnl">
<button id="bSbt" class="btn" >Test</button>
</div>
</div>
<div id="resData"></div>
<script src="https://my.exalogic.sk/cdn/zepto.min.js" type="text/javascript"></script>
<script src="https://my.exalogic.sk/cdn/zepto.sha1.min.js" type="text/javascript"></script>
<script type="text/javascript">
(function ($) {
var _this = null;
var Application = function () {
return new Application.init();
};
_this = Application;
Application.controls = {
selAddress: '#tAdd',
selUserName: '#tUsrN',
selUserPass: '#tUsrP',
selBtnSubmit: '#bSbt',
selResultData: '#resData',
ctlResultData: null
};
Application.userData = null;
Application.userSalt = '';
Application.token = '';
Application.init = function () {
_this.controls.ctlResultData = $(this.controls.selResultData);
_this.controls.ctlResultData.empty();
$(_this.controls.selBtnSubmit).on('click', function(){ Application.evhButtonClick(); });
};
Application.evhButtonClick = function() {
var exc = myException(''),
baseUrl = getUrl();
exc = Application.testPing(baseUrl);
if(!exc.result) return;
exc = Application.login(baseUrl);
if(!exc.result) return;
exc = Application.stockCards(baseUrl);
if(!exc.result) return;
exc = Application.logout(baseUrl);
if(!exc.result) return;
};
Application.testPing = function(baseUrl) {
var exc = myException(''), datah = {html:''};
loadUrl = baseUrl + 'ping';
exc = ajaxHtml(loadUrl, datah);
if (exc.result == false) {
addLogRow('Ping', 1, exc.description);
} else {
addLogRow('Ping', 0, datah.html);
}
return exc;
};
Application.login = function(baseUrl) {
var exc = myException(''), datah, ajaxUrl;
data = dataResult();
post = { userName: $(Application.controls.selUserName).val() };
ajaxUrl = baseUrl + 'v1/user/login/salt';
exc = ajaxPost(ajaxUrl, data, post);
if (exc.result == false) {
addLogRow('Salt', 1, exc.description);
return exc;
} else {
Application.userSalt = data.data;
addLogRow('Salt', 0, data.data);
}
post = { userLoginArg:{ UserName: $(Application.controls.selUserName).val(), Password: Zepto.fn.sha1(Application.userSalt + $(Application.controls.selUserPass).val()) }};
data = dataResult();
ajaxUrl = baseUrl + 'v1/user/login';
exc = ajaxPost(ajaxUrl, data, post);
if (exc.result == false) {
addLogRow('Token', 1, exc.description);
return exc;
} else {
addLogRow('Token', 0, Application.token);
}
data = dataResult();
ajaxUrl = baseUrl + 'v1/user/login/verify/' + Application.token;
exc = ajaxGet(ajaxUrl, data);
if (exc.result == false) {
addLogRow('Login verify', 1, exc.description);
} else {
addLogRow('Login verify', 0);
}
return exc;
};
Application.logout = function(baseUrl) {
var exc = myException(''),data;
if(Application.token == null || Application.token.length == 0) {
addLogRow('Logout', 1, 'No token');
return exc;
}
data = dataResult();
exc = ajaxGet(baseUrl + 'v1/user/logout/', data);
if (exc.result == false) {
addLogRow('Logout', 1, exc.description);
} else {
addLogRow('Logout', 0);
}
return exc;
};
Application.stockCards = function(baseUrl) {
_this.controls.ctlResultData.append('<div class="resrh">Skladové karty</div>');
var exc = myException(''),data;
if(Application.token == null || Application.token.length == 0) {
exc.description = "No token."
return exc;
}
var stock = '';
res = dataResult();
ajaxUrl = baseUrl + 'v1/stock/list';
post = {};
exc = ajaxPost(ajaxUrl, res, post);
if (exc.result == false) {
addLogRow('Sklad', 1, exc.description);
return exc;
} else {
if(res.data==null || res.data.length==0) {
addLogRow('Sklad', 1, 'Zoznam skladov je prázdny.');
return exc;
}
addLogRow('Sklad', 0, stock);
var html = '<div class="resr">';
html += '<table border="0" class="tb"><thead><tr><th>Názov</th></tr></thead><tbody>';
res.data.forEach(function (item, index) {
html += '<td>' + item.Name + '</td></tr>';
});
html += '</tbody></table></div>';
_this.controls.ctlResultData.append(html);
stock = res.data[0].Name;
}
res = dataResult();
ajaxUrl = baseUrl + 'v1/stock/stock-card/list-settings';
post = { stockCardsListSettingsArg: { StockName: stock } };
exc = ajaxPost(ajaxUrl, res, post);
if (exc.result == false) {
addLogRow('Filter', 1, exc.description);
return exc;
} else {
addLogRow('Filter', 0);
}
res = dataResult();
ajaxUrl = baseUrl + 'v1/stock/stock-card/list';
post = { stockCardsListArg: {
LoadSettings: {
PageSize: 10,
PageIndex: 0,
Filters: {},
Sort: {}
},
StockOrStockGroupName: stock,
}
};
exc = ajaxPost(ajaxUrl, res, post);
if (exc.result == false) {
addLogRow('Karty', 1, exc.description);
return exc;
} else {
if(res.data==null || res.data.Items==null || res.data.Items.length==0){
addLogRow('Karty', 1, 'Zoznam kariet je prázdny.');
return exc;
}
addLogRow('Karty', 0);
var html = '<div class="resr">';
html += '<table border="0" class="tb"><thead><tr><th>IDNum</th><th>Číslo</th><th>Názov</th><th class="right">Cena 1 s DPH</th></tr></thead><tbody>';
res.data.Items.forEach(function (item, index) {
html += '<tr><td>' + item.IDNum + '</td>';
html += '<td>' + item.Number + '</td>';
html += '<td>' + item.Name + '</td>';
html += '<td class="right">' + item.PricesInfo.PriceWithVAT1 + '</td></tr>';
});
html += '</tbody></table></div>';
_this.controls.ctlResultData.append(html);
}
return exc;
};
function addLogRow(header, type, message) {
var h = header,m = message, c;
if (type != 0) {
c = 'reserr';
} else {
c = 'resok';
m = m==null || m.length==0 ? 'OK' : m;
}
_this.controls.ctlResultData.append('<div class="resr">'+h+': <span class="'+c+'">'+m+'</span></div>');
}
function getUrl() {
var urlBase = $(Application.controls.selAddress).val();
if ( urlBase == '' || ( !urlBase.startsWith('http:') && ! urlBase.startsWith('https:') ) ) {
urlBase = 'http://' + urlBase;
}
if ( ! urlBase.endsWith('/') ) { urlBase = urlBase + '/'; }
return urlBase;
}
function ajaxGet(ajaxurl, rfResult, jdata, processdata) {
var exc = myException('');
if (!processdata) { processdata = false; }
if (!jdata) { jdata = null; } else { jdata = JSON.stringify(jdata); }
try {
$.ajax({ type: 'GET', cache: false, async: false,
dataType: 'json', contentType: 'application/json; charset=utf-8',
url: ajaxurl, processData: processdata,
data: jdata,
headers: {'userData': Application.token},
success: function (data, textStatus, xhr) {
dataResultGet(data, rfResult);
if (rfResult.result == false && rfResult.errNumber === 2) {
}
Application.token = xhr.getResponseHeader('userData');
exc.result = true;
if (rfResult.result == false) {
exc.result = false;
exc.errNumber = rfResult.errNumber;
exc.description = rfResult.description;
}
},
error: function (xhr, exception, errorThrown) {
exc = z_GetAjaxException(xhr, exception, errorThrown);
}
});
} catch (error) {
}
return exc;
}
function ajaxPost(ajaxurl, rfResult, jdata, processdata) {
var exc = myException('');
if (!processdata) { processdata = false; }
if (!jdata) { jdata = null; }
try {
$.ajax({
type: 'POST', cache: false, async: false,
dataType: 'json', contentType: 'application/json; charset=utf-8',
url: ajaxurl, processData: processdata,
data: JSON.stringify(jdata),
headers: {'userData': Application.token},
success: function (data, textStatus, xhr) {
dataResultGet(data, rfResult);
if (rfResult.result == false && rfResult.errNumber === 2) {
}
Application.token = xhr.getResponseHeader('userData');
exc.result = true;
if (rfResult.result == false) {
exc.result = false;
exc.errNumber = rfResult.errNumber;
exc.description = rfResult.description;
}
},
error: function (xhr, exception, errorThrown) {
exc = z_GetAjaxException(xhr, exception, errorThrown);
}
});
} catch (error) {
}
return exc;
}
function ajaxHtml(ajaxurl, rfResult, callType, jdata) {
var exc = myException('');
if (!callType) { callType = 'GET'; }
try {
$.ajax({
type: callType, url: ajaxurl, cache: false, async: false,
dataType: 'html', contentType: 'text/html; charset=utf-8',
processData: false, data: JSON.stringify(jdata),
headers: {'userData': Application.token},
success: function (data, textStatus, xhr) {
rfResult.html = data;
Application.token = xhr.getResponseHeader('userData');
exc.result = true;
},
error: function (xhr, exception, errorThrown) {
exc = z_GetAjaxException(xhr, exception, errorThrown);
}
});
} catch (error) {
}
return exc;
}
function myException(descr, msg, errNum, res) {
return { result: !res ? false : res, errNumber: !errNum ? 0 : errNum, message: !msg ? '' : msg, description: !descr ? '' : descr };
};
function dataResult() {
return { result: false, errNumber: 0, description: '', data: null };
};
function dataResultGet(data, rfResult) {
rfResult.result = data.result;
rfResult.errNumber = data.errNumber;
rfResult.description = data.description;
rfResult.data = data.data;
}
function z_GetAjaxException(jqXHR, exception, errorThrown) {
var exc = myException();
if (jqXHR.status === 0) {
exc = myException('Server webovej služby je v tejto chvíli nedostupný.', '', 111);
} else if (jqXHR.status == 404) {
exc = myException('Metóda pre spracovanie požiadavky nebola nájdená.', '', 404);
} else if (jqXHR.status == 500) {
exc = myException('Interná chyba servera webovej služby.', '', 500);
} else if (exception === 'parsererror') {
exc = myException('Chyba pre spracovaní JSON dát zo servera.', '', 900);
} else if (exception === 'timeout') {
exc = myException('Čas pre spracovanie požiadavky vypršal.', '', 901);
} else if (exception === 'abort') {
exc = myException('Asynchrónne volanie bolo prerušené.', '', 902);
} else {
exc = myException('Neznáma chyba.<br/>' + jqXHR.statusText, '', 99);
}
return exc;
}
window.Application = Application;
window.Application.init();
})(Zepto);
</script>
</body>
</html>