Bocian.php.view.js 40 KB

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