TableAjax.php 211 KB

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