TableAjax.php 192 KB

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