TableAjax.php 212 KB

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