TableAjax.php 210 KB

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