TableAjax.php 212 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006
  1. <?php
  2. Lib::loadClass('ViewAjax');
  3. Lib::loadClass('TableAjaxMap');
  4. Lib::loadClass('Typespecial');
  5. Lib::loadClass('SE_Layout');
  6. Lib::loadClass('FoldersConfig');
  7. Lib::loadClass('FileUploader');
  8. Lib::loadClass('UserProfile');
  9. Lib::loadClass('ProcesHelper');
  10. Lib::loadClass('Router');
  11. class TableAjax extends ViewAjax {
  12. private $_cnf = '';// Column
  13. private $_htmlID = '';
  14. private $_rowFunctions = array();
  15. private $_pageSize = 10;
  16. private $_pageSizes = array();
  17. private $_filterInit = null;
  18. private $_forceFilterInit = null;
  19. private $_showProcesInit = true;
  20. public function __construct($tblAcl) {
  21. $this->_tbl = $tblAcl->getName();
  22. $this->_acl = $tblAcl;
  23. $this->_zasobID = $tblAcl->getID();
  24. $this->_pageSize = 10;
  25. {
  26. UserProfile::load();
  27. $tableAjaxSettings = UserProfile::getTableAjaxSettings();
  28. $this->_pageSize = V::get('pageSize', 10, $tableAjaxSettings, 'int');
  29. }
  30. $this->_pageSizes = array(10, 20, 50, 100);// default page sizes
  31. $this->_filterInit = new stdClass();
  32. $hash = V::get('_hash', '', $_GET);
  33. if ($hash) {
  34. $this->_htmlID = $hash;
  35. $this->_readState();
  36. } else {
  37. $this->_htmlID = $this->generateHtmlID();
  38. $this->_readState();
  39. }
  40. }
  41. public function showProcesInit($bool = true) {
  42. $this->_showProcesInit = $bool;
  43. }
  44. private function _hasStateFilterInit() {
  45. return array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache']) && array_key_exists('_filterInit', $_SESSION['TableAjax_Cache'][$this->_htmlID]);
  46. }
  47. // TODO: read state from cache by key $this->_htmlID
  48. // TODO: load filters and state: table, edit, add, etc.
  49. // TODO: save this data in Workspace 1, 2, 3, etc.
  50. // TODO: default filters in VIEWTABLE_AJAX
  51. // $tbl->setLabel($zasobObj->OPIS);
  52. // $tbl->setFilterInit($filterInit);
  53. // $tbl->addRowFunction('edit');
  54. // $tbl->addRowFunction('hist');
  55. // $tbl->addRowFunction('files');
  56. // $tbl->addRowFunction('cp');
  57. private function _readState() {
  58. if (!array_key_exists('TableAjax_Cache', $_SESSION)) {
  59. $_SESSION['TableAjax_Cache'] = array();
  60. }
  61. //trigger_error("F." . __FUNCTION__ . " (" . (array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache'])) . ")", E_USER_NOTICE);
  62. //trigger_error("F." . __FUNCTION__ . " (".basename($_SERVER['SCRIPT_FILENAME'])."::_filterInit: " . json_encode($_SESSION['TableAjax_Cache'][$this->_htmlID]['_filterInit']) . ")", E_USER_NOTICE);
  63. if (array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache'])) {
  64. foreach ($_SESSION['TableAjax_Cache'][$this->_htmlID] as $k => $v) {
  65. //trigger_error("F." . __FUNCTION__ . " key: ({$k})", E_USER_NOTICE);
  66. switch ($k) {
  67. case '_label':
  68. $this->_label = $v;
  69. break;
  70. case '_filterInit':
  71. $this->_filterInit = $v;
  72. break;
  73. case '_rowFunctions':
  74. $this->_rowFunctions = $v;
  75. break;
  76. default:
  77. }
  78. }
  79. }
  80. }
  81. protected function _saveState($key = null) {
  82. if (!array_key_exists('TableAjax_Cache', $_SESSION)) {
  83. $_SESSION['TableAjax_Cache'] = array();
  84. }
  85. if (!array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache'])) {
  86. $_SESSION['TableAjax_Cache'][$this->_htmlID] = array();
  87. }
  88. if (!$key) {
  89. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_label'] = $this->_label;
  90. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_filterInit'] = $this->_filterInit;
  91. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_rowFunctions'] = $this->_rowFunctions;
  92. } else if ($key == '_label') {
  93. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_label'] = $this->_label;
  94. } else if ($key == '_filterInit') {
  95. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_filterInit'] = $this->_filterInit;
  96. } else if ($key == '_rowFunctions') {
  97. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_rowFunctions'] = $this->_rowFunctions;
  98. }
  99. }
  100. public function setPageSizes($pageSizes) {
  101. $this->_pageSizes = $pageSizes;
  102. }
  103. public function setFilterInit($filterInit) {
  104. if ($this->_hasStateFilterInit()) {
  105. return;
  106. }
  107. $this->_filterInit = (object)$filterInit;
  108. $this->_saveState();
  109. }
  110. /**
  111. * @param array $forceFilterInit
  112. */
  113. public function setForceFilterInit($forceFilterInit) {
  114. $this->_forceFilterInit = (object)$forceFilterInit;
  115. }
  116. private function setFilters($filterInit) {
  117. $this->_filterInit = (object)$filterInit;
  118. $this->_saveState();
  119. }
  120. public function addRowFunction($funName, $funParams = array()) {
  121. $defaultRowFunction = array();
  122. //$defaultRowFunction['edit'] = '<a href="#EDIT/{0}" class="glyphicon glyphicon-pencil" title="Edytuj rekord"></a>';
  123. //$defaultRowFunction['hist'] = '<a href="#HIST/{0}" class="glyphicon glyphicon-book" title="Historia"></a>';
  124. //$defaultRowFunction['files'] = '<a href="#FILES/{0}" class="glyphicon glyphicon-folder-open" title="Pliki"></a>';
  125. //$defaultRowFunction['cp'] = '<a href="#" class="glyphicon glyphicon-plus-sign" title="Kopiuj rekord" onclick="return tableAjaxCopy({0});"></a>';
  126. $defaultRowFunction['edit'] = array('href'=>'#EDIT/{0}', 'ico'=>'glyphicon glyphicon-pencil', 'title'=>'Edytuj rekord');
  127. $defaultRowFunction['hist'] = array('href'=>'#HIST/{0}', 'ico'=>'glyphicon glyphicon-book', 'title'=>'Historia');
  128. $defaultRowFunction['files'] = array('href'=>'#FILES/{0}', 'ico'=>'glyphicon glyphicon-folder-open', 'title'=>'Pliki');
  129. $defaultRowFunction['cp'] = array('href'=>'#', 'ico'=>'glyphicon glyphicon-plus-sign', 'title'=>'Kopiuj rekord', 'onclick'=>'return tableAjaxCopy({0});');
  130. //@2015-12-09 nie dziala $defaultRowFunction['messages'] = array('href'=>'index.php?_route=TableMsgs&_task=tableRow&idTable=' . $this->_zasobID . '&idRow={0}', 'ico'=>'glyphicon glyphicon-envelope', 'title'=>'Wiadomosci');
  131. if (array_key_exists($funName, $defaultRowFunction)) {
  132. $this->_rowFunctions[$funName] = $defaultRowFunction[$funName];
  133. }
  134. else {
  135. $this->_rowFunctions[$funName] = $funParams;
  136. }
  137. $this->_saveState('_rowFunctions');
  138. }
  139. private function _parseRowFunctions($recordID = null, $pomin = array(), $showLabel = false) {
  140. $rowFunctions = array();
  141. foreach ($this->_rowFunctions as $kFunName => $vParams) {
  142. if (in_array($kFunName, $pomin)) continue;
  143. //$rowFunctionsOut .= str_replace('{0}', $recordID, $vUrl);
  144. $attrs = array();
  145. // $defaultRowFunction['cp'] = (object)array('href'=>'#', 'ico'=>'glyphicon glyphicon-plus-sign', 'title'=>'Kopiuj rekord', 'onclick'=>'return tableAjaxCopy({0});');
  146. $label = '';
  147. $ico = '';
  148. foreach ($vParams as $kParamName => $v) {
  149. if ($kParamName == 'ico') {
  150. $ico = '<span class="' . $v . '"></span>';
  151. continue;
  152. }
  153. $attr = $v;
  154. if ($recordID > 0) {
  155. $attr = str_replace('{0}', $recordID, $attr);
  156. }
  157. if ($showLabel && $kParamName == 'title') {
  158. $label = $attr;
  159. }
  160. $attr = $kParamName . '="' . $attr . '"';
  161. $attrs[] = $attr;
  162. }
  163. $rowFunctions[$kFunName] = '<a ' . implode(' ', $attrs) . '>' . "{$ico} {$label} " . '</a>';
  164. }
  165. return $rowFunctions;
  166. }
  167. private function _showRowFunctions($recordID = null, $pomin = array(), $showLabel = false) {
  168. $rowFunctionsOut = $this->_parseRowFunctions($recordID, $pomin, $showLabel);
  169. $rowFunctionsOut = implode('', $rowFunctionsOut);
  170. return $rowFunctionsOut;
  171. }
  172. private function _showRowFunctionsJson($recordID = null, $pomin = array(), $showLabel = false) {
  173. $rowFunctions = $this->_parseRowFunctions($recordID, $pomin, $showLabel);
  174. $rowFunctions = (object)$rowFunctions;
  175. return $rowFunctions;
  176. }
  177. private function _showExportFieldsJson() {
  178. $exportFields = $this->_acl->getExportFieldList();
  179. return $exportFields;
  180. }
  181. private function getProcesInitSelected() {
  182. $userAcl = User::getAcl();
  183. return $userAcl->getPermsFiltrProcesId();
  184. }
  185. public function allowTreeView() {
  186. if ($this->_tbl == 'CRM_LISTA_ZASOBOW') return true;
  187. if ($this->_tbl == 'CRM_PROCES') return true;
  188. return false;
  189. }
  190. public function hasGeomFields() {
  191. $hasGeomFields = false;
  192. $fieldsList = $this->_acl->getFields();
  193. foreach ($fieldsList as $kID => $vCol) {
  194. if ($this->_acl->isGeomField($vCol['name'])) {
  195. if ($this->_acl->hasFieldPerm($kID, 'R')) {
  196. $hasGeomFields = true;
  197. break;
  198. }
  199. }
  200. }
  201. return $hasGeomFields;
  202. }
  203. public function render() {
  204. $hasGeomFlds = $this->hasGeomFields();
  205. $tblAjaxMap = null;
  206. if ($hasGeomFlds) {
  207. $tblAjaxMap = new TableAjaxMap($this->_acl, 512, 400);
  208. }
  209. $hasPermCreate = $this->_acl->hasCreatePerms();
  210. $jsToogleFiltrProcesuFunctionName = 'tableAjaxToggleFiltrProcesInit';
  211. ob_start();
  212. ?>
  213. <div class="container">
  214. <?php SE_Layout::showMessagesForTable($this->_tbl); ?>
  215. </div>
  216. <?php if ($tblAjaxMap) $tblAjaxMap->printCSS(); ?>
  217. <?php if ($tblAjaxMap) $tblAjaxMap->printJS(); ?>
  218. <script src="stuff/jquery-ui-1.10.4.custom.min.js"></script>
  219. <link rel="stylesheet" type="text/css" href="stuff/jquery-ui-smoothness/jquery-ui-1.10.4.custom.min.css">
  220. <style type="text/css">
  221. .AjaxTable{max-width:100%;background-color:transparent;border-collapse:collapse;border-spacing:0;}
  222. .AjaxTableCont {position:relative; margin:10px 0; width:100%; overflow-x:auto; border:none;}
  223. .AjaxTable *,
  224. .AjaxTable.table {white-space:nowrap; width:auto;}
  225. .AjaxTable .popover * {white-space:normal;}
  226. .AjaxTable p {margin:0;}
  227. .AjaxTable td, .AjaxTable th {line-height:18px;}
  228. .AjaxTable i {margin: 0 0 0 2px;opacity: 0.5;}
  229. .AjaxTable span.filter {background-color:#999;}
  230. .AjaxTable .indeterminate {opacity: 0.4;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=40)";filter:alpha(opacity=40);}
  231. .AjaxTable .columnpicker li, .AjaxTable .actions li {padding-left:5px;}
  232. .AjaxTableCont .btn-toolbar {margin:2px 0 0 0;}
  233. .AjaxTableCont .btn-toolbar .btn-group {vertical-align:top;}
  234. .AjaxTable input[type=checkbox] {margin:0;padding:0;height:13px;}
  235. .AjaxTable input[type=text].filter {margin:0;padding:0 5px;box-shadow:none;width:100%;background:#eee;color:#000;}
  236. .AjaxTable input[type=text].filter {border-width:2px 0;border-color:#eee;border-style:solid;}
  237. .AjaxTable input[type=text].filter-active {border-color:#00ACCC;}
  238. .AjaxTable .date-wrap {width:100%;min-width:115px;}
  239. .AjaxTable .dateWrap .add-on {margin:0;padding:0;background:none;border:none;float:right;cursor:pointer;}
  240. .AjaxTable .actions a {padding:0;margin:0;}
  241. .AjaxTableCont .text-right {text-align:right}
  242. .AjaxTableCont .breadcrumb em {color:#bbb;}
  243. .AjaxTable-loading .head-info {background:url(./icon/loading.gif) no-repeat left top; background-position:0 6px;}
  244. .AjaxTable-loading .loading-info,
  245. .AjaxTableCont .tblAjax__inlineEditBox .loading-info {display:block; padding:0 0 0 20px; background:url(./icon/loading.gif) no-repeat left top;}
  246. .AjaxTableCont .loading-info {display:none;}
  247. .AjaxTableCont .tblAjax__inlineEditBox .loading-info {display:block;}
  248. .AjaxTableCont .table {margin-bottom:0px;}
  249. .AjaxTableCont .stickyCol1 a { color:#333; }
  250. .AjaxTableCont .stickyCol1 a:hover { color:#337AB7; text-decoration:none; }
  251. .AjaxTableTaskCnt {padding:0 10px 10px 10px;}
  252. .AjaxTable .tbl-short-txt{max-width:140px; overflow:hidden;}
  253. .AjaxTable .tbl-short-txt span{display:block; height:18px;}
  254. .AjaxTable .tooltip-inner{white-space:normal;}
  255. .AjaxTable thead .sort .ta-ordering {cursor:pointer;}
  256. .AjaxTable thead .sort .ta-ordering span {margin:0 10px 0 0; padding:0; background-repeat:no-repeat; background-position:right top;}
  257. .AjaxTable thead .sort .ta-ordering-down span:after{content:"\e252";font-family:"Glyphicons Halflings";line-height:1;margin:0 0 0 3px;display:inline-block;color:#bbb;}
  258. .AjaxTable thead .sort .ta-ordering-up span:after{content:"\e253";font-family:"Glyphicons Halflings";line-height:1;margin:0 0 0 3px;display:inline-block;color:#bbb;}
  259. .AjaxTable thead .sort .ta-ordering {position:relative;}
  260. .AjaxTable thead .sort th .hover-show:hover{background-color:#000; background-image:url(stuff/twitter-bootstrap/img/glyphicons-halflings-white.png);}
  261. .AjaxTable thead .sort th .hover-show{display:none;}
  262. .AjaxTable thead .sort th:hover .hover-show{display:inline;}
  263. .AjaxTable thead .sort .ta-ordering .remove-cell {position:absolute; top:6px; right:2px; display:none; color:#f00;}
  264. .AjaxTable thead .sort .ta-ordering:hover .remove-cell {display:block;}
  265. .AjaxTableCont .pagination { margin:0; }
  266. .AjaxTableCont .pagination a { line-height:16px; }
  267. .AjaxTableCont .AjaxTableEdit-label { display:block; margin:0 0 3px 0; font-size:12px !important; line-height:16px !important; }
  268. .AjaxTableCont .AjaxTableEdit-label code { padding:0; white-space:nowrap; background-color:transparent; border:none; color:#777; font-size:10px !important; line-height:14px !important; }
  269. .AjaxTableCont .AjaxTableEdit .show-last-value .button-appendBack .glyphicon,
  270. .AjaxTableCont .AjaxFrmHorizontalEdit .show-last-value .button-appendBack .glyphicon {display:none;}
  271. .AjaxTableHist em {color:silver;}
  272. .AjaxTableCont .foot * { font-size:12px !important; }
  273. .AjaxTableCont .foot { margin:10px; }
  274. .AjaxTableCont .foot .foot-info { float:left; padding:0 20px; }
  275. .AjaxTableCont .foot .foot-info p { line-height:16px; margin:5px 0; }
  276. .AjaxTable-loading .foot .foot-info {padding-left:20px; background:url(./icon/loading.gif) no-repeat left top;}
  277. .tblAjax__head__specialFilter {margin:0;padding:4px 4px 4px 127px;}
  278. .tblAjax__head__specialFilter .btn-group {margin:0 4px;padding:0;}
  279. .tblAjax__head__specialFilter .btn-group .glyphicon-remove {color:#f00;}
  280. .tblAjax__head__specialFilter .btn-group button.disabled .glyphicon-remove {color:#bbb;}
  281. /* overwrite bootstrap table border */
  282. .AjaxTable, .AjaxTableEdit,
  283. .AjaxTable td, .AjaxTableEdit td,
  284. .AjaxTable th, .AjaxTableEdit th { border-color:#999; }
  285. /* cell A_STATUS */
  286. .AjaxTable .cell-A_STATUS-NORMAL { background:#aeffae; color:#000; text-align:center; }
  287. .AjaxTable .cell-A_STATUS-WAITING { background:#ffd2ff; color:#000; text-align:center; }
  288. .AjaxTable .cell-A_STATUS-MONITOR { background:#cccaff; color:#000; text-align:center; }
  289. .AjaxTable .cell-A_STATUS-WARNING { background:#ffbaba; color:#000; text-align:center; }
  290. .AjaxTable .cell-A_STATUS-DELETED { background:#e0e0e0; color:#808080; text-align:center; }
  291. .AjaxTable .cell-A_STATUS-OFF_SOFT { background:#fce3b7; color:#808080; text-align:center; }
  292. .AjaxTable .cell-A_STATUS-OFF_HARD { background:#eee; color:#808080; text-align:center; }
  293. /* cell Status */
  294. .AjaxTable .cell-Status-U { background:rgb(0,176,80); color:#000; text-align:center; }
  295. .AjaxTable .cell-Status-NU { background:#f00; color:#000; text-align:center; }
  296. .AjaxTable .cell-Status-P { background:rgb(112,48,160); color:#000; text-align:center; }
  297. .AjaxTable .cell-Status-PT { background:rgb(127,127,127); color:#000; text-align:center; }
  298. .AjaxTable .cell-Status-O { background:rgb(0,176,240); color:#000; text-align:center; }
  299. .AjaxTable .cell-Status-DZ { background:rgb(0,112,192); color:#000; text-align:center; }
  300. .AjaxTable .cell-Status-Z {}
  301. /* map */
  302. .AjaxTable .cell-mapfld { cursor:pointer; }
  303. .AjaxTable .cell-mapfld:hover { opacity:1; }
  304. .AjaxTable .cell-mapfld-remove { display:none; }
  305. .AjaxTable .cell-mapfld-hasValue .cell-mapfld-select { color:#f00; }
  306. .AjaxTable .cell-mapfld-hasValue .cell-mapfld-remove { display:inline-block; }
  307. .AjaxTableCont .mapEditor { position:absolute; bottom:0; right:6px; width:512px; height:318px; overflow:hidden; color:#eee; border:1px solid #999; }
  308. .AjaxTableCont .mapEditor-panel { height:16px; padding:0 6px; background:#999; border-bottom:1px solid #eee; }
  309. .AjaxTableCont .mapEditor-panel a { display:block; float:right; padding:0 6px; font-weight:bold; font-size:12px; line-height:16px; color:#fff; }
  310. .AjaxTableCont .mapEditor-panel a:hover { color:#006CD7; text-decoration:none; }
  311. .AjaxTableCont .mapEditor-panel a.mapEditor-panel-close:hover { color:#f00; }
  312. .AjaxTableCont .mapEditor-map { background:#fff; height:400px; }
  313. .AjaxTableCont-mapEditorContainer .mapEditor-map { border:1px solid #999; overflow:hidden; }
  314. /* .mapEditor-btnBackToWindow "olControlSave",overview_replacement */
  315. .olControlEditingToolbar .mapEditor-btnBackToWindowItemInactive,
  316. .olControlEditingToolbar .mapEditor-btnBackToWindowItemActive {
  317. background-image: url(icon/map.window.png);
  318. background-position: 0 0;
  319. background-repeat: no-repeat;
  320. }
  321. /*
  322. .mapEditor-btnBackToWindowItemInactive { background-image: url(stuff/open-layers/theme/default/img/overview_replacement.gif); }
  323. .mapEditor-btnBackToWindowItemActive { background-image: url(stuff/open-layers/theme/default/img/overview_replacement.gif); }
  324. */
  325. .ui-dialog-content .mapEditor-btnBackToWindowItemInactive,
  326. .ui-dialog-content .mapEditor-btnBackToWindowItemActive { display:none; }
  327. .AjaxTableCont .valign-btns-bottom a { vertical-align:text-bottom; font-weight:normal; font-size:12px; line-height:14px; }
  328. .ui-resizable-s { bottom:0; }
  329. .ui-resizable-e { right:0; }
  330. .AjaxTableCont-mapEditorContainer .ui-resizable-s { background-color:#ddd; }
  331. .AjaxTableCont-mapEditorContainer .ui-resizable-s:hover { background-color:#888; }
  332. </style>
  333. <div class="AjaxTableCont">
  334. <ul class="breadcrumb">
  335. <li><a href="#" onclick="return tableAjaxBackToTable();"><?php echo $this->getLabelHtml(); ?></a></li>
  336. <!-- TODO: if has perm 'C' then add btn to create new record -->
  337. <?php if ($hasPermCreate) : ?>
  338. <li><a title="Dodaj nowy rekord"
  339. class=""
  340. href="#CREATE"><span class="glyphicon glyphicon-plus"></span> Dodaj nowy rekord</a></li>
  341. <?php endif; ?>
  342. <?php if ($this->_showProcesInit) : ?>
  343. <div class="btn-group pull-right">
  344. <a class="btn btn-xs btn-info dropdown-toggle"
  345. data-toggle="dropdown"
  346. href="#"
  347. title="Uruchom filtr procesu powiązanego z tabelą <?php echo $this->getLabel(); ?>"
  348. onclick="return <?php echo $jsToogleFiltrProcesuFunctionName; ?>(this);">
  349. Filtr procesu <span class="caret"></span>
  350. </a>
  351. <ul class="dropdown-menu pull-left" style="max-height:250px;overflow:auto;">
  352. <li class="disabled"><a href="#" onclick="return false;"> loading ... </a></li>
  353. </ul>
  354. </div>
  355. <?php endif; ?>
  356. <?php if ($this->_tbl == 'IN7_MK_BAZA_DYSTRYBUCJI') : ?>
  357. <a class="pull-right" style="padding:0 20px 0 0;" href="<?php echo "index.php?MENU_INIT=TREEJS&ZASOB_ID={$this->_zasobID}"; ?>"><i class="glyphicon glyphicon-eye-open"></i> Drzewo</a>
  358. <?php elseif ($this->allowTreeView()) : ?>
  359. <a class="pull-right" style="padding:0 20px 0 0;" href="<?php echo "index.php?MENU_INIT=VIEWTREE_AJAX&ZASOB_ID={$this->_zasobID}"; ?>"><i class="glyphicon glyphicon-eye-open"></i> Drzewo</a>
  360. <?php endif; ?>
  361. </ul>
  362. <div id="<?php echo $this->_htmlID; ?>"></div>
  363. </div>
  364. <script>
  365. (function($) {
  366. var TableAjaxGeomField = function() {
  367. var priv = {}; //private api
  368. var publ = {}; //public api
  369. priv.options = {};
  370. var defaults = {
  371. recordID: '',
  372. fieldValue: '',
  373. hasValueClassName: 'TableAjaxGeomField-hasValue',
  374. linkClassNamePrefix: 'TableAjaxGeomField',
  375. linkSelectClassName: 'select',
  376. linkSelectAddClassNames: '', // 'glyphicon glyphicon-map-marker'
  377. linkRemoveClassName: 'remove',
  378. linkRemoveAddClassNames: '', // 'glyphicon glyphicon-remove'
  379. removeUrl: '',
  380. onSelect: null,
  381. onRemove: null,
  382. debug: false
  383. };
  384. priv.init = function() {
  385. priv.render();
  386. };
  387. priv.render = function() {
  388. var state = priv.options;
  389. var cellMapSelect = jQuery('<i title="Pokaż/utwórz obiekt na mapie"></i>');
  390. cellMapSelect.addClass(state.linkClassNamePrefix + '-' + state.linkSelectClassName);
  391. if (state.linkSelectAddClassNames) {
  392. cellMapSelect.addClass(state.linkSelectAddClassNames);
  393. }
  394. cellMapSelect.on('click', {recordID: priv.options.recordID, fieldValue: priv.options.fieldValue}, function(e) {
  395. if (typeof state.onSelect == "function") {
  396. state.onSelect.call(this, e.data.recordID, e.data.fieldValue);
  397. }
  398. });
  399. var cellMapRemove = jQuery('<i title="Usuń obiekt z mapy"></i>');
  400. cellMapRemove.addClass(state.linkClassNamePrefix + '-' + state.linkRemoveClassName);
  401. if (state.linkRemoveAddClassNames) {
  402. cellMapRemove.addClass(state.linkRemoveAddClassNames);
  403. }
  404. cellMapRemove.on('click', {recordID: state.recordID, fieldValue: state.fieldValue}, function(e) {
  405. if (typeof state.onRemove == "function") {
  406. state.onRemove.call(this, publ, e.data.recordID, e.data.fieldValue);
  407. }
  408. });
  409. var node = $(state.id);
  410. node.empty();
  411. node.addClass(state.linkClassNamePrefix);
  412. node.removeClass(state.hasValueClassName);
  413. if (state.fieldValue) {
  414. node.addClass(state.hasValueClassName);
  415. }
  416. node.append(cellMapSelect);
  417. node.append(cellMapRemove);
  418. };
  419. publ.setValue = function(value) {
  420. if (priv.options.debug) console.log('TEST setValue: ', value, 'this', this);
  421. priv.options.fieldValue = value;
  422. priv.render();
  423. };
  424. publ.init = function(options) {
  425. if (priv.options.debug) console.log('TableAjaxGeomField initialization...', options);
  426. //merge supplied options with defaults
  427. $.extend(priv.options, defaults, options);
  428. priv.init();
  429. return publ;
  430. };
  431. return publ;
  432. };
  433. $.fn.TableAjaxGeomFieldSetValue = function(value) {
  434. return this.each(function() {
  435. var tblAjaxMapGeomFld = $(this).data('TableAjaxGeomField');
  436. if (tblAjaxMapGeomFld) {
  437. tblAjaxMapGeomFld.setValue(value);
  438. }
  439. });
  440. return this;
  441. };
  442. $.fn.TableAjaxGeomField = function(options) {
  443. options = options || {};
  444. return this.each(function() {
  445. options.id = this;
  446. if (!$(this).data('TableAjaxGeomField')) {
  447. $(this).data('TableAjaxGeomField', new TableAjaxGeomField().init(options));
  448. }
  449. });
  450. return this;
  451. };
  452. }(jQuery));
  453. (function($, undefined) {
  454. var TableAjax = function() {
  455. var priv = {}; //private api
  456. var publ = {}; //public api
  457. priv.options = {};
  458. var defaults = {
  459. url: '', //webservice url
  460. urlData: '', //webservice params
  461. urlPost: false, //use POST instead of GET
  462. debug: false, //prints debug info to console
  463. filter: false, //show filter row
  464. filterInit: false,// init filters data
  465. forceFilterInit: false,
  466. columnPicker: false, //show columnpicker
  467. checkboxes: false, //show body checkboxes
  468. actions: '', //holds action links
  469. pageSize: 10, //current pagesize
  470. pageSizes: [10, 20, 30, 40, 50, 'All'], //available pagesizes
  471. hidePagerOnEmpty: false, //removes pager if no rows
  472. types: { //type specific options
  473. string: {},
  474. number: {},
  475. bool: {},
  476. date: {}
  477. },
  478. rowFunctions: false,
  479. tblFunctions: false,
  480. specialFilterFunctions: false,
  481. filtersClean: false,
  482. router: false,
  483. longDesc: false,
  484. exportFields: [],
  485. mapEditor: false, // mapEditor visible or not
  486. mapEditorContainer: 'window' // 'window' or 'dock'
  487. };
  488. var _uiNodeCont; // container holding table
  489. var _uiNode$Table; // the table node
  490. var _head; // table header
  491. var _headSort; // table header sorting row
  492. var _headFilter; // table header columns filter row
  493. var _headSpecialFilter; // table header special filter row
  494. var _bodyNode; // table body
  495. var _body; // TODO: table body need render?
  496. var _foot; // table footer
  497. var _inlineEditBox; // inline edit box with form
  498. var _popoverCell; // inline popover cell
  499. var _popoverCellCurrent; // inline popover cell
  500. var _popoverCellAjaxXhr;
  501. var _mapEditor; // map editor node
  502. var _mapEditorWrap; // map editor wrapper node
  503. var _mapEditorDialog; // map editor jquery ui dialog node
  504. var _state = {};// state - to replace variables below (date, ...)
  505. var _data; //columns and rows
  506. var _totalPages; // total pages
  507. var _currDpOp; // clicked datetimepicker operator
  508. var _filterFields = {}; // array with filter DOM elements
  509. var _filterTimeout; // timer for delayed filtering
  510. var _uniqueCols = {}; // array with checked rows /// TODO: mv to _state.
  511. var _checkToggleChecked = false; // check-all toggle state
  512. var _exportFieldsSelect = {};
  513. var _tableWidth;
  514. /*
  515. initialize the plugin.
  516. */
  517. priv.init = function() {
  518. _uiNodeCont = priv.options.id;
  519. _state = {};// init state
  520. _state.page = 1;
  521. _state.specialFilters = {};
  522. _state.filters = {};
  523. _state.filters.currSortCol = '';
  524. _state.filters.currSortFlip = false;
  525. _state.filters.filterCols = {};
  526. priv.initEvents();
  527. priv.initialRender();// set up _uiNode$...
  528. priv.options.types.string = ((priv.options.types || {}).string || {});
  529. priv.options.types.number = ((priv.options.types || {}).number || {});
  530. priv.options.types.bool = ((priv.options.types || {}).bool || {});
  531. priv.options.types.date = ((priv.options.types || {}).date || {});
  532. if (priv.options.mapEditorContainer != 'dock'
  533. && priv.options.mapEditorContainer != 'window') {
  534. priv.options.mapEditorContainer = 'window';
  535. }
  536. if (priv.options.filterInit) {
  537. priv.setStateFilters(priv.options.filterInit);
  538. }
  539. $.each(priv.options.exportFields, function(ind, col) {
  540. _exportFieldsSelect[col] = true;
  541. });
  542. //try call webservice for data
  543. priv.update(priv.options.router);
  544. if (typeof priv.options.router == "function") {
  545. $(window).bind('hashchange', function() {
  546. priv.options.router.apply(this);
  547. });
  548. }
  549. };
  550. priv.initEvents = function() {
  551. jQuery(_uiNodeCont).on('TableAjax:render', priv.onRender);
  552. };
  553. priv.onRender = function(e) {
  554. if (priv.options.debug) console.log('onRender.arguments:', arguments.length, arguments, 'e:', e);
  555. if (arguments.length > 1) {
  556. for (var i=1; i<arguments.length; i++) {
  557. switch (arguments[i]) {
  558. case 'head': _head = undefined; break;
  559. case 'body': _body = undefined; break;
  560. case 'foot': _foot = undefined; break;
  561. case 'foot_pagination': {
  562. priv.renderFooterInfo();
  563. priv.renderFooterPagination();
  564. priv.renderFooterPageSizes();
  565. }
  566. break;
  567. case 'footer__toolbar__info': priv.renderFooterInfo(); break;
  568. case 'footer__toolbar__pagination': priv.renderFooterPagination(); break;
  569. case 'footer__toolbar__pagesizes': priv.renderFooterPageSizes(); break;
  570. case 'foot__columnPicker': priv.renderFooterColumnPicker(); break;
  571. case 'head__specialFilters': priv.renderHeadSpecialFilters(); break;
  572. }
  573. }
  574. priv.renderTable();
  575. }
  576. };
  577. priv.initialRender = function() {
  578. _uiNode$Table = $('<table class="AjaxTable table table-striped table-hover table-bordered table-condensed"></table>').appendTo(_uiNodeCont);
  579. _head = $('<thead></thead>').prependTo(_uiNode$Table);
  580. _headSort = $('<tr class="sort tblAjax__head__sort"></tr>').prependTo(_head);
  581. _headFilter = $('<tr class="filter tblAjax__head__filter"></tr>').appendTo(_head);
  582. _bodyNode = $('<tbody></tbody>').insertAfter(_head);
  583. $('<tfoot></tfoot>').insertAfter(_bodyNode);
  584. _foot = $('<div class="foot tblAjax__footer"></div>').insertAfter(_uiNodeCont);
  585. var footToolbar = $('<div class="btn-toolbar tblAjax__footer__toolbar"></div>').appendTo(_foot);
  586. $('<span class="tblAjax__footer__toolbar__info"></span>').appendTo(footToolbar);
  587. $('<span class="tblAjax__footer__toolbar__pagination"></span>').appendTo(footToolbar);
  588. $('<span class="tblAjax__footer__toolbar__pagesizes"></span>').appendTo(footToolbar);
  589. $('<span class="tblAjax__footer__toolbar__columnPicker"></span>').appendTo(footToolbar);
  590. $('<span class="tblAjax__footer__toolbar__functions"></span>').appendTo(footToolbar);
  591. $('<span class="tblAjax__footer__toolbar__export"></span>').appendTo(footToolbar);
  592. _mapEditorWrap = $('<div class="mapEditor" style="display:none"></div>').insertAfter(_foot);
  593. _mapEditor = $('<div class="mapEditor-map"></div>').appendTo(_mapEditorWrap);
  594. _popoverCell = $('<div class="popoverCell" style="display:none"></div>').insertAfter(_foot);
  595. $('<div class="tblAjax__inlineEditBox"></div>').insertAfter(_foot);
  596. $('<div class="btn-toolbar tblAjax__head__specialFilter"></div>').insertBefore(_uiNodeCont);
  597. priv.renderInlineEditBox();// .tblAjax__inlineEditBox
  598. _foot = _head = _body = _headSort = _headFilter = undefined;// TODO: refactor
  599. /// console.log('L.<?php echo __LINE__; ?> priv.initialRender, _uiNode$Table: ', _uiNode$Table.html())
  600. }
  601. /*
  602. creates the table with all its parts and handlers.
  603. note that only the parts we need is created.
  604. (yeah, the function is huge)
  605. */
  606. priv.renderTable = function() {
  607. //create table itself
  608. /// console.log('renderTable:: _data', _data);//TODO:DBG:RMME
  609. /// console.log('renderTable:: _uiNode$Table', _uiNode$Table);//TODO:DBG:RMME
  610. //create the header which will later hold both sorting and filtering
  611. /// console.log('L.<?php echo __LINE__; ?> renderTable:: _head', _head);//TODO:DBG:RMME
  612. if (!_head) {
  613. _headSort = _headFilter = _headSpecialFilter = undefined;
  614. //_head = $('<thead></thead>');
  615. // $('<tr class="sort"></tr>').prependTo(_head);
  616. //_uiNode$Table.find('thead').replaceWith(_head);
  617. _head = _uiNode$Table.find('thead');
  618. }
  619. //create the header sorting row
  620. if (!_headSort) {
  621. /// console.log('L.<?php echo __LINE__; ?> renderTable::renderTableTheadSort...');//TODO:DBG:RMME
  622. priv.renderTableTheadSort();
  623. }
  624. //create the header filtering row
  625. if (!_headFilter && priv.options.filter) {
  626. /// console.log('L.<?php echo __LINE__; ?> renderTable::renderTableTheadFilter...');//TODO:DBG:RMME
  627. priv.renderTableTheadFilter();
  628. _headFilter = true;
  629. }
  630. //create the header special filters row
  631. if (!_headSpecialFilter && priv.options.specialFilterFunctions) {
  632. priv.renderHeadSpecialFilters();
  633. _headSpecialFilter = true;
  634. }
  635. //create the body
  636. if (!_body) {
  637. _uiNode$Table.find('tbody').remove();
  638. _bodyNode = $('<tbody></tbody>').insertAfter(_head);
  639. //_bodyNode.on('change', '.unique', priv.rowChecked);
  640. //find out what rows to show next...
  641. var rowsAdded = 0;
  642. //slice out the chunk of data we need and create rows
  643. $.each(_data.rows, function(index, props) {
  644. var rowNode = priv.renderRow(props);
  645. if (rowNode) rowNode.appendTo(_bodyNode);
  646. rowsAdded++;
  647. //enough rows created?
  648. if (rowsAdded >= priv.options.pageSize) {
  649. return false;
  650. }
  651. });
  652. if (_state.page == 1) {
  653. _totalPages = Math.ceil(_data.total / priv.options.pageSize);
  654. }
  655. //pad with empty rows if we're at last page.
  656. if (_state.page == _totalPages) {
  657. while (rowsAdded < priv.options.pageSize) {
  658. var rowNode = priv.renderRowEmptyNode();
  659. if (rowNode) rowNode.appendTo(_bodyNode);
  660. rowsAdded++;
  661. }
  662. }
  663. }
  664. //create the footer
  665. if (!_foot) {
  666. priv.renderTableTfoot();
  667. priv.renderFooter();
  668. }
  669. _foot = $(_uiNodeCont).next('.foot');
  670. var stickyCol1Width = (12 + 3) * 4 + 2 * 5 + 1;
  671. var stickyCol2Width = 50 + 2 * 5 + 1;
  672. if (undefined === _tableWidth) {
  673. _tableWidth = true;
  674. var contW = jQuery(_uiNodeCont).width();
  675. var th1 = _uiNode$Table.find('.stickyCol1:first');
  676. var th2 = th1.next();
  677. var th1W = th1.innerWidth();
  678. var th2W = 50 + 2 * 5;//th2.innerWidth();
  679. var colsW = stickyCol1Width + stickyCol2Width;
  680. jQuery(_uiNodeCont).css({width:'' + (contW - colsW) + 'px', marginLeft:'' + colsW + 'px', overflowX:'scroll', overflowY:'visible', paddingBottom:'1px'});
  681. }
  682. _uiNode$Table.find('.stickyCol1').css({position:'absolute',
  683. left:'0',
  684. top:'auto',
  685. width:'' + stickyCol1Width + 'px',
  686. });
  687. //_uiNode$Table.find('.filter').find('.stickyCol1').css({height:'34px'});
  688. var sortStickyColHeight = _uiNode$Table.find('.sort').find('th:last').outerHeight();
  689. _uiNode$Table.find('.sort').find('.stickyCol1').css({height: sortStickyColHeight + 'px'});
  690. _uiNode$Table.find('.sort').find('.stickyCol2').css({height: sortStickyColHeight + 'px'});
  691. _uiNode$Table.find('.stickyCol2').css({position:'absolute',
  692. left:'' + (stickyCol1Width) + 'px',
  693. top:'auto',
  694. width:'' + stickyCol2Width + 'px',
  695. borderRight: '1px solid silver'
  696. });
  697. if (_data.total == 0 && priv.options.hidePagerOnEmpty) {
  698. $('.btn-toolbar', _foot).remove();
  699. }
  700. if (priv.options.debug) console.log('table created L.<?php echo __LINE__; ?>');
  701. if (typeof priv.options.tableCreated == 'function') {
  702. priv.options.tableCreated.call(_uiNode$Table.get(0), {table: _uiNode$Table.get(0)});
  703. }
  704. };
  705. priv.renderRow = function(props) {
  706. var rowNode = $('<tr></tr>'),
  707. uniqueColName = _state.uniqueCol,
  708. rowPK = (uniqueColName in props)? props[uniqueColName] : null,
  709. cellNode
  710. ;
  711. if (priv.options.rowFunctions || priv.options.filtersClean) {
  712. cellNode = priv.renderCellRowFunctions(priv.options.rowFunctions, rowPK, props);
  713. cellNode.addClass('text-right stickyCol1');
  714. cellNode.appendTo(rowNode);
  715. }
  716. //create checkbox
  717. if (_state.uniqueCol && priv.options.checkboxes) {
  718. var check = _uniqueCols[props[_state.uniqueCol]] != undefined ? 'checked' : '';
  719. var checkable = props['checkable'] === false ? 'disabled' : '';
  720. cellNode = $('<td></td>').appendTo(rowNode);
  721. $('<input class="unique" {0} {1} type="checkbox" />'.f(check, checkable)).appendTo(cellNode);
  722. }
  723. if (uniqueColName) rowNode.data('unique', rowPK);
  724. //create cells
  725. for (var i = 0; i < _state.colsSorted.length; i++) {
  726. var columnName = _state.colsSorted[i],
  727. columnProps = _data.cols[columnName],
  728. val = '',
  729. cellNode,
  730. cellCnt,
  731. format,
  732. showTooltip
  733. ;
  734. if (!columnProps) continue;
  735. if (columnProps.hidden) continue;// TODO: "unique" is hidden
  736. val = props[columnName];
  737. cellNode = $('<td></td>').appendTo(rowNode);
  738. if (columnName !== uniqueColName) {
  739. cellNode.on('dblclick', {id:rowPK, col:columnName}, priv.rowDblClicked);
  740. }
  741. if (i == 1) {// primaryKey(ID)
  742. cellCnt = $('<div></div>').appendTo(cellNode);// fix dblclick for copy
  743. cellNode.addClass('stickyCol2');
  744. } else {
  745. cellCnt = $('<span></span>').appendTo(cellNode);
  746. }
  747. cellNode.data('column', columnName);
  748. if (val === undefined) continue;
  749. format = props[columnName + 'Format'] || columnProps.format || '{0}';
  750. showTooltip = true;
  751. switch (columnProps.type) {
  752. case "string":
  753. cellCnt.html(format.f(val));
  754. break;
  755. case "number":
  756. val = Number(val);
  757. var forceDecimals = !isNaN(columnProps.decimals);
  758. if (forceDecimals) cellCnt.html(format.f(val.toFixed(columnProps.decimals)));
  759. else {
  760. (val || 0) % 1 === 0
  761. ? cellCnt.html(format.f(val))
  762. : cellCnt.html(format.f(val.toFixed(priv.options.types.number.decimals || 2)));
  763. }
  764. break;
  765. case "date":
  766. cellCnt.html(format.f(val));
  767. break;
  768. case "bool":
  769. $('<input type="checkbox" {0} disabled />'.f(val ? "checked" : "")).appendTo(cellCnt);
  770. break;
  771. case "special":
  772. cellCnt.html(format.f(val));
  773. break;
  774. case "simpleLink":
  775. var valLink = String(val);
  776. if (undefined !== columnProps._tsRetId
  777. && (0 === columnProps._tsRetId || '0' === columnProps._tsRetId)
  778. && undefined !== columnProps._tsSimpleLink) {
  779. valLink = columnProps._tsSimpleLink.format;
  780. $.each(columnProps._tsSimpleLink.aliasMap, function(i, v) {
  781. //console.log('simpleLink aliasMap columnName:', columnName, 'i:', i, 'v:', v, 'props['+v+']', props[v], 'val', val, 'typeof val', typeof val);
  782. if (undefined !== props[v]) {
  783. valLink = valLink.replace(new RegExp('\{' + i + '\}', 'g'), props[v]);
  784. }
  785. });
  786. }
  787. cellCnt.html(format.f(valLink));
  788. break;
  789. case "geom":
  790. cellCnt.TableAjaxGeomField({
  791. recordID: rowPK,
  792. fieldValue: val,
  793. hasValueClassName: 'cell-mapfld-hasValue',
  794. //removeUrl: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=THE_GEOM_REMOVE&ID=' + rowPK,
  795. linkClassNamePrefix: 'cell-mapfld',
  796. linkSelectClassName: 'select',
  797. linkSelectAddClassNames: 'glyphicon glyphicon-map-marker',
  798. linkRemoveClassName: 'remove',
  799. linkRemoveAddClassNames: 'glyphicon glyphicon-remove',
  800. onSelect: function(recordID, geomShape) {
  801. if (priv.options.debug) console.log('recordID:', recordID, 'geomShape:', geomShape);
  802. priv.mapEditorShow();
  803. _mapEditor.TableAjaxMapSelectRecord(recordID, geomShape);
  804. },
  805. onRemove: function(geomField, recordID, geomShape) {
  806. if (confirm('Czy usunąć obiekt z mapy dla rekordu ' + recordID + '?')) {
  807. if (!recordID) return;
  808. var selectedRecordId = recordID;
  809. function notifyAjaxCallback(data) {
  810. var notify = {};
  811. notify.type = (data && data.type)? data.type : '';
  812. notify.msg = (data && data.msg)? data.msg : '';
  813. switch (notify.type) {
  814. case 'success':
  815. if (!notify.msg) notify.msg = 'Usunięto obiekt z mapy dla rekordu ' + selectedRecordId;
  816. break;
  817. case 'info':
  818. if (!notify.msg) notify.msg = 'Rekord nie był powiązany z żadnym obiektem na mapie';
  819. break;
  820. case 'error':
  821. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  822. break;
  823. case 'warning':
  824. notify.type = 'warn';
  825. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  826. break;
  827. default:
  828. notify.msg = 'Nieznany błąd';
  829. if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
  830. notify.type = '';
  831. }
  832. jQuery.notify(notify.msg, notify.type);
  833. }
  834. $.ajax({
  835. data: {},
  836. dataType: 'json',
  837. type: "POST",
  838. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=THE_GEOM_REMOVE&ID=' + recordID
  839. })
  840. .done(function(data, textStatus, jqXHR){
  841. notifyAjaxCallback(data);
  842. if (priv.options.debug) console.log('data.record.the_geom:', data.record.the_geom);
  843. if (data && data.record && data.record.the_geom) {
  844. if (priv.options.debug) console.log('data.record.the_geom:2:', data.record.the_geom);
  845. geomField.setValue(data.record.the_geom);
  846. }
  847. else if (data && data.record) {
  848. if (priv.options.debug) console.log('data.record.the_geom:2:', data.record.the_geom);
  849. geomField.setValue(data.record.the_geom);
  850. }
  851. _mapEditor.TableAjaxMapRefresh();
  852. })
  853. .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
  854. if (jqXHR.responseJSON) {
  855. notifyAjaxCallback(jqXHR.responseJSON);
  856. }
  857. else {
  858. var txt = jqXHR.responseText || 'Wystąpiły błędy';
  859. if (jqXHR.status == 404) {
  860. jQuery.notify(jqXHR.responseText, 'error');
  861. } else {
  862. jQuery.notify(jqXHR.responseText, 'warn');
  863. }
  864. }
  865. });
  866. }
  867. }
  868. });
  869. break;
  870. }
  871. if (columnProps._tsRetId) {
  872. showTooltip = false;
  873. if (columnProps._tsRetId > 0) {
  874. cellCnt.on('click', {id:rowPK, col:columnName, friendly:columnProps.friendly, value:format.f(val)}, priv.popoverCellTypeSpecial);
  875. }
  876. }
  877. if (i > 1 && priv.options.longDesc) {// TODO: use better check for columns: functions and pk
  878. cellNode.addClass('tbl-short-txt');
  879. if (showTooltip) {
  880. cellCnt.tooltip({title: cellCnt.text(), placement: 'left'});
  881. }
  882. }
  883. }
  884. return rowNode;
  885. };
  886. priv.renderCellRowFunctions = function(rowFunctions, rowPK, rowProps) {
  887. var cellNode = $('<td></td>'),
  888. keys = Object.keys(rowFunctions),
  889. total = keys.length,
  890. moreFuncBtnNode,
  891. moreFunctions = [],
  892. idx
  893. ;
  894. if (priv.options.debug) console.log('TableAjax::renderCellRowFunctions: rowFunctions', rowFunctions);
  895. idx = keys.indexOf('hist');
  896. if (idx !== -1) {
  897. histFunc = keys.splice(idx, 1);
  898. keys.push('hist');
  899. }
  900. moreFunctions = keys.splice(3);
  901. keys.forEach(function(key) {
  902. var funObj = rowFunctions[key],
  903. funcNode = priv.generateFunctionNode(funObj, rowPK, {ico: true, label: false})
  904. ;
  905. funcNode.appendTo(cellNode);
  906. });
  907. moreFuncBtnNode = $('<a href="#" style="margin:0 2px;text-decoration:none" title="Więcej funkcji dla rekordu nr '+rowPK+'" class="glyphicon glyphicon-menu-hamburger"> </a>');
  908. moreFuncBtnNode.on('click', {rowPK: rowPK, rowFunctions: rowFunctions, more: moreFunctions}, priv.popoverCellMoreFunctions);
  909. moreFuncBtnNode.appendTo(cellNode);
  910. return cellNode;
  911. };
  912. priv.popoverCellMoreFunctions = function(e) {
  913. e.preventDefault();
  914. e.stopPropagation();
  915. if (priv.options.debug) console.log('TableAjax::popoverCellMoreFunctions: rowPK', e.data.rowPK, 'moreFunctions', e.data.more, 'rowFunctions', e.data.rowFunctions);
  916. if ('rowPK' in e.data && e.data.rowPK > 0) {
  917. var lastId = _popoverCell.data('rowid'),
  918. lastCol = _popoverCell.data('col'),
  919. rowPK = e.data.rowPK,
  920. moreFunctions = e.data.more,
  921. rowFunctions = e.data.rowFunctions,
  922. funcListNode
  923. ;
  924. if (lastId == e.data.rowPK && lastCol == 'moreFunctions') {
  925. //_popoverCellCurrent.popover('toggle');
  926. }
  927. else {
  928. if (_popoverCellCurrent) {
  929. _popoverCellCurrent.popover('destroy');
  930. }
  931. _popoverCell.data('rowid', rowPK);
  932. _popoverCell.data('col', 'rowFunctions');
  933. _popoverCell.empty();
  934. funcListNode = $('<ul class="list-unstyled"></ul>').appendTo(_popoverCell);
  935. moreFunctions.forEach(function(funcName) {
  936. var funcItemNode = $('<li></li>').appendTo(funcListNode),
  937. funObj = rowFunctions[funcName],
  938. funcNode = priv.generateFunctionNode(funObj, rowPK, {ico: true, label: true})
  939. ;
  940. funcItemNode.append(funcNode);
  941. });
  942. _popoverCell.append('<div class="popoverCellContent" style="white-space:normal"></div>');
  943. _popoverCellCurrent = jQuery(e.currentTarget);
  944. // title : '<span class="text-info"><strong>title</strong></span> <button type="button" id="close" class="close">&times;</button>'
  945. var opts = {
  946. container: 'body',
  947. placement: 'right',
  948. trigger: 'click',
  949. template: '',
  950. html: true,
  951. content: _popoverCell.html()
  952. }
  953. opts.template += '<div class="popover" role="tooltip" style="max-width:400px;width:300px;">';
  954. {
  955. opts.template += '<div class="arrow"></div>';
  956. //opts.template += '<h3 class="popover-title"></h3>';
  957. opts.template += '<div style="display:block;position:relative;">';
  958. {
  959. opts.template += '<div class="popover-title">';
  960. opts.template += '</div>';
  961. opts.template += '<button type="button" class="close" onclick="return hidePopover();" style="position:absolute;right:8px;top:6px;">&times;</button>';
  962. }
  963. opts.template += '</div>';
  964. opts.template += '<div class="popover-content"></div>';
  965. }
  966. opts.template += '</div>';
  967. _popoverCellCurrent.popover(opts);
  968. _popoverCellCurrent.on('shown.bs.popover', function(e) {
  969. if (_popoverCellCurrent) {
  970. var popoverNodeId = _popoverCellCurrent.attr('aria-describedby');
  971. if (popoverNodeId) {
  972. jQuery('#' + popoverNodeId).find('.popoverCellContent').html('<p class="text-muted">Pobieranie funkcji...<p>');
  973. }
  974. }
  975. priv.ajaxLoadMoreFunctionsCell(rowPK);
  976. });
  977. _popoverCellCurrent.popover('show');
  978. }
  979. } else {
  980. if (priv.options.debug) console.log('NO data');
  981. return false;
  982. }
  983. return;
  984. };
  985. priv.generateFunctionNode = function(funObj, rowPK, props) {
  986. var defaultsProps = {
  987. ico: true,
  988. label: false
  989. },
  990. props = $.extend({}, defaultsProps, props);
  991. funcNode = $('<a href="#" style="margin:0 2px;"></a>')
  992. ;
  993. if ('href' in funObj) funcNode.attr('href', funObj.href.f(rowPK));
  994. if (props.ico) {
  995. if ('ico' in funObj) funcNode.append('<span class="' + funObj.ico + '"></span>');
  996. }
  997. if ('onclick' in funObj) funcNode.attr('onclick', funObj.onclick.f(rowPK));
  998. if ('title' in funObj) funcNode.attr('title', funObj.title);
  999. if (props.label) {
  1000. if ('title' in funObj) funcNode.append(' ' + funObj.title);
  1001. }
  1002. return funcNode;
  1003. };
  1004. priv.ajaxLoadMoreFunctionsCell = function(rowPK) {
  1005. if (_popoverCellAjaxXhr) {
  1006. _popoverCellAjaxXhr.abort();
  1007. }
  1008. _popoverCellAjaxXhr = $.ajax({
  1009. type: 'GET',
  1010. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=MORE_FUNCTIONS_CELL&ID=' + rowPK,
  1011. dataType: 'json',
  1012. contentType: "application/json; charset=utf-8",
  1013. data: ''
  1014. })
  1015. .done(function(data, textStatus, jqXHR){
  1016. if (data && 'success' === data.type) {
  1017. var popoverCellContent,
  1018. rowFunctions = []
  1019. ;
  1020. if (data.rowFunctions && data.rowFunctions.length > 0) {
  1021. rowFunctions = data.rowFunctions;
  1022. }
  1023. if (rowFunctions.length > 0) {
  1024. var popoverCellContent = $('<ul class="list-unstyled"></ul>');
  1025. rowFunctions.forEach(function(funObj) {
  1026. var funcItemNode = $('<li></li>').appendTo(popoverCellContent),
  1027. funcNode = priv.generateFunctionNode(funObj, rowPK, {ico: true, label: true})
  1028. ;
  1029. funcItemNode.append(funcNode);
  1030. });
  1031. } else {
  1032. popoverCellContent = '<p class="text-muted">Brak dodatkowych funkcji</p>';
  1033. }
  1034. //_popoverCell.append(popoverCellContent);// cache
  1035. if (_popoverCellCurrent) {
  1036. var popoverNodeId = _popoverCellCurrent.attr('aria-describedby');
  1037. if (popoverNodeId) {
  1038. var pooverCntNode = jQuery('#' + popoverNodeId).find('.popoverCellContent');
  1039. pooverCntNode.empty().append(popoverCellContent);
  1040. if (rowFunctions.length <= 0) {
  1041. pooverCntNode.find('p.text-muted').delay(600).hide(300);
  1042. }
  1043. }
  1044. }
  1045. }
  1046. });
  1047. };
  1048. priv.renderRowEmptyNode = function() {
  1049. var rowNode = $('<tr></tr>');
  1050. if (priv.options.rowFunctions || priv.options.filtersClean) {
  1051. $('<td class="text-right stickyCol1">&nbsp;</td>').appendTo(rowNode);
  1052. }
  1053. if (_state.uniqueCol && priv.options.checkboxes) {
  1054. $('<td><input disabled type="checkbox" /></td>').appendTo(rowNode);
  1055. }
  1056. for (var i = 0; i < _state.colsSorted.length; i++) {
  1057. var columnName = _state.colsSorted[i],
  1058. columnProps = _data.cols[columnName]
  1059. ;
  1060. if (!columnProps) return;
  1061. if (columnProps.hidden) continue;// "unique" is hidden - TODO: rm "unique" from _state.colsSorted ?
  1062. if (i == 1) {// TODO: 1 is pk - use better check
  1063. $('<td class="stickyCol2">&nbsp;</td>').appendTo(rowNode);
  1064. } else {
  1065. $('<td>&nbsp;</td>').appendTo(rowNode);
  1066. }
  1067. }
  1068. return rowNode;
  1069. };
  1070. priv.renderTableTheadSort = function() {
  1071. var nodeClass = 'tblAjax__' + 'head__sort',
  1072. currentNode = _uiNode$Table.find('thead').find('.' + nodeClass),
  1073. node;
  1074. // currentNode.find('i').tooltip('hide');
  1075. node = $('<tr class="sort ' + nodeClass + '"></tr>');
  1076. //create the functions column
  1077. if (priv.options.rowFunctions || priv.options.filtersClean) {
  1078. var headCell = $('<th class="text-right head-info stickyCol1"></th>').appendTo(node);
  1079. $.map(priv.options.tblFunctions, function(funObj, funName){
  1080. var funHtml = $('<a></a>');
  1081. funHtml.attr('href', funObj.href || '#');
  1082. if (funObj.title) funHtml.attr('title', funObj.title);
  1083. if (funObj.icon) funHtml.html('<span class="glyphicon glyphicon-' + funObj.icon + '"></span> ');
  1084. if (funObj.method && priv[funObj.method] && typeof priv[funObj.method] == 'function') {
  1085. funHtml.on('click', priv[funObj.method]);
  1086. }
  1087. funHtml.appendTo(headCell);
  1088. });
  1089. }
  1090. //create the checkall toggle
  1091. if (_state.uniqueCol && priv.options.checkboxes) {
  1092. var checked = _checkToggleChecked ? 'checked' : '';
  1093. var headCell = $('<th></th>').appendTo(node);
  1094. var elem = $('<input {0} class="checkToggle" type="checkbox" />'.f(checked)).appendTo(headCell);
  1095. elem.on('change', priv.checkToggleChanged);
  1096. }
  1097. //create the sortable headers
  1098. for (var i = 0; i < _state.colsSorted.length; i++) {
  1099. var column = _state.colsSorted[i];
  1100. var props = _data.cols[column];
  1101. if (!props.hidden) {
  1102. var headCell = $('<th class="ta-ordering"></th>').appendTo(node);
  1103. if (i == 1) headCell.addClass('stickyCol2');
  1104. if (false) {// TODO: old way
  1105. var link = $('<a class="pull-left" href="#">{0}</a>'.f(props.friendly || column));
  1106. link.on('click', {column: column}, priv.columnClicked).appendTo(headCell);
  1107. if (props.tooltip) {
  1108. $('<i class="glyphicon glyphicon-info-sign"></i>').tooltip({
  1109. title: props.tooltip.trim(),
  1110. html: true,
  1111. container: 'body',
  1112. placement: "top",
  1113. delay: {
  1114. show: 500,
  1115. hide: 100
  1116. }
  1117. }).appendTo(link);
  1118. }
  1119. //Add sort arrow
  1120. if (column == _state.filters.currSortCol) {
  1121. if (_state.filters.currSortFlip) $('<i class="glyphicon glyphicon-chevron-down pull-right"></i>').appendTo(headCell);
  1122. else $('<i class="glyphicon glyphicon-chevron-up pull-right"></i>').appendTo(headCell);
  1123. }
  1124. //Add hide btn
  1125. if (column != 'ID') {
  1126. var hideColBtn = $('<i class="glyphicon glyphicon-remove pull-right hover-show"></i>');
  1127. hideColBtn.on('click', {column: column}, priv.columnHideClicked);
  1128. hideColBtn.appendTo(headCell);
  1129. }
  1130. }
  1131. if (props.type != 'special' && props.type != 'geom') {
  1132. headCell.on('click', {column: column}, priv.columnClicked);
  1133. }
  1134. var colTitle = column;
  1135. if (props.description && props.description.length > 0) {
  1136. colTitle = props.description;
  1137. colTitle += ' (' + column + ')';
  1138. }
  1139. else if (props._tsRetId > 0) {
  1140. colTitle = 'Kliknij na pole i przejdź do powiązanych rekordów (' + colTitle + ')';
  1141. }
  1142. if (props.friendly) {
  1143. var headCnt = $('<span class="pull-left" title="{1}">{0}</span>'.f(props.friendly, colTitle));
  1144. } else {
  1145. var headCnt = $('<span class="pull-left" title="{1}">{0}</span>'.f(column, colTitle));
  1146. }
  1147. headCnt.appendTo(headCell);
  1148. //Add sort arrow
  1149. if (column == _state.filters.currSortCol) {
  1150. if (_state.filters.currSortFlip) headCell.addClass('ta-ordering-down');
  1151. else headCell.addClass('ta-ordering-up');
  1152. }
  1153. if (column != 'ID') {
  1154. var hideColBtn = $('<i class="glyphicon glyphicon-remove remove-cell"></i>');
  1155. hideColBtn.on('click', {column: column}, priv.columnHideClicked);
  1156. hideColBtn.appendTo(headCell);
  1157. }
  1158. }
  1159. }
  1160. currentNode.replaceWith(node);
  1161. };
  1162. priv.renderHeadSpecialFilters = function() {
  1163. var nodeClass = 'tblAjax__' + 'head__specialFilter',
  1164. currentNode = $(_uiNodeCont).prev('.' + nodeClass),
  1165. node;
  1166. /// console.log('L.<?php echo __LINE__; ?> renderTable::renderTableTheadFilter...');//TODO:DBG:RMME
  1167. if (!priv.options.specialFilterFunctions) {
  1168. return;
  1169. }
  1170. var node = $('<div class="btn-toolbar tblAjax__head__specialFilter"></div>');
  1171. $.map(priv.options.specialFilterFunctions, function(groupObj, groupName) {
  1172. var btnHtml,
  1173. btnSelected,
  1174. groupLabel = groupObj.label || groupName,
  1175. groupHtml = $('<div class="btn-group"></div>')
  1176. ;
  1177. // _state.specialFilters[e.data.group] = e.data.value;
  1178. if (groupName in _state.specialFilters) {
  1179. btnSelected = _state.specialFilters[groupName];
  1180. }
  1181. if (groupObj.icon) {
  1182. $('<button class="btn btn-xs btn-default" title="' + groupLabel + '"><i class="' + groupObj.icon + '"></i></button>').appendTo(groupHtml);
  1183. }
  1184. $.map(groupObj.btns, function(btnObj, btnName) {
  1185. btnHtml = $('<button class="btn btn-xs btn-default' + ((btnSelected && btnSelected == btnObj.value)? ' active' : '') + '">' + btnName + '</button>').appendTo(groupHtml);
  1186. btnHtml.on('click', {group: groupName, value: btnObj.value}, priv.specialFilterChanged);
  1187. });
  1188. btnHtml = $('<button class="btn btn-xs btn-default' + ((!btnSelected)? ' disabled' : '') + '" title="Kasuj filtr"><i class="glyphicon glyphicon-remove"></i></button>').appendTo(groupHtml);
  1189. btnHtml.on('click', {group: groupName, value: ''}, priv.specialFilterChanged);
  1190. groupHtml.appendTo(node);
  1191. });
  1192. currentNode.replaceWith(node);
  1193. };
  1194. priv.renderTableTheadFilter = function() {
  1195. var nodeClass = 'tblAjax__' + 'head__filter',
  1196. currentNode = _uiNode$Table.find('thead').find('.' + nodeClass),
  1197. node;
  1198. // currentNode.find('i').tooltip('hide');
  1199. node = $('<tr class="filter ' + nodeClass + '"></tr>');
  1200. //_head.find(".filter").remove();
  1201. //_headFilter = $('<tr class="filter"></tr>').appendTo(_head);
  1202. var headCell;
  1203. var elem;
  1204. var placeHolder = '';
  1205. var tooltip = '';
  1206. //create the functions column
  1207. if (priv.options.rowFunctions || priv.options.filtersClean) {
  1208. var headCell = $('<th class="text-right stickyCol1"></th>').appendTo(node);
  1209. headCell.css({padding: '0'});
  1210. if (priv.options.filtersClean) {
  1211. var elem = $('<button title="Kasuj filtry" class="btn btn-xs btn-link glyphicon glyphicon-remove"></button>').appendTo(headCell);
  1212. elem.on('click', priv.filtersClean);
  1213. }
  1214. }
  1215. //create the filter checkbox
  1216. if (_state.uniqueCol && priv.options.checkboxes) {
  1217. tooltip = priv.options.types.bool.filterTooltip || 'Toggle between:<br/>indeterminate,<br/>checked,<br/>unchecked';
  1218. headCell = $('<th></th>').appendTo(node);
  1219. elem = $('<input class="filter indeterminate" checked type="checkbox" />').appendTo(headCell);
  1220. $.map(_state.filters.filterCols, function(colProps, col) {
  1221. if (col == "unique") {
  1222. if (colProps.filter) elem.prop('checked', true).removeClass('indeterminate');
  1223. else if (!colProps.filter) elem.prop('checked', false).removeClass('indeterminate');
  1224. else if (colProps.filter == '') elem.addClass('indeterminate');
  1225. }
  1226. });
  1227. if (tooltip) {
  1228. elem.tooltip({
  1229. title: tooltip.trim(),
  1230. html: true,
  1231. container: 'body',
  1232. trigger: 'hover',
  1233. placement: 'top',
  1234. delay: {
  1235. show: 500,
  1236. hide: 100
  1237. }
  1238. });
  1239. }
  1240. elem.on('click', {column: "unique"}, priv.filterChanged);
  1241. }
  1242. //create the column filters
  1243. for (var i = 0; i < _state.colsSorted.length; i++) {
  1244. var column = _state.colsSorted[i];
  1245. var props = _data.cols[column];
  1246. tooltip = props.filterTooltip === true ? undefined : props.filterTooltip === false ? '' : props.filterTooltip;
  1247. placeHolder = props.placeHolder === true ? undefined : props.placeHolder === false ? '' : props.placeHolder;
  1248. if (!props.hidden) {
  1249. headCell = $('<th></th>').appendTo(node);
  1250. headCell.css({padding: '0'});
  1251. if (i == 1) headCell.addClass('stickyCol2');
  1252. // @mark MarkTableAjaxFilterColType
  1253. switch (props.type || 'string') {
  1254. case "number":
  1255. if (placeHolder == undefined) placeHolder = priv.options.types.number.placeHolder;
  1256. placeHolder = (placeHolder === true || placeHolder == undefined) ? '10..20 =50' : placeHolder === false ? '' : placeHolder;
  1257. if (tooltip == undefined) tooltip = priv.options.types.number.filterTooltip;
  1258. tooltip = (tooltip === true || tooltip == undefined) ? 'Values 10 to 20:<br/>10..20<br/>Values exactly 50:<br/>=50' : tooltip === false ? '' : tooltip;
  1259. elem = $('<input placeholder="{0}" class="filter" type="text" />'.f(placeHolder));
  1260. elem.on('keyup', {column: column}, priv.filterChanged);
  1261. break;
  1262. case "date":
  1263. if (placeHolder == undefined) placeHolder = priv.options.types.date.placeHolder;
  1264. placeHolder = (placeHolder === true || placeHolder == undefined) ? '-7..0' : placeHolder === false ? '' : placeHolder;
  1265. if (tooltip == undefined) tooltip = priv.options.types.date.filterTooltip;
  1266. tooltip = (tooltip === true || tooltip == undefined) ? 'Today:<br/>0..1<br/>A week today excluded:<br/>-7..0' : tooltip === false ? '' : tooltip;
  1267. elem = $('<div><input placeholder="{0}" class="filter" type="text" /></div>'.f(placeHolder));
  1268. if (priv.options.types.date.datePicker === true || priv.options.types.date.datePicker == undefined)
  1269. {
  1270. if ($().datepicker)
  1271. {
  1272. elem.addClass('date-wrap');
  1273. var today = 0;//new priv.ext.XDate(false).setHours(0, 0, 0, 0).toString('yyyy-MM-dd');
  1274. var dp = $('<div style="float:right" class="date" data-date="{0}" data-date-format="{1}" />'.f(today, 'yyyy-mm-dd')).appendTo(elem);
  1275. $('<input style="display:none" type="text" />').appendTo(dp);
  1276. $('<span class="add-on"><i class="glyphicon glyphicon-chevron-right"></i></span>').on('click', {op: "l"}, priv.dpOpChanged).appendTo(dp);
  1277. $('<span class="add-on"><i class="glyphicon glyphicon-chevron-left"></i></span>').on('click', {op: "r"}, priv.dpOpChanged).appendTo(dp);
  1278. dp.datepicker({weekStart:1});
  1279. dp.on('changeDate', {column: column, input: $('input.filter', elem)}, priv.dpClicked);
  1280. }
  1281. else
  1282. if (priv.options.debug) console.log('datepicker plugin not found');
  1283. }
  1284. elem.on('keyup', 'input.filter', {column: column}, priv.filterChanged);
  1285. break;
  1286. case "bool":
  1287. if (tooltip == undefined) tooltip = priv.options.types.bool.filterTooltip;
  1288. tooltip = (tooltip === true || tooltip == undefined) ? 'Toggle between:<br/>indeterminate,<br/>checked,<br/>unchecked' : tooltip === false ? '' : tooltip;
  1289. elem = $('<input class="filter indeterminate" checked type="checkbox" />');
  1290. elem.on('click', {column: column}, priv.filterChanged);
  1291. break;
  1292. case "string":
  1293. if (placeHolder == undefined) placeHolder = priv.options.types.string.placeHolder;
  1294. placeHolder = (placeHolder === true || placeHolder == undefined) ? '%' : placeHolder === false ? '' : placeHolder;
  1295. if (tooltip == undefined) tooltip = priv.options.types.string.filterTooltip;
  1296. tooltip = (tooltip === true || tooltip == undefined) ? 'Find str: str<br/>Find all but str: !str<br/>Find str inside: %str%' : tooltip === false ? '' : tooltip;
  1297. elem = $('<input placeholder="{0}" class="filter" type="text" size="8" />'.f(placeHolder));
  1298. elem.on('keyup', {column: column}, priv.filterChanged);
  1299. break;
  1300. case "special":
  1301. elem = $('<div>&nbsp;</div>');
  1302. break;
  1303. case "simpleLink":
  1304. elem = $('<div>&nbsp;</div>');
  1305. break;
  1306. case "geom":
  1307. if (placeHolder == undefined) placeHolder = priv.options.types.string.placeHolder;
  1308. placeHolder = (placeHolder === true || placeHolder == undefined) ? '%' : placeHolder === false ? '' : placeHolder;
  1309. elem = $('<input placeholder="{0}" class="filter" type="text" size="8" />'.f(placeHolder));
  1310. elem.on('keyup', {column: column}, priv.filterChanged);
  1311. break;
  1312. case "none":
  1313. elem = $('<div>&nbsp;</div>');
  1314. break;
  1315. }
  1316. if (false) {// tooltip OFF - (tooltip)
  1317. elem.tooltip({
  1318. title: tooltip.trim(),
  1319. html: true,
  1320. container: 'body',
  1321. trigger: 'focus',
  1322. placement: 'top',
  1323. delay: {
  1324. show: 500,
  1325. hide: 100
  1326. }
  1327. });
  1328. }
  1329. if (elem && props.filter) {
  1330. $.map(_state.filters.filterCols, function(colProps, col) {
  1331. if (col == column) {
  1332. var columnSettings = _data.cols[col];
  1333. if (columnSettings.type == 'bool') {
  1334. if (colProps.filter) elem.prop('checked', true).removeClass('indeterminate');
  1335. else if (!colProps.filter) elem.prop('checked', false).removeClass('indeterminate');
  1336. else if (colProps.filter == '') elem.addClass('indeterminate');
  1337. }
  1338. else elem.val(colProps.filter);
  1339. }
  1340. });
  1341. if (priv.options.forceFilterInit && undefined !== priv.options.forceFilterInit[column]) {
  1342. elem.prop('disabled', true);
  1343. }
  1344. elem.appendTo(headCell);
  1345. _filterFields[column] = elem;
  1346. }
  1347. }
  1348. }
  1349. currentNode.replaceWith(node);
  1350. };
  1351. priv.renderTableTfoot = function() {
  1352. _uiNode$Table.find('tfoot').remove();
  1353. _foot = $('<tfoot></tfoot>').insertAfter(_bodyNode);
  1354. //$(_uiNodeCont).next('.foot').replaceWith(_foot);
  1355. };
  1356. priv.renderFooter = function() {
  1357. priv.renderFooterInfo();
  1358. priv.renderFooterPagination();
  1359. priv.renderFooterPageSizes();
  1360. priv.renderFooterColumnPicker();
  1361. priv.renderFooterFunctions();
  1362. priv.renderFooterExport();
  1363. };
  1364. priv.renderFooterInfo = function() {
  1365. var nodeClass = 'tblAjax__' + 'footer__toolbar__info',
  1366. currentNode = $(_uiNodeCont).next('.foot').find('.' + nodeClass),
  1367. node;
  1368. if (priv.options.debug) console.log('Render: ', nodeClass);
  1369. node = $('<div class="foot-info ' + nodeClass + '"></div>');
  1370. //console.log('renderFooterInfo total', _data.total, 'page', _state.page, 'priv.options.pageSize', priv.options.pageSize);
  1371. var fromRow = Math.max(_state.page - 1, 0) * _state.pageSize;
  1372. var total = _data.total;
  1373. var toRow = Math.min(fromRow + _state.pageSize, total);
  1374. if (_data.total > 0) {
  1375. $('<p>Wiersze od {0} do {1} z {2}</p>'.f(fromRow + 1, toRow, total)).appendTo(node);
  1376. } else {
  1377. $('<p>Brak wierszy pasujących do kryteriów wyszukiwania</p>').appendTo(node);
  1378. }
  1379. currentNode.replaceWith(node);
  1380. };
  1381. priv.renderFooterPagination = function() {
  1382. var nodeClass = 'tblAjax__' + 'footer__toolbar__pagination',
  1383. currentNode = $(_uiNodeCont).next('.foot').find('.' + nodeClass),
  1384. node;
  1385. var currPage = _state.page;
  1386. var totalPages = Math.ceil(_data.total / _state.pageSize);
  1387. if (priv.options.debug) console.log('Render: ', nodeClass, '_data.total', _data.total, 'currPage', currPage);
  1388. /// console.log('Render: ', nodeClass, '_data.total', _data.total, 'currPage', currPage, '_state.page', _state.page);
  1389. if (_data.total > 0) {
  1390. node = $('<div class="btn-group ' + nodeClass + '"></div>');
  1391. //create the pager.
  1392. var lowerPage = currPage - 2;
  1393. var upperPage = currPage + 2;
  1394. if (upperPage > totalPages) {
  1395. var diff = upperPage - totalPages;
  1396. upperPage = totalPages;
  1397. lowerPage -= diff;
  1398. }
  1399. if (lowerPage < 1) lowerPage = 1;
  1400. if (upperPage < 5) upperPage = 5;
  1401. //$('<li class="{0}"><a href="#">&lt;&lt;</a></li>'.f(currPage == 1 ? 'disabled' : ''))
  1402. $('<button type="button" class="btn btn-default{0}">&lt;&lt;</button>'.f(currPage == 1 ? ' disabled' : ''))
  1403. .on('click', {pageIndex: 1}, priv.pageChanged)
  1404. .appendTo(node);
  1405. //$('<li class="{0}"><a href="#">&lt;</a></li>'.f(currPage == 1 ? 'disabled' : ''))
  1406. $('<button type="button" class="btn btn-default{0}">&lt;</button>'.f(currPage == 1 ? ' disabled' : ''))
  1407. .on('click', {pageIndex: currPage - 1}, priv.pageChanged)
  1408. .appendTo(node);
  1409. for (var i = lowerPage; i <= upperPage; i++) {
  1410. var link;
  1411. //if (i != currPage) link = $('<li class="{1}"><a href="#">{0}</a></li>'.f(i, i > totalPages ? 'disabled' : ''));
  1412. if (i != currPage) link = $('<button type="button" class="btn btn-default{1}">{0}</button>'.f(i, i > totalPages ? 'disabled' : ''));
  1413. //if (i == currPage) link = $('<li class="active"><a href="#">{0}</a></li>'.f(i));
  1414. if (i == currPage) link = $('<button type="button" class="btn btn-default active">{0}</button>'.f(i));
  1415. if (link) {
  1416. link.on('click', {pageIndex: i}, priv.pageChanged);
  1417. link.appendTo(node);
  1418. }
  1419. }
  1420. //$('<li class="{0}"><a href="#">&gt;</a></li>'.f(currPage == totalPages ? 'disabled' : ''))
  1421. $('<button type="button" class="btn btn-default{0}">&gt;</button>'.f(currPage == totalPages ? ' disabled' : ''))
  1422. .on('click', {pageIndex: currPage + 1}, priv.pageChanged)
  1423. .appendTo(node);
  1424. //$('<li class="{0}"><a href="#">&gt;&gt;</a></li>'.f(currPage == totalPages ? 'disabled' : ''))
  1425. $('<button type="button" class="btn btn-default{0}">&gt;&gt;</button>'.f(currPage == totalPages ? ' disabled' : ''))
  1426. .on('click', {pageIndex: totalPages}, priv.pageChanged)
  1427. .appendTo(node);
  1428. } else {
  1429. node = $('<span class="' + nodeClass + '"></span>');
  1430. }
  1431. currentNode.replaceWith(node);
  1432. };
  1433. priv.renderFooterPageSizes = function() {
  1434. var nodeClass = 'tblAjax__' + 'footer__toolbar__pagesizes',
  1435. currentNode = $(_uiNodeCont).next('.foot').find('.' + nodeClass),
  1436. node;
  1437. if (priv.options.debug) console.log('Render: ', nodeClass);
  1438. if (_data.total > 0 && priv.options.pageSizes.length > 0) {
  1439. node = $('<div class="btn-group dropup pagesize ' + nodeClass + '"></div>');
  1440. var btn = $('<button class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" href="#">Liczba wierszy&nbsp;</button>').appendTo(node);
  1441. var span = $('<span class="caret"></span>').appendTo(btn);
  1442. var ul = $('<ul class="dropdown-menu" style="max-height:250px;overflow:auto;">').appendTo(node);
  1443. $.each(priv.options.pageSizes, function(index, val) {
  1444. var li = $('<li></li>').appendTo(ul);
  1445. if (val == priv.options.pageSize) {
  1446. $('<a style="color:#337AB7;">{0}</a>'.f(val)).appendTo(li);
  1447. } else {
  1448. $('<a href="#">{0}</a>'.f(val)).appendTo(li);
  1449. }
  1450. });
  1451. node.on('click', 'a', priv.pageSizeChanged);
  1452. } else {
  1453. node = $('<span class="' + nodeClass + '"></span>');
  1454. }
  1455. currentNode.replaceWith(node);
  1456. };
  1457. priv.renderFooterColumnPicker = function() {
  1458. var nodeClass = 'tblAjax__' + 'footer__toolbar__columnPicker',
  1459. currentNode = $(_uiNodeCont).next('.foot').find('.' + nodeClass),
  1460. node;
  1461. if (priv.options.debug) console.log('Render: ', nodeClass);
  1462. if (priv.options.columnPicker) {
  1463. node = $('<div class="btn-group dropup columnpicker ' + nodeClass + '"></div>');
  1464. var btn = $('<button class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" href="#">Kolumny&nbsp;</button>').appendTo(node);
  1465. var span = $('<span class="caret"></span>').appendTo(btn);
  1466. var ul = $('<ul class="dropdown-menu" style="max-height:250px;overflow:auto;">').appendTo(node);
  1467. $.each(_data.cols, function(col, props) {
  1468. if (props.type != "unique" && col != 'ID') {
  1469. var li = $('<li></li>').appendTo(ul),
  1470. a = $('<a href="#" style="padding:0px 20px;"></a>').appendTo(li),
  1471. label = props.friendly || col;
  1472. label = label.replace(/<br\/?>/g, ' ');
  1473. $('<input {0} type="checkbox" title="{1}" value="{1}" style="margin:0">&nbsp;{2}</input>'.f((props.hidden) ? '' : 'checked', col, label)).appendTo(a);
  1474. }
  1475. });
  1476. node.on('click', 'input', priv.columnPickerClicked);
  1477. node.on('click', 'a', priv.columnPickerLinkClicked);
  1478. } else {
  1479. node = $('<span class="' + nodeClass + '"></span>');
  1480. }
  1481. currentNode.replaceWith(node);
  1482. };
  1483. priv.renderFooterFunctions = function() {
  1484. var nodeClass = 'tblAjax__' + 'footer__toolbar__functions',
  1485. currentNode = $(_uiNodeCont).next('.foot').find('.' + nodeClass),
  1486. node;
  1487. if (priv.options.debug) console.log('Render: ', nodeClass);
  1488. if (priv.options.tblFunctions) {
  1489. node = $('<div class="btn-group ' + nodeClass + '"></div>');
  1490. $.map(priv.options.tblFunctions, function(funObj, funName){
  1491. var funHtml = $('<button class="btn btn-sm btn-default"></button>');
  1492. if (funObj.title) funHtml.attr('title', funObj.title);
  1493. if (funObj.method) funHtml.on('click', priv[funObj.method]);
  1494. else if (funObj.href) funHtml.on('click', {hash:funObj.href}, priv.routeChanged);
  1495. var funIconHtml = $('<i></i>');
  1496. if (funObj.icon) funIconHtml.attr('class', 'glyphicon glyphicon-' + funObj.icon);
  1497. funIconHtml.prependTo(funHtml);
  1498. funHtml.addClass('btn');
  1499. funHtml.appendTo(node);
  1500. });
  1501. } else {
  1502. node = $('<span class="' + nodeClass + '"></span>');
  1503. }
  1504. currentNode.replaceWith(node);
  1505. };
  1506. priv.renderFooterExport = function() {
  1507. var nodeClass = 'tblAjax__' + 'footer__toolbar__export',
  1508. currentNode = $(_uiNodeCont).next('.foot').find('.' + nodeClass),
  1509. node;
  1510. if (priv.options.debug) console.log('Render: ', nodeClass);
  1511. if (priv.options.exportFields.length) {
  1512. node = $('<div class="btn-group dropup pagesize ' + nodeClass + '"></div>');
  1513. var btn = $('<button class="btn btn-sm dropdown-toggle" data-toggle="dropdown" href="#">Export&nbsp;</button>').appendTo(node);
  1514. var span = $('<span class="caret"></span>').appendTo(btn);
  1515. var ul = $('<ul class="dropdown-menu" style="max-height:250px;padding:5px 20px 5px 8px;overflow:auto;">').appendTo(node);
  1516. $.each(_data.cols, function(col, props) {
  1517. if (-1 !== priv.options.exportFields.indexOf(col)) {
  1518. var li = $('<li></li>').appendTo(ul);
  1519. $('<input {0} type="checkbox" title="{1}" value="{1}" >&nbsp;{2}</input>'.f((_exportFieldsSelect[col])? 'checked' : '', col, props.friendly || col)).appendTo(li);
  1520. li.on('click', 'input', priv.exportFieldChanged);
  1521. }
  1522. });
  1523. var li = $('<li></li>').appendTo(ul);
  1524. $('<a href="index.php" target="_blank" class=""><i class="glyphicon glyphicon-share"></i>Export do HTML</a>').appendTo(li);
  1525. li.on('click', 'a', priv.exportToHTML);
  1526. var li = $('<li></li>').appendTo(ul);
  1527. $('<a href="index.php" target="_blank" class=""><i class="glyphicon glyphicon-share"></i>Export do CSV</a>').appendTo(li);
  1528. li.on('click', 'a', priv.exportToCSV);
  1529. } else {
  1530. node = $('<span class="' + nodeClass + '"></span>');
  1531. }
  1532. currentNode.replaceWith(node);
  1533. };
  1534. priv.renderInlineEditBox = function() {
  1535. var nodeClass = 'tblAjax__' + 'inlineEditBox',
  1536. currentNode = $(_uiNodeCont).parent().children('.' + nodeClass),
  1537. node;
  1538. var node = $('<div class="' + nodeClass + ' modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>');
  1539. /// console.log('L.<?php echo __LINE__; ?> Render: priv.renderInlineEditBox, currentNode.html:', currentNode.html(), currentNode);
  1540. var modalWrap = $('<div class="modal-dialog"></div>').appendTo(node);
  1541. var modalWrap = $('<div class="modal-content"></div>').appendTo(modalWrap);
  1542. var frmInlineEdit = $('<form style="margin:0;padding:0;"></form>').appendTo(modalWrap);
  1543. var iebHead = $('<div class="modal-header" style="cursor:pointer">').appendTo(frmInlineEdit);
  1544. $('<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="glyphicon glyphicon-remove" style="color:red"></i></button>').appendTo(iebHead);
  1545. $('<h4 id="myModalLabel">Edytuj</h4>').appendTo(iebHead);
  1546. var iebBodyWrap = $('<div class="modal-body" style="padding:0"></div>').appendTo(frmInlineEdit);
  1547. var iebBody = $('<div style="padding:15px"></div>').appendTo(iebBodyWrap);
  1548. $('<input type="hidden" name="ID" value="">').appendTo(iebBody);
  1549. $('<input type="hidden" name="col" value="">').appendTo(iebBody);
  1550. $('<div class="inlineEditBox-cnt"></div>').appendTo(iebBody);
  1551. var iebFoot = $('<div class="modal-footer"></div>').appendTo(frmInlineEdit);
  1552. $('<button class="btn" data-dismiss="modal" aria-hidden="true">Zamknij</button>').appendTo(iebFoot);
  1553. var iebBtnSave = $('<input type="submit" value="Zapisz" class="btn btn-primary btn-save">').appendTo(iebFoot);
  1554. frmInlineEdit.on('submit', function() {
  1555. var inlineEditBox$Node = $(_uiNodeCont).parent().children('.tblAjax__inlineEditBox');
  1556. var data = inlineEditBox$Node.find('form').serialize();
  1557. inlineEditBox$Node.find('.inlineEditBox-cnt').html('<span class="loading-info"> loading ...</span>');
  1558. function notifyAjaxCallback(data) {
  1559. var notify = {};
  1560. notify.type = (data && data.type)? data.type : '';
  1561. notify.msg = (data && data.msg)? data.msg : '';
  1562. switch (notify.type) {
  1563. case 'success':
  1564. if (!notify.msg) notify.msg = 'Dane poprawnie zaktualizowane';
  1565. break;
  1566. case 'info':
  1567. if (!notify.msg) notify.msg = 'Nie wprowadzono żadnych zmian';
  1568. break;
  1569. case 'error':
  1570. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  1571. break;
  1572. case 'warning':
  1573. notify.type = 'warn';
  1574. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  1575. break;
  1576. default:
  1577. notify.msg = 'Nieznany błąd';
  1578. if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
  1579. notify.type = '';
  1580. }
  1581. jQuery.notify(notify.msg, notify.type);
  1582. }
  1583. $.ajax({
  1584. data: data,
  1585. dataType: 'json',
  1586. type: "POST",
  1587. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=EDIT_INLINE_SAVE'
  1588. })
  1589. .done(function(data, textStatus, jqXHR){
  1590. notifyAjaxCallback(data);
  1591. publ.refresh();
  1592. inlineEditBox$Node.modal('hide');
  1593. })
  1594. .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
  1595. if (jqXHR.responseJSON) {
  1596. notifyAjaxCallback(jqXHR.responseJSON);
  1597. }
  1598. else {
  1599. var txt = jqXHR.responseText || 'Wystąpiły błędy';
  1600. if (jqXHR.status == 404) {
  1601. jQuery.notify(jqXHR.responseText, 'error');
  1602. } else {
  1603. jQuery.notify(jqXHR.responseText, 'warn');
  1604. }
  1605. }
  1606. inlineEditBox$Node.modal('hide');
  1607. });
  1608. return false;
  1609. });
  1610. currentNode.replaceWith(node);
  1611. };
  1612. priv.exportFieldChanged = function(e) {
  1613. e.stopPropagation();
  1614. var column = $(this).val();
  1615. _exportFieldsSelect[column] = !_exportFieldsSelect[column];
  1616. };
  1617. priv.exportToHTML = function(e) {
  1618. priv.exportData('html', $(this), e);
  1619. };
  1620. priv.exportToCSV = function(e) {
  1621. priv.exportData('csv', $(this), e);
  1622. };
  1623. priv.exportData = function(format, node, e) {
  1624. var exportFields = [];
  1625. $.each(_exportFieldsSelect, function(col, selected) {
  1626. if (selected) {
  1627. exportFields.push(col);
  1628. }
  1629. });
  1630. if (!exportFields.length) {
  1631. alert('Nie wybrano żadnych pól do eksportu.');
  1632. e.preventDefault();
  1633. return false;
  1634. }
  1635. var limit = 10000;
  1636. if (!_data.total || _data.total <= 0) {
  1637. alert('Brak rekordów do eksportu.');
  1638. e.preventDefault();
  1639. return false;
  1640. }
  1641. if (_data.total > limit) {
  1642. if (!confirm('Za dużo rekordów. Wyeksportowane zostaną tylko pierwsze ' + limit + ' z ' + _data.total + ' rekordów.')) {
  1643. e.preventDefault();
  1644. return false;
  1645. }
  1646. }
  1647. var exportUrl = 'index.php?MENU_INIT=VIEWTABLE_AJAX_EXPORT&ZASOB_ID=<?php echo $this->_zasobID; ?>';
  1648. if ('csv' == format) exportUrl += '&HEADER_NOT_INIT=YES';
  1649. exportUrl += '&format=' + format;
  1650. exportUrl += '&flds=' + exportFields.join(',');
  1651. exportUrl += '&sortCol=' + (_state.filters.currSortCol || '');
  1652. exportUrl += '&sortDir=' + (_state.filters.currSortFlip ? "desc" : "asc");
  1653. if (Object.keys(_state.filters.filterCols).length > 0) {
  1654. $.each(_state.filters.filterCols, function(col, colProps) {
  1655. if (colProps.filter && colProps.filter.length > 0) {
  1656. exportUrl += '&f_' + col + '=' + colProps.filter;
  1657. }
  1658. });
  1659. }
  1660. // specialFilters
  1661. $.each(_state.specialFilters, function(groupName, btnValue) {
  1662. if (btnValue.length > 0) {
  1663. exportUrl += '&sf_' + groupName + '=' + btnValue;
  1664. }
  1665. });
  1666. if (priv.options.forceFilterInit) {
  1667. $.map(priv.options.forceFilterInit, function(fltrProps, fltr) {
  1668. exportUrl += '&sf_' + fltr + '=' + fltrProps;
  1669. });
  1670. }
  1671. node.attr('href', exportUrl);
  1672. };
  1673. /*
  1674. calls the webservice(if defined).
  1675. used only inside priv.init
  1676. */
  1677. priv.update = function(callback) {
  1678. var skipCols, resetChecked;// undefined
  1679. if (!priv.options.url) {
  1680. if (priv.options.debug) console.log('no url found L.<?php echo __LINE__; ?>');
  1681. return;
  1682. }
  1683. if (priv.options.debug) console.log('requesting data from url:{0} data:{1} L.<?php echo __LINE__; ?>'.f(priv.options.url, JSON.stringify(priv.options.urlData) || ''));
  1684. var initUrlAdd = '',
  1685. reqData = {},
  1686. filtersInitSet = false;
  1687. initUrlAdd += '&currSortCol=' + _state.filters.currSortCol;
  1688. initUrlAdd += '&currSortFlip=' + ((_state.filters.currSortCol)? "desc" : "asc");
  1689. if (Object.keys(_state.filters.filterCols).length > 0) {
  1690. $.each(_state.filters.filterCols, function(col, colProps) {
  1691. if (colProps.filter && colProps.filter.length > 0) {
  1692. initUrlAdd += '&f_' + col + '=' + colProps.filter;
  1693. filtersInitSet = true;
  1694. }
  1695. });
  1696. }
  1697. $.each(_state.specialFilters, function(groupName, btnValue) {
  1698. if (btnValue.length > 0) {
  1699. initUrlAdd += '&sf_' + groupName + '=' + btnValue;
  1700. filtersInitSet = true;
  1701. }
  1702. });
  1703. if (priv.options.forceFilterInit) {
  1704. $.map(priv.options.forceFilterInit, function(fltrProps, fltr) {
  1705. reqData['f_' + fltr] = fltrProps;
  1706. filtersInitSet = true;
  1707. });
  1708. }
  1709. $.ajax({
  1710. url: priv.options.url + initUrlAdd,
  1711. type: priv.options.urlPost ? 'POST' : 'GET',
  1712. dataType: 'json',
  1713. contentType: "application/json; charset=utf-8",
  1714. data: reqData,
  1715. async: true,
  1716. success: function(data) {
  1717. if (priv.options.debug) console.log('request finished L.<?php echo __LINE__; ?>');
  1718. // assign the new data
  1719. if (data && data.cols) {
  1720. priv.setStateCols(data.cols, data.uniqueCol);
  1721. }
  1722. // set initial filters (_state.filters.filterCols)
  1723. if (filtersInitSet && _data && _data.cols) {
  1724. $.map(reqData, function(fltrValue, fltr){
  1725. var colName = null;
  1726. if (fltr.substr(0, 3) == 'sf_') {
  1727. colName = fltr.substr(3);
  1728. }
  1729. else if (fltr.substr(0, 2) == 'f_') {
  1730. colName = fltr.substr(2);
  1731. }
  1732. if (colName && _data.cols[colName]) {
  1733. //add the filter to the filter array
  1734. _state.filters.filterCols[colName] = {
  1735. filter: fltrValue,
  1736. colName: colName
  1737. };
  1738. }
  1739. });
  1740. }
  1741. // assign the new state (data)
  1742. state = {data: {}};
  1743. if (!skipCols) state.data.cols = data.cols || {};
  1744. state.data.rows = data.rows || [];
  1745. state.data.total = data.total || 0;
  1746. state.page = data.page || 0;
  1747. state.pageSize = data.pageSize || priv.options.pageSize;
  1748. state.filters = data.filters || {};
  1749. priv.setState(state);
  1750. if (typeof callback == "function")
  1751. callback.call(this);
  1752. },
  1753. error: function(err) {
  1754. //console.log('request error: {0}'.f(JSON.stringify(err)));
  1755. if (typeof callback == "function")
  1756. callback.call(this);
  1757. }
  1758. });
  1759. };
  1760. /*
  1761. assigns the new data.
  1762. */
  1763. priv.setState = function(state) {
  1764. var oldState = _state,// TODO: use to check what really changed (use extend!)
  1765. renderParts = {};
  1766. if (state.data) {
  1767. if (state.data.cols && state.data.cols.length > 0) {// TODO: never happen, but if happend then rerender all
  1768. priv.setStateCols(state.data.cols, state.data.uniqueCol);
  1769. priv.setStateData(state.data);
  1770. renderParts['head'] = true;
  1771. } else {
  1772. priv.setStateData(state.data, true);
  1773. }
  1774. renderParts['body'] = true;
  1775. renderParts['foot_pagination'] = true;
  1776. }
  1777. if (state.hasOwnProperty('specialFilters')) {
  1778. _state.specialFilters = state.specialFilters;
  1779. renderParts['head__specialFilters'] = true;
  1780. }
  1781. if (state.hasOwnProperty('page')) {
  1782. if (state.page != _state.page) {
  1783. _state.page = state.page;
  1784. renderParts['foot_pagination'] = true;
  1785. }
  1786. }
  1787. if (state.hasOwnProperty('pageSize')) {
  1788. if (state.pageSize != _state.pageSize) {
  1789. _state.pageSize = state.pageSize;
  1790. renderParts['foot_pagination'] = true;
  1791. }
  1792. }
  1793. if (state.hasOwnProperty('filters')) {
  1794. /// console.log('L.<?php echo __LINE__; ?> setState::state.filters: ', state.filters);//TODO:DBG:RMME
  1795. priv.setStateFilters(state.filters);
  1796. // TODO: if state diff's
  1797. renderParts['head__specialFilters'] = true;
  1798. renderParts['foot_pagination'] = true;
  1799. }
  1800. renderParts = Object.keys(renderParts);
  1801. if (priv.options.debug) console.log('setState::renderParts: ', renderParts);//TODO:DBG:RMME
  1802. ///console.log('L.<?php echo __LINE__; ?> setState::renderParts: ', renderParts);//TODO:DBG:RMME
  1803. if (renderParts.length > 0) {
  1804. jQuery(_uiNodeCont).trigger('TableAjax:render', renderParts);
  1805. }
  1806. };
  1807. priv.setStateCols = function(cols, uniqueCol) {
  1808. _state.cols = cols;
  1809. _state.uniqueCol = uniqueCol;
  1810. // fix col name - props.column
  1811. $.each(_state.cols, function(col, props) {
  1812. props.column = col;
  1813. });
  1814. // fix col types - default 'string'
  1815. $.each(_state.cols, function(col, props) {
  1816. if (!props.type) cols[col].type = "string";
  1817. });
  1818. // fix props.filter - set true if not set - TODO: allow filter this col?
  1819. $.each(_state.cols, function(col, props) {
  1820. if (props.filter == undefined) props.filter = true;
  1821. });
  1822. if (_state.uniqueCol) {
  1823. //create a unique column definition
  1824. _state.cols["unique"] = {
  1825. column: "unique",
  1826. type: "unique",
  1827. index: -1,
  1828. hidden: true
  1829. };
  1830. }
  1831. _state.colsSorted = Object.keys(_state.cols).sort(function(a, b) {
  1832. return _state.cols[a].index - _state.cols[b].index;
  1833. });
  1834. };
  1835. priv.setStateFilters = function(stateFilters) {
  1836. var newFilterCols = {},
  1837. newSpecialFilters = {};
  1838. $.map(stateFilters, function(fltrProps, fltr) {
  1839. switch (fltr) {
  1840. case 'currSortCol': _state.filters.currSortCol = fltrProps; break;
  1841. case 'currSortFlip': _state.filters.currSortFlip = (fltrProps == 'desc')? true : false; break;
  1842. default:
  1843. if (fltr.substr(0, 2) == 'f_') {
  1844. newFilterCols[fltr.substr(2)] = {
  1845. filter: fltrProps,
  1846. colName: fltr.substr(2)
  1847. };
  1848. }
  1849. else if (fltr.substr(0, 3) == 'sf_') {
  1850. var groupName = fltr.substr(3);
  1851. if (priv.options.specialFilterFunctions.hasOwnProperty(groupName)) {
  1852. newSpecialFilters[groupName] = fltrProps;
  1853. }
  1854. }
  1855. }
  1856. });
  1857. _state.filters.filterCols = newFilterCols;
  1858. _state.specialFilters = newSpecialFilters;
  1859. };
  1860. priv.setStateData = function(pData, skipCols, resetChecked) {
  1861. var data = $.extend(true, {}, pData);
  1862. data.cols = _state.cols;// always use old cols - change cols mved to priv.setStateCols
  1863. _data = data;
  1864. _data.rowsOrg = _data.rows;
  1865. //we might have more/less data now. Recalculate stuff.
  1866. if (_state.page > 1) {
  1867. _totalPages = Math.ceil(_data.total / priv.options.pageSize);
  1868. }
  1869. //keep any previously checked rows around?
  1870. if (resetChecked === true || resetChecked === undefined)
  1871. _uniqueCols = {};
  1872. else {
  1873. for (var key in _uniqueCols)
  1874. _uniqueCols[key] = priv.getRow(key);
  1875. }
  1876. if (_state.uniqueCol) {
  1877. //add rows that needs to be pre-checked
  1878. $.each(_data.rows, function(index, row) {
  1879. if (row["checked"] === true)
  1880. _uniqueCols[row[_state.uniqueCol]] = row;
  1881. });
  1882. }
  1883. };
  1884. /**
  1885. * Filters the data.
  1886. */
  1887. priv.filter = function() {
  1888. if (!priv.options.filter) return;
  1889. if (Object.keys(_state.filters.filterCols).length == 0) return;
  1890. publ.loadPage(0);
  1891. };
  1892. /*
  1893. sorts the data on the current sorting column
  1894. */
  1895. priv.sort = function() {
  1896. if (!_data.cols[_state.filters.currSortCol]) _state.filters.currSortCol = "";
  1897. if (!_state.filters.currSortCol) return;
  1898. publ.loadPage(0);
  1899. };
  1900. /*
  1901. helper that returns the underlying data by the unique value
  1902. */
  1903. priv.getRow = function(uniqueValue) {
  1904. var row;
  1905. $.each(_data.rowsOrg, function(i, r) {
  1906. if (r[_state.uniqueCol] == uniqueValue) {
  1907. row = r;
  1908. return false;
  1909. }
  1910. });
  1911. return row;
  1912. };
  1913. /*
  1914. when: typing a filter
  1915. what: triggers filtering on the value
  1916. */
  1917. priv.filterChanged = function(e) {
  1918. //clear old timer if we're typing fast enough
  1919. if (priv.options.debug) console.log('filterChanged L.<?php echo __LINE__; ?>');
  1920. if (_filterTimeout) {
  1921. clearTimeout(_filterTimeout);
  1922. if (priv.options.debug) console.log('filtering cancelled');
  1923. }
  1924. var filter = this.value
  1925. , fltr = $(this)
  1926. , col = _data.cols[e.data.column]
  1927. , timeout = 300;
  1928. if (this.value) {
  1929. if (!fltr.hasClass('filter-active')) {
  1930. fltr.addClass('filter-active');
  1931. }
  1932. } else {
  1933. if (fltr.hasClass('filter-active')) {
  1934. fltr.removeClass('filter-active');
  1935. }
  1936. }
  1937. //boolean filters needs some special care
  1938. if (col.type == "bool" || col.type == "unique") {
  1939. timeout = 0;
  1940. var elem = $(this);
  1941. var cssClass = 'indeterminate';
  1942. if (elem.hasClass(cssClass)) {
  1943. e.preventDefault();
  1944. elem.removeClass(cssClass);
  1945. filter = true;
  1946. } else {
  1947. if (!elem.is(':checked')) {
  1948. filter = false;
  1949. } else {
  1950. elem.addClass(cssClass);
  1951. filter = '';
  1952. }
  1953. }
  1954. }
  1955. //add the filter to the filter array
  1956. _state.filters.filterCols[col.column] = {
  1957. filter: filter,
  1958. colName: col.column
  1959. };
  1960. //wait a few deciseconds before filtering
  1961. _filterTimeout = setTimeout(function() {
  1962. _filterTimeout = undefined;
  1963. priv.filter();
  1964. }, timeout);
  1965. };
  1966. priv.filtersClean = function(e) {
  1967. if (_filterTimeout) {
  1968. clearTimeout(_filterTimeout);
  1969. if (priv.options.debug) console.log('filtering cancelled - filtersClean');
  1970. }
  1971. var filtersActive = false;
  1972. $.map(_state.filters.filterCols, function(colProps, col) {
  1973. if (colProps.filter.length > 0) {
  1974. filtersActive = true;
  1975. colProps.filter = '';
  1976. }
  1977. });
  1978. if (filtersActive) {
  1979. // TODO: dont remove value from forceFilterInit fields - no field names in search fields?
  1980. /// TODO: rerender _head (thead.filter)
  1981. var elems = _uiNode$Table.find('thead').find('.filter').find('input');
  1982. elems.val('').prop('disabled', false);
  1983. elems.removeClass('filter-active');
  1984. priv.filter();
  1985. }
  1986. return false;
  1987. },
  1988. /**
  1989. * Filters the data by specialFilter.
  1990. * when: click on special filter
  1991. * what: triggers filtering on the value
  1992. */
  1993. priv.specialFilterChanged = function(e) {
  1994. if (priv.options.debug) console.log('specialFilterChanged e.data:', e.data);
  1995. var state = {};
  1996. state.specialFilters = _state.specialFilters;
  1997. state.specialFilters[e.data.group] = e.data.value;
  1998. priv.setState(state);
  1999. publ.loadPage(0);
  2000. };
  2001. priv.longTextChanged = function(e) {
  2002. priv.options.longDesc = !priv.options.longDesc;
  2003. _bodyNode.find('td').each(function(ind, el){
  2004. var $el = jQuery(el);
  2005. if (!$el.attr('class') || $el.attr('class') == 'tbl-short-txt') {
  2006. //console.log(el.attr('class') + ': ' + el.text());
  2007. if (el.firstChild && el.firstChild.nodeName == 'SPAN') {
  2008. if (priv.options.longDesc) {
  2009. $el.addClass('tbl-short-txt');
  2010. var $elSpan = jQuery(el.firstChild);
  2011. $elSpan.tooltip({title: $elSpan.text(), placement: 'left'});
  2012. } else {
  2013. $el.removeClass('tbl-short-txt');
  2014. }
  2015. }
  2016. }
  2017. });
  2018. return false;
  2019. };
  2020. priv.mapEditorHide = function() {
  2021. priv.options.mapEditor = false;
  2022. if ('window' == priv.options.mapEditorContainer) {
  2023. //_mapEditorDialog.dialog("close");
  2024. _mapEditorDialog.dialog("destroy");
  2025. }
  2026. _mapEditorWrap.hide();
  2027. _mapEditor.hide();
  2028. };
  2029. priv.mapEditorShow = function() {
  2030. //console.log('TODO:mapEditorShow():', priv.options.mapEditorContainer, 'visible:', priv.options.mapEditor);
  2031. priv.options.mapEditor = true;
  2032. _mapEditor.show();
  2033. _mapEditorWrap.show();
  2034. _mapEditor.TableAjaxMap({
  2035. //debug: true,
  2036. wpsUrl: 'http://biuro.biall-net.pl/wps',
  2037. wfsUrl: 'http://biuro.biall-net.pl/wps',
  2038. showAddLayerWidget: <?php echo ($this->hasAdditionalLayers())? 'true' : 'false'; ?>,
  2039. zoomStrategyActivate: 14,
  2040. layerName: '<?php echo $this->getLabelHtml(); ?>',
  2041. addBtn: {
  2042. title: 'Przenieś mapę do okna',
  2043. displayClass: 'mapEditor-btnBackToWindow',
  2044. trigger: function() {
  2045. priv.mapEditorHide();
  2046. priv.options.mapEditorContainer = 'window';
  2047. priv.mapEditorShow();
  2048. priv.resizableMapDockNode('destroy');
  2049. }
  2050. },
  2051. onSaveFeature: function(selectedRecordId, selectedFeatureExtent) {
  2052. if (priv.options.debug) console.log('onSaveFeature (',selectedRecordId,'/',selectedFeatureExtent,') ', this);
  2053. if (!selectedRecordId) {
  2054. alert('Brak zaznaczonego rekordu - wybierz rekord z tabeli');
  2055. return;
  2056. }
  2057. function notifyAjaxCallback(data) {
  2058. var notify = {};
  2059. notify.type = (data && data.type)? data.type : '';
  2060. notify.msg = (data && data.msg)? data.msg : '';
  2061. switch (notify.type) {
  2062. case 'success':
  2063. if (!notify.msg) notify.msg = 'Aktualizacja danych dla rekordu ' + selectedRecordId;
  2064. break;
  2065. case 'info':
  2066. if (!notify.msg) notify.msg = 'Nie wprowadzono żadnych zmian';
  2067. break;
  2068. case 'error':
  2069. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  2070. break;
  2071. case 'warning':
  2072. notify.type = 'warn';
  2073. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  2074. break;
  2075. default:
  2076. notify.msg = 'Nieznany błąd';
  2077. if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
  2078. notify.type = '';
  2079. }
  2080. jQuery.notify(notify.msg, notify.type);
  2081. }
  2082. $.ajax({
  2083. data: {polygon: selectedFeatureExtent},
  2084. dataType: 'json',
  2085. type: "POST",
  2086. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=THE_GEOM_SAVE&ID=' + selectedRecordId
  2087. })
  2088. .done(function(data, textStatus, jqXHR){
  2089. notifyAjaxCallback(data);
  2090. //jQuery.notify('Aktualizacja danych dla rekordu ' + selectedRecordId, 'success');
  2091. publ.loadPage(0);// TODO: reload table data
  2092. })
  2093. .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
  2094. if (jqXHR.responseJSON) {
  2095. notifyAjaxCallback(jqXHR.responseJSON);
  2096. }
  2097. else {
  2098. var txt = jqXHR.responseText || 'Wystąpiły błędy';
  2099. if (jqXHR.status == 404) {
  2100. jQuery.notify(jqXHR.responseText, 'error');
  2101. } else {
  2102. jQuery.notify(jqXHR.responseText, 'warn');
  2103. }
  2104. }
  2105. });
  2106. },
  2107. onSelectBox: function(bounds) {
  2108. if (undefined !== OpenLayers.Bounds && bounds instanceof OpenLayers.Bounds) {
  2109. var column = 'the_geom';
  2110. if (undefined !== _filterFields['the_geom']) {
  2111. var filter = 'BBOX:' + bounds.top + ',' + bounds.right + ',' + bounds.bottom + ',' + bounds.left;
  2112. _filterFields[column].val(filter);
  2113. _state.filters.filterCols[column] = {
  2114. filter: filter,
  2115. colName: column
  2116. };
  2117. priv.filter();
  2118. }
  2119. }
  2120. }
  2121. });
  2122. priv.mapEditorShowElement();
  2123. };
  2124. priv.mapEditorShowElement = function() {
  2125. if ('window' == priv.options.mapEditorContainer) {
  2126. var mapEditor = _mapEditorWrap.children('.mapEditor-map');
  2127. if (!mapEditor || !mapEditor.length) {
  2128. var tblCont = jQuery(_uiNodeCont).parent('.AjaxTableCont');
  2129. var mapEditor = tblCont.children('.AjaxTableCont-mapEditorContainer').children('.mapEditor-map');
  2130. if (!mapEditor || !mapEditor.length) {
  2131. // TODO: create new map
  2132. }
  2133. _mapEditorWrap.append(mapEditor);
  2134. }
  2135. _mapEditorWrap.css({padding:'5px'});
  2136. _mapEditorDialog = _mapEditorWrap.dialog({
  2137. width: 540,
  2138. minWidth: 400,
  2139. minHeight: 400,
  2140. open: function(e, ui) {
  2141. var n = jQuery(this),
  2142. mapWrap = n.children(":first"),
  2143. map = mapWrap.children(":first");
  2144. map.css({width: n.width() - 5, height: n.height() - 5});
  2145. _mapEditor.TableAjaxMapUpdateSize();
  2146. },
  2147. resizeStart: function(e, ui) {
  2148. jQuery(this).children(":first").children(":first").css({display:'none'});
  2149. },
  2150. resizeStop: function(e, ui){
  2151. var n = jQuery(this),
  2152. map = n.children(":first").children(":first");
  2153. n.css({width: n.parent().width()});
  2154. map.css({display: 'block', height: n.height(), width: n.width()});
  2155. _mapEditor.TableAjaxMapUpdateSize();
  2156. },
  2157. dragStop: function(e, ui){
  2158. _mapEditor.TableAjaxMapUpdateSize();// to prevent drag-zoom error
  2159. }
  2160. });
  2161. _mapEditorWrap.bind('dialogclose', function(e) {
  2162. priv.options.mapEditor = false;
  2163. });
  2164. var dialogTitleBar = _mapEditorDialog.parent().parent().find('.ui-dialog-titlebar');
  2165. var dialogTitleBarCloseBtn = dialogTitleBar.find('.ui-dialog-titlebar-close');
  2166. if (dialogTitleBarCloseBtn) {
  2167. var btnToggle = jQuery('<span style="width:18px;height:18px;position:absolute;top:50%;right:25px;margin-top:-9px;" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only"><i style="margin-top:3px;" class="glyphicon glyphicon-fullscreen"></i></span>');
  2168. btnToggle.on('click', function(e) {
  2169. priv.options.mapEditorContainer = 'dock';
  2170. _mapEditorWrap.dialog('close');
  2171. priv.mapEditorShowElement();
  2172. });
  2173. btnToggle.insertBefore(dialogTitleBarCloseBtn);
  2174. }
  2175. }
  2176. else if ('dock' == priv.options.mapEditorContainer) {
  2177. priv.resizableMapDockNode('prepare');
  2178. _mapEditor.TableAjaxMapUpdateSize();
  2179. }
  2180. };
  2181. priv.resizableMapDockNode = function(task) {
  2182. if ('prepare' == task) {
  2183. var mapEditor = _mapEditorWrap.children('.mapEditor-map');
  2184. if (mapEditor && mapEditor.length) {// map is inside _mapEditorWrap (window)
  2185. var mapDockNode = jQuery('<div class="AjaxTableCont-mapEditorContainer"></div>');
  2186. var tblCont = jQuery(_uiNodeCont).parent('.AjaxTableCont');
  2187. tblCont.children('.AjaxTableCont-mapEditorContainer').remove();
  2188. var breadcrumb = tblCont.children('.breadcrumb');
  2189. if (!breadcrumb || !breadcrumb.length) {
  2190. tblCont.prepend(mapDockNode);
  2191. } else {
  2192. mapDockNode.insertAfter(breadcrumb);
  2193. }
  2194. mapDockNode.append(mapEditor);
  2195. }
  2196. var mapDockResizable = mapEditor.parent();
  2197. mapDockResizable.resizable({handles: 's', minHeight: 300, minWidth: 300});
  2198. var resizeLineHeigth = 6;
  2199. mapDockResizable.children(":first").css({height: 'auto'});
  2200. mapDockResizable.css({marginBottom: resizeLineHeigth+'px'});
  2201. mapEditor.css({marginBottom: resizeLineHeigth+'px'});
  2202. mapEditor.children(":first").css({width: mapEditor.width()});
  2203. mapDockResizable.find('.ui-resizable-s').css({height:resizeLineHeigth+'px', bottom: '-'+resizeLineHeigth+'px'});
  2204. mapDockResizable.on('resizestart', function(event, ui) {
  2205. ui.element.children(":first").children(":first").css({display:'none'})
  2206. });
  2207. mapDockResizable.on('resizestop', function(event, ui) {
  2208. ui.element.children(":first").children(":first").css({display:'block', height: ui.element.height()});
  2209. });
  2210. } else if ('destroy' == task) {
  2211. var mapDockResizable = jQuery(_uiNodeCont).parent('.AjaxTableCont').children('.AjaxTableCont-mapEditorContainer');
  2212. mapDockResizable.resizable('destroy');
  2213. mapDockResizable.remove();
  2214. }
  2215. };
  2216. priv.mapEditorChanged = function(e) {
  2217. if (priv.options.debug) console.log('mapEditorChanged option(',priv.options.mapEditor,')');
  2218. priv.options.mapEditor = !priv.options.mapEditor;
  2219. if (priv.options.mapEditor) {
  2220. priv.mapEditorShow();
  2221. }
  2222. else {
  2223. priv.mapEditorHide();
  2224. }
  2225. return false;
  2226. };
  2227. /*
  2228. when: changing page in pager
  2229. what: triggers table to be created with new page
  2230. */
  2231. priv.pageChanged = function(e) {
  2232. e.preventDefault();
  2233. var totalPages = Math.ceil(_data.total / _state.pageSize);
  2234. if (e.data.pageIndex < 1 || e.data.pageIndex > totalPages) return;
  2235. //set the new page
  2236. _state.page = e.data.pageIndex;
  2237. publ.loadPage(_state.page);
  2238. };
  2239. /*
  2240. when: changing pagesize in pagesize dropdown
  2241. what: triggers table to be created with new pagesize
  2242. */
  2243. priv.pageSizeChanged = function(e) {
  2244. e.preventDefault();
  2245. var val = $(this).text();
  2246. if (priv.options.debug) console.log('pagesize changed to:{0}'.f(val));
  2247. if (parseInt(val) == priv.options.pageSize) {
  2248. return false;
  2249. }
  2250. priv.options.pageSize = parseInt(val);
  2251. publ.loadPage(1, priv.options.pageSize);
  2252. jQuery(_uiNodeCont).trigger('TableAjax:render', ['body', 'foot_pagination']);
  2253. priv.saveProfilePageSize(priv.options.pageSize);
  2254. };
  2255. /*
  2256. when: clicking a column
  2257. what: triggers table to be sorted by the column
  2258. */
  2259. priv.columnClicked = function(e) {
  2260. e.preventDefault();
  2261. if (priv.options.debug) console.log('col:{0} clicked'.f(e.data.column));
  2262. //set the new sorting column
  2263. if (_state.filters.currSortCol == e.data.column) _state.filters.currSortFlip = !_state.filters.currSortFlip;
  2264. _state.filters.currSortCol = e.data.column;
  2265. /// TODO: var state = {}; state.currSortCol = ''; state.currSortFlip = ''; priv.setState(state);
  2266. _headSort = undefined;
  2267. _body = undefined;
  2268. priv.sort();
  2269. };
  2270. priv.saveProfilePageSize = function(pageSize) {
  2271. var reqData = {};
  2272. reqData.pageSize = pageSize;
  2273. $.ajax({
  2274. data: reqData,
  2275. type: "POST",
  2276. dataType: 'json',
  2277. // async: true,
  2278. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=PAGE_SIZE_SAVE'
  2279. })
  2280. .done(function(data, textStatus, jqXHR){
  2281. if (data && data.type && data.type == 'info') {
  2282. jQuery.notify('Nie wprowadzono żadnych zmian', 'info');
  2283. } else {
  2284. jQuery.notify('Zapisano ustawienia', 'success');
  2285. }
  2286. })
  2287. .fail(function(){
  2288. jQuery.notify('Wystąpił błąd podczas zapisywania ustawień', 'error');
  2289. });
  2290. };
  2291. priv.saveHiddenCols = function() {
  2292. var reqData = {};
  2293. $.each(_data.cols, function(col, props) {
  2294. if (props.type != "unique" && col != 'unique' && col != 'ID') {
  2295. reqData[col] = (props.hidden)? 'HIDE' : 'SHOW';
  2296. }
  2297. });
  2298. $.ajax({
  2299. data: reqData,
  2300. type: "POST",
  2301. dataType: 'json',
  2302. // async: true,
  2303. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=HIDDEN_COLS_SAVE'
  2304. })
  2305. .done(function(data, textStatus, jqXHR){
  2306. if (data && data.type && data.type == 'info') {
  2307. jQuery.notify('Nie wprowadzono żadnych zmian', 'info');
  2308. } else {
  2309. jQuery.notify('Zapisano ustawienia', 'success');
  2310. }
  2311. })
  2312. .fail(function(){
  2313. jQuery.notify('Wystąpił błąd podczas zapisywania ustawień', 'error');
  2314. });
  2315. };
  2316. /*
  2317. when: clicking a column in columnpicker
  2318. what: triggers table to show/hide the column
  2319. */
  2320. priv.columnPickerClicked = function(e) {
  2321. e.stopPropagation();
  2322. var column = $(this).val();
  2323. //toggle column visibility
  2324. _data.cols[column].hidden = !_data.cols[column].hidden;
  2325. priv.saveHiddenCols();
  2326. //_data.cols[column].index = new priv.ext.XDate();
  2327. jQuery(_uiNodeCont).trigger('TableAjax:render', ['head', 'body']);
  2328. };
  2329. priv.columnPickerLinkClicked = function(e) {
  2330. e.stopPropagation();
  2331. e.preventDefault();
  2332. var input$ = $(this).find('input');
  2333. if (input$.length != 1) return;
  2334. var column = input$.val();
  2335. if (!column) return;
  2336. input$.prop("checked", !input$.is(':checked'));
  2337. //toggle column visibility
  2338. _data.cols[column].hidden = !_data.cols[column].hidden;
  2339. priv.saveHiddenCols();
  2340. //_data.cols[column].index = new priv.ext.XDate();
  2341. jQuery(_uiNodeCont).trigger('TableAjax:render', ['head', 'body']);
  2342. };
  2343. priv.columnHideClicked = function(e) {
  2344. e.stopPropagation();
  2345. var column;
  2346. if (e.data && e.data.column) {
  2347. column = e.data.column;
  2348. } else {
  2349. return;
  2350. }
  2351. //toggle column visibility
  2352. _data.cols[column].hidden = !_data.cols[column].hidden;
  2353. priv.saveHiddenCols();
  2354. //_data.cols[column].index = new priv.ext.XDate();
  2355. jQuery(_uiNodeCont).trigger('TableAjax:render', ['head', 'body', 'foot__columnPicker']);
  2356. };
  2357. /*
  2358. when: clicking a row checkbox
  2359. what: toggles checked state on row, and add/removes it from checked array
  2360. */
  2361. priv.rowChecked = function(e) {
  2362. var elem = $(this);
  2363. //get the row's unique value
  2364. var unique = elem.closest('tr').data('unique');
  2365. if (priv.options.debug) console.log('row({0}) {1}'.f(unique, elem.is(':checked') ? 'checked' : 'unchecked'));
  2366. //store the row in checked array
  2367. if (elem.is(':checked')) _uniqueCols[unique] = priv.getRow(unique);
  2368. else delete _uniqueCols[unique];
  2369. };
  2370. /*
  2371. when: clicking anywhere on a row
  2372. what: row data and other info is returned to caller
  2373. */
  2374. // priv.rowClicked = function(e) {// TODO: not used
  2375. // if (!_state.uniqueCol) {
  2376. // if (priv.options.debug) console.log('no unique column specified');
  2377. // return;
  2378. // }
  2379. // //gather callback data
  2380. // var elem = $(this);
  2381. // var column = _data.cols[elem.data('column')];
  2382. // var unique = elem.closest('tr').data('unique');
  2383. // var row = priv.getRow(unique);
  2384. // var isChecked = elem.closest('tr').find('.unique').is(':checked');
  2385. // //trigger callback
  2386. // if (typeof priv.options.rowClicked == 'function') {
  2387. // priv.options.rowClicked.call(e.target, {
  2388. // event: e,
  2389. // row: row,
  2390. // column: column,
  2391. // checked: isChecked
  2392. // });
  2393. // }
  2394. // };
  2395. /**
  2396. * Inline edit.
  2397. */
  2398. priv.rowDblClicked = function(e) {
  2399. var inlineEditBox$Node = $(_uiNodeCont).parent().children('.tblAjax__inlineEditBox');
  2400. // hide popover for typespecial fld on click
  2401. if (_popoverCellCurrent) {
  2402. _popoverCellCurrent.popover('hide');
  2403. }
  2404. // e.clientX: 1002; e.clientY: 245
  2405. if ('id' in e.data && 'col' in e.data && e.data.id > 0) {
  2406. inlineEditBox$Node.modal();
  2407. inlineEditBox$Node.show();
  2408. inlineEditBox$Node.on('shown.bs.modal', function(e) {
  2409. var dialogBox = jQuery(this).find('.modal-dialog'),
  2410. modalBody = dialogBox.find('.modal-body'),
  2411. boudingRect = dialogBox.get(0).getBoundingClientRect();
  2412. dialogBox.css({position: 'absolute', margin:0, top: boudingRect.top, left: boudingRect.left});
  2413. modalBody.css({overflow: 'scroll'});
  2414. dialogBox.resizable({minHeight: 300, minWidth: 300, alsoResize: modalBody});
  2415. dialogBox.draggable({handle: '.modal-header'});
  2416. });
  2417. inlineEditBox$Node.on('hidden.bs.modal', function(e) {
  2418. var dialogBox = jQuery(this).find('.modal-dialog'),
  2419. modalBody = dialogBox.find('.modal-body');
  2420. dialogBox.removeAttr('style');
  2421. modalBody.removeAttr('style');
  2422. modalBody.css({padding: '0'});
  2423. dialogBox.resizable();
  2424. dialogBox.draggable();
  2425. dialogBox.resizable('destroy');
  2426. dialogBox.draggable('destroy');
  2427. });
  2428. inlineEditBox$Node.find('input[name=ID]').val(e.data.id);
  2429. inlineEditBox$Node.find('input[name=col]').val(e.data.col);
  2430. inlineEditBox$Node.find('.inlineEditBox-cnt').html('<span class="loading-info"> loading ...</span>');
  2431. $.ajax({
  2432. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=EDIT_INLINE&ID=' + e.data.id + '&col=' + e.data.col,
  2433. type: 'GET',
  2434. dataType: 'text',
  2435. data: '',
  2436. async: true,
  2437. success: function(data) {
  2438. inlineEditBox$Node.find('.inlineEditBox-cnt').html(data);
  2439. inlineEditBox$Node.find('.btn-save').show();
  2440. initDateTimePicker(inlineEditBox$Node);
  2441. inlineEditBox$Node.find('textarea').autosize();
  2442. var fld = inlineEditBox$Node.find('input[id^="f"]');
  2443. if (fld && !fld.hasClass('se_type-date')) {
  2444. fld.focus();
  2445. fld.keydown(function(event) {
  2446. if (event.which == 13) {
  2447. event.preventDefault();
  2448. inlineEditBox$Node.find('form').submit();
  2449. }
  2450. });
  2451. }
  2452. },
  2453. error: function(err) {
  2454. if (priv.options.debug) console.log('err');
  2455. }
  2456. });
  2457. } else {
  2458. if (priv.options.debug) console.log('NO data');
  2459. return false;
  2460. }
  2461. };
  2462. priv.ajaxLoadTypeSpeciallCell = function(id, col) {
  2463. if (_popoverCellAjaxXhr) {
  2464. _popoverCellAjaxXhr.abort();
  2465. }
  2466. _popoverCellAjaxXhr = $.ajax({
  2467. type: 'GET',
  2468. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=TYPESPECIALL_CELL&ID=' + id + '&col=' + col,
  2469. dataType: 'json',
  2470. contentType: "application/json; charset=utf-8",
  2471. data: '',
  2472. success: function(req){
  2473. if (req.data && req.data.tbl_id > 0) {
  2474. var addHtml = '';
  2475. for(var i in req.data.items){
  2476. var url = 'index.php?MENU_INIT=VIEWTABLE_AJAX';
  2477. url += '&ZASOB_ID=' + req.data.tbl_id;
  2478. url += '&f_' + req.data.fld_name + '=' + req.data.items[i].id;
  2479. url += '&_hash=' + Math.random().toString(36).substring(2);
  2480. addHtml += '<a href="' + url + '">Wyszukaj ' + req.data.items[i].id + '</a>: ' + req.data.items[i].label;
  2481. addHtml += '<br>';
  2482. }
  2483. //_popoverCell.append(addHtml);// cache
  2484. if (_popoverCellCurrent) {
  2485. var popoverNodeId = _popoverCellCurrent.attr('aria-describedby');
  2486. if (popoverNodeId) {
  2487. jQuery('#' + popoverNodeId).find('.popoverCellContent').append(addHtml);
  2488. }
  2489. }
  2490. }
  2491. }
  2492. });
  2493. };
  2494. priv.popoverCellTypeSpecial = function(e) {
  2495. e.preventDefault();
  2496. e.stopPropagation();
  2497. if ('id' in e.data && 'col' in e.data && e.data.id > 0) {
  2498. var lastId = _popoverCell.data('rowid'),
  2499. lastCol = _popoverCell.data('col'),
  2500. rowPK = e.data.id,
  2501. colName = e.data.col
  2502. ;
  2503. if (lastId == rowPK && lastCol == colName) {
  2504. //_popoverCellCurrent.popover('toggle');
  2505. }
  2506. else {
  2507. if (_popoverCellCurrent) {
  2508. _popoverCellCurrent.popover('destroy');
  2509. }
  2510. _popoverCell.data('rowid', rowPK);
  2511. _popoverCell.data('col', colName);
  2512. _popoverCell.html(e.data.value + '<div class="popoverCellContent loading" style="white-space:normal"></div>');
  2513. _popoverCellCurrent = jQuery(e.currentTarget);
  2514. // title : '<span class="text-info"><strong>title</strong></span> <button type="button" id="close" class="close">&times;</button>'
  2515. var opts = {
  2516. placement: 'left'
  2517. , trigger: 'click'
  2518. // , title: e.data.col + '<a href="#" class="glyphicon glyphicon-remove pull-right" onclick="return hidePopover();"></a>'
  2519. , title: '<div style="display:block;position:relative;padding:0 20px 0 0;">' + (e.data.friendly || colName) + ' <button type="button" class="close" onclick="return hidePopover();" style="position:absolute;right:0;top:0;">&times;</button>' + '</div>'
  2520. , html: true
  2521. , content: _popoverCell.html()
  2522. }
  2523. _popoverCellCurrent.popover(opts);
  2524. if (_data.cols[colName]) {
  2525. if (_data.cols[colName]._tsRetId > 0) {
  2526. _popoverCellCurrent.on('shown.bs.popover', function() {
  2527. priv.ajaxLoadTypeSpeciallCell(rowPK, colName);
  2528. });
  2529. }
  2530. }
  2531. _popoverCellCurrent.popover('show');
  2532. }
  2533. } else {
  2534. if (priv.options.debug) console.log('NO data');
  2535. return false;
  2536. }
  2537. return;
  2538. };
  2539. priv.routeChanged = function(e) {
  2540. hash = e.data.hash || '';
  2541. if (hash.length == 0) {
  2542. return;
  2543. }
  2544. if (hash.substring(0, 1) != '#') {
  2545. hash = '#' + hash;
  2546. }
  2547. location.hash = hash;
  2548. };
  2549. priv.refresh = function(e) {
  2550. e.preventDefault();
  2551. publ.loadPage(_state.page);
  2552. };
  2553. publ.init = function(options) {
  2554. if (priv.options.debug) console.log('TableAjax initialization...');
  2555. //merge supplied options with defaults
  2556. $.extend(priv.options, defaults, options);
  2557. priv.init();
  2558. return publ;
  2559. };
  2560. publ.refresh = function() {
  2561. publ.loadPage(_state.page);
  2562. };
  2563. publ.loadPage = function(page, pageSize) {
  2564. var skipCols = true, // skipCols = true - prevent columns delete
  2565. resetChecked = false;
  2566. var reqData = {
  2567. page: page,
  2568. pageSize: (pageSize || priv.options.pageSize),
  2569. currSortCol: (_state.filters.currSortCol || ''),
  2570. currSortFlip: _state.filters.currSortFlip ? "desc" : "asc"
  2571. };
  2572. if (Object.keys(_state.filters.filterCols).length > 0) {
  2573. $.each(_state.filters.filterCols, function(col, colProps) {
  2574. if (colProps.filter && colProps.filter.length > 0) {
  2575. reqData['f_' + col] = colProps.filter;
  2576. }
  2577. });
  2578. skipCols = true;
  2579. }
  2580. // specialFilters
  2581. $.each(_state.specialFilters, function(groupName, btnValue) {
  2582. if (btnValue.length > 0) {
  2583. reqData['sf_' + groupName] = btnValue;
  2584. }
  2585. });
  2586. if (priv.options.forceFilterInit) {
  2587. $.map(priv.options.forceFilterInit, function(fltrProps, fltr) {
  2588. reqData['f_' + fltr] = fltrProps;
  2589. filtersInitSet = true;
  2590. });
  2591. }
  2592. _uiNode$Table.parent().parent().addClass('AjaxTable-loading');
  2593. $.ajax({
  2594. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>',
  2595. type: 'GET',
  2596. dataType: 'json',
  2597. contentType: "application/json; charset=utf-8",
  2598. data: reqData,
  2599. async: true,
  2600. success: function(data) {
  2601. state = {data: {}};
  2602. state.data.rows = data.rows || [];
  2603. state.data.total = data.total || 0;
  2604. state.page = data.page || 0;
  2605. state.pageSize = data.pageSize || priv.options.pageSize;
  2606. state.filters = data.filters || {};
  2607. priv.setState(state);
  2608. _uiNode$Table.parent().parent().removeClass('AjaxTable-loading');
  2609. },
  2610. error: function(err) {
  2611. if (priv.options.debug) console.log('request error: {0}'.f(JSON.stringify(err)));
  2612. }
  2613. });
  2614. };
  2615. publ.getCurrentPage = function() {
  2616. return _state.page;
  2617. };
  2618. publ.popoverCellRemove = function() {
  2619. if (_popoverCellCurrent) {
  2620. _popoverCellCurrent.popover('destroy');
  2621. }
  2622. _popoverCell.data('rowid', -1);
  2623. _popoverCell.data('col', -1);
  2624. _popoverCell.html('');
  2625. };
  2626. return publ;
  2627. }
  2628. $.fn.TableAjax = function(options) {
  2629. options = options || {};
  2630. return this.each(function() {
  2631. options.id = this;
  2632. $(this).data('TableAjax', new TableAjax().init(options));
  2633. });
  2634. };
  2635. $.fn.TableAjaxLoadPage = function(page, pageSize) {
  2636. return this.each(function() {
  2637. var tblAjax = jQuery(this).data('TableAjax');
  2638. var curPage = page || tblAjax.getCurrentPage();
  2639. if (tblAjax) tblAjax.loadPage(curPage, pageSize);
  2640. });
  2641. };
  2642. $.fn.TableAjaxRefresh = function(page, pageSize) {
  2643. return this.each(function() {
  2644. var tblAjax = jQuery(this).data('TableAjax');
  2645. if (tblAjax) tblAjax.refresh();
  2646. });
  2647. };
  2648. String.prototype.format = String.prototype.f = function() {
  2649. var s = this;
  2650. i = arguments.length;
  2651. while (i--) s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
  2652. return s;
  2653. };
  2654. })(jQuery);
  2655. </script>
  2656. <?php
  2657. $filterInit = $this->_filterInit;
  2658. $forceFilterInit = $this->_forceFilterInit;
  2659. $pageSizes = $this->_pageSizes;
  2660. $pageSize = $this->_pageSize;
  2661. $rowFunctions = $this->_rowFunctions;//$this->_showRowFunctionsJson();
  2662. $exportFields = $this->_showExportFieldsJson();
  2663. ?>
  2664. <script>
  2665. jQuery(document).ready(function(){
  2666. jQuery('#<?php echo $this->_htmlID; ?>').TableAjax({
  2667. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>',
  2668. columnPicker: true,
  2669. filter: true,
  2670. filterInit: <?php echo json_encode($filterInit); ?>,
  2671. forceFilterInit: <?php echo json_encode($forceFilterInit); ?>,
  2672. debug: false,
  2673. height: 400,
  2674. sorting: true,
  2675. paging: true,
  2676. pageSize: <?php echo $pageSize; ?>,
  2677. pageSizes: <?php echo json_encode($pageSizes); ?>,
  2678. tblFunctions: {
  2679. shortdesc: {
  2680. icon: 'align-left',
  2681. title: 'Long desc',
  2682. method: 'longTextChanged'
  2683. },
  2684. <?php if ($hasGeomFlds) : ?>
  2685. mapeditor: {
  2686. icon: 'map-marker',
  2687. title: 'Mapa',
  2688. method: 'mapEditorChanged'
  2689. },
  2690. <?php endif; ?>
  2691. create: {
  2692. href: '#CREATE',
  2693. icon: 'plus',
  2694. title: 'Dodaj nowy rekord'
  2695. },
  2696. refresh: {
  2697. icon: 'refresh',
  2698. title: 'Odśwież dane',
  2699. method: 'refresh'
  2700. }
  2701. },
  2702. rowFunctions: <?php echo json_encode($rowFunctions); ?>,
  2703. exportFields: <?php echo json_encode($exportFields); ?>,
  2704. specialFilterFunctions: <?php
  2705. $fltrs = $this->_acl->getSpecialFilters();
  2706. if (!empty($fltrs)) {
  2707. echo json_encode($fltrs);
  2708. } else {
  2709. echo 'false';
  2710. }
  2711. echo ',';
  2712. ?>
  2713. router: function() {
  2714. var routes = {
  2715. EDIT: function(args) {
  2716. var recordID = args;
  2717. if (typeof args == 'object') {
  2718. recordID = args.shift();
  2719. recordID = parseInt(recordID);
  2720. }
  2721. if (typeof recordID !== 'number' || recordID <= 0) {
  2722. // TODO: msg
  2723. return false;
  2724. }
  2725. var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
  2726. cont.hide();
  2727. // remove previous task content
  2728. var taskCnt = jQuery('#<?php echo $this->_htmlID; ?>_task');
  2729. taskCnt.parent().remove();
  2730. taskCnt.remove();
  2731. var taskCont = jQuery('<div class="AjaxTableCont"></div>').insertBefore(cont);
  2732. jQuery('<ul class="breadcrumb">' +
  2733. '<li><a href="#" onclick="return tableAjaxBackToTable();"><?php echo $this->getLabelHtml(); ?></a></li>' +
  2734. '<li class="active">Edytuj rekord</li>' +
  2735. '</ul>').appendTo(taskCont);
  2736. taskCnt = jQuery('<div id="<?php echo $this->_htmlID . '_task'; ?>" class="AjaxTableTaskCnt AjaxTable-loading"></div>').appendTo(taskCont);
  2737. jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
  2738. jQuery.ajax({
  2739. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=EDIT&ID=' + recordID,
  2740. type: 'GET',
  2741. dataType: 'text',
  2742. data: '',
  2743. async: true,
  2744. success: function(data) {
  2745. taskCnt.removeClass('AjaxTable-loading');
  2746. jQuery(data).appendTo(taskCnt);
  2747. initDateTimePicker(taskCnt);
  2748. },
  2749. error: function(err) {
  2750. taskCnt.removeClass('AjaxTable-loading');
  2751. //console.log('request error: {0}'.f(err));
  2752. }
  2753. });
  2754. //return false;
  2755. },
  2756. HIST: function(args) {
  2757. var recordID = args;
  2758. if (typeof args == 'object') {
  2759. recordID = args.shift();
  2760. recordID = parseInt(recordID);
  2761. }
  2762. if (typeof recordID !== 'number' || recordID <= 0) {
  2763. // TODO: msg
  2764. return false;
  2765. }
  2766. var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
  2767. cont.hide();
  2768. // remove previous task content
  2769. var taskCnt = jQuery('#<?php echo $this->_htmlID; ?>_task');
  2770. taskCnt.parent().remove();
  2771. taskCnt.remove();
  2772. var taskCont = jQuery('<div class="AjaxTableCont"></div>').insertBefore(cont);
  2773. jQuery('<ul class="breadcrumb">' +
  2774. '<li><a href="#" onclick="return tableAjaxBackToTable();"><?php echo $this->getLabelHtml(); ?></a></li>' +
  2775. '<li class="active">Historia rekordu</li>' +
  2776. '</ul>').appendTo(taskCont);
  2777. var taskCnt = jQuery('<div id="<?php echo $this->_htmlID . '_task'; ?>" class="AjaxTableTaskCnt AjaxTable-loading"></div>').appendTo(taskCont);
  2778. jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
  2779. jQuery.ajax({
  2780. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=HIST&ID=' + recordID,
  2781. type: 'GET',
  2782. dataType: 'text',
  2783. data: '',
  2784. async: true,
  2785. success: function(data) {
  2786. taskCnt.removeClass('AjaxTable-loading');
  2787. //console.log('request finished L.<?php echo __LINE__; ?>');
  2788. jQuery(data).appendTo(taskCnt);
  2789. },
  2790. error: function(err) {
  2791. taskCnt.removeClass('AjaxTable-loading');
  2792. //console.log('request error: {0}'.f(err));
  2793. }
  2794. });
  2795. //return false;
  2796. },
  2797. FILES: function tableAjaxFiles(args) {
  2798. var recordID = args;
  2799. if (typeof args == 'object') {
  2800. recordID = args.shift();
  2801. recordID = parseInt(recordID);
  2802. }
  2803. if (typeof recordID !== 'number' || recordID <= 0) {
  2804. // TODO: msg
  2805. return false;
  2806. }
  2807. var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
  2808. cont.hide();
  2809. // remove previous task content
  2810. var taskCnt = jQuery('#<?php echo $this->_htmlID; ?>_task');
  2811. taskCnt.parent().remove();
  2812. taskCnt.remove();
  2813. var taskCont = jQuery('<div class="AjaxTableCont"></div>').insertBefore(cont);
  2814. jQuery('<ul class="breadcrumb">' +
  2815. '<li><a href="#" onclick="return tableAjaxBackToTable();"><?php echo $this->getLabelHtml(); ?></a></li>' +
  2816. '<li class="active">Pliki</li>' +
  2817. '</ul>').appendTo(taskCont);
  2818. var taskCnt = jQuery('<div id="<?php echo $this->_htmlID . '_task'; ?>" class="AjaxTable-loading"></div>').appendTo(taskCont);
  2819. jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
  2820. jQuery.ajax({
  2821. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=FILES&ID=' + recordID,
  2822. type: 'GET',
  2823. dataType: 'text',
  2824. data: '',
  2825. async: true,
  2826. success: function(data) {
  2827. taskCnt.removeClass('AjaxTable-loading');
  2828. //console.log('request finished L.<?php echo __LINE__; ?>', data);
  2829. jQuery(data).appendTo(taskCnt);
  2830. },
  2831. error: function(jqXHR, textStatus, errorThrown) {
  2832. //console.log('request error:', jqXHR.status, 'txt:', jqXHR.responseText, 'err:', jqXHR);
  2833. taskCnt.removeClass('AjaxTable-loading');
  2834. var txt = jqXHR.responseText || 'Error';
  2835. if (jqXHR.status == 404) {
  2836. jQuery('<div class="container"><div class="alert alert-danger">' + txt + '</div></div>').appendTo(taskCnt);
  2837. } else {
  2838. jQuery('<div class="container"><div class="alert alert-danger">' + txt + '</div></div>').appendTo(taskCnt);
  2839. }
  2840. }
  2841. });
  2842. //return false;
  2843. },
  2844. CREATE: function tableAjaxCreate() {
  2845. var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
  2846. cont.hide();
  2847. // remove previous task content
  2848. var taskCnt = jQuery('#<?php echo $this->_htmlID; ?>_task');
  2849. taskCnt.parent().remove();
  2850. taskCnt.remove();
  2851. var taskCont = jQuery('<div class="AjaxTableCont"></div>').insertBefore(cont);
  2852. jQuery('<ul class="breadcrumb">' +
  2853. '<li><a href="#" onclick="return tableAjaxBackToTable();"><?php echo $this->getLabelHtml(); ?></a></li>' +
  2854. '<li class="active">Dodaj nowy rekord</li>' +
  2855. '</ul>').appendTo(taskCont);
  2856. taskCnt = jQuery('<div id="<?php echo $this->_htmlID . '_task'; ?>" class="AjaxTableTaskCnt AjaxTable-loading"></div>').appendTo(taskCont);
  2857. jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
  2858. var reqData = {};
  2859. var forceFilterInit = <?php echo json_encode($forceFilterInit);// TODO: read from TableAjax ?>;
  2860. if (forceFilterInit) {
  2861. $.map(forceFilterInit, function(fltrProps, fltr) {
  2862. reqData['ff_' + fltr] = fltrProps;
  2863. });
  2864. }
  2865. jQuery.ajax({
  2866. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=CREATE',
  2867. type: 'GET',
  2868. dataType: 'text',
  2869. data: reqData,
  2870. async: true,
  2871. success: function(data) {
  2872. taskCnt.removeClass('AjaxTable-loading');
  2873. //console.log('request finished L.<?php echo __LINE__; ?>');
  2874. jQuery(data).appendTo(taskCnt);
  2875. initDateTimePicker(taskCnt);
  2876. },
  2877. error: function(err) {
  2878. taskCnt.removeClass('AjaxTable-loading');
  2879. //console.log('request error: {0}'.f(err));
  2880. }
  2881. });
  2882. //return false;
  2883. }
  2884. };
  2885. var routePath = location.hash;
  2886. //console.log('location.hash: ' + routePath);
  2887. if (location.hash == '' || location.hash == '#') {
  2888. return false;
  2889. }
  2890. if (routePath.charAt(0) == '#') {
  2891. routePath = routePath.substr(1);
  2892. }
  2893. //console.log('routePath: ' + routePath);
  2894. var parts = routePath.split('/');
  2895. var task = parts.shift();
  2896. //console.log('task(' + task + ') parts:');
  2897. //console.log(parts);
  2898. if (task in routes && typeof routes[task] == 'function') {
  2899. var con = jQuery('#<?php echo $this->_htmlID; ?>');
  2900. if (con) {
  2901. var tblAjax = con.data('TableAjax');
  2902. if (tblAjax) {
  2903. tblAjax.popoverCellRemove();
  2904. }
  2905. }
  2906. routes[task](parts);
  2907. } else {
  2908. return false;
  2909. }
  2910. },
  2911. filtersClean: true,
  2912. longDesc: true
  2913. });
  2914. });
  2915. function tableAjaxBackToTable() {
  2916. var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
  2917. cont.show();
  2918. var taskCont = jQuery('#<?php echo $this->_htmlID . '_task'; ?>').parent();
  2919. taskCont.remove();
  2920. // reload first page
  2921. var con = jQuery('#<?php echo $this->_htmlID; ?>');
  2922. con.TableAjaxLoadPage();// TODO: load current page
  2923. }
  2924. function tableAjaxCopy(args) {
  2925. var recordID = args;
  2926. if (typeof args == 'object') {
  2927. recordID = args.shift();
  2928. recordID = parseInt(recordID);
  2929. }
  2930. if (typeof recordID !== 'number' || recordID <= 0) {
  2931. // TODO: msg
  2932. return false;
  2933. }
  2934. if (!confirm('Czy na pewno chcesz utworzyc nowy rekord na podstawie danych z rekordu ID = ' + recordID + '?')) {
  2935. return false;
  2936. }
  2937. var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
  2938. function notifyAjaxCallback(data) {
  2939. var notify = {};
  2940. notify.type = (data && data.type)? data.type : '';
  2941. notify.msg = (data && data.msg)? data.msg : '';
  2942. switch (notify.type) {
  2943. case 'success':
  2944. if (!notify.msg) notify.msg = 'OK';
  2945. break;
  2946. case 'info':
  2947. if (!notify.msg) notify.msg = '';
  2948. break;
  2949. case 'error':
  2950. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  2951. break;
  2952. case 'warning':
  2953. notify.type = 'warn';
  2954. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  2955. break;
  2956. default:
  2957. notify.msg = 'Nieznany błąd';
  2958. if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
  2959. notify.type = '';
  2960. }
  2961. jQuery.notify(notify.msg, notify.type);
  2962. }
  2963. var reqData = {};
  2964. jQuery.ajax({
  2965. data: reqData,
  2966. dataType: 'json',
  2967. type: "GET",
  2968. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=COPY&ID=' + recordID,
  2969. })
  2970. .done(function(data, textStatus, jqXHR){
  2971. var con = jQuery('#<?php echo $this->_htmlID; ?>');
  2972. con.TableAjaxRefresh();
  2973. notifyAjaxCallback(data);
  2974. })
  2975. .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
  2976. if (jqXHR.responseJSON) {
  2977. notifyAjaxCallback(jqXHR.responseJSON);
  2978. }
  2979. else {
  2980. var txt = jqXHR.responseText || 'Wystąpiły błędy';
  2981. if (jqXHR.status == 404) {
  2982. jQuery.notify(jqXHR.responseText, 'error');
  2983. } else {
  2984. jQuery.notify(jqXHR.responseText, 'warn');
  2985. }
  2986. }
  2987. });
  2988. return false;
  2989. }
  2990. function hidePopover() {
  2991. var con = jQuery('#<?php echo $this->_htmlID; ?>');
  2992. if (con) {
  2993. var tblAjax = con.data('TableAjax');
  2994. if (tblAjax) {
  2995. tblAjax.popoverCellRemove();
  2996. }
  2997. }
  2998. return false;
  2999. }
  3000. function <?php echo $jsToogleFiltrProcesuFunctionName; ?>(n) {
  3001. var $n = jQuery(n);
  3002. var $ul = $n.next();
  3003. if ($n.data('fetched')) return false;
  3004. function parseProcesInitData(pInitData) {
  3005. var procesInitMapHtml = '';
  3006. if (!pInitData) {
  3007. return '<li><a href="#">' + "Brak danych" + '</a></li>';
  3008. } else {
  3009. function _viewProcesInitListItem(pInitId, gotoIds, pInitList) {
  3010. var label = pInitList[pInitId];
  3011. var jsInfo = "window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces=" + pInitId + "&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;";
  3012. var out = '<a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=' + pInitId + '&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $this->_zasobID; ?>" title="' + "{" + pInitId + "} " + label + '">';
  3013. out += ' <i class="glyphicon glyphicon-info-sign"';
  3014. out += ' onclick="' + jsInfo + '"';
  3015. out += ' style="color:#aaa;"';
  3016. out += ' onmouseover="' + "this.style.color='#337AB7'" + '"';
  3017. out += ' onmouseout="' + "this.style.color='#aaa'" + '"></i>';
  3018. out += " {" + pInitId + "} " + label;
  3019. out += '</a>';
  3020. return out;
  3021. }
  3022. function _viewProcesGotoAndRetListItem(gotoId, pInitList) {
  3023. var label = pInitList[gotoId];
  3024. var jsInfo = "window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces=" + gotoId + "&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;";
  3025. var out = '';
  3026. out += '<a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=' + gotoId + '&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $this->_zasobID; ?>" title="' + "{" + gotoId + "} " + label + '">';
  3027. out += ' <span style="padding:10px;"></span>';
  3028. out += ' <i class="glyphicon glyphicon-arrow-right" style="color:#aaa"></i>';
  3029. out += ' <i class="glyphicon glyphicon-info-sign"';
  3030. out += ' onclick="' + jsInfo + '"';
  3031. out += ' style="color:#aaa;"';
  3032. out += ' onmouseover="' + "this.style.color='#337AB7'" + '"';
  3033. out += ' onmouseout="' + "this.style.color='#aaa'" + '"></i>';
  3034. out += " {" + gotoId + "} " + label;
  3035. out += '</a>';
  3036. return out;
  3037. }
  3038. function _viewProcesGotoAndRetLvl2ListItem(gotoLvl2Id, pInitList) {
  3039. var label = pInitList[gotoLvl2Id];
  3040. var jsInfo = "window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces=" + gotoLvl2Id + "&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;";
  3041. var out = '';
  3042. out += '<a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=' + gotoLvl2Id + '&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $this->_zasobID; ?>" title="' + "{" + gotoLvl2Id + "} " + label + '">';
  3043. out += ' <span style="padding:20px;"></span>';
  3044. out += ' <i class="glyphicon glyphicon-arrow-right" style="color:#aaa"></i>';
  3045. out += ' <i class="glyphicon glyphicon-info-sign"';
  3046. out += ' onclick="' + jsInfo + '"';
  3047. out += ' style="color:#aaa;"';
  3048. out += ' onmouseover="' + "this.style.color='#337AB7'" + '"';
  3049. out += ' onmouseout="' + "this.style.color='#aaa'" + '"></i>';
  3050. out += " {" + gotoLvl2Id + "} " + label;
  3051. out += '</a>';
  3052. return out;
  3053. }
  3054. var sel = '',
  3055. liStyle = "white-space:nowrap; overflow:hidden; max-width:500px; /* text-overflow:ellipsis; */";
  3056. $.map(pInitData.mapTree, function(gotoIds, vInitId) {
  3057. sel = (pInitData.pInitListSelected && pInitData.pInitListSelected == vInitId)? ' class="disabled"' : '';
  3058. procesInitMapHtml += '<li' + sel + ' style="' + liStyle + '">';
  3059. procesInitMapHtml += _viewProcesInitListItem(vInitId, gotoIds, pInitData.pInitList);
  3060. procesInitMapHtml += '</li>' + "\n";
  3061. $.map(gotoIds, function(gotoLvl2Ids, gotoId) {
  3062. sel = (pInitData.pInitListSelected && pInitData.pInitListSelected == vInitId)? ' class="disabled"' : '';
  3063. procesInitMapHtml += '<li' + sel + ' style="' + liStyle + '">';
  3064. procesInitMapHtml += _viewProcesGotoAndRetListItem(gotoId, pInitData.pInitList);
  3065. procesInitMapHtml += '</li>' + "\n";
  3066. $.map(gotoLvl2Ids, function(vBool, gotoLvl2Id) {
  3067. sel = (pInitData.pInitListSelected && pInitData.pInitListSelected == vInitId)? ' class="disabled"' : '';
  3068. procesInitMapHtml += '<li' + sel + ' style="' + liStyle + '">';
  3069. procesInitMapHtml += _viewProcesGotoAndRetLvl2ListItem(gotoLvl2Id, pInitData.pInitList);
  3070. procesInitMapHtml += '</li>' + "\n";
  3071. });
  3072. });
  3073. });
  3074. }
  3075. return procesInitMapHtml;
  3076. }
  3077. jQuery.ajax({
  3078. data: null,
  3079. dataType: 'json',
  3080. type: "GET",
  3081. async: true,
  3082. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=PROCES_INIT_FILTR',
  3083. })
  3084. .always(function(data, textStatus, jqXHR) {
  3085. var type = data.type || null,
  3086. msg = data.msg || "Error",
  3087. pInitData = data.pInitData || null;
  3088. if (type) {
  3089. if ('success' == type) {
  3090. $ul.html(parseProcesInitData(pInitData));
  3091. } else if ('error' == type) {
  3092. $ul.html('<li><a href="#">' + msg + '</a></li>');
  3093. } else {
  3094. $ul.html('<li><a href="#">Wystapił błąd podczas pobierania listy procesów</a></li>');
  3095. }
  3096. } else {
  3097. $ul.html('<li><a href="#">Wystapił błąd podczas pobierania listy procesów</a></li>');
  3098. }
  3099. $n.data('fetched', true);
  3100. });
  3101. return false;
  3102. }
  3103. </script>
  3104. <?php
  3105. $out = ob_get_contents();
  3106. ob_end_clean();
  3107. return $out;
  3108. }
  3109. public function _viewProcesInitListItem($vInitId, $gotoIds, $pInitList) {
  3110. $vLabel = $pInitList[$vInitId];
  3111. $kId = $vInitId;
  3112. ?>
  3113. <a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=<?php echo $kId; ?>&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $this->_zasobID; ?>" title="<?php echo htmlspecialchars("{{$kId}} {$vLabel}"); ?>">
  3114. <i class="glyphicon glyphicon-info-sign"
  3115. onclick="window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces=<?php echo $kId; ?>&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;"
  3116. style="color:#aaa;"
  3117. onmouseover="this.style.color='#337AB7'"
  3118. onmouseout="this.style.color='#aaa'"></i>
  3119. <?php echo "{{$kId}} {$vLabel}"; ?>
  3120. </a>
  3121. <?php
  3122. }
  3123. public function _viewProcesGotoAndRetListItem($vGotoId, $pInitList) {
  3124. $vLabel = $pInitList[$vGotoId];
  3125. $kId = $vGotoId;
  3126. // TODO:?: prevent to execute procedure
  3127. ?>
  3128. <a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=<?php echo $kId; ?>&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $this->_zasobID; ?>" title="<?php echo htmlspecialchars("{{$kId}} {$vLabel}"); ?>">
  3129. <span style="padding:10px;"></span>
  3130. <i class="glyphicon glyphicon-arrow-right" style="color:#aaa"></i>
  3131. <i class="glyphicon glyphicon-info-sign"
  3132. onclick="window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces=<?php echo $kId; ?>&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;"
  3133. style="color:#aaa;"
  3134. onmouseover="this.style.color='#337AB7'"
  3135. onmouseout="this.style.color='#aaa'"></i>
  3136. <?php echo "{{$kId}} {$vLabel}"; ?>
  3137. </a>
  3138. <?php
  3139. }
  3140. public function _viewProcesGotoAndRetLvl2ListItem($vGotoLvl2Id, $pInitList) {
  3141. $vLabel = $pInitList[$vGotoLvl2Id];
  3142. $kId = $vGotoLvl2Id;
  3143. // TODO:?: prevent to execute procedure
  3144. ?>
  3145. <a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=<?php echo $kId; ?>&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $this->_zasobID; ?>" title="<?php echo htmlspecialchars("{{$kId}} {$vLabel}"); ?>">
  3146. <span style="padding:20px;"></span>
  3147. <i class="glyphicon glyphicon-arrow-right" style="color:#aaa"></i>
  3148. <i class="glyphicon glyphicon-info-sign"
  3149. onclick="window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces=<?php echo $kId; ?>&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;"
  3150. style="color:#aaa;"
  3151. onmouseover="this.style.color='#337AB7'"
  3152. onmouseout="this.style.color='#aaa'"></i>
  3153. <?php echo "{{$kId}} {$vLabel}"; ?>
  3154. </a>
  3155. <?php
  3156. }
  3157. public function hasAdditionalLayers() {
  3158. $layers = TableAjaxMap::getAdditionalLayers($this->_zasobID);
  3159. return !empty($layers);
  3160. }
  3161. public function ajaxTask($task) {
  3162. switch ($task) {
  3163. case 'EDIT': {
  3164. $id = V::get('ID', 0, $_REQUEST, 'int');
  3165. if ($id > 0) {
  3166. $this->sendAjaxEdit($id, $_REQUEST);
  3167. } else {
  3168. echo '404';
  3169. }
  3170. break;
  3171. }
  3172. case 'EDIT_SAVE': {
  3173. $this->sendAjaxResponseJson('ajaxEditSave', $_REQUEST);
  3174. break;
  3175. }
  3176. case 'EDIT_INLINE': {
  3177. $id = V::get('ID', 0, $_REQUEST, 'int');
  3178. $col = V::get('col', '', $_REQUEST);
  3179. if ($id > 0 && !empty($col)) {
  3180. $this->sendAjaxEditInline($id, $col, $_REQUEST);
  3181. } else {
  3182. echo '404';
  3183. }
  3184. break;
  3185. }
  3186. case 'EDIT_INLINE_SAVE': {
  3187. $this->sendAjaxResponseJson('ajaxEditInlineSave', $_REQUEST);
  3188. break;
  3189. }
  3190. case 'COPY': {
  3191. $this->sendAjaxResponseJson('ajaxCopy', $_REQUEST);
  3192. break;
  3193. }
  3194. case 'CREATE': {
  3195. $this->sendAjaxCreate($_REQUEST);
  3196. break;
  3197. }
  3198. case 'CREATE_SAVE': {
  3199. $this->sendAjaxResponseJson('ajaxCreateSave', $_REQUEST);
  3200. break;
  3201. }
  3202. case 'HIST': {
  3203. $id = V::get('ID', 0, $_REQUEST, 'int');
  3204. if ($id > 0) {
  3205. $this->sendAjaxHistory($id, $_REQUEST);
  3206. } else {
  3207. echo '404';
  3208. }
  3209. break;
  3210. }
  3211. case 'FILES': {
  3212. $id = V::get('ID', 0, $_REQUEST, 'int');
  3213. if ($id > 0) {
  3214. $this->sendAjaxFiles($id, $_REQUEST);
  3215. } else {
  3216. echo '404';
  3217. }
  3218. break;
  3219. }
  3220. case 'FILES_UPLOAD': {
  3221. $id = V::get('ID', 0, $_REQUEST, 'int');
  3222. if ($id > 0) {
  3223. $this->sendAjaxFilesUpload($id, $_REQUEST);
  3224. } else {
  3225. echo '404';
  3226. }
  3227. break;
  3228. }
  3229. case 'FILES_LIST': {
  3230. $id = V::get('ID', 0, $_REQUEST, 'int');
  3231. if ($id > 0) {
  3232. $this->sendAjaxFilesList($id, $_REQUEST);
  3233. } else {
  3234. echo '404';
  3235. }
  3236. break;
  3237. }
  3238. case 'FILE_REMOVE': {
  3239. $id = V::get('ID', 0, $_REQUEST, 'int');
  3240. if ($id > 0) {
  3241. $this->sendAjaxFileRemove($id, $_REQUEST);
  3242. } else {
  3243. echo '404';
  3244. }
  3245. break;
  3246. }
  3247. case 'filePermsRefresh': {
  3248. $this->sendAjaxResponseJson('ajaxFilePermsRefresh', $_REQUEST);
  3249. break;
  3250. }
  3251. case 'FILES_CONN_TBL_LIST': {
  3252. $id = V::get('ID', 0, $_REQUEST, 'int');
  3253. if ($id > 0) {
  3254. $this->sendAjaxFilesConnTblList($id, $_REQUEST);
  3255. } else {
  3256. echo '404';
  3257. }
  3258. break;
  3259. }
  3260. case 'TYPESPECIAL': {
  3261. $fldID = V::get('fldID', 0, $_REQUEST, 'int');
  3262. if ($fldID > 0) {
  3263. $this->sendTypeSpecial($fldID, $_REQUEST);
  3264. } else {
  3265. echo '404';
  3266. }
  3267. break;
  3268. }
  3269. case 'TYPESPECIALL_CELL': {
  3270. $id = V::get('ID', 0, $_REQUEST, 'int');
  3271. $col = V::get('col', '', $_REQUEST);
  3272. if ($id > 0 && !empty($col)) {
  3273. $this->sendTypeSpecialCell($id, $col, $_REQUEST);
  3274. } else {
  3275. echo '404';
  3276. }
  3277. break;
  3278. }
  3279. case 'MORE_FUNCTIONS_CELL': {
  3280. $this->sendAjaxResponseJson('ajaxMoreFunctionsCell', $_REQUEST);
  3281. break;
  3282. }
  3283. case 'HIDDEN_COLS_SAVE': {
  3284. $this->sendAjaxResponseJson('ajaxHiddenColsSave', $_POST);
  3285. break;
  3286. }
  3287. case 'PAGE_SIZE_SAVE': {
  3288. $this->sendAjaxResponseJson('ajaxPageSizeSave', $_POST);
  3289. break;
  3290. }
  3291. case 'THE_GEOM_SAVE': {
  3292. $this->sendAjaxResponseJson('ajaxTheGeomSave', $_REQUEST);
  3293. break;
  3294. }
  3295. case 'THE_GEOM_REMOVE': {
  3296. $this->sendAjaxResponseJson('ajaxTheGeomRemove', $_REQUEST);
  3297. break;
  3298. }
  3299. case 'PROCES_INIT_FILTR': {
  3300. $this->sendAjaxResponseJson('ajaxProcesInitFiltr', $_REQUEST);
  3301. break;
  3302. }
  3303. default:
  3304. $this->sendAjaxResponseJson('ajaxData', $_REQUEST);
  3305. }
  3306. }
  3307. /**
  3308. * ajax url: &_task=EDIT_INLINE
  3309. * @param $rowID - $_GET['ID']
  3310. * @param $fieldName - $_GET['col']
  3311. */
  3312. private function sendAjaxEditInline($rowID, $fieldName, $args) {
  3313. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3314. header("Content-type: text/plain");
  3315. $fieldID = $this->_acl->getFieldIdByName($fieldName);
  3316. if (!$fieldID) {
  3317. echo "404: No field by name ({$fieldName})";
  3318. exit;
  3319. }
  3320. if ($DBG) echo "fieldID: {$fieldID}\n";
  3321. $row = $this->_acl->getItem($rowID);
  3322. if (!$row) {
  3323. echo "404: No item ID({$rowID})";
  3324. exit;
  3325. }
  3326. if (!$this->_acl->isAllowed($fieldID, 'R', $row)) {
  3327. if ($DBG) echo " R not allowed\n";
  3328. } else {
  3329. if ($DBG) echo " R allowed\n";
  3330. }
  3331. if (!$this->_acl->isAllowed($fieldID, 'W', $row)) {
  3332. if ($DBG) echo " W not allowed\n";
  3333. } else {
  3334. if ($DBG) echo " W allowed\n";
  3335. }
  3336. $fieldVal = '';
  3337. if ($this->_acl->isAllowed($fieldID, 'R', $row)) {
  3338. $fieldVal = V::get($fieldName, $fieldVal, $row);
  3339. } else {
  3340. $fieldVal = '*****';
  3341. }
  3342. $fieldVal = V::get("f{$fieldID}", $fieldVal, $_POST);
  3343. $vCol = $this->_acl->getField($fieldID);
  3344. $vCol['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
  3345. $tsValues = array();
  3346. $typeSpecial = Typespecial::getInstance($fieldID, $vCol['name']);
  3347. if ($typeSpecial) {
  3348. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$fieldID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
  3349. $specialValues = $typeSpecial->getEditSelectedValuesByIds($this->_zasobID, $row->ID, $fieldName, V::get($fieldName, $fieldVal, $row));
  3350. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$fieldID.') specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValues);echo'</pre>';}
  3351. if (!empty($specialValues)) {
  3352. $tsValues[$row->ID] = implode('<br>', $specialValues);
  3353. }
  3354. }
  3355. ?>
  3356. <label for="<?php echo "f{$fieldID}"; ?>" class="AjaxTableEdit-label">
  3357. <strong title="<?php echo "[{$fieldID}] {$fieldName}"; ?>"><?php echo "{$vCol['label']}"; ?></strong>
  3358. <?php if (!empty($vCol['opis'])) : ?>
  3359. <em><?php echo $vCol['opis']; ?></em>
  3360. <?php $perms = $this->_acl->getFieldPerms($fieldID); SE_Layout::hotKeyDBG($perms); ?>
  3361. <?php endif; ?>
  3362. </label>
  3363. <?php
  3364. $fieldParams = array('widthClass'=>'inside-modal', 'maxGrid'=>6);
  3365. if (!empty($tsValues[$row->ID])) {
  3366. $fieldParams['typespecialValue'] = $tsValues[$row->ID];
  3367. }
  3368. $vDefault = $this->_acl->getColDefault($fieldName);
  3369. if (!empty($vDefault)) {
  3370. $fieldParams['default'] = $vDefault;
  3371. }
  3372. echo $this->_acl->showFormItem('W', $fieldID, "f{$fieldID}", $fieldVal, $fieldParams, $row);
  3373. if ($typeSpecial
  3374. || $this->_acl->isDateField($fieldName)
  3375. || $this->_acl->isDateTimeField($fieldName)
  3376. ) {
  3377. echo '<p style="padding:120px 0;"></p>';
  3378. }
  3379. exit;
  3380. }
  3381. private function ajaxEditInlineSave($args) {
  3382. $primaryKeyField = $this->_acl->getPrimaryKeyField();
  3383. $primaryKey = V::get($primaryKeyField, 0, $args, 'int');
  3384. $fieldName = V::get('col', '', $_REQUEST);
  3385. if (empty($primaryKey) || empty($fieldName)) {
  3386. throw new HttpException("Wrong param id or col!", 400);
  3387. }
  3388. $fieldID = $this->_acl->getFieldIdByName($fieldName);
  3389. if (!$fieldID) {
  3390. throw new HttpException("Field not exists!", 404);
  3391. }
  3392. $item = $this->_acl->getItem($primaryKey);
  3393. if (!$item) {
  3394. throw new HttpException("Item not exists!", 404);
  3395. }
  3396. $itemFromUser = $this->_acl->convertObjectFromUserInput($args, $type = 'array_by_id', $prefix = 'f');
  3397. if (!isset($itemFromUser[$fieldName])) {
  3398. throw new HttpException("Field not set!", 400);
  3399. }
  3400. $itemPatch = array();
  3401. $itemPatch[$fieldName] = V::get($fieldName, null, $itemFromUser);
  3402. $itemPatch[$primaryKeyField] = $primaryKey;
  3403. $response = new stdClass();
  3404. try {
  3405. $affected = $this->_acl->updateItem($itemPatch);
  3406. if ($affected > 0) {
  3407. $response->type = 'success';
  3408. $response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
  3409. } else if ($affected == 0) {
  3410. $response->type = 'info';
  3411. $response->msg = "Nie wprowadzono żadnych zmian";
  3412. }
  3413. $response->record = $this->_acl->getItem($primaryKey);
  3414. }
  3415. catch (Exception $e) {
  3416. $response->type = 'error';
  3417. $response->msg = $e->getMessage();
  3418. }
  3419. return $response;
  3420. }
  3421. private function sendAjaxEdit($id, $args) {
  3422. header("Content-type: text/plain");
  3423. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3424. $cols = array();
  3425. $record = $this->_acl->getItem($id);
  3426. if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
  3427. echo '<div class="alert alert-danger">';
  3428. echo "Brak dostępu do rekordu";// TODO: more info - reason
  3429. echo '</div>';
  3430. return;
  3431. }
  3432. $fieldsList = $this->_acl->getFields();
  3433. foreach ($fieldsList as $kID => $vCol) {
  3434. if ($vCol['name'] == 'ID') {
  3435. unset($fieldsList[$kID]);
  3436. continue;
  3437. }
  3438. $cols[$kID] = '';
  3439. if ($this->_acl->isAllowed($kID, 'R', $record)) {
  3440. $cols[$kID] = V::get($vCol['name'], '', $record);
  3441. } else {
  3442. $cols[$kID] = '*****';
  3443. }
  3444. $cols[$kID] = V::get("f{$kID}", $cols[$kID], $_POST);
  3445. $fieldsList[$kID]['label'] = (!empty($vCol['label']))? $vCol['label'] : str_replace('_', ' ', $vCol['name']);
  3446. }
  3447. $tsValues = array();
  3448. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fieldsList (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fieldsList);echo'</pre>';}
  3449. if (!empty($fieldsList)) {
  3450. foreach ($fieldsList as $vColID => $vCol) {
  3451. $typeSpecial = Typespecial::getInstance($vColID, $vCol['name']);
  3452. if ($typeSpecial) {
  3453. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$vColID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
  3454. $colValue = V::get($vCol['name'], '', $record);
  3455. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">V::get('.$vCol['name'].', "", $record) (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($colValue);echo'</pre>';}
  3456. $specialValues = $typeSpecial->getEditSelectedValuesByIds($this->_zasobID, $record->ID, $vCol['name'], $colValue);
  3457. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$vColID.') specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValues);echo'</pre>';}
  3458. if (!empty($specialValues)) {
  3459. $tsValues[$vColID] = implode('<br>', $specialValues);
  3460. }
  3461. }
  3462. }
  3463. }
  3464. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">tsValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($tsValues);echo'</pre>';}
  3465. $rowFunctionsOut = $this->_showRowFunctions($record->ID, array('edit', 'cp'), true);
  3466. ?>
  3467. <div class="container AjaxFrmHorizontalEdit" style="max-width:940px">
  3468. <form class="form-horizontal" action="" method="post" id="EDIT_FRM_<?php echo $this->_htmlID; ?>">
  3469. <fieldset>
  3470. <legend>Edycja rekordu Nr <?php echo $record->ID; ?><span class="pull-right valign-btns-bottom"><?php echo $rowFunctionsOut; ?></span></legend>
  3471. <?php $tabindex = 0; foreach ($fieldsList as $kID => $vCol) : ?>
  3472. <?php if ($this->_acl->isAllowed($kID, 'W', $record)) : ?>
  3473. <div class="form-group">
  3474. <label class="col-xs-12 col-sm-3 col-md-2 control-label" for="<?php echo "f{$kID}"; ?>"><?php echo $vCol['label']; ?>
  3475. <i class="glyphicon glyphicon-info-sign frm-help" data-toggle="popover" data-trigger="hover" title="" data-content="<?php echo htmlspecialchars($vCol['opis']); ?>" data-original-title="<?php echo "[{$kID}] {$vCol['name']}"; ?>"></i>
  3476. <?php $perms = $this->_acl->getFieldPerms($kID); SE_Layout::hotKeyDBG($perms); ?>
  3477. </label>
  3478. <div class="col-xs-12 col-sm-9 col-md-10">
  3479. <?php
  3480. $fieldParams = array('appendBack'=>true, 'tabindex'=>(++$tabindex), 'maxGrid'=>8);
  3481. if (!empty($tsValues[$kID])) {
  3482. $fieldParams['typespecialValue'] = $tsValues[$kID];
  3483. }
  3484. echo $this->_acl->showFormItem('W', $kID, "f{$kID}", $cols[$kID], $fieldParams, $record);
  3485. ?>
  3486. </div>
  3487. </div>
  3488. <?php elseif ($this->_acl->isAllowed($kID, 'R', $record)) : ?>
  3489. <div class="form-group">
  3490. <label class="col-xs-12 col-sm-3 col-md-2 control-label" for="<?php echo "f{$kID}"; ?>"><?php echo $vCol['label']; ?>
  3491. <i class="glyphicon glyphicon-info-sign frm-help" data-toggle="popover" data-trigger="hover" title="" data-content="<?php echo htmlspecialchars($vCol['opis']); ?>" data-original-title="<?php echo "[{$kID}] {$vCol['name']}"; ?>"></i>
  3492. <?php $perms = $this->_acl->getFieldPerms($kID); SE_Layout::hotKeyDBG($perms); ?>
  3493. </label>
  3494. <div class="col-xs-12 col-sm-9 col-md-10">
  3495. <p style="margin-top:5px;">
  3496. <?php
  3497. //echo $this->_acl->showFormItem('R', $kID, "f{$kID}", $cols[$kID], array('appendBack'=>true), $record);
  3498. if (!empty($tsValues[$kID])) {
  3499. echo $tsValues[$kID];
  3500. } else if (!empty($record->{$vCol['name']})) {
  3501. echo $record->{$vCol['name']};
  3502. }
  3503. ?>
  3504. </p>
  3505. </div>
  3506. </div>
  3507. <?php endif; ?>
  3508. <?php endforeach; ?>
  3509. <div class="form-group">
  3510. <div class="col-xs-offset-0 col-xs-12 col-sm-offset-3 col-sm-9 col-md-offset-2 col-md-10">
  3511. <button type="submit" class="btn btn-primary" tabindex="<?php echo (++$tabindex); ?>">Zapisz</button>
  3512. </div>
  3513. </div>
  3514. </fieldset>
  3515. </form>
  3516. <p style="padding:100px 0;"></p>
  3517. </div>
  3518. <script>
  3519. jQuery(document).ready(function(){
  3520. jQuery('textarea').autosize();
  3521. jQuery('.frm-help').popover({trigger:'hover'});
  3522. jQuery('#EDIT_FRM_<?php echo $this->_htmlID; ?>').on('submit', function(){
  3523. var data = jQuery(this).serialize();
  3524. // TODO: change Edit btn to return to edit record with fields -> show form
  3525. var taskCont = jQuery('#<?php echo $this->_htmlID; ?>_task').parent();
  3526. //taskCont.empty();
  3527. taskCont.children().fadeOut('slow');
  3528. var alertCntWrap = jQuery('<div class="AjaxTableAlert AjaxTable-loading"></div>').prependTo(taskCont)
  3529. , alertCnt = jQuery('<div class="container"></div>').prependTo(alertCntWrap);
  3530. jQuery('<div class="alert alert-danger"><div style="padding:0 0 0 20px; background:url(./icon/loading.gif) no-repeat left top;"> zapisywanie ... </div></div>').appendTo(alertCnt);
  3531. function notifyAjaxCallback(data) {
  3532. var notify = {}, outMsg = '';
  3533. notify.type = (data && data.type)? data.type : '';
  3534. notify.msg = (data && data.msg)? data.msg : '';
  3535. switch (notify.type) {
  3536. case 'success':
  3537. if (!notify.msg) notify.msg = 'Dane poprawnie zaktualizowane';
  3538. break;
  3539. case 'info':
  3540. if (!notify.msg) notify.msg = 'Nie wprowadzono żadnych zmian';
  3541. break;
  3542. case 'error':
  3543. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  3544. break;
  3545. case 'warning':
  3546. notify.type = 'warn';
  3547. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  3548. break;
  3549. default:
  3550. notify.msg = 'Nieznany błąd';
  3551. if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
  3552. notify.type = '';
  3553. }
  3554. jQuery.notify(notify.msg, notify.type);
  3555. var alertType = ('error' == notify.type) ? 'danger' : notify.type;
  3556. outMsg = '<div class="alert alert-' + alertType + '">' + notify.msg + '</div>';
  3557. return outMsg;
  3558. }
  3559. $.ajax({
  3560. data: data,
  3561. dataType: 'json',
  3562. type: "POST",
  3563. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=EDIT_SAVE&ID=<?php echo $record->ID; ?>',
  3564. })
  3565. .done(function(data, textStatus, jqXHR){
  3566. var outMsg = notifyAjaxCallback(data);
  3567. alertCntWrap.removeClass('AjaxTable-loading');
  3568. //console.log('request finished L.<?php echo __LINE__; ?>');
  3569. alertCnt.empty();
  3570. var out = '';
  3571. out += outMsg;
  3572. out += '<div class="breadcrumb">' +
  3573. ' <a href="#" onclick="return tableAjaxBackToTable();" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-arrow-left"></i> Wróć do tabeli <?php echo $this->getLabelHtml(); ?></a>' +
  3574. ' <a href="#EDIT/<?php echo $id; ?>/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-pencil"></i> Edytuj rekord <?php echo $id; ?></a>' +
  3575. '</div>';
  3576. jQuery(out).appendTo(alertCnt);
  3577. })
  3578. .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
  3579. if (jqXHR.responseJSON) {
  3580. notifyAjaxCallback(jqXHR.responseJSON);
  3581. }
  3582. else {
  3583. var txt = jqXHR.responseText || 'Wystąpiły błędy';
  3584. if (jqXHR.status == 404) {
  3585. jQuery.notify(jqXHR.responseText, 'error');
  3586. } else {
  3587. jQuery.notify(jqXHR.responseText, 'warn');
  3588. }
  3589. }
  3590. alertCntWrap.removeClass('AjaxTable-loading');
  3591. //console.log('Request Error: {0}: {1}'.f(textStatus, errorThrown));
  3592. alertCnt.empty();
  3593. jQuery(errorTxt).appendTo(alertCnt);
  3594. var errLinks = jQuery('<div class="breadcrumb"></div>').appendTo(alertCnt);
  3595. jQuery('<a href="#" onclick="return tableAjaxBackToTable();"> <i class="icon-arrow-left"></i> Wróć do tabeli <?php echo $this->getLabelHtml(); ?></a>').appendTo(errLinks);
  3596. var backToEditBtn = jQuery('<a href="#EDIT/<?php echo $id; ?>/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-small"> <i class="icon-pencil"></i> Popraw dane <?php echo $id; ?></a>').appendTo(errLinks);
  3597. backToEditBtn.on('click', function(){
  3598. alertCnt.remove();
  3599. taskCont.children().fadeIn('slow');
  3600. return false;
  3601. });
  3602. });
  3603. return false;
  3604. });
  3605. jQuery('#EDIT_FRM_<?php echo $this->_htmlID; ?>').find('.show-last-value input').on('input', function(e) {
  3606. var input, btn, btnIco;
  3607. input = jQuery(e.target);
  3608. btn = input.next('.button-appendBack');
  3609. btnIco = btn.find('.glyphicon');
  3610. //console.log('title',btn.attr('title'),'val',input.val(),'input', input, 'btn', btn);
  3611. if (btn.attr('title') != input.val()) {
  3612. btnIco.show();
  3613. } else {
  3614. btnIco.hide();
  3615. }
  3616. });
  3617. jQuery('#EDIT_FRM_<?php echo $this->_htmlID; ?>').find('.show-last-value').find('.button-appendBack').on('click', function(e) {
  3618. var input, btn, btnIco;
  3619. btn = jQuery(this);
  3620. btnIco = btn.find('.glyphicon');
  3621. input = btn.prev();
  3622. //console.log('title',btn.attr('title'),'val',input.val(),'input', input, 'btn', btn);
  3623. if (input.is('input')) {
  3624. if (btn.attr('title') != input.val()) {
  3625. input.val(btn.attr('title'));
  3626. btnIco.hide();
  3627. }
  3628. }
  3629. });
  3630. });
  3631. </script>
  3632. <?php
  3633. exit;
  3634. }
  3635. private function ajaxEditSave($args) {
  3636. $primaryKeyField = $this->_acl->getPrimaryKeyField();
  3637. $primaryKey = V::get($primaryKeyField, 0, $args, 'int');
  3638. if (empty($primaryKey)) {
  3639. throw new HttpException("Wrong param id!", 400);
  3640. }
  3641. $item = $this->_acl->getItem($primaryKey);
  3642. if (!$item) {
  3643. throw new HttpException("Item not exists!", 404);
  3644. }
  3645. $itemFromUser = $this->_acl->convertObjectFromUserInput($args, $type = 'array_by_id', $prefix = 'f');
  3646. $response = new stdClass();
  3647. try {
  3648. $itemFromUser[$primaryKeyField] = $primaryKey;
  3649. $affected = $this->_acl->updateItem($itemFromUser);
  3650. if ($affected > 0) {
  3651. $response->type = 'success';
  3652. $response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
  3653. } else if ($affected == 0) {
  3654. $response->type = 'info';
  3655. $response->msg = "Nie wprowadzono żadnych zmian";
  3656. }
  3657. $response->record = $this->_acl->getItem($primaryKey);
  3658. }
  3659. catch (Exception $e) {
  3660. $response->type = 'error';
  3661. $response->msg = "Wystąpiły błędy!";
  3662. $response->msg .= $e->getMessage();
  3663. }
  3664. return $response;
  3665. }
  3666. private function sendAjaxCreate($args) {
  3667. header("Content-type: text/plain");
  3668. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3669. if (!$this->_acl->hasCreatePerms()) {
  3670. ?>
  3671. <div class="container">
  3672. <div class="alert alert-danger">
  3673. Brak uprawnień do utworzenia nowego rekordu.
  3674. </div>
  3675. </div>
  3676. <?php
  3677. return;
  3678. }
  3679. $cols = array();
  3680. $forceFilterInit = array();
  3681. $defaultAclGroup = User::getDefaultAclGroup();
  3682. if ($defaultAclGroup) {
  3683. $forceFilterInit['A_ADM_COMPANY'] = $defaultAclGroup;
  3684. $forceFilterInit['A_CLASSIFIED'] = $defaultAclGroup;
  3685. }
  3686. foreach ($_GET as $k => $v) {
  3687. if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
  3688. $fldName = substr($k, 3);
  3689. $forceFilterInit[$fldName] = $v;
  3690. }
  3691. }
  3692. $fieldsList = $this->_acl->getFields();
  3693. foreach ($fieldsList as $kID => $vCol) {
  3694. $defaultValue = '';
  3695. if ($vCol['name'] == 'ID') {
  3696. unset($fieldsList[$kID]);
  3697. continue;
  3698. }
  3699. if (!empty($forceFilterInit[$vCol['name']])) {
  3700. $defaultValue = $forceFilterInit[$vCol['name']];
  3701. }
  3702. // TODO: read from session cache
  3703. $cols[$kID] = V::get("f{$kID}", $defaultValue, $_POST);
  3704. $fieldsList[$kID]['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
  3705. }
  3706. ?>
  3707. <div class="container AjaxFrmHorizontalEdit">
  3708. <form class="form-horizontal" action="" method="post" id="CREATE_FRM_<?php echo $this->_htmlID; ?>">
  3709. <fieldset>
  3710. <legend>Dodaj nowy rekord</legend>
  3711. <?php $tabindex = 0; foreach ($fieldsList as $kID => $vCol) : ?>
  3712. <?php if ($this->_acl->isAllowed($kID, 'C')) : ?>
  3713. <div class="form-group">
  3714. <label class="col-xs-12 col-sm-3 col-md-2 control-label" for="<?php echo "f{$kID}"; ?>"><?php echo $vCol['label']; ?>
  3715. <i class="glyphicon glyphicon-info-sign frm-help" data-toggle="popover" data-trigger="hover" title="" data-content="<?php echo htmlspecialchars($vCol['opis']); ?>" data-original-title="<?php echo "[{$kID}] {$vCol['name']}"; ?>"></i>
  3716. <?php $perms = $this->_acl->getFieldPerms($kID); SE_Layout::hotKeyDBG($perms); ?>
  3717. </label>
  3718. <div class="col-xs-12 col-sm-9 col-md-10">
  3719. <?php
  3720. $fieldParams = array('appendBack'=>true, 'tabindex'=>(++$tabindex), 'maxGrid'=>8);
  3721. echo $this->_acl->showFormItem('C', $kID, "f{$kID}", $cols[$kID], $fieldParams);
  3722. ?>
  3723. </div>
  3724. </div>
  3725. <?php endif; ?>
  3726. <?php endforeach; ?>
  3727. <div class="form-group">
  3728. <div class="col-xs-offset-0 col-xs-12 col-sm-offset-3 col-sm-9 col-md-offset-2 col-md-10">
  3729. <button type="submit" class="btn btn-primary" tabindex="<?php echo (++$tabindex); ?>">Dodaj rekord</button>
  3730. </div>
  3731. </div>
  3732. </fieldset>
  3733. </form>
  3734. </div>
  3735. <script>
  3736. jQuery(document).ready(function(){
  3737. jQuery('textarea').autosize();
  3738. jQuery('.frm-help').popover({trigger:'hover'});
  3739. jQuery('#CREATE_FRM_<?php echo $this->_htmlID; ?>').on('submit', function(){
  3740. var data = jQuery(this).serialize();
  3741. var taskContLast = jQuery('#<?php echo $this->_htmlID; ?>_task'),
  3742. taskCont = taskContLast.parent();
  3743. taskContLast.fadeOut('slow');
  3744. var taskCnt = jQuery('<div id="<?php echo $this->_htmlID . '_task'; ?>" class="AjaxTableTaskCnt AjaxTable-loading"></div>').appendTo(taskCont);
  3745. jQuery('<div class="alert alert-danger"><div style="padding:0 0 0 20px; background:url(./icon/loading.gif) no-repeat left top;"> save ... </div></div>').appendTo(taskCnt);
  3746. function notifyAjaxCallback(data) {
  3747. var notify = {};
  3748. notify.type = (data && data.type)? data.type : '';
  3749. notify.msg = (data && data.msg)? data.msg : '';
  3750. switch (notify.type) {
  3751. case 'success':
  3752. if (!notify.msg) notify.msg = 'OK';
  3753. break;
  3754. case 'info':
  3755. if (!notify.msg) notify.msg = '';
  3756. break;
  3757. case 'error':
  3758. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  3759. break;
  3760. case 'warning':
  3761. notify.type = 'warn';
  3762. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  3763. break;
  3764. default:
  3765. notify.msg = 'Nieznany błąd';
  3766. if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
  3767. notify.type = '';
  3768. }
  3769. jQuery.notify(notify.msg, notify.type);
  3770. }
  3771. $.ajax({
  3772. data: data,
  3773. dataType: 'json',
  3774. type: "POST",
  3775. async: true,
  3776. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=CREATE_SAVE'
  3777. })
  3778. .always(function(dataOrJqXHR){
  3779. var data;
  3780. if (dataOrJqXHR && 'readyState' in dataOrJqXHR && 'status' in dataOrJqXHR) {
  3781. if ('responseJSON' in dataOrJqXHR) {
  3782. data = dataOrJqXHR.responseJSON;
  3783. } else {
  3784. data = {};
  3785. data.msg = dataOrJqXHR.responseText || 'Nieznany błąd';
  3786. if (dataOrJqXHR.status == 404) {
  3787. data.type = 'error';
  3788. } else {
  3789. data.type = 'warning';
  3790. }
  3791. }
  3792. }
  3793. else {
  3794. data = dataOrJqXHR;
  3795. }
  3796. notifyAjaxCallback(data);
  3797. taskCnt.removeClass('AjaxTable-loading');
  3798. taskCnt.empty();
  3799. if (data.type == 'error' || data.type == 'warning') {
  3800. var out = '<div class="container">' +
  3801. '<div class="alert alert-danger">' +
  3802. '<h4>Wystąpiły błędy!</h4>' + data.msg +
  3803. (('errors' in data)? '<p>' + data.errors + '</p>' : '') +
  3804. '</div>';
  3805. out += '<div class="breadcrumb">' +
  3806. ' <a class="create-fix" href="#CREATE/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-arrow-left"></i> Wróć do formularza i popraw dane</a></li>' +
  3807. '</div>' +
  3808. '</div>';
  3809. jQuery(out).appendTo(taskCnt);
  3810. var taskContLastNode = taskContLast
  3811. , taskCntNode = taskCnt;
  3812. taskCnt.find('.create-fix').click(function(){
  3813. taskCntNode.remove();
  3814. taskContLastNode.fadeIn('slow');
  3815. return false;
  3816. });
  3817. }
  3818. else if (data.type == 'success') {
  3819. var msg = '';
  3820. if (data.id && data.id > 0) {
  3821. msg = 'Utworzono pomyślnie rekord: ID = ' + data.id;
  3822. } else if (data.msg) {
  3823. msg = data.msg;
  3824. } else {
  3825. msg = 'OK';
  3826. }
  3827. var out = '<div class="container">';
  3828. out += '<div class="alert alert-success">' + msg + '</div>';
  3829. out += '<div class="breadcrumb">' +
  3830. ' <a href="#" onclick="return tableAjaxBackToTable();" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-arrow-left"></i> Wróć do tabeli <?php echo $this->getLabelHtml(); ?></a>' +
  3831. ' <a href="#EDIT/' + data.id + '" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-pencil"></i> Edytuj rekord ' + data.id + '</a>' +
  3832. ' <a href="#CREATE/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-plus"></i> Dodaj nowy rekord</a></li>' +
  3833. '</div>';
  3834. out += '</div>';
  3835. jQuery(out).appendTo(taskCnt);
  3836. }
  3837. });
  3838. return false;
  3839. });
  3840. });
  3841. </script>
  3842. <?php
  3843. exit;
  3844. }
  3845. private function ajaxCreateSave($args) {
  3846. $response = new stdClass();
  3847. $createdId = null;
  3848. try {
  3849. $item = $this->_acl->convertObjectFromUserInput($args, $type = 'array_by_id', $prefix = 'f');
  3850. $createdId = $this->_acl->addItem($item);
  3851. if ($createdId) {
  3852. $response->type = 'success';
  3853. $response->msg = "Utworzono pomyślnie rekord nr {$createdId}";
  3854. $response->id = $createdId;
  3855. $response->record = $this->_acl->getItem($createdId);
  3856. }
  3857. else {
  3858. $response->type = 'error';
  3859. $response->msg = "Nie udało się utworzyć nowego rekordu!";
  3860. }
  3861. }
  3862. catch (Exception $e) {
  3863. $response->type = 'error';
  3864. $response->msg = "Wystąpiły błędy!";
  3865. $response->msg = $e->getMessage();
  3866. }
  3867. return $response;
  3868. }
  3869. private function ajaxCopy($args) {
  3870. $id = V::get('ID', 0, $_REQUEST, 'int');
  3871. if ($id <= 0) {
  3872. throw new HttpException("Wrong param ID!", 404);
  3873. }
  3874. $item = $this->_acl->getItem($id);
  3875. if (!$item) {
  3876. throw new HttpException("Item '{$id}' not exists!", 404);
  3877. }
  3878. $response = new stdClass();
  3879. $itemCopy = $this->_acl->createItemCopy($item);
  3880. $createdId = null;
  3881. try {
  3882. $createdId = $this->_acl->addItem($itemCopy);
  3883. if ($createdId) {
  3884. $response->type = 'success';
  3885. $response->msg = "Rekord skopiowany pomyślnie - utworzono rekord nr {$createdId}";
  3886. $response->id = $createdId;
  3887. $response->record = $this->_acl->getItem($createdId);
  3888. }
  3889. else {
  3890. $response->type = 'error';
  3891. $response->msg = "Nie udało się skopiować rekordu!";
  3892. }
  3893. }
  3894. catch (Exception $e) {
  3895. $response->type = 'error';
  3896. $response->msg = "Wystąpiły błędy!";
  3897. $response->msg = $e->getMessage();
  3898. }
  3899. return $response;
  3900. }
  3901. private function sendAjaxHistory($id, $args) {
  3902. header("Content-type: text/plain");
  3903. $record = $this->_acl->getItem($id);
  3904. if (!$record) {
  3905. header('HTTP/1.0 404 Not Found');
  3906. echo "404: No item ID({$rowID})";
  3907. exit;
  3908. }
  3909. $visibleCols = $this->_acl->getRealFieldList();
  3910. $rowsHist = $this->_acl->getHistItems($id);
  3911. $rowFunctionsOut = $this->_showRowFunctions($record->ID, array('hist', 'cp'), true);
  3912. $visibleColsWithIds = array();
  3913. $visibleColsLabels = array();
  3914. foreach ($visibleCols as $vColName) {
  3915. $fldId = $this->_acl->getFieldIdByName($vColName);
  3916. if ($fldId) {
  3917. $visibleColsWithIds[$fldId] = $vColName;
  3918. $label = $this->_acl->getFieldLabel($fldId);
  3919. $label = (!$label)? $vColName : '<span title="' . "[{$fldId}] {$vColName}" . '">' . $label . '</span>';
  3920. $visibleColsLabels[$fldId] = $label;
  3921. }
  3922. }
  3923. ?>
  3924. <fieldset>
  3925. <legend>Historia rekordu Nr <?php echo $id; ?>
  3926. <span class="pull-right valign-btns-bottom"><?php echo $rowFunctionsOut; ?></span>
  3927. </legend>
  3928. </fieldset>
  3929. <?php if (empty($rowsHist)) : ?>
  3930. <div class="alert alert-info">
  3931. <h4>Brak danych</h4>
  3932. </div>
  3933. <?php else: ?>
  3934. <table class="table table-striped table-hover table-bordered table-condensed AjaxTableHist">
  3935. <thead>
  3936. <tr>
  3937. <th>Data</th>
  3938. <th>User</th>
  3939. <th>Zmiany</th>
  3940. </tr>
  3941. </thead>
  3942. <tbody>
  3943. <?php foreach ($rowsHist as $row) : ?>
  3944. <tr>
  3945. <td style="white-space:nowrap"><?php echo $row->_created; ?></td>
  3946. <td><?php echo $row->_author; ?></td>
  3947. <td>
  3948. <?php foreach ($visibleColsWithIds as $fldId => $colName) : ?>
  3949. <?php if (in_array($colName, array('ID', 'A_RECORD_UPDATE_DATE', 'A_RECORD_UPDATE_AUTHOR', 'A_RECORD_CREATE_DATE', 'A_RECORD_CREATE_AUTHOR'))) continue; ?>
  3950. <?php if ($row->$colName == 'N/S;') continue; ?>
  3951. <p><em><?php echo $visibleColsLabels[$fldId]; ?></em>:
  3952. <?php if ($this->_acl->isAllowed($fldId, 'R', $record)) : ?>
  3953. <?php echo $row->$colName; ?>
  3954. <?php else : ?>
  3955. <span title="Brak uprawnień do odczytu tego pola">*****</span>
  3956. <?php endif; ?>
  3957. </p>
  3958. <?php endforeach; ?>
  3959. </td>
  3960. </tr>
  3961. <?php endforeach; ?>
  3962. </tbody>
  3963. </table>
  3964. <div style="overflow-x:scroll; overflow-y:visible; padding-bottom:1px; margin:10px 0;">
  3965. <table class="table table-striped table-hover table-bordered table-condensed AjaxTableHist">
  3966. <thead>
  3967. <tr>
  3968. <?php foreach ($visibleColsWithIds as $fldId => $colName) : ?>
  3969. <th><?php echo str_replace('_', ' ', $visibleColsLabels[$fldId]); ?></th>
  3970. <?php endforeach; ?>
  3971. </tr>
  3972. </thead>
  3973. <tbody>
  3974. <?php foreach ($rowsHist as $row) : ?>
  3975. <tr>
  3976. <?php foreach ($visibleColsWithIds as $fldId => $colName) : ?>
  3977. <td>
  3978. <?php if ($row->$colName == 'N/S;') : ?>
  3979. <em>N/S;</em>
  3980. <?php elseif ($this->_acl->isAllowed($fldId, 'R', $record)) : ?>
  3981. <?php echo $row->$colName; ?>
  3982. <?php else : ?>
  3983. <span title="Brak uprawnień do odczytu tego pola">*****</span>
  3984. <?php endif; ?>
  3985. </td>
  3986. <?php endforeach; ?>
  3987. </tr>
  3988. <?php endforeach; ?>
  3989. </tbody>
  3990. </table>
  3991. </div>
  3992. <?php endif; ?>
  3993. <?php
  3994. exit;
  3995. }
  3996. /**
  3997. * Returns text/plain with type at first line: ERROR, WARNING, INFO, SUCCESS
  3998. */
  3999. private function sendAjaxFilesUpload($id, $args) {
  4000. // http://www.sitepoint.com/html5-ajax-file-upload/
  4001. //$ajaxFileName = (isset($_SERVER['HTTP_X_FILENAME']) ? $_SERVER['HTTP_X_FILENAME'] : false);
  4002. //header("Content-type: text/plain");
  4003. header("Content-type: application/json");
  4004. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  4005. $dbID = $this->_acl->getDB();
  4006. $db = DB::getDB($dbID);
  4007. if (!$db) {
  4008. header('HTTP/1.0 406 Not Acceptable');
  4009. echo '{"type":"ERROR", "string": "No DB (' . $dbID . ')"}';
  4010. exit;
  4011. }
  4012. $record = $this->_acl->getItem($id);
  4013. if (!$record) {
  4014. header('HTTP/1.0 404 Not Found');
  4015. echo '{"type":"ERROR", "string": "No item ID(' . $rowID . ')"}';
  4016. exit;
  4017. }
  4018. $tblName = $this->_acl->getName();
  4019. $confTblName = "{$tblName}_COLUMN";
  4020. $folderConfAll = FoldersConfig::getRawData();
  4021. if (!FoldersConfig::hasConfig($confTblName)) {
  4022. header('HTTP/1.0 404 Not Found');
  4023. echo '{"type":"ERROR", "string": "Brak danych konfiguracyjnych(' . $tblName . ')"}';
  4024. exit;
  4025. }
  4026. $folderConf = FoldersConfig::getAll($confTblName);
  4027. $uploader = new FileUploader($confTblName, $record);
  4028. $errMsg = '';
  4029. if (!$uploader->setConfig($folderConf, $errMsg)) {
  4030. header('HTTP/1.0 404 Not Found');
  4031. echo '{"type":"ERROR", "string": "Błąd danych konfiguracyjnych(' . $tblName . ') <br>' . $errMsg . '"}';
  4032. exit;
  4033. }
  4034. $uploader->findFolder();
  4035. $errorMsg = '';
  4036. if (!empty($_POST['SCANS_COLUMN_ADD'])) {
  4037. $uploaded = $uploader->tryMoveFromScanAjax($errorMsg);
  4038. }
  4039. else {
  4040. $uploaded = $uploader->tryUploadAjax($errorMsg);
  4041. }
  4042. if ($uploaded) {
  4043. $uploadedFileName = '';
  4044. $uploadedFile = $uploader->getLastUploadedFile();
  4045. if ($uploadedFile) {
  4046. $uploadedFileName = explode('/', $uploadedFile);
  4047. $uploadedFileName = end($uploadedFileName);
  4048. }
  4049. echo '{"type":"SUCCESS", "string": "Plik został poprawnie wgrany do odpowiedniego katalogu '.$uploadedFileName.'"}';
  4050. if (!empty($uploadedFileName)) {
  4051. $sqlObj = new stdClass();
  4052. $sqlObj->ID = $record->ID;
  4053. $sqlObj->M_DIST_FILES = "Wgrano plik {$uploadedFileName}";
  4054. $db->UPDATE_OBJ($this->_tbl, $sqlObj);
  4055. }
  4056. } else {
  4057. echo '{"type":"ERROR", "string": "' . $errorMsg . '"}';
  4058. }
  4059. exit;
  4060. }
  4061. private function sendAjaxFileRemove($id, $args) {
  4062. header("Content-type: application/json");
  4063. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  4064. if (empty($_POST['filename'])) {
  4065. echo '{"type":"ERROR", "string": "Nie wybrano pliku do usunięcia"}';
  4066. exit;
  4067. }
  4068. $dbID = $this->_acl->getDB();
  4069. $db = DB::getDB($dbID);
  4070. if (!$db) {
  4071. header('HTTP/1.0 406 Not Acceptable');
  4072. echo '{"type":"ERROR", "string": "No DB (' . $dbID . ')"}';
  4073. exit;
  4074. }
  4075. $record = $this->_acl->getItem($id);
  4076. if (!$record) {
  4077. header('HTTP/1.0 404 Not Found');
  4078. echo '{"type":"ERROR", "string": "No item ID(' . $rowID . ')"}';
  4079. exit;
  4080. }
  4081. $tblName = $this->_acl->getName();
  4082. $confTblName = "{$tblName}_COLUMN";
  4083. $folderConfAll = FoldersConfig::getRawData();
  4084. if (!FoldersConfig::hasConfig($confTblName)) {
  4085. header('HTTP/1.0 404 Not Found');
  4086. echo '{"type":"ERROR", "string": "Brak danych konfiguracyjnych (' . $tblName . ')"}';
  4087. exit;
  4088. }
  4089. $folderConf = FoldersConfig::getAll($confTblName);
  4090. $uploader = new FileUploader($confTblName, $record);
  4091. if (!$uploader->setConfig($folderConf)) {
  4092. header('HTTP/1.0 404 Not Found');
  4093. echo '{"type":"ERROR", "string": "Błąd danych konfiguracyjnych (' . $tblName . ')"}';
  4094. exit;
  4095. }
  4096. $uploader->findFolder();
  4097. $errorMsg = '';
  4098. $removed = $uploader->tryRemoveFromAjax($_POST['filename'], $errorMsg);
  4099. if (!$removed) {
  4100. echo '{"type":"ERROR", "string": "{' . $errorMsg . '}"}';
  4101. } else {
  4102. echo '{"type":"SUCCESS","string":"Plik został poprawnie usunięty"}';
  4103. }
  4104. exit;
  4105. }
  4106. private function sendAjaxFilesList($id, $args) {
  4107. header("Content-type: application/json");
  4108. $dbID = $this->_acl->getDB();
  4109. $db = DB::getDB($dbID);
  4110. if (!$db) {
  4111. header('HTTP/1.0 406 Not Acceptable');
  4112. echo '{"type":"ERROR", "string": "No DB (' . $dbID . ')"}';
  4113. exit;
  4114. }
  4115. $record = $this->_acl->getItem($id);
  4116. if (!$record) {
  4117. header('HTTP/1.0 404 Not Found');
  4118. echo '{"type":"ERROR", "string": "No item ID(' . $rowID . ')"}';
  4119. exit;
  4120. }
  4121. $tblName = $this->_acl->getName();
  4122. $confTblName = "{$tblName}_COLUMN";
  4123. $folderConfAll = FoldersConfig::getRawData();
  4124. if (!FoldersConfig::hasConfig($confTblName)) {
  4125. header('HTTP/1.0 404 Not Found');
  4126. echo '{"type":"ERROR", "string": "Brak danych konfiguracyjnych (' . $tblName . ')"}';
  4127. exit;
  4128. }
  4129. $folderConf = FoldersConfig::getAll($confTblName);
  4130. $uploader = new FileUploader($confTblName, $record);
  4131. if (!$uploader->setConfig($folderConf)) {
  4132. header('HTTP/1.0 404 Not Found');
  4133. echo '{"type":"ERROR", "string": "Błąd danych konfiguracyjnych (' . $tblName . ')"}';
  4134. exit;
  4135. }
  4136. $uploader->findFolder();
  4137. $mainFolder = $uploader->getDestFolder();
  4138. $files = $uploader->getFilesFromFolder($mainFolder, false, true);
  4139. $localPath = $uploader->getLocalPath();
  4140. $folderWeb = $uploader->getFolderWeb();
  4141. $jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
  4142. echo json_encode($jsonFiles);
  4143. exit;
  4144. }
  4145. private function ajaxFilePermsRefresh($args) {
  4146. header("Content-type: application/json");
  4147. $id = V::get('ID', 0, $args, 'int');
  4148. if ($id <= 0) throw new HttpException("Wrong param ID", 404);
  4149. $dbID = $this->_acl->getDB();
  4150. $db = DB::getDB($dbID);
  4151. if (!$db) throw new HttpException("No DB", 406);
  4152. $record = $this->_acl->getItem($id);
  4153. if (!$record) throw new Exception("No item ID({$rowID})", 404);
  4154. $tblName = $this->_acl->getName();
  4155. // TODO: SyncPermsCustomTables->getRecordTask($tbl, $id);
  4156. $sql_L_APPOITMENT_USER = V::get('L_APPOITMENT_USER', '', $record);
  4157. $sql_A_ADM_COMPANY = V::get('A_ADM_COMPANY', '', $record);
  4158. $sql_A_CLASSIFIED = V::get('A_CLASSIFIED', '', $record);
  4159. $mainDB = DB::getDB();
  4160. if ('IN7_MK_BAZA_DYSTRYBUCJI' == $tblName) {
  4161. $sql = "insert into `_SYNC_FILE_PERMS` (
  4162. `ID_PROJECT`,
  4163. `A_SYNCHRONIZED`
  4164. )
  4165. values (
  4166. '{$record->ID}'
  4167. , 0
  4168. )
  4169. ON DUPLICATE KEY UPDATE
  4170. `A_SYNCHRONIZED`=0
  4171. ";
  4172. }
  4173. else if ('IN7_DZIENNIK_KORESP' == $tblName) {
  4174. $sql = "insert into `_SYNC_FILE_PERMS` (
  4175. `ID_PROJECT`,
  4176. `A_SYNCHRONIZED`
  4177. )
  4178. values (
  4179. '{$record->ID_PROJECT}'
  4180. , 0
  4181. )
  4182. ON DUPLICATE KEY UPDATE
  4183. `A_SYNCHRONIZED`=0
  4184. ";
  4185. }
  4186. else {
  4187. $sql = "insert into `_SYNC_TABLE_FILE_PERMS` (
  4188. `TBL_NAME`,
  4189. `TBL_ID`,
  4190. `L_APPOITMENT_USER`,
  4191. `A_ADM_COMPANY`,
  4192. `A_CLASSIFIED`,
  4193. `A_SYNCHRONIZED`
  4194. )
  4195. values (
  4196. '{$tblName}'
  4197. , '{$id}'
  4198. , '{$sql_L_APPOITMENT_USER}'
  4199. , '{$sql_A_ADM_COMPANY}'
  4200. , '{$sql_A_CLASSIFIED}'
  4201. , 0
  4202. )
  4203. ON DUPLICATE KEY UPDATE
  4204. `A_SYNCHRONIZED`=0
  4205. ";
  4206. }
  4207. $res = $mainDB->query($sql);
  4208. if ($mainDB->has_errors()) {
  4209. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';
  4210. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($mainDB->get_errors());echo'</pre>';
  4211. throw new Exception("Nie udało się dodać zadania");
  4212. }
  4213. // TODO: this blocks browser ajax query
  4214. //$limit = 3;
  4215. //while ($limit--) {
  4216. // sleep(10);
  4217. // TODO: check if task is done
  4218. //}
  4219. $confTblName = "{$tblName}_COLUMN";
  4220. $folderConfAll = FoldersConfig::getRawData();
  4221. if (!FoldersConfig::hasConfig($confTblName)) {
  4222. throw new Exception("Brak danych konfiguracyjnych ({$tblName})", 404);
  4223. }
  4224. $folderConf = FoldersConfig::getAll($confTblName);
  4225. $uploader = new FileUploader($confTblName, $record);
  4226. if (!$uploader->setConfig($folderConf)) {
  4227. throw new Exception("Błąd danych konfiguracyjnych ({$tblName})", 404);
  4228. }
  4229. $uploader->findFolder();
  4230. $mainFolder = $uploader->getDestFolder();
  4231. $files = $uploader->getFilesFromFolder($mainFolder, false, true);
  4232. $localPath = $uploader->getLocalPath();
  4233. $folderWeb = $uploader->getFolderWeb();
  4234. $jsonData = new stdClass();
  4235. $jsonData->msg = 'Zadanie dodane';
  4236. $jsonData->type = 'success';
  4237. $jsonData->files = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
  4238. return $jsonData;
  4239. }
  4240. private function sendAjaxFilesConnTblList($id, $args) {
  4241. header("Content-type: application/json");
  4242. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  4243. $dbID = $this->_acl->getDB();
  4244. $db = DB::getDB($dbID);
  4245. if (!$db) {
  4246. header('HTTP/1.0 406 Not Acceptable');
  4247. echo 'No DB (' . $dbID . ')';
  4248. exit;
  4249. }
  4250. $record = $this->_acl->getItem($id);
  4251. if (!$record) {
  4252. header('HTTP/1.0 404 Not Found');
  4253. echo 'No item ID(' . $rowID . ')';
  4254. exit;
  4255. }
  4256. $connTblName = '';
  4257. $connTblID = V::get('connTblID', 0, $_REQUEST, 'int');
  4258. if ($connTblID <= 0) {
  4259. header('HTTP/1.0 406 Not Acceptable');
  4260. echo 'No conn Table ID';
  4261. exit;
  4262. }
  4263. $connTblTypespecials = $this->getConnectedTblTypespecials($connTblID);
  4264. if (empty($connTblTypespecials)) {
  4265. header('HTTP/1.0 406 Not Acceptable');
  4266. echo "No conn Table (ID={$connTblID})";
  4267. exit;
  4268. }
  4269. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">connTblTypespecials (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($connTblTypespecials);echo'</pre>';}
  4270. if(1) {
  4271. header('HTTP/1.0 404 Not Found');
  4272. echo 'TODO: ...';
  4273. exit;
  4274. }
  4275. $tblName = $this->_acl->getName();
  4276. $confTblName = "{$tblName}_COLUMN";
  4277. $folderConfAll = FoldersConfig::getRawData();
  4278. if (!FoldersConfig::hasConfig($confTblName)) {
  4279. header('HTTP/1.0 404 Not Found');
  4280. echo '{"type":"ERROR", "string": "Brak danych konfiguracyjnych (' . $tblName . ')"}';
  4281. exit;
  4282. }
  4283. $folderConf = FoldersConfig::getAll($confTblName);
  4284. $uploader = new FileUploader($confTblName, $record);
  4285. if (!$uploader->setConfig($folderConf)) {
  4286. header('HTTP/1.0 404 Not Found');
  4287. echo '{"type":"ERROR", "string": "Błąd danych konfiguracyjnych (' . $tblName . ')"}';
  4288. exit;
  4289. }
  4290. $uploader->findFolder();
  4291. $mainFolder = $uploader->getDestFolder();
  4292. $files = $uploader->getFilesFromFolder($mainFolder, false, true);
  4293. $localPath = $uploader->getLocalPath();
  4294. $folderWeb = $uploader->getFolderWeb();
  4295. $jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
  4296. echo json_encode($jsonFiles);
  4297. exit;
  4298. }
  4299. public function convertFileListToJson($files, $folderWeb, $localPath, $mainFolder) {
  4300. $jsonFiles = array();
  4301. if (!is_array($files) || empty($files)) {
  4302. return $jsonFiles;
  4303. }
  4304. sort($files);
  4305. foreach ($files as $vFilePath) {
  4306. $file = new stdClass();
  4307. $file->name = str_replace("{$localPath}/{$mainFolder}/", '', $vFilePath);
  4308. //$file->name = explode('/', $vFilePath);
  4309. //$file->name = end($file->name);
  4310. $file->size = filesize($vFilePath);
  4311. $file->sizeStr = round($file->size, 2) . "B";
  4312. if ($file->size > 1024 * 1024) {
  4313. $file->sizeStr = round(($file->size / (1024 * 1024)), 2) . "M";
  4314. } else if ($file->size > 1024) {
  4315. $file->sizeStr = round(($file->size / 1024), 2) . "K";
  4316. }
  4317. $file->type = '';
  4318. $file->created = date("Y-m-d H:i:s", filectime($vFilePath));
  4319. $file->web = str_replace($localPath, $folderWeb, $vFilePath);
  4320. $jsonFiles[] = $file;
  4321. }
  4322. return $jsonFiles;
  4323. }
  4324. private function getConnectedTables() {
  4325. $connTbls = array();
  4326. return $connTbls;// TODO: OFF - hardlinki tworzone w bash_sync_perms.php
  4327. $fields = $this->_acl->getVisibleFieldList();
  4328. if (!empty($fields)) {
  4329. foreach ($fields as $vColID => $vCol) {
  4330. $typeSpecial = Typespecial::getInstance($vColID);
  4331. if ($typeSpecial) {
  4332. $tsConnTbls = $typeSpecial->getTblAliasList();
  4333. if (!empty($tsConnTbls)) {
  4334. foreach ($tsConnTbls as $kID => $vName) {
  4335. $connTbls[$kID] = $vName;
  4336. }
  4337. }
  4338. }
  4339. }
  4340. }
  4341. return $connTbls;
  4342. }
  4343. private function getConnectedTblTypespecials($connTblID) {
  4344. $connTblTypespecials = array();
  4345. $fields = $this->_acl->getVisibleFieldList();
  4346. if (!empty($fields)) {
  4347. foreach ($fields as $vColID => $vCol) {
  4348. $typeSpecial = Typespecial::getInstance($vColID);
  4349. if ($typeSpecial) {
  4350. $tsConnTbls = $typeSpecial->getTblAliasList();
  4351. if (array_key_exists($connTblID, $tsConnTbls)) {
  4352. $connTblTypespecials[] = $typeSpecial;
  4353. }
  4354. }
  4355. }
  4356. }
  4357. return $connTblTypespecials;
  4358. }
  4359. private function sendAjaxFiles($id, $args) {
  4360. header("Content-type: text/plain");
  4361. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  4362. $dbID = $this->_acl->getDB();
  4363. $db = DB::getDB($dbID);
  4364. if (!$db) {
  4365. header('HTTP/1.0 406 Not Acceptable');
  4366. exit;
  4367. }
  4368. $record = $this->_acl->getItem($id);
  4369. if (!$record) {
  4370. header('HTTP/1.0 404 Not Found');
  4371. echo "404: No item ID({$rowID})";
  4372. exit;
  4373. }
  4374. if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
  4375. echo '<div class="alert alert-danger">';
  4376. echo "Brak dostępu do rekordu";// TODO: more info - reason
  4377. echo '</div>';
  4378. return;
  4379. }
  4380. $tblName = $this->_acl->getName();
  4381. $confTblName = "{$tblName}_COLUMN";
  4382. $folderConfAll = FoldersConfig::getRawData();
  4383. if (!FoldersConfig::hasConfig($confTblName)) {
  4384. header('HTTP/1.0 404 Not Found');
  4385. echo "Brak danych konfiguracyjnych";
  4386. exit;
  4387. }
  4388. $folderConf = FoldersConfig::getAll($confTblName);
  4389. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$folderConf (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($folderConf);echo'</pre>';
  4390. $uploader = new FileUploader($confTblName, $record);
  4391. $errMsg = '';
  4392. if (!$uploader->setConfig($folderConf, $errMsg)) {
  4393. header('HTTP/1.0 404 Not Found');
  4394. echo "Błąd danych konfiguracyjnych ({$tblName})";
  4395. echo '<br>' . "\n" . $errMsg;
  4396. exit;
  4397. }
  4398. $uploader->findFolder();
  4399. if($DBG){ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">uploader (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($uploader);echo'</pre>'; }
  4400. $mainFolder = $uploader->getDestFolder();
  4401. if($DBG){ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">mainFolder (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($mainFolder);echo'</pre>'; }
  4402. $files = $uploader->getFilesFromFolder($mainFolder, false, true);
  4403. if($DBG){ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">files (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($files);echo'</pre>'; }
  4404. $sharePoint = V::get('share_point', null, $folderConf);
  4405. if ($sharePoint) {
  4406. $sharePoint = FoldersConfig::getNfsOsPath() . "{$sharePoint}/{$mainFolder}";
  4407. }
  4408. $localPath = $uploader->getLocalPath();
  4409. $folderWeb = $uploader->getFolderWeb();
  4410. $jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
  4411. if($DBG){ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">jsonFiles (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($jsonFiles);echo'</pre>'; }
  4412. $folderSkanyConf = FoldersConfig::getAll('SCANS_COLUMN');
  4413. $skanyLocalPath = V::get('mount_point', null, $folderSkanyConf);
  4414. $skanySharePoint = V::get('share_point', null, $folderSkanyConf);
  4415. $skanyFolderWeb = V::get('www_share_point', null, $folderSkanyConf);
  4416. $skanyFiles = $uploader->getFilesFromSkany($folderSkanyConf, false);
  4417. sort($skanyFiles);
  4418. $fileTypes = FoldersConfig::getAll('m_dist_files_types');
  4419. $rowFunctionsOut = $this->_showRowFunctions($record->ID, array('files', 'cp'), true);
  4420. $fileIndexField = V::get('DEST_FILE_INDEX_FIELD', 'ID', $folderConf);
  4421. $fileIndex = V::get($fileIndexField, $record->ID, $record);
  4422. ?>
  4423. <script src="stuff/jquery.form.js"></script>
  4424. <div class="container">
  4425. <h4 style="margin:20px 0 3px 0;">Pliki w katalogu
  4426. <?php if ($sharePoint) : ?>
  4427. <a href="<?php echo $sharePoint; ?>"><span class="glyphicon glyphicon-folder-open"></span><code><?php echo $mainFolder; ?></code></a>
  4428. <?php else : ?>
  4429. <code><?php echo $mainFolder; ?></code>
  4430. <?php endif; ?>
  4431. <span class="pull-right valign-btns-bottom">
  4432. <span id="FILES_LIST_ACTIONS_<?php echo $this->_htmlID; ?>"></span>
  4433. <?php echo $rowFunctionsOut; ?>
  4434. </span>
  4435. </h4>
  4436. <div style="clear:both; max-height:180px; overflow:auto; border-bottom:1px solid #ddd;">
  4437. <table class="table table-bordered table-hover">
  4438. <colgroup>
  4439. <col style="">
  4440. <col style="width:30px;">
  4441. <?php if ($sharePoint) : ?>
  4442. <col style="width:30px;">
  4443. <?php endif; ?>
  4444. <col style="width:80px;">
  4445. <col style="width:140px;">
  4446. </colgroup>
  4447. <tbody id="FILES_LIST_<?php echo $this->_htmlID; ?>">
  4448. <?php if (empty($mainFolder)) : ?>
  4449. <tr>
  4450. <td colspan="5">
  4451. <div class="alert alert-warning">
  4452. <h4>Brak folderu!</h4>
  4453. Folder dla tego rekordu nie został utworzony.
  4454. </div>
  4455. </td>
  4456. </tr>
  4457. <?php elseif (empty($files)) : ?>
  4458. <tr>
  4459. <td colspan="5">
  4460. <div class="alert alert-info">
  4461. <h4>Brak plików</h4>
  4462. </div>
  4463. </td>
  4464. </tr>
  4465. <?php endif; ?>
  4466. </tbody>
  4467. </table>
  4468. </div>
  4469. <br>
  4470. <br>
  4471. <div id="FILES_CONN_TBLS_<?php echo $this->_htmlID; ?>"></div>
  4472. <form enctype="multipart/form-data" method="POST" action="" id="FILES_FRM_<?php echo $this->_htmlID; ?>" class="form-inline">
  4473. <input type="hidden" name="M_DIST_UPLOAD_SOURCE" value="local">
  4474. <ul id="FILES_TAB_<?php echo $this->_htmlID; ?>" class="nav nav-tabs" style="margin:0;">
  4475. <li class="active"><a href="#local" data-toggle="local">Wybierz plik lokalny</a></li>
  4476. <li><a href="#scan" data-toggle="scan">Wybierz plik ze skanów</a></li>
  4477. </ul>
  4478. <div id="myTabContent" class="tab-content">
  4479. <div class="tab-pane fade in active" id="local" style="text-align: center;">
  4480. <input name="M_DIST_FILES_NAME" type="file" size="60" class="field-upload btn" style="width:86%;margin:10px auto;padding:10px 4%;background:#eee;text-align:center;" ondragover="this.style.backgroundColor='#D9EDF7'" ondragleave="this.style.backgroundColor='#eee'" ondragend="this.style.backgroundColor='#eee'">
  4481. </div>
  4482. <div class="tab-pane fade" id="scan">
  4483. <?php if (empty($skanyFiles)) : ?>
  4484. <div class="alert alert-info">
  4485. <h4>Brak plików</h4>
  4486. <?php if(!empty($skanyFolderWeb)) echo "skonfiguruj urządzenie biurowe aby wysyłało skany na ftp://skaner:(h*a*s*l*o)@".$_SERVER['SERVER_NAME']." <br> lub <a href=".FoldersConfig::getNfsOsPath().$skanySharePoint.">".FoldersConfig::getNfsOsPath().$skanySharePoint."</a>"; ?>
  4487. </div>
  4488. <?php else : ?>
  4489. <div style="max-height:150px; overflow:auto; border-bottom:1px solid #ddd;">
  4490. <table class="table table-bordered table-hover">
  4491. <colgroup>
  4492. <col style="width:30px;">
  4493. <col style="">
  4494. <col style="width:30px;">
  4495. <col style="width:80px;">
  4496. <col style="width:140px;">
  4497. </colgroup>
  4498. <tbody>
  4499. <?php foreach ($skanyFiles as $vFilePath) : ?>
  4500. <tr>
  4501. <?php
  4502. $vFileName = explode('/', $vFilePath);
  4503. $vFileName = end($vFileName);
  4504. $vFileSize = filesize($vFilePath);
  4505. $vFileSizeOut = round($vFileSize, 2) . "B";
  4506. if ($vFileSize > 1024 * 1024) {
  4507. $vFileSizeOut = round(($vFileSize / (1024 * 1024)), 2) . "M";
  4508. } else if ($vFileSize > 1024) {
  4509. $vFileSizeOut = round(($vFileSize / 1024), 0) . "K";
  4510. }
  4511. ?>
  4512. <td><input style="margin:0;" type="radio" name="SCANS_COLUMN_ADD" value="<?php echo $vFileName; ?>"></td>
  4513. <td><div style="overflow:hidden; white-space:nowrap;" title="<?php echo $vFileName; ?>"><?php echo $vFileName; ?></div></td>
  4514. <td style="white-space:nowrap; text-align:center;"><a href="<?php echo str_replace($skanyLocalPath, $skanyFolderWeb, $vFilePath); ?>" target="_blank" class="glyphicon glyphicon-download-alt"></a></td>
  4515. <td style="white-space:nowrap;"><?php echo $vFileSizeOut; ?></td>
  4516. <td style="white-space:nowrap;"><?php echo date("Y-m-d H:i:s", filectime($vFilePath)); ?></td>
  4517. </tr>
  4518. <?php endforeach; ?>
  4519. </tbody>
  4520. </table>
  4521. </div>
  4522. <?php endif; ?>
  4523. </div>
  4524. </div>
  4525. <br>
  4526. <h4>Ustal nazwę pliku zgodną z obiegiem dokumentów
  4527. <?php //TODO: link do procesu o obiegu dokumentów <i class="glyphicon glyphicon-question-sign" style="cursor:help" title="działa w nowszych przeglądarkach jak Firefox, Chrome"></i> ?>
  4528. </h4>
  4529. <table style="width:100%" class="table table-bordered">
  4530. <tr>
  4531. <th>Nr</th>
  4532. <th>Typ</th>
  4533. <th style="width:40%;">Opis <i class="glyphicon glyphicon-question-sign" title="kogo dotyczy / czego / sprawa / nazwa_firmy itp"></i></th>
  4534. <th style="width:16%">Data wersji</th>
  4535. <th style="width:12%">Numer wersji</th>
  4536. </tr>
  4537. <tr>
  4538. <td>
  4539. <?php echo $fileIndex; ?>
  4540. </td>
  4541. <td>
  4542. <select class="form-control" name="M_DIST_FILES_TYPE">
  4543. <?php foreach ($fileTypes as $kType => $vLabel) : ?>
  4544. <option value="<?php echo $kType; ?>"<?php if ($kType == 'TODO') { echo ' selected="selected"'; } ?> ><?php echo $vLabel; ?></option>
  4545. <?php endforeach; ?>
  4546. </select>
  4547. <br>
  4548. <label class="checkbox">
  4549. <input type="checkbox" name="M_DIST_FILES_TYPE_AUTO">
  4550. Wykrycie automatyczne typu z wysylanego pliku
  4551. </label>
  4552. <label class="checkbox">
  4553. <input type="checkbox" name="M_DIST_FILES_TEMP">
  4554. Plik tymczasowy / roboczy / nieoficjalny (_TEMP)
  4555. </label>
  4556. </td>
  4557. <td>
  4558. <input class="form-control" style="width:100%" type="text" name="M_DIST_FILES_DESCRIPTION" value="" maxlength="50">
  4559. <br><label>jeśli nie zostanie podany to zostanie automatycznie wygenerowany na podstawie nazwy pliku wysyłanego</label>
  4560. </td>
  4561. <td>
  4562. <div class="input-group">
  4563. <input name="M_DIST_FILES_DATE" type="text" value="<?php echo date('Y-m-d');?>" class="se_type-date form-control" data-format="yyyy-MM-dd" maxlength="10"><span class="input-group-addon">
  4564. <span class="glyphicon glyphicon-calendar"></span>
  4565. </span>
  4566. </div>
  4567. <!--
  4568. <input class="form-control" type="date" name="M_DIST_FILES_DATE" value="<?php echo date('Y-m-d');?>" maxlength="10">
  4569. -->
  4570. <br><label>jeśli nie zostanie podana to zostanie ustawiona na dzisiaj (<?php echo date('Y-m-d');?>)</label>
  4571. </td>
  4572. <td>
  4573. <input class="form-control" style="width:100%" type="number" name="M_DIST_FILES_VERSION">
  4574. <br>
  4575. <label class="checkbox">
  4576. <input type="checkbox" name="M_DIST_FILES_VERSION_AUTO">
  4577. Automatycznie dodaj wersje
  4578. </label>
  4579. </td>
  4580. </tr>
  4581. <tr>
  4582. <td colspan="5">
  4583. <div id="FRM_UPLOAD_RESULTS_<?php echo $this->_htmlID; ?>"></div>
  4584. <p>
  4585. <input type="submit" value="Wyślij" class="btn btn-primary"> wybrany plik do folderu:
  4586. </p>
  4587. <p>
  4588. <code><b><?php echo $uploader->getDestPathShare(true); ?></b></code>
  4589. <br><i style="color:#777">(Jeśli folder nie istnieje to zostanie utworzony automatycznie)</i>
  4590. </p>
  4591. </td>
  4592. </tr>
  4593. </table>
  4594. </form>
  4595. </div>
  4596. <script>
  4597. function fileListUpdateAjax<?php echo $this->_htmlID; ?>() {
  4598. var postData = {};
  4599. jQuery.ajax({
  4600. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=FILES_LIST&ID=<?php echo $record->ID; ?>',
  4601. type: 'POST',
  4602. //dataType: 'json',
  4603. //contentType: "application/json; charset=utf-8",
  4604. data: postData,
  4605. async: true,
  4606. success: function(data) {
  4607. fileListUpdate<?php echo $this->_htmlID; ?>(data);
  4608. },
  4609. error: function(jhr, textStatus, errorThrown) {
  4610. if (priv.options.debug) console.log('request error: ', errorThrown, ' textStatus: ', textStatus);
  4611. }
  4612. });
  4613. }
  4614. function fileListUpdate<?php echo $this->_htmlID; ?>(fileListJson) {
  4615. var fileListNode = jQuery('#FILES_LIST_<?php echo $this->_htmlID; ?>');
  4616. fileListNode.empty();
  4617. fileListJson.map(function(file){
  4618. var node = $('<tr></tr>');
  4619. var fFun = $('<i class="glyphicon glyphicon-remove" style="cursor:pointer" data-filename="' + file.name + '"></i>');
  4620. var fNameCell = $('<td style="overflow: hidden;"></td>');
  4621. var fName = $('<div style="overflow:hidden; white-space:nowrap;" title="' + file.name + '"></div>');
  4622. fName.append(fFun);
  4623. fName.append(file.name);
  4624. fName.appendTo(fNameCell);
  4625. node.append(fNameCell);
  4626. node.append('<td style="overflow:hidden; white-space:nowrap; text-align:center;">' + '<a href="' + file.web + '" target="_blank" class="glyphicon glyphicon-download-alt"></a>' + '</td>');
  4627. <?php if ($sharePoint) : ?>
  4628. node.append('<td style="overflow:hidden; white-space:nowrap; text-align:center;">' + '<a href="<?php echo $sharePoint; ?>/' + file.name + '" target="_blank" class="glyphicon glyphicon-folder-open"></a>' + '</td>');
  4629. <?php endif; ?>
  4630. node.append('<td style="overflow:hidden; white-space:nowrap; text-align:right;">' + file.sizeStr + '</td>');
  4631. node.append('<td style="overflow:hidden; white-space:nowrap;">' + file.created + '</td>');
  4632. node.appendTo(fileListNode);
  4633. $(fFun).click(function(e){
  4634. var n = $(e.target);
  4635. var fname= n.data('filename');
  4636. if (!fname) {
  4637. return false;
  4638. }
  4639. if (confirm('Czy jesteś pewien, że chcesz usunąć plik o nazwie ' + fname + '?')) {
  4640. var postData = {filename: fname};
  4641. jQuery.ajax({
  4642. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=FILE_REMOVE&ID=<?php echo $record->ID; ?>',
  4643. type: 'POST',
  4644. //dataType: 'json',
  4645. //contentType: "application/json; charset=utf-8",
  4646. data: postData,
  4647. async: true,
  4648. success: function(data) {
  4649. if (data && data.type) {
  4650. if (data.type == 'SUCCESS') {
  4651. n.parents('tr').remove();
  4652. //console.log('TODO: SUCCESS msg: ', data.string);
  4653. }
  4654. else if (data.type == 'ERROR') {
  4655. //console.log('TODO: ERROR msg: ', data.string);
  4656. }
  4657. } else {
  4658. if (priv.options.debug) console.log('TODO: ??? data: ', data);
  4659. }
  4660. },
  4661. error: function(jhr, textStatus, errorThrown) {
  4662. if (priv.options.debug) console.log('rm error: ', errorThrown, ' textStatus: ', textStatus);
  4663. }
  4664. });
  4665. }
  4666. });
  4667. });
  4668. }
  4669. function connTblListUpdateAjax<?php echo $this->_htmlID; ?>(connTblID) {
  4670. var postData = {};
  4671. // clear current file list
  4672. jQuery('#FILES_CONN_TBLS_<?php echo $this->_htmlID; ?>').find('.files-list').empty();
  4673. jQuery.ajax({
  4674. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=FILES_CONN_TBL_LIST&ID=<?php echo $record->ID; ?>&connTblID=' + connTblID,
  4675. type: 'POST',
  4676. //dataType: 'json',
  4677. //contentType: "application/json; charset=utf-8",
  4678. data: postData,
  4679. async: true,
  4680. success: function(data) {
  4681. connTblListUpdate<?php echo $this->_htmlID; ?>(data);
  4682. },
  4683. error: function(jqXHR, textStatus, errorThrown) {
  4684. var txt = jqXHR.responseText || 'Error';
  4685. jQuery('#FILES_CONN_TBLS_<?php echo $this->_htmlID; ?>').find('.files-list').html('<tr><td colspan="6"><div class="alert alert-danger">' + txt + '</div></td></tr>');
  4686. if (priv.options.debug) console.log('connTblListUpdateAjax error: ', errorThrown, ' textStatus: ', textStatus);
  4687. }
  4688. });
  4689. }
  4690. function connTblListUpdate<?php echo $this->_htmlID; ?>(fileListJson) {
  4691. var fileListNode = jQuery('#FILES_CONN_TBLS_<?php echo $this->_htmlID; ?>').find('.files-list');
  4692. fileListNode.empty();
  4693. fileListJson.map(function(file){
  4694. var node = $('<tr></tr>');
  4695. var fNameCell = $('<td style="overflow: hidden;"></td>');
  4696. var fName = $('<div style="overflow:hidden; white-space:nowrap;" title="' + file.name + '"></div>');
  4697. fName.append(file.name);
  4698. fName.appendTo(fNameCell);
  4699. node.append(fNameCell);
  4700. node.append('<td style="overflow:hidden; white-space:nowrap; text-align:center;">' + '<a href="' + file.web + '" target="_blank" class="glyphicon glyphicon-download-alt"></a>' + '</td>');
  4701. node.append('<td style="overflow:hidden; white-space:nowrap; text-align:right;">' + file.sizeStr + '</td>');
  4702. node.append('<td style="overflow:hidden; white-space:nowrap;">' + file.created + '</td>');
  4703. node.appendTo(fileListNode);
  4704. });
  4705. }
  4706. function fileListActions<?php echo $this->_htmlID; ?>() {
  4707. var filePermsReload = jQuery('#FILES_LIST_ACTIONS_<?php echo $this->_htmlID; ?>');
  4708. var btnReload = jQuery('<button class="btn-link btn-sm" title="odśwież uprawnienia do plików"><span class="glyphicon glyphicon-refresh"></span>Odśwież</button>');
  4709. btnReload.on('click', function(e) {
  4710. //console.log('TODO: click reload perms...');
  4711. function notifyAjaxCallback(data) {
  4712. var notify = {};
  4713. notify.type = (data && data.type)? data.type : '';
  4714. notify.msg = (data && data.msg)? data.msg : '';
  4715. switch (notify.type) {
  4716. case 'success':
  4717. if (!notify.msg) notify.msg = 'OK';
  4718. break;
  4719. case 'info':
  4720. if (!notify.msg) notify.msg = '';
  4721. break;
  4722. case 'error':
  4723. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  4724. break;
  4725. case 'warning':
  4726. notify.type = 'warn';
  4727. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  4728. break;
  4729. default:
  4730. notify.msg = 'Nieznany błąd';
  4731. if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
  4732. notify.type = '';
  4733. }
  4734. jQuery.notify(notify.msg, notify.type);
  4735. }
  4736. var reqData = {};
  4737. jQuery.ajax({
  4738. data: reqData,
  4739. dataType: 'json',
  4740. type: "GET",
  4741. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=filePermsRefresh&ID=<?php echo $record->ID; ?>',
  4742. })
  4743. .done(function(data, textStatus, jqXHR){
  4744. notifyAjaxCallback(data);
  4745. if (data && data.files) {
  4746. fileListUpdate<?php echo $this->_htmlID; ?>(data.files);
  4747. }
  4748. })
  4749. .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
  4750. if (jqXHR.responseJSON) {
  4751. notifyAjaxCallback(jqXHR.responseJSON);
  4752. }
  4753. else {
  4754. var txt = jqXHR.responseText || 'Wystąpiły błędy';
  4755. if (jqXHR.status == 404) {
  4756. jQuery.notify(jqXHR.responseText, 'error');
  4757. } else {
  4758. jQuery.notify(jqXHR.responseText, 'warn');
  4759. }
  4760. }
  4761. });
  4762. });
  4763. filePermsReload.append(btnReload);
  4764. }
  4765. jQuery(document).ready(function(){
  4766. $('#FILES_TAB_<?php echo $this->_htmlID; ?> a').click(function(e) {
  4767. e.preventDefault();
  4768. $(this).tab('show');
  4769. })
  4770. .on('shown.bs.tab', function(e) {
  4771. var fileSource = $(e.target).data('toggle')
  4772. , frm = jQuery('#FILES_FRM_<?php echo $this->_htmlID; ?>').get(0);
  4773. if (frm['M_DIST_UPLOAD_SOURCE']) {
  4774. frm['M_DIST_UPLOAD_SOURCE'].value = fileSource;
  4775. }
  4776. })
  4777. jQuery('#FILES_FRM_<?php echo $this->_htmlID; ?>').ajaxForm({
  4778. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=FILES_UPLOAD&ID=<?php echo $record->ID; ?>',
  4779. beforeSubmit: function(args, $form, options) {
  4780. //console.log('#FILES_FRM_<?php echo $this->_htmlID; ?>.ajaxForm->beforeSubmit()...');
  4781. var argsMap = [];
  4782. args.map(function(v, k) {
  4783. argsMap[v.name] = v.value;
  4784. });
  4785. // validate
  4786. if (argsMap['M_DIST_UPLOAD_SOURCE'] == 'local') {
  4787. if (!argsMap['M_DIST_FILES_NAME']) {
  4788. //console.log('#FILES_FRM_<?php echo $this->_htmlID; ?>.ajaxForm->beforeSubmit() M_DIST_UPLOAD_SOURCE=local && !M_DIST_FILES_NAME');
  4789. return false;
  4790. }
  4791. }
  4792. else if (argsMap['M_DIST_UPLOAD_SOURCE'] == 'scan') {
  4793. if (!argsMap['SCANS_COLUMN_ADD']) {
  4794. //console.log('#FILES_FRM_<?php echo $this->_htmlID; ?>.ajaxForm->beforeSubmit() M_DIST_UPLOAD_SOURCE=scan && !SCANS_COLUMN_ADD');
  4795. return false;
  4796. }
  4797. }
  4798. else {
  4799. return false;
  4800. }
  4801. var $out = $('#FRM_UPLOAD_RESULTS_<?php echo $this->_htmlID; ?>');
  4802. $out.html('Wysyłanie...');
  4803. },
  4804. success: function(data) {
  4805. //console.log('#FILES_FRM_<?php echo $this->_htmlID; ?>.ajaxForm->success()...');
  4806. var $out = $('#FRM_UPLOAD_RESULTS_<?php echo $this->_htmlID; ?>');
  4807. var btnClose = '<button type="button" class="close" data-dismiss="alert"><i class="glyphicon glyphicon-remove"></i></button>';
  4808. if (typeof data == 'object') {
  4809. if (data.type == 'ERROR') {
  4810. $out.html('<div class="alert alert-danger">' + btnClose + data.string + '</div>');
  4811. } else if (data.type == 'SUCCESS') {
  4812. $out.html('<div class="alert alert-success">' + btnClose + data.string + '</div>');
  4813. fileListUpdateAjax<?php echo $this->_htmlID; ?>();
  4814. }
  4815. } else {
  4816. if (data.substr(0, 7) == 'WARNING') {
  4817. data = data.substr(7);
  4818. $out.html('<div class="alert alert-warning">' + btnClose + data + '</div>');
  4819. } else if (data.substr(0, 5) == 'ERROR') {
  4820. data = data.substr(5);
  4821. $out.html('<div class="alert alert-danger">' + btnClose + data + '</div>');
  4822. } else if (data.substr(0, 7) == 'SUCCESS') {
  4823. data = data.substr(7);
  4824. $out.html('<div class="alert alert-success">' + btnClose + data + '</div>');
  4825. fileListUpdateAjax<?php echo $this->_htmlID; ?>();
  4826. } else if (data.substr(0, 4) == 'INFO') {
  4827. data = data.substr(4);
  4828. $out.html('<div class="alert alert-info">' + btnClose + data + '</div>');
  4829. }
  4830. }
  4831. }
  4832. });
  4833. fileListActions<?php echo $this->_htmlID; ?>();
  4834. var fileList = <?php echo json_encode($jsonFiles); ?>;
  4835. fileListUpdate<?php echo $this->_htmlID; ?>(fileList);
  4836. var connTbls = <?php echo json_encode($this->getConnectedTables()); ?>;
  4837. if (connTbls) {
  4838. var connTblsOut = '';
  4839. for(var key in connTbls) {
  4840. connTblsOut += '<button class="btn btn-sm btn-default conn-tbl-load" data-zasobid="' + key + '">' + connTbls[key] + '</button>';
  4841. };
  4842. if (connTblsOut) {
  4843. connTblsOut = 'Pliki w powiązanych tabelach: <div class="btn-group">' + connTblsOut + '</div>';
  4844. connTblsOut += '<div style="max-height:180px; overflow:auto; border-bottom:1px solid #ddd;">' +
  4845. '<table class="table table-bordered table-hover">' +
  4846. '<colgroup>' +
  4847. '<col style="">' +
  4848. '<col style="width:30px;">' +
  4849. <?php if ($sharePoint) : ?>
  4850. '<col style="width:30px;">' +
  4851. <?php endif; ?>
  4852. '<col style="width:80px;">' +
  4853. '<col style="width:140px;">' +
  4854. '</colgroup>' +
  4855. '<tbody class="files-list">' +
  4856. '</tbody>' +
  4857. '</table>' +
  4858. '</div>';
  4859. var _connTblsWrap = jQuery('#FILES_CONN_TBLS_<?php echo $this->_htmlID; ?>');
  4860. _connTblsWrap.css('marginBottom', '26px');
  4861. _connTblsWrap.html(connTblsOut);
  4862. _connTblsWrap.find('.conn-tbl-load').each(function(){
  4863. jQuery(this).click(function(e){
  4864. var tblID = jQuery(e.target).data('zasobid');
  4865. if (tblID) {
  4866. connTblListUpdateAjax<?php echo $this->_htmlID; ?>(tblID);
  4867. }// TODO: else show error
  4868. });
  4869. });
  4870. }
  4871. }
  4872. initDateTimePicker(jQuery('#FILES_FRM_<?php echo $this->_htmlID; ?>'));
  4873. });
  4874. </script>
  4875. <?php
  4876. exit;
  4877. }
  4878. private function sendTypeSpecial($fldID, $args) {
  4879. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  4880. header("Content-type: application/json");
  4881. $fldName = '';
  4882. $fld = $this->_acl->getField($fldID);
  4883. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fld('.$fldID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fld);echo'</pre>';}
  4884. if (!$fld) {
  4885. // 404
  4886. } else {
  4887. $fldName = $fld['name'];
  4888. }
  4889. $jsonData = array();
  4890. $typeSpecial = Typespecial::getInstance($fldID, $fldName);
  4891. if ($typeSpecial) {
  4892. $query = V::get('q', '', $_REQUEST);
  4893. $rawRows = null;
  4894. $rows = $typeSpecial->getValuesWithExports($query);
  4895. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">rows('.$query.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($rows);echo'</pre>';}
  4896. foreach ($rows as $kID => $vItem) {
  4897. $itemJson = new stdClass();
  4898. $itemJson->id = $vItem->id;
  4899. $itemJson->name = $vItem->param_out;
  4900. if (!empty($vItem->exports)) {
  4901. $itemJson->exports = $vItem->exports;
  4902. }
  4903. $jsonData[] = $itemJson;
  4904. }
  4905. }
  4906. /*
  4907. MENU_INIT:VIEWTABLE_AJAX
  4908. ZASOB_ID:1188
  4909. _task:TYPESPECIAL
  4910. fldID:3866
  4911. Form Dataview sourceview URL encoded
  4912. q:te
  4913. */
  4914. echo json_encode($jsonData);
  4915. exit;
  4916. }
  4917. private function sendTypeSpecialCell($id, $fldName, $args) {
  4918. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  4919. header("Content-type: application/json");
  4920. $jsonData = new stdClass();
  4921. $fldID = $this->_acl->getFieldIdByName($fldName);
  4922. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fld('.$fldName.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fldID);echo'</pre>';}
  4923. $item = $this->_acl->getItem($id);
  4924. if (!$this->_acl->isAllowed($fldID, 'R', $item)) {
  4925. $jsonData->msg = 'Brak dostępu';
  4926. echo json_encode($jsonData);
  4927. exit;
  4928. }
  4929. if (!$fldID) {
  4930. $jsonData->msg = 'Wrong field';
  4931. echo json_encode($jsonData);
  4932. exit;
  4933. }
  4934. $typeSpecial = Typespecial::getInstance($fldID, $fldName);
  4935. if ($typeSpecial) {
  4936. $jsonData->data = $typeSpecial->getReturnData($this->_zasobID, $id, $fldName, '');
  4937. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">specialValuesByIds('.$id.'/'.$fldName.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValuesByIds);echo'</pre>';}
  4938. }
  4939. echo json_encode($jsonData);
  4940. exit;
  4941. }
  4942. private function ajaxData($args) {
  4943. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  4944. $pageSize = V::get('pageSize', $this->_pageSize, $args, 'int');
  4945. $page = V::get('page', 0, $args, 'int');
  4946. $currSortCol = V::get('currSortCol', '', $args);
  4947. $currSortFlip = V::get('currSortFlip', '', $args);
  4948. if ($page > 0) {
  4949. $page -= 1;
  4950. }
  4951. else {
  4952. }
  4953. $params = array();
  4954. $params['limit'] = $pageSize;
  4955. $params['limitstart'] = $page * $params['limit'];
  4956. $params['order_by'] = ($currSortCol)? $currSortCol : '';
  4957. $params['order_dir'] = $currSortFlip;
  4958. $filters = new stdClass();
  4959. $filters->currSortCol = $currSortCol;
  4960. $filters->currSortFlip = $currSortFlip;
  4961. foreach ($args as $k => $v) {
  4962. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && strlen($v) > 0) {// filter prefix
  4963. $params[$k] = $v;
  4964. $filters->{$k} = $v;
  4965. }
  4966. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && strlen($v) > 0) {// special filter prefix
  4967. $params[$k] = $v;
  4968. $filters->{$k} = $v;
  4969. }
  4970. }
  4971. $this->setFilters($filters);
  4972. $vCols = $this->_acl->getVirtualFieldList();
  4973. if (!empty($vCols)) {
  4974. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">vCols (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($vCols);echo'</pre>';}
  4975. }
  4976. $visibleCols = $this->_acl->getVisibleFieldList();
  4977. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">visibleCols (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($visibleCols);echo'</pre>';}
  4978. $jsonData = new stdClass();
  4979. $jsonData->page = $page + 1;
  4980. $jsonData->pageSize = $pageSize;
  4981. $jsonData->filters = $filters;
  4982. $jsonData->cols = new stdClass();
  4983. $jsonData->uniqueCol = $this->_acl->getPrimaryKeyField();
  4984. $ind = 0;
  4985. foreach ($visibleCols as $fieldID => $col) {
  4986. $ind++;
  4987. $columnConfig = (object)array('index'=>$ind);
  4988. if (in_array($col, array('A_STATUS','A_STATUS_CURRENT','A_SERVICES_STATUS_CURRENT'))) {
  4989. $columnConfig->format = '<div class="cell-A_STATUS-{0}">{0}</div>';
  4990. }
  4991. else if (in_array($col, array('Status'))) {
  4992. // Ahmes problems Status colors
  4993. $columnConfig->format = '<div class="cell-Status-{0}">{0}</div>';
  4994. }
  4995. else if ($this->_acl->isGeomField($col)) {
  4996. $columnConfig->type = 'geom';
  4997. }
  4998. if ('' !== ($label = $this->_acl->getFieldLabel($fieldID))) {
  4999. $columnConfig->friendly = $label;
  5000. }
  5001. $colType = $this->_acl->getFieldType($col);
  5002. if ($colType) {// @see MarkTableAjaxFilterColType
  5003. if ($colType['type'] == 'date') {
  5004. //$columnConfig->type = 'date';// TODO: require datetimepicker
  5005. }
  5006. } else {// typespecial - no type
  5007. $columnConfig->type = 'special';
  5008. }
  5009. $typeSpecial = Typespecial::getInstance($fieldID, $col);
  5010. if ($typeSpecial) {
  5011. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">typeSpecial (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
  5012. $columnConfig->_tsRetId = $typeSpecial->getReturnId();
  5013. if ($columnConfig->_tsRetId == 0) {
  5014. $tsParamOut = V::get('param_out', null, $typeSpecial);
  5015. if ($tsParamOut) {
  5016. $tsFormat = V::get('format', null, $tsParamOut);
  5017. $tsValues = V::get('values', null, $tsParamOut);
  5018. $tsAliases = V::get('alias', null, $tsParamOut);
  5019. if (false !== strpos($tsFormat, '<a') && !empty($tsValues) && !empty($tsAliases)) {
  5020. $tsAliasMap = array();
  5021. /* [values] => Array([ID] => 1467), [alias] => Array([1467] => ID) */
  5022. $bugTsColsNotVisible = array();
  5023. foreach ($tsValues as $kVarName => $vIdZasob) {
  5024. if (array_key_exists($vIdZasob, $tsAliases)) {
  5025. $tsAliasMap[$kVarName] = $tsAliases[$vIdZasob];
  5026. } else {
  5027. $bugTsColsNotVisible[] = "noAliasFor {$vIdZasob}";
  5028. }
  5029. if (!array_key_exists($vIdZasob, $visibleCols)) {
  5030. $bugTsColsNotVisible[] = $vIdZasob;
  5031. }
  5032. }
  5033. if (empty($bugTsColsNotVisible)) {
  5034. $tsSimpleLink = new stdClass();
  5035. $tsSimpleLink->format = $tsFormat;
  5036. $tsSimpleLink->aliasMap = $tsAliasMap;
  5037. $columnConfig->_tsSimpleLink = $tsSimpleLink;
  5038. $columnConfig->type = 'simpleLink';
  5039. } else {
  5040. $columnConfig->_tsSimpleLinkBug = $bugTsColsNotVisible;
  5041. }
  5042. }
  5043. }
  5044. }
  5045. }
  5046. // @see ajaxHiddenColsSave
  5047. if (UserProfile::isHiddenColumn($this->_zasobID, $fieldID)) {
  5048. $columnConfig->hidden = true;
  5049. }
  5050. $columnConfig->description = $this->_acl->getFieldOpis($fieldID);
  5051. $jsonData->cols->{$col} = $columnConfig;
  5052. }
  5053. $jsonData->rows = array();
  5054. $jsonData->total = $this->_acl->getTotal($params);
  5055. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">get_total (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($jsonData->total);echo'</pre>';}
  5056. $items = $this->_acl->getItems($params);
  5057. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">items (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($items);echo'</pre>';}
  5058. // TODO: add virtual data by Typespecial
  5059. if (!empty($vCols) && !empty($items)) {
  5060. foreach ($vCols as $vColID => $vCol) {
  5061. $colType = $this->_acl->getFieldTypeById($vColID);
  5062. if ($colType) {
  5063. continue;// pomin Typespecial dla realnych komorek w bazie danych
  5064. }
  5065. $typeSpecial = Typespecial::getInstance($vColID, $vCol);
  5066. if ($typeSpecial) {
  5067. $columnConfig = V::get($vCol, null, $jsonData->cols);
  5068. if ($columnConfig && !empty($columnConfig->_tsSimpleLink)) {
  5069. // pomin simple link values - mved to js render
  5070. } else {
  5071. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$vColID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
  5072. $ids = array_keys($items);
  5073. $specialValues = $typeSpecial->getValuesByIds($this->_zasobID, $ids);
  5074. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$vCol.') specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValues);echo'</pre>';}
  5075. if (!empty($specialValues)) foreach ($specialValues as $kItemID => $vValues) {
  5076. $tsValue = implode('<br>', $vValues);
  5077. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Item['.$kItemID.'].'.$vCol.' specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($items[$kItemID]);echo'</pre>';}
  5078. if (!empty($items[$kItemID]->{$vCol}) && !empty($tsValue)) {
  5079. $items[$kItemID]->{$vCol} .= ": {$tsValue}";
  5080. } else {
  5081. $items[$kItemID]->{$vCol} = $tsValue;
  5082. }
  5083. }
  5084. }
  5085. }
  5086. }
  5087. }
  5088. foreach ($items as $vItem) {
  5089. // TODO: hide items without 'R'
  5090. foreach ($visibleCols as $kID => $vCol) {
  5091. // TODO: ID default 'R'
  5092. if (!$this->_acl->isAllowed($kID, 'R', $vItem)) {
  5093. $vItem->{$vCol} = '*****';
  5094. }
  5095. // null => empty string
  5096. if (!isset($vItem->{$vCol}) || (!$vItem->{$vCol} && $vItem->{$vCol} !== '0')) {
  5097. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">isEmptyString['.$vCol.'] (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($vItem->{$vCol});echo'</pre>';}
  5098. $vItem->{$vCol} = '';
  5099. }
  5100. }
  5101. $jsonData->rows[] = $vItem;
  5102. }
  5103. return $jsonData;
  5104. }
  5105. private function fixEmptyValueFromUser($fieldID) {// TODO: moved to TableAcl->fixEmptyValueFromUser
  5106. $value = '';
  5107. $type = $this->_acl->getFieldTypeById($fieldID);
  5108. if ($type) {
  5109. if ($type['type'] == 'date') {
  5110. $value = $type['default'];
  5111. }
  5112. // fix bug when field is unique and is null allowed: change empty string to null
  5113. if ($type['null']) {
  5114. $value = 'NULL';
  5115. }
  5116. // fix bug when field is enum and is set to '0': for php '0' is empty
  5117. if (substr($type['type'], 0, 4) == 'enum') {// && $args["f{$fieldID}"] === '0') {
  5118. if (false !== strpos($type['type'], "''")) {
  5119. // enum('', '1','2')
  5120. $value = '';
  5121. } else if (false !== strpos($type['type'], "'0'")) {
  5122. // enum('0', '1','2')
  5123. $value = '0';
  5124. } else {
  5125. $value = $type['default'];
  5126. }
  5127. }
  5128. }
  5129. return $value;
  5130. }
  5131. /**
  5132. * set hidden cols in $_SESSION['USER_PROFILE'][$this->_zasobID];
  5133. * $_SESSION['USER_PROFILE'][$this->_zasobID][fld_id] => boolean
  5134. */
  5135. private function ajaxHiddenColsSave($args) {
  5136. $response = new stdClass();
  5137. if (empty($args)) {
  5138. $response->type = 'info';
  5139. return $response;
  5140. }
  5141. UserProfile::load();
  5142. // clean up old, wrong values
  5143. if (array_key_exists("{$this->_tbl}_COLUMN", $_SESSION['USER_PROFILE'])) {
  5144. unset($_SESSION['USER_PROFILE']["{$this->_tbl}_COLUMN"]);
  5145. }
  5146. $colVis = UserProfile::getHiddenCols($this->_zasobID);
  5147. $fields = $this->_acl->getFields();
  5148. foreach ($fields as $kFldId => $vFld) {
  5149. $vFldName = $vFld['name'];
  5150. if (isset($args[$vFldName])) {
  5151. if ($args[$vFldName] == 'SHOW') {
  5152. $colVis[$kFldId] = 1;
  5153. } else if ($args[$vFldName] == 'HIDE') {
  5154. $colVis[$kFldId] = 0;
  5155. }
  5156. }
  5157. }
  5158. UserProfile::setHiddenCols($this->_zasobID, $colVis);
  5159. UserProfile::save();
  5160. $response->type = 'success';
  5161. return $response;
  5162. }
  5163. private function ajaxPageSizeSave($args) {
  5164. $response = new stdClass();
  5165. if (empty($args)) {
  5166. $response->type = 'info';
  5167. return $response;
  5168. }
  5169. $pageSize = V::get('pageSize', 0, $args, 'int');
  5170. UserProfile::load();
  5171. // clean up old, wrong values
  5172. if (array_key_exists("{$this->_tbl}_COLUMN", $_SESSION['USER_PROFILE'])) {
  5173. unset($_SESSION['USER_PROFILE']["{$this->_tbl}_COLUMN"]);
  5174. }
  5175. $tableAjaxSettings = UserProfile::getTableAjaxSettings();
  5176. $tableAjaxSettings['pageSize'] = $pageSize;
  5177. UserProfile::setTableAjaxSettings($tableAjaxSettings);
  5178. UserProfile::save();
  5179. $response->type = 'success';
  5180. return $response;
  5181. }
  5182. private function ajaxTheGeomSave($args) {
  5183. $primaryKeyField = $this->_acl->getPrimaryKeyField();
  5184. $primaryKey = V::get($primaryKeyField, 0, $args, 'int');
  5185. $polygon = V::get('polygon', 0, $args);
  5186. $geomFieldName = 'the_geom';
  5187. if ($primaryKey <= 0) {
  5188. throw new HttpException("Wrong param ID", 404);
  5189. }
  5190. // TODO: validate polygon - ex.: POLYGON((2072030.2315435 7234115.910678,2072029.4815435 7234093.660678,2072115.2315435 7234091.160678,2072115.4815435 7234113.660678,2072115.2315435 7234113.660678,2072094.2315435 7234113.910678,2072030.2315435 7234115.910678)))
  5191. $record = $this->_acl->getItem($primaryKey);
  5192. if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
  5193. throw new HttpException("Brak dostępu do rekordu", 403);
  5194. }
  5195. $theGeomFieldId = $this->_acl->getFieldIdByName($geomFieldName);
  5196. if (!$this->_acl->isAllowed($theGeomFieldId, 'W', $record)) {
  5197. throw new HttpException("Brak dostępu do zapisu dla pola {$geomFieldName}", 403);
  5198. }
  5199. $itemPatch = array();
  5200. $itemPatch[$geomFieldName] = "GeomFromText('{$polygon}')";
  5201. $itemPatch[$primaryKeyField] = $primaryKey;
  5202. $response = new stdClass();
  5203. try {
  5204. $affected = $this->_acl->updateItem($itemPatch);
  5205. if ($affected > 0) {
  5206. $response->type = 'success';
  5207. $response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
  5208. } else if ($affected == 0) {
  5209. $response->type = 'info';
  5210. $response->msg = "Nie wprowadzono żadnych zmian";
  5211. }
  5212. $response->record = $this->_acl->getItem($primaryKey);
  5213. }
  5214. catch (Exception $e) {
  5215. $response->type = 'error';
  5216. $response->msg = $e->getMessage();
  5217. }
  5218. return $response;
  5219. }
  5220. private function sendAjaxResponseJson($method, $args) {
  5221. try {
  5222. $response = $this->{$method}($args);
  5223. }
  5224. catch (HttpException $e) {
  5225. $response = new stdClass();
  5226. $response->type = 'error';
  5227. $response->msg = $e->getMessage();
  5228. $response->errorCode = $e->getCode();
  5229. Http::sendHeaderByCode($e->getCode());
  5230. }
  5231. catch (Exception $e) {
  5232. $response = new stdClass();
  5233. $response->type = 'error';
  5234. $response->msg = $e->getMessage();
  5235. $response->errorCode = $e->getCode();
  5236. }
  5237. header('Content-type: application/json');
  5238. if (!$response) $response = new stdClass();
  5239. echo json_encode($response);
  5240. exit;
  5241. }
  5242. private function ajaxTheGeomRemove($args) {// ajax task 'THE_GEOM_REMOVE'
  5243. $primaryKeyField = $this->_acl->getPrimaryKeyField();
  5244. $primaryKey = V::get($primaryKeyField, 0, $args, 'int');
  5245. $geomFieldName = 'the_geom';
  5246. $response = new stdClass();
  5247. if ($primaryKey <= 0) {
  5248. throw new HttpException("Wrong param ID", 404);
  5249. }
  5250. $record = $this->_acl->getItem($primaryKey);
  5251. if (!$record) {
  5252. throw new HttpException("Nie odnaleziono rekordu nr {$primaryKey}", 404);
  5253. }
  5254. if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
  5255. throw new HttpException("Brak dostępu do rekordu nr {$primaryKey}", 403);
  5256. }
  5257. $theGeomFieldId = $this->_acl->getFieldIdByName($geomFieldName);
  5258. if (!$this->_acl->isAllowed($theGeomFieldId, 'W', $record)) {
  5259. throw new HttpException("Brak dostępu do zapisu dla pola {$geomFieldName}", 403);
  5260. }
  5261. if (empty($record->{$geomFieldName})) {
  5262. $response->type = 'info';
  5263. $response->msg = "Rekord nie jest powiązany z żadnym obiektem na mapie";
  5264. $response->record = $record;
  5265. return $response;
  5266. }
  5267. $itemPatch = array();
  5268. $itemPatch[$geomFieldName] = "NULL";
  5269. $itemPatch[$primaryKeyField] = $primaryKey;
  5270. $response = new stdClass();
  5271. try {
  5272. $affected = $this->_acl->updateItem($itemPatch);
  5273. if ($affected > 0) {
  5274. $response->type = 'success';
  5275. $response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
  5276. } else if ($affected == 0) {
  5277. $response->type = 'info';
  5278. $response->msg = "Nie wprowadzono żadnych zmian";
  5279. }
  5280. $response->record = $this->_acl->getItem($primaryKey);
  5281. }
  5282. catch (Exception $e) {
  5283. $response->type = 'error';
  5284. $response->msg = $e->getMessage();
  5285. }
  5286. return $response;
  5287. }
  5288. private function ajaxProcesInitFiltr($args) {// ajax task 'PROCES_INIT_FILTR'
  5289. $response = new stdClass();
  5290. $pInitList = array();// [proces_init_id] => label (DESC)
  5291. if (!$this->_showProcesInit) {
  5292. $response->type = 'error';
  5293. return $response;
  5294. }
  5295. $userAcl = User::getAcl();
  5296. $pInitList = $userAcl->getTableProcesInitList($this->_zasobID);
  5297. if (!empty($pInitList)) {
  5298. $procesIds = array_keys($pInitList);
  5299. $mapTree = ACL::getProcesInitMapTreeOnlyIds($procesIds);
  5300. DBG::_('DBG_MAP', '1', "mapTree", $mapTree, __CLASS__, __FUNCTION__, __LINE__);
  5301. DBG::_('DBG_MAP', '1', "pInitList", $pInitList, __CLASS__, __FUNCTION__, __LINE__);
  5302. $pInitListSelected = $this->getProcesInitSelected();
  5303. $response->pInitData = new stdClass();
  5304. $response->pInitData->pInitList = $pInitList;
  5305. $response->pInitData->mapTree = $mapTree;
  5306. $response->pInitData->pInitListSelected = $pInitListSelected;
  5307. }
  5308. $response->type = 'success';
  5309. return $response;
  5310. }
  5311. function ajaxMoreFunctionsCell($args) {// ajax task 'MORE_FUNCTIONS_CELL'
  5312. $id = V::get('ID', 0, $args, 'int');
  5313. if ($id <= 0) throw new HttpException("404", 404);
  5314. $response = new stdClass();
  5315. $response->type = 'success';
  5316. $response->msg = 'Funkcje';
  5317. $response->rowFunctions = [];
  5318. $tableName = $this->_acl->getName();
  5319. if(1){// TODO: fetch $totalMsgs from TableMsgs
  5320. $msgs = Router::getRoute('Msgs');
  5321. $msgsList = $msgs->getActiveMessagesForTableRecord($tableName, $id);
  5322. $totalMsgs = count($msgsList);
  5323. $rowFunc = new stdClass();
  5324. $rowFunc->ico = 'glyphicon glyphicon-envelope';
  5325. $rowFunc->href = 'index.php?_route=TableMsgs&_task=tableRow&idTable=' . $this->_zasobID . '&idRow=' . $id;
  5326. $rowFunc->title = "Wiadomości <span class=\"badge\">{$totalMsgs}</span>";
  5327. $response->rowFunctions[] = $rowFunc;
  5328. }
  5329. if ('CRM_PROCES' == $this->_acl->getName()) {// TODO: mv to table gui xml or php class
  5330. $record = $this->_acl->getItem($id);
  5331. // procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001
  5332. $rowFunc = new stdClass();
  5333. $rowFunc->ico = 'glyphicon glyphicon-eye-open';
  5334. $rowFunc->href = "procesy5.php?task=CRM_PROCES&filtr_id={$id}";
  5335. $rowFunc->title = "Zobacz na drzewie procesów {{$id}}";
  5336. $response->rowFunctions[] = $rowFunc;
  5337. $wskazniki = ProcesHelper::get_wskazniki($id);
  5338. $connectedZasobyTotal = count($wskazniki);
  5339. $rowFunc = new stdClass();
  5340. $rowFunc->ico = 'glyphicon glyphicon-random';
  5341. $rowFunc->href = "index.php?MENU_INIT=PROCES_ADD_ZASOB&procesID={$id}";
  5342. $rowFunc->title = "Powiązane zasoby <span class=\"badge\">{$connectedZasobyTotal}</span>";
  5343. $response->rowFunctions[] = $rowFunc;
  5344. }
  5345. if ('CRM_LISTA_ZASOBOW' == $this->_acl->getName()) {// TODO: mv to table gui xml or php class
  5346. $record = $this->_acl->getItem($id);
  5347. // procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001
  5348. $rowFunc = new stdClass();
  5349. $rowFunc->ico = 'glyphicon glyphicon-eye-open';
  5350. $rowFunc->href = "procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id={$id}";
  5351. $rowFunc->title = "Zobacz na drzewie zasobów [{$id}]";
  5352. $response->rowFunctions[] = $rowFunc;
  5353. // index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob=22001
  5354. $rowFunc = new stdClass();
  5355. $rowFunc->ico = 'glyphicon glyphicon-random';
  5356. $rowFunc->href = "index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob={$id}";
  5357. $rowFunc->title = "Powiązane procesy (OB)";
  5358. $response->rowFunctions[] = $rowFunc;
  5359. // index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob=22001
  5360. $rowFunc = new stdClass();
  5361. $rowFunc->ico = 'glyphicon glyphicon-random';
  5362. $rowFunc->href = "index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob={$id}";
  5363. $rowFunc->title = "Powiązane dane (IDS)";
  5364. $response->rowFunctions[] = $rowFunc;
  5365. $groupTypeList = array();
  5366. $groupTypeList[] = 'STANOWISKO';
  5367. $groupTypeList[] = 'PODMIOT';
  5368. $groupTypeList[] = 'DZIAL';
  5369. if (in_array($record->TYPE, $groupTypeList)) {
  5370. $rowFunc = new stdClass();
  5371. $rowFunc->ico = 'glyphicon glyphicon-retweet';
  5372. $rowFunc->href = "index.php?_route=Users&_task=syncGroup&idGroup={$id}";
  5373. $rowFunc->title = "Synchronizuj do LDAP";
  5374. $response->rowFunctions[] = $rowFunc;
  5375. }
  5376. }
  5377. if ('ADMIN_USERS' == $this->_acl->getName()) {// TODO: mv to table gui xml
  5378. $record = $this->_acl->getItem($id);
  5379. $isAllowedoReadUserLogin = false;
  5380. if ($this->_acl->canReadRecord($record)) {
  5381. $idFieldUserLogin = $this->_acl->getFieldIdByName('ADM_ACCOUNT');
  5382. if ($idFieldUserLogin) {
  5383. if ($this->_acl->isAllowed($idFieldUserLogin, 'R', $record)) {
  5384. $isAllowedoReadUserLogin = true;
  5385. }
  5386. }
  5387. }
  5388. if ($isAllowedoReadUserLogin) {
  5389. $rowFunc = new stdClass();
  5390. $rowFunc->ico = 'glyphicon glyphicon-user';
  5391. $rowFunc->href = 'index.php?_route=Users&_task=userGroups&usrLogin=' . $record->ADM_ACCOUNT;
  5392. $rowFunc->title = "Ustal stanowisko";
  5393. $response->rowFunctions[] = $rowFunc;
  5394. $rowFunc = new stdClass();
  5395. $rowFunc->ico = 'glyphicon glyphicon-retweet';
  5396. $rowFunc->href = 'index.php?_route=Users&_task=syncUser&usrLogin=' . $record->ADM_ACCOUNT;
  5397. $rowFunc->title = "Synchronizuj do LDAP";
  5398. $response->rowFunctions[] = $rowFunc;
  5399. $rowFunc = new stdClass();
  5400. $rowFunc->ico = 'glyphicon glyphicon-minus';
  5401. $rowFunc->href = 'index.php?MENU_INIT=USER_OCENA_PRACOWNIKA&usrLogin=' . $record->ADM_ACCOUNT;
  5402. $rowFunc->title = "Ocena pracownika";
  5403. $response->rowFunctions[] = $rowFunc;
  5404. }
  5405. }
  5406. return $response;
  5407. }
  5408. }