Bocian.php.view.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  1. console.log('test1... DBG:', DBG)
  2. // localStorage.setItem('Bocian.pracownicyIds', JSON.stringify(ids))
  3. // var ids = localStorage.getItem('Bocian.pracownicyIds')
  4. // localStorage.removeItem('Bocian.pracownicyIds')
  5. // localStorage.removeItem('Bocian.kontrahenciIds')
  6. // localStorage.removeItem('Bocian.depth') // TODO: zapis na stronie głównej i BiAuditRaport
  7. if (!URL_FETCH_KONTRAHENCI_POWIAZANIA) {
  8. throw "Brak zmiennej URL_FETCH_KONTRAHENCI_POWIAZANIA"
  9. }
  10. $(window).on('hashchange', function() {
  11. initLocalStorage();
  12. rootChangeForm();
  13. });
  14. /* DATA FOR READ REAPORT */
  15. function urlFetchKontrahenciPowiazania() {
  16. // Documentation: https://github.com/github/fetch
  17. fetch(URL_FETCH_KONTRAHENCI_POWIAZANIA, {
  18. credentials: 'same-origin'
  19. })
  20. .then(function parseJSON(response) {
  21. return response.json()
  22. })
  23. .then(function(data) {
  24. var reaportItemsKontrahenciPowiazani = null;
  25. data.body.items.forEach (function(row) {
  26. reaportItemsKontrahenciPowiazani += '<tr><td><input type="checkbox" name="kontrID[]" value="'+row['ID']+'" /></td>'+
  27. '<td align="right">'+row["ID"]+'</td>';
  28. });
  29. $( "#body-reaport-kontrahenci-powiazani-tree" ).html(reaportItemsKontrahenciPowiazani);
  30. console.log('request succeeded with JSON response URL_FETCH_KONTRAHENCI_POWIAZANIA', data)
  31. }).catch(function(error) {
  32. console.log('request failed', error)
  33. });
  34. }
  35. /* FORM DATA FOR GENERATAE REAPORT */
  36. function loadCurrentDepthInInput(idInput) {
  37. var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  38. $(idInput).val(function() {
  39. return depthValue;
  40. });
  41. }
  42. function updateLocalStorageBiAuditDepth(idInput) {
  43. $(idInput).keyup(function() {
  44. delayUpdate(function(){
  45. var newValue = $(idInput).val();
  46. var responseValue = validateValueDepth(parseInt(newValue));
  47. setItemLocalStorage('Bocian.biAuditForm.depth', responseValue);
  48. loadCurrentDepthInInput('.smad-depth');
  49. }, 1000 );
  50. });
  51. }
  52. function validateValueDepth(newValue) {
  53. var value = null;
  54. value = newValue;
  55. if (parseInt(newValue) < 0) {
  56. value = 1;
  57. }
  58. if (parseInt(newValue) > 16) {
  59. value = 16;
  60. }
  61. return value;
  62. }
  63. var delayUpdate = (function() {
  64. var timer = 0;
  65. return function(callback, ms) {
  66. clearTimeout (timer);
  67. timer = setTimeout(callback, ms);
  68. };
  69. })();
  70. function initLocalStorage() {
  71. if (getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') === null) {
  72. setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', []);
  73. }
  74. if (getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') === null) {
  75. setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', []);
  76. }
  77. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', 0);
  78. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', 0);
  79. if (getItemLocalStorage('Bocian.biAuditForm.depth') === null) {
  80. updateLocalStorageBiAuditDepth(2);
  81. }
  82. }
  83. /**
  84. * Funkcja pozwala na wyświetlenie okienka importu
  85. */
  86. function showViewUploadFile( event, headerTitle, enumType ) {
  87. event.preventDefault();
  88. var enumType = enumType;
  89. swal({
  90. title: 'Importuj plik csv',
  91. input: 'file',
  92. inputAttributes: {
  93. 'accept': 'text/csv',
  94. 'aria-label': 'Upload csv file'
  95. },
  96. confirmButtonText: 'Importuj',
  97. preConfirm: function (file) {
  98. return new Promise(function (resolve, reject) {
  99. if (!file) {
  100. reject("Proszę wybrać plik csv");
  101. return
  102. }
  103. var formData = new FormData();
  104. formData.append('file', file);
  105. console.log('uploadowany plik: ',formData);
  106. var responseParseFile = parseCsvFile( formData, enumType );
  107. console.log('TODO: upload file', file)
  108. resolve('file imported')
  109. })
  110. },
  111. }).then(function (result) {
  112. console.log('result', result)
  113. }).catch(function (e) {
  114. console.log('catch: ', e)
  115. });
  116. }
  117. /**
  118. * Funkcja przekazuje dane z pliku csv do przeparsowania
  119. */
  120. function parseCsvFile( fileData, enumType ) {
  121. event.preventDefault();
  122. fetch(URL_FORM_DATA_CSV_FILE_AJAX, {
  123. method: 'POST',
  124. credentials: 'same-origin',
  125. body: fileData
  126. })
  127. .then(function(response) {
  128. return response.json()
  129. }).then(function(json) {
  130. console.log('parsed json', json)
  131. swal({
  132. title: 'Dane załadowane z pliku CSV',
  133. html: json.body.view,
  134. width: Math.round(window.innerWidth * 0.9),
  135. allowOutsideClick: false, // TODO: btn Anuluj na dole?
  136. showCloseButton: true,
  137. confirmButtonText: 'Zapisz',
  138. preConfirm: function (dataForm) {
  139. return new Promise(function (resolve, reject) {
  140. if (!dataForm) {
  141. reject("Formularz nie zawiera danych do zapisania");
  142. return
  143. }
  144. // zapisanie danych
  145. var responseSaveData = saveFormCsvFileAjaxAction(enumType);
  146. console.log('TODO: data save from form', dataForm)
  147. resolve('data save from form')
  148. })
  149. },
  150. }).then(function (result) {
  151. console.log('result', result)
  152. }).catch(function (e) {
  153. console.log('catch: ', e)
  154. });
  155. // return json;
  156. }).catch(function(ex) {
  157. console.log('parsing failed', ex)
  158. });
  159. }
  160. /**
  161. * Funkcja zapisuje dane z formularza do wgrania pliku csv
  162. */
  163. function saveFormCsvFileAjaxAction(enumType) {
  164. event.preventDefault();
  165. var formDataFrom = $("#formDataFromCsv").serialize();
  166. formDataFrom = formDataFrom.replace(/%5B/g,"[");
  167. formDataFrom = formDataFrom.replace(/%5D/g,"]");
  168. //var formDataFrom = $("#formDataFromCsv").serializeArray();
  169. console.log('dane z formularza formDataFrom ', formDataFrom );
  170. fetch(URL_SAVE_FORM_CSV_FILE_AJAX, {
  171. method: 'POST',
  172. credentials: 'same-origin',
  173. headers: {
  174. 'Content-Type': 'application/json'
  175. },
  176. body: JSON.stringify({
  177. formData: formDataFrom,
  178. enumType: enumType
  179. })
  180. })
  181. .then(function(response) {
  182. return response.json()
  183. }).then(function(json) {
  184. console.log('parsed json', json)
  185. if (result.type == 'success') {
  186. p5UI__notifyAjaxCallback(result);
  187. }
  188. // return json;
  189. }).catch(function(ex) {
  190. console.log('parsing failed', ex)
  191. });
  192. }
  193. function defaultBIAuditLocalStorage() {
  194. localStorage.removeItem('Bocian.biAuditForm.pracownicyIds');
  195. localStorage.removeItem('Bocian.biAuditForm.kontrahenciIds');
  196. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', 1);
  197. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', 1);
  198. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', 0);
  199. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', 0);
  200. setItemLocalStorage('Bocian.biAuditForm.depth', 2);
  201. }
  202. function generateBiAuditRaport(event) {
  203. event.preventDefault();
  204. var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  205. var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  206. var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  207. // validate
  208. if (!depthValue || depthValue === 0) {
  209. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie podano wartości dla głębokości powiązań' });
  210. } else if (!pracownicyIdsArray || pracownicyIdsArray.length === 0) {
  211. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano pracowników' });
  212. } else if (!kontrahenciIdsArray || kontrahenciIdsArray.length === 0) {
  213. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano kontrahentów' });
  214. } else {
  215. // send
  216. window.fetch(URL_GENERATE_BI_AUDIT_RAPORT_AJAX, {
  217. method: 'POST',
  218. headers: {
  219. 'Content-Type': 'application/json'
  220. },
  221. credentials: 'same-origin',
  222. body: JSON.stringify({
  223. pracownicyIds: pracownicyIdsArray,
  224. kontrahenciIds: kontrahenciIdsArray,
  225. depthValue: depthValue
  226. })
  227. })
  228. .then(function(response) {
  229. console.log('Firsst then', response);
  230. return response.text();
  231. })
  232. .then(function(responseText) {
  233. try {
  234. return JSON.parse(responseText);
  235. } catch (e) {
  236. throw responseText;
  237. }
  238. })
  239. .then(function(result) {
  240. if (result.type == 'success') {
  241. p5UI__notifyAjaxCallback(result);
  242. defaultBIAuditLocalStorage();
  243. window.setTimeout(window.location.href = "/SE/index.php?_route=ViewTableAjax&namespace=default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA", 4000);
  244. resolve(result.msg);
  245. } else {
  246. reject(result.msg);
  247. }
  248. })
  249. .catch(function(error) {
  250. console.log('request failed', error)
  251. });
  252. }
  253. }
  254. function addPracownikToGroup(event) {
  255. event.preventDefault();
  256. var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  257. if (pracownicyIdsArray === null) {
  258. showTextListIdPracownikow = 'ID pracowników: nie wybrano';
  259. } else {
  260. showTextListIdPracownikow = 'ID pracowników: ' + pracownicyIdsArray;
  261. }
  262. swal({
  263. title: 'Przenieś do grupy',
  264. input: 'select',
  265. text: showTextListIdPracownikow,
  266. inputOptions: getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups'),
  267. inputPlaceholder: 'Wybierz grupę',
  268. showCancelButton: true,
  269. confirmButtonText: 'Zapisz',
  270. showLoaderOnConfirm: true,
  271. preConfirm: function (idGroup) {
  272. return new Promise(function (resolve, reject) {
  273. console.log('value', idGroup);
  274. if ( !pracownicyIdsArray || pracownicyIdsArray === null || pracownicyIdsArray === 'undefined' ) {
  275. reject('Wybierz pracowników');
  276. } else if ( pracownicyIdsArray.length === 0 ) {
  277. reject('Wybierz pracowników');
  278. }
  279. if (!idGroup) reject('Proszę wybrać nazwę grupy');
  280. window.fetch(URL_ADD_PRACOWNICY_TO_GROUP, {
  281. method: 'POST',
  282. header: {
  283. 'contentType': 'applications/json'
  284. },
  285. credentials: 'same-origin',
  286. body: JSON.stringify({
  287. 'idGroup': idGroup,
  288. 'pracownicyIds': getItemLocalStorage('Bocian.biAuditForm.pracownicyIds'),
  289. })
  290. })
  291. .then(function(response) {
  292. return response.text();
  293. })
  294. .then(function(responseText) {
  295. try {
  296. return JSON.parse(responseText);
  297. } catch (e) {
  298. throw responseText;
  299. }
  300. })
  301. .then(function(result) {
  302. if (result.type == 'success') {
  303. p5UI__notifyAjaxCallback(result);
  304. resolve(result.msg);
  305. } else {
  306. reject(result.msg);
  307. }
  308. })
  309. .catch(function(error) {
  310. console.log('request failed', error)
  311. });
  312. })
  313. },
  314. allowOutsideClick: false
  315. }).then(function (groupPracownicyData) {
  316. //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
  317. });
  318. }
  319. function addKontrahenciToGroup(event) {
  320. event.preventDefault();
  321. var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  322. if (kontrahenciIdsArray === null) {
  323. showTextListIdKontrahentow = 'ID pracowników: nie wybrano';
  324. } else {
  325. showTextListIdKontrahentow = 'ID pracowników: ' + pracownicyIdsArray;
  326. }
  327. swal({
  328. title: 'Przenieś do grupy',
  329. input: 'select',
  330. text: showTextListIdKontrahentow,
  331. inputOptions: getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups'),
  332. inputPlaceholder: 'Wybierz grupę',
  333. showCancelButton: true,
  334. confirmButtonText: 'Zapisz',
  335. showLoaderOnConfirm: true,
  336. preConfirm: function (idGroup) {
  337. return new Promise(function (resolve, reject) {
  338. if (!idGroup) reject('Proszę wybrać nazwę grupy');
  339. if ( !kontrahenciIdsArray || kontrahenciIdsArray === null || kontrahenciIdsArray === 'undefined' ) {
  340. reject('Wybierz kontrahentów');
  341. } else if ( kontrahenciIdsArray.length === 0 ) {
  342. reject('Wybierz kontrahentów');
  343. }
  344. window.fetch(URL_ADD_KONTRAHENCI_TO_GROUP, {
  345. method: 'POST',
  346. header: {
  347. 'contentType': 'applications/json'
  348. },
  349. credentials: 'same-origin',
  350. body: JSON.stringify({
  351. 'idGroup': idGroup,
  352. 'kontrahenciIds': getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds'),
  353. })
  354. })
  355. .then(function(response) {
  356. return response.text();
  357. })
  358. .then(function(responseText) {
  359. try {
  360. return JSON.parse(responseText);
  361. } catch (e) {
  362. throw responseText;
  363. }
  364. })
  365. .then(function(result) {
  366. result
  367. if (result.type == 'success') {
  368. p5UI__notifyAjaxCallback(result);
  369. resolve(result.msg);
  370. } else {
  371. reject(result.msg);
  372. }
  373. })
  374. ;
  375. })
  376. },
  377. allowOutsideClick: false
  378. }).then(function (groupKontrahenciData) {
  379. //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
  380. });
  381. }
  382. function createGroupKontrahenci(event) {
  383. event.preventDefault();
  384. swal({
  385. title: 'Utwórz grupę',
  386. input: 'text',
  387. showCancelButton: true,
  388. confirmButtonText: 'Zapisz',
  389. showLoaderOnConfirm: true,
  390. preConfirm: function (NAZWA) {
  391. return new Promise(function (resolve, reject) {
  392. if (!NAZWA) reject('Proszę podać nazwę grupy');
  393. window.fetch(URL_CREATE_KONTRAHENCIS_GROUP, {
  394. method: 'POST',
  395. header: {
  396. 'contentType': 'applications/json'
  397. },
  398. credentials: 'same-origin',
  399. body: JSON.stringify({
  400. 'NAZWA': NAZWA
  401. })
  402. })
  403. .then(function(response) {
  404. return response.text();
  405. })
  406. .then(function(responseText) {
  407. try {
  408. return JSON.parse(responseText);
  409. } catch (e) {
  410. throw responseText;
  411. }
  412. })
  413. .then(function(result) {
  414. if (result.type == 'success') {
  415. p5UI__notifyAjaxCallback(result);
  416. resolve(result.body);
  417. } else {
  418. reject("Proszę podać inną nazwę grupy");
  419. }
  420. })
  421. .catch(function(error) {
  422. console.log('request failed', error)
  423. })
  424. })
  425. },
  426. allowOutsideClick: false
  427. }).then(function (groupKontrahenciData) {
  428. //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
  429. groupsKontrahenci = '<button class="btn btn-default" title="'+groupKontrahenciData['nazwa']+'" data-group-filter="'+groupKontrahenciData['id']+'">'+groupKontrahenciData['nazwa']+'</button>';
  430. $('#group-kontrahenci').append(groupsKontrahenci);
  431. });
  432. }
  433. function createGroupPracownicy(event) {
  434. event.preventDefault();
  435. swal({
  436. title: 'Utwórz grupę',
  437. input: 'text',
  438. showCancelButton: true,
  439. confirmButtonText: 'Zapisz',
  440. showLoaderOnConfirm: true,
  441. preConfirm: function (NAZWA) {
  442. return new Promise(function (resolve, reject) {
  443. if (!NAZWA) reject('Proszę podać nazwę grupy');
  444. window.fetch(URL_CREATE_PRACOWNICY_GROUP, {
  445. method: 'POST',
  446. header: {
  447. 'contentType': 'applications/json'
  448. },
  449. credentials: 'same-origin',
  450. body: JSON.stringify({
  451. 'NAZWA': NAZWA
  452. })
  453. })
  454. .then(function(response) {
  455. return response.text();
  456. })
  457. .then(function(responseText) {
  458. try {
  459. return JSON.parse(responseText);
  460. } catch (e) {
  461. throw responseText;
  462. }
  463. })
  464. .then(function(result) {
  465. if (result.type == 'success') {
  466. p5UI__notifyAjaxCallback(result);
  467. resolve(result.msg);
  468. } else {
  469. reject(result.msg);
  470. }
  471. });
  472. })
  473. },
  474. allowOutsideClick: false
  475. }).then(function (groupPracownicyData) {
  476. //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
  477. groupsPracownicy = '<button class="btn btn-default" title="'+groupPracownicyData['NAZWA']+'" data-group-filter="'+groupPracownicyData['ID']+'">'+groupPracownicyData['NAZWA']+'</button>';
  478. $('#group-pracownicy').append(groupsPracownicy);
  479. });
  480. }
  481. // fetch(URL_FETCH_TEST_KRS, {
  482. // credentials: 'same-origin'
  483. // })
  484. // .then(function parseJSON(response) {
  485. // return response.json()
  486. // })
  487. // .then(function(data) {
  488. // console.log('request succeeded with JSON response', data)
  489. // }).catch(function(error) {
  490. // console.log('request failed', error)
  491. // })
  492. //
  493. // fetch(URL_FETCH_TEST_CEIDG, {
  494. // credentials: 'same-origin'
  495. // })
  496. // .then(function parseJSON(response) {
  497. // return response.json()
  498. // })
  499. // .then(function(data) {
  500. // console.log('request succeeded with JSON response', data)
  501. // }).catch(function(error) {
  502. // console.log('request failed', error)
  503. // })
  504. function rootChangeForm() {
  505. //todo: do przeniesienia
  506. urlFetchKontrahenciPowiazania();
  507. var valueUrl = global.location.hash;
  508. console.log('URL', valueUrl);
  509. switch (valueUrl) {
  510. case '#KONTRAHENCI':
  511. $( ".container-bi_audit_form_kontrahenci_raport" ).html( VIEW_KONTRAHENCI );
  512. urlFetchKontrahenci(1);
  513. fetchGroupKontrahenci();
  514. $( ".container-bi_audit_form_pracownicy_raport" ).hide();
  515. $( ".container-bi_audit_form_kontrahenci_raport" ).show();
  516. break;
  517. case '#PRACOWNICY':
  518. $( ".container-bi_audit_form_pracownicy_raport" ).html( VIEW_PRACOWNICY );
  519. urlFetchPracownicy(1);
  520. fetchGroupPracownicy();
  521. $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
  522. $( ".container-bi_audit_form_pracownicy_raport" ).show();
  523. break;
  524. // case '#REAPORT':
  525. // $( ".container-bi_audit_form_raport_data" ).html( VIEW_TREE_REAPORT );
  526. // urlFetchKontrahenciPowiazania();
  527. // $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
  528. // $( ".container-bi_audit_form_pracownicy_raport" ).hide();
  529. // $( ".container-bi_audit_form_raport_data" ).show();
  530. // break;
  531. default:
  532. $( ".container-bi_audit_form_pracownicy_raport" ).html( VIEW_PRACOWNICY );
  533. urlFetchPracownicy(1);
  534. fetchGroupPracownicy();
  535. $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
  536. $( ".container-bi_audit_form_pracownicy_raport" ).show();
  537. break;
  538. }
  539. //aktualizacja inputa głebokości powiazan
  540. loadCurrentDepthInInput('.smad-depth');
  541. updateLocalStorageBiAuditDepth('.smad-depth');
  542. }
  543. function getAddressData(objectValue) {
  544. var objectValue = objectValue || [];
  545. var listData = '';
  546. if (!objectValue) {
  547. return true;
  548. }
  549. objectValue.forEach (function(item) {
  550. if (item['kodPocztowy']) { listData += '<div>kod pocztowy: ' + item['kodPocztowy'] + '<div>'; }
  551. if (item['miejscowosc']) { listData += '<div>miejscowość: ' + item['miejscowosc'] + '<div>'; }
  552. if (item['nrBudynku']) { listData += '<div>nr budynku: ' + item['nrBudynku'] + '<div>'; }
  553. if (item['nrLokalu']) { listData += '<div>nr lokalu: ' + item['nrLokalu'] + '<div>'; }
  554. if (item['typAdresu']) { listData += '<div>typ adresu: ' + item['typAdresu'] + '<div>'; }
  555. if (item['ulica']) { listData += '<div>ulica: ' + item['ulica'] + '<div>'; }
  556. listData += '<div>------<div>';
  557. });
  558. return listData;
  559. }
  560. function urlFetchKontrahenci(page) {
  561. var page = page || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page');
  562. selectPage('KONTRAHENCI', page);
  563. if ( page === 1) {
  564. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', 1);
  565. }
  566. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  567. fetch(URL_FETCH_KONTRAHENCI + '&page=' + page + '&filterIdGroup=' + filterIdGroup, {
  568. credentials: 'same-origin'
  569. })
  570. .then(function parseJSON(response) {
  571. return response.json()
  572. var filterIdGroup = filterIdGroup || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  573. })
  574. .then(function(data) {
  575. console.log('kkontrahenci data', data);
  576. var listItemsKontrahenci = null;
  577. data.body.items.forEach (function(row) {
  578. listItemsKontrahenci += '<tr><td><input type="checkbox" name="kontrID[]" value="'+row['ID']+'" /></td>'+
  579. '<td align="right">'+row["ID"]+'</td>'+
  580. '<td align="right">'+row["Nazwa_grupy_kapitalowej"]+'</td>'+
  581. '<td align="right">'+row["Pelna_nazwa_kontrahenta"]+'</td>'+
  582. '<td align="right">'+row["Numer_kontrahenta"]+'</td>'+
  583. '<td align="right">'+row["Skrocona_Nazwa_Kontrahenta"]+'</td>'+
  584. '<td align="right">'+row["Typ_kontrahenta"]+'</td>'+
  585. '<td align="right">'+row["NIP"]+'</td>'+
  586. '<td align="right">'+row["KRS"]+'</td>'+
  587. '<td align="right">'+row["REGON"]+'</td>'+
  588. '<td align="right">'+row["PESEL"]+'</td>'+
  589. '<td align="right">'+row["Forma_prawna_dzialalnosci"]+'</td>'+
  590. '<td align="right">'+row["Ulica"]+'</td>'+
  591. '<td align="right">'+row["Numer_budynku"]+'</td>'+
  592. '<td align="right">'+row["Numer_mieszkania_lokalu"]+'</td>'+
  593. '<td align="right">'+row["Miejscowosc"]+'</td>'+
  594. '<td align="right">'+row["Kod_pocztowy"]+'</td>'+
  595. '<td align="right">'+row["Kraj"]+'</td>'+
  596. '<td align="right">'+row["Telefon"]+'</td>'+
  597. '<td align="right">'+row["Fax"]+'</td>'+
  598. '<td align="right">'+row["Mail"]+'</td>'+
  599. '<td align="right">'+row["A_ADM_COMPANY"]+'</td>'+
  600. '<td align="right">'+row["A_CLASSIFIED"]+'</td>'+
  601. '<td align="right">'+row["A_STATUS"]+'</td>'+
  602. '<td align="right">'+row["A_STATUS_INFO"]+'</td>'+
  603. '<td align="right">'+row["Dodano"]+'</td>'+
  604. '<td align="right">'+row["L_APPOITMENT_USER"]+'</td>'+
  605. '<td align="right">'+row["Podmiot_dominujacy"]+'</td>'+
  606. '<td align="right">'+row["Tytul_dokumentu"]+'</td>'+
  607. '<td align="right">'+row["ownCompany"]+'</td>'+
  608. '<td align="right">'+row["uwagi"]+'</td></tr>';
  609. });
  610. if (data.body.pagination !== undefined) {
  611. Pagination.Init(document.getElementById('pagination-kontrahenci'), {
  612. url: '/SE/index.php?_route=UrlAction_Bocian#KONTRAHENCI',
  613. id_pagination: 'pagination-kontrahenci',
  614. type: 'KONTRAHENCI',
  615. total_items: data.body.pagination.total_items, // pages size
  616. size: data.body.pagination.size, // pages size
  617. page: page, // selected page
  618. step: 1 // pages before and after current
  619. });
  620. }
  621. $( "#body-kontrahenci" ).html(listItemsKontrahenci);
  622. checkAll('KONTRAHENCI');
  623. catchEventCheckbox('KONTRAHENCI');
  624. checkedChoiseItems('KONTRAHENCI', getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') );
  625. // $( ".container-bi_audit_raport" ).append( data.body.view );
  626. console.log('request succeeded with JSON responseKontrahenci', data)
  627. }).catch(function(error) {
  628. console.log('request failed', error)
  629. })
  630. }
  631. function urlFetchPracownicy(page) {
  632. var page = page || getItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page');
  633. if ( page === 1) {
  634. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', 1);
  635. }
  636. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
  637. selectPage('PRACOWNICY', page);
  638. fetch(URL_FETCH_PRACOWNICY + '&page=' + page + '&filterIdGroup=' + filterIdGroup, {
  639. credentials: 'same-origin'
  640. })
  641. .then(function parseJSON(response) {
  642. return response.json()
  643. })
  644. .then(function(data) {
  645. var addresPerson = '';
  646. var listItemsPracownik = null;
  647. console.log('urlFetchPracownicy', data.body.items);
  648. data.body.items.forEach (function(row) {
  649. if (row["default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy"]) {
  650. addresPerson = getAddressData(row["default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy"]);
  651. }
  652. listItemsPracownik += '<tr><td><input type="checkbox" name="prID[]" value="'+row['ID']+'" /></td>'+
  653. '<td align="right">'+row["ID"]+'</td>'+
  654. '<td align="right">'+row["imiona"]+'</td>'+
  655. '<td align="right">'+row["nazwisko"]+'</td>'+
  656. '<td align="right">'+row["nip"]+'</td>'+
  657. '<td align="right">'+row["pesel"]+'</td>'+
  658. '<td align="right">'+row["regon"]+'</td>'+
  659. '<td align="right">'+row["source"]+'</td>'+
  660. '<td align="right">'+row["A_ADM_COMPANY"]+'</td>'+
  661. '<td align="right">'+row["A_CLASSIFIED"]+'</td>'+
  662. '<td align="right">'+row["A_STATUS"]+'</td>'+
  663. '<td align="right">'+row["A_STATUS_INFO"]+'</td>'+
  664. '<td align="right">'+row["L_APPOITMENT_USER"]+'</td>'+
  665. '<td align="right">'+ addresPerson +'</td></tr>';
  666. });
  667. if (data.body.pagination.size) {
  668. Pagination.Init(document.getElementById('pagination-pracownicy'), {
  669. url: '/SE/index.php?_route=UrlAction_Bocian#PRACOWNICY',
  670. id_pagination: 'pagination-pracownicy',
  671. type: 'PRACOWNICY',
  672. total_items: data.body.pagination.total_items, // pages size
  673. size: data.body.pagination.size, // pages size
  674. page: data.body.pagination.current, // selected page
  675. step: 1 // pages before and after current
  676. });
  677. }
  678. $( "#body-pracownicy" ).html( listItemsPracownik);
  679. checkAll('PRACOWNICY');
  680. catchEventCheckbox('PRACOWNICY');
  681. checkedChoiseItems('PRACOWNICY', getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') );
  682. // $( ".container-bi_audit_raport" ).append( data.body.view );
  683. console.log('request succeeded with JSON responsePRACOWNICY', data)
  684. }).catch(function(error) {
  685. console.log('request failed', error)
  686. })
  687. }
  688. function selectPage(type, nrPage) {
  689. var type = type.toLowerCase();
  690. $('#pagination-' + type + ' ul li a').each(function(index, value){
  691. if (this.text === nrPage) {
  692. $(this).addClass('active');
  693. } else {
  694. $(this).removeClass('active');
  695. }
  696. });
  697. }
  698. function checkAll(type) {
  699. $('#checkAll-' + type).change(function() {
  700. var valueCheckbox = null;
  701. var checkboxes = $('form').find(':checkbox');
  702. if($(this).prop('checked')) {
  703. checkboxes.prop('checked', true);
  704. //valueCheckbox = checkboxes.prop("checked");
  705. var allValsChecked = [];
  706. var checkedValues = $('#smad-table-' + type + ' input:checkbox:checked').map(function() {
  707. if (this.value !== 'on') {
  708. allValsChecked.push(parseInt(this.value));
  709. }
  710. }).get();
  711. updateListIdBiAuditReaport(type, allValsChecked);
  712. } else {
  713. checkboxes.prop('checked', false);
  714. var allValsUnChecked = [];
  715. var checkedValues = $('#smad-table-' + type + ' input:checkbox:not(:checked)').map(function() {
  716. if (this.value !== 'on') {
  717. allValsUnChecked.push(parseInt(this.value));
  718. }
  719. }).get();
  720. deleteListIdBiAuditReaport(type, allValsUnChecked);
  721. }
  722. });
  723. }
  724. /**
  725. * Select again checkbox before selected item chekbox from storage (pracownicy/kontrahenci)
  726. */
  727. function checkedChoiseItems(type, store) {
  728. var idElement = 'smad-table-' + type;
  729. // if id element exist
  730. if (document.getElementById(idElement)) {
  731. // checked again if user selected Item (pracownicy/kontrahent)
  732. for (i = 0; i < store.length; i++) {
  733. $('#body-'+type.toLowerCase() +' input[type=checkbox] ').map(function(k, v) {
  734. if ( store[i] === parseInt(this.value) ){
  735. $(this).prop('checked', true);
  736. }
  737. }).get();
  738. }
  739. }
  740. //$('#checkAll-' + type).on('bind', function() {
  741. $('#smad-table-' + type + ' input[type=checkbox]').on( 'load', function() {
  742. var itemsCHecked = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  743. getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  744. if (itemsCHecked.lenght === 0 ) {
  745. return;
  746. }
  747. var valueCheckbox = null;
  748. var checkboxes = $('form').find(':checkbox');
  749. if($(this).prop('checked')) {
  750. checkboxes.prop('checked', true);
  751. var allValsChecked = [];
  752. var checkedValues = $('#smad-table-' + type + ' input:checkbox:checked').map(function() {
  753. if (this.value !== 'on') {
  754. allValsChecked.push(parseInt(this.value));
  755. }
  756. }).get();
  757. updateListIdBiAuditReaport(type, allValsChecked);
  758. } else {
  759. checkboxes.prop('checked', false);
  760. var allValsUnChecked = [];
  761. var checkedValues = $('#smad-table-' + type + ' input:checkbox:not(:checked)').map(function() {
  762. if (this.value !== 'on') {
  763. allValsUnChecked.push(parseInt(this.value));
  764. }
  765. }).get();
  766. deleteListIdBiAuditReaport(type, allValsUnChecked);
  767. }
  768. });
  769. }
  770. function catchEventCheckbox(type) {
  771. $('#smad-table-' + type + ' input[type="checkbox"]').on('change', function() {
  772. if($(this).is(":checked")) {
  773. var allValsChecked = [];
  774. if (this.value !== 'on') {
  775. allValsChecked.push(parseInt(this.value));
  776. }
  777. updateListIdBiAuditReaport(type, allValsChecked);
  778. } else {
  779. var allValsUnChecke = [];
  780. if (this.value !== 'on') {
  781. allValsUnChecke.push(parseInt(this.value));
  782. }
  783. deleteListIdBiAuditReaport(type, allValsUnChecke);
  784. }
  785. });
  786. }
  787. function clearSelectedCheckbox() {
  788. $('#checkAll-PRACOWNICY').prop('checked', false)
  789. $('#checkAll-KONTRAHENCI').prop('checked', false)
  790. }
  791. function updateListIdBiAuditReaport(type, valueArray) {
  792. var currentStoragePracownicyIds = [];
  793. var updateListPracownicyIds = null;
  794. var currentStorageKontrahenciIds = [];
  795. var updateListKontrahenciIds = null;
  796. if ( type == 'PRACOWNICY') {
  797. currentStoragePracownicyIds = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  798. if(currentStoragePracownicyIds !== null) {
  799. updateListPracownicyIds = [...new Set([...currentStoragePracownicyIds ,...valueArray])];
  800. }
  801. else {
  802. updateListPracownicyIds = valueArray;
  803. }
  804. setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', updateListPracownicyIds);
  805. }
  806. if ( type == 'KONTRAHENCI') {
  807. currentStorageKontrahenciIds = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  808. if(currentStorageKontrahenciIds !== null) {
  809. updateListKontrahenciIds = [...new Set([...currentStorageKontrahenciIds ,...valueArray])];
  810. }
  811. else {
  812. updateListKontrahenciIds = valueArray;
  813. }
  814. setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', updateListKontrahenciIds);
  815. }
  816. }
  817. function deleteListIdBiAuditReaport(type, valueArray) {
  818. var currentStoragePracownicyIds = [];
  819. var updateListPracownicyIds = null;
  820. if ( type == 'PRACOWNICY') {
  821. deleteItemLocalStorage('Bocian.biAuditForm.pracownicyIds', valueArray);
  822. }
  823. if ( type == 'KONTRAHENCI') {
  824. deleteItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', valueArray);
  825. }
  826. }
  827. // filter group detect
  828. function fetchGroupPracownicy() {
  829. fetch(URL_FETCH_GROUP_PRACOWNICY, {
  830. credentials: 'same-origin'
  831. })
  832. .then(function parseJSON(response) {
  833. return response.json()
  834. })
  835. .then(function(data) {
  836. setItemLocalStorage('Bocian.biAuditForm.pracownicy.groups', data.body.itmesGroupPracownicy);
  837. if (data.body.itmesGroupPracownicy === null) {
  838. return;
  839. }
  840. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
  841. var groupsPracownicy = '';
  842. var activeButton = '';
  843. data.body.itmesGroupPracownicy.forEach (function(row) {
  844. if ( filterIdGroup === row['ID'] ) { activeButton = 'active'; $('#group-pracownicy button.active').removeClass('active'); }
  845. groupsPracownicy += '<button class="btn btn-default '+activeButton+'" title="' + row['NAZWA'] + '" data-group-filter="' + row['ID'] + '">' + row['NAZWA'] + '</button>';
  846. });
  847. $("#group-pracownicy").append(groupsPracownicy);
  848. console.log('request succeeded with JSON fetchGroupPracownicy', data.body.itmesGroupPracownicy)
  849. }).catch(function(error) {
  850. console.log('request failed', error)
  851. });
  852. }
  853. function fetchGroupKontrahenci() {
  854. fetch(URL_FETCH_GROUP_KONTRAHENCI, {
  855. credentials: 'same-origin'
  856. })
  857. .then(function parseJSON(response) {
  858. return response.json()
  859. })
  860. .then(function(data) {
  861. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups', data.body.itemsGroupKontrahenci);
  862. if (data.body.itemsGroupKontrahenci === null) {
  863. return;
  864. }
  865. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  866. var groupsKontrahenci = '';
  867. var activeButton = '';
  868. data.body.itemsGroupKontrahenci.forEach (function(row) {
  869. if ( filterIdGroup === row['ID'] ) { activeButton = 'active'; $('#group-kontrahenci button.active').removeClass('active'); }
  870. groupsKontrahenci += '<button class="btn btn-default '+activeButton+'" title="'+row['NAZWA']+'" data-group-filter="'+row['ID']+'">'+row['NAZWA']+'</button>';
  871. });
  872. $("#group-kontrahenci").append(groupsKontrahenci);
  873. console.log('request succeeded with JSON fetchGroupKontrahenci', data.body.itemsGroupKontrahenci);
  874. }).catch(function(error) {
  875. console.log('request failed', error)
  876. });
  877. }
  878. function detectChoiseFilter() {
  879. $('#group-kontrahenci').on('click', 'button', function(evt) {
  880. $('#group-kontrahenci button.active').removeClass('active');
  881. $(this).addClass('active');
  882. // pobranie id grupy kliknietego buttonu
  883. var filterIdGroup = $(this).attr("data-group-filter");
  884. // ustawić id grupy do sesyjnej
  885. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', parseInt(filterIdGroup));
  886. // wywylac funckje pobrania danych
  887. urlFetchKontrahenci(1);
  888. });
  889. $('#group-pracownicy').on('click', 'button', function(evt) {
  890. $('#group-pracownicy button.active').removeClass('active');
  891. $(this).addClass('active');
  892. // pobranie id grupy kliknietego buttonu
  893. var filterIdGroup = $(this).attr("data-group-filter");
  894. // ustawić id grupy do sesyjnej
  895. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', parseInt(filterIdGroup));
  896. // wywylac funckje pobrania danych
  897. urlFetchPracownicy(1);
  898. });
  899. }
  900. // Local storage
  901. function setItemLocalStorage(key, array) {
  902. localStorage.setItem(key, JSON.stringify(array));
  903. }
  904. function getItemLocalStorage(key) {
  905. var retrievedData = localStorage.getItem(key);
  906. var response = JSON.parse(retrievedData);
  907. return response;
  908. }
  909. function deleteItemLocalStorage(key, itemsArray) {
  910. var currentStorageArray = getItemLocalStorage(key);
  911. var newStorageArray = removeItemArrayInArray(currentStorageArray, itemsArray);
  912. setItemLocalStorage(key, newStorageArray);
  913. }
  914. /**
  915. * arr - array
  916. * item - search item
  917. */
  918. function removeItemInArray(arr, item) {
  919. for(var i = arr.length; i--;) {
  920. if(arr[i] === item) {
  921. arr.splice(i, 1);
  922. }
  923. }
  924. return arr;
  925. }
  926. /**
  927. * arr - array
  928. * item - array list items
  929. */
  930. function removeItemArrayInArray(arr, itemsArray) {
  931. for(var i = arr.length; i--;) {
  932. for(var j = itemsArray.length; j--;) {
  933. if(arr[i] === itemsArray[j]) {
  934. arr.splice(i, 1);
  935. }
  936. }
  937. }
  938. return arr;
  939. }
  940. // Pagination
  941. var Pagination = {
  942. code: '', // end show html paginations
  943. clickPage: 1, // set default 1 page
  944. // --------------------
  945. // Utility
  946. // --------------------
  947. // initialize default data
  948. Extend: function(data) {
  949. data = data || {};
  950. Pagination.url = data.url;
  951. Pagination.id_pagination = data.id_pagination;
  952. Pagination.type = data.type;
  953. Pagination.total_items = data.total_items;
  954. Pagination.size = data.size || 2;
  955. Pagination.page = data.page || 1;
  956. Pagination.step = data.step || 3;
  957. },
  958. // add pages by number (from [s] to [f])
  959. Add: function(s, f) {
  960. for (var i = s; i < f; i++) {
  961. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">' + i + '</a></li>';
  962. }
  963. },
  964. // add last page with separator
  965. Last: function() {
  966. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">>></a></li>';
  967. },
  968. // add first page with separator
  969. First: function() {
  970. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default"><<</a></li>';
  971. },
  972. // add last page with separator
  973. Next: function() {
  974. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">></a></li>';
  975. },
  976. // add first page with separator
  977. Prev: function() {
  978. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default"><</a></li>';
  979. },
  980. // --------------------
  981. // Handlers
  982. // --------------------
  983. // change page
  984. Click: function() {
  985. clearSelectedCheckbox();
  986. var selectPage = $("#pagination-"+Pagination.type.toLowerCase()+' .tblAjax__footer__toolbar__pagination').find('a.active').text();
  987. Pagination.clickPage = +this.innerHTML || '';
  988. if ( selectPage === NaN || selectPage > Pagination.size) { selectPage = 1; }
  989. switch (this.innerHTML) {
  990. case '&gt;&gt;': // last
  991. Pagination.clickPage = Pagination.size;
  992. break;
  993. case '&lt;&lt;': // first
  994. Pagination.clickPage = 1;
  995. break;
  996. case '&lt;': // prev
  997. Pagination.clickPage = parseInt(selectPage) - 1;
  998. if (Pagination.clickPage < 1) {
  999. Pagination.clickPage = 1;
  1000. }
  1001. break;
  1002. case '&gt;': // next
  1003. Pagination.clickPage = parseInt(selectPage) + 1;
  1004. if (Pagination.clickPage > Pagination.size) {
  1005. Pagination.clickPage = Pagination.size;
  1006. }
  1007. break;
  1008. }
  1009. if ( Pagination.type === 'KONTRAHENCI' ) {
  1010. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', Pagination.clickPage);
  1011. Pagination.page = urlFetchKontrahenci(Pagination.clickPage);
  1012. }
  1013. else if ( Pagination.type === 'PRACOWNICY' ){
  1014. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', Pagination.clickPage);
  1015. Pagination.page = urlFetchPracownicy(Pagination.clickPage);
  1016. }
  1017. Pagination.Start();
  1018. },
  1019. // --------------------
  1020. // Script structure pagination
  1021. // --------------------
  1022. // binding pages
  1023. Bind: function() {
  1024. var a = Pagination.e.getElementsByTagName('a');
  1025. var currentPage = Pagination.clickPage || 1;
  1026. for (var i = 0; i < a.length; i++) {
  1027. if (+a[i].innerHTML === Pagination.page) a[i].className = 'btn btn-default active';
  1028. a[i].addEventListener('click', Pagination.Click, false);
  1029. }
  1030. },
  1031. // write pagination
  1032. Finish: function() {
  1033. Pagination.e.innerHTML = Pagination.code;
  1034. Pagination.code = '</ul></nav>';
  1035. Pagination.Bind();
  1036. },
  1037. // find pagination type
  1038. Start: function() {
  1039. 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>';
  1040. Pagination.code += '<nav aria-label="Page navigation" class="footer_pagination_menu_items"><ul class="btn-group tblAjax__footer__toolbar__pagination smad-pagination">';
  1041. Pagination.First();
  1042. Pagination.Prev();
  1043. if ( Pagination.type === 'KONTRAHENCI' ) {
  1044. Pagination.page = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page') || 1;
  1045. }
  1046. else if ( Pagination.type === 'PRACOWNICY' ){
  1047. Pagination.page = getItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page') || 1;
  1048. }
  1049. if ( Pagination.page > Pagination.size ) {
  1050. Pagination.page = 1;
  1051. }
  1052. if (Pagination.size < Pagination.step * 2 + 6) {
  1053. Pagination.Add(1, Pagination.size + 1);
  1054. }
  1055. /*else if (Pagination.page < Pagination.step * 2 + 1) {
  1056. Pagination.Add(1, Pagination.step * 2 + 4);
  1057. }
  1058. else if (Pagination.page > Pagination.size - Pagination.step * 2) {
  1059. Pagination.Add(Pagination.size - Pagination.step * 2 - 2, Pagination.size + 1);
  1060. }*/
  1061. else {
  1062. // Pagination.Add(Pagination.page - Pagination.step, Pagination.page + Pagination.step + 1);
  1063. }
  1064. Pagination.Next();
  1065. Pagination.Last();
  1066. Pagination.Finish();
  1067. },
  1068. // --------------------
  1069. // Initialization
  1070. // --------------------
  1071. // binding buttons
  1072. Buttons: function(e) {
  1073. var nav = e.getElementsByTagName('a');
  1074. },
  1075. // create skeleton
  1076. Create: function(e) {
  1077. var html = [
  1078. '<div></div>' // pagination container
  1079. ];
  1080. e.innerHTML = html.join('');
  1081. Pagination.e = e.getElementsByTagName('div')[0];
  1082. Pagination.Buttons(e);
  1083. },
  1084. // init
  1085. Init: function(e, data) {
  1086. Pagination.Extend(data);
  1087. Pagination.Create(e);
  1088. Pagination.Start();
  1089. }
  1090. };
  1091. function todo__fetchRaport(id) {
  1092. p5WFS_GetFeature('default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', {
  1093. primaryKey: id,
  1094. resolve: 'all',
  1095. resolveDepth: 3,
  1096. }).then(function (features) {
  1097. console.log('features', features)
  1098. }).catch(function (e) {
  1099. console.warn(e)
  1100. p5UI__notifyAjaxCallback({ type: 'error', msg: e })
  1101. })
  1102. }
  1103. $(document).ready(function(){
  1104. rootChangeForm();
  1105. detectChoiseFilter();
  1106. });
  1107. global.checkAll = checkAll;
  1108. global.checkedChoiseItems = checkedChoiseItems;
  1109. global.catchEventCheckbox = catchEventCheckbox;
  1110. global.clearSelectedCheckbox = clearSelectedCheckbox;
  1111. global.createGroupPracownicy = createGroupPracownicy;
  1112. global.createGroupKontrahenci = createGroupKontrahenci;
  1113. global.selectPage = selectPage;
  1114. global.detectChoiseFilter = detectChoiseFilter;
  1115. global.updateListIdBiAuditReaport = updateListIdBiAuditReaport;
  1116. global.deleteListIdBiAuditReaport = deleteListIdBiAuditReaport;
  1117. global.urlFetchPracownicy = urlFetchPracownicy;
  1118. global.generateBiAuditRaport = generateBiAuditRaport;
  1119. global.getAddressData = getAddressData;
  1120. global.Pagination = Pagination;
  1121. global.todo__fetchRaport = todo__fetchRaport;
  1122. global.initLocalStorage = initLocalStorage;
  1123. global.setItemLocalStorage = setItemLocalStorage;
  1124. global.getItemLocalStorage = getItemLocalStorage;
  1125. global.deleteItemLocalStorage = deleteItemLocalStorage;
  1126. global.defaultBIAuditLocalStorage = defaultBIAuditLocalStorage;
  1127. global.removeItemInArray = removeItemInArray;
  1128. global.removeItemArrayInArray = removeItemArrayInArray;
  1129. global.addPracownikToGroup = addPracownikToGroup;
  1130. global.showViewUploadFile = showViewUploadFile;
  1131. global.parseCsvFile = parseCsvFile;