Bocian.php.view.js 40 KB

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