Bocian.php.view.js 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231
  1. var DBG = DBG || 0;
  2. if (!URL_TABLE_POWIAZANIA) throw "Brak URL_TABLE_POWIAZANIA";
  3. if (!BASE_URLS) throw "Brak BASE_URLS"
  4. var RECORD_MORE_FUNCTIONS_OPENED_NODE = null;
  5. if (!FIELD_LIST_PRACOWNICY) throw "Brak FIELD_LIST_PRACOWNICY"
  6. if (!FIELD_LIST_KONTRAHENCI) throw "Brak FIELD_LIST_KONTRAHENCI"
  7. $(window).on('hashchange', function() {
  8. initLocalStorage();
  9. rootChangeForm();
  10. updateTopCounters();
  11. hideMoreRecordFunctionsPopover()
  12. });
  13. /* DATA FOR READ REAPORT */
  14. function urlFetchKontrahenciPowiazania() {
  15. // Documentation: https://github.com/github/fetch
  16. fetch(URL_FETCH_KONTRAHENCI_POWIAZANIA, {
  17. credentials: 'same-origin'
  18. })
  19. .then(function parseJSON(response) {
  20. return response.json()
  21. })
  22. .then(function(data) {
  23. var reaportItemsKontrahenciPowiazani = null;
  24. data.body.items.forEach (function(row) {
  25. reaportItemsKontrahenciPowiazani += '<tr><td><input type="checkbox" name="kontrID[]" value="'+row['ID']+'" /></td>'+
  26. '<td align="right">'+row["ID"]+'</td>';
  27. });
  28. $( "#body-reaport-kontrahenci-powiazani-tree" ).html(reaportItemsKontrahenciPowiazani);
  29. }).catch(function(error) {
  30. if(DBG) console.log('request failed', error)
  31. });
  32. }
  33. /* FORM DATA FOR GENERATAE REAPORT */
  34. /**
  35. * Load data default title reaport in storage
  36. */
  37. function loadCurrentReaportTitleInInput(idInput) {
  38. var reaportTitleValue = getItemLocalStorage("Bocian.biAuditForm.smadReaportTitle");
  39. if ( getItemLocalStorage('Bocian.biAuditForm.smadReaportTitle') === null ) {
  40. reaportTitleValue = setItemLocalStorage('Bocian.biAuditForm.smadReaportTitle', 'Default reaport');
  41. }
  42. $(idInput).val(function() {
  43. return reaportTitleValue;
  44. });
  45. }
  46. /**
  47. * Update data title reaport in storage from input
  48. */
  49. function updateLocalStorageBiAuditReaportTitle(idInput) {
  50. $(idInput).keyup(function() {
  51. delayUpdate(function(){
  52. var newValue = $(idInput).val();
  53. setItemLocalStorage('Bocian.biAuditForm.smadReaportTitle', newValue);
  54. loadCurrentReaportTitleInInput('.smad-reaport-title-pracownicy');
  55. loadCurrentReaportTitleInInput('.smad-reaport-title-kontrahenci');
  56. }, 1000 );
  57. });
  58. }
  59. /**
  60. * Load data default depth in storage
  61. */
  62. function loadCurrentDepthInInput(idInput) {
  63. var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  64. $(idInput).val(function() {
  65. return depthValue;
  66. });
  67. }
  68. /**
  69. * Update data default depth in storage
  70. */
  71. function updateLocalStorageBiAuditDepth(idInput) {
  72. $(idInput).keyup(function() {
  73. delayUpdate(function(){
  74. var newValue = $(idInput).val();
  75. var responseValue = validateValueDepth(parseInt(newValue));
  76. setItemLocalStorage('Bocian.biAuditForm.depth', responseValue);
  77. loadCurrentDepthInInput('.smad-depth');
  78. loadCurrentDepthInInput('.smad-depth-kontrahenci');
  79. // check depth value
  80. if ( parseInt(newValue) > 6 ) {
  81. // check count praconwicy/kontrahenci
  82. var formItemsPraconwicyKontrahenci = countChoiseItemsPraconwicyKontrahenci();
  83. // disable button generate reaport if not choise 'praconwicy' or 'kontrahenci'
  84. if (
  85. (formItemsPraconwicyKontrahenci.totalPracownicy === 0 && formItemsPraconwicyKontrahenci.totalKontrahenci != 0 ) ||
  86. (formItemsPraconwicyKontrahenci.totalPracownicy != 0 && formItemsPraconwicyKontrahenci.totalKontrahenci === 0 )
  87. ) {
  88. p5UI__notifyAjaxCallback({ type: 'error', msg: messageCriticalSearchData });
  89. $('.bottom--message-warning-critical-search').text(messageCriticalSearchData);
  90. if(DBG) console.log('popup i dodanie komunikatu niżej');
  91. } else {
  92. $('.bottom--message-warning-critical-search').text('');
  93. if(DBG) console.log('popup i dodanie wyczysc komunikatu ');
  94. }
  95. }
  96. }, 1000 );
  97. });
  98. }
  99. function validateValueDepth(newValue) {
  100. var value = null;
  101. value = newValue;
  102. if (parseInt(newValue) < 0) {
  103. value = 1;
  104. }
  105. if (parseInt(newValue) > 16) {
  106. value = 16;
  107. }
  108. return value;
  109. }
  110. var delayUpdate = (function() {
  111. var timer = 0;
  112. return function(callback, ms) {
  113. clearTimeout (timer);
  114. timer = setTimeout(callback, ms);
  115. };
  116. })();
  117. /**
  118. * Check count choise pracownicy/kontrahenci
  119. */
  120. function countChoiseItemsPraconwicyKontrahenci() {
  121. var countPracownicy = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  122. var countKontrahenci = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  123. var formItems = {
  124. 'totalPracownicy': ((countPracownicy) ? Object.keys(countPracownicy).length : 0),
  125. 'totalKontrahenci': ((countKontrahenci) ? Object.keys(countKontrahenci).length : 0)
  126. };
  127. return formItems;
  128. }
  129. /**
  130. * Załadowanie wybranej pozycji w select czy zwracać wyniki tylko z obiektami docelowymi onlyTarget
  131. */
  132. function loadCurrentOnlyTargetsSelect() {
  133. var analizaOnlyTargets = getItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets');
  134. $('#smad-select-target').val(analizaOnlyTargets).attr("selected", "selected");
  135. $('#smad-select-target-kontrahenci').val(analizaOnlyTargets).attr("selected", "selected");
  136. }
  137. /**
  138. * Załadowanie do storage informacji czy zwracać wyniki tylko z obiektami docelowymi
  139. */
  140. function updateLocalStorageBiAuditOnlyTargets(idSelect) {
  141. $(idSelect).change(function() {
  142. var newValue = $(idSelect).val();
  143. var responseValue = newValue;
  144. setItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets', responseValue);
  145. $('#smad-select-target').val(newValue).attr("selected", "selected");
  146. $('#smad-select-target-kontrahenci').val(newValue).attr("selected", "selected");
  147. // load in select selected option
  148. loadCurrentOnlyTargetsSelect();
  149. });
  150. }
  151. function initLocalStorage() {
  152. if (getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') === null) {
  153. setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', []);
  154. }
  155. if (getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') === null) {
  156. setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', []);
  157. }
  158. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', 0);
  159. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', 0);
  160. if (getItemLocalStorage('Bocian.biAuditForm.depth') === null) {
  161. updateLocalStorageBiAuditDepth(7);
  162. }
  163. if (getItemLocalStorage('Bocian.biAuditForm.smadReaportTitle') === null) {
  164. updateLocalStorageBiAuditReaportTitle('Default reaport');
  165. }
  166. if (getItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets') === null) {
  167. setItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets', defaultOnlyTarger);
  168. }
  169. }
  170. /**
  171. * Funkcja pozwala na wyświetlenie okienka importu
  172. */
  173. function showViewUploadFile( event, headerTitle, enumType, showCheckbox, csvFileExample ) {
  174. event.preventDefault();
  175. var enumType = enumType;
  176. if( csvFileExample !== undefined) { // przykład + instrukcja do pobrania
  177. csvFileExample = '<div><a href="'+csvFileExample+'" title="Pobierz przykład" download target="_balnk">Pobierz przykład</a></div>';
  178. }
  179. swal({
  180. title: 'Importuj plik csv',
  181. input: 'file',
  182. html: csvFileExample,
  183. inputAttributes: {
  184. 'accept': 'text/csv',
  185. 'aria-label': 'Upload csv file'
  186. },
  187. confirmButtonText: 'Importuj',
  188. preConfirm: function (file) {
  189. return new Promise(function (resolve, reject) {
  190. if (!file) {
  191. reject("Proszę wybrać plik csv");
  192. return
  193. }
  194. var input = document.querySelector('input[type="file"]');
  195. var data = new FormData()
  196. data.append('file', input.files[0])
  197. data.append('showCheckbox', showCheckbox);
  198. var responseParseFile = parseCsvFile( data, enumType );
  199. resolve('file imported')
  200. })
  201. },
  202. }).then(function (result) {
  203. if(DBG) console.log('result', result);
  204. }).catch(function (e) {
  205. if(DBG) console.log('catch: ', e);
  206. });
  207. }
  208. /**
  209. * Funkcja przekazuje dane z pliku csv do przeparsowania
  210. */
  211. function parseCsvFile( fileData, enumType ) {
  212. event.preventDefault();
  213. if(DBG) console.log( 'parseCsvFile fileData', fileData);
  214. fetch(URL_FORM_DATA_CSV_FILE_AJAX, {
  215. method: 'POST',
  216. credentials: 'same-origin',
  217. body: fileData
  218. })
  219. .then(function(response) {
  220. return response.json()
  221. }).then(function(json) {
  222. swal({
  223. title: 'Dane załadowane z pliku CSV',
  224. html: json.body.view,
  225. width: Math.round(window.innerWidth * 0.9),
  226. allowOutsideClick: false, // TODO: btn Anuluj na dole?
  227. showCloseButton: true,
  228. confirmButtonText: 'Zapisz',
  229. preConfirm: function (dataForm) {
  230. return new Promise(function (resolve, reject) {
  231. if (!dataForm) {
  232. reject("Formularz nie zawiera danych do zapisania");
  233. return
  234. }
  235. // zapisanie danych
  236. var responseSaveData = saveFormCsvFileAjaxAction(enumType);
  237. resolve('data save from form')
  238. })
  239. },
  240. }).then(function (result) {
  241. if(DBG) console.log('result', result)
  242. }).catch(function (e) {
  243. if(DBG) console.log('catch: ', e)
  244. });
  245. }).catch(function(ex) {
  246. if(DBG) console.log('parsing failed', ex);
  247. });
  248. }
  249. /**
  250. * Funkcja zapisuje dane z formularza do wgrania pliku csv
  251. */
  252. function saveFormCsvFileAjaxAction(enumType) {
  253. event.preventDefault();
  254. var formDataFrom = $("#formDataFromCsv").serialize();
  255. formDataFrom = formDataFrom.replace(/%5B/g,"[");
  256. formDataFrom = formDataFrom.replace(/%5D/g,"]");
  257. fetch(URL_SAVE_FORM_CSV_FILE_AJAX, {
  258. method: 'POST',
  259. credentials: 'same-origin',
  260. headers: {
  261. 'Content-Type': 'application/json'
  262. },
  263. body: JSON.stringify({
  264. formData: formDataFrom,
  265. enumType: enumType
  266. })
  267. })
  268. .then(function(response) {
  269. return response.json()
  270. }).then(function(json) {
  271. if(DBG) console.log('parsed json', json);
  272. if (response.type == 'success') {
  273. p5UI__notifyAjaxCallback(response.msg);
  274. }
  275. // return json;
  276. }).catch(function(ex) {
  277. if(DBG) console.log('parsing failed', ex);
  278. });
  279. }
  280. function defaultBIAuditLocalStorage() {
  281. localStorage.removeItem('Bocian.biAuditForm.pracownicyIds');
  282. localStorage.removeItem('Bocian.biAuditForm.kontrahenciIds');
  283. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', 1);
  284. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', 1);
  285. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', 0);
  286. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', 0);
  287. setItemLocalStorage('Bocian.biAuditForm.depth', 7);
  288. setItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets', defaultOnlyTarger);
  289. }
  290. function generateBiAuditRaport(event) {
  291. event.preventDefault();
  292. var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  293. var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  294. var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  295. var smadReaportTitle = getItemLocalStorage('Bocian.biAuditForm.smadReaportTitle');
  296. var analizaOnlyTargets = getItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets');
  297. // validate
  298. if(!smadReaportTitle || smadReaportTitle == '') {
  299. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie podano tytułu raportu' });
  300. }
  301. if (!depthValue || depthValue === 0) {
  302. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie podano wartości dla głębokości powiązań' });
  303. } else if ( (!pracownicyIdsArray || pracownicyIdsArray.length === 0) && (!kontrahenciIdsArray || kontrahenciIdsArray.length === 0) ) {
  304. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano pozycji do analizy' });
  305. } else {
  306. var generateReaport = true; // generuj raport
  307. // if not choise 'pracowniocy' or 'kontrahenci'
  308. if ( (!pracownicyIdsArray || pracownicyIdsArray.length === 0) || (!kontrahenciIdsArray || kontrahenciIdsArray.length === 0) ) {
  309. var messageConfirm = '';
  310. // check selected items
  311. if ( !pracownicyIdsArray || pracownicyIdsArray.length === 0 ) {
  312. messageConfirm = 'Nie wybrano osób! Czas przygotowania raportu może wydłużyć się ze względu na sprawdzenie powiązania ze wszystkimi osobami w systemie. Czy jesteś pewny? ';
  313. }
  314. if ( !kontrahenciIdsArray || kontrahenciIdsArray.length === 0 ) {
  315. messageConfirm = 'Nie wybrano podmiotów/kontrahentów! Czas przygotowania raportu może wydłużyć się ze względu na sprawdzenie powiązania ze wszystkimi podmiotami/kontrahentami w systemie. Czy jesteś pewny? ';
  316. }
  317. // show confirm window with message
  318. if (confirm(messageConfirm)) {
  319. generateReaport = true;
  320. } else { // cancel
  321. generateReaport = false;
  322. }
  323. }
  324. if (generateReaport === true) {
  325. // send
  326. window.fetch(URL_GENERATE_BI_AUDIT_RAPORT_AJAX, {
  327. method: 'POST',
  328. headers: {
  329. 'Content-Type': 'application/json'
  330. },
  331. credentials: 'same-origin',
  332. body: JSON.stringify({
  333. pracownicyIds: pracownicyIdsArray,
  334. kontrahenciIds: kontrahenciIdsArray,
  335. depthValue: depthValue,
  336. smadReaportTitle: smadReaportTitle,
  337. analizaOnlyTargets: analizaOnlyTargets
  338. })
  339. })
  340. .then(function(response) {
  341. if(DBG) console.log('Firsst then', response);
  342. return response.text();
  343. })
  344. .then(function(responseText) {
  345. try {
  346. return JSON.parse(responseText);
  347. } catch (e) {
  348. throw responseText;
  349. }
  350. })
  351. .then(function(result) {
  352. if (result.type == 'success') {
  353. p5UI__notifyAjaxCallback(result);
  354. defaultBIAuditLocalStorage();
  355. updateTopCounters();
  356. // unchecked checkbox pracownicy
  357. $('#smad-table-PRACOWNICY form').find(':checkbox').prop('checked', false);
  358. // unchecked checkbox kontrahenci
  359. $('#smad-table-KONTRAHENCI form').find(':checkbox').prop('checked', false);
  360. //
  361. $('#count-selected-item-kontrahenci').text('0');
  362. $('#count-selected-item-pracownicy').text('0');
  363. $('.bottom--message-warning-critical-search').text('');
  364. window.setTimeout(URL_TABLE_POWIAZANIA, 6000);
  365. resolve(result.msg);
  366. } else {
  367. reject(result.msg);
  368. }
  369. })
  370. .catch(function(error) {
  371. if(DBG) console.log('request failed', error);
  372. });
  373. }
  374. }
  375. }
  376. /**
  377. * Dodaj nowego pracownika
  378. */
  379. function createPracownikAjax(event) {
  380. event.preventDefault();
  381. swal({
  382. title: 'Dodaj osobę',
  383. showCancelButton: true,
  384. confirmButtonText: 'Zapisz',
  385. showLoaderOnConfirm: true,
  386. html:
  387. '<div class="form-group">'+
  388. '<input class="form-control required" id="personName" placeholder="Imię" >' +
  389. '<input class="form-control required" id="personSurname" placeholder="Nazwisko">'+
  390. '<input class="form-control required" id="personNip" placeholder="NIP">'+
  391. '<input class="form-control required" id="personPesel" placeholder="PESEL">'+
  392. '<input class="form-control required" id="personRegon" placeholder="REGON">'+
  393. '</div>',
  394. preConfirm: () => {
  395. return new Promise(function (resolve, reject) {
  396. // data from form
  397. var personName = $('#personName').val();
  398. var personSurname = $('#personSurname').val();
  399. var personNip = $('#personNip').val();
  400. var personPesel = $('#personPesel').val();
  401. var personRegon = $('#personRegon').val();
  402. //validate data from input
  403. if (!personName){
  404. reject('Proszę podać imię')
  405. return;
  406. }
  407. if (!personSurname){
  408. reject('Proszę podać nazwisko')
  409. return;
  410. }
  411. window.fetch(URL_CREATE_PRACOWNICY, {
  412. method: 'POST',
  413. header: {
  414. 'contentType': 'applications/json'
  415. },
  416. credentials: 'same-origin',
  417. body: JSON.stringify({
  418. 'personName': personName,
  419. 'personSurname': personSurname,
  420. 'personNip': personNip,
  421. 'personPesel': personPesel,
  422. 'personRegon': personRegon
  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. urlFetchPracownicy(1);
  440. }
  441. })
  442. .catch(function(error) {
  443. if(DBG) console.log('request failed', error);
  444. })
  445. })
  446. },
  447. allowOutsideClick: false
  448. }).then(function (createPerson) {
  449. if(DBG) console.log('dodanie osoby: ', createPerson);
  450. });
  451. }
  452. /**
  453. * Dodaj nowego kontrahenta
  454. */
  455. function createKontrahentAjax(event) {
  456. event.preventDefault();
  457. swal({
  458. title: 'Dodaj podmiot/kontrahenta',
  459. showCancelButton: true,
  460. confirmButtonText: 'Zapisz',
  461. showLoaderOnConfirm: true,
  462. html:
  463. '<div class="form-group">'+
  464. '<input class="form-control required" id="companyFullName" placeholder="Pelna nazwa" >' +
  465. '<input class="form-control required" id="companyShortName" placeholder="Skrócona nazwa\">'+
  466. '<input class="form-control required" id="companyNameGroup" placeholder="Nazwa grupy kapitałowej">'+
  467. '<input class="form-control required" id="companyKrs" placeholder="KRS">'+
  468. '<input class="form-control required" id="companyNip" placeholder="NIP">'+
  469. '<input class="form-control required" id="companyPesel" placeholder="PESEL">'+
  470. '<input class="form-control required" id="companyFax" placeholder="FAX">'+
  471. '<input class="form-control required" id="companyTelefon" placeholder="Telefon">'+
  472. '<input class="form-control required" id="companyMail" placeholder="Mail">'+
  473. '<input class="form-control required" id="companyStreet" placeholder="Ulica">'+
  474. '<input class="form-control required" id="companyNumberBuilding" placeholder="Numer budynku">'+
  475. '<input class="form-control required" id="companyNumberLocal" placeholder="Numer mieszkania /lokalu">'+
  476. '<input class="form-control required" id="companyPostCode" placeholder="Kod pocztowy">'+
  477. '<input class="form-control required" id="companyPlace" placeholder="Miejscowosc">'+
  478. '<input class="form-control required" id="companyCountry" placeholder="Kraj">'+
  479. '<input class="form-control required" id="companyTypeCompany" placeholder="Typ kontrahenta">'+
  480. '<input class="form-control required" id="companyTitleDocument" placeholder="Tytul dokumentu">'+
  481. '<input class="form-control required" id="companyDesc" placeholder="uwagi">'+
  482. '</div>',
  483. preConfirm: () => {
  484. return new Promise(function (resolve, reject) {
  485. // data from form
  486. var companyFullName = $('#companyFullName').val();
  487. var companyShortName = $('#companyShortName').val();
  488. var companyNameGroup = $('#companyNameGroup').val();
  489. var companyKrs = $('#companyKrs').val();
  490. var companyNip = $('#companyNip').val();
  491. var companyPesel = $('#companyPesel').val();
  492. var companyFax = $('#companyFax').val();
  493. var companyTelefon = $('#companyTelefon').val();
  494. var companyMail = $('#companyMail').val();
  495. var companyStreet = $('#companyStreet').val();
  496. var companyNumberBuilding = $('#companyNumberBuilding').val();
  497. var companyNumberLocal = $('#companyNumberLocal').val();
  498. var companyPostCode = $('#companyPostCode').val();
  499. var companyPlace = $('#companyPlace').val();
  500. var companyCountry = $('#companyCountry').val();
  501. var companyTypeCompany = $('#companyTypeCompany').val();
  502. var companyTitleDocument = $('#companyTitleDocument').val();
  503. var companyDesc = $('#companyDesc').val();
  504. //validate data from input
  505. if (!companyFullName){
  506. reject('Proszę podać pełną nazwę');
  507. return;
  508. }
  509. window.fetch(URL_CREATE_KONTRAHENCI, {
  510. method: 'POST',
  511. header: {
  512. 'contentType': 'applications/json'
  513. },
  514. credentials: 'same-origin',
  515. body: JSON.stringify({
  516. 'companyFullName': companyFullName,
  517. 'companyShortName': companyShortName,
  518. 'companyNameGroup': companyNameGroup,
  519. 'companyKrs': companyKrs,
  520. 'companyNip': companyNip,
  521. 'companyPesel': companyPesel,
  522. 'companyFax': companyFax,
  523. 'companyTelefon': companyTelefon,
  524. 'companyMail': companyMail,
  525. 'companyStreet': companyStreet,
  526. 'companyNumberBuilding': companyNumberBuilding,
  527. 'companyNumberLocal': companyNumberLocal,
  528. 'companyPostCode': companyPostCode,
  529. 'companyPlace': companyPlace,
  530. 'companyCountry': companyCountry,
  531. 'companyTypeCompany': companyTypeCompany,
  532. 'companyTitleDocument': companyTitleDocument,
  533. 'companyDesc': companyDesc
  534. })
  535. })
  536. .then(function(response) {
  537. return response.text();
  538. })
  539. .then(function(responseText) {
  540. try {
  541. return JSON.parse(responseText);
  542. } catch (e) {
  543. throw responseText;
  544. }
  545. })
  546. .then(function(result) {
  547. if (result.type == 'success') {
  548. p5UI__notifyAjaxCallback(result);
  549. resolve(result.body);
  550. urlFetchKontrahenci(1);
  551. }
  552. })
  553. .catch(function(error) {
  554. if(DBG) console.log('request failed', error);
  555. })
  556. })
  557. },
  558. allowOutsideClick: false
  559. }).then(function (createPerson) {
  560. if(DBG) console.log('dodanie podmiotu: ', createPerson);
  561. });
  562. }
  563. /**
  564. * Popup z opcja przeniesienia pracowników do innej grupy
  565. */
  566. function addPracownikToGroup(event) {
  567. event.preventDefault();
  568. var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  569. if (pracownicyIdsArray === null || !pracownicyIdsArray || !pracownicyIdsArray.length) {
  570. showTextListIdPracownikow = 'nie wybrano osób';
  571. } else {
  572. showTextListIdPracownikow = '' + pracownicyIdsArray.length + ' osób';
  573. }
  574. var arrayGroupOptions = [];
  575. var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups');
  576. // utworzenie tablicy Optionsów grupy
  577. listGroupStorage.map(function(item) {
  578. if (item.ID !== undefined) {
  579. arrayGroupOptions[item.ID] = item.NAZWA;
  580. }
  581. });
  582. swal({
  583. title: 'Dodaj do grupy',
  584. input: 'select',
  585. text: showTextListIdPracownikow,
  586. inputOptions: arrayGroupOptions,
  587. inputPlaceholder: 'Wybierz grupę',
  588. showCancelButton: true,
  589. confirmButtonText: 'Zapisz',
  590. showLoaderOnConfirm: true,
  591. preConfirm: function (idGroup) {
  592. return new Promise(function (resolve, reject) {
  593. if(DBG) console.log('idGrupy value', idGroup);
  594. if ( !pracownicyIdsArray || pracownicyIdsArray === null || pracownicyIdsArray === 'undefined' ) {
  595. reject('Wybierz pracowników');
  596. } else if ( pracownicyIdsArray.length === 0 ) {
  597. reject('Wybierz pracowników');
  598. }
  599. if (!idGroup) reject('Proszę wybrać nazwę grupy');
  600. window.fetch(URL_ADD_PRACOWNICY_TO_GROUP, {
  601. method: 'POST',
  602. header: {
  603. 'contentType': 'applications/json'
  604. },
  605. credentials: 'same-origin',
  606. body: JSON.stringify({
  607. 'idGroup': idGroup,
  608. 'pracownicyIds': getItemLocalStorage('Bocian.biAuditForm.pracownicyIds'),
  609. })
  610. })
  611. .then(function(response) {
  612. return response.text();
  613. })
  614. .then(function(responseText) {
  615. try {
  616. return JSON.parse(responseText);
  617. } catch (e) {
  618. throw responseText;
  619. }
  620. })
  621. .then(function(result) {
  622. if (result.type == 'success') {
  623. p5UI__notifyAjaxCallback(result);
  624. resolve(result.msg);
  625. } else {
  626. reject(result.msg);
  627. }
  628. })
  629. .catch(function(error) {
  630. if(DBG) console.warn('request failed', error);
  631. });
  632. })
  633. },
  634. allowOutsideClick: false
  635. }).then(function (groupPracownicyData) {
  636. //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
  637. });
  638. }
  639. function addPracownikAllToGroup(event) {
  640. event.preventDefault();
  641. var showTextListIdPracownikow = 'wszystkich pracowników pasujących do kryteriów wyszukiwania';
  642. var arrayGroupOptions = [];
  643. var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups');
  644. // utworzenie tablicy Optionsów grupy
  645. listGroupStorage.map(function(item) {
  646. if (item.ID !== undefined) {
  647. arrayGroupOptions[item.ID] = item.NAZWA;
  648. }
  649. });
  650. swal({
  651. title: 'Dodaj do grupy',
  652. input: 'select',
  653. text: showTextListIdPracownikow,
  654. inputOptions: arrayGroupOptions,
  655. inputPlaceholder: 'Wybierz grupę',
  656. showCancelButton: true,
  657. confirmButtonText: 'Zapisz',
  658. showLoaderOnConfirm: true,
  659. preConfirm: function (idGroup) {
  660. return new Promise(function (resolve, reject) {
  661. if (!idGroup) {
  662. reject('Proszę wybrać nazwę grupy');
  663. return;
  664. }
  665. var filterFields = {}
  666. var frm = document.getElementById('filtersFieldRemoveBtn-PRACOWNICY').form
  667. var fieldNameList = FIELD_LIST_PRACOWNICY
  668. fieldNameList.filter(function (fieldName) {
  669. if (!frm[fieldName] && DBG) console.log('Err missing field: "'+fieldName+'"');
  670. return (frm[fieldName]) ? true : false
  671. }).map(function (fieldName) {
  672. return [ fieldName, frm[fieldName].value ]
  673. }).filter(function (filter) {
  674. return ( filter[1].length > 0 )
  675. }).map(function (filter) {
  676. filterFields[ filter[0] ] = filter[1]
  677. })
  678. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
  679. if (filterIdGroup) filterFields[ 'filterIdGroup' ] = filterIdGroup
  680. window.fetch(URL_ADD_PRACOWNICY_TO_GROUP, {
  681. method: 'POST',
  682. header: {
  683. 'contentType': 'applications/json'
  684. },
  685. credentials: 'same-origin',
  686. body: JSON.stringify({
  687. 'idGroup': idGroup,
  688. 'type': 'filter',
  689. 'filter': filterFields,
  690. })
  691. })
  692. .then(function(response) {
  693. return response.text();
  694. })
  695. .then(function(responseText) {
  696. try {
  697. return JSON.parse(responseText);
  698. } catch (e) {
  699. throw responseText;
  700. }
  701. })
  702. .then(function(result) {
  703. if (result.type == 'success') {
  704. p5UI__notifyAjaxCallback(result);
  705. resolve(result.msg);
  706. } else {
  707. reject(result.msg);
  708. }
  709. })
  710. .catch(function(error) {
  711. if(DBG) console.log('request failed', error);
  712. });
  713. })
  714. },
  715. allowOutsideClick: false
  716. }).then(function (groupPracownicyData) {
  717. //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
  718. });
  719. }
  720. /**
  721. * Popup z opcja przeniesienia kontrahentów do innej grupy
  722. */
  723. function addKontrahenciToGroup(event) {
  724. event.preventDefault();
  725. var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  726. if (kontrahenciIdsArray === null || !kontrahenciIdsArray || !kontrahenciIdsArray.length) {
  727. showTextListIdKontrahentow = 'nie wybrano kontrahentów';
  728. } else {
  729. showTextListIdKontrahentow = '' + kontrahenciIdsArray.length + ' podmiotów/kontrahentów';
  730. }
  731. var arrayGroupOptions = [];
  732. var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups');
  733. // utworzenie tablicy Optionsów grupy
  734. listGroupStorage.map(function(item) {
  735. if (item.ID !== undefined) {
  736. arrayGroupOptions[item.ID] = item.NAZWA;
  737. }
  738. });
  739. swal({
  740. title: 'Dodaj do grupy',
  741. input: 'select',
  742. text: showTextListIdKontrahentow,
  743. inputOptions: arrayGroupOptions,
  744. inputPlaceholder: 'Wybierz grupę',
  745. showCancelButton: true,
  746. confirmButtonText: 'Zapisz',
  747. showLoaderOnConfirm: true,
  748. preConfirm: function (idGroup) {
  749. return new Promise(function (resolve, reject) {
  750. if (!idGroup) {
  751. reject('Proszę wybrać nazwę grupy');
  752. return;
  753. }
  754. if (!kontrahenciIdsArray || !kontrahenciIdsArray.length) {
  755. reject('Wybierz kontrahentów');
  756. return;
  757. }
  758. window.fetch(URL_ADD_KONTRAHENCI_TO_GROUP, {
  759. method: 'POST',
  760. header: {
  761. 'contentType': 'applications/json'
  762. },
  763. credentials: 'same-origin',
  764. body: JSON.stringify({
  765. 'idGroup': idGroup,
  766. 'kontrahenciIds': getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds'),
  767. })
  768. })
  769. .then(function(response) {
  770. return response.text();
  771. })
  772. .then(function(responseText) {
  773. try {
  774. return JSON.parse(responseText);
  775. } catch (e) {
  776. throw responseText;
  777. }
  778. })
  779. .then(function(result) {
  780. result
  781. if (result.type == 'success') {
  782. p5UI__notifyAjaxCallback(result);
  783. resolve(result.msg);
  784. } else {
  785. reject(result.msg);
  786. }
  787. })
  788. ;
  789. })
  790. },
  791. allowOutsideClick: false
  792. }).then(function (groupKontrahenciData) {
  793. //TODO: PIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
  794. });
  795. }
  796. function addKontrahenciAllToGroup(event) {
  797. event.preventDefault();
  798. var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  799. var showTextListIdKontrahentow = 'wszystkich podmotów/kontrahentów pasujących do kryteriów wyszukiwania';
  800. var arrayGroupOptions = [];
  801. var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups');
  802. // utworzenie tablicy Optionsów grupy
  803. listGroupStorage.map(function(item) {
  804. if (item.ID !== undefined) {
  805. arrayGroupOptions[item.ID] = item.NAZWA;
  806. }
  807. });
  808. swal({
  809. title: 'Dodaj do grupy',
  810. input: 'select',
  811. text: showTextListIdKontrahentow,
  812. inputOptions: arrayGroupOptions,
  813. inputPlaceholder: 'Wybierz grupę',
  814. showCancelButton: true,
  815. confirmButtonText: 'Zapisz',
  816. showLoaderOnConfirm: true,
  817. preConfirm: function (idGroup) {
  818. return new Promise(function (resolve, reject) {
  819. if (!idGroup) {
  820. reject('Proszę wybrać nazwę grupy');
  821. return;
  822. }
  823. var filterFields = {}
  824. var frm = document.getElementById('filtersFieldRemoveBtn-KONTRAHENCI').form
  825. var fieldNameList = FIELD_LIST_KONTRAHENCI
  826. fieldNameList.filter(function (fieldName) {
  827. if (!frm[fieldName] && DBG) console.log('Err missing field: "'+fieldName+'"')
  828. return (frm[fieldName]) ? true : false
  829. }).map(function (fieldName) {
  830. return [ fieldName, frm[fieldName].value ]
  831. }).filter(function (filter) {
  832. return ( filter[1].length > 0 )
  833. }).map(function (filter) {
  834. filterFields[ filter[0] ] = filter[1]
  835. })
  836. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  837. if (filterIdGroup) filterFields[ 'filterIdGroup' ] = filterIdGroup
  838. window.fetch(URL_ADD_KONTRAHENCI_TO_GROUP, {
  839. method: 'POST',
  840. header: {
  841. 'contentType': 'applications/json'
  842. },
  843. credentials: 'same-origin',
  844. body: JSON.stringify({
  845. 'idGroup': idGroup,
  846. 'type': 'filter',
  847. 'filter': filterFields,
  848. })
  849. })
  850. .then(function(response) {
  851. return response.text();
  852. })
  853. .then(function(responseText) {
  854. try {
  855. return JSON.parse(responseText);
  856. } catch (e) {
  857. throw responseText;
  858. }
  859. })
  860. .then(function(result) {
  861. if (result.type == 'success') {
  862. p5UI__notifyAjaxCallback(result);
  863. resolve(result.msg);
  864. } else {
  865. reject(result.msg);
  866. }
  867. })
  868. .catch(function(error) {
  869. if(DBG) console.log('request failed', error);
  870. });
  871. })
  872. },
  873. allowOutsideClick: false
  874. });
  875. }
  876. function removeKontrahenciFromGroup(event){
  877. event.preventDefault;
  878. var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  879. if (kontrahenciIdsArray === null || !kontrahenciIdsArray || !kontrahenciIdsArray.length) {
  880. showTextListIdKontrahentow = 'nie wybrano kontrahentów';
  881. } else {
  882. showTextListIdKontrahentow = '' + kontrahenciIdsArray.length + ' podmiotów/kontrahentów';
  883. }
  884. var groupId = localStorage.getItem("Bocian.biAuditForm.kontrahenci.filterIdGroup");
  885. var removeTitle = "Czy chcesz usunąć z "
  886. if(groupId === "0"){
  887. removeTitle+= "systemu";
  888. } else {
  889. var arrayGroupOptions = [];
  890. var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups');
  891. // utworzenie tablicy Optionsów grupy
  892. listGroupStorage.map(function(item) {
  893. if (item.ID !== undefined) {
  894. arrayGroupOptions[item.ID] = item.NAZWA;
  895. }
  896. });
  897. removeTitle+= "grupy ";
  898. removeTitle+= arrayGroupOptions[groupId];
  899. }
  900. swal({
  901. title: removeTitle,
  902. text: showTextListIdKontrahentow,
  903. showCancelButton: true,
  904. confirmButtonText: 'Submit',
  905. showLoaderOnConfirm: true,
  906. preConfirm: function () {
  907. return new Promise(function (resolve, reject) {
  908. if (!kontrahenciIdsArray || !kontrahenciIdsArray.length) {
  909. reject('Wybierz kontrahentów');
  910. return;
  911. }
  912. window.fetch(URL_REMOVE_KONTRAHENCI_FROM_GROUP, {
  913. method: 'POST',
  914. header: {
  915. 'contentType': 'applications/json'
  916. },
  917. credentials: 'same-origin',
  918. body: JSON.stringify({
  919. 'idGroup': getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup'),
  920. 'kontrahenciIds': getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds'),
  921. })
  922. })
  923. .then(function(response) {
  924. return response.text();
  925. })
  926. .then(function(responseText) {
  927. try {
  928. return JSON.parse(responseText);
  929. } catch (e) {
  930. throw responseText;
  931. }
  932. })
  933. .then(function(result) {
  934. result
  935. if (result.type == 'success') {
  936. p5UI__notifyAjaxCallback(result);
  937. resolve(result.msg);
  938. } else {
  939. reject(result.msg);
  940. }
  941. })
  942. ;
  943. })
  944. },
  945. allowOutsideClick: false
  946. }).then((result) => {
  947. });
  948. }
  949. function removePracownikFromGroup(event){
  950. event.preventDefault;
  951. var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  952. if (pracownicyIdsArray === null || !pracownicyIdsArray || !pracownicyIdsArray.length) {
  953. showTextListIdPracownikow = 'nie wybrano osób';
  954. } else {
  955. showTextListIdPracownikow = '' + pracownicyIdsArray.length + ' osób';
  956. }
  957. var groupId = localStorage.getItem("Bocian.biAuditForm.pracownicy.filterIdGroup");
  958. var removeTitle = "Czy chcesz usunąć z "
  959. if(groupId === "0"){
  960. removeTitle+= "systemu";
  961. } else {
  962. var arrayGroupOptions = [];
  963. var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups');
  964. // utworzenie tablicy Optionsów grupy
  965. listGroupStorage.map(function(item) {
  966. if (item.ID !== undefined) {
  967. arrayGroupOptions[item.ID] = item.NAZWA;
  968. }
  969. });
  970. removeTitle+= "grupy ";
  971. removeTitle+= arrayGroupOptions[groupId];
  972. }
  973. swal({
  974. title: removeTitle,
  975. text: showTextListIdPracownikow,
  976. showCancelButton: true,
  977. confirmButtonText: 'Submit',
  978. showLoaderOnConfirm: true,
  979. preConfirm: function () {
  980. return new Promise(function (resolve, reject) {
  981. if (!pracownicyIdsArray || !pracownicyIdsArrayi.length) {
  982. reject('Wybierz osoby');
  983. return;
  984. }
  985. window.fetch(URL_ADD_KONTRAHENCI_TO_GROUP, {
  986. method: 'POST',
  987. header: {
  988. 'contentType': 'applications/json'
  989. },
  990. credentials: 'same-origin',
  991. body: JSON.stringify({
  992. 'idGroup': getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup'),
  993. 'pracownicyIds': getItemLocalStorage('Bocian.biAuditForm.pracownicyIds'),
  994. })
  995. })
  996. .then(function(response) {
  997. return response.text();
  998. })
  999. .then(function(responseText) {
  1000. try {
  1001. return JSON.parse(responseText);
  1002. } catch (e) {
  1003. throw responseText;
  1004. }
  1005. })
  1006. .then(function(result) {
  1007. result
  1008. if (result.type == 'success') {
  1009. p5UI__notifyAjaxCallback(result);
  1010. resolve(result.msg);
  1011. } else {
  1012. reject(result.msg);
  1013. }
  1014. })
  1015. ;
  1016. })
  1017. },
  1018. allowOutsideClick: false
  1019. }).then((result) => {
  1020. if (result.value) {
  1021. swal({
  1022. type: 'success',
  1023. title: 'Ajax request finished!',
  1024. html: 'Submitted email: ' + result.value
  1025. })
  1026. }
  1027. });
  1028. }
  1029. function createGroupKontrahenci(event) {
  1030. event.preventDefault();
  1031. swal({
  1032. title: 'Utwórz grupę',
  1033. input: 'text',
  1034. showCancelButton: true,
  1035. confirmButtonText: 'Zapisz',
  1036. showLoaderOnConfirm: true,
  1037. preConfirm: function (NAZWA) {
  1038. return new Promise(function (resolve, reject) {
  1039. if (!NAZWA) reject('Proszę podać nazwę grupy');
  1040. window.fetch(URL_CREATE_KONTRAHENCIS_GROUP, {
  1041. method: 'POST',
  1042. header: {
  1043. 'contentType': 'applications/json'
  1044. },
  1045. credentials: 'same-origin',
  1046. body: JSON.stringify({
  1047. 'NAZWA': NAZWA
  1048. })
  1049. })
  1050. .then(function(response) {
  1051. return response.text();
  1052. })
  1053. .then(function(responseText) {
  1054. try {
  1055. return JSON.parse(responseText);
  1056. } catch (e) {
  1057. throw responseText;
  1058. }
  1059. })
  1060. .then(function(result) {
  1061. if (result.type == 'success') {
  1062. p5UI__notifyAjaxCallback(result);
  1063. resolve(result.body);
  1064. } else {
  1065. reject("Proszę podać inną nazwę grupy");
  1066. }
  1067. })
  1068. .catch(function(error) {
  1069. if(DBG) console.log('request failed', error);
  1070. })
  1071. })
  1072. },
  1073. allowOutsideClick: false
  1074. }).then(function (groupKontrahenciData) {
  1075. //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
  1076. groupsKontrahenci = '<button class="btn btn-default" title="'+groupKontrahenciData['nazwa']+'" data-group-filter="'+groupKontrahenciData['id']+'">'+groupKontrahenciData['nazwa']+'</button>';
  1077. $('#group-kontrahenci').append(groupsKontrahenci);
  1078. });
  1079. }
  1080. function createGroupPracownicy(event) {
  1081. event.preventDefault();
  1082. swal({
  1083. title: 'Utwórz grupę',
  1084. input: 'text',
  1085. showCancelButton: true,
  1086. confirmButtonText: 'Zapisz',
  1087. showLoaderOnConfirm: true,
  1088. preConfirm: function (NAZWA) {
  1089. return new Promise(function (resolve, reject) {
  1090. if (!NAZWA) reject('Proszę podać nazwę grupy');
  1091. window.fetch(URL_CREATE_PRACOWNICY_GROUP, {
  1092. method: 'POST',
  1093. header: {
  1094. 'contentType': 'applications/json'
  1095. },
  1096. credentials: 'same-origin',
  1097. body: JSON.stringify({
  1098. 'NAZWA': NAZWA
  1099. })
  1100. })
  1101. .then(function(response) {
  1102. return response.text();
  1103. })
  1104. .then(function(responseText) {
  1105. try {
  1106. return JSON.parse(responseText);
  1107. } catch (e) {
  1108. throw responseText;
  1109. }
  1110. })
  1111. .then(function(result) {
  1112. if (result.type == 'success') {
  1113. p5UI__notifyAjaxCallback(result);
  1114. resolve(result.body);
  1115. } else {
  1116. reject("Proszę podać inną nazwę grupy");
  1117. }
  1118. })
  1119. .catch(function(error) {
  1120. if(DBG) console.log('request failed', error);
  1121. })
  1122. })
  1123. },
  1124. allowOutsideClick: false
  1125. }).then(function (groupPracownicyData) {
  1126. if(DBG) console.log('grupa prac2: ', groupPracownicyData);
  1127. //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
  1128. groupsPracownicy = '<button class="btn btn-default" title="'+groupPracownicyData['nazwa']+'" data-group-filter="'+groupPracownicyData['id']+'">'+groupPracownicyData['nazwa']+'</button>';
  1129. $('#group-pracownicy').append(groupsPracownicy);
  1130. });
  1131. }
  1132. /**
  1133. * Function for load view Form pracownicy/kontrahenci
  1134. */
  1135. function rootChangeForm() {
  1136. //todo: do przeniesienia
  1137. urlFetchKontrahenciPowiazania();
  1138. var valueUrl = global.location.hash;
  1139. switch (valueUrl) {
  1140. case '#KONTRAHENCI':
  1141. $( ".container-bi_audit_form_kontrahenci_raport" ).html( VIEW_KONTRAHENCI );
  1142. urlFetchKontrahenci(1);
  1143. fetchGroupKontrahenci();
  1144. $( ".container-bi_audit_form_pracownicy_raport" ).hide();
  1145. $( ".container-bi_audit_form_kontrahenci_raport" ).show();
  1146. //parseGraph();
  1147. break;
  1148. case '#PRACOWNICY':
  1149. $( ".container-bi_audit_form_pracownicy_raport" ).html( VIEW_PRACOWNICY );
  1150. urlFetchPracownicy(1);
  1151. fetchGroupPracownicy();
  1152. $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
  1153. $( ".container-bi_audit_form_pracownicy_raport" ).show();
  1154. break;
  1155. // case '#REAPORT':
  1156. // $( ".container-bi_audit_form_raport_data" ).html( VIEW_TREE_REAPORT );
  1157. // urlFetchKontrahenciPowiazania();
  1158. // $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
  1159. // $( ".container-bi_audit_form_pracownicy_raport" ).hide();
  1160. // $( ".container-bi_audit_form_raport_data" ).show();
  1161. // break;
  1162. default:
  1163. $( ".container-bi_audit_form_pracownicy_raport" ).html( VIEW_PRACOWNICY );
  1164. urlFetchPracownicy(1);
  1165. fetchGroupPracownicy();
  1166. $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
  1167. $( ".container-training" ).hide();
  1168. $( ".container-about" ).hide();
  1169. $( ".container-bi_audit_form_pracownicy_raport" ).show();
  1170. break;
  1171. }
  1172. // pobranie defaultowego tytułu dla generowanego raportu
  1173. loadCurrentReaportTitleInInput('.smad-reaport-title-pracownicy');
  1174. loadCurrentReaportTitleInInput('.smad-reaport-title-kontrahenci');
  1175. // aktualizacja inputów defaultowego tytułu dla generowanego raportu
  1176. updateLocalStorageBiAuditReaportTitle('.smad-reaport-title-pracownicy');
  1177. updateLocalStorageBiAuditReaportTitle('.smad-reaport-title-kontrahenci');
  1178. //aktualizacja inputa głebokości powiazan
  1179. loadCurrentDepthInInput('.smad-depth');
  1180. loadCurrentDepthInInput('.smad-depth-kontrahenci');
  1181. updateLocalStorageBiAuditDepth('.smad-depth');
  1182. updateLocalStorageBiAuditDepth('.smad-depth-kontrahenci');
  1183. // aktualizacja select option czy zwracać wyniki tylko z obiektami docelowymi
  1184. updateLocalStorageBiAuditOnlyTargets('#smad-select-target');
  1185. updateLocalStorageBiAuditOnlyTargets('#smad-select-target-kontrahenci');
  1186. // load in select selected option BI_analiza_onlyTargets
  1187. loadCurrentOnlyTargetsSelect();
  1188. }
  1189. function getAddressData(objectValue) {
  1190. var objectValue = objectValue || [];
  1191. var listData = '';
  1192. if (!objectValue) {
  1193. return true;
  1194. }
  1195. objectValue.forEach (function(item) {
  1196. if (item['kodPocztowy']) { listData += '<div>kod pocztowy: ' + item['kodPocztowy'] + '<div>'; }
  1197. if (item['miejscowosc']) { listData += '<div>miejscowość: ' + item['miejscowosc'] + '<div>'; }
  1198. if (item['nrBudynku']) { listData += '<div>nr budynku: ' + item['nrBudynku'] + '<div>'; }
  1199. if (item['nrLokalu']) { listData += '<div>nr lokalu: ' + item['nrLokalu'] + '<div>'; }
  1200. if (item['typAdresu']) { listData += '<div>typ adresu: ' + item['typAdresu'] + '<div>'; }
  1201. if (item['ulica']) { listData += '<div>ulica: ' + item['ulica'] + '<div>'; }
  1202. listData += '<div>------<div>';
  1203. });
  1204. return listData;
  1205. }
  1206. /**
  1207. * Get name name group
  1208. */
  1209. function getNameGroupById(store, filterIdGroup) {
  1210. var NAZWA = '';
  1211. if (!store || filterIdGroup === 0 ) {
  1212. NAZWA = 'Wszyscy';
  1213. } else {
  1214. $(store).each(function() {
  1215. if ( parseInt(filterIdGroup) === parseInt(this.ID) ) {
  1216. NAZWA = this.NAZWA;
  1217. }
  1218. });
  1219. }
  1220. return NAZWA;
  1221. }
  1222. function urlFetchKontrahenci(page) {
  1223. hideMoreRecordFunctionsPopover()
  1224. var page = page || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page');
  1225. selectPage('KONTRAHENCI', page);
  1226. if ( page === 1) {
  1227. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', 1);
  1228. }
  1229. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  1230. var frm = document.getElementById('filtersFieldRemoveBtn-KONTRAHENCI').form
  1231. var fieldNameList = FIELD_LIST_KONTRAHENCI
  1232. var filterFields = fieldNameList.map(function (fieldName) {
  1233. return [ fieldName, frm[fieldName].value ]
  1234. }).filter(function (filter) {
  1235. return ( filter[1].length > 0 )
  1236. }).map(function (filter) {
  1237. return '' + filter[0] + '=' + filter[1]
  1238. }).join('&')
  1239. filterFields = (filterFields.length > 0) ? '&' + filterFields : ''
  1240. fetch(URL_FETCH_KONTRAHENCI + '&page=' + page + '&filterIdGroup=' + filterIdGroup + filterFields, {
  1241. credentials: 'same-origin'
  1242. })
  1243. .then(function parseJSON(response) {
  1244. return response.json()
  1245. var filterIdGroup = filterIdGroup || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  1246. })
  1247. .then(function(data) {
  1248. var listItemsKontrahenci = null;
  1249. data.body.items.forEach (function(row) {
  1250. listItemsKontrahenci += '<tr><td style="white-space:nowrap">' +
  1251. '<input style="vertical-align:top" type="checkbox" name="kontrID[]" value="'+row['ID']+'" />' +
  1252. '<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>' +
  1253. '</td>' +
  1254. '<td align="right">'+row["ID"]+'</td>'+
  1255. '<td align="right">' + ( row["Nazwa_grupy_kapitalowej"] || '' ) + '</td>' +
  1256. '<td align="right">' + ( row["Pelna_nazwa_kontrahenta"] || '' ) + '</td>' +
  1257. '<td align="right">' + ( row["Numer_kontrahenta"] || '' ) + '</td>' +
  1258. '<td align="right">' + ( row["Skrocona_Nazwa_Kontrahenta"] || '' ) + '</td>' +
  1259. '<td align="right">' + ( row["Typ_kontrahenta"] || '' ) + '</td>' +
  1260. '<td align="right">' + ( row["NIP"] || '' ) + '</td>' +
  1261. '<td align="right">' + ( row["KRS"] || '' ) + '</td>' +
  1262. '<td align="right">' + ( row["REGON"] || '' ) + '</td>' +
  1263. '<td align="right">' + ( row["PESEL"] || '' ) + '</td>' +
  1264. '<td align="right">' + ( row["Forma_prawna_dzialalnosci"] || '' ) + '</td>' +
  1265. '<td align="right">' + ( row["Ulica"] || '' ) + '</td>' +
  1266. '<td align="right">' + ( row["Numer_budynku"] || '' ) + '</td>' +
  1267. '<td align="right">' + ( row["Numer_mieszkania_lokalu"] || '' ) + '</td>' +
  1268. '<td align="right">' + ( row["Miejscowosc"] || '' ) + '</td>' +
  1269. '<td align="right">' + ( row["Kod_pocztowy"] || '' ) + '</td>' +
  1270. '<td align="right">' + ( row["Kraj"] || '' ) + '</td>' +
  1271. '<td align="right">' + ( row["Telefon"] || '' ) + '</td>' +
  1272. '<td align="right">' + ( row["Fax"] || '' ) + '</td>' +
  1273. '<td align="right">' + ( row["Mail"] || '' ) + '</td>' +
  1274. '<td align="right">' + ( row["A_ADM_COMPANY"] || '' ) + '</td>' +
  1275. '<td align="right">' + ( row["A_CLASSIFIED"] || '' ) + '</td>' +
  1276. '<td align="right">' + ( row["Dodano"] || '' ) + '</td>' +
  1277. '<td align="right">' + ( row["Podmiot_dominujacy"] || '' ) + '</td>' +
  1278. '<td align="right">' + ( row["Tytul_dokumentu"] || '' ) + '</td>' +
  1279. '<td align="right">' + ( row["ownCompany"] || '' ) + '</td>' +
  1280. '<td align="right">' + ( row["uwagi"] || '' ) + '</td></tr>';
  1281. });
  1282. if (data.body.pagination !== undefined) {
  1283. Pagination.Init(document.getElementById('pagination-kontrahenci'), {
  1284. url: BASE_URLS+'index.php?_route=UrlAction_Bocian#KONTRAHENCI',
  1285. id_pagination: 'pagination-kontrahenci',
  1286. type: 'KONTRAHENCI',
  1287. limit: data.body.pagination.limit,
  1288. total_items: data.body.pagination.total_items, // pages size
  1289. size: data.body.pagination.size, // pages size
  1290. page: page, // selected page
  1291. step: 1 // pages before and after current
  1292. });
  1293. var paginationShowNextCount = 1;
  1294. if ( parseInt(data.body.pagination.current) !== 1) {
  1295. paginationShowNextCount = parseInt(data.body.pagination.limit) * (parseInt(data.body.pagination.current) - 1 ) + 1;
  1296. }
  1297. $('#paginationShowNextCount-KONTRAHENCI').text(paginationShowNextCount);
  1298. $('#smad-filter-desc-kontrahenci').text(data.body.pagination.total_items);
  1299. if (data.body.pagination.total_items > 0) {
  1300. var btnGraphView = $('<button class="btn btn-primary smad-kontrahenci-graph-button" onClick="graphShowHide(\'kontrahenci\')" style="padding:1px 5px; margin-left:12px">GRAF POWIĄZAŃ</button>')
  1301. var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>')
  1302. btnAddAll.on('click', { pagination: data.body.pagination }, function (event) {
  1303. // event.data.pagination: { [ filter_idGroup: ... ] }
  1304. // fetch ids from request, set to LocatStorage, update selected on gui
  1305. var postData = {}
  1306. if ('filter_idGroup' in event.data.pagination && event.data.pagination['filter_idGroup']) postData['filter_idGroup'] = event.data.pagination['filter_idGroup']
  1307. Object.keys(event.data.pagination).filter(function (key) {
  1308. return ('f_' === key.substr(0, 2))
  1309. }).forEach(function (filterKey) {
  1310. var value = event.data.pagination[filterKey]
  1311. postData[filterKey] = value
  1312. })
  1313. var thisButton = $(this)
  1314. thisButton.attr('disabled', true)
  1315. thisButton.text( thisButton.text() + '...' )
  1316. p5UI__notifyAjaxCallback({ type: 'info', msg: "Pobieranie podmiotów/kontrahentów..." })
  1317. global.fetch(URL_FETCH_KONTRAHENCI_IDS_AJAX, {
  1318. credentials: 'same-origin',
  1319. method: 'POST',
  1320. headers: {
  1321. 'Content-Type': 'application/json'
  1322. },
  1323. body: JSON.stringify(postData)
  1324. })
  1325. .then(function __parseJSON(response) {
  1326. return response.json()
  1327. })
  1328. .then(function (json) {
  1329. if ('success' === json.type && json.body && json.body.ids) {
  1330. updateListIdBiAuditReaport('KONTRAHENCI', json.body.ids.map(function (id) {
  1331. return parseInt(id)
  1332. }))
  1333. jQuery('#body-kontrahenci').find('input[name="kontrID[]"]').attr('checked', true)
  1334. thisButton.attr('disabled', false)
  1335. var txt = thisButton.text()
  1336. thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
  1337. p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+json.body.ids.length+" kontrahentów" })
  1338. }
  1339. })
  1340. .catch(function (e) {
  1341. p5UI__notifyAjaxCallback({ type: 'error', msg: '' + e })
  1342. thisButton.attr('disabled', false)
  1343. var txt = thisButton.text()
  1344. thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
  1345. })
  1346. })
  1347. $('#smad-filter-desc-kontrahenci').append(btnAddAll);
  1348. $('#smad-filter-desc-kontrahenci').append(btnGraphView);
  1349. }
  1350. }
  1351. var groupSelectData = getNameGroupById(getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups'), filterIdGroup);
  1352. $('#smad-filter-head-title-kontrahenci').text(groupSelectData);
  1353. if(DBG) console.log('kontrahenci groupSelectData: ', groupSelectData);
  1354. $( "#body-kontrahenci" ).html(listItemsKontrahenci);
  1355. checkAll('KONTRAHENCI');
  1356. catchEventCheckbox('KONTRAHENCI');
  1357. checkedChoiseItems('KONTRAHENCI', getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') );
  1358. // $( ".container-bi_audit_raport" ).append( data.body.view );
  1359. if(DBG) console.log('request succeeded with JSON responseKontrahenci', data)
  1360. updateTopCounters();
  1361. }).catch(function(error) {
  1362. if(DBG) console.log('request failed', error);
  1363. })
  1364. }
  1365. function urlFetchPracownicy(page) {
  1366. hideMoreRecordFunctionsPopover()
  1367. var page = page || getItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page');
  1368. if ( page === 1) {
  1369. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', 1);
  1370. }
  1371. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
  1372. selectPage('PRACOWNICY', page);
  1373. var frm = document.getElementById('filtersFieldRemoveBtn-PRACOWNICY').form
  1374. var fieldNameList = FIELD_LIST_PRACOWNICY
  1375. var filterFields = fieldNameList.filter(function (fieldName) {
  1376. if (!frm[fieldName] && DBG) console.log('Err missing field: "'+fieldName+'"')
  1377. return (frm[fieldName]) ? true : false
  1378. }).map(function (fieldName) {
  1379. return [ fieldName, frm[fieldName].value ]
  1380. }).filter(function (filter) {
  1381. return ( filter[1].length > 0 )
  1382. }).map(function (filter) {
  1383. return '' + filter[0] + '=' + filter[1]
  1384. }).join('&')
  1385. filterFields = (filterFields.length > 0) ? '&' + filterFields : ''
  1386. var paginationLimit = 20;
  1387. /*p5WFS_GetFeature('default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1388. Object.assign({
  1389. sortBy: 'ID+D',
  1390. maxFeatures: paginationLimit,
  1391. startIndex: (page - 1) * paginationLimit,
  1392. // TODO: backRefNS, backRefPK, backRefField - TODO: from groups
  1393. // resolve: 'all',
  1394. // resolveDepth: 2
  1395. 'ogc:Filter': '<wfs:Query>' + '\n' + [
  1396. '*',
  1397. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*',
  1398. [
  1399. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object',
  1400. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row',
  1401. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object',
  1402. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI'
  1403. ].join('/')
  1404. ].map(function (fieldName) {
  1405. return '<wfs:PropertyName>' + fieldName + '</wfs:PropertyName>';
  1406. }).join('\n') + '\n' + '</wfs:Query>'
  1407. }, (filterIdGroup > 0)
  1408. ? {
  1409. backRefNS: 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1410. backRefPK: filterIdGroup,
  1411. backRefField: 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1412. }
  1413. : {}
  1414. )
  1415. ).then(function (items) {
  1416. if(DBG)console.log('p5WFS_GetFeature: items: ', items);
  1417. }).catch(function (err) {
  1418. if(DBG)console.log('p5WFS_GetFeature: err: ', err);
  1419. })*/
  1420. fetch(URL_FETCH_PRACOWNICY + '&page=' + page + '&filterIdGroup=' + filterIdGroup + filterFields, {
  1421. credentials: 'same-origin'
  1422. })
  1423. .then(function parseJSON(response) {
  1424. return response.json()
  1425. })
  1426. .then(function(data) {
  1427. var addresPerson = '';
  1428. var listItemsPracownik = null;
  1429. if(DBG) console.log('urlFetchPracownicy', data.body.items);
  1430. data.body.items.forEach (function(row) {
  1431. if (row["default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy"]) {
  1432. addresPerson = getAddressData(row["default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy"]);
  1433. }
  1434. listItemsPracownik += '<tr><td style="white-space:nowrap">' +
  1435. '<input style="vertical-align:top" type="checkbox" name="prID[]" value="'+row['ID']+'" />' +
  1436. '<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>' +
  1437. '</td>' +
  1438. '<td align="right">'+row["ID"]+'</td>' +
  1439. '<td align="right">' + ( row["imiona"] || '' ) + '</td>' +
  1440. '<td align="right">' + ( row["nazwisko"] || '' ) + '</td>' +
  1441. '<td align="right">' + ( row["nip"] || '' ) + '</td>' +
  1442. '<td align="right">' + ( row["pesel"] || '' ) + '</td>' +
  1443. '<td align="right">' + ( row["regon"] || '' ) + '</td>' +
  1444. '<td align="right">' + ( row["source"] || '' ) + '</td>' +
  1445. '<td align="right">' + ( row["jednostka_organizacyjna"] || '' ) + '</td>' +
  1446. '<td align="right">' + ( row["A_STATUS"] || '' ) + '</td>' +
  1447. '<td align="right">' + ( row["A_STATUS_INFO"] || '' ) + '</td>' +
  1448. '<td align="right">' + ( row["L_APPOITMENT_USER"] || '' ) + '</td>' +
  1449. '<td align="right">'+ addresPerson +'</td></tr>';
  1450. });
  1451. if (data.body.pagination.size) {
  1452. Pagination.Init(document.getElementById('pagination-pracownicy'), {
  1453. url: BASE_URLS+'index.php?_route=UrlAction_Bocian#PRACOWNICY',
  1454. id_pagination: 'pagination-pracownicy',
  1455. type: 'PRACOWNICY',
  1456. limit: data.body.pagination.limit,
  1457. total_items: data.body.pagination.total_items, // pages size
  1458. size: data.body.pagination.size, // pages size
  1459. page: data.body.pagination.current, // selected page
  1460. step: 1 // pages before and after current
  1461. });
  1462. var paginationShowNextCount = 1;
  1463. if ( parseInt(data.body.pagination.current) !== 1) {
  1464. paginationShowNextCount = parseInt(data.body.pagination.limit) * (parseInt(data.body.pagination.current) - 1 ) + 1;
  1465. }
  1466. $('#paginationShowNextCount-PRACOWNICY').text(paginationShowNextCount);
  1467. $('#smad-filter-desc-pracownicy').text(data.body.pagination.total_items);
  1468. if (data.body.pagination.total_items > 0) {
  1469. var btnGraphView = $('<button class="btn btn-primary smad-pracownicy-graph-button" onClick="graphShowHide(\'pracownicy\')" style="padding:1px 5px; margin-left:12px">GRAF POWIĄZAŃ</button>')
  1470. var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>')
  1471. btnAddAll.on('click', { pagination: data.body.pagination }, function (event) {
  1472. // event.data.pagination: { [ filter_idGroup: ... ] }
  1473. // fetch ids from request, set to LocatStorage, redirect to '#KONTRAHENCI'
  1474. var postData = {}
  1475. if ('filter_idGroup' in event.data.pagination && event.data.pagination['filter_idGroup']) postData['filter_idGroup'] = event.data.pagination['filter_idGroup']
  1476. Object.keys(event.data.pagination).filter(function (key) {
  1477. return ('f_' === key.substr(0, 2))
  1478. }).forEach(function (filterKey) {
  1479. var value = event.data.pagination[filterKey]
  1480. postData[filterKey] = value
  1481. })
  1482. var thisButton = $(this)
  1483. thisButton.attr('disabled', true)
  1484. thisButton.text( thisButton.text() + '...' )
  1485. p5UI__notifyAjaxCallback({ type: 'info', msg: "Pobieranie pracowników..." })
  1486. global.fetch(URL_FETCH_PRACOWNICY_IDS_AJAX, {
  1487. credentials: 'same-origin',
  1488. method: 'POST',
  1489. headers: {
  1490. 'Content-Type': 'application/json'
  1491. },
  1492. body: JSON.stringify(postData)
  1493. })
  1494. .then(function __parseJSON(response) {
  1495. return response.json()
  1496. })
  1497. .then(function (json) {
  1498. if ('success' === json.type && json.body && json.body.ids) {
  1499. updateListIdBiAuditReaport('PRACOWNICY', json.body.ids.map(function (id) {
  1500. return parseInt(id)
  1501. }))
  1502. thisButton.attr('disabled', false)
  1503. var txt = thisButton.text()
  1504. thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
  1505. p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+json.body.ids.length+" pracowników" })
  1506. window.location.hash = 'KONTRAHENCI'
  1507. }
  1508. })
  1509. .catch(function (e) {
  1510. p5UI__notifyAjaxCallback({ type: 'error', msg: '' + e })
  1511. thisButton.attr('disabled', false)
  1512. var txt = thisButton.text()
  1513. thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
  1514. })
  1515. })
  1516. $('#smad-filter-desc-pracownicy').append(btnAddAll);
  1517. $('#smad-filter-desc-pracownicy').append(btnGraphView);
  1518. }
  1519. }
  1520. // wyświetlenie wybranej grupy w naglówku nad tabela
  1521. var groupSelectData = getNameGroupById(getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups'), filterIdGroup);
  1522. $('#smad-filter-head-title-pracownicy').text(groupSelectData);
  1523. // zaladaowanie listy pracowników
  1524. $( "#body-pracownicy" ).html( listItemsPracownik);
  1525. checkAll('PRACOWNICY');
  1526. catchEventCheckbox('PRACOWNICY');
  1527. checkedChoiseItems('PRACOWNICY', getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') );
  1528. updateTopCounters();
  1529. }).catch(function(error) {
  1530. if(DBG) console.log('request failed', error)
  1531. })
  1532. }
  1533. function selectPage(type, nrPage) {
  1534. var type = type.toLowerCase();
  1535. $('#pagination-' + type + ' ul li a').each(function(index, value){
  1536. if (this.text === nrPage) {
  1537. $(this).addClass('active');
  1538. } else {
  1539. $(this).removeClass('active');
  1540. }
  1541. });
  1542. }
  1543. function checkAll(type) {
  1544. $('#checkAll-' + type).change(function() {
  1545. var valueCheckbox = null;
  1546. var checkboxes = $('form').find(':checkbox');
  1547. if($(this).prop('checked')) {
  1548. checkboxes.prop('checked', true);
  1549. //valueCheckbox = checkboxes.prop("checked");
  1550. var allValsChecked = [];
  1551. var checkedValues = $('#smad-table-' + type + ' input:checkbox:checked').map(function() {
  1552. if (this.value !== 'on') {
  1553. allValsChecked.push(parseInt(this.value));
  1554. }
  1555. }).get();
  1556. updateListIdBiAuditReaport(type, allValsChecked);
  1557. } else {
  1558. checkboxes.prop('checked', false);
  1559. var allValsUnChecked = [];
  1560. var checkedValues = $('#smad-table-' + type + ' input:checkbox:not(:checked)').map(function() {
  1561. if (this.value !== 'on') {
  1562. allValsUnChecked.push(parseInt(this.value));
  1563. }
  1564. }).get();
  1565. deleteListIdBiAuditReaport(type, allValsUnChecked);
  1566. }
  1567. // update count selected IDs
  1568. updateCountItemCheckedByType(type.toLowerCase());
  1569. });
  1570. }
  1571. /**
  1572. * Select again checkbox before selected item chekbox from storage (pracownicy/kontrahenci)
  1573. */
  1574. function checkedChoiseItems(type, store) {
  1575. updateCountItemCheckedByType(type.toLowerCase());
  1576. var idElement = 'smad-table-' + type;
  1577. // if id element exist
  1578. if (document.getElementById(idElement)) {
  1579. // if not checked
  1580. if (!store) {
  1581. return false;
  1582. }
  1583. // checked again if user selected Item (pracownicy/kontrahent)
  1584. for (i = 0; i < store.length; i++) {
  1585. $('#body-'+type.toLowerCase() +' input[type=checkbox] ').map(function(k, v) {
  1586. if ( store[i] === parseInt(this.value) ){
  1587. $(this).prop('checked', true);
  1588. }
  1589. }).get();
  1590. }
  1591. }
  1592. $('#smad-table-' + type + ' input[type=checkbox]').on( 'load', function() {
  1593. var itemsCHecked = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  1594. getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  1595. if (itemsCHecked.lenght === 0 ) {
  1596. return;
  1597. }
  1598. var valueCheckbox = null;
  1599. var checkboxes = $('form').find(':checkbox');
  1600. if($(this).prop('checked')) {
  1601. checkboxes.prop('checked', true);
  1602. var allValsChecked = [];
  1603. var checkedValues = $('#smad-table-' + type + ' input:checkbox:checked').map(function() {
  1604. if (this.value !== 'on') {
  1605. allValsChecked.push(parseInt(this.value));
  1606. }
  1607. }).get();
  1608. updateListIdBiAuditReaport(type, allValsChecked);
  1609. } else {
  1610. checkboxes.prop('checked', false);
  1611. var allValsUnChecked = [];
  1612. var checkedValues = $('#smad-table-' + type + ' input:checkbox:not(:checked)').map(function() {
  1613. if (this.value !== 'on') {
  1614. allValsUnChecked.push(parseInt(this.value));
  1615. }
  1616. }).get();
  1617. deleteListIdBiAuditReaport(type, allValsUnChecked);
  1618. }
  1619. });
  1620. }
  1621. function catchEventCheckbox(type) {
  1622. $('#smad-table-' + type + ' input[type="checkbox"]').on('change', function() {
  1623. if($(this).is(":checked")) {
  1624. var allValsChecked = [];
  1625. if (this.value !== 'on') {
  1626. allValsChecked.push(parseInt(this.value));
  1627. }
  1628. updateListIdBiAuditReaport(type, allValsChecked);
  1629. } else {
  1630. var allValsUnChecke = [];
  1631. if (this.value !== 'on') {
  1632. allValsUnChecke.push(parseInt(this.value));
  1633. }
  1634. deleteListIdBiAuditReaport(type, allValsUnChecke);
  1635. }
  1636. // update count selected IDs
  1637. updateCountItemCheckedByType(type.toLowerCase());
  1638. });
  1639. }
  1640. function clearSelectedCheckbox() {
  1641. $('#checkAll-PRACOWNICY').prop('checked', false)
  1642. $('#checkAll-KONTRAHENCI').prop('checked', false)
  1643. }
  1644. function updateListIdBiAuditReaport(type, valueArray) {
  1645. var currentStoragePracownicyIds = [];
  1646. var updateListPracownicyIds = null;
  1647. var currentStorageKontrahenciIds = [];
  1648. var updateListKontrahenciIds = null;
  1649. if ( type == 'PRACOWNICY') {
  1650. currentStoragePracownicyIds = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  1651. if(currentStoragePracownicyIds !== null) {
  1652. updateListPracownicyIds = [...new Set([...currentStoragePracownicyIds ,...valueArray])];
  1653. }
  1654. else {
  1655. updateListPracownicyIds = valueArray;
  1656. }
  1657. setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', updateListPracownicyIds);
  1658. }
  1659. if ( type == 'KONTRAHENCI') {
  1660. currentStorageKontrahenciIds = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  1661. if(currentStorageKontrahenciIds !== null) {
  1662. updateListKontrahenciIds = [...new Set([...currentStorageKontrahenciIds ,...valueArray])];
  1663. }
  1664. else {
  1665. updateListKontrahenciIds = valueArray;
  1666. }
  1667. setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', updateListKontrahenciIds);
  1668. }
  1669. }
  1670. function deleteListIdBiAuditReaport(type, valueArray) {
  1671. var currentStoragePracownicyIds = [];
  1672. var updateListPracownicyIds = null;
  1673. if ( type == 'PRACOWNICY') {
  1674. deleteItemLocalStorage('Bocian.biAuditForm.pracownicyIds', valueArray);
  1675. }
  1676. if ( type == 'KONTRAHENCI') {
  1677. deleteItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', valueArray);
  1678. }
  1679. }
  1680. // filter group detect
  1681. function fetchGroupPracownicy() {
  1682. fetch(URL_FETCH_GROUP_PRACOWNICY, {
  1683. credentials: 'same-origin'
  1684. })
  1685. .then(function parseJSON(response) {
  1686. return response.json()
  1687. })
  1688. .then(function(data) {
  1689. setItemLocalStorage('Bocian.biAuditForm.pracownicy.groups', data.body.itmesGroupPracownicy);
  1690. if (data.body.itmesGroupPracownicy === null) {
  1691. return;
  1692. }
  1693. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
  1694. var currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  1695. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', filterIdGroup);
  1696. setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
  1697. var groupsPracownicy = '';
  1698. var activeButton = '';
  1699. data.body.itmesGroupPracownicy.forEach (function(row) {
  1700. activeButton = '';
  1701. if ( filterIdGroup === parseInt(row['ID']) ) {activeButton = 'active'; $('#group-pracownicy button.active').removeClass('active');
  1702. }
  1703. groupsPracownicy += '<button class="btn btn-default '+activeButton+'" title="' + row['NAZWA'] + '" data-group-filter="' + row['ID'] + '">' + row['NAZWA'] + '</button>';
  1704. });
  1705. $("#group-pracownicy").append(groupsPracownicy);
  1706. updateCountItemCheckedByType('pracownicy');
  1707. // detect filter group
  1708. detectChoiseFilter();
  1709. }).catch(function(error) {
  1710. if(DBG) console.log('request failed', error)
  1711. });
  1712. }
  1713. function fetchGroupKontrahenci() {
  1714. fetch(URL_FETCH_GROUP_KONTRAHENCI, {
  1715. credentials: 'same-origin'
  1716. })
  1717. .then(function parseJSON(response) {
  1718. return response.json()
  1719. })
  1720. .then(function(data) {
  1721. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups', data.body.itemsGroupKontrahenci);
  1722. if (data.body.itemsGroupKontrahenci === null) {
  1723. return;
  1724. }
  1725. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  1726. var currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  1727. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', filterIdGroup);
  1728. setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
  1729. var groupsKontrahenci = '';
  1730. var activeButton = '';
  1731. data.body.itemsGroupKontrahenci.forEach (function(row) {
  1732. activeButton = '';
  1733. if ( filterIdGroup === parseInt(row['ID']) ) { activeButton = 'active'; $('#group-kontrahenci button.active').removeClass('active'); }
  1734. groupsKontrahenci += '<button class="btn btn-default '+activeButton+'" title="'+row['NAZWA']+'" data-group-filter="'+row['ID']+'">'+row['NAZWA']+'</button>';
  1735. });
  1736. $("#group-kontrahenci").append(groupsKontrahenci);
  1737. updateCountItemCheckedByType('kontrahenci');
  1738. // detect filter group
  1739. detectChoiseFilter();
  1740. if(DBG) console.log('request succeeded with JSON fetchGroupKontrahenci', data.body.itemsGroupKontrahenci);
  1741. }).catch(function(error) {
  1742. if(DBG) console.log('request failed', error)
  1743. });
  1744. }
  1745. function detectChoiseFilter() {
  1746. $('#group-kontrahenci').on('click', 'button', function(evt) {
  1747. $('#group-kontrahenci button.active').removeClass('active');
  1748. $(this).addClass('active');
  1749. // pobranie id grupy kliknietego buttonu
  1750. var filterIdGroup = $(this).attr("data-group-filter");
  1751. // aktaulna wartość zagłebienia
  1752. var currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  1753. // czy zwracać wyniki tylko z obiektami docelowymi
  1754. var analizaOnlyTargets = getItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets');
  1755. //reset LocalStorage
  1756. // defaultBIAuditLocalStorage();
  1757. // ustawienie ostaniej wartości zagłebienia przed resete
  1758. setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
  1759. // czy zwracać wyniki tylko z obiektami docelowymi
  1760. setItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets', analizaOnlyTargets);
  1761. // ustawić id grupy do sesyjnej
  1762. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', parseInt(filterIdGroup));
  1763. // wywylac funckje pobrania danych
  1764. urlFetchKontrahenci(1);
  1765. });
  1766. $('#group-pracownicy').on('click', 'button', function(e) {
  1767. e.preventDefault();
  1768. $('#group-pracownicy button.active').removeClass('active');
  1769. $(this).addClass('active');
  1770. // pobranie id grupy kliknietego buttonu
  1771. var filterIdGroup = $(this).attr("data-group-filter");
  1772. // aktaulna wartość zagłebienia
  1773. var currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  1774. //reset LocalStorage
  1775. // defaultBIAuditLocalStorage();
  1776. // ustawienie ostaniej wartości zagłebienia przed resete
  1777. setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
  1778. // ustawić id grupy do sesyjnej
  1779. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', parseInt(filterIdGroup));
  1780. // wywylac funckje pobrania danych
  1781. urlFetchPracownicy(1);
  1782. });
  1783. }
  1784. // Local storage
  1785. function setItemLocalStorage(key, array) {
  1786. localStorage.setItem(key, JSON.stringify(array));
  1787. }
  1788. function getItemLocalStorage(key) {
  1789. var retrievedData = localStorage.getItem(key);
  1790. var response = JSON.parse(retrievedData);
  1791. return response;
  1792. }
  1793. function deleteItemLocalStorage(key, itemsArray) {
  1794. var currentStorageArray = getItemLocalStorage(key);
  1795. var newStorageArray = removeItemArrayInArray(currentStorageArray, itemsArray);
  1796. setItemLocalStorage(key, newStorageArray);
  1797. }
  1798. /**
  1799. * arr - array
  1800. * item - search item
  1801. */
  1802. function removeItemInArray(arr, item) {
  1803. for(var i = arr.length; i--;) {
  1804. if(arr[i] === item) {
  1805. arr.splice(i, 1);
  1806. }
  1807. }
  1808. return arr;
  1809. }
  1810. /**
  1811. * arr - array
  1812. * item - array list items
  1813. */
  1814. function removeItemArrayInArray(arr, itemsArray) {
  1815. for(var i = arr.length; i--;) {
  1816. for(var j = itemsArray.length; j--;) {
  1817. if(arr[i] === itemsArray[j]) {
  1818. arr.splice(i, 1);
  1819. }
  1820. }
  1821. }
  1822. return arr;
  1823. }
  1824. /**
  1825. * Function show/hide graph view
  1826. */
  1827. function graphShowHide(nameSection) {
  1828. var node = $('.smad-'+nameSection+'-graph-view')
  1829. if (!node || !node.length) return;
  1830. if ('block' !== node.css('display')) {
  1831. node.show()
  1832. graphFetchData(node.get(0), nameSection)
  1833. } else {
  1834. node.hide()
  1835. }
  1836. }
  1837. function graphFetchData(node, nameSection) {
  1838. var page = page || getItemLocalStorage('Bocian.biAuditForm.'+nameSection+'.pagination.page');
  1839. if ( page === 1) {
  1840. setItemLocalStorage('Bocian.biAuditForm.'+nameSection+'.pagination.page', 1);
  1841. }
  1842. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.'+nameSection+'.filterIdGroup');
  1843. var frm = document.getElementById('filtersFieldRemoveBtn-' + nameSection.toUpperCase()).form
  1844. var fieldNameList = ('pracownicy' === nameSection) ? FIELD_LIST_PRACOWNICY : FIELD_LIST_KONTRAHENCI
  1845. var filterFields = fieldNameList.filter(function (fieldName) {
  1846. if (!frm[fieldName] && DBG) console.log('Err missing field: "'+fieldName+'"')
  1847. return (frm[fieldName]) ? true : false
  1848. }).map(function (fieldName) {
  1849. return [ fieldName, frm[fieldName].value ]
  1850. }).filter(function (filter) {
  1851. return ( filter[1].length > 0 )
  1852. })
  1853. // filterFields = (filterFields.length > 0) ? '&' + filterFields : ''
  1854. // <ogc:Filter>
  1855. // <ogc:Or>
  1856. // <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1857. // <ogc:PropertyName>A_STATUS</ogc:PropertyName>
  1858. // <ogc:Literal>*O%23MA*</ogc:Literal>
  1859. // </ogc:PropertyIsLike>
  1860. // <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1861. // <ogc:PropertyName>A_STATUS</ogc:PropertyName>
  1862. // <ogc:Literal>*ARNING</ogc:Literal>
  1863. // </ogc:PropertyIsLike>
  1864. // </ogc:Or>
  1865. // </ogc:Filter>
  1866. var ogcFilterFields = (filterFields.length > 0)
  1867. ? '<ogc:Filter><ogc:And>' + filterFields.map(function(filter) {
  1868. if ('ID' === filter[0].substr(2)) return '<ogc:PropertyIsEqualTo>' +
  1869. '<ogc:PropertyName>' + filter[0].substr(2) + '</ogc:PropertyName>' +
  1870. '<ogc:Literal>' + filter[1] + '</ogc:Literal>' +
  1871. '</ogc:PropertyIsEqualTo>';
  1872. return '<ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">' +
  1873. '<ogc:PropertyName>' + filter[0].substr(2) + '</ogc:PropertyName>' +
  1874. '<ogc:Literal>*' + filter[1] + '*</ogc:Literal>' +
  1875. '</ogc:PropertyIsLike>';
  1876. }) + '</ogc:And></ogc:Filter>'
  1877. : ''
  1878. var paginationLimit = 20;
  1879. if(DBG)console.log('graphFetchData...', {
  1880. paginationLimit: paginationLimit,
  1881. page: page,
  1882. filterIdGroup: filterIdGroup,
  1883. filterFields: filterFields,
  1884. ogcFilterFields: ogcFilterFields,
  1885. });
  1886. function refFieldsOnPathToList(typeName, fields) {
  1887. var fields = fields || []
  1888. var flatList = []
  1889. var refPathBase = [
  1890. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object',
  1891. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row',
  1892. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object'
  1893. ]
  1894. flatList.push(refPathBase.concat(typeName).join('/'))
  1895. fields.forEach(function (fieldName) {
  1896. flatList.push(refPathBase.concat(typeName, fieldName).join('/'))
  1897. })
  1898. return flatList;
  1899. }
  1900. p5WFS_GetFeature('default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1901. Object.assign({
  1902. sortBy: 'ID+D',
  1903. maxFeatures: paginationLimit,
  1904. startIndex: (page - 1) * paginationLimit,
  1905. // TODO: backRefNS, backRefPK, backRefField - TODO: from groups
  1906. // resolve: 'all',
  1907. // resolveDepth: 2
  1908. 'ogc:Filter': '<wfs:Query>' + '\n' + [
  1909. 'ID',
  1910. 'imiona',
  1911. 'nazwisko',
  1912. 'miejscowosc'
  1913. ].concat(refFieldsOnPathToList('default_db__x3A__BI_audit_KRS:BI_audit_KRS', [ 'ID', 'nazwa', 'krs', 'S_miejscowosc' ]))
  1914. .concat(refFieldsOnPathToList('default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI', [ 'ID', 'Pelna_nazwa_kontrahenta' ]))
  1915. .concat(refFieldsOnPathToList('default_db__x3A__BI_audit_MSIG:BI_audit_MSIG', [ 'ID', 'nazwa' ]))
  1916. .concat(refFieldsOnPathToList('default_db__x3A__BI_audit_CEIDG:BI_audit_CEIDG', [ 'ID', 'nazwisko', 'firma' ]))
  1917. .concat([
  1918. // '*',
  1919. // 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*',
  1920. [
  1921. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object',
  1922. 'ID'
  1923. ].join('/'),
  1924. [
  1925. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object',
  1926. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row',
  1927. 'ID'
  1928. ].join('/'),
  1929. [
  1930. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object',
  1931. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row',
  1932. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object',
  1933. 'ID'
  1934. ].join('/')
  1935. ]).map(function (fieldName) {
  1936. return '<wfs:PropertyName>' + fieldName + '</wfs:PropertyName>';
  1937. }).join('\n') + '\n' +
  1938. ( ogcFilterFields ? ogcFilterFields : '' ) +
  1939. '</wfs:Query>'
  1940. }, (filterIdGroup > 0)
  1941. ? {
  1942. backRefNS: 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1943. backRefPK: filterIdGroup,
  1944. backRefField: 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1945. }
  1946. : {}
  1947. )
  1948. ).then(function (items) {
  1949. if(DBG)console.log('p5WFS_GetFeature: items: ', items);
  1950. graphRender(node, {
  1951. msg: "Pobrano dane",
  1952. typeName: ('pracownicy' === nameSection) ? 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY' : 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  1953. items: items
  1954. })
  1955. }).catch(function (err) {
  1956. if(DBG)console.log('p5WFS_GetFeature: err: ', err);
  1957. // graphRender(node, { msg: "Wystąpiły błędy podczas pobierania danych", nameSection: nameSection, err: err })
  1958. })
  1959. }
  1960. function graphRender(wrapNode, props) {
  1961. var svgNode = jQuery(wrapNode).children('svg')
  1962. svgNode = (svgNode.length) ? d3.select(svgNode.get(0)) : d3.select(wrapNode).append("svg")
  1963. // svg.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill","white").attr('class','background').on('mouseup', () => redraw())
  1964. // svgNode.attr("width", '100%')
  1965. // .attr("height", '300px')
  1966. // .append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
  1967. // var data = parseGraphRec(props.items, props.nameSection)
  1968. var _todoGraphData = [];
  1969. parseResponseRec(_todoGraphData, props.items, props.typeName)
  1970. if(DBG)console.log('_todoGraphData', _todoGraphData)
  1971. var _nodes = [];
  1972. var _links = [];
  1973. var mapNodeIdToIdx = {};
  1974. _todoGraphData.forEach(function (levelData, levelIdx) {
  1975. if (levelData.nodes && levelData.nodes.length) {
  1976. levelData.nodes.forEach(function (node) {
  1977. try {
  1978. if (node.id in mapNodeIdToIdx) return;
  1979. _nodes.push(node) // _nodes.add(node)
  1980. mapNodeIdToIdx[node.id] = _nodes.length - 1
  1981. } catch (e) {
  1982. if(DBG)console.log('_graphData.nodes.add [level='+levelIdx+'] error:', e);
  1983. }
  1984. })
  1985. }
  1986. })
  1987. var linkIdsAdded = []
  1988. _todoGraphData.forEach(function (levelData, levelIdx) {
  1989. if (levelData.edges && levelData.edges.length) {
  1990. levelData.edges.forEach(function (edge) {
  1991. if(DBG)console.log('_graphData.edges.add [level='+levelIdx+']:', {edge, source:mapNodeIdToIdx[edge.source], target:mapNodeIdToIdx[edge.target], mapNodeIdToIdx});
  1992. // try {
  1993. // var source = mapNodeIdToIdx[edge.source]
  1994. // var target = mapNodeIdToIdx[edge.target]
  1995. // if (!source || !target) { // && !== 0
  1996. // console.warn('(!source || !target)', {source, target, edge, mapNodeIdToIdx})
  1997. // }
  1998. if (-1 !== linkIdsAdded.indexOf(edge.id)) return
  1999. // _links.push({
  2000. // id: edge.id,
  2001. // source: mapNodeIdToIdx[edge.source],
  2002. // target: mapNodeIdToIdx[edge.target],
  2003. // value: 1
  2004. // })
  2005. _links.push({
  2006. id: edge.id,
  2007. source: edge.source,
  2008. target: edge.target,
  2009. value: 1
  2010. }) // _edges.add(edge)
  2011. linkIdsAdded.push(edge.id)
  2012. // } catch (e) {
  2013. // if(DBG)console.log('_graphData.edges.add [level='+levelIdx+'] error:', e);
  2014. // }
  2015. })
  2016. }
  2017. })
  2018. var totalLinks = _links.length
  2019. // console.log('DBG:0: _links', _links)
  2020. // console.log('DBG:1: _nodes', _nodes)
  2021. _nodes = _nodes.filter(function (node, idx) {
  2022. if (node.typeName !== props.typeName) return true
  2023. for (i=0; i<totalLinks; i++) {
  2024. var link = _links[i]
  2025. if (_links[i].source === node.id) return true
  2026. if (_links[i].target === node.id) return true
  2027. }
  2028. return false
  2029. })
  2030. // console.log('DBG:2: _nodes', _nodes)
  2031. jQuery(wrapNode).find('p').remove()
  2032. if (!_nodes || !_nodes.length) {
  2033. jQuery(wrapNode).find('svg').remove()
  2034. jQuery(wrapNode).append('<p>Brak powiązań</p>')
  2035. return;
  2036. }
  2037. var graphData = { nodes: _nodes, links: _links };
  2038. var graf = renderGraph(svgNode, graphData, {
  2039. width: jQuery(wrapNode).width()
  2040. })
  2041. graf.on('click', (event) => {
  2042. if(DBG)console.log('event', event)
  2043. // event = {
  2044. // nativeEvent: d3.event,
  2045. // node: a,
  2046. // element: d3.event.srcElement
  2047. // }
  2048. // TODO: !a.expanded && redraw({type: a.name, criteria: 'ID'})
  2049. })
  2050. }
  2051. function parseGraphRec(items, featureType, parentFeatureId) {
  2052. var parentFeatureId = parentFeatureId || null
  2053. var nodesArray = []
  2054. var linksArray = []
  2055. if (!items) return;
  2056. items.forEach(function (item) {
  2057. if ('string' === typeof item) {
  2058. if(DBG)console.log('TODO: xlink "'+item+'": ', {item:item, parentFeatureId:parentFeatureId})
  2059. return;
  2060. }
  2061. if (!item['ID']) {
  2062. if(DBG)console.log('TODO: SKIP item('+featureType+') - missing ID: ', {item:item, parentFeatureId:parentFeatureId})
  2063. return;
  2064. }
  2065. var id = item['ID']
  2066. console.log('item('+featureType+'): ', {item:item, parentFeatureId:parentFeatureId})
  2067. var featureId = featureType + '.' + id
  2068. Object.keys(item).filter(function (fieldName) { return ('ID' !== fieldName); })
  2069. .forEach(function (fieldName) {
  2070. parseGraphRec(item[fieldName], fieldName, featureId)
  2071. })
  2072. })
  2073. // items.forEach(element => {
  2074. // const rowObject = hasTargetArray(element);
  2075. // if (rowObject)
  2076. // rowObject.array.forEach(objectElement => {
  2077. // const trackNode = hasTargetArray(objectElement);
  2078. // if (trackNode) {
  2079. // let group = trackNode.name;
  2080. // let expanded = false;
  2081. // if (expansion && expansion.type && group === expansion.type) {
  2082. // group = trackNode.array[0][expansion.criteria];
  2083. // expanded = true;
  2084. // }
  2085. // nodes[group] = {expanded: expanded, type: trackNode.name};
  2086. // instanceTypes[trackNode.array[0].ID] = group;
  2087. // }
  2088. // });
  2089. // });
  2090. return {
  2091. nodes: nodesArray,
  2092. links: linksArray
  2093. }
  2094. }
  2095. function parseResponseRec(_todoGraphData, json, typeName, parentNodeId, level) {
  2096. var level = level || 0
  2097. var parentNodeId = parentNodeId || null
  2098. if(DBG)console.log('DBG::parseResponseRec', {json:json, typeName:typeName, parentNodeId:parentNodeId, isString: p5Utils__isString(json), isArray: p5Utils__isArray(json), isObject: p5Utils__isObject(json)});
  2099. if (p5Utils__isArray(json)) {
  2100. // TODO: create named group
  2101. var isXlinkList = (json.length > 0 && p5Utils__isString(json[0]))
  2102. json.forEach(function (subJson) {
  2103. if (isXlinkList) {
  2104. parseResponseXlinkListRec(_todoGraphData, subJson, typeName, parentNodeId, level)
  2105. } else {
  2106. parseResponseRec(_todoGraphData, subJson, typeName, parentNodeId, level)
  2107. }
  2108. })
  2109. } else if (p5Utils__isObject(json) && isP5LinkObject(json)) {
  2110. if(DBG)console.log('DBG::parseResponseRec isP5LinkObject');
  2111. parseResponseP5Link(_todoGraphData, json, typeName, parentNodeId, level)
  2112. } else if (p5Utils__isObject(json)) {
  2113. // _todoGraphData.nodes.add({ id: nodeId, label: nodeId })
  2114. if (!_todoGraphData[level]) _todoGraphData[level] = { nodes: [], edges: [] }
  2115. var nodeObject = dataMakeNode({
  2116. typeName: typeName,
  2117. primaryKey: (json['ID']) ? json['ID'] : null, // TODO: get primaryKey from object
  2118. row: json,
  2119. })
  2120. var nodeId = nodeObject.id
  2121. if ("default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row" === typeName) {
  2122. parseResponseRec__row(_todoGraphData, json, typeName, parentNodeId, level)
  2123. }
  2124. else if ("default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object" === typeName) {
  2125. // parseResponseRec__row_object(_todoGraphData, json, typeName, parentNodeId, level)
  2126. Object.keys(json).filter(function (fieldName) {
  2127. return (fieldName.indexOf(':') > -1)
  2128. })
  2129. .forEach(function (fieldName) {
  2130. var value = json[fieldName]
  2131. parseResponseRec(_todoGraphData, value, fieldName, parentNodeId, level + 1)
  2132. })
  2133. }
  2134. else {
  2135. _todoGraphData[level].nodes.push(nodeObject)
  2136. if (parentNodeId) {
  2137. _todoGraphData[level].edges.push(dataMakeEdge(parentNodeId, nodeObject))
  2138. }
  2139. Object.keys(json).filter(function (fieldName) {
  2140. return (fieldName.indexOf(':') > -1)
  2141. })
  2142. .forEach(function (fieldName) {
  2143. var value = json[fieldName]
  2144. parseResponseRec(_todoGraphData, value, fieldName, nodeId, level + 1)
  2145. })
  2146. }
  2147. } else if (p5Utils__isString(json)) {
  2148. if(DBG)console.log('TODO: Not implemented - parseResponseRec isString');
  2149. } else {
  2150. if(DBG)console.log('TODO: Not implemented - parseResponseRec is not string, not array and not object');
  2151. }
  2152. }
  2153. function parseResponseXlinkListRec(_todoGraphData, json, typeName, parentNodeId, level) {
  2154. if(DBG)console.log('DBG::parseResponseRec:XlinkList', {json:json, typeName:typeName, parentNodeId:parentNodeId, isString: p5Utils__isString(json), isArray: p5Utils__isArray(json), isObject: p5Utils__isObject(json)});
  2155. if (p5Utils__isString(json)) { // xlink "https://biuro.biall-net.pl/wfs/default_db/BI_audit_ENERGA_RUM_KONTRAHENCI#BI_audit_ENERGA_RUM_KONTRAHENCI.9233",
  2156. var nodeId = json.substr(json.indexOf('#') + 1)
  2157. {
  2158. // _graphData.nodes.add({ id: nodeId, label: nodeId })
  2159. if (!_todoGraphData[level]) _todoGraphData[level] = { nodes: [], edges: [] }
  2160. var nodeObject = dataMakeXlinkNode({
  2161. xlink: json,
  2162. typeName: typeName,
  2163. })
  2164. _todoGraphData[level].nodes.push(nodeObject)
  2165. if (parentNodeId) {
  2166. _todoGraphData[level].edges.push(dataMakeEdge(parentNodeId, nodeObject))
  2167. }
  2168. }
  2169. } else if (p5Utils__isObject(json) && isP5LinkObject(json)) {
  2170. parseResponseP5Link(_todoGraphData, json, typeName, parentNodeId, level)
  2171. } else {
  2172. if(DBG)console.log('TODO: Not implemented - parseResponseRec:XlinkList is not string and not object');
  2173. }
  2174. }
  2175. function parseResponseP5Link(_todoGraphData, json, typeName, parentNodeId, level) {
  2176. if(DBG)console.log('parseResponseRec isObject and P5Link - fetch more xlink object');
  2177. // example json: { type: "next",
  2178. // @backRefNS: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA",
  2179. // @backRefPK: "42",
  2180. // @typeName: "default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_P…ow:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row",
  2181. // @startIndex: "10" }
  2182. if (!parentNodeId) throw "Missing parentNodeId for ref link object";
  2183. var objectName = typeName.substr(typeName.indexOf(':') + 1)
  2184. {
  2185. // _graphData.nodes.add({ id: nodeId, label: nodeId })
  2186. if (!_todoGraphData[level]) _todoGraphData[level] = { nodes: [], edges: [] }
  2187. switch (json.type) {
  2188. case 'next': {
  2189. // TODO: add fetch next node
  2190. // var nodeObject = dataMakeFetchMoreNode({
  2191. // parentNodeId: parentNodeId,
  2192. // type: json.type,
  2193. // objectName: objectName,
  2194. // ref: json,
  2195. // })
  2196. // _todoGraphData[level].nodes.push(nodeObject)
  2197. // _todoGraphData[level].edges.push(dataMakeFetchMoreEdge(parentNodeId, nodeObject))
  2198. } break;
  2199. default: {
  2200. if(DBG)console.log('TODO: Not implemented - parseResponseRec isObject with type "'+json.type+'" - fetch more xlink object');
  2201. }
  2202. }
  2203. }
  2204. }
  2205. function parseResponseRec__row(_todoGraphData, json, typeName, parentNodeId, level) {
  2206. var nodeObject = dataMakeNode({
  2207. typeName: typeName,
  2208. primaryKey: (json['ID']) ? json['ID'] : null, // TODO: get primaryKey from object
  2209. })
  2210. var nodeId = nodeObject.id
  2211. // 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row',
  2212. // 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object',
  2213. // 'default_db__x3A__BI_audit_KRS:BI_audit_KRS' --> Kontrahenci
  2214. var rowObjectChildrens = []
  2215. var rowTN = 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row'
  2216. var rowObjTN = 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object'
  2217. // { row: row_obj: [ { ID, kontr: [ "http...kontr.ID" ] }, { ID, kontr: [ "http...krs.ID" ] } ], ... }
  2218. var rowJson = json
  2219. if (rowJson[rowObjTN] && rowJson[rowObjTN].length > 1) {
  2220. var pathItems = []
  2221. rowJson[rowObjTN].forEach(function (rowObjJson) {
  2222. Object.keys(rowObjJson)
  2223. .filter(function (rowObjFld) { return (-1 !== rowObjFld.indexOf(':')); })
  2224. .filter(function (rowObjRefFld) { return (rowObjJson[rowObjRefFld] && rowObjJson[rowObjRefFld].length); })
  2225. .forEach(function (rowObjRefFld) {
  2226. pathItems.push([ rowObjRefFld, rowObjJson[rowObjRefFld][0] ])
  2227. })
  2228. })
  2229. }
  2230. // console.log('node('+nodeId+') pathItems:', pathItems);
  2231. var lastParentFid = null
  2232. pathItems.reverse().forEach(function (pathItem) {
  2233. var nodeObject = ('string' === typeof pathItem[1])
  2234. ? dataMakeXlinkNode({
  2235. xlink: pathItem[1],
  2236. typeName: pathItem[0]
  2237. })
  2238. : dataMakeNode({
  2239. typeName: pathItem[0],
  2240. primaryKey: (pathItem[1]['ID']) ? pathItem[1]['ID'] : null,
  2241. row: pathItem[1]
  2242. })
  2243. ;
  2244. // _todoGraphData[todoLevel].nodes.push(nodeObject) // already added below
  2245. if (lastParentFid) _todoGraphData[level].edges.push(dataMakeEdge(lastParentFid, nodeObject))
  2246. lastParentFid = nodeObject.id
  2247. })
  2248. Object.keys(json).filter(function (fieldName) {
  2249. return (fieldName.indexOf(':') > -1)
  2250. })
  2251. .forEach(function (fieldName) {
  2252. var value = json[fieldName]
  2253. parseResponseRec(_todoGraphData, value, fieldName, parentNodeId, level + 1)
  2254. })
  2255. }
  2256. function isP5LinkObject(json) {
  2257. if ( !('type' in json) || !json['type'] ) return false;
  2258. if ( !('value' in json) || !json['value'] ) return false;
  2259. if ( !('@typeName' in json) || !json['@typeName'] ) return false;
  2260. if ( !('@startIndex' in json) || !json['@startIndex'] ) return false;
  2261. if ( !('@backRefPK' in json) || !json['@backRefPK'] ) return false;
  2262. if ( !('@backRefNS' in json) || !json['@backRefNS'] ) return false;
  2263. return true;
  2264. }
  2265. function dataMakeNode(params) {
  2266. var objectName = params.typeName.substr(params.typeName.indexOf(':') + 1)
  2267. var nodeId = objectName + '.' + params.primaryKey // TODO: primaryKey?
  2268. var graphNode = {
  2269. id: nodeId,
  2270. name: nodeId,
  2271. group: objectName,
  2272. _loaded: true,
  2273. typeName: params.typeName,
  2274. primaryKey: params.primaryKey // TODO: _primaryKey
  2275. }
  2276. if (params.row) graphNode.row = params.row
  2277. return graphAddNodeLabel(graphNode)
  2278. }
  2279. function dataMakeEdge(parentNodeId, nodeObject) {
  2280. return {
  2281. id: parentNodeId + nodeObject.id,
  2282. source: parentNodeId,
  2283. target: nodeObject.id,
  2284. }
  2285. }
  2286. function dataMakeXlinkNode(params) {
  2287. var objectName = params.typeName.substr(params.typeName.indexOf(':') + 1)
  2288. var nodeId = params.xlink.substr(params.xlink.indexOf('#') + 1)
  2289. var primaryKey = nodeId.substr(nodeId.lastIndexOf('.') + 1)
  2290. var graphNode = {
  2291. id: nodeId,
  2292. name: nodeId,
  2293. group: objectName,
  2294. _loaded: false,
  2295. typeName: params.typeName,
  2296. primaryKey: primaryKey
  2297. }
  2298. return graphAddNodeLabel(graphNode)
  2299. }
  2300. function dataMakeFetchMoreNode(params) {
  2301. // params = {
  2302. // parentNodeId: parentNodeId,
  2303. // type: json.type,
  2304. // objectName: objectName,
  2305. // ref: json,
  2306. // }
  2307. if(DBG)console.log('DBG dataMakeFetchMoreNode(params)', params)
  2308. var nodeId = params.parentNodeId+'fetch-more-features-'+params.type+'-on-' + params.objectName;
  2309. return {
  2310. id: nodeId,
  2311. label: 'Pobierz więcej (+)',
  2312. group: 'fetch-more-data', // params.objectName,
  2313. _loaded: false,
  2314. _type: 'ref',
  2315. parentNodeId: params.parentNodeId,
  2316. ref: params.ref,
  2317. // typeName: typeName,
  2318. // primaryKey: nodeId.substr(nodeId.lastIndexOf('.') + 1)
  2319. };
  2320. }
  2321. function dataMakeFetchMoreEdge(parentNodeId, fetchMoreNode) {
  2322. // @param parentNodeId - from node id
  2323. // @param fetchMoreNode - from dataMakeFetchMoreNode
  2324. if(DBG)console.log('DBG dataMakeFetchMoreEdge(parentNodeId, fetchMoreNode)', {parentNodeId:parentNodeId, fetchMoreNode:fetchMoreNode})
  2325. return {
  2326. id: fetchMoreNode.id,
  2327. from: parentNodeId,
  2328. to: fetchMoreNode.id
  2329. }
  2330. }
  2331. function makeShortLabel(label) { // TODO: shorter name
  2332. // BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1234567
  2333. if (label.length < 30) return label;
  2334. var exLabel = label.split('.')
  2335. if (exLabel.length !== 2) return label;
  2336. return exLabel[0].substr(0, 24) + '...' + exLabel[0].substr(-10) + '.' + exLabel[1];
  2337. }
  2338. function graphAddNodeLabel(graphNode) {
  2339. // var graphNode = {
  2340. // id: nodeId,
  2341. // name: nodeId,
  2342. // group: objectName,
  2343. // _loaded: true,
  2344. // typeName: params.typeName,
  2345. // primaryKey: params.primaryKey // TODO: _primaryKey
  2346. // }
  2347. var label = graphNode.id // TODO: get from schema assert @label attribute
  2348. label = makeShortLabel(graphNode.id)
  2349. switch (graphNode.typeName) {
  2350. case 'default_db__x3A__BI_audit_KRS:BI_audit_KRS': {
  2351. // <xs:assert test="@default_db__x3A__BI_audit_KRS:label = concat(nazwa, ' ', krs, ' ', S_miejscowosc)" id="I_audit_KRS___d6e76977-1">
  2352. if (graphNode.row) label = [graphNode.row.nazwa, graphNode.row.krs, graphNode.row.S_miejscowosc].filter(function (val) { return val; }).join(' ');
  2353. label = (label) ? label : makeShortLabel(graphNode.id)
  2354. label = label + ' (krs)'
  2355. } break;
  2356. case 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY': {
  2357. // <xs:assert id="_PRACOWNICY___d6e76324-1" test="@label = concat(imiona, ' ', nazwisko, ' ', miejscowosc)"/>
  2358. if (graphNode.row) label = [graphNode.row.imiona, graphNode.row.nazwisko, graphNode.row.miejscowosc].filter(function (val) { return val; }).join(' ');
  2359. label = (label) ? label : makeShortLabel(graphNode.id)
  2360. label = label + ' (pracownicy)'
  2361. } break;
  2362. case 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI': {
  2363. // <xs:assert id="KONTRAHENCI___d6e76526-1" test="@label = concat(substr(Pelna_nazwa_kontrahenta, 0, 20, '\n umów na kwotę ', @sum))"/>
  2364. if (graphNode.row) label = [graphNode.row.Pelna_nazwa_kontrahenta].filter(function (val) { return val; }).join(' ');
  2365. label = (label) ? label : makeShortLabel(graphNode.id)
  2366. label = label + ' (kontrahent)'
  2367. } break;
  2368. case 'default_db__x3A__BI_audit_CEIDG:BI_audit_CEIDG': {
  2369. // <xs:assert test="@label = concat(nazwisko, substring(firma, 1, 20))"/>
  2370. if (graphNode.row) label = [graphNode.row.nazwisko, graphNode.row.firma].filter(function (val) { return val; }).join(' ');
  2371. label = (label) ? label : makeShortLabel(graphNode.id)
  2372. label = label + ' (ceidg)'
  2373. } break;
  2374. case 'default_db__x3A__BI_audit_MSIG:BI_audit_MSIG': {
  2375. // <xs:assert test="@label = substring(nazwa, 1, 20)"/>
  2376. if (graphNode.row) label = [graphNode.row.nazwa].filter(function (val) { return val; }).join(' ');
  2377. label = (label) ? label : makeShortLabel(graphNode.id)
  2378. label = label + ' (msig)'
  2379. } break;
  2380. }
  2381. return Object.assign(graphNode, {
  2382. label: label,
  2383. })
  2384. }
  2385. /**
  2386. * Cleart list local storage by type
  2387. * typeNameLocalStorage - name (praconwicy/kontrahenci)
  2388. */
  2389. function clearListLocalStorageByType(typeNameLocalStorage) {
  2390. if (typeNameLocalStorage === 'pracownicy') {
  2391. setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', []);
  2392. }
  2393. if (typeNameLocalStorage === 'kontrahenci') {
  2394. setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', []);
  2395. }
  2396. // update count selected item
  2397. updateCountItemCheckedByType(typeNameLocalStorage);
  2398. // unchecked checkbox
  2399. $('#smad-table-'+typeNameLocalStorage.toUpperCase()+' form').find(':checkbox').prop('checked', false);
  2400. }
  2401. /**
  2402. * Update count selected pracowniyc/kontrahenci
  2403. */
  2404. function updateCountItemCheckedByType(typeNameLocalStorage) {
  2405. var countId = 0;
  2406. updateTopCounters();
  2407. if (typeNameLocalStorage === 'pracownicy') {
  2408. var countPracownicy = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  2409. if (countPracownicy === null || countPracownicy === undefined) {
  2410. return countId;
  2411. }
  2412. countId = Object.keys(countPracownicy).length;
  2413. $('#count-selected-item-pracownicy').text(countId);
  2414. }
  2415. if (typeNameLocalStorage === 'kontrahenci') {
  2416. var countKontrahenci = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  2417. if (countKontrahenci === null || countKontrahenci === undefined) {
  2418. return countId;
  2419. }
  2420. countId = Object.keys(countKontrahenci).length;
  2421. $('#count-selected-item-kontrahenci').text(countId);
  2422. }
  2423. return countId;
  2424. }
  2425. function updateTopCounters() {
  2426. var countPracownicy = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  2427. var countKontrahenci = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  2428. var totalPracownicy = (countPracownicy) ? Object.keys(countPracownicy).length : 0;
  2429. var totalKontrahenci = (countKontrahenci) ? Object.keys(countKontrahenci).length : 0;
  2430. var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  2431. if(DBG) console.warn({totalPracownicy: totalPracownicy, totalKontrahenci: totalKontrahenci})
  2432. $('.top--count-selected-item-pracownicy').text(totalPracownicy ? '('+totalPracownicy+')' : '');
  2433. $('.top--count-selected-item-kontrahenci').text(totalKontrahenci ? '('+totalKontrahenci+')' : '');
  2434. $('.bottom--count-selected-item-pracownicy').text(totalPracownicy ? "Wybrano: (" + totalPracownicy + ") osób" : '');
  2435. $('.bottom--count-selected-item-kontrahenci').text(totalKontrahenci ? "Wybrano: (" + totalKontrahenci + ") podmiotów/kontrahentaów" : '');
  2436. // disable button generate reaport if not choise 'praconwicy' or 'kontrahenci'
  2437. if ( totalPracownicy === 0 && totalKontrahenci === 0 ) {
  2438. $('.smad-generate-reaport-button').addClass('disabled');
  2439. } else {
  2440. if ( ( totalPracownicy === 0 || totalKontrahenci === 0 ) && parseInt(depthValue) > 6) {
  2441. $('.bottom--message-warning-critical-search').text(messageCriticalSearchData);
  2442. if(DBG) console.log('dodanie komunikatu niżej');
  2443. } else {
  2444. if(DBG) console.log('wyczyc komunikatu niżej');
  2445. $('.bottom--message-warning-critical-search').text('');
  2446. }
  2447. $('.smad-generate-reaport-button').removeClass('disabled');
  2448. }
  2449. }
  2450. // Pagination
  2451. var Pagination = {
  2452. code: '', // end show html paginations
  2453. clickPage: 1, // set default 1 page
  2454. // --------------------
  2455. // Utility
  2456. // --------------------
  2457. // initialize default data
  2458. Extend: function(data) {
  2459. data = data || {};
  2460. Pagination.url = data.url;
  2461. Pagination.id_pagination = data.id_pagination;
  2462. Pagination.type = data.type;
  2463. Pagination.limit = data.limit;
  2464. Pagination.total_items = data.total_items;
  2465. Pagination.size = data.size || 2;
  2466. Pagination.page = data.page || 1;
  2467. Pagination.step = data.step || 3;
  2468. },
  2469. // add pages by number (from [s] to [f])
  2470. Add: function(s, f) {
  2471. for (var i = s; i < f; i++) {
  2472. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">' + i + '</a></li>';
  2473. }
  2474. },
  2475. // add last page with separator
  2476. Last: function() {
  2477. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">>></a></li>';
  2478. },
  2479. // add first page with separator
  2480. First: function() {
  2481. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default"><<</a></li>';
  2482. },
  2483. // add last page with separator
  2484. Next: function() {
  2485. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">></a></li>';
  2486. },
  2487. // add first page with separator
  2488. Prev: function() {
  2489. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default"><</a></li>';
  2490. },
  2491. // --------------------
  2492. // Handlers
  2493. // --------------------
  2494. // change page
  2495. Click: function() {
  2496. clearSelectedCheckbox();
  2497. var selectPage = $("#pagination-"+Pagination.type.toLowerCase()+' .tblAjax__footer__toolbar__pagination').find('a.active').text();
  2498. Pagination.clickPage = +this.innerHTML || '';
  2499. if ( selectPage === NaN || selectPage > Pagination.size) { selectPage = 1; }
  2500. switch (this.innerHTML) {
  2501. case '&gt;&gt;': // last
  2502. Pagination.clickPage = Pagination.size;
  2503. break;
  2504. case '&lt;&lt;': // first
  2505. Pagination.clickPage = 1;
  2506. break;
  2507. case '&lt;': // prev
  2508. Pagination.clickPage = parseInt(selectPage) - 1;
  2509. if (Pagination.clickPage < 1) {
  2510. Pagination.clickPage = 1;
  2511. }
  2512. break;
  2513. case '&gt;': // next
  2514. Pagination.clickPage = parseInt(selectPage) + 1;
  2515. if (Pagination.clickPage > Pagination.size) {
  2516. Pagination.clickPage = Pagination.size;
  2517. }
  2518. break;
  2519. }
  2520. if ( Pagination.type === 'KONTRAHENCI' ) {
  2521. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', Pagination.clickPage);
  2522. Pagination.page = urlFetchKontrahenci(Pagination.clickPage);
  2523. }
  2524. else if ( Pagination.type === 'PRACOWNICY' ){
  2525. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', Pagination.clickPage);
  2526. Pagination.page = urlFetchPracownicy(Pagination.clickPage);
  2527. }
  2528. Pagination.Start();
  2529. },
  2530. // --------------------
  2531. // Script structure pagination
  2532. // --------------------
  2533. // binding pages
  2534. Bind: function() {
  2535. var a = Pagination.e.getElementsByTagName('a');
  2536. var currentPage = Pagination.clickPage || 1;
  2537. for (var i = 0; i < a.length; i++) {
  2538. if (+a[i].innerHTML === Pagination.page) a[i].className = 'btn btn-default active';
  2539. a[i].addEventListener('click', Pagination.Click, false);
  2540. }
  2541. },
  2542. // write pagination
  2543. Finish: function() {
  2544. Pagination.e.innerHTML = Pagination.code;
  2545. Pagination.code = '</ul></nav>';
  2546. Pagination.Bind();
  2547. },
  2548. // find pagination type
  2549. Start: function() {
  2550. Pagination.code = '';
  2551. if ( Pagination.type === 'KONTRAHENCI' ) {
  2552. 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>';
  2553. } else if ( Pagination.type === 'PRACOWNICY' ) {
  2554. 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>';
  2555. }
  2556. Pagination.code += '<nav aria-label="Page navigation" class="footer_pagination_menu_items"><ul class="btn-group tblAjax__footer__toolbar__pagination smad-pagination">';
  2557. Pagination.First();
  2558. Pagination.Prev();
  2559. if ( Pagination.type === 'KONTRAHENCI' ) {
  2560. Pagination.page = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page') || 1;
  2561. }
  2562. else if ( Pagination.type === 'PRACOWNICY' ) {
  2563. Pagination.page = getItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page') || 1;
  2564. }
  2565. if ( Pagination.page > Pagination.size ) {
  2566. Pagination.page = 1;
  2567. }
  2568. if (Pagination.size < Pagination.step * 2 + 6) {
  2569. Pagination.Add(1, Pagination.size + 1);
  2570. }
  2571. else if (Pagination.page < Pagination.step * 2 + 1) {
  2572. Pagination.Add(1, Pagination.step * 2 + 4);
  2573. }
  2574. else if (Pagination.page > Pagination.size - Pagination.step * 2) {
  2575. Pagination.Add(Pagination.size - Pagination.step * 2 - 2, Pagination.size + 1);
  2576. }
  2577. else {
  2578. Pagination.Add(Pagination.page - Pagination.step, Pagination.page + Pagination.step + 1);
  2579. }
  2580. Pagination.Next();
  2581. Pagination.Last();
  2582. Pagination.Finish();
  2583. },
  2584. // --------------------
  2585. // Initialization
  2586. // --------------------
  2587. // binding buttons
  2588. Buttons: function(e) {
  2589. var nav = e.getElementsByTagName('a');
  2590. },
  2591. // create skeleton
  2592. Create: function(e) {
  2593. var html = [
  2594. '<div></div>' // pagination container
  2595. ];
  2596. e.innerHTML = html.join('');
  2597. Pagination.e = e.getElementsByTagName('div')[0];
  2598. Pagination.Buttons(e);
  2599. },
  2600. // init
  2601. Init: function(e, data) {
  2602. Pagination.Extend(data);
  2603. Pagination.Create(e);
  2604. Pagination.Start();
  2605. }
  2606. };
  2607. function todo__fetchRaport(id) {
  2608. /* p5WFS_GetFeature('default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', {
  2609. primaryKey: id,
  2610. resolve: 'all',
  2611. resolveDepth: 3,
  2612. }).then(function (features) {
  2613. if(DBG) console.log('features', features)
  2614. }).catch(function (e) {
  2615. if(DBG) console.warn(e)
  2616. p5UI__notifyAjaxCallback({ type: 'error', msg: e })
  2617. })*/
  2618. }
  2619. function removeFiltersPracownicy(event, btnNode) {
  2620. event.preventDefault()
  2621. var fieldNameList = FIELD_LIST_PRACOWNICY
  2622. fieldNameList.forEach(function (fieldName) {
  2623. btnNode.form[fieldName].value = ''
  2624. })
  2625. urlFetchPracownicy(1)
  2626. }
  2627. function removeFiltersKontrahenci(event, btnNode) {
  2628. event.preventDefault()
  2629. var fieldNameList = FIELD_LIST_KONTRAHENCI
  2630. fieldNameList.forEach(function (fieldName) {
  2631. btnNode.form[fieldName].value = ''
  2632. })
  2633. urlFetchKontrahenci(1)
  2634. }
  2635. function onChangeFiltersPracownicy(event, inputNode) {
  2636. urlFetchPracownicy(1)
  2637. }
  2638. function onKeypressFiltersPracownicy(event, inputNode) {
  2639. if ("Enter" === event.key) {
  2640. event.stopPropagation()
  2641. event.preventDefault()
  2642. urlFetchPracownicy(1)
  2643. return false
  2644. }
  2645. }
  2646. function onChangeFiltersKontrahenci(event, inputNode) {
  2647. urlFetchKontrahenci(1)
  2648. }
  2649. function onKeypressFiltersKontrahenci(event, inputNode) {
  2650. if ("Enter" === event.key) {
  2651. event.stopPropagation()
  2652. event.preventDefault()
  2653. urlFetchKontrahenci(1)
  2654. return false
  2655. }
  2656. }
  2657. function loadMoreRecordFunctions(event, node, rowPK, namespace) {
  2658. var _node = node
  2659. var _rowPK = rowPK
  2660. var toShow = true
  2661. if (RECORD_MORE_FUNCTIONS_OPENED_NODE) {
  2662. if (RECORD_MORE_FUNCTIONS_OPENED_NODE === node) toShow = false
  2663. if (RECORD_MORE_FUNCTIONS_OPENED_NODE !== node) {
  2664. jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('destroy')
  2665. }
  2666. }
  2667. RECORD_MORE_FUNCTIONS_OPENED_NODE = node
  2668. // jQuery(node).popover({
  2669. // container: 'body',
  2670. // placement: 'right',
  2671. // trigger: 'click',
  2672. // template: '<div class="popover" role="tooltip" style="max-width:600px;width:440px;">' +
  2673. // '<div class="arrow"></div>' +
  2674. // '<div style="display:block;position:relative;">' +
  2675. // '<div class="popover-title">' +
  2676. // '</div>' +
  2677. // '<button type="button" class="close" onclick="return hideMoreRecordFunctionsPopover();" style="position:absolute;right:8px;top:6px;">&times;</button>' +
  2678. // '</div>' +
  2679. // '<div class="popover-content"></div>' +
  2680. // '</div>' +
  2681. // '',
  2682. // html: true,
  2683. // })
  2684. // jQuery(node).popover('show')
  2685. global.fetch(BASE_URLS + 'index.php?_route=ViewTableAjax&namespace=' + namespace + '&_task=moreFunctionsCellAjax&ID=' + rowPK, {
  2686. credentials: 'same-origin'
  2687. }).then(function (response) {
  2688. return response.json()
  2689. }).then(function (json) {
  2690. var funcListWrap = $('<div></div>')
  2691. var funcListNode = $('<ul class="list-unstyled popoverRowFunctions"></ul>').appendTo(funcListWrap)
  2692. if (_node === RECORD_MORE_FUNCTIONS_OPENED_NODE) {
  2693. if (json && 'success' === json.type && json.rowFunctions && json.rowFunctions.length > 0) {
  2694. json.rowFunctions.forEach(function(funObj) {
  2695. var funcNode = p5UI_TableAjax_generateFunctionNode(funObj, _rowPK, {ico: true, label: true});
  2696. var funcItemNode = jQuery('<li></li>')
  2697. funcItemNode.append(funcNode)
  2698. funcListNode.append(funcItemNode)
  2699. });
  2700. }
  2701. }
  2702. // jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('destroy')
  2703. jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover({
  2704. container: 'body',
  2705. placement: 'right',
  2706. trigger: 'click',
  2707. template: '<div class="popover" role="tooltip" style="max-width:600px;width:440px;">' +
  2708. '<div class="arrow"></div>' +
  2709. '<div style="display:block;position:relative;">' +
  2710. '<div class="popover-title">' +
  2711. '</div>' +
  2712. '<button type="button" class="close" onclick="return hideMoreRecordFunctionsPopover();" style="position:absolute;right:8px;top:6px;">&times;</button>' +
  2713. '</div>' +
  2714. '<div class="popover-content"></div>' +
  2715. '</div>' +
  2716. '',
  2717. html: true,
  2718. content: funcListWrap.html(),
  2719. })
  2720. jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('show')
  2721. }).catch(function (err) {
  2722. if(DBG) console.log('err', err);
  2723. })
  2724. }
  2725. var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
  2726. var defaultsProps = {
  2727. ico: true,
  2728. label: false
  2729. },
  2730. props = jQuery.extend({}, defaultsProps, props);
  2731. funcNode = $('<a href="#" style="margin:0 2px;"></a>')
  2732. ;
  2733. if ('href' in funObj) funcNode.attr('href', p5Utils__format(funObj.href, [rowPK]));
  2734. if (props.ico) {
  2735. if ('ico' in funObj) funcNode.append('<span class="' + funObj.ico + '"></span>');
  2736. }
  2737. if ('onclick' in funObj) funcNode.attr('onclick', p5Utils__format(funObj.onclick, [rowPK]));
  2738. if ('title' in funObj) funcNode.attr('title', funObj.title);
  2739. if ('target' in funObj) funcNode.attr('target', funObj.target);
  2740. if (props.label) {
  2741. if ('label' in funObj) {
  2742. funcNode.append(' ' + funObj.label);
  2743. } else if ('title' in funObj) {
  2744. funcNode.append(' ' + funObj.title);
  2745. }
  2746. }
  2747. return funcNode;
  2748. };
  2749. global.p5UI_TableAjax_generateFunctionNode = p5UI_TableAjax_generateFunctionNode
  2750. $(document).ready(function(){
  2751. rootChangeForm();
  2752. updateTopCounters();
  2753. });
  2754. global.hideMoreRecordFunctionsPopover = function() {
  2755. if (RECORD_MORE_FUNCTIONS_OPENED_NODE) jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('destroy')
  2756. }
  2757. global.pracownicyLoadMoreRecordFunctions = function(event, node, rowPK) {
  2758. return loadMoreRecordFunctions(event, node, rowPK, "default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY")
  2759. }
  2760. global.kontrahenciLoadMoreRecordFunctions = function(event, node, rowPK) {
  2761. return loadMoreRecordFunctions(event, node, rowPK, "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI")
  2762. }
  2763. global.removeFiltersPracownicy = removeFiltersPracownicy;
  2764. global.removeFiltersKontrahenci = removeFiltersKontrahenci;
  2765. global.onChangeFiltersPracownicy = onChangeFiltersPracownicy;
  2766. global.onKeypressFiltersPracownicy = onKeypressFiltersPracownicy;
  2767. global.onChangeFiltersKontrahenci = onChangeFiltersKontrahenci;
  2768. global.onKeypressFiltersKontrahenci = onKeypressFiltersKontrahenci;
  2769. global.checkAll = checkAll;
  2770. global.checkedChoiseItems = checkedChoiseItems;
  2771. global.catchEventCheckbox = catchEventCheckbox;
  2772. global.clearSelectedCheckbox = clearSelectedCheckbox;
  2773. global.getNameGroupById = getNameGroupById;
  2774. global.createGroupPracownicy = createGroupPracownicy;
  2775. global.createGroupKontrahenci = createGroupKontrahenci;
  2776. global.selectPage = selectPage;
  2777. global.detectChoiseFilter = detectChoiseFilter;
  2778. global.updateListIdBiAuditReaport = updateListIdBiAuditReaport;
  2779. global.deleteListIdBiAuditReaport = deleteListIdBiAuditReaport;
  2780. global.urlFetchPracownicy = urlFetchPracownicy;
  2781. global.generateBiAuditRaport = generateBiAuditRaport;
  2782. global.getAddressData = getAddressData;
  2783. global.loadCurrentReaportTitleInInput = loadCurrentReaportTitleInInput;
  2784. global.updateLocalStorageBiAuditReaportTitle = updateLocalStorageBiAuditReaportTitle;
  2785. global.Pagination = Pagination;
  2786. global.todo__fetchRaport = todo__fetchRaport;
  2787. global.initLocalStorage = initLocalStorage;
  2788. global.setItemLocalStorage = setItemLocalStorage;
  2789. global.getItemLocalStorage = getItemLocalStorage;
  2790. global.deleteItemLocalStorage = deleteItemLocalStorage;
  2791. global.defaultBIAuditLocalStorage = defaultBIAuditLocalStorage;
  2792. global.removeItemInArray = removeItemInArray;
  2793. global.removeItemArrayInArray = removeItemArrayInArray;
  2794. global.addPracownikToGroup = addPracownikToGroup;
  2795. global.addPracownikAllToGroup = addPracownikAllToGroup;
  2796. global.addKontrahenciToGroup = addKontrahenciToGroup;
  2797. global.addKontrahenciAllToGroup = addKontrahenciAllToGroup;
  2798. global.createPracownikAjax = createPracownikAjax;
  2799. global.createKontrahentAjax = createKontrahentAjax;
  2800. global.removePracownikFromGroup = removePracownikFromGroup;
  2801. global.removeKontrahenciFromGroup= removeKontrahenciFromGroup;
  2802. global.showViewUploadFile = showViewUploadFile;
  2803. global.parseCsvFile = parseCsvFile;
  2804. global.graphShowHide = graphShowHide;
  2805. global.clearListLocalStorageByType = clearListLocalStorageByType;
  2806. // message
  2807. global.messageCriticalSearchData = 'Krytyczne wielkości danych do przeszukania. Optymalna wartość głębokość szukania powiaząń to: 6';
  2808. global.defaultOnlyTarger = 'y';