|
@@ -0,0 +1,1219 @@
|
|
|
+console.log('test1... DBG:', DBG)
|
|
|
+
|
|
|
+// localStorage.setItem('Bocian.pracownicyIds', JSON.stringify(ids))
|
|
|
+// var ids = localStorage.getItem('Bocian.pracownicyIds')
|
|
|
+// localStorage.removeItem('Bocian.pracownicyIds')
|
|
|
+// localStorage.removeItem('Bocian.kontrahenciIds')
|
|
|
+// localStorage.removeItem('Bocian.depth') // TODO: zapis na stronie głównej i BiAuditRaport
|
|
|
+
|
|
|
+if (!URL_FETCH_TEST) {
|
|
|
+ throw "Brak zmiennej URL_FETCH_TEST"
|
|
|
+}
|
|
|
+
|
|
|
+$(window).on('hashchange', function() {
|
|
|
+ initLocalStorage();
|
|
|
+ rootChangeForm();
|
|
|
+});
|
|
|
+
|
|
|
+function loadCurrentDepthInInput(idInput) {
|
|
|
+ var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
|
|
|
+
|
|
|
+ $(idInput).val(function() {
|
|
|
+ return depthValue;
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function updateLocalStorageBiAuditDepth(idInput) {
|
|
|
+ $(idInput).keyup(function() {
|
|
|
+ delayUpdate(function(){
|
|
|
+ var newValue = $(idInput).val();
|
|
|
+ var responseValue = validateValueDepth(parseInt(newValue));
|
|
|
+
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.depth', responseValue);
|
|
|
+ loadCurrentDepthInInput('.smad-depth');
|
|
|
+ }, 1000 );
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function validateValueDepth(newValue) {
|
|
|
+ var value = null;
|
|
|
+ value = newValue;
|
|
|
+
|
|
|
+ if (parseInt(newValue) < 0) {
|
|
|
+ value = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (parseInt(newValue) > 16) {
|
|
|
+ value = 16;
|
|
|
+ }
|
|
|
+
|
|
|
+ return value;
|
|
|
+}
|
|
|
+
|
|
|
+var delayUpdate = (function() {
|
|
|
+ var timer = 0;
|
|
|
+ return function(callback, ms) {
|
|
|
+ clearTimeout (timer);
|
|
|
+ timer = setTimeout(callback, ms);
|
|
|
+ };
|
|
|
+})();
|
|
|
+
|
|
|
+function initLocalStorage() {
|
|
|
+
|
|
|
+ if (getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') === null) {
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', []);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') === null) {
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', []);
|
|
|
+ }
|
|
|
+
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', 0);
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', 0);
|
|
|
+
|
|
|
+ if (getItemLocalStorage('Bocian.biAuditForm.depth') === null) {
|
|
|
+ updateLocalStorageBiAuditDepth(2);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function defaultBIAuditLocalStorage() {
|
|
|
+ localStorage.removeItem('Bocian.biAuditForm.pracownicyIds');
|
|
|
+ localStorage.removeItem('Bocian.biAuditForm.kontrahenciIds');
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', 1);
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', 1);
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', 0);
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', 0);
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.depth', 2);
|
|
|
+}
|
|
|
+
|
|
|
+function generateBiAuditRaport(event) {
|
|
|
+ event.preventDefault();
|
|
|
+
|
|
|
+ var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
|
|
|
+ var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
|
|
|
+ var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
|
|
|
+
|
|
|
+ // validate
|
|
|
+ if (!depthValue || depthValue === 0) {
|
|
|
+ p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie podano wartości dla głębokości powiązań' });
|
|
|
+ } else if (!pracownicyIdsArray || pracownicyIdsArray.length === 0) {
|
|
|
+ p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano pracowników' });
|
|
|
+ } else if (!kontrahenciIdsArray || kontrahenciIdsArray.length === 0) {
|
|
|
+ p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano kontrahentów' });
|
|
|
+ } else {
|
|
|
+ // send
|
|
|
+ window.fetch(URL_GENERATE_BI_AUDIT_RAPORT_AJAX, {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
+ },
|
|
|
+ credentials: 'same-origin',
|
|
|
+ body: JSON.stringify({
|
|
|
+ pracownicyIds: pracownicyIdsArray,
|
|
|
+ kontrahenciIds: kontrahenciIdsArray,
|
|
|
+ depthValue: depthValue
|
|
|
+ })
|
|
|
+ })
|
|
|
+ .then(function(response) {
|
|
|
+ console.log('Firsst then', response);
|
|
|
+ return response.text();
|
|
|
+ })
|
|
|
+ .then(function(responseText) {
|
|
|
+ try {
|
|
|
+ return JSON.parse(responseText);
|
|
|
+ } catch (e) {
|
|
|
+ throw responseText;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .then(function(result) {
|
|
|
+ result
|
|
|
+ if (result.type == 'success') {
|
|
|
+
|
|
|
+ p5UI__notifyAjaxCallback(result);
|
|
|
+ defaultBIAuditLocalStorage();
|
|
|
+ window.setTimeout(window.location.href = "https://bravecom.yellowgroup.pl/SE/index.php?_route=ViewTableAjax&namespace=default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA", 4000);
|
|
|
+ resolve(result.msg);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ reject(result.msg);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(function(error) {
|
|
|
+ console.log('request failed', error)
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function addPracownikToGroup(event) {
|
|
|
+ event.preventDefault();
|
|
|
+
|
|
|
+ var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
|
|
|
+
|
|
|
+ if (pracownicyIdsArray === null) {
|
|
|
+ showTextListIdPracownikow = 'ID pracowników: nie wybrano';
|
|
|
+ } else {
|
|
|
+ showTextListIdPracownikow = 'ID pracowników: ' + pracownicyIdsArray;
|
|
|
+ }
|
|
|
+
|
|
|
+ swal({
|
|
|
+ title: 'Przenieś do grupy',
|
|
|
+ input: 'select',
|
|
|
+ text: showTextListIdPracownikow,
|
|
|
+ inputOptions: getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups'),
|
|
|
+ inputPlaceholder: 'Wybierz grupę',
|
|
|
+ showCancelButton: true,
|
|
|
+ confirmButtonText: 'Zapisz',
|
|
|
+ showLoaderOnConfirm: true,
|
|
|
+ preConfirm: function (idGroup) {
|
|
|
+ return new Promise(function (resolve, reject) {
|
|
|
+ console.log('value', idGroup);
|
|
|
+
|
|
|
+ if ( !pracownicyIdsArray || pracownicyIdsArray === null || pracownicyIdsArray === 'undefined' ) {
|
|
|
+ reject('Wybierz pracowników');
|
|
|
+ } else if ( pracownicyIdsArray.length === 0 ) {
|
|
|
+ reject('Wybierz pracowników');
|
|
|
+ }
|
|
|
+ if (!idGroup) reject('Proszę wybrać nazwę grupy');
|
|
|
+
|
|
|
+ window.fetch(URL_ADD_PRACOWNICY_TO_GROUP, {
|
|
|
+ method: 'POST',
|
|
|
+ header: {
|
|
|
+ 'contentType': 'applications/json'
|
|
|
+ },
|
|
|
+ credentials: 'same-origin',
|
|
|
+ body: JSON.stringify({
|
|
|
+ 'idGroup': idGroup,
|
|
|
+ 'pracownicyIds': getItemLocalStorage('Bocian.biAuditForm.pracownicyIds'),
|
|
|
+ })
|
|
|
+ })
|
|
|
+ .then(function(response) {
|
|
|
+ return response.text();
|
|
|
+ })
|
|
|
+ .then(function(responseText) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ return JSON.parse(responseText);
|
|
|
+ } catch (e) {
|
|
|
+ throw responseText;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .then(function(result) {
|
|
|
+ result
|
|
|
+ if (result.type == 'success') {
|
|
|
+ p5UI__notifyAjaxCallback(result);
|
|
|
+ resolve(result.msg);
|
|
|
+ } else {
|
|
|
+ reject(result.msg);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(function(error) {
|
|
|
+ console.log('request failed', error)
|
|
|
+ });
|
|
|
+ })
|
|
|
+ },
|
|
|
+ allowOutsideClick: false
|
|
|
+ }).then(function (groupPracownicyData) {
|
|
|
+ //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function addKontrahenciToGroup(event) {
|
|
|
+ event.preventDefault();
|
|
|
+
|
|
|
+ var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
|
|
|
+
|
|
|
+ if (kontrahenciIdsArray === null) {
|
|
|
+ showTextListIdKontrahentow = 'ID pracowników: nie wybrano';
|
|
|
+ } else {
|
|
|
+ showTextListIdKontrahentow = 'ID pracowników: ' + pracownicyIdsArray;
|
|
|
+ }
|
|
|
+
|
|
|
+ swal({
|
|
|
+ title: 'Przenieś do grupy',
|
|
|
+ input: 'select',
|
|
|
+ text: showTextListIdKontrahentow,
|
|
|
+ inputOptions: getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups'),
|
|
|
+ inputPlaceholder: 'Wybierz grupę',
|
|
|
+ showCancelButton: true,
|
|
|
+ confirmButtonText: 'Zapisz',
|
|
|
+ showLoaderOnConfirm: true,
|
|
|
+ preConfirm: function (idGroup) {
|
|
|
+ return new Promise(function (resolve, reject) {
|
|
|
+
|
|
|
+ if (!idGroup) reject('Proszę wybrać nazwę grupy');
|
|
|
+ if ( !kontrahenciIdsArray || kontrahenciIdsArray === null || kontrahenciIdsArray === 'undefined' ) {
|
|
|
+ reject('Wybierz kontrahentów');
|
|
|
+ } else if ( kontrahenciIdsArray.length === 0 ) {
|
|
|
+ reject('Wybierz kontrahentów');
|
|
|
+ }
|
|
|
+
|
|
|
+ window.fetch(URL_ADD_KONTRAHENCI_TO_GROUP, {
|
|
|
+ method: 'POST',
|
|
|
+ header: {
|
|
|
+ 'contentType': 'applications/json'
|
|
|
+ },
|
|
|
+ credentials: 'same-origin',
|
|
|
+ body: JSON.stringify({
|
|
|
+ 'idGroup': idGroup,
|
|
|
+ 'kontrahenciIds': getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds'),
|
|
|
+ })
|
|
|
+ })
|
|
|
+ .then(function(response) {
|
|
|
+ return response.text();
|
|
|
+ })
|
|
|
+ .then(function(responseText) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ return JSON.parse(responseText);
|
|
|
+ } catch (e) {
|
|
|
+ throw responseText;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .then(function(result) {
|
|
|
+ result
|
|
|
+ if (result.type == 'success') {
|
|
|
+ p5UI__notifyAjaxCallback(result);
|
|
|
+ resolve(result.msg);
|
|
|
+ } else {
|
|
|
+ reject(result.msg);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ;
|
|
|
+ })
|
|
|
+ },
|
|
|
+ allowOutsideClick: false
|
|
|
+ }).then(function (groupKontrahenciData) {
|
|
|
+ //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function createGroupKontrahenci(event) {
|
|
|
+ event.preventDefault();
|
|
|
+
|
|
|
+ swal({
|
|
|
+ title: 'Utwórz grupę',
|
|
|
+ input: 'text',
|
|
|
+ showCancelButton: true,
|
|
|
+ confirmButtonText: 'Zapisz',
|
|
|
+ showLoaderOnConfirm: true,
|
|
|
+ preConfirm: function (NAZWA) {
|
|
|
+ return new Promise(function (resolve, reject) {
|
|
|
+ if (!NAZWA) reject('Proszę podać nazwę grupy');
|
|
|
+
|
|
|
+ window.fetch(URL_CREATE_KONTRAHENCIS_GROUP, {
|
|
|
+ method: 'POST',
|
|
|
+ header: {
|
|
|
+ 'contentType': 'applications/json'
|
|
|
+ },
|
|
|
+ credentials: 'same-origin',
|
|
|
+ body: JSON.stringify({
|
|
|
+ 'NAZWA': NAZWA
|
|
|
+ })
|
|
|
+ })
|
|
|
+ .then(function(response) {
|
|
|
+ return response.text();
|
|
|
+ })
|
|
|
+ .then(function(responseText) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ return JSON.parse(responseText);
|
|
|
+ } catch (e) {
|
|
|
+ throw responseText;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .then(function(result) {
|
|
|
+ result
|
|
|
+ if (result.type == 'success') {
|
|
|
+ p5UI_notifyAjaxCallback(result);
|
|
|
+ resolve(result.msg);
|
|
|
+ } else {
|
|
|
+ reject(result.msg);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ;
|
|
|
+ })
|
|
|
+ },
|
|
|
+ allowOutsideClick: false
|
|
|
+ }).then(function (groupKontrahenciData) {
|
|
|
+ //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
|
|
|
+ groupsKontrahenci = '<button class="btn btn-default" title="'+groupKontrahenciData['NAZWA']+'" data-group-filter="'+groupKontrahenciData['ID']+'">'+groupKontrahenciData['NAZWA']+'</button>';
|
|
|
+ $('#group-kontrahenci').append(groupsKontrahenci);
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function createGroupPracownicy(event) {
|
|
|
+ event.preventDefault();
|
|
|
+
|
|
|
+ swal({
|
|
|
+ title: 'Utwórz grupę',
|
|
|
+ input: 'text',
|
|
|
+ showCancelButton: true,
|
|
|
+ confirmButtonText: 'Zapisz',
|
|
|
+ showLoaderOnConfirm: true,
|
|
|
+ preConfirm: function (NAZWA) {
|
|
|
+ return new Promise(function (resolve, reject) {
|
|
|
+ if (!NAZWA) reject('Proszę podać nazwę grupy');
|
|
|
+
|
|
|
+ window.fetch(URL_CREATE_PRACOWNICY_GROUP, {
|
|
|
+ method: 'POST',
|
|
|
+ header: {
|
|
|
+ 'contentType': 'applications/json'
|
|
|
+ },
|
|
|
+ credentials: 'same-origin',
|
|
|
+ body: JSON.stringify({
|
|
|
+ 'NAZWA': NAZWA
|
|
|
+ })
|
|
|
+ })
|
|
|
+ .then(function(response) {
|
|
|
+ return response.text();
|
|
|
+ })
|
|
|
+ .then(function(responseText) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ return JSON.parse(responseText);
|
|
|
+ } catch (e) {
|
|
|
+ throw responseText;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .then(function(result) {
|
|
|
+ result
|
|
|
+ if (result.type == 'success') {
|
|
|
+ p5UI_notifyAjaxCallback(result);
|
|
|
+ resolve(result.msg);
|
|
|
+ } else {
|
|
|
+ reject(result.msg);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ;
|
|
|
+ })
|
|
|
+ },
|
|
|
+ allowOutsideClick: false
|
|
|
+ }).then(function (groupPracownicyData) {
|
|
|
+ //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
|
|
|
+ groupsPracownicy = '<button class="btn btn-default" title="'+groupPracownicyData['NAZWA']+'" data-group-filter="'+groupPracownicyData['ID']+'">'+groupPracownicyData['NAZWA']+'</button>';
|
|
|
+ $('#group-pracownicy').append(groupsPracownicy);
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// // Documentation: https://github.com/github/fetch
|
|
|
+// fetch(URL_FETCH_TEST, {
|
|
|
+// credentials: 'same-origin'
|
|
|
+// })
|
|
|
+// .then(function parseJSON(response) {
|
|
|
+// return response.json()
|
|
|
+// })
|
|
|
+// .then(function(data) {
|
|
|
+// //$( ".container" ).append( data.body.view );
|
|
|
+// console.log('request succeeded with JSON response', data)
|
|
|
+// }).catch(function(error) {
|
|
|
+// console.log('request failed', error)
|
|
|
+// })
|
|
|
+//
|
|
|
+// fetch(URL_FETCH_TEST_KRS, {
|
|
|
+// credentials: 'same-origin'
|
|
|
+// })
|
|
|
+// .then(function parseJSON(response) {
|
|
|
+// return response.json()
|
|
|
+// })
|
|
|
+// .then(function(data) {
|
|
|
+// console.log('request succeeded with JSON response', data)
|
|
|
+// }).catch(function(error) {
|
|
|
+// console.log('request failed', error)
|
|
|
+// })
|
|
|
+//
|
|
|
+// fetch(URL_FETCH_TEST_CEIDG, {
|
|
|
+// credentials: 'same-origin'
|
|
|
+// })
|
|
|
+// .then(function parseJSON(response) {
|
|
|
+// return response.json()
|
|
|
+// })
|
|
|
+// .then(function(data) {
|
|
|
+// console.log('request succeeded with JSON response', data)
|
|
|
+// }).catch(function(error) {
|
|
|
+// console.log('request failed', error)
|
|
|
+// })
|
|
|
+
|
|
|
+function rootChangeForm() {
|
|
|
+
|
|
|
+ var valueUrl = global.location.hash;
|
|
|
+
|
|
|
+ switch (valueUrl) {
|
|
|
+ case '#KONTRAHENCI':
|
|
|
+ $( ".container-bi_audit_form_kontrahenci_raport" ).html( VIEW_KONTRAHENCI );
|
|
|
+ urlFetchKontrahenci(1);
|
|
|
+ fetchGroupKontrahenci();
|
|
|
+ $( ".container-bi_audit_form_pracownicy_raport" ).hide();
|
|
|
+ $( ".container-bi_audit_form_kontrahenci_raport" ).show();
|
|
|
+ break;
|
|
|
+
|
|
|
+ case '#PRACOWNICY':
|
|
|
+ $( ".container-bi_audit_form_pracownicy_raport" ).html( VIEW_PRACOWNICY );
|
|
|
+ urlFetchPracownicy(1);
|
|
|
+ fetchGroupPracownicy()
|
|
|
+ $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
|
|
|
+ $( ".container-bi_audit_form_pracownicy_raport" ).show();
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ $( ".container-bi_audit_form_pracownicy_raport" ).html( VIEW_PRACOWNICY );
|
|
|
+ urlFetchPracownicy(1);
|
|
|
+ fetchGroupPracownicy()
|
|
|
+ $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
|
|
|
+ $( ".container-bi_audit_form_pracownicy_raport" ).show();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ //aktualizacja inputa głebokości powiazan
|
|
|
+ loadCurrentDepthInInput('.smad-depth');
|
|
|
+ updateLocalStorageBiAuditDepth('.smad-depth');
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function getAddressData(objectValue) {
|
|
|
+
|
|
|
+ var objectValue = objectValue || [];
|
|
|
+ var listData = '';
|
|
|
+
|
|
|
+ if (!objectValue) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ objectValue.forEach (function(item) {
|
|
|
+ if (item['kodPocztowy']) { listData += '<div>kod pocztowy: ' + item['kodPocztowy'] + '<div>'; }
|
|
|
+ if (item['miejscowosc']) { listData += '<div>miejscowość: ' + item['miejscowosc'] + '<div>'; }
|
|
|
+ if (item['nrBudynku']) { listData += '<div>nr budynku: ' + item['nrBudynku'] + '<div>'; }
|
|
|
+ if (item['nrLokalu']) { listData += '<div>nr lokalu: ' + item['nrLokalu'] + '<div>'; }
|
|
|
+ if (item['typAdresu']) { listData += '<div>typ adresu: ' + item['typAdresu'] + '<div>'; }
|
|
|
+ if (item['ulica']) { listData += '<div>ulica: ' + item['ulica'] + '<div>'; }
|
|
|
+ listData += '<div>------<div>';
|
|
|
+ });
|
|
|
+
|
|
|
+ return listData;
|
|
|
+}
|
|
|
+
|
|
|
+function urlFetchKontrahenci(page) {
|
|
|
+ var page = page || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page');
|
|
|
+
|
|
|
+ selectPage('KONTRAHENCI', page);
|
|
|
+ if ( page === 1) {
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
|
|
|
+
|
|
|
+ fetch(URL_FETCH_KONTRAHENCI + '&page=' + page + '&filterIdGroup=' + filterIdGroup, {
|
|
|
+ credentials: 'same-origin'
|
|
|
+ })
|
|
|
+ .then(function parseJSON(response) {
|
|
|
+ return response.json()
|
|
|
+
|
|
|
+ var filterIdGroup = filterIdGroup || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
|
|
|
+ })
|
|
|
+ .then(function(data) {
|
|
|
+
|
|
|
+ var listItemsKontrahenci = null;
|
|
|
+ data.body.items.forEach (function(row) {
|
|
|
+ listItemsKontrahenci += '<tr><td><input type="checkbox" name="kontrID[]" value="'+row['ID']+'" /></td>'+
|
|
|
+ '<td align="right">'+row["ID"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Nazwa_grupy_kapitalowej"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Pelna_nazwa_kontrahenta"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Numer_kontrahenta"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Skrocona_Nazwa_Kontrahenta"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Typ_kontrahenta"]+'</td>'+
|
|
|
+ '<td align="right">'+row["NIP"]+'</td>'+
|
|
|
+ '<td align="right">'+row["KRS"]+'</td>'+
|
|
|
+ '<td align="right">'+row["REGON"]+'</td>'+
|
|
|
+ '<td align="right">'+row["PESEL"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Forma_prawna_dzialalnosci"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Ulica"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Numer_budynku"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Numer_mieszkania_lokalu"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Miejscowosc"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Kod_pocztowy"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Kraj"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Telefon"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Fax"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Mail"]+'</td>'+
|
|
|
+ '<td align="right">'+row["A_ADM_COMPANY"]+'</td>'+
|
|
|
+ '<td align="right">'+row["A_CLASSIFIED"]+'</td>'+
|
|
|
+ '<td align="right">'+row["A_STATUS"]+'</td>'+
|
|
|
+ '<td align="right">'+row["A_STATUS_INFO"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Dodano"]+'</td>'+
|
|
|
+ '<td align="right">'+row["L_APPOITMENT_USER"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Podmiot_dominujacy"]+'</td>'+
|
|
|
+ '<td align="right">'+row["Tytul_dokumentu"]+'</td>'+
|
|
|
+ '<td align="right">'+row["ownCompany"]+'</td>'+
|
|
|
+ '<td align="right">'+row["uwagi"]+'</td></tr>';
|
|
|
+ });
|
|
|
+
|
|
|
+ if (data.body.pagination !== undefined) {
|
|
|
+ Pagination.Init(document.getElementById('pagination-kontrahenci'), {
|
|
|
+ url: 'https://bravecom.yellowgroup.pl/SE/index.php?_route=UrlAction_Bocian#KONTRAHENCI',
|
|
|
+ id_pagination: 'pagination-kontrahenci',
|
|
|
+ type: 'KONTRAHENCI',
|
|
|
+ total_items: data.body.pagination.total_items, // pages size
|
|
|
+ size: data.body.pagination.size, // pages size
|
|
|
+ page: page, // selected page
|
|
|
+ step: 1 // pages before and after current
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $( "#body-kontrahenci" ).html(listItemsKontrahenci);
|
|
|
+ checkAll('KONTRAHENCI');
|
|
|
+ catchEventCheckbox('KONTRAHENCI');
|
|
|
+ checkedChoiseItems('KONTRAHENCI', getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') );
|
|
|
+
|
|
|
+ // $( ".container-bi_audit_raport" ).append( data.body.view );
|
|
|
+ console.log('request succeeded with JSON responseKontrahenci', data)
|
|
|
+ }).catch(function(error) {
|
|
|
+ console.log('request failed', error)
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function urlFetchPracownicy(page) {
|
|
|
+
|
|
|
+ var page = page || getItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page');
|
|
|
+
|
|
|
+ if ( page === 1) {
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
|
|
|
+
|
|
|
+ selectPage('PRACOWNICY', page);
|
|
|
+
|
|
|
+ fetch(URL_FETCH_PRACOWNICY + '&page=' + page + '&filterIdGroup=' + filterIdGroup, {
|
|
|
+ credentials: 'same-origin'
|
|
|
+ })
|
|
|
+ .then(function parseJSON(response) {
|
|
|
+ return response.json()
|
|
|
+ })
|
|
|
+ .then(function(data) {
|
|
|
+
|
|
|
+ var addresPerson = '';
|
|
|
+ var listItemsPracownik = null;
|
|
|
+ console.log('urlFetchPracownicy', data.body.items);
|
|
|
+
|
|
|
+ data.body.items.forEach (function(row) {
|
|
|
+
|
|
|
+ if (row["default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy"]) {
|
|
|
+ addresPerson = getAddressData(row["default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy"]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ listItemsPracownik += '<tr><td><input type="checkbox" name="prID[]" value="'+row['ID']+'" /></td>'+
|
|
|
+ '<td align="right">'+row["ID"]+'</td>'+
|
|
|
+ '<td align="right">'+row["imiona"]+'</td>'+
|
|
|
+ '<td align="right">'+row["nazwisko"]+'</td>'+
|
|
|
+ '<td align="right">'+row["nip"]+'</td>'+
|
|
|
+ '<td align="right">'+row["pesel"]+'</td>'+
|
|
|
+ '<td align="right">'+row["regon"]+'</td>'+
|
|
|
+ '<td align="right">'+row["source"]+'</td>'+
|
|
|
+ '<td align="right">'+row["A_ADM_COMPANY"]+'</td>'+
|
|
|
+ '<td align="right">'+row["A_CLASSIFIED"]+'</td>'+
|
|
|
+ '<td align="right">'+row["A_STATUS"]+'</td>'+
|
|
|
+ '<td align="right">'+row["A_STATUS_INFO"]+'</td>'+
|
|
|
+ '<td align="right">'+row["L_APPOITMENT_USER"]+'</td>'+
|
|
|
+ '<td align="right">'+ addresPerson +'</td></tr>';
|
|
|
+ });
|
|
|
+
|
|
|
+ if (data.body.pagination.size) {
|
|
|
+ Pagination.Init(document.getElementById('pagination-pracownicy'), {
|
|
|
+ url: 'https://bravecom.yellowgroup.pl/SE/index.php?_route=UrlAction_Bocian#PRACOWNICY',
|
|
|
+ id_pagination: 'pagination-pracownicy',
|
|
|
+ type: 'PRACOWNICY',
|
|
|
+ total_items: data.body.pagination.total_items, // pages size
|
|
|
+ size: data.body.pagination.size, // pages size
|
|
|
+ page: data.body.pagination.current, // selected page
|
|
|
+ step: 1 // pages before and after current
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ $( "#body-pracownicy" ).html( listItemsPracownik);
|
|
|
+ checkAll('PRACOWNICY');
|
|
|
+ catchEventCheckbox('PRACOWNICY');
|
|
|
+ checkedChoiseItems('PRACOWNICY', getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') );
|
|
|
+
|
|
|
+ // $( ".container-bi_audit_raport" ).append( data.body.view );
|
|
|
+ console.log('request succeeded with JSON responsePRACOWNICY', data)
|
|
|
+ }).catch(function(error) {
|
|
|
+ console.log('request failed', error)
|
|
|
+ })
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function selectPage(type, nrPage) {
|
|
|
+ var type = type.toLowerCase();
|
|
|
+
|
|
|
+ $('#pagination-' + type + ' ul li a').each(function(index, value){
|
|
|
+ if (this.text === nrPage) {
|
|
|
+ $(this).addClass('active');
|
|
|
+ } else {
|
|
|
+ $(this).removeClass('active');
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function checkAll(type) {
|
|
|
+
|
|
|
+ $('#checkAll-' + type).change(function() {
|
|
|
+
|
|
|
+ var valueCheckbox = null;
|
|
|
+ var checkboxes = $('form').find(':checkbox');
|
|
|
+ if($(this).prop('checked')) {
|
|
|
+ checkboxes.prop('checked', true);
|
|
|
+ //valueCheckbox = checkboxes.prop("checked");
|
|
|
+ var allValsChecked = [];
|
|
|
+ var checkedValues = $('#smad-table-' + type + ' input:checkbox:checked').map(function() {
|
|
|
+
|
|
|
+ if (this.value !== 'on') {
|
|
|
+ allValsChecked.push(parseInt(this.value));
|
|
|
+ }
|
|
|
+ }).get();
|
|
|
+
|
|
|
+ updateListIdBiAuditReaport(type, allValsChecked);
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ checkboxes.prop('checked', false);
|
|
|
+
|
|
|
+ var allValsUnChecked = [];
|
|
|
+ var checkedValues = $('#smad-table-' + type + ' input:checkbox:not(:checked)').map(function() {
|
|
|
+ if (this.value !== 'on') {
|
|
|
+ allValsUnChecked.push(parseInt(this.value));
|
|
|
+ }
|
|
|
+ }).get();
|
|
|
+
|
|
|
+ deleteListIdBiAuditReaport(type, allValsUnChecked);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Select again checkbox before selected item chekbox from storage (pracownicy/kontrahenci)
|
|
|
+ */
|
|
|
+function checkedChoiseItems(type, store) {
|
|
|
+
|
|
|
+ var idElement = 'smad-table-' + type;
|
|
|
+
|
|
|
+ // if id element exist
|
|
|
+ if (document.getElementById(idElement)) {
|
|
|
+
|
|
|
+ // checked again if user selected Item (pracownicy/kontrahent)
|
|
|
+ for (i = 0; i < store.length; i++) {
|
|
|
+ $('#body-'+type.toLowerCase() +' input[type=checkbox] ').map(function(k, v) {
|
|
|
+ if ( store[i] === parseInt(this.value) ){
|
|
|
+ $(this).prop('checked', true);
|
|
|
+ }
|
|
|
+ }).get();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //$('#checkAll-' + type).on('bind', function() {
|
|
|
+ $('#smad-table-' + type + ' input[type=checkbox]').on( 'load', function() {
|
|
|
+ var itemsCHecked = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
|
|
|
+
|
|
|
+ getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
|
|
|
+
|
|
|
+ if (itemsCHecked.lenght === 0 ) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var valueCheckbox = null;
|
|
|
+ var checkboxes = $('form').find(':checkbox');
|
|
|
+ if($(this).prop('checked')) {
|
|
|
+ checkboxes.prop('checked', true);
|
|
|
+ var allValsChecked = [];
|
|
|
+ var checkedValues = $('#smad-table-' + type + ' input:checkbox:checked').map(function() {
|
|
|
+
|
|
|
+ if (this.value !== 'on') {
|
|
|
+ allValsChecked.push(parseInt(this.value));
|
|
|
+ }
|
|
|
+ }).get();
|
|
|
+
|
|
|
+ updateListIdBiAuditReaport(type, allValsChecked);
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ checkboxes.prop('checked', false);
|
|
|
+
|
|
|
+ var allValsUnChecked = [];
|
|
|
+ var checkedValues = $('#smad-table-' + type + ' input:checkbox:not(:checked)').map(function() {
|
|
|
+ if (this.value !== 'on') {
|
|
|
+ allValsUnChecked.push(parseInt(this.value));
|
|
|
+ }
|
|
|
+ }).get();
|
|
|
+
|
|
|
+ deleteListIdBiAuditReaport(type, allValsUnChecked);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function catchEventCheckbox(type) {
|
|
|
+
|
|
|
+ $('#smad-table-' + type + ' input[type="checkbox"]').on('change', function() {
|
|
|
+ if($(this).is(":checked")) {
|
|
|
+ var allValsChecked = [];
|
|
|
+ if (this.value !== 'on') {
|
|
|
+ allValsChecked.push(parseInt(this.value));
|
|
|
+ }
|
|
|
+
|
|
|
+ updateListIdBiAuditReaport(type, allValsChecked);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ var allValsUnChecke = [];
|
|
|
+ if (this.value !== 'on') {
|
|
|
+ allValsUnChecke.push(parseInt(this.value));
|
|
|
+ }
|
|
|
+
|
|
|
+ deleteListIdBiAuditReaport(type, allValsUnChecke);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function clearSelectedCheckbox() {
|
|
|
+ $('#checkAll-PRACOWNICY').prop('checked', false)
|
|
|
+ $('#checkAll-KONTRAHENCI').prop('checked', false)
|
|
|
+}
|
|
|
+
|
|
|
+function updateListIdBiAuditReaport(type, valueArray) {
|
|
|
+
|
|
|
+ var currentStoragePracownicyIds = [];
|
|
|
+ var updateListPracownicyIds = null;
|
|
|
+ var currentStorageKontrahenciIds = [];
|
|
|
+ var updateListKontrahenciIds = null;
|
|
|
+
|
|
|
+ if ( type == 'PRACOWNICY') {
|
|
|
+ currentStoragePracownicyIds = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
|
|
|
+
|
|
|
+ if(currentStoragePracownicyIds !== null) {
|
|
|
+ updateListPracownicyIds = [...new Set([...currentStoragePracownicyIds ,...valueArray])];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ updateListPracownicyIds = valueArray;
|
|
|
+ }
|
|
|
+
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', updateListPracownicyIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( type == 'KONTRAHENCI') {
|
|
|
+ currentStorageKontrahenciIds = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
|
|
|
+
|
|
|
+ if(currentStorageKontrahenciIds !== null) {
|
|
|
+ updateListKontrahenciIds = [...new Set([...currentStorageKontrahenciIds ,...valueArray])];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ updateListKontrahenciIds = valueArray;
|
|
|
+ }
|
|
|
+
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', updateListKontrahenciIds);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function deleteListIdBiAuditReaport(type, valueArray) {
|
|
|
+
|
|
|
+ var currentStoragePracownicyIds = [];
|
|
|
+ var updateListPracownicyIds = null;
|
|
|
+
|
|
|
+ if ( type == 'PRACOWNICY') {
|
|
|
+ deleteItemLocalStorage('Bocian.biAuditForm.pracownicyIds', valueArray);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( type == 'KONTRAHENCI') {
|
|
|
+ deleteItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', valueArray);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// filter group detect
|
|
|
+function fetchGroupPracownicy() {
|
|
|
+
|
|
|
+ fetch(URL_FETCH_GROUP_PRACOWNICY, {
|
|
|
+ credentials: 'same-origin'
|
|
|
+ })
|
|
|
+ .then(function parseJSON(response) {
|
|
|
+ return response.json()
|
|
|
+ })
|
|
|
+ .then(function(data) {
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.pracownicy.groups', data.body.itmesGroupPracownicy);
|
|
|
+
|
|
|
+ if (data.body.itmesGroupPracownicy === null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
|
|
|
+ var groupsPracownicy = '';
|
|
|
+ var activeButton = '';
|
|
|
+
|
|
|
+ data.body.itmesGroupPracownicy.forEach (function(row) {
|
|
|
+ if ( filterIdGroup === row['ID'] ) { activeButton = 'active'; $('#group-pracownicy button.active').removeClass('active'); }
|
|
|
+ groupsPracownicy += '<button class="btn btn-default '+activeButton+'" title="' + row['NAZWA'] + '" data-group-filter="' + row['ID'] + '">' + row['NAZWA'] + '</button>';
|
|
|
+ });
|
|
|
+
|
|
|
+ $("#group-pracownicy").append(groupsPracownicy);
|
|
|
+
|
|
|
+ console.log('request succeeded with JSON fetchGroupPracownicy', data.body.itmesGroupPracownicy)
|
|
|
+ }).catch(function(error) {
|
|
|
+ console.log('request failed', error)
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function fetchGroupKontrahenci() {
|
|
|
+
|
|
|
+ fetch(URL_FETCH_GROUP_KONTRAHENCI, {
|
|
|
+ credentials: 'same-origin'
|
|
|
+ })
|
|
|
+ .then(function parseJSON(response) {
|
|
|
+ return response.json()
|
|
|
+ })
|
|
|
+ .then(function(data) {
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups', data.body.itemsGroupKontrahenci);
|
|
|
+
|
|
|
+ if (data.body.itemsGroupKontrahenci === null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
|
|
|
+ var groupsKontrahenci = '';
|
|
|
+ var activeButton = '';
|
|
|
+
|
|
|
+ data.body.itemsGroupKontrahenci.forEach (function(row) {
|
|
|
+ if ( filterIdGroup === row['ID'] ) { activeButton = 'active'; $('#group-kontrahenci button.active').removeClass('active'); }
|
|
|
+ groupsKontrahenci += '<button class="btn btn-default '+activeButton+'" title="'+row['NAZWA']+'" data-group-filter="'+row['ID']+'">'+row['NAZWA']+'</button>';
|
|
|
+ });
|
|
|
+
|
|
|
+ $("#group-kontrahenci").append(groupsKontrahenci);
|
|
|
+
|
|
|
+ console.log('request succeeded with JSON fetchGroupKontrahenci', data.body.itemsGroupKontrahenci);
|
|
|
+ }).catch(function(error) {
|
|
|
+ console.log('request failed', error)
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function detectChoiseFilter() {
|
|
|
+
|
|
|
+ $('#group-kontrahenci').on('click', 'button', function(evt) {
|
|
|
+
|
|
|
+ $('#group-kontrahenci button.active').removeClass('active');
|
|
|
+ $(this).addClass('active');
|
|
|
+
|
|
|
+ // pobranie id grupy kliknietego buttonu
|
|
|
+ var filterIdGroup = $(this).attr("data-group-filter");
|
|
|
+ // ustawić id grupy do sesyjnej
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', parseInt(filterIdGroup));
|
|
|
+ // wywylac funckje pobrania danych
|
|
|
+ urlFetchKontrahenci(1);
|
|
|
+
|
|
|
+ });
|
|
|
+ $('#group-pracownicy').on('click', 'button', function(evt) {
|
|
|
+
|
|
|
+ $('#group-pracownicy button.active').removeClass('active');
|
|
|
+ $(this).addClass('active');
|
|
|
+
|
|
|
+ // pobranie id grupy kliknietego buttonu
|
|
|
+ var filterIdGroup = $(this).attr("data-group-filter");
|
|
|
+ // ustawić id grupy do sesyjnej
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', parseInt(filterIdGroup));
|
|
|
+ // wywylac funckje pobrania danych
|
|
|
+ urlFetchPracownicy(1);
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// Local storage
|
|
|
+function setItemLocalStorage(key, array) {
|
|
|
+ localStorage.setItem(key, JSON.stringify(array));
|
|
|
+}
|
|
|
+
|
|
|
+function getItemLocalStorage(key) {
|
|
|
+ var retrievedData = localStorage.getItem(key);
|
|
|
+ var response = JSON.parse(retrievedData);
|
|
|
+
|
|
|
+ return response;
|
|
|
+}
|
|
|
+
|
|
|
+function deleteItemLocalStorage(key, itemsArray) {
|
|
|
+
|
|
|
+ var currentStorageArray = getItemLocalStorage(key);
|
|
|
+
|
|
|
+ var newStorageArray = removeItemArrayInArray(currentStorageArray, itemsArray);
|
|
|
+
|
|
|
+ setItemLocalStorage(key, newStorageArray);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * arr - array
|
|
|
+ * item - search item
|
|
|
+ */
|
|
|
+function removeItemInArray(arr, item) {
|
|
|
+ for(var i = arr.length; i--;) {
|
|
|
+ if(arr[i] === item) {
|
|
|
+ arr.splice(i, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * arr - array
|
|
|
+ * item - array list items
|
|
|
+ */
|
|
|
+function removeItemArrayInArray(arr, itemsArray) {
|
|
|
+ for(var i = arr.length; i--;) {
|
|
|
+ for(var j = itemsArray.length; j--;) {
|
|
|
+ if(arr[i] === itemsArray[j]) {
|
|
|
+ arr.splice(i, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
+
|
|
|
+// Pagination
|
|
|
+var Pagination = {
|
|
|
+
|
|
|
+ code: '', // end show html paginations
|
|
|
+ clickPage: 1, // set default 1 page
|
|
|
+
|
|
|
+ // --------------------
|
|
|
+ // Utility
|
|
|
+ // --------------------
|
|
|
+ // initialize default data
|
|
|
+ Extend: function(data) {
|
|
|
+ data = data || {};
|
|
|
+ Pagination.url = data.url;
|
|
|
+ Pagination.id_pagination = data.id_pagination;
|
|
|
+ Pagination.type = data.type;
|
|
|
+ Pagination.total_items = data.total_items;
|
|
|
+ Pagination.size = data.size || 2;
|
|
|
+ Pagination.page = data.page || 1;
|
|
|
+ Pagination.step = data.step || 3;
|
|
|
+ },
|
|
|
+
|
|
|
+ // add pages by number (from [s] to [f])
|
|
|
+ Add: function(s, f) {
|
|
|
+ for (var i = s; i < f; i++) {
|
|
|
+ Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">' + i + '</a></li>';
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // add last page with separator
|
|
|
+ Last: function() {
|
|
|
+ Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">>></a></li>';
|
|
|
+ },
|
|
|
+
|
|
|
+ // add first page with separator
|
|
|
+ First: function() {
|
|
|
+ Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default"><<</a></li>';
|
|
|
+ },
|
|
|
+
|
|
|
+ // add last page with separator
|
|
|
+ Next: function() {
|
|
|
+ Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">></a></li>';
|
|
|
+ },
|
|
|
+
|
|
|
+ // add first page with separator
|
|
|
+ Prev: function() {
|
|
|
+ Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default"><</a></li>';
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // --------------------
|
|
|
+ // Handlers
|
|
|
+ // --------------------
|
|
|
+
|
|
|
+ // change page
|
|
|
+ Click: function() {
|
|
|
+ clearSelectedCheckbox();
|
|
|
+
|
|
|
+ var selectPage = $("#pagination-"+Pagination.type.toLowerCase()+' .tblAjax__footer__toolbar__pagination').find('a.active').text();
|
|
|
+ Pagination.clickPage = +this.innerHTML || '';
|
|
|
+ if ( selectPage === NaN || selectPage > Pagination.size) { selectPage = 1; }
|
|
|
+
|
|
|
+ switch (this.innerHTML) {
|
|
|
+ case '>>': // last
|
|
|
+ Pagination.clickPage = Pagination.size;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case '<<': // first
|
|
|
+ Pagination.clickPage = 1;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case '<': // prev
|
|
|
+ Pagination.clickPage = parseInt(selectPage) - 1;
|
|
|
+ if (Pagination.clickPage < 1) {
|
|
|
+ Pagination.clickPage = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case '>': // next
|
|
|
+ Pagination.clickPage = parseInt(selectPage) + 1;
|
|
|
+
|
|
|
+ if (Pagination.clickPage > Pagination.size) {
|
|
|
+ Pagination.clickPage = Pagination.size;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( Pagination.type === 'KONTRAHENCI' ) {
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', Pagination.clickPage);
|
|
|
+ Pagination.page = urlFetchKontrahenci(Pagination.clickPage);
|
|
|
+ }
|
|
|
+ else if ( Pagination.type === 'PRACOWNICY' ){
|
|
|
+ setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', Pagination.clickPage);
|
|
|
+ Pagination.page = urlFetchPracownicy(Pagination.clickPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ Pagination.Start();
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ // --------------------
|
|
|
+ // Script structure pagination
|
|
|
+ // --------------------
|
|
|
+
|
|
|
+ // binding pages
|
|
|
+ Bind: function() {
|
|
|
+ var a = Pagination.e.getElementsByTagName('a');
|
|
|
+ var currentPage = Pagination.clickPage || 1;
|
|
|
+ for (var i = 0; i < a.length; i++) {
|
|
|
+ if (+a[i].innerHTML === Pagination.page) a[i].className = 'btn btn-default active';
|
|
|
+ a[i].addEventListener('click', Pagination.Click, false);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // write pagination
|
|
|
+ Finish: function() {
|
|
|
+ Pagination.e.innerHTML = Pagination.code;
|
|
|
+ Pagination.code = '</ul></nav>';
|
|
|
+ Pagination.Bind();
|
|
|
+ },
|
|
|
+
|
|
|
+ // find pagination type
|
|
|
+ Start: function() {
|
|
|
+ Pagination.code = '<div class="foot-info tblAjax__footer__toolbar__info footer_pagination_menu_items"><p>Wiersze od 1 do ' + Pagination.total_items + ' z ' + Pagination.total_items + '</p></div>';
|
|
|
+ Pagination.code += '<nav aria-label="Page navigation" class="footer_pagination_menu_items"><ul class="btn-group tblAjax__footer__toolbar__pagination smad-pagination">';
|
|
|
+ Pagination.First();
|
|
|
+ Pagination.Prev();
|
|
|
+
|
|
|
+
|
|
|
+ if ( Pagination.type === 'KONTRAHENCI' ) {
|
|
|
+ Pagination.page = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page') || 1;
|
|
|
+ }
|
|
|
+ else if ( Pagination.type === 'PRACOWNICY' ){
|
|
|
+ Pagination.page = getItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page') || 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( Pagination.page > Pagination.size ) {
|
|
|
+ Pagination.page = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Pagination.size < Pagination.step * 2 + 6) {
|
|
|
+ Pagination.Add(1, Pagination.size + 1);
|
|
|
+ }
|
|
|
+ /*else if (Pagination.page < Pagination.step * 2 + 1) {
|
|
|
+ Pagination.Add(1, Pagination.step * 2 + 4);
|
|
|
+ }
|
|
|
+ else if (Pagination.page > Pagination.size - Pagination.step * 2) {
|
|
|
+ Pagination.Add(Pagination.size - Pagination.step * 2 - 2, Pagination.size + 1);
|
|
|
+ }*/
|
|
|
+ else {
|
|
|
+ // Pagination.Add(Pagination.page - Pagination.step, Pagination.page + Pagination.step + 1);
|
|
|
+ }
|
|
|
+ Pagination.Next();
|
|
|
+ Pagination.Last();
|
|
|
+ Pagination.Finish();
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ // --------------------
|
|
|
+ // Initialization
|
|
|
+ // --------------------
|
|
|
+
|
|
|
+ // binding buttons
|
|
|
+ Buttons: function(e) {
|
|
|
+ var nav = e.getElementsByTagName('a');
|
|
|
+ },
|
|
|
+
|
|
|
+ // create skeleton
|
|
|
+ Create: function(e) {
|
|
|
+
|
|
|
+ var html = [
|
|
|
+ '<div></div>' // pagination container
|
|
|
+ ];
|
|
|
+
|
|
|
+ e.innerHTML = html.join('');
|
|
|
+ Pagination.e = e.getElementsByTagName('div')[0];
|
|
|
+ Pagination.Buttons(e);
|
|
|
+ },
|
|
|
+
|
|
|
+ // init
|
|
|
+ Init: function(e, data) {
|
|
|
+ Pagination.Extend(data);
|
|
|
+ Pagination.Create(e);
|
|
|
+ Pagination.Start();
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+function todo__fetchRaport(id) {
|
|
|
+ p5WFS_GetFeature('default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', {
|
|
|
+ primaryKey: id,
|
|
|
+ resolve: 'all',
|
|
|
+ resolveDepth: 3,
|
|
|
+ }).then(function (features) {
|
|
|
+ console.log('features', features)
|
|
|
+ }).catch(function (e) {
|
|
|
+ console.warn(e)
|
|
|
+ p5UI__notifyAjaxCallback({ type: 'error', msg: e })
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+$(document).ready(function(){
|
|
|
+ rootChangeForm();
|
|
|
+ detectChoiseFilter();
|
|
|
+});
|
|
|
+
|
|
|
+global.checkAll = checkAll;
|
|
|
+global.checkedChoiseItems = checkedChoiseItems;
|
|
|
+global.catchEventCheckbox = catchEventCheckbox;
|
|
|
+global.clearSelectedCheckbox = clearSelectedCheckbox;
|
|
|
+global.createGroupPracownicy = createGroupPracownicy;
|
|
|
+global.createGroupKontrahenci = createGroupKontrahenci;
|
|
|
+global.selectPage = selectPage;
|
|
|
+global.detectChoiseFilter = detectChoiseFilter;
|
|
|
+
|
|
|
+global.updateListIdBiAuditReaport = updateListIdBiAuditReaport;
|
|
|
+global.deleteListIdBiAuditReaport = deleteListIdBiAuditReaport;
|
|
|
+
|
|
|
+global.urlFetchPracownicy = urlFetchPracownicy;
|
|
|
+global.generateBiAuditRaport = generateBiAuditRaport;
|
|
|
+global.getAddressData = getAddressData;
|
|
|
+
|
|
|
+global.Pagination = Pagination;
|
|
|
+global.todo__fetchRaport = todo__fetchRaport;
|
|
|
+
|
|
|
+global.initLocalStorage = initLocalStorage;
|
|
|
+global.setItemLocalStorage = setItemLocalStorage;
|
|
|
+global.getItemLocalStorage = getItemLocalStorage;
|
|
|
+global.deleteItemLocalStorage = deleteItemLocalStorage;
|
|
|
+global.defaultBIAuditLocalStorage = defaultBIAuditLocalStorage;
|
|
|
+global.removeItemInArray = removeItemInArray;
|
|
|
+global.removeItemArrayInArray = removeItemArrayInArray;
|
|
|
+
|
|
|
+global.addPracownikToGroup = addPracownikToGroup;
|