TableAjax.php 191 KB

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