TableAjax.php 192 KB

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