Bocian.php.view.js 40 KB

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