TableAjax.php 193 KB

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