Bocian.php.view.js 66 KB

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