Bocian.php.view.js 61 KB

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