Bocian.php.view.js 40 KB

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