TableAjax.php 226 KB

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