TableAjax.php 192 KB

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