TableAjax.php 190 KB

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