Bocian.php.view.js 40 KB

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