Bocian.php.view.js 44 KB

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