TableAjax.php 190 KB

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