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