Bocian.php.view.js 41 KB

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