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