Bocian.php.view.js 42 KB

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