window['NickolaS_Solutions']['alert']={
'config':{
'loaded':false
}
,'data':{}
,'confirm':function(message,action){
var message=message,action=action,_this=this;
document.querySelector('#ns-confirmation-alert .ns-confirmation-button').setAttribute('onclick','window.NickolaS_Solutions.alert.close(\'confirmation\');'+action);
_this.open('confirmation',message);
}
,'open':function(code,body,duration,title,header,callback){
var code=code,body=body,duration=duration,title=title,header=header,callback=callback,_this=this;
_this.register(code,title,header);
if (body!=null){
document.querySelector('#ns-'+code+'Alert ._NS_alertBody').innerHTML=body;
}
//console.log('alert div display: '+document.querySelector('#ns-'+code+'Alert').style.display);
//document.querySelector('#ns-alertBackground').style.display='block';
document.querySelector('#ns-'+code+'Alert').style.display='flex';
if (document.querySelector('#ns-'+code+'Alert').style.display!=='flex'){
document.querySelector('#ns-'+code+'Alert').style.display='block';
}
if (duration>0){
setTimeout(function(code,callback){_this.close(code);if(typeof(callback)!='undefined'){eval(callback);}},(duration*1000),code,callback);
}
}
,'close':function(code){
document.querySelector('#ns-'+code+'Alert').style.display='none';
document.querySelector('#ns-alertBackground').style.display='none';
}
,'register':function(code,title,header){
var _this=this,code=code,ID='_NS_'+code+'Alert',title=title,header=header,container=null,blocker=null,styleData={};
if (typeof(_this['data'][code])!='undefined'){
return true;
}
if (!(_this['config']['loaded'])){
blocker=document.createElement('div');
blocker.id='_NS_alertBackground';
styleData={'position':'fixed','top':'0px','bottom':'0px','left':'0px','right':'0px','background-color':'#000000','opacity':'0.5','display':'none','z-index':'100000'};
for (var k in styleData){
blocker.style[k]=styleData[k];
}
document.body.appendChild(blocker);
_this['config']['loaded']=true;
}
container=document.querySelector('#'+ID);
if (container===null){
container=document.createElement('div');
container.id=ID;
container.className='_NS_alert';
styleData={'position':'fixed','top':'0px','bottom':'0px','left':'0px','right':'0px','display':'none','z-index':'100001','overflow-y':'auto'};
for (var k in styleData){
container.style[k]=styleData[k];
}
container.innerHTML='
';
document.body.appendChild(container);
}
}
};
window['NickolaS_Solutions']['confirmationRequest']={
'callbacks':{},
'timestamp':null,
'init':function(message,callbackConfig){
this['timestamp']=(new Date).getTime();
this['callbacks'][this['timestamp']]=callbackConfig;
window['NickolaS_Solutions']['alert'].open('confirmation-request',message);
},
'confirm':function(){
var controllerObject=this['callbacks'][this['timestamp']].shift(),
method=this['callbacks'][this['timestamp']].shift();
controllerObject[method].apply(controllerObject,this['callbacks'][this['timestamp']]);
this.cancel();
}
,'close':function(){
delete(this['callbacks'][this['timestamp']]);
window['NickolaS_Solutions']['alert'].close('confirmation-request');
}
};window['NickolaS_Solutions']['inputError']={
'targets':{}
,'run':function(inputContainer,selector,error){
var inputContainer=inputContainer,selector=selector,error=error
,target=null,_this=this;
target=_this.getTarget(inputContainer,selector);
//console.log(inputContainer+' .NS_inputError.'+_this['map'][ID]);
console.log(arguments);
target['eb'].innerHTML=error;
target['eb'].style.display='block';
//target['eb'].style.backgroundColor='#FFAAAA';
//target['eb'].classList.remove('d-none');
//document.querySelector(inputContainer+' .NS_inputError.'+ID).innerHTML=error;
}
,'getTarget':function(inputContainer,selector){
var inputContainer=inputContainer,selector=selector,_this=this
,initialInputField=null,inputField=null,errorBlock=null
,ID=(inputContainer+' | '+selector),timestamp=(new Date()).getTime()
,igc='';
if (typeof(_this['targets'][ID])=='undefined'){
initialInputField=document.querySelector(inputContainer+' *[name="'+selector+'"]');
//console.log('error '+errorID);
//console.log('initialInputField');
//console.log(initialInputField);
//initialInputField.classList.add('inputField'+timestamp);
if (initialInputField.classList.contains('inGroup')){
inputField=initialInputField;
igc=initialInputField.dataset['in_group'];
//console.log(initialInputField);
}
else {
inputField=initialInputField;
}
document.querySelectorAll(inputContainer+' *[name="'+selector+'"]').forEach(function(el){
var el=el,alias=null;
el.dataset['error_id']=ID;
if (el.dataset['alias']!=null){
alias=el.dataset['alias'];
document.querySelector(inputContainer+' .'+alias).dataset['error_id']=ID;
document.querySelector(inputContainer+' .'+alias).addEventListener('focus',function(){
window['NickolaS_Solutions'].inputError.hide(this.dataset['error_id']);
});
}
else {
el.dataset['error_id']=ID;
el.addEventListener('input',function(){
window['NickolaS_Solutions'].inputError.hide(this.dataset['error_id']);
});
}
//el.setAttribute('oninput','window['NickolaS_Solutions'].inputError.hide(\''+ID+'\');');
});
//initialInputField;
//initialInputField.addEventListener('input')
errorBlock=document.createElement('div');
errorBlock.classList.add('NS_inputError','alert','alert-danger','px-2','py-1','mb-0','invalid_'+igc);
//errorBlock.classList.add(_this['map'][key]);
_this['targets'][ID]={
'ib':inputField
,'eb':errorBlock
};
if (igc!=''){
document.querySelector(inputContainer+' div.'+igc).insertAdjacentElement('afterend',errorBlock);
}
else {
inputField.insertAdjacentElement('afterend',errorBlock);
}
//_this['targets'][ID]['eb'].style.backgroundColor='#FF9999';
/** /
_this['map'][key]=selector+'_'+timestamp;
inputField.classList.add(_this['map'][key]);
inputField.insertAdjacentHTML('afterend','
');/**/
}
return _this['targets'][ID];
}
,'hide':function(ID){
var ID=ID,_this=this;
//_this['targets'][ID]['eb'].add('d-none');
_this['targets'][ID]['eb'].style.display='none';
_this['targets'][ID]['ib'].classList.remove('invalid');
}
,'reset':function(inputContainer){
var inputContainer=inputContainer,_this=this,ID='',IDParts=[],IDx='';
for (ID in _this['targets']){
if (ID.substr(0,inputContainer.length)==inputContainer){
_this.hide(ID);
}
}
}
};window['NickolaS_Solutions']['request'] = {
'run': function (method, URL, data, actions, returnJSON, extraHeaders) {
var responseClone=null,method = method,
URL = URL, data = data, actions = actions,
returnJSON = returnJSON,
headers = {
'X-Requested-With': 'XMLHttpRequest',
'Accept': returnJSON ? 'application/json' : 'text/html',
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content'),
'Language-Id': languageID
};
if (typeof (extraHeaders) != 'undefined') {
Object.assign(headers, extraHeaders);
}
if (URL.substr(0, 4) != 'http') {
URL = window['baseRequestURL'] + URL;
}
console.log(method + ' | ' + URL);
var requestParams = {'method': method, 'headers': headers};
if (method != 'GET' && method != 'HEAD') {
requestParams['body'] = (typeof data === 'object' && headers['Content-type'] != 'application/octet-stream') ? JSON.stringify(data) : data;
}
console.log(requestParams);
fetch(URL, requestParams).then(function (response) {
responseClone=response.clone();
switch (response.status) {
case 419:
return response.json().then(reply => {
alert('CSRF lost');
if (typeof (actions['customError']) != 'undefined') {
actions['customError'](actions['errorConfig']);
}
});
break;
case 422:
return response.json().then(reply => {
var k = '', kp = [], c = document.querySelector(actions['containerSelector']);
if (typeof (window['NickolaS_Solutions']['inputErrorBlockMapping']) == 'undefined') {
window['NickolaS_Solutions']['inputErrorBlockMapping'] = {};
}
var im = window['NickolaS_Solutions']['inputErrorBlockMapping'], imk = '';
var inputElement = null, inputBlock = null, inputErrorBlock = null, errorBlockID = '';
for (k in reply['errors']) {
console.log('checking ' + k + ' | ' + k.replace(/[_.]/g, '-'));
imk = actions['containerSelector'] + ' | ' + k;
if (typeof (im[imk]) == 'undefined') {
kp = k.split('.');
console.log('.input-block-' + k.replace(/[_.]/g, '-') + ', *[name="'
+ kp[0] + ((kp.length > 1) ? ('[' + kp.slice(1).join('][') + ']') : '') + '"]');
console.log(c.querySelectorAll('.input-block-' + k.replace(/[_.]/g, '-') + ', *[name="'
+ kp[0] + ((kp.length > 1) ? ('[' + kp.slice(1).join('][') + ']') : '') + '"]'));
inputBlock = c.querySelectorAll('.input-block-' + k.replace(/[_.]/g, '-') + ', *[name="'
+ kp[0] + ((kp.length > 1) ? ('[' + kp.slice(1).join('][') + ']') : '') + '"]')[0];
errorBlockID = 'input-error-block-' + k.replace(/[_.]/g, '-');
console.log(errorBlockID);
console.log('inputBlock');
console.log(inputBlock);
if (typeof (inputBlock['dataset']['error-block-id']) == 'undefined') {
var timestamp = (new Date).getTime();
inputBlock.insertAdjacentHTML('afterend', '
');
inputBlock['dataset']['errorBlockId'] = errorBlockID;
im[imk] = errorBlockID;
}
}
c.querySelector('.' + im[imk])
.insertAdjacentHTML('beforeend', '' + reply['errors'][k].join('
') + '
');
}
if (typeof (actions['customError']) != 'undefined') {
actions['customError'](actions['errorConfig']);
}
});
break;
case 403:
case 500:
case 502:
return response.json().then(reply => {
if (typeof (actions['customError']) != 'undefined') {
actions['customError'](actions['errorConfig']);
}
});
break;
default:
console.log('status: ' + response.status);
if (!response.ok) {
throw new Error('Request failed:', response.status);
}
break;
}
console.log('request 22');
console.log(response);
console.log(response.headers.entries());
console.log('returnJSON: ' + returnJSON);
if (returnJSON) {
//console.log(response.text());
return response.json().then(actions['success']);
var responseJSON = response.json();
console.log(responseJSON);
console.log(actions);
return actions['success'](responseJSON);
} else {
return response.text();
}
})
.catch(async function (error) {
if (typeof actions.fatalError !== 'undefined') {
actions.fatalError(error);
}
var rawResponse=await responseClone.text();
fetch(window['_NS_requestParsingFailReporter'],{
'method':'POST','headers': {'Accept':'application/json'},
'body':JSON.stringify({
'URL':URL,
'request':requestParams['body'],
'reply':rawResponse,
'parsingError':(typeof(error)=='object')?error['message']:error
})
});
console.log('fatalError:');
console.dir(error);
});
},
'defaultReplyActions': {
'redirect': function (reply) {
setTimeout(function () {
document.location.replace(reply.redirect_url);
}, 2000);
}
, 'success': function (reply) {
window['NickolaS_Solutions'].alert.open('success', '' + reply.success_message + '
', 2, 'Success');
}
, 'fail': function (reply, inputErrorConfig) {
var reply = reply, inputErrorConfig = inputErrorConfig, _that = NickolaS_Solutions
, inputContainer = '', errorKey = '', result = [];
if (typeof (inputErrorConfig) == 'undefined') {
inputErrorConfig = {};
inputContainer = '';
} else {
inputContainer = inputErrorConfig['_container'];
}
reply['errorMap'].forEach(function (errorSet) {
var selector = errorSet[0], errors = [];
errorSet[1].forEach(function (i) {
errors.push(reply.errors[i]);
});
//result.push({selector:errors});
if (typeof (inputErrorConfig[selector]) != 'undefined') {
inputErrorConfig[selector][0](inputErrorConfig[selector][1], errors);
} else {
if (selector != 'global') {
if (inputContainer != '') {
if (typeof (_that.inputError) != 'undefined') {
_that.inputError.run(inputContainer, selector, errors.join(' '));
} else {
result.push('' + selector + ': ' + errors.join(' '));
}
} else {
result.push('' + selector + ': ' + errors.join(' '));
}
} else {
if (errors.length > 0) {
result.push(errors.join(' '));
}
}
}
/** /
/**/
});
/** /
for (errorKey in reply['error_fields']){
reply.errors.push(errorKey+': '+reply['error_fields'][errorKey]);
}
window['NickolaS_Solutions'].alert.open('fail','Fail',''+reply.errors.join('
')+'
',2);
/**/
//console.log(JSON.stringify(result,null,2));
if (result.length > 0) {
window['NickolaS_Solutions'].alert.open('fail', '' + result.join('
') + '
', 2, 'Fail');
}
//console.dir(reply.errors);
}
, '__fail': function (reply, targetSelectors) {
var reply = reply, targetSelectors = targetSelectors, errorKey = '', result = [];
if (typeof (targetSelectors) == 'undefined') {
targetSelectors = {};
}
reply['errorMap'].forEach(function (errorSet) {
var selector = errorSet[0], errors = [];
errorSet[1].forEach(function (i) {
errors.push(reply.errors[i]);
});
//result.push({selector:errors});
if (typeof (targetSelectors[selector]) != 'undefined') {
targetSelectors[selector][0](targetSelectors[selector][1], errors);
} else {
if (selector != 'global') {
//document.querySelector('#'+selector+'Input').setCustomValidity(errors.join("\n"));
}
result.push('' + selector + ': ' + errors.join(' '));
}
/** /
/**/
});
/** /
for (errorKey in reply['error_fields']){
reply.errors.push(errorKey+': '+reply['error_fields'][errorKey]);
}
window['NickolaS_Solutions'].alert.open('fail','Fail',''+reply.errors.join('
')+'
',2);
/**/
window['NickolaS_Solutions'].alert.open('fail', '' + result.join('
') + '
', 2, 'Fail');
console.dir(reply.errors)
}
, '_not_allowed': function (reply) {
//'alert'
//login('request');
//window['NickolaS_Solutions'].alert.open('forbidden',null,3,'','','login(\'request\');');
window['NickolaS_Solutions'].alert.open('forbidden', null, 3);
}
, 'forbidden': function (reply) {
window['NickolaS_Solutions']['defaultReplyActions']['not_allowed'](reply);
}
}
, 'setReplyAction': function (code, callback) {
window['NickolaS_Solutions']['defaultReplyActions'][code] = callback;
}
};
window['NickolaS_Solutions']['defaultReplyActions'] = window['NickolaS_Solutions']['request']['defaultReplyActions'];
window['NickolaS_Solutions']['runRequest'] = window['NickolaS_Solutions']['request']['run'];
window['NickolaS_Solutions']['post'] = function (URL, params, actions, returnJSON, headers) {
window['NickolaS_Solutions']['request']['run']('POST', URL, params, actions, returnJSON, headers);
};
window['NickolaS_Solutions']['get'] = function (URL, params, actions, returnJSON) {
window['NickolaS_Solutions']['request']['run']('GET', URL, params, actions, returnJSON);
};
window['NickolaS_Solutions']['DOM']={
'getElements':function(list){
var elements=[];
//console.dir(list);
//console.log(typeof(list));
switch(typeof(list)){
case 'string':
return document.querySelectorAll(list);
break;
case 'object':
if (list instanceof NodeList){
return list;
}
elements.push(list);
return elements;
break;
case 'array':
return list;
break;
}
}
,'addClass':function(list,newClass){
var newClass=newClass;
this.getElements(list).forEach(function(e){
var fullClassName=' '+e.className.trim()+' ';
//console.log('oldClass: '+e.className);
if (fullClassName.indexOf(newClass)==-1){
e.className+=(' '+newClass);
}
//console.log('newClass: '+e.className);
/** /
var classNameParts=e.className.split(' '),valid=true;
classNameParts.forEach(function(cp){
if (cp==newClass){
valid=false;
}
});
e.className+=(' '+className);
/**/
});
}
,'removeClass':function(list,classNameToRemove){
var classNameToRemove=classNameToRemove;
this.getElements(list).forEach(function(e){
var fullClassName=' '+e.className.trim()+' ';
e.className=fullClassName.replace(' '+classNameToRemove+' ',' ').trim();
/** /
var classParts=e.className.split(' '),finalClasses=[];
classParts.forEach(function(c){
if (c!=className){
finalClasses.push(c);
}
});
e.className=finalClasses.join(' ');
/**/
});
}
,'disable':function(list){
var _this=this;
//console.log('disabled');console.dir(_this.getElements(list));
_this.getElements(list).forEach(function(e){
e.disabled=true;
_this.addClass(e,'disabled');
});
}
,'enable':function(list){
var _this=this;
//console.log('enable');console.dir(_this.getElements(list));
_this.getElements(list).forEach(function(e){
e.disabled=false;
_this.removeClass(e,'disabled');
});
}
,'cleanSelect':function(el){
var el=el;
if (typeof(el)=='string'){
el=document.querySelectorAll(el)[0];
}
el.querySelectorAll('option').forEach(function(o){
switch(o.value){
case '': o.selected=true; break;
case '0': o.selected=false; break;
default: o.remove(); break;
}
});
}
,'resetFields__':function(selector){
var container=document.querySelector(selector);
switch(container.tagName){
case 'DIV':
break;
}
console.log(container.tagName+': '+selector);
/**/
document.querySelectorAll(selector).forEach(function(f){
var i=0, varNameParts=[], vnpi=0, vnpx=0, vnpy=0, el, value='';
if (typeof(f.elements)!='undefined'){
for(i=0;i0){
for (vnpi=0;vnpi<=vnpy;vnpi++){
if (vnpi==vnpy){
if (varNameParts[vnpx]==''){
if (typeof(dataParts[varNameParts[vnpy]])=='undefined'){
dataParts[varNameParts[vnpy]]=[];
}
dataParts[varNameParts[vnpy]].push(value);
}
else {
if (typeof(dataParts[varNameParts[vnpy]])=='undefined'){
dataParts[varNameParts[vnpy]]={};
}
dataParts[varNameParts[vnpy]][varNameParts[vnpx]]=value;
}
}
else {
if (typeof(dataParts[varNameParts[vnpi]])=='undefined'){
dataParts[varNameParts[vnpi]]={};
}
dataParts=dataParts[varNameParts[vnpi]];
}
}
}
else {
data[varNameParts[vnpx]]=value;
}
//console.log(el.tagName+' '+el.name);
}
}
}
}
}/** /
foundList.forEach(function(f){
var f=f,i=0, varNameParts=[], vnpi=0, vnpx=0, vnpy=0, elt=null, value='',o=0;
alert(JSON.stringify(f,null,2));
if (typeof(f.elements)!='undefined'){
for(i=0;i0){
for (vnpi=0;vnpi<=vnpy;vnpi++){
if (vnpi==vnpy){
if (varNameParts[vnpx]==''){
if (typeof(dataParts[varNameParts[vnpy]])=='undefined'){
dataParts[varNameParts[vnpy]]=[];
}
dataParts[varNameParts[vnpy]].push(value);
}
else {
if (typeof(dataParts[varNameParts[vnpy]])=='undefined'){
dataParts[varNameParts[vnpy]]={};
}
dataParts[varNameParts[vnpy]][varNameParts[vnpx]]=value;
}
}
else {
if (typeof(dataParts[varNameParts[vnpi]])=='undefined'){
dataParts[varNameParts[vnpi]]={};
}
dataParts=dataParts[varNameParts[vnpi]];
}
}
}
else {
data[varNameParts[vnpx]]=value;
}
//console.log(el.tagName+' '+el.name);
}
}
}
}
});/**/
//console.dir(data);
return data;
//console.dir(data);
}
};window['NickolaS_Solutions']['dataPage']={
'list':{}
,'load':function(selector,config,reset){
var selector=selector,config=config,reset=reset,_this=this,ID=null
,dataFilters={},isNew=true;
if (typeof(reset)=='undefined'){
reset=false;
}
if (typeof(_this['list'][selector])!='undefined'){
ID=selector;
isNew=false;
}
else {
ID=document.querySelector(selector).dataset['dataPage'];
if (!ID){
ID=_this['uniqid']();
}
else {
isNew=false;
}
}
if (typeof(config)=='undefined'){
config=_this['list'][ID];
}
else {
if (typeof(_this['list'][ID])=='undefined' || reset==true){
_this['list'][ID]=config;
_this['list'][ID]['__container']=document.querySelector(selector);
_this['list'][ID]['__selector']=selector;
_this['list'][ID]['pagination']={
'next':1
,'current btn-primary':1
,'length':0
};
switch(_this['list'][ID]['__container'].tagName.toLowerCase()){
case 'table':
if (document.querySelector(selector+' > tbody')==null){
document.querySelector(selector+' > thead')
.insertAdjacentHTML('afterend',' ');
}
_this['list'][ID]['__dataContainer']=document
.querySelector(selector+' > tbody');
break;
default:
_this['list'][ID]['__dataContainer']=_this['list'][ID]['__container'];
break;
}
document.querySelector(selector).dataset['dataPage']=ID;
var lt=typeof(_this['list'][ID]['lengths']);
if (lt=='string'){
_this['list'][ID]['lengths']=_this['list'][ID]['lengths'].split(',');
}
if (lt=='undefined'){
_this['list'][ID]['lengths']=[10,25,50,100];
}
var lx=0,lengthOptions='';
lx=_this['list'][ID]['lengths'].length;
_this['list'][ID]['lengths'].forEach(function(l){
lengthOptions+=(''+l+' ');
});
if (isNew){
if (typeof(config['ignoreTop'])=='undefined'){
_this['list'][ID]['__container'].insertAdjacentHTML('beforebegin',''
+((lx>1)?('
'
+''+lengthOptions+' '
+'
');
}
else {
_this['list'][ID]['__container'].insertAdjacentHTML('beforebegin',
'
'
+'
'
);
}
if (typeof(_this['list'][ID]['skipPagination'])=='undefined'){
_this['list'][ID]['skipPagination']=false;
}
if (!_this['list'][ID]['skipPagination']){
_this['list'][ID]['__container'].insertAdjacentHTML('afterend','
');
}
}
}
config=_this['list'][ID];
}
if (typeof(config['filters'])!='undefined'){
dataFilters=config['filters']();
}
var searchElement=document.getElementById(ID+'Search');
if (searchElement!=null){
dataFilters['search']={'value':(searchElement.value.length>2)?searchElement.value:''};
}
if (typeof(dataFilters['length'])=='undefined'){
//dataFilters['length']=1;
if (typeof(config['skipLength'])=='undefined'){
//dataFilters['__length']=document.getElementById(ID+'Length').value;
}
}
if (typeof(dataFilters['__length'])=='undefined'){
var lengthElement=document.getElementById(ID+'Length');
if (lengthElement!=null){
dataFilters['__length']=lengthElement.value;
}
else {
dataFilters['__length']=_this['list'][ID]['pagination']['length'];
}
//_this['list'][ID]['pagination']['length']=document.getElementById(ID+'Length').value;
}
//else {
_this['list'][ID]['pagination']['length']=dataFilters['__length'];
//}
dataFilters['__offset']=(_this['list'][ID]['pagination']['next']-1)*dataFilters['__length'];
/** /
config['__dataContainer'].style['background-color']='#ff9999';
if (typeof(config['__loader'])=='undefined'){
var loaderID='loader'+(new Date()).getTime();
document.querySelector('body').insertAdjacentHTML('beforeend','
');
config['__loader']=document.querySelector('#'+loaderID+' pre');
}
config['__loader'].textContent=JSON.stringify(config['__dataContainer'].getBoundingClientRect(),null,2);
config['__dataContainer'].style['max-height']='200px';
config['__dataContainer'].style['overflow-y']='scroll';
console.dir(config['__dataContainer']);
console.dir(window);
/**/
switch(typeof(config['startPlaceholder'])){
case 'function':
config['__dataContainer'].innerHTML=config['startPlaceholder']();
break;
case 'string':
config['__dataContainer'].innerHTML=config['startPlaceholder'];
break;
}
//setTimeout(function(config){config['__dataContainer'].innerHTML='';},2000,config);
window['NickolaS_Solutions'][(typeof(config['WPAJAX'])!='undefined')?'wp_ajax':'post'](((typeof(config['customURL'])!='undefined')?config['customURL']():config['URL']),dataFilters,{'success':function(reply){
var reply=reply,e=0,finalData={'data':[]},parserConfig=null,dataDOM='',isValid=true;
finalData['recordsTotal']=reply.data['total'];
finalData['recordsFiltered']=reply.data['filtered'];
if (typeof(config['validateFirst'])!='undefined'){
isValid=config.validateFirst(reply);
}
if (isValid){
if (typeof(config['beforeParsing'])!='undefined'){
config.beforeParsing(reply);
}
if (typeof(config.parserConfig)!='undefined'){
parserConfig=config.parserConfig(reply);
}
reply.data.forEach(function(e){
var e=e,r=null;
r=config.parser(e,parserConfig);
if (typeof(r)=='string'){
dataDOM+=r;
}
else {
dataDOM+=('
'+r.join(' ')+' ');
}
//console.log(typeof(r));console.log(r);
//finalData.data.push(config.parser(e,parserConfig));
});
if(dataDOM==''){
switch(typeof(config['zeroPlaceholder'])){
case 'function':
dataDOM=config['zeroPlaceholder']();
break;
case 'string':
dataDOM=config['zeroPlaceholder'];
break;
}
}
//console.log(finalData);
config['__dataContainer'].innerHTML=dataDOM;
if (!config['skipPagination']){
_this['list'][ID]['pagination']['current btn-primary']=_this['list'][ID]['pagination']['next'];
_this.updatePagination(ID,reply['total']);
}
//console.log('after load '+ID+JSON.stringify(_this['list'][ID]['pagination'],null,2));
if (typeof(config['afterLoad'])!='undefined'){
config['afterLoad'](reply);
}
}
},'required_action':((typeof(config['requiredActions'])!='undefined')?config['requiredActions']:{})},1,{'Content-type':'application/json'});
}
,'run':function(offset){
}
,'updatePagination':function(ID,total){
var ID=ID, total=total, px=0, pi=0, pj=0, _this=this, resultDOM=''
,pc=parseInt(_this['list'][ID]['pagination']['current btn-primary']),pn=0,py=0;
console.log(ID+': '+total);
px=Math.ceil(total/_this['list'][ID]['pagination']['length']);
if (px>1){
if (px<8){
for(pi=1;pi<=px;pi++){
resultDOM+='';
}
}
else {
resultDOM+='
1 ';
if (pc<5){
for (pi=2;pi<=5;pi++){
resultDOM+='';
}
resultDOM+='
... ';
}
else {
resultDOM+='
... ';
if (pc>(px-4)){
for (pi=(px-4);pi