Bocian.php.view.js 42 KB

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