Bocian.php.view.js 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050
  1. if (!URL_TABLE_POWIAZANIA) throw "Brak URL_TABLE_POWIAZANIA";
  2. if (!BASE_URLS) throw "Brak BASE_URLS"
  3. var RECORD_MORE_FUNCTIONS_OPENED_NODE = null;
  4. if (!FIELD_LIST_PRACOWNICY) throw "Brak FIELD_LIST_PRACOWNICY"
  5. if (!FIELD_LIST_KONTRAHENCI) throw "Brak FIELD_LIST_KONTRAHENCI"
  6. $(window).on('hashchange', function() {
  7. initLocalStorage();
  8. rootChangeForm();
  9. updateTopCounters();
  10. hideMoreRecordFunctionsPopover()
  11. });
  12. /* DATA FOR READ REAPORT */
  13. function urlFetchKontrahenciPowiazania() {
  14. // Documentation: https://github.com/github/fetch
  15. fetch(URL_FETCH_KONTRAHENCI_POWIAZANIA, {
  16. credentials: 'same-origin'
  17. })
  18. .then(function parseJSON(response) {
  19. return response.json()
  20. })
  21. .then(function(data) {
  22. var reaportItemsKontrahenciPowiazani = null;
  23. data.body.items.forEach (function(row) {
  24. reaportItemsKontrahenciPowiazani += '<tr><td><input type="checkbox" name="kontrID[]" value="'+row['ID']+'" /></td>'+
  25. '<td align="right">'+row["ID"]+'</td>';
  26. });
  27. $( "#body-reaport-kontrahenci-powiazani-tree" ).html(reaportItemsKontrahenciPowiazani);
  28. }).catch(function(error) {
  29. console.log('request failed', error)
  30. });
  31. }
  32. /* FORM DATA FOR GENERATAE REAPORT */
  33. function loadCurrentDepthInInput(idInput) {
  34. var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  35. $(idInput).val(function() {
  36. return depthValue;
  37. });
  38. }
  39. function updateLocalStorageBiAuditDepth(idInput) {
  40. $(idInput).keyup(function() {
  41. delayUpdate(function(){
  42. var newValue = $(idInput).val();
  43. var responseValue = validateValueDepth(parseInt(newValue));
  44. setItemLocalStorage('Bocian.biAuditForm.depth', responseValue);
  45. loadCurrentDepthInInput('.smad-depth');
  46. loadCurrentDepthInInput('.smad-depth-kontrahenci');
  47. }, 1000 );
  48. });
  49. }
  50. function validateValueDepth(newValue) {
  51. var value = null;
  52. value = newValue;
  53. if (parseInt(newValue) < 0) {
  54. value = 1;
  55. }
  56. if (parseInt(newValue) > 16) {
  57. value = 16;
  58. }
  59. return value;
  60. }
  61. var delayUpdate = (function() {
  62. var timer = 0;
  63. return function(callback, ms) {
  64. clearTimeout (timer);
  65. timer = setTimeout(callback, ms);
  66. };
  67. })();
  68. function initLocalStorage() {
  69. if (getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') === null) {
  70. setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', []);
  71. }
  72. if (getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') === null) {
  73. setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', []);
  74. }
  75. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', 0);
  76. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', 0);
  77. if (getItemLocalStorage('Bocian.biAuditForm.depth') === null) {
  78. updateLocalStorageBiAuditDepth(7);
  79. }
  80. }
  81. /**
  82. * Funkcja pozwala na wyświetlenie okienka importu
  83. */
  84. function showViewUploadFile( event, headerTitle, enumType, showCheckbox, csvFileExample ) {
  85. event.preventDefault();
  86. var enumType = enumType;
  87. if( csvFileExample !== undefined) { // przykład + instrukcja do pobrania
  88. csvFileExample = '<div><a href="'+csvFileExample+'" title="Pobierz przykład" download target="_balnk">Pobierz przykład</a></div>';
  89. }
  90. swal({
  91. title: 'Importuj plik csv',
  92. input: 'file',
  93. html: csvFileExample,
  94. inputAttributes: {
  95. 'accept': 'text/csv',
  96. 'aria-label': 'Upload csv file'
  97. },
  98. confirmButtonText: 'Importuj',
  99. preConfirm: function (file) {
  100. return new Promise(function (resolve, reject) {
  101. if (!file) {
  102. reject("Proszę wybrać plik csv");
  103. return
  104. }
  105. var input = document.querySelector('input[type="file"]');
  106. var data = new FormData()
  107. data.append('file', input.files[0])
  108. data.append('showCheckbox', showCheckbox);
  109. var responseParseFile = parseCsvFile( data, enumType );
  110. resolve('file imported')
  111. })
  112. },
  113. }).then(function (result) {
  114. console.log('result', result)
  115. }).catch(function (e) {
  116. console.log('catch: ', e)
  117. });
  118. }
  119. /**
  120. * Funkcja przekazuje dane z pliku csv do przeparsowania
  121. */
  122. function parseCsvFile( fileData, enumType ) {
  123. event.preventDefault();
  124. console.log( 'parseCsvFile fileData', fileData);
  125. fetch(URL_FORM_DATA_CSV_FILE_AJAX, {
  126. method: 'POST',
  127. credentials: 'same-origin',
  128. body: fileData
  129. })
  130. .then(function(response) {
  131. return response.json()
  132. }).then(function(json) {
  133. swal({
  134. title: 'Dane załadowane z pliku CSV',
  135. html: json.body.view,
  136. width: Math.round(window.innerWidth * 0.9),
  137. allowOutsideClick: false, // TODO: btn Anuluj na dole?
  138. showCloseButton: true,
  139. confirmButtonText: 'Zapisz',
  140. preConfirm: function (dataForm) {
  141. return new Promise(function (resolve, reject) {
  142. if (!dataForm) {
  143. reject("Formularz nie zawiera danych do zapisania");
  144. return
  145. }
  146. // zapisanie danych
  147. var responseSaveData = saveFormCsvFileAjaxAction(enumType);
  148. resolve('data save from form')
  149. })
  150. },
  151. }).then(function (result) {
  152. console.log('result', result)
  153. }).catch(function (e) {
  154. console.log('catch: ', e)
  155. });
  156. }).catch(function(ex) {
  157. console.log('parsing failed', ex)
  158. });
  159. }
  160. /**
  161. * Funkcja zapisuje dane z formularza do wgrania pliku csv
  162. */
  163. function saveFormCsvFileAjaxAction(enumType) {
  164. event.preventDefault();
  165. var formDataFrom = $("#formDataFromCsv").serialize();
  166. formDataFrom = formDataFrom.replace(/%5B/g,"[");
  167. formDataFrom = formDataFrom.replace(/%5D/g,"]");
  168. //var formDataFrom = $("#formDataFromCsv").serializeArray();
  169. console.log('dane z formularza formDataFrom ', formDataFrom );
  170. fetch(URL_SAVE_FORM_CSV_FILE_AJAX, {
  171. method: 'POST',
  172. credentials: 'same-origin',
  173. headers: {
  174. 'Content-Type': 'application/json'
  175. },
  176. body: JSON.stringify({
  177. formData: formDataFrom,
  178. enumType: enumType
  179. })
  180. })
  181. .then(function(response) {
  182. return response.json()
  183. }).then(function(json) {
  184. console.log('parsed json', json)
  185. if (response.type == 'success') {
  186. p5UI__notifyAjaxCallback(response.msg);
  187. }
  188. // return json;
  189. }).catch(function(ex) {
  190. console.log('parsing failed', ex)
  191. });
  192. }
  193. function defaultBIAuditLocalStorage() {
  194. localStorage.removeItem('Bocian.biAuditForm.pracownicyIds');
  195. localStorage.removeItem('Bocian.biAuditForm.kontrahenciIds');
  196. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', 1);
  197. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', 1);
  198. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', 0);
  199. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', 0);
  200. setItemLocalStorage('Bocian.biAuditForm.depth', 7);
  201. }
  202. function generateBiAuditRaport(event) {
  203. event.preventDefault();
  204. var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  205. var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  206. var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  207. // validate
  208. if (!depthValue || depthValue === 0) {
  209. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie podano wartości dla głębokości powiązań' });
  210. } else if (!pracownicyIdsArray || pracownicyIdsArray.length === 0) {
  211. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano pracowników' });
  212. } else if (!kontrahenciIdsArray || kontrahenciIdsArray.length === 0) {
  213. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano kontrahentów' });
  214. } else {
  215. // send
  216. window.fetch(URL_GENERATE_BI_AUDIT_RAPORT_AJAX, {
  217. method: 'POST',
  218. headers: {
  219. 'Content-Type': 'application/json'
  220. },
  221. credentials: 'same-origin',
  222. body: JSON.stringify({
  223. pracownicyIds: pracownicyIdsArray,
  224. kontrahenciIds: kontrahenciIdsArray,
  225. depthValue: depthValue
  226. })
  227. })
  228. .then(function(response) {
  229. console.log('Firsst then', response);
  230. return response.text();
  231. })
  232. .then(function(responseText) {
  233. try {
  234. return JSON.parse(responseText);
  235. } catch (e) {
  236. throw responseText;
  237. }
  238. })
  239. .then(function(result) {
  240. if (result.type == 'success') {
  241. p5UI__notifyAjaxCallback(result);
  242. defaultBIAuditLocalStorage();
  243. window.setTimeout(URL_TABLE_POWIAZANIA, 6000);
  244. resolve(result.msg);
  245. } else {
  246. reject(result.msg);
  247. }
  248. })
  249. .catch(function(error) {
  250. console.log('request failed', error)
  251. });
  252. }
  253. }
  254. /**
  255. * Popup z opcja przeniesienia pracowników do innej grupy
  256. */
  257. function addPracownikToGroup(event) {
  258. event.preventDefault();
  259. var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  260. if (pracownicyIdsArray === null || !pracownicyIdsArray || !pracownicyIdsArray.length) {
  261. showTextListIdPracownikow = 'nie wybrano pracowników';
  262. } else {
  263. showTextListIdPracownikow = '' + pracownicyIdsArray.length + ' pracowników';
  264. }
  265. var arrayGroupOptions = [];
  266. var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups');
  267. // utworzenie tablicy Optionsów grupy
  268. listGroupStorage.map(function(item) {
  269. if (item.ID !== undefined) {
  270. arrayGroupOptions[item.ID] = item.NAZWA;
  271. }
  272. });
  273. swal({
  274. title: 'Dodaj do grupy',
  275. input: 'select',
  276. text: showTextListIdPracownikow,
  277. inputOptions: arrayGroupOptions,
  278. inputPlaceholder: 'Wybierz grupę',
  279. showCancelButton: true,
  280. confirmButtonText: 'Zapisz',
  281. showLoaderOnConfirm: true,
  282. preConfirm: function (idGroup) {
  283. return new Promise(function (resolve, reject) {
  284. console.log('idGrupy value', idGroup);
  285. if ( !pracownicyIdsArray || pracownicyIdsArray === null || pracownicyIdsArray === 'undefined' ) {
  286. reject('Wybierz pracowników');
  287. } else if ( pracownicyIdsArray.length === 0 ) {
  288. reject('Wybierz pracowników');
  289. }
  290. if (!idGroup) reject('Proszę wybrać nazwę grupy');
  291. window.fetch(URL_ADD_PRACOWNICY_TO_GROUP, {
  292. method: 'POST',
  293. header: {
  294. 'contentType': 'applications/json'
  295. },
  296. credentials: 'same-origin',
  297. body: JSON.stringify({
  298. 'idGroup': idGroup,
  299. 'pracownicyIds': getItemLocalStorage('Bocian.biAuditForm.pracownicyIds'),
  300. })
  301. })
  302. .then(function(response) {
  303. return response.text();
  304. })
  305. .then(function(responseText) {
  306. try {
  307. return JSON.parse(responseText);
  308. } catch (e) {
  309. throw responseText;
  310. }
  311. })
  312. .then(function(result) {
  313. if (result.type == 'success') {
  314. p5UI__notifyAjaxCallback(result);
  315. resolve(result.msg);
  316. } else {
  317. reject(result.msg);
  318. }
  319. })
  320. .catch(function(error) {
  321. console.log('request failed', error)
  322. });
  323. })
  324. },
  325. allowOutsideClick: false
  326. }).then(function (groupPracownicyData) {
  327. //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
  328. });
  329. }
  330. function addPracownikAllToGroup(event) {
  331. event.preventDefault();
  332. var showTextListIdPracownikow = 'wszystkich pracowników pasujących do kryteriów wyszukiwania';
  333. var arrayGroupOptions = [];
  334. var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups');
  335. // utworzenie tablicy Optionsów grupy
  336. listGroupStorage.map(function(item) {
  337. if (item.ID !== undefined) {
  338. arrayGroupOptions[item.ID] = item.NAZWA;
  339. }
  340. });
  341. swal({
  342. title: 'Dodaj do grupy',
  343. input: 'select',
  344. text: showTextListIdPracownikow,
  345. inputOptions: arrayGroupOptions,
  346. inputPlaceholder: 'Wybierz grupę',
  347. showCancelButton: true,
  348. confirmButtonText: 'Zapisz',
  349. showLoaderOnConfirm: true,
  350. preConfirm: function (idGroup) {
  351. return new Promise(function (resolve, reject) {
  352. if (!idGroup) {
  353. reject('Proszę wybrać nazwę grupy');
  354. return;
  355. }
  356. var filterFields = {}
  357. var frm = document.getElementById('filtersFieldRemoveBtn-PRACOWNICY').form
  358. var fieldNameList = FIELD_LIST_PRACOWNICY
  359. fieldNameList.filter(function (fieldName) {
  360. if (!frm[fieldName]) console.log('Err missing field: "'+fieldName+'"')
  361. return (frm[fieldName]) ? true : false
  362. }).map(function (fieldName) {
  363. return [ fieldName, frm[fieldName].value ]
  364. }).filter(function (filter) {
  365. return ( filter[1].length > 0 )
  366. }).map(function (filter) {
  367. filterFields[ filter[0] ] = filter[1]
  368. })
  369. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
  370. if (filterIdGroup) filterFields[ 'filterIdGroup' ] = filterIdGroup
  371. window.fetch(URL_ADD_PRACOWNICY_TO_GROUP, {
  372. method: 'POST',
  373. header: {
  374. 'contentType': 'applications/json'
  375. },
  376. credentials: 'same-origin',
  377. body: JSON.stringify({
  378. 'idGroup': idGroup,
  379. 'type': 'filter',
  380. 'filter': filterFields,
  381. })
  382. })
  383. .then(function(response) {
  384. return response.text();
  385. })
  386. .then(function(responseText) {
  387. try {
  388. return JSON.parse(responseText);
  389. } catch (e) {
  390. throw responseText;
  391. }
  392. })
  393. .then(function(result) {
  394. if (result.type == 'success') {
  395. p5UI__notifyAjaxCallback(result);
  396. resolve(result.msg);
  397. } else {
  398. reject(result.msg);
  399. }
  400. })
  401. .catch(function(error) {
  402. console.log('request failed', error)
  403. });
  404. })
  405. },
  406. allowOutsideClick: false
  407. }).then(function (groupPracownicyData) {
  408. //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
  409. });
  410. }
  411. /**
  412. * Popup z opcja przeniesienia kontrahentów do innej grupy
  413. */
  414. function addKontrahenciToGroup(event) {
  415. event.preventDefault();
  416. var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  417. if (kontrahenciIdsArray === null || !kontrahenciIdsArray || !kontrahenciIdsArray.length) {
  418. showTextListIdKontrahentow = 'nie wybrano kontrahentów';
  419. } else {
  420. showTextListIdKontrahentow = '' + kontrahenciIdsArray.length + ' kontrahentów';
  421. }
  422. var arrayGroupOptions = [];
  423. var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups');
  424. // utworzenie tablicy Optionsów grupy
  425. listGroupStorage.map(function(item) {
  426. if (item.ID !== undefined) {
  427. arrayGroupOptions[item.ID] = item.NAZWA;
  428. }
  429. });
  430. swal({
  431. title: 'Dodaj do grupy',
  432. input: 'select',
  433. text: showTextListIdKontrahentow,
  434. inputOptions: arrayGroupOptions,
  435. inputPlaceholder: 'Wybierz grupę',
  436. showCancelButton: true,
  437. confirmButtonText: 'Zapisz',
  438. showLoaderOnConfirm: true,
  439. preConfirm: function (idGroup) {
  440. return new Promise(function (resolve, reject) {
  441. if (!idGroup) {
  442. reject('Proszę wybrać nazwę grupy');
  443. return;
  444. }
  445. if (!kontrahenciIdsArray || !kontrahenciIdsArray.length) {
  446. reject('Wybierz kontrahentów');
  447. return;
  448. }
  449. window.fetch(URL_ADD_KONTRAHENCI_TO_GROUP, {
  450. method: 'POST',
  451. header: {
  452. 'contentType': 'applications/json'
  453. },
  454. credentials: 'same-origin',
  455. body: JSON.stringify({
  456. 'idGroup': idGroup,
  457. 'kontrahenciIds': getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds'),
  458. })
  459. })
  460. .then(function(response) {
  461. return response.text();
  462. })
  463. .then(function(responseText) {
  464. try {
  465. return JSON.parse(responseText);
  466. } catch (e) {
  467. throw responseText;
  468. }
  469. })
  470. .then(function(result) {
  471. result
  472. if (result.type == 'success') {
  473. p5UI__notifyAjaxCallback(result);
  474. resolve(result.msg);
  475. } else {
  476. reject(result.msg);
  477. }
  478. })
  479. ;
  480. })
  481. },
  482. allowOutsideClick: false
  483. }).then(function (groupKontrahenciData) {
  484. //TODO: PIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
  485. });
  486. }
  487. function addKontrahenciAllToGroup(event) {
  488. event.preventDefault();
  489. var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  490. var showTextListIdKontrahentow = 'wszystkich kontrahentów pasujących do kryteriów wyszukiwania';
  491. var arrayGroupOptions = [];
  492. var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups');
  493. // utworzenie tablicy Optionsów grupy
  494. listGroupStorage.map(function(item) {
  495. if (item.ID !== undefined) {
  496. arrayGroupOptions[item.ID] = item.NAZWA;
  497. }
  498. });
  499. swal({
  500. title: 'Dodaj do grupy',
  501. input: 'select',
  502. text: showTextListIdKontrahentow,
  503. inputOptions: arrayGroupOptions,
  504. inputPlaceholder: 'Wybierz grupę',
  505. showCancelButton: true,
  506. confirmButtonText: 'Zapisz',
  507. showLoaderOnConfirm: true,
  508. preConfirm: function (idGroup) {
  509. return new Promise(function (resolve, reject) {
  510. if (!idGroup) {
  511. reject('Proszę wybrać nazwę grupy');
  512. return;
  513. }
  514. var filterFields = {}
  515. var frm = document.getElementById('filtersFieldRemoveBtn-KONTRAHENCI').form
  516. var fieldNameList = FIELD_LIST_KONTRAHENCI
  517. fieldNameList.filter(function (fieldName) {
  518. if (!frm[fieldName]) console.log('Err missing field: "'+fieldName+'"')
  519. return (frm[fieldName]) ? true : false
  520. }).map(function (fieldName) {
  521. return [ fieldName, frm[fieldName].value ]
  522. }).filter(function (filter) {
  523. return ( filter[1].length > 0 )
  524. }).map(function (filter) {
  525. filterFields[ filter[0] ] = filter[1]
  526. })
  527. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  528. if (filterIdGroup) filterFields[ 'filterIdGroup' ] = filterIdGroup
  529. window.fetch(URL_ADD_KONTRAHENCI_TO_GROUP, {
  530. method: 'POST',
  531. header: {
  532. 'contentType': 'applications/json'
  533. },
  534. credentials: 'same-origin',
  535. body: JSON.stringify({
  536. 'idGroup': idGroup,
  537. 'type': 'filter',
  538. 'filter': filterFields,
  539. })
  540. })
  541. .then(function(response) {
  542. return response.text();
  543. })
  544. .then(function(responseText) {
  545. try {
  546. return JSON.parse(responseText);
  547. } catch (e) {
  548. throw responseText;
  549. }
  550. })
  551. .then(function(result) {
  552. if (result.type == 'success') {
  553. p5UI__notifyAjaxCallback(result);
  554. resolve(result.msg);
  555. } else {
  556. reject(result.msg);
  557. }
  558. })
  559. .catch(function(error) {
  560. console.log('request failed', error)
  561. });
  562. })
  563. },
  564. allowOutsideClick: false
  565. });
  566. }
  567. function createGroupKontrahenci(event) {
  568. event.preventDefault();
  569. swal({
  570. title: 'Utwórz grupę',
  571. input: 'text',
  572. showCancelButton: true,
  573. confirmButtonText: 'Zapisz',
  574. showLoaderOnConfirm: true,
  575. preConfirm: function (NAZWA) {
  576. return new Promise(function (resolve, reject) {
  577. if (!NAZWA) reject('Proszę podać nazwę grupy');
  578. window.fetch(URL_CREATE_KONTRAHENCIS_GROUP, {
  579. method: 'POST',
  580. header: {
  581. 'contentType': 'applications/json'
  582. },
  583. credentials: 'same-origin',
  584. body: JSON.stringify({
  585. 'NAZWA': NAZWA
  586. })
  587. })
  588. .then(function(response) {
  589. return response.text();
  590. })
  591. .then(function(responseText) {
  592. try {
  593. return JSON.parse(responseText);
  594. } catch (e) {
  595. throw responseText;
  596. }
  597. })
  598. .then(function(result) {
  599. if (result.type == 'success') {
  600. p5UI__notifyAjaxCallback(result);
  601. resolve(result.body);
  602. } else {
  603. reject("Proszę podać inną nazwę grupy");
  604. }
  605. })
  606. .catch(function(error) {
  607. console.log('request failed', error)
  608. })
  609. })
  610. },
  611. allowOutsideClick: false
  612. }).then(function (groupKontrahenciData) {
  613. //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
  614. groupsKontrahenci = '<button class="btn btn-default" title="'+groupKontrahenciData['nazwa']+'" data-group-filter="'+groupKontrahenciData['id']+'">'+groupKontrahenciData['nazwa']+'</button>';
  615. $('#group-kontrahenci').append(groupsKontrahenci);
  616. });
  617. }
  618. function createGroupPracownicy(event) {
  619. event.preventDefault();
  620. swal({
  621. title: 'Utwórz grupę',
  622. input: 'text',
  623. showCancelButton: true,
  624. confirmButtonText: 'Zapisz',
  625. showLoaderOnConfirm: true,
  626. preConfirm: function (NAZWA) {
  627. return new Promise(function (resolve, reject) {
  628. if (!NAZWA) reject('Proszę podać nazwę grupy');
  629. window.fetch(URL_CREATE_PRACOWNICY_GROUP, {
  630. method: 'POST',
  631. header: {
  632. 'contentType': 'applications/json'
  633. },
  634. credentials: 'same-origin',
  635. body: JSON.stringify({
  636. 'NAZWA': NAZWA
  637. })
  638. })
  639. .then(function(response) {
  640. return response.text();
  641. })
  642. .then(function(responseText) {
  643. try {
  644. return JSON.parse(responseText);
  645. } catch (e) {
  646. throw responseText;
  647. }
  648. })
  649. .then(function(result) {
  650. if (result.type == 'success') {
  651. console.log('grupa prac1: ', result);
  652. p5UI__notifyAjaxCallback(result);
  653. resolve(result.body);
  654. } else {
  655. reject("Proszę podać inną nazwę grupy");
  656. }
  657. })
  658. .catch(function(error) {
  659. console.log('request failed', error)
  660. })
  661. })
  662. },
  663. allowOutsideClick: false
  664. }).then(function (groupPracownicyData) {
  665. console.log('grupa prac2: ', groupPracownicyData);
  666. //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
  667. groupsPracownicy = '<button class="btn btn-default" title="'+groupPracownicyData['nazwa']+'" data-group-filter="'+groupPracownicyData['id']+'">'+groupPracownicyData['nazwa']+'</button>';
  668. $('#group-pracownicy').append(groupsPracownicy);
  669. });
  670. }
  671. function rootChangeForm() {
  672. //todo: do przeniesienia
  673. urlFetchKontrahenciPowiazania();
  674. var valueUrl = global.location.hash;
  675. console.log('URL', valueUrl);
  676. switch (valueUrl) {
  677. case '#KONTRAHENCI':
  678. $( ".container-bi_audit_form_kontrahenci_raport" ).html( VIEW_KONTRAHENCI );
  679. urlFetchKontrahenci(1);
  680. fetchGroupKontrahenci();
  681. $( ".container-bi_audit_form_pracownicy_raport" ).hide();
  682. $( ".container-bi_audit_form_kontrahenci_raport" ).show();
  683. break;
  684. case '#PRACOWNICY':
  685. $( ".container-bi_audit_form_pracownicy_raport" ).html( VIEW_PRACOWNICY );
  686. urlFetchPracownicy(1);
  687. fetchGroupPracownicy();
  688. $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
  689. $( ".container-bi_audit_form_pracownicy_raport" ).show();
  690. break;
  691. // case '#REAPORT':
  692. // $( ".container-bi_audit_form_raport_data" ).html( VIEW_TREE_REAPORT );
  693. // urlFetchKontrahenciPowiazania();
  694. // $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
  695. // $( ".container-bi_audit_form_pracownicy_raport" ).hide();
  696. // $( ".container-bi_audit_form_raport_data" ).show();
  697. // break;
  698. default:
  699. $( ".container-bi_audit_form_pracownicy_raport" ).html( VIEW_PRACOWNICY );
  700. urlFetchPracownicy(1);
  701. fetchGroupPracownicy();
  702. $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
  703. $( ".container-bi_audit_form_pracownicy_raport" ).show();
  704. break;
  705. }
  706. //aktualizacja inputa głebokości powiazan
  707. loadCurrentDepthInInput('.smad-depth');
  708. loadCurrentDepthInInput('.smad-depth-kontrahenci');
  709. updateLocalStorageBiAuditDepth('.smad-depth');
  710. updateLocalStorageBiAuditDepth('.smad-depth-kontrahenci');
  711. }
  712. function getAddressData(objectValue) {
  713. var objectValue = objectValue || [];
  714. var listData = '';
  715. if (!objectValue) {
  716. return true;
  717. }
  718. objectValue.forEach (function(item) {
  719. if (item['kodPocztowy']) { listData += '<div>kod pocztowy: ' + item['kodPocztowy'] + '<div>'; }
  720. if (item['miejscowosc']) { listData += '<div>miejscowość: ' + item['miejscowosc'] + '<div>'; }
  721. if (item['nrBudynku']) { listData += '<div>nr budynku: ' + item['nrBudynku'] + '<div>'; }
  722. if (item['nrLokalu']) { listData += '<div>nr lokalu: ' + item['nrLokalu'] + '<div>'; }
  723. if (item['typAdresu']) { listData += '<div>typ adresu: ' + item['typAdresu'] + '<div>'; }
  724. if (item['ulica']) { listData += '<div>ulica: ' + item['ulica'] + '<div>'; }
  725. listData += '<div>------<div>';
  726. });
  727. return listData;
  728. }
  729. /**
  730. * Get name name group
  731. */
  732. function getNameGroupById(store, filterIdGroup) {
  733. var NAZWA = '';
  734. if (!store || filterIdGroup === 0 ) {
  735. NAZWA = 'Wszyscy';
  736. } else {
  737. $(store).each(function() {
  738. if ( parseInt(filterIdGroup) === parseInt(this.ID) ) {
  739. NAZWA = this.NAZWA;
  740. }
  741. });
  742. }
  743. return NAZWA;
  744. }
  745. function urlFetchKontrahenci(page) {
  746. hideMoreRecordFunctionsPopover()
  747. var page = page || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page');
  748. selectPage('KONTRAHENCI', page);
  749. if ( page === 1) {
  750. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', 1);
  751. }
  752. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  753. var frm = document.getElementById('filtersFieldRemoveBtn-KONTRAHENCI').form
  754. var fieldNameList = FIELD_LIST_KONTRAHENCI
  755. var filterFields = fieldNameList.map(function (fieldName) {
  756. return [ fieldName, frm[fieldName].value ]
  757. }).filter(function (filter) {
  758. return ( filter[1].length > 0 )
  759. }).map(function (filter) {
  760. return '' + filter[0] + '=' + filter[1]
  761. }).join('&')
  762. filterFields = (filterFields.length > 0) ? '&' + filterFields : ''
  763. fetch(URL_FETCH_KONTRAHENCI + '&page=' + page + '&filterIdGroup=' + filterIdGroup + filterFields, {
  764. credentials: 'same-origin'
  765. })
  766. .then(function parseJSON(response) {
  767. return response.json()
  768. var filterIdGroup = filterIdGroup || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  769. })
  770. .then(function(data) {
  771. var listItemsKontrahenci = null;
  772. data.body.items.forEach (function(row) {
  773. listItemsKontrahenci += '<tr><td style="white-space:nowrap">' +
  774. '<input style="vertical-align:top" type="checkbox" name="kontrID[]" value="'+row['ID']+'" />' +
  775. '<i onClick="kontrahenciLoadMoreRecordFunctions(event, this, '+row['ID']+')" style="margin-left:6px; cursor:pointer; color:#333" class="glyphicon glyphicon-menu-hamburger" title="Więcej funkcji dla rekordu nr ' + row['ID'] + '"></i>' +
  776. '</td>' +
  777. '<td align="right">'+row["ID"]+'</td>'+
  778. '<td align="right">' + ( row["Nazwa_grupy_kapitalowej"] || '' ) + '</td>' +
  779. '<td align="right">' + ( row["Pelna_nazwa_kontrahenta"] || '' ) + '</td>' +
  780. '<td align="right">' + ( row["Numer_kontrahenta"] || '' ) + '</td>' +
  781. '<td align="right">' + ( row["Skrocona_Nazwa_Kontrahenta"] || '' ) + '</td>' +
  782. '<td align="right">' + ( row["Typ_kontrahenta"] || '' ) + '</td>' +
  783. '<td align="right">' + ( row["NIP"] || '' ) + '</td>' +
  784. '<td align="right">' + ( row["KRS"] || '' ) + '</td>' +
  785. '<td align="right">' + ( row["REGON"] || '' ) + '</td>' +
  786. '<td align="right">' + ( row["PESEL"] || '' ) + '</td>' +
  787. '<td align="right">' + ( row["Forma_prawna_dzialalnosci"] || '' ) + '</td>' +
  788. '<td align="right">' + ( row["Ulica"] || '' ) + '</td>' +
  789. '<td align="right">' + ( row["Numer_budynku"] || '' ) + '</td>' +
  790. '<td align="right">' + ( row["Numer_mieszkania_lokalu"] || '' ) + '</td>' +
  791. '<td align="right">' + ( row["Miejscowosc"] || '' ) + '</td>' +
  792. '<td align="right">' + ( row["Kod_pocztowy"] || '' ) + '</td>' +
  793. '<td align="right">' + ( row["Kraj"] || '' ) + '</td>' +
  794. '<td align="right">' + ( row["Telefon"] || '' ) + '</td>' +
  795. '<td align="right">' + ( row["Fax"] || '' ) + '</td>' +
  796. '<td align="right">' + ( row["Mail"] || '' ) + '</td>' +
  797. '<td align="right">' + ( row["A_ADM_COMPANY"] || '' ) + '</td>' +
  798. '<td align="right">' + ( row["A_CLASSIFIED"] || '' ) + '</td>' +
  799. '<td align="right">' + ( row["Dodano"] || '' ) + '</td>' +
  800. '<td align="right">' + ( row["Podmiot_dominujacy"] || '' ) + '</td>' +
  801. '<td align="right">' + ( row["Tytul_dokumentu"] || '' ) + '</td>' +
  802. '<td align="right">' + ( row["ownCompany"] || '' ) + '</td>' +
  803. '<td align="right">' + ( row["uwagi"] || '' ) + '</td></tr>';
  804. });
  805. if (data.body.pagination !== undefined) {
  806. Pagination.Init(document.getElementById('pagination-kontrahenci'), {
  807. url: BASE_URLS+'index.php?_route=UrlAction_Bocian#KONTRAHENCI',
  808. id_pagination: 'pagination-kontrahenci',
  809. type: 'KONTRAHENCI',
  810. limit: data.body.pagination.limit,
  811. total_items: data.body.pagination.total_items, // pages size
  812. size: data.body.pagination.size, // pages size
  813. page: page, // selected page
  814. step: 1 // pages before and after current
  815. });
  816. var paginationShowNextCount = 1;
  817. if ( parseInt(data.body.pagination.current) !== 1) {
  818. paginationShowNextCount = parseInt(data.body.pagination.limit) * (parseInt(data.body.pagination.current) - 1 ) + 1;
  819. }
  820. $('#paginationShowNextCount-KONTRAHENCI').text(paginationShowNextCount);
  821. $('#smad-filter-desc-kontrahenci').text(data.body.pagination.total_items);
  822. if (data.body.pagination.total_items > 0) {
  823. var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>')
  824. btnAddAll.on('click', { pagination: data.body.pagination }, function (event) {
  825. // event.data.pagination: { [ filter_idGroup: ... ] }
  826. // fetch ids from request, set to LocatStorage, update selected on gui
  827. var postData = {}
  828. if ('filter_idGroup' in event.data.pagination && event.data.pagination['filter_idGroup']) postData['filter_idGroup'] = event.data.pagination['filter_idGroup']
  829. Object.keys(event.data.pagination).filter(function (key) {
  830. return ('f_' === key.substr(0, 2))
  831. }).forEach(function (filterKey) {
  832. var value = event.data.pagination[filterKey]
  833. postData[filterKey] = value
  834. })
  835. var thisButton = $(this)
  836. thisButton.attr('disabled', true)
  837. thisButton.text( thisButton.text() + '...' )
  838. p5UI__notifyAjaxCallback({ type: 'info', msg: "Pobieranie kontrahentów..." })
  839. global.fetch(URL_FETCH_KONTRAHENCI_IDS_AJAX, {
  840. credentials: 'same-origin',
  841. method: 'POST',
  842. headers: {
  843. 'Content-Type': 'application/json'
  844. },
  845. body: JSON.stringify(postData)
  846. })
  847. .then(function __parseJSON(response) {
  848. return response.json()
  849. })
  850. .then(function (json) {
  851. if ('success' === json.type && json.body && json.body.ids) {
  852. updateListIdBiAuditReaport('KONTRAHENCI', json.body.ids.map(function (id) {
  853. return parseInt(id)
  854. }))
  855. jQuery('#body-kontrahenci').find('input[name="kontrID[]"]').attr('checked', true)
  856. thisButton.attr('disabled', false)
  857. var txt = thisButton.text()
  858. thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
  859. p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+json.body.ids.length+" kontrahentów" })
  860. }
  861. })
  862. .catch(function (e) {
  863. p5UI__notifyAjaxCallback({ type: 'error', msg: '' + e })
  864. thisButton.attr('disabled', false)
  865. var txt = thisButton.text()
  866. thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
  867. })
  868. })
  869. $('#smad-filter-desc-kontrahenci').append(btnAddAll);
  870. }
  871. }
  872. var groupSelectData = getNameGroupById(getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups'), filterIdGroup);
  873. $('#smad-filter-head-title-kontrahenci').text(groupSelectData);
  874. console.log('kontrahenci groupSelectData: ', groupSelectData);
  875. $( "#body-kontrahenci" ).html(listItemsKontrahenci);
  876. checkAll('KONTRAHENCI');
  877. catchEventCheckbox('KONTRAHENCI');
  878. checkedChoiseItems('KONTRAHENCI', getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') );
  879. // $( ".container-bi_audit_raport" ).append( data.body.view );
  880. console.log('request succeeded with JSON responseKontrahenci', data)
  881. updateTopCounters();
  882. }).catch(function(error) {
  883. console.log('request failed', error)
  884. })
  885. }
  886. function urlFetchPracownicy(page) {
  887. hideMoreRecordFunctionsPopover()
  888. var page = page || getItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page');
  889. if ( page === 1) {
  890. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', 1);
  891. }
  892. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
  893. selectPage('PRACOWNICY', page);
  894. var frm = document.getElementById('filtersFieldRemoveBtn-PRACOWNICY').form
  895. var fieldNameList = FIELD_LIST_PRACOWNICY
  896. var filterFields = fieldNameList.filter(function (fieldName) {
  897. if (!frm[fieldName]) console.log('Err missing field: "'+fieldName+'"')
  898. return (frm[fieldName]) ? true : false
  899. }).map(function (fieldName) {
  900. return [ fieldName, frm[fieldName].value ]
  901. }).filter(function (filter) {
  902. return ( filter[1].length > 0 )
  903. }).map(function (filter) {
  904. return '' + filter[0] + '=' + filter[1]
  905. }).join('&')
  906. filterFields = (filterFields.length > 0) ? '&' + filterFields : ''
  907. // TODO: fetch data from API
  908. // p5WFS_GetFeature('default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY', {
  909. // sortBy: 'ID+D',
  910. // maxFeatures: 20,
  911. // // TODO: startIndex: 0, // TODO: from pagination
  912. // // TODO: backRefNS, backRefPK, backRefField - TODO: from groups
  913. // // resolve: 'all',
  914. // // resolveDepth: 2
  915. // 'ogc:Filter': '<wfs:Query>' + '\n' + [
  916. // '*',
  917. // 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*',
  918. // [
  919. // 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object',
  920. // 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row',
  921. // 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object',
  922. // 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI'
  923. // ].join('/')
  924. // ].map(function (fieldName) {
  925. // return '<wfs:PropertyName>' + fieldName + '</wfs:PropertyName>';
  926. // }).join('\n') + '\n' + '</wfs:Query>'
  927. // }).then(function (items) {
  928. // console.log('p5WFS_GetFeature: items: ', items);
  929. // }).catch(function (err) {
  930. // console.log('p5WFS_GetFeature: err: ', err);
  931. // })
  932. fetch(URL_FETCH_PRACOWNICY + '&page=' + page + '&filterIdGroup=' + filterIdGroup + filterFields, {
  933. credentials: 'same-origin'
  934. })
  935. .then(function parseJSON(response) {
  936. return response.json()
  937. })
  938. .then(function(data) {
  939. var addresPerson = '';
  940. var listItemsPracownik = null;
  941. console.log('urlFetchPracownicy', data.body.items);
  942. data.body.items.forEach (function(row) {
  943. if (row["default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy"]) {
  944. addresPerson = getAddressData(row["default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy"]);
  945. }
  946. listItemsPracownik += '<tr><td style="white-space:nowrap">' +
  947. '<input style="vertical-align:top" type="checkbox" name="prID[]" value="'+row['ID']+'" />' +
  948. '<i onClick="pracownicyLoadMoreRecordFunctions(event, this, '+row['ID']+')" style="margin-left:6px; cursor:pointer; color:#333" class="glyphicon glyphicon-menu-hamburger" title="Więcej funkcji dla rekordu nr ' + row['ID'] + '"></i>' +
  949. '</td>' +
  950. '<td align="right">'+row["ID"]+'</td>' +
  951. '<td align="right">' + ( row["imiona"] || '' ) + '</td>' +
  952. '<td align="right">' + ( row["nazwisko"] || '' ) + '</td>' +
  953. '<td align="right">' + ( row["nip"] || '' ) + '</td>' +
  954. '<td align="right">' + ( row["pesel"] || '' ) + '</td>' +
  955. '<td align="right">' + ( row["regon"] || '' ) + '</td>' +
  956. '<td align="right">' + ( row["source"] || '' ) + '</td>' +
  957. '<td align="right">' + ( row["jednostka_organizacyjna"] || '' ) + '</td>' +
  958. '<td align="right">' + ( row["A_STATUS"] || '' ) + '</td>' +
  959. '<td align="right">' + ( row["A_STATUS_INFO"] || '' ) + '</td>' +
  960. '<td align="right">' + ( row["L_APPOITMENT_USER"] || '' ) + '</td>' +
  961. '<td align="right">'+ addresPerson +'</td></tr>';
  962. });
  963. if (data.body.pagination.size) {
  964. Pagination.Init(document.getElementById('pagination-pracownicy'), {
  965. url: BASE_URLS+'index.php?_route=UrlAction_Bocian#PRACOWNICY',
  966. id_pagination: 'pagination-pracownicy',
  967. type: 'PRACOWNICY',
  968. limit: data.body.pagination.limit,
  969. total_items: data.body.pagination.total_items, // pages size
  970. size: data.body.pagination.size, // pages size
  971. page: data.body.pagination.current, // selected page
  972. step: 1 // pages before and after current
  973. });
  974. var paginationShowNextCount = 1;
  975. if ( parseInt(data.body.pagination.current) !== 1) {
  976. paginationShowNextCount = parseInt(data.body.pagination.limit) * (parseInt(data.body.pagination.current) - 1 ) + 1;
  977. }
  978. $('#paginationShowNextCount-PRACOWNICY').text(paginationShowNextCount);
  979. $('#smad-filter-desc-pracownicy').text(data.body.pagination.total_items);
  980. if (data.body.pagination.total_items > 0) {
  981. var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>')
  982. btnAddAll.on('click', { pagination: data.body.pagination }, function (event) {
  983. // event.data.pagination: { [ filter_idGroup: ... ] }
  984. // fetch ids from request, set to LocatStorage, redirect to '#KONTRAHENCI'
  985. var postData = {}
  986. if ('filter_idGroup' in event.data.pagination && event.data.pagination['filter_idGroup']) postData['filter_idGroup'] = event.data.pagination['filter_idGroup']
  987. Object.keys(event.data.pagination).filter(function (key) {
  988. return ('f_' === key.substr(0, 2))
  989. }).forEach(function (filterKey) {
  990. var value = event.data.pagination[filterKey]
  991. postData[filterKey] = value
  992. })
  993. var thisButton = $(this)
  994. thisButton.attr('disabled', true)
  995. thisButton.text( thisButton.text() + '...' )
  996. p5UI__notifyAjaxCallback({ type: 'info', msg: "Pobieranie pracowników..." })
  997. global.fetch(URL_FETCH_PRACOWNICY_IDS_AJAX, {
  998. credentials: 'same-origin',
  999. method: 'POST',
  1000. headers: {
  1001. 'Content-Type': 'application/json'
  1002. },
  1003. body: JSON.stringify(postData)
  1004. })
  1005. .then(function __parseJSON(response) {
  1006. return response.json()
  1007. })
  1008. .then(function (json) {
  1009. if ('success' === json.type && json.body && json.body.ids) {
  1010. updateListIdBiAuditReaport('PRACOWNICY', json.body.ids.map(function (id) {
  1011. return parseInt(id)
  1012. }))
  1013. thisButton.attr('disabled', false)
  1014. var txt = thisButton.text()
  1015. thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
  1016. p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+json.body.ids.length+" pracowników" })
  1017. window.location.hash = 'KONTRAHENCI'
  1018. }
  1019. })
  1020. .catch(function (e) {
  1021. p5UI__notifyAjaxCallback({ type: 'error', msg: '' + e })
  1022. thisButton.attr('disabled', false)
  1023. var txt = thisButton.text()
  1024. thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
  1025. })
  1026. })
  1027. $('#smad-filter-desc-pracownicy').append(btnAddAll);
  1028. }
  1029. }
  1030. // wyświetlenie wybranej grupy w naglówku nad tabela
  1031. var groupSelectData = getNameGroupById(getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups'), filterIdGroup);
  1032. $('#smad-filter-head-title-pracownicy').text(groupSelectData);
  1033. // zaladaowanie listy pracowników
  1034. $( "#body-pracownicy" ).html( listItemsPracownik);
  1035. checkAll('PRACOWNICY');
  1036. catchEventCheckbox('PRACOWNICY');
  1037. checkedChoiseItems('PRACOWNICY', getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') );
  1038. updateTopCounters();
  1039. }).catch(function(error) {
  1040. console.log('request failed', error)
  1041. })
  1042. }
  1043. function selectPage(type, nrPage) {
  1044. var type = type.toLowerCase();
  1045. $('#pagination-' + type + ' ul li a').each(function(index, value){
  1046. if (this.text === nrPage) {
  1047. $(this).addClass('active');
  1048. } else {
  1049. $(this).removeClass('active');
  1050. }
  1051. });
  1052. }
  1053. function checkAll(type) {
  1054. $('#checkAll-' + type).change(function() {
  1055. var valueCheckbox = null;
  1056. var checkboxes = $('form').find(':checkbox');
  1057. if($(this).prop('checked')) {
  1058. checkboxes.prop('checked', true);
  1059. //valueCheckbox = checkboxes.prop("checked");
  1060. var allValsChecked = [];
  1061. var checkedValues = $('#smad-table-' + type + ' input:checkbox:checked').map(function() {
  1062. if (this.value !== 'on') {
  1063. allValsChecked.push(parseInt(this.value));
  1064. }
  1065. }).get();
  1066. updateListIdBiAuditReaport(type, allValsChecked);
  1067. } else {
  1068. checkboxes.prop('checked', false);
  1069. var allValsUnChecked = [];
  1070. var checkedValues = $('#smad-table-' + type + ' input:checkbox:not(:checked)').map(function() {
  1071. if (this.value !== 'on') {
  1072. allValsUnChecked.push(parseInt(this.value));
  1073. }
  1074. }).get();
  1075. deleteListIdBiAuditReaport(type, allValsUnChecked);
  1076. }
  1077. // update count selected IDs
  1078. updateCountItemCheckedByType(type.toLowerCase());
  1079. });
  1080. }
  1081. /**
  1082. * Select again checkbox before selected item chekbox from storage (pracownicy/kontrahenci)
  1083. */
  1084. function checkedChoiseItems(type, store) {
  1085. updateCountItemCheckedByType(type.toLowerCase());
  1086. var idElement = 'smad-table-' + type;
  1087. // if id element exist
  1088. if (document.getElementById(idElement)) {
  1089. // if not checked
  1090. if (!store) {
  1091. return false;
  1092. }
  1093. // checked again if user selected Item (pracownicy/kontrahent)
  1094. for (i = 0; i < store.length; i++) {
  1095. $('#body-'+type.toLowerCase() +' input[type=checkbox] ').map(function(k, v) {
  1096. if ( store[i] === parseInt(this.value) ){
  1097. $(this).prop('checked', true);
  1098. }
  1099. }).get();
  1100. }
  1101. }
  1102. $('#smad-table-' + type + ' input[type=checkbox]').on( 'load', function() {
  1103. var itemsCHecked = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  1104. getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  1105. if (itemsCHecked.lenght === 0 ) {
  1106. return;
  1107. }
  1108. var valueCheckbox = null;
  1109. var checkboxes = $('form').find(':checkbox');
  1110. if($(this).prop('checked')) {
  1111. checkboxes.prop('checked', true);
  1112. var allValsChecked = [];
  1113. var checkedValues = $('#smad-table-' + type + ' input:checkbox:checked').map(function() {
  1114. if (this.value !== 'on') {
  1115. allValsChecked.push(parseInt(this.value));
  1116. }
  1117. }).get();
  1118. updateListIdBiAuditReaport(type, allValsChecked);
  1119. } else {
  1120. checkboxes.prop('checked', false);
  1121. var allValsUnChecked = [];
  1122. var checkedValues = $('#smad-table-' + type + ' input:checkbox:not(:checked)').map(function() {
  1123. if (this.value !== 'on') {
  1124. allValsUnChecked.push(parseInt(this.value));
  1125. }
  1126. }).get();
  1127. deleteListIdBiAuditReaport(type, allValsUnChecked);
  1128. }
  1129. });
  1130. }
  1131. function catchEventCheckbox(type) {
  1132. $('#smad-table-' + type + ' input[type="checkbox"]').on('change', function() {
  1133. if($(this).is(":checked")) {
  1134. var allValsChecked = [];
  1135. if (this.value !== 'on') {
  1136. allValsChecked.push(parseInt(this.value));
  1137. }
  1138. updateListIdBiAuditReaport(type, allValsChecked);
  1139. } else {
  1140. var allValsUnChecke = [];
  1141. if (this.value !== 'on') {
  1142. allValsUnChecke.push(parseInt(this.value));
  1143. }
  1144. deleteListIdBiAuditReaport(type, allValsUnChecke);
  1145. }
  1146. // update count selected IDs
  1147. updateCountItemCheckedByType(type.toLowerCase());
  1148. });
  1149. }
  1150. function clearSelectedCheckbox() {
  1151. $('#checkAll-PRACOWNICY').prop('checked', false)
  1152. $('#checkAll-KONTRAHENCI').prop('checked', false)
  1153. }
  1154. function updateListIdBiAuditReaport(type, valueArray) {
  1155. var currentStoragePracownicyIds = [];
  1156. var updateListPracownicyIds = null;
  1157. var currentStorageKontrahenciIds = [];
  1158. var updateListKontrahenciIds = null;
  1159. if ( type == 'PRACOWNICY') {
  1160. currentStoragePracownicyIds = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  1161. if(currentStoragePracownicyIds !== null) {
  1162. updateListPracownicyIds = [...new Set([...currentStoragePracownicyIds ,...valueArray])];
  1163. }
  1164. else {
  1165. updateListPracownicyIds = valueArray;
  1166. }
  1167. setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', updateListPracownicyIds);
  1168. }
  1169. if ( type == 'KONTRAHENCI') {
  1170. currentStorageKontrahenciIds = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  1171. if(currentStorageKontrahenciIds !== null) {
  1172. updateListKontrahenciIds = [...new Set([...currentStorageKontrahenciIds ,...valueArray])];
  1173. }
  1174. else {
  1175. updateListKontrahenciIds = valueArray;
  1176. }
  1177. setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', updateListKontrahenciIds);
  1178. }
  1179. }
  1180. function deleteListIdBiAuditReaport(type, valueArray) {
  1181. var currentStoragePracownicyIds = [];
  1182. var updateListPracownicyIds = null;
  1183. if ( type == 'PRACOWNICY') {
  1184. deleteItemLocalStorage('Bocian.biAuditForm.pracownicyIds', valueArray);
  1185. }
  1186. if ( type == 'KONTRAHENCI') {
  1187. deleteItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', valueArray);
  1188. }
  1189. }
  1190. // filter group detect
  1191. function fetchGroupPracownicy() {
  1192. fetch(URL_FETCH_GROUP_PRACOWNICY, {
  1193. credentials: 'same-origin'
  1194. })
  1195. .then(function parseJSON(response) {
  1196. return response.json()
  1197. })
  1198. .then(function(data) {
  1199. setItemLocalStorage('Bocian.biAuditForm.pracownicy.groups', data.body.itmesGroupPracownicy);
  1200. if (data.body.itmesGroupPracownicy === null) {
  1201. return;
  1202. }
  1203. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
  1204. var currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  1205. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', filterIdGroup);
  1206. setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
  1207. var groupsPracownicy = '';
  1208. var activeButton = '';
  1209. data.body.itmesGroupPracownicy.forEach (function(row) {
  1210. if ( filterIdGroup === row['ID'] ) { activeButton = 'active'; $('#group-pracownicy button.active').removeClass('active'); }
  1211. groupsPracownicy += '<button class="btn btn-default '+activeButton+'" title="' + row['NAZWA'] + '" data-group-filter="' + row['ID'] + '">' + row['NAZWA'] + '</button>';
  1212. });
  1213. $("#group-pracownicy").append(groupsPracownicy);
  1214. updateCountItemCheckedByType('pracownicy');
  1215. // detect filter group
  1216. detectChoiseFilter();
  1217. }).catch(function(error) {
  1218. console.log('request failed', error)
  1219. });
  1220. }
  1221. function fetchGroupKontrahenci() {
  1222. fetch(URL_FETCH_GROUP_KONTRAHENCI, {
  1223. credentials: 'same-origin'
  1224. })
  1225. .then(function parseJSON(response) {
  1226. return response.json()
  1227. })
  1228. .then(function(data) {
  1229. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups', data.body.itemsGroupKontrahenci);
  1230. if (data.body.itemsGroupKontrahenci === null) {
  1231. return;
  1232. }
  1233. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  1234. var currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  1235. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', filterIdGroup);
  1236. setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
  1237. var groupsKontrahenci = '';
  1238. var activeButton = '';
  1239. data.body.itemsGroupKontrahenci.forEach (function(row) {
  1240. if ( filterIdGroup === row['ID'] ) { activeButton = 'active'; $('#group-kontrahenci button.active').removeClass('active'); }
  1241. groupsKontrahenci += '<button class="btn btn-default '+activeButton+'" title="'+row['NAZWA']+'" data-group-filter="'+row['ID']+'">'+row['NAZWA']+'</button>';
  1242. });
  1243. $("#group-kontrahenci").append(groupsKontrahenci);
  1244. updateCountItemCheckedByType('kontrahenci');
  1245. // detect filter group
  1246. detectChoiseFilter();
  1247. console.log('request succeeded with JSON fetchGroupKontrahenci', data.body.itemsGroupKontrahenci);
  1248. }).catch(function(error) {
  1249. console.log('request failed', error)
  1250. });
  1251. }
  1252. function detectChoiseFilter() {
  1253. $('#group-kontrahenci').on('click', 'button', function(evt) {
  1254. $('#group-kontrahenci button.active').removeClass('active');
  1255. $(this).addClass('active');
  1256. // pobranie id grupy kliknietego buttonu
  1257. var filterIdGroup = $(this).attr("data-group-filter");
  1258. // aktaulna wartość zagłebienia
  1259. var currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  1260. //reset LocalStorage
  1261. // defaultBIAuditLocalStorage();
  1262. // ustawienie ostaniej wartości zagłebienia przed resete
  1263. setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
  1264. // ustawić id grupy do sesyjnej
  1265. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', parseInt(filterIdGroup));
  1266. // wywylac funckje pobrania danych
  1267. urlFetchKontrahenci(1);
  1268. });
  1269. $('#group-pracownicy').on('click', 'button', function(evt) {
  1270. $('#group-pracownicy button.active').removeClass('active');
  1271. $(this).addClass('active');
  1272. // pobranie id grupy kliknietego buttonu
  1273. var filterIdGroup = $(this).attr("data-group-filter");
  1274. // aktaulna wartość zagłebienia
  1275. var currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  1276. //reset LocalStorage
  1277. // defaultBIAuditLocalStorage();
  1278. // ustawienie ostaniej wartości zagłebienia przed resete
  1279. setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
  1280. // ustawić id grupy do sesyjnej
  1281. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', parseInt(filterIdGroup));
  1282. // wywylac funckje pobrania danych
  1283. urlFetchPracownicy(1);
  1284. });
  1285. }
  1286. // Local storage
  1287. function setItemLocalStorage(key, array) {
  1288. localStorage.setItem(key, JSON.stringify(array));
  1289. }
  1290. function getItemLocalStorage(key) {
  1291. var retrievedData = localStorage.getItem(key);
  1292. var response = JSON.parse(retrievedData);
  1293. return response;
  1294. }
  1295. function deleteItemLocalStorage(key, itemsArray) {
  1296. var currentStorageArray = getItemLocalStorage(key);
  1297. var newStorageArray = removeItemArrayInArray(currentStorageArray, itemsArray);
  1298. setItemLocalStorage(key, newStorageArray);
  1299. }
  1300. /**
  1301. * arr - array
  1302. * item - search item
  1303. */
  1304. function removeItemInArray(arr, item) {
  1305. for(var i = arr.length; i--;) {
  1306. if(arr[i] === item) {
  1307. arr.splice(i, 1);
  1308. }
  1309. }
  1310. return arr;
  1311. }
  1312. /**
  1313. * arr - array
  1314. * item - array list items
  1315. */
  1316. function removeItemArrayInArray(arr, itemsArray) {
  1317. for(var i = arr.length; i--;) {
  1318. for(var j = itemsArray.length; j--;) {
  1319. if(arr[i] === itemsArray[j]) {
  1320. arr.splice(i, 1);
  1321. }
  1322. }
  1323. }
  1324. return arr;
  1325. }
  1326. /**
  1327. * Cleart list local storage by type
  1328. * typeNameLocalStorage - name (praconwicy/kontrahenci)
  1329. */
  1330. function clearListLocalStorageByType(typeNameLocalStorage) {
  1331. if (typeNameLocalStorage === 'pracownicy') {
  1332. setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', []);
  1333. }
  1334. if (typeNameLocalStorage === 'kontrahenci') {
  1335. setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', []);
  1336. }
  1337. // update count selected item
  1338. updateCountItemCheckedByType(typeNameLocalStorage);
  1339. // unchecked checkbox
  1340. $('#smad-table-'+typeNameLocalStorage.toUpperCase()+' form').find(':checkbox').prop('checked', false);
  1341. }
  1342. /**
  1343. * Update count selected pracowniyc/kontrahenci
  1344. */
  1345. function updateCountItemCheckedByType(typeNameLocalStorage) {
  1346. var countId = 0;
  1347. updateTopCounters();
  1348. if (typeNameLocalStorage === 'pracownicy') {
  1349. var countPracownicy = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  1350. if (countPracownicy === null || countPracownicy === undefined) {
  1351. return countId;
  1352. }
  1353. countId = Object.keys(countPracownicy).length;
  1354. $('#count-selected-item-pracownicy').text(countId);
  1355. }
  1356. if (typeNameLocalStorage === 'kontrahenci') {
  1357. var countKontrahenci = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  1358. if (countKontrahenci === null || countKontrahenci === undefined) {
  1359. return countId;
  1360. }
  1361. countId = Object.keys(countKontrahenci).length;
  1362. $('#count-selected-item-kontrahenci').text(countId);
  1363. }
  1364. return countId;
  1365. }
  1366. function updateTopCounters() {
  1367. var countPracownicy = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  1368. var countKontrahenci = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  1369. var totalPracownicy = (countPracownicy) ? Object.keys(countPracownicy).length : 0;
  1370. var totalKontrahenci = (countKontrahenci) ? Object.keys(countKontrahenci).length : 0;
  1371. console.warn({totalPracownicy: totalPracownicy, totalKontrahenci: totalKontrahenci})
  1372. $('.top--count-selected-item-pracownicy').text(totalPracownicy ? '('+totalPracownicy+')' : '');
  1373. $('.top--count-selected-item-kontrahenci').text(totalKontrahenci ? '('+totalKontrahenci+')' : '');
  1374. $('.top--count-selected-item-pracownicy').attr('title', totalPracownicy ? "Wybrano: " + totalPracownicy + " pracowników" : '');
  1375. $('.top--count-selected-item-kontrahenci').attr('title', totalKontrahenci ? "Wybrano: " + totalKontrahenci + " kontrahentów" : '');
  1376. }
  1377. // Pagination
  1378. var Pagination = {
  1379. code: '', // end show html paginations
  1380. clickPage: 1, // set default 1 page
  1381. // --------------------
  1382. // Utility
  1383. // --------------------
  1384. // initialize default data
  1385. Extend: function(data) {
  1386. data = data || {};
  1387. Pagination.url = data.url;
  1388. Pagination.id_pagination = data.id_pagination;
  1389. Pagination.type = data.type;
  1390. Pagination.limit = data.limit;
  1391. Pagination.total_items = data.total_items;
  1392. Pagination.size = data.size || 2;
  1393. Pagination.page = data.page || 1;
  1394. Pagination.step = data.step || 3;
  1395. },
  1396. // add pages by number (from [s] to [f])
  1397. Add: function(s, f) {
  1398. for (var i = s; i < f; i++) {
  1399. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">' + i + '</a></li>';
  1400. }
  1401. },
  1402. // add last page with separator
  1403. Last: function() {
  1404. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">>></a></li>';
  1405. },
  1406. // add first page with separator
  1407. First: function() {
  1408. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default"><<</a></li>';
  1409. },
  1410. // add last page with separator
  1411. Next: function() {
  1412. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">></a></li>';
  1413. },
  1414. // add first page with separator
  1415. Prev: function() {
  1416. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default"><</a></li>';
  1417. },
  1418. // --------------------
  1419. // Handlers
  1420. // --------------------
  1421. // change page
  1422. Click: function() {
  1423. clearSelectedCheckbox();
  1424. var selectPage = $("#pagination-"+Pagination.type.toLowerCase()+' .tblAjax__footer__toolbar__pagination').find('a.active').text();
  1425. Pagination.clickPage = +this.innerHTML || '';
  1426. if ( selectPage === NaN || selectPage > Pagination.size) { selectPage = 1; }
  1427. switch (this.innerHTML) {
  1428. case '&gt;&gt;': // last
  1429. Pagination.clickPage = Pagination.size;
  1430. break;
  1431. case '&lt;&lt;': // first
  1432. Pagination.clickPage = 1;
  1433. break;
  1434. case '&lt;': // prev
  1435. Pagination.clickPage = parseInt(selectPage) - 1;
  1436. if (Pagination.clickPage < 1) {
  1437. Pagination.clickPage = 1;
  1438. }
  1439. break;
  1440. case '&gt;': // next
  1441. Pagination.clickPage = parseInt(selectPage) + 1;
  1442. if (Pagination.clickPage > Pagination.size) {
  1443. Pagination.clickPage = Pagination.size;
  1444. }
  1445. break;
  1446. }
  1447. if ( Pagination.type === 'KONTRAHENCI' ) {
  1448. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', Pagination.clickPage);
  1449. Pagination.page = urlFetchKontrahenci(Pagination.clickPage);
  1450. }
  1451. else if ( Pagination.type === 'PRACOWNICY' ){
  1452. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', Pagination.clickPage);
  1453. Pagination.page = urlFetchPracownicy(Pagination.clickPage);
  1454. }
  1455. Pagination.Start();
  1456. },
  1457. // --------------------
  1458. // Script structure pagination
  1459. // --------------------
  1460. // binding pages
  1461. Bind: function() {
  1462. var a = Pagination.e.getElementsByTagName('a');
  1463. var currentPage = Pagination.clickPage || 1;
  1464. for (var i = 0; i < a.length; i++) {
  1465. if (+a[i].innerHTML === Pagination.page) a[i].className = 'btn btn-default active';
  1466. a[i].addEventListener('click', Pagination.Click, false);
  1467. }
  1468. },
  1469. // write pagination
  1470. Finish: function() {
  1471. Pagination.e.innerHTML = Pagination.code;
  1472. Pagination.code = '</ul></nav>';
  1473. Pagination.Bind();
  1474. },
  1475. // find pagination type
  1476. Start: function() {
  1477. Pagination.code = '';
  1478. if ( Pagination.type === 'KONTRAHENCI' ) {
  1479. 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>';
  1480. } else if ( Pagination.type === 'PRACOWNICY' ) {
  1481. 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>';
  1482. }
  1483. Pagination.code += '<nav aria-label="Page navigation" class="footer_pagination_menu_items"><ul class="btn-group tblAjax__footer__toolbar__pagination smad-pagination">';
  1484. Pagination.First();
  1485. Pagination.Prev();
  1486. if ( Pagination.type === 'KONTRAHENCI' ) {
  1487. Pagination.page = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page') || 1;
  1488. }
  1489. else if ( Pagination.type === 'PRACOWNICY' ) {
  1490. Pagination.page = getItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page') || 1;
  1491. }
  1492. if ( Pagination.page > Pagination.size ) {
  1493. Pagination.page = 1;
  1494. }
  1495. if (Pagination.size < Pagination.step * 2 + 6) {
  1496. Pagination.Add(1, Pagination.size + 1);
  1497. }
  1498. else if (Pagination.page < Pagination.step * 2 + 1) {
  1499. Pagination.Add(1, Pagination.step * 2 + 4);
  1500. }
  1501. else if (Pagination.page > Pagination.size - Pagination.step * 2) {
  1502. Pagination.Add(Pagination.size - Pagination.step * 2 - 2, Pagination.size + 1);
  1503. }
  1504. else {
  1505. Pagination.Add(Pagination.page - Pagination.step, Pagination.page + Pagination.step + 1);
  1506. }
  1507. Pagination.Next();
  1508. Pagination.Last();
  1509. Pagination.Finish();
  1510. },
  1511. // --------------------
  1512. // Initialization
  1513. // --------------------
  1514. // binding buttons
  1515. Buttons: function(e) {
  1516. var nav = e.getElementsByTagName('a');
  1517. },
  1518. // create skeleton
  1519. Create: function(e) {
  1520. var html = [
  1521. '<div></div>' // pagination container
  1522. ];
  1523. e.innerHTML = html.join('');
  1524. Pagination.e = e.getElementsByTagName('div')[0];
  1525. Pagination.Buttons(e);
  1526. },
  1527. // init
  1528. Init: function(e, data) {
  1529. Pagination.Extend(data);
  1530. Pagination.Create(e);
  1531. Pagination.Start();
  1532. }
  1533. };
  1534. function todo__fetchRaport(id) {
  1535. p5WFS_GetFeature('default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', {
  1536. primaryKey: id,
  1537. resolve: 'all',
  1538. resolveDepth: 3,
  1539. }).then(function (features) {
  1540. console.log('features', features)
  1541. }).catch(function (e) {
  1542. console.warn(e)
  1543. p5UI__notifyAjaxCallback({ type: 'error', msg: e })
  1544. })
  1545. }
  1546. function removeFiltersPracownicy(event, btnNode) {
  1547. event.preventDefault()
  1548. var fieldNameList = FIELD_LIST_PRACOWNICY
  1549. fieldNameList.forEach(function (fieldName) {
  1550. btnNode.form[fieldName].value = ''
  1551. })
  1552. urlFetchPracownicy(1)
  1553. }
  1554. function removeFiltersKontrahenci(event, btnNode) {
  1555. event.preventDefault()
  1556. var fieldNameList = FIELD_LIST_KONTRAHENCI
  1557. fieldNameList.forEach(function (fieldName) {
  1558. btnNode.form[fieldName].value = ''
  1559. })
  1560. urlFetchKontrahenci(1)
  1561. }
  1562. function onChangeFiltersPracownicy(event, inputNode) {
  1563. urlFetchPracownicy(1)
  1564. }
  1565. function onKeypressFiltersPracownicy(event, inputNode) {
  1566. if ("Enter" === event.key) {
  1567. event.stopPropagation()
  1568. event.preventDefault()
  1569. urlFetchPracownicy(1)
  1570. return false
  1571. }
  1572. }
  1573. function onChangeFiltersKontrahenci(event, inputNode) {
  1574. urlFetchKontrahenci(1)
  1575. }
  1576. function onKeypressFiltersKontrahenci(event, inputNode) {
  1577. if ("Enter" === event.key) {
  1578. event.stopPropagation()
  1579. event.preventDefault()
  1580. urlFetchKontrahenci(1)
  1581. return false
  1582. }
  1583. }
  1584. function loadMoreRecordFunctions(event, node, rowPK, namespace) {
  1585. var _node = node
  1586. var _rowPK = rowPK
  1587. var toShow = true
  1588. if (RECORD_MORE_FUNCTIONS_OPENED_NODE) {
  1589. if (RECORD_MORE_FUNCTIONS_OPENED_NODE === node) toShow = false
  1590. if (RECORD_MORE_FUNCTIONS_OPENED_NODE !== node) {
  1591. jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('destroy')
  1592. }
  1593. }
  1594. RECORD_MORE_FUNCTIONS_OPENED_NODE = node
  1595. // jQuery(node).popover({
  1596. // container: 'body',
  1597. // placement: 'right',
  1598. // trigger: 'click',
  1599. // template: '<div class="popover" role="tooltip" style="max-width:600px;width:440px;">' +
  1600. // '<div class="arrow"></div>' +
  1601. // '<div style="display:block;position:relative;">' +
  1602. // '<div class="popover-title">' +
  1603. // '</div>' +
  1604. // '<button type="button" class="close" onclick="return hideMoreRecordFunctionsPopover();" style="position:absolute;right:8px;top:6px;">&times;</button>' +
  1605. // '</div>' +
  1606. // '<div class="popover-content"></div>' +
  1607. // '</div>' +
  1608. // '',
  1609. // html: true,
  1610. // })
  1611. // jQuery(node).popover('show')
  1612. global.fetch(BASE_URLS + 'index.php?_route=ViewTableAjax&namespace=' + namespace + '&_task=moreFunctionsCellAjax&ID=' + rowPK, {
  1613. credentials: 'same-origin'
  1614. }).then(function (response) {
  1615. return response.json()
  1616. }).then(function (json) {
  1617. var funcListWrap = $('<div></div>')
  1618. var funcListNode = $('<ul class="list-unstyled popoverRowFunctions"></ul>').appendTo(funcListWrap)
  1619. if (_node === RECORD_MORE_FUNCTIONS_OPENED_NODE) {
  1620. if (json && 'success' === json.type && json.rowFunctions && json.rowFunctions.length > 0) {
  1621. json.rowFunctions.forEach(function(funObj) {
  1622. var funcNode = p5UI_TableAjax_generateFunctionNode(funObj, _rowPK, {ico: true, label: true});
  1623. var funcItemNode = jQuery('<li></li>')
  1624. funcItemNode.append(funcNode)
  1625. funcListNode.append(funcItemNode)
  1626. });
  1627. }
  1628. }
  1629. // jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('destroy')
  1630. jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover({
  1631. container: 'body',
  1632. placement: 'right',
  1633. trigger: 'click',
  1634. template: '<div class="popover" role="tooltip" style="max-width:600px;width:440px;">' +
  1635. '<div class="arrow"></div>' +
  1636. '<div style="display:block;position:relative;">' +
  1637. '<div class="popover-title">' +
  1638. '</div>' +
  1639. '<button type="button" class="close" onclick="return hideMoreRecordFunctionsPopover();" style="position:absolute;right:8px;top:6px;">&times;</button>' +
  1640. '</div>' +
  1641. '<div class="popover-content"></div>' +
  1642. '</div>' +
  1643. '',
  1644. html: true,
  1645. content: funcListWrap.html(),
  1646. })
  1647. jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('show')
  1648. }).catch(function (err) {
  1649. // console.log('err', err)
  1650. })
  1651. }
  1652. var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
  1653. var defaultsProps = {
  1654. ico: true,
  1655. label: false
  1656. },
  1657. props = jQuery.extend({}, defaultsProps, props);
  1658. funcNode = $('<a href="#" style="margin:0 2px;"></a>')
  1659. ;
  1660. if ('href' in funObj) funcNode.attr('href', p5Utils__format(funObj.href, [rowPK]));
  1661. if (props.ico) {
  1662. if ('ico' in funObj) funcNode.append('<span class="' + funObj.ico + '"></span>');
  1663. }
  1664. if ('onclick' in funObj) funcNode.attr('onclick', p5Utils__format(funObj.onclick, [rowPK]));
  1665. if ('title' in funObj) funcNode.attr('title', funObj.title);
  1666. if ('target' in funObj) funcNode.attr('target', funObj.target);
  1667. if (props.label) {
  1668. if ('label' in funObj) {
  1669. funcNode.append(' ' + funObj.label);
  1670. } else if ('title' in funObj) {
  1671. funcNode.append(' ' + funObj.title);
  1672. }
  1673. }
  1674. return funcNode;
  1675. };
  1676. global.p5UI_TableAjax_generateFunctionNode = p5UI_TableAjax_generateFunctionNode
  1677. $(document).ready(function(){
  1678. rootChangeForm();
  1679. detectChoiseFilter();
  1680. updateTopCounters();
  1681. });
  1682. global.hideMoreRecordFunctionsPopover = function() {
  1683. if (RECORD_MORE_FUNCTIONS_OPENED_NODE) jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('destroy')
  1684. }
  1685. global.pracownicyLoadMoreRecordFunctions = function(event, node, rowPK) {
  1686. return loadMoreRecordFunctions(event, node, rowPK, "default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY")
  1687. }
  1688. global.kontrahenciLoadMoreRecordFunctions = function(event, node, rowPK) {
  1689. return loadMoreRecordFunctions(event, node, rowPK, "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI")
  1690. }
  1691. global.removeFiltersPracownicy = removeFiltersPracownicy;
  1692. global.removeFiltersKontrahenci = removeFiltersKontrahenci;
  1693. global.onChangeFiltersPracownicy = onChangeFiltersPracownicy;
  1694. global.onKeypressFiltersPracownicy = onKeypressFiltersPracownicy;
  1695. global.onChangeFiltersKontrahenci = onChangeFiltersKontrahenci;
  1696. global.onKeypressFiltersKontrahenci = onKeypressFiltersKontrahenci;
  1697. global.checkAll = checkAll;
  1698. global.checkedChoiseItems = checkedChoiseItems;
  1699. global.catchEventCheckbox = catchEventCheckbox;
  1700. global.clearSelectedCheckbox = clearSelectedCheckbox;
  1701. global.getNameGroupById = getNameGroupById;
  1702. global.createGroupPracownicy = createGroupPracownicy;
  1703. global.createGroupKontrahenci = createGroupKontrahenci;
  1704. global.selectPage = selectPage;
  1705. global.detectChoiseFilter = detectChoiseFilter;
  1706. global.updateListIdBiAuditReaport = updateListIdBiAuditReaport;
  1707. global.deleteListIdBiAuditReaport = deleteListIdBiAuditReaport;
  1708. global.urlFetchPracownicy = urlFetchPracownicy;
  1709. global.generateBiAuditRaport = generateBiAuditRaport;
  1710. global.getAddressData = getAddressData;
  1711. global.Pagination = Pagination;
  1712. global.todo__fetchRaport = todo__fetchRaport;
  1713. global.initLocalStorage = initLocalStorage;
  1714. global.setItemLocalStorage = setItemLocalStorage;
  1715. global.getItemLocalStorage = getItemLocalStorage;
  1716. global.deleteItemLocalStorage = deleteItemLocalStorage;
  1717. global.defaultBIAuditLocalStorage = defaultBIAuditLocalStorage;
  1718. global.removeItemInArray = removeItemInArray;
  1719. global.removeItemArrayInArray = removeItemArrayInArray;
  1720. global.addPracownikToGroup = addPracownikToGroup;
  1721. global.addPracownikAllToGroup = addPracownikAllToGroup;
  1722. global.addKontrahenciToGroup = addKontrahenciToGroup;
  1723. global.addKontrahenciAllToGroup = addKontrahenciAllToGroup;
  1724. global.showViewUploadFile = showViewUploadFile;
  1725. global.parseCsvFile = parseCsvFile;
  1726. global.clearListLocalStorageByType = clearListLocalStorageByType;