TableAjax.php 211 KB

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