TableAjax.php 211 KB

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