Bocian.php.view.js 42 KB

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