Bocian.php.view.js 58 KB

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