| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060 |
- //
- // CommonEditorViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 14-7-16.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "CommonEditorViewController.h"
- #import "CommonEditorCellEdit.h"
- #import "RASingleton.h"
- //#import "RANetwork.h"
- #import "CommonEditorCellEnum.h"
- #import "CommonEditorCellEditor.h"
- #import "CommonEditorCellSwitch.h"
- #import "CommonEditorCellModel.h"
- #import "CommonEditorCellAction.h"
- #import "EnumSelectViewController.h"
- #import "DatePickerViewController.h"
- #import "SignatureViewController.h"
- #import "CommonEditorCellSignature.h"
- #import "CommonEditorCellLabel.h"
- //#import "AddressEditorViewController.h"
- //#import "CreditCardEditorViewController.h"
- #import "MonthPickerViewController.h"
- //#import "ContactListViewController.h"
- #import "CommonEditorCellMAction.h"
- #import "CommonEditorCellTextView.h"
- #import "RAUtils.h"
- #import "CommonEditorCellImg.h"
- #import "RAConvertor.h"
- //#import "NetworkUtils.h"
- #import "config.h"
- //#import "CustomIOSAlertView.h"
- #import "DefaultAppearance.h"
- #import "DefaultTableHeaderView.h"
- #define INTNUMBERS @"0123456789\n"
- #define NUMBERS @"0123456789.\n"
- # ifdef OFFLINE_MODE
- #import "OLDataProvider.h"
- # endif
- #import <objc/objc.h>
- //#import "MainViewController.h"
- #import "AppDelegate.h"
- #import "FileCache.h"
- //#import "RAConvertor.h"
- #import "EnumSelectAndSortViewController.h"
- #import "CommonEditorRangeCell.h"
- #import "CommonEditorWebCell.h"
- #import "CommonEditorBannerCell.h"
- #import "ContentPreviewController.h"
- #import "NetworkUtils.h"
- #import "EnumSelectOnlineViewController.h"
- #import "common_const.h"
- @interface subitem_data ()
- @end
- @implementation subitem_data
- @end
- @interface CommonEditorViewController ()<CommonEditorRangeDelegate,CommonEditorWebCellDelegate,CommonEditorBannerDelegate>
- @end
- @implementation CommonEditorViewController
- - (void)viewDidLayoutSubviews {
- [super viewDidLayoutSubviews];
- [self resize_tableHeader];
- }
- #pragma mark - Code TableView
- - (UIView*)get_tableHeader
- {
- return [UIView new];
- }
- -(void) resize_tableHeader
- {
- //利用systemLayoutSizeFittingSize:计算出真实高度
- CGFloat height = [self.editorTable.tableHeaderView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
- CGRect headerFrame = self.editorTable.tableHeaderView.frame;
- headerFrame.size.height = height;//20是留的上下边距
- //修改tableHeaderView的frame
- self.editorTable.tableHeaderView.frame = headerFrame;
- }
- - (void)initTableView {
-
- self.editorTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- self.editorTable.translatesAutoresizingMaskIntoConstraints = NO;
- [self.tableContainer addSubview:self.editorTable];
- [self.tableContainer sendSubviewToBack:self.editorTable];
-
- NSLayoutConstraint *top_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
- attribute:NSLayoutAttributeTop
- relatedBy:NSLayoutRelationEqual
- toItem:self.tableContainer
- attribute:NSLayoutAttributeTop
- multiplier:1
- constant:0];
- self.tb_top_constraint = top_constraint;
- [self.tableContainer addConstraint:top_constraint];
-
- NSLayoutConstraint *left_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
- attribute:NSLayoutAttributeLeft
- relatedBy:NSLayoutRelationEqual
- toItem:self.tableContainer
- attribute:NSLayoutAttributeLeft
- multiplier:1
- constant:0];
- self.tb_left_constraint = left_constraint;
- [self.tableContainer addConstraint:left_constraint];
-
- NSLayoutConstraint *bottom_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
- attribute:NSLayoutAttributeBottom
- relatedBy:NSLayoutRelationEqual
- toItem:self.tableContainer
- attribute:NSLayoutAttributeBottom
- multiplier:1
- constant:0];
- self.tb_bottom_constraint = bottom_constraint;
- [self.tableContainer addConstraint:bottom_constraint];
-
- NSLayoutConstraint *right_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
- attribute:NSLayoutAttributeRight
- relatedBy:NSLayoutRelationEqual
- toItem:self.tableContainer
- attribute:NSLayoutAttributeRight
- multiplier:1
- constant:0];
- self.tb_right_constraint = right_constraint;
- [self.tableContainer addConstraint:right_constraint];
-
-
-
- self.editorTable.delegate = self;
- self.editorTable.dataSource = self;
- self.editorTable.tableFooterView = [UIView new];
- // self.editorTable.tableHeaderView = [UIView new];
- self.editorTable.tableHeaderView = [self get_tableHeader];
- }
- - (void)registerPhoneCell {
-
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Action_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellAction"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Edit_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEdit"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Enum_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEnum"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Image_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellImg"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Label_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellLabel"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_MAction_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellMAction"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Model_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellModel"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Signature_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSignature"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Switch_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSwitch"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_TextView_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellTextView"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Range_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorRangeCell"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Web_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorWebCell"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Banner_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorBannerCell"];
-
- [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Editor_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEditor"];
- }
- - (void)registerPadCell {
-
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellAction" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellAction"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellEdit" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEdit"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellEnum" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEnum"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellImg" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellImg"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellLabel" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellLabel"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellMAction" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellMAction"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellModel" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellModel"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellSignature" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSignature"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellSwitch" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSwitch"];
- [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellTextView" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellTextView"];
-
-
-
- // [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorRangeCell" bundle:nil] forCellReuseIdentifier:@"CommonEditorRangeCell"];
- // [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorWebCell" bundle:nil] forCellReuseIdentifier:@"CommonEditorWebCell"];
- // [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorBannerCell" bundle:nil] forCellReuseIdentifier:@"CommonEditorBannerCell"];
- }
- - (void)setupEditorTable {
-
- [self initTableView];
- // Regist Nib Cell
- NSString *model = [UIDevice currentDevice].model;
- if ([model isEqualToString:@"iPhone"]) {
- [self registerPhoneCell];
- }
- else
- {
- [self registerPadCell];
- }
- }
- #pragma mark ==============
- -(void) commonAction:(NSString *)value index:(NSIndexPath*) indexPath data:(NSMutableDictionary*) item_json
- {
-
-
- NSAssert(true, ([NSString stringWithFormat:@"%@ commonAction not impl",[self class_name]]));
- }
- - (NSString *)class_name {
- if (!_class_name) {
- const char *class_name_ch = object_getClassName([self class]);
- _class_name = [NSString stringWithUTF8String:class_name_ch];
- }
- return _class_name;
- }
- - (NSString *)urgency_timer_name {
- if (!_urgency_timer_name) {
- _urgency_timer_name = [NSString stringWithFormat:@"%@_urgency_timer",self.class_name];
- }
- return _urgency_timer_name;
- }
- - (int)level {
- if (_level == -1) {
-
- __block AppDelegate *appDelegate = nil;
-
- dispatch_async(dispatch_get_main_queue(), ^{
- //some UI methods ej
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
- });
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- NSDictionary *urgencyDic = [RASingleton.sharedInstance globalParameterForKey:@"urgencyDic"];
-
- id count = [urgencyDic objectForKey:@"count"];
-
- _level = count == nil ? 0 : [count intValue];
- }
- return _level;
- }
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void) request_fill
- {
-
- }
- -(void) viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
-
- // 键盘高度变化通知,ios5.0新增的
- //#ifdef __IPHONE_5_0
- // float version = [[[UIDevice currentDevice] systemVersion] floatValue];
- // if (version >= 5.0) {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];
- // }
- //#endif
-
- }
- -(void) viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
-
- //if(!self.alert.isBeingDismissed)
- //{
- //
- // [self.alert dismissViewControllerAnimated:YES completion:nil];
- // DebugLog(@"alert dismiss by viewwillDisapper %p",self.alert);
- //}
- }
- -(void)manually_refresh
- {
- return;
- //不支持手动刷新
- //
- // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
- // reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
- //
- // if ([self respondsToSelector:@selector(reload_data)])
- // [self performSelector:@selector(reload_data) withObject:nil afterDelay:1];
- // DebugLog(@"refresh!!!!!!!!");
-
- }
- -(void)reload_data
- {
-
- [self.lastedit endEditing:true];
- [self.lasttextview endEditing:true];
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
-
- [reF endRefreshing];
-
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
- [self refresh:nil discardDirty:true];
- }
- - (void)alertMessage:(NSString *)msg {
-
-
- // [RAUtils message_box:nil message:msg completion:nil] ;
-
- [RAUtils message_box:nil message:msg completion:nil];
-
- }
- -(void)dealloc
- {
-
- [self.autocompleteView removeFromSuperview];
- // [self.editorTable removeObserver:self forKeyPath:@"frame"];
-
- }
- //- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
- //{
- // // 方式1.匹配keypath
- // if ([keyPath isEqualToString:@"frame"]) {
- //
- // self.autocompleteView.frame = self.editorTable.frame;
- // }
- //
- //
- //}
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
-
-
-
- NSString *model = [UIDevice currentDevice].model;
- if ([model isEqualToString:@"iPhone"]||true) {
- [self setupEditorTable];
- }
- // else {
- // // 在键盘事件中,使用tableContainer计算frame 保证屏幕旋转后table height正确
- // if (self.tableContainer == nil) {
- // self.tableContainer = [[CommonEditorTableContainerView alloc] initWithFrame:self.editorTable.frame];
- // self.tableContainer.autoresizingMask = self.editorTable.autoresizingMask;
- // CGRect frame = self.editorTable.frame;
- // frame.origin.x = 0;
- // frame.origin.y = 0;
- // [self.view addSubview:self.tableContainer];
- // [self.view sendSubviewToBack:self.tableContainer];
- // [self.tableContainer addSubview:self.editorTable];
- // }
- // }
-
-
- NSArray* nibView = [[NSBundle mainBundle] loadNibNamed:@"CommonEditorAutoCompleteView" owner:nil options:nil];
- self.autocompleteView = [nibView firstObject];
-
- self.autocompleteView.dataSource = self;
- // [self.tableContainer addSubview:self.autocompleteView];
- [self.navigationController.view addSubview:self.autocompleteView];
- self.autocompleteView.frame = self.navigationController.view.frame;
- // self.autocompleteView.frame = self.editorTable.frame;
- // [self.editorTable addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
- self.autocompleteView.hidden = true;
-
-
- // [self.view bringSubviewToFront:self.autocompleteView];
-
- //
-
-
- // self.switchlock = [[NSLock alloc] init];
-
-
- // [self.editorTable setExclusiveTouch:false];
-
- self.editable = NO;
-
- if(self.loading_msg==nil)
- self.loading_msg = @"Please Wait";
- if(self.loading_title==nil)
- self.loading_title = @"Loading...";
-
- // UIRefreshControl *ref = [[UIRefreshControl alloc]init];
- // ref.tag = 200 ;
- // ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
- // ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- // // ref.hidden = true;
- // [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
- //
- // if(!self.disable_dropdown_refresh)
- // [self.editorTable addSubview:ref];
-
- self.level = -1;
-
- if (!self.changed_data) {
- self.changed_data = [[NSMutableDictionary alloc] init];
- }
-
- // UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
- // // closeButton.title = @"Close";
- //
- // self.navigationItem.leftBarButtonItem = closeButton;
- __weak typeof(self) weakself = self;
- if(self.url_type==URL_REMOTE)
- {
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:self.loading_title completion:nil];
- [RADataProvider request_editor:self.request_url params:self.params completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary* editor_json = result;
-
-
- #ifdef DEBUG
-
- DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
-
- #endif
-
-
-
-
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- [pop hide];
- if([[editor_json valueForKey:@"result"] intValue]==RESULT_TRUE)
- {
- NSArray* arr_menu =editor_json[@"menu"];
-
- if( arr_menu !=nil)
- {
- [self injectMenu:arr_menu];
- }
-
- weakself.content_data_download = [editor_json mutableCopy];
-
- weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
-
- // self.content_data = [editor_json mutableCopy];
- // self.content_data = [self translate_json:editor_json];
-
- // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
-
- [weakself download_success];
-
- [weakself.editorTable reloadData];
-
- // NSString * ttt=[self.content_data valueForKey:@"title"] ;
-
- weakself.navigationItem.title = [weakself.content_data_download valueForKey:@"title"] ;
- }
- else if([[editor_json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE)
- {
- [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:nil];
- }
- else
- {
- [weakself download_failed];
- [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
-
- }
- // }];
-
-
-
-
-
- }];
- // }];
-
- // self.alert = waitalert;
-
- }
- else if(self.url_type== URL_LOCAL || self.url_type==URL_FILE)
- {
-
-
- NSData* json =nil;
- if(self.url_type== URL_LOCAL)
- json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
- else
- json=[NSData dataWithContentsOfFile:self.request_url];
- NSError *error=nil;
- self.content_data_download = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
- self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
-
- self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
- [self.editorTable reloadData];
-
- // NSString * ttt=[self.content_data valueForKey:@"title"] ;
-
- // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
- }
- else
- {
-
- self.content_data_control=[self translate_json:self.content_data_download changed: self.changed_data];
- [self.editorTable reloadData];
-
- // NSString * ttt=[self.content_data valueForKey:@"title"] ;
-
- self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
- }
-
-
- self.requried = [[NSMutableDictionary alloc] init];
-
- self.cancommit = true;
-
- // 恢复编辑后重置URL Type,避免刷新Crash
- if (self.url_type == URL_RESTORE) {
- self.url_type = URL_REMOTE;
- }
- }
- -(void) injectMenu:(NSArray* ) menu
- {
-
-
- UIBarButtonItem *menuItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_more_dot"] style:UIBarButtonItemStylePlain target:self action:@selector(menuItemClick:)];
- self.injectMenu = menu;
- // // closeButton.title = @"Close";
- //
- self.navigationItem.rightBarButtonItem = menuItem;
-
- }
- - (void)menuItemClick:(id)sender {
-
- NSAssert(true, ([NSString stringWithFormat:@"%@ menuItemClick not impl",[self class_name]]));
- }
- -(NSMutableDictionary*) check_cancommit :(bool) alert
- {
- [[RAUtils keyWindow] endEditing:YES];
-
-
- // [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)];
-
-
- [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
-
- self.first_miss_pos = nil;
-
- self.cancommit=true;
- NSMutableArray* fields=[[NSMutableArray alloc] init];
- NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
- // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
- int section_count=(int)self.content_data_control.count;//[[self.content_data_download valueForKey:@"section_count"] intValue];
-
-
- // NSString* aaa = [RAUtils dict2string:self.content_data_control];
- for(int i=0;i<section_count;i++)
- {
- DebugLog(@"debug...section:%d",i);
- NSMutableArray * sectionjson = [self.content_data_control[i] mutableCopy];//[[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = (int)sectionjson.count;//[[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[sectionjson[j] mutableCopy];//[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- NSString* key = [itemjson valueForKey:@"name"];
- if(key==nil || key.length==0)
- continue;
- if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
- {
- NSString* single_select = [itemjson valueForKey:@"single_select"];
- if([single_select isEqualToString:@"true"])
- {
- NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
- int count = [[cadejson valueForKey:@"count"] intValue];
- bool setvalue = false;
- for(int cc=0;cc<count;cc++)
- {
- NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- if([[valjson valueForKey:@"check"]intValue]==1)
- {
- [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
-
- setvalue=true;
- break;
- }
- }
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
-
- }
- }
- else //multiple select
- {
- NSMutableArray* checked = [[NSMutableArray alloc] init];
- NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
- int count = [[cadejson valueForKey:@"count"] intValue];
- for(int cc=0;cc<count;cc++)
- {
- NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- if([[valjson valueForKey:@"check"]intValue]==1)
- {
-
- // [checked addObject:[NSNumber numberWithInt:[[valjson valueForKey:@"value_id"] intValue]]];
- [checked addObject:[NSString stringWithFormat:@"%@",[valjson valueForKey:@"value_id"]]];
-
-
- }
- }
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"]&&checked.count==0)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- else
- {
- NSString * string = [checked componentsJoinedByString:@","];
- [upparams setValue:string forKey:[itemjson valueForKey:@"name"]];
- }
- }
- /*
- upparams setValue:itemjson forKey:<#(NSString *)#>
-
- */
- }else
- if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
-
- }
- else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- NSString* valuestr = [itemjson valueForKey:@"value"];
- [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
- }
- else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
- {
- NSString* valuestr = [itemjson valueForKey:@"value"];
- [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
-
- NSString* value = [itemjson valueForKey:@"value"];
- NSMutableDictionary* boolitem=nil;
- NSMutableDictionary* subjson=nil;
- if([value isEqualToString:@"true"])
- {
- boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
-
- }
- else
- {
- boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
-
- }
- subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
- if( subjson!=nil /*&& !active*/)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
- if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
- [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
- else
- {
- if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[modify_item valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
- }
- }
- else if([[itemjson valueForKey:@"control"] isEqualToString:@"img"])
- {
- if([itemjson valueForKey:@"avalue"]!=nil && ![[itemjson valueForKey:@"avalue"]isEqualToString:@""])
- [upparams setValue:[itemjson valueForKey:@"avalue"] forKey:[itemjson valueForKey:@"name"]];
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
- else if([[itemjson valueForKey:@"control"] isEqualToString:@"edit"])
- {
- int min_length = [[itemjson valueForKey:@"min_length"] intValue];
- NSString* check_len_val =itemjson[@"value"];
- if( check_len_val.length<min_length && check_len_val.length!=0)
- {
- self.cancommit = false;
-
-
-
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is too short",fields.count+1,itemjson[@"aname"]];
-
-
- if(check_len_val.length==0 &&[[itemjson valueForKey:@"required"] isEqualToString: @"true"])
- mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- else if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""] )
- {
- NSString *keyboard_type = [itemjson objectForKey:@"keyboard"];
- BOOL check_max = [itemjson objectForKey:@"max_type"] != nil ? YES : NO;
- BOOL check_min = [itemjson objectForKey:@"min_type"] != nil ? YES : NO;
- if ([keyboard_type isEqualToString:@"number"] && (check_max || check_min)) {
- // 检查最大值最小值
- int max_type = [[itemjson objectForKey:@"max_type"] intValue];
- int min_type = [[itemjson objectForKey:@"min_type"] intValue];
-
- float max_value = MAXFLOAT;
- float min_value = 0;
-
- NSString *mfield = nil;
- float f_value = [check_len_val floatValue];
-
- if (check_max) {
-
- if (max_type > 0) {
- // key
- NSString *max_key = [itemjson objectForKey:@"max"];
- id max_obj = [self downloadValueForKey:max_key];
- if (max_obj) {
- max_value = [max_obj floatValue];
- }
-
- } else {
- // value
- id max_obj = [itemjson objectForKey:@"max"];
- if (max_obj != nil) {
- max_value = [max_obj floatValue];
- }
-
- }
-
- if (max_value < f_value) {
- mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not larger than %.2f",fields.count+1,itemjson[@"aname"],max_value];
- }
- }
-
- if (check_min) {
-
- if (min_type > 0) {
- // key
- NSString *min_key = [itemjson objectForKey:@"min"];
- id min_obj = [self downloadValueForKey:min_key];
- if (min_obj) {
- min_value = [min_obj floatValue];
- }
- } else {
- // value
- id min_obj = [itemjson objectForKey:@"min"];
- if (min_obj != nil) {
- min_value = [min_obj floatValue];
- }
- }
-
- if (min_value > f_value) {
- mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not smaller than %.2f",fields.count+1,itemjson[@"aname"],min_value];
- }
- }
-
-
- if (check_min && check_max) {
- if (f_value < min_value || f_value > max_value) {
- mfield =[NSString stringWithFormat:@"%ld. the value of %@ must between %.2f and %.2f",fields.count+1,itemjson[@"aname"],min_value,max_value];
- }
- }
-
- if (mfield != nil) {
- self.cancommit = false;
- [fields addObject:mfield];
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- } else {
- [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- }
-
- } else {
- [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- }
-
- }
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
- else if ([[itemjson valueForKey:@"control"] isEqualToString:@"range"])
- {
-
- if([itemjson valueForKey:@"min_value"]!=nil && ![[itemjson valueForKey:@"min_value"]isEqualToString:@""] &&[itemjson valueForKey:@"max_value"]!=nil && ![[itemjson valueForKey:@"max_value"]isEqualToString:@""])
- {
- NSMutableDictionary* valjson = [NSMutableDictionary new];
- if([itemjson valueForKey:@"min_value"]!=nil && ![[itemjson valueForKey:@"min_value"]isEqualToString:@""])
- valjson[@"min"] = itemjson[@"min_value"];
- if([itemjson valueForKey:@"max_value"]!=nil && ![[itemjson valueForKey:@"max_value"]isEqualToString:@""])
- valjson[@"max"] = itemjson[@"max_value"];
-
-
-
-
- NSString* val=[RAConvertor dict2string:valjson];
- [upparams setValue:val forKey:[itemjson valueForKey:@"name"]];
- // }
-
- }
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%lu. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
- else
- {
- if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
- [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
- // subitem_data * data=[self subitem_param:itemjson addto:upparams alert:alert];
- // upparams= data.params;
- // fields=[[fields arrayByAddingObjectsFromArray:data.missingfields] mutableCopy];
- }
- }
- if(self.cancommit==false && alert)
- {
- NSString* missfields=[fields componentsJoinedByString:@"\n"];
- NSString* msg = [NSString stringWithFormat:@"%@",missfields];
-
-
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning"
- message:msg
- preferredStyle:UIAlertControllerStyleAlert];
- [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }]];
- // [alertController addAction:[UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- // [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
- // // if (@available(iOS 10.0, *)) {
- // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
- // // } else {
- // // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=NOTIFICATIONS_ID&path=com.xxx.xxx"]];//prefs:root=服务&path=项目bundleID }
- //
- // }]];
- [self presentViewController:alertController animated:YES completion:nil];
-
-
-
- // CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
- //
- //
- //
- //
- // // Add some custom content to the alert view
- // [alertView setContainerView:[self createDemoView:msg]];
- //
- // // Modify the parameters
- //
-
-
- // [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"OK", nil]];
- // //[alertView setDelegate:self];
- //
- // // You may use a Block, rather than a delegate.
- // [alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
- // // DebugLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, (int)[alertView tag]);
- // [alertView close];
- // }];
- //
- // // [alertView setUseMotionEffects:true];
- //
- // // And launch the dialog
- //
- // [alertView sizeToFit];
- // [alertView show];
-
- // [RAUtils alert_view:msg title:@"Please complete missing fields:"];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- [self.editorTable reloadData];
-
- [self.editorTable scrollToRowAtIndexPath:self.first_miss_pos atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
- return upparams;
- }
- else
- {
- self.cancommit=true;
- //[self.editorTable reloadData];
- }
-
- return upparams;
-
- }
- - (UIView *)createDemoView:(NSString*) msg
- {
- UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
-
- // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
- // [imageView setImage:[UIImage imageNamed:@"demo"]];
-
- UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
- titleLabel.font = [UIFont boldSystemFontOfSize:20];
- titleLabel.text=@"Please complete missing fields:";
- titleLabel.numberOfLines = 0;
- titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
- // titleLabel.textAlignment = NSTextAlignmentRight;
- titleLabel.textAlignment = NSTextAlignmentCenter;
- CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
-
-
- // CGSize sizetitle = [@"Please complete missing fields:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
- //
- CGSize sizetitle = [RAUtils sizeWithFont:@"Please complete missing fields:" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
-
- //[titleLabel sizeToFit];
- // titleLabel.center.x = demoView.center.x;
- titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
- [demoView addSubview:titleLabel];
-
- UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
- lineLabel.font = [UIFont boldSystemFontOfSize:17];
- lineLabel.text=msg;
- lineLabel.numberOfLines = 0;
- lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
-
- // CGSize sizemsg = [msg sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- CGSize sizemsg = [RAUtils sizeWithFont:msg font:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
- //[lineLabel sizeToFit];
-
- [demoView addSubview:lineLabel];
- demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
- return demoView;
- }
- //- (void)willPresentAlertView:(UIAlertView *)alertView{
- //
- //
- // alertView set
- // for( UIView * view in alertView.subviews )
- //
- // { if( [view isKindOfClass:[UILabel class]] )
- //
- // { UILabel* label = (UILabel*) view;
- //
- // label.textAlignment = NSTextAlignmentLeft; }
- //
- // }
- //
- //}
- //-(bool) action_btn_passed_check:(NSDictionary* ) data;
- //{
- // if(data == nil)
- // return false;
- // int section_count=[[data valueForKey:@"section_count"] intValue];
- //
- // for(int sc=0;sc<section_count)
- //
- //}
- //-(NSString*) get_param:(NSString*)param_name content_item:(NSDictionary*)itemjson
- //{
- //
- // NSString * item_name = [itemjson valueForKey:@"name"];
- // NSDictionary* cadejson= [itemjson objectForKey:@"cadedate"];
- // int cade_count = [[cadejson valueForKey:@"count"] intValue];
- // if([item_name isEqualToString:param_name] )
- // {
- // NSString* param_val=nil;
- //
- // bool single_select =[[itemjson valueForKey:@"single_select"] boolValue];
- //
- // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
- //
- //
- // for(int cc=0;cc<cade_count;cc++)
- // {
- // NSDictionary * valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
- // if([[valjson valueForKey:@"check"] boolValue])
- // {
- // NSString * valueid=[valjson valueForKey:@"value_id"];
- // if(valueid!=nil)
- // [arr_val addObject: valueid];
- // if(single_select)
- // break;
- // }
- //
- // }
- //
- // param_val = [arr_val componentsJoinedByString:@","];
- //
- // return param_val;
- // //[self.params setValue:param_val forKey:param_name];
- //
- // }
- // else
- // {
- // for(int cc=0;cc<cade_count;cc++)
- // {
- // NSDictionary * valjson=[itemjson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
- // NSDictionary* subitems=[valjson objectForKey:@"sub_item"];
- // if(subitems==nil)
- // continue;
- // int subcount=[[subitems valueForKey:@"count"] intValue];
- // for(int sc=0;sc<subcount;sc++)
- // {
- // NSDictionary* subitem = [subitems objectForKey:[NSString stringWithFormat:@"item_%d",sc]];
- // NSString* subval=[self get_param:param_name content_item:subitem];
- // if(subval!=nil)
- // return subval;
- // }
- //
- //
- // }
- //
- //
- // }
- // return nil;
- //
- //}
- -(void) download_success
- {
- // 用于处理不同child,在成功去的数据后,需要附加的操作。
-
-
- }
- - (void)download_failed {
- // 用于不同Child 处理失败
- }
- -(NSDictionary*) get_refresh_param
- {
- NSMutableDictionary* params= [[NSMutableDictionary alloc]init];
-
- NSDictionary * param_names = [self.content_data_download objectForKey:@"up_params"];
-
- int param_count=[[param_names valueForKey:@"count"] intValue];
-
- for(int pc=0;pc<param_count;pc++)
- {
-
- NSString* param_name = [param_names valueForKey:[NSString stringWithFormat:@"val_%d",pc]];
- NSString* param_val = [self getValue:param_name];
- [self.params setValue:param_val forKey:param_name];
-
- // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- //
- // for(int i=0;i<section_count;i++)
- // {
- // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // int item_count = [[sectionjson valueForKey:@"count"] intValue];
- // for(int j=0;j<item_count;j++)
- // {
- // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- //
- // NSString * control_type = [itemjson valueForKey:@"control"];
- // // NSString * item_name = [itemjson valueForKey:@"name"];
- // if([control_type isEqualToString:@"enum"])
- // {
- // NSString* subval= [self get_param:param_name content_item:itemjson];
- // if(subval!=nil)
- // {
- // [self.params setValue:subval forKey:param_name];
- // break;
- // }
- // // if([item_name isEqualToString:param_name] )
- // // {
- // // NSString* param_val=nil;
- // //
- // // bool single_select =[[itemjson valueForKey:@"single_select"] boolValue];
- // //
- // // int cade_count = [[itemjson valueForKey:@"count"] intValue];
- // //
- // // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
- // //
- // //
- // // for(int cc=0;cc<cade_count;cc++)
- // // {
- // // NSDictionary * valjson=[itemjson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
- // // if([[valjson valueForKey:@"check"] boolValue])
- // // {
- // // [arr_val addObject: [valjson valueForKey:@"value_id"]];
- // // if(single_select)
- // // break;
- // // }
- // //
- // // }
- // //
- // // param_val = [arr_val componentsJoinedByString:@","];
- // //
- // // [self.params setValue:param_val forKey:param_name];
- // // break;
- // // }
- // // else
- // // {
- // // NSString* subval= [self get_param:param_name content_item:itemjson];
- // // if(subval!=nil)
- // // {
- // // [self.params setValue:subval forKey:param_name];
- // // break;
- // // }
- // // }
- // }
- // }
- // }
-
-
- }
- return params;
-
- // NSString* param_name=[item_json valueForKey:@"name"];
- // NSString* param_val=nil;
- //
- // bool single_select =[[item_json valueForKey:@"single_select"] boolValue];
- //
- // int cade_count = [[value valueForKey:@"count"] intValue];
- //
- // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
- //
- //
- // for(int cc=0;cc<cade_count;cc++)
- // {
- // NSDictionary * valjson=[value objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
- // if([[valjson valueForKey:@"check"] boolValue])
- // {
- // [arr_val addObject: [valjson valueForKey:@"value_id"]];
- // if(single_select)
- // break;
- // }
- //
- // }
- //
- // param_val = [arr_val componentsJoinedByString:@","];
- //
- // [self.changed_data setObject:param_val forKey:param_name];
- }
- -(NSMutableDictionary*) CopyDirty:(NSDictionary*) dirty to:(NSMutableDictionary*) to
- {
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
-
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
-
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"dirty"] isEqualToString:@"true"] && [itemjson[@"noneoverride"] boolValue]!=true)
- {
- int toindex = -1;
- for(int l=0;l<[to_sectionjson[@"count"] intValue];l++)
- {
- NSDictionary* lobject = to_sectionjson[[NSString stringWithFormat:@"item_%d",l]];
- if([[lobject[@"name"] stringValue] isEqualToString:[itemjson[@"name"]stringValue]])
- {
- toindex = l;
- break;
- }
- }
-
-
- [to_sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",toindex ]];
- }
-
- }
- [to setObject:to_sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
- return to;
- }
- //-(void) refresh:(NSString*) trigger
- //{
- // [self refresh:trigger discardDirty:false];
- //}
- -(void) refresh:(NSString*) trigger discardDirty:(bool) discardDirty
- {
-
- [self.lastedit endEditing:true];
- [self.lasttextview endEditing:true];
- if(self.url_type==URL_REMOTE)
- {
-
-
- self.params[@"refresh_trigger"]=trigger;
- __weak typeof(self) weakself = self;
-
-
- NSDictionary* refresh_params=[self get_refresh_param];
-
- NSArray* changed_key=[refresh_params allKeys];
- for(int i=0;i<changed_key.count;i++)
- {
- NSString* obj_str=[NSString stringWithFormat:@"%@",[refresh_params valueForKey:(NSString*)changed_key[i]]];
- [self.params setObject:obj_str forKey:(NSString*)changed_key[i]];
- }
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:self.loading_title completion:nil];
- [RADataProvider request_editor:self.request_url params:self.params completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary* editor_json = result;
-
-
- #ifdef DEBUG
-
- DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
-
- #endif
-
-
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- [pop hide];
- // DebugLog(@"alert dismiss by network return %p",waitalert);
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
- if(!discardDirty)
- {
- weakself.content_data_download = [weakself CopyDirty:weakself.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
- }
- else
- weakself.content_data_download = [editor_json mutableCopy];
-
- weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
-
-
- [weakself download_success];
- [weakself.editorTable reloadData];
-
- }
- else if([[editor_json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE)
- {
- [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:editor_json[@"err_msg"]];
- }
- else
- {
- [weakself download_failed];
- [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
- }
- // }];
-
-
-
-
-
-
-
- }];
-
- // }];
- // self.alert = waitalert;
-
- }
- else
- {
-
- // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
- NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
- NSError *error=nil;
- self.content_data_download = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
- [self request_fill];
-
- self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
- [self.editorTable reloadData];
-
- // NSString * ttt=[self.content_data valueForKey:@"title"] ;
-
- // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
- }
- }
- -(subitem_data*) subitem_param:(NSDictionary*) itemjson addto:(NSMutableDictionary*) upparam alert:(bool)alert
- {
-
- subitem_data * data = [[subitem_data alloc] init];
-
- NSMutableArray * fields = [[NSMutableArray alloc]init];
-
- NSString * control_type = [itemjson valueForKey:@"control"];
- bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
- if([control_type isEqual:@"enum"] && single_select)
- {
- NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
-
- int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
-
- for(int k=0;k<cade_count;k++)
- {
- NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
- int check=[[valjson valueForKey:@"check"] intValue];
-
- NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
- bool active =[[valjson valueForKey:@"active"] boolValue];
- if(check==1 && subjson!=nil && !active)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
-
- NSString* required = [addjson valueForKey:@"required"];
- NSString* key=[addjson valueForKey:@"name"];
- if(key==nil || key.length==0)
- continue;
-
- if([[addjson valueForKey:@"control"] isEqualToString:@"enum" ])
- {
- NSString* single_select = [addjson valueForKey:@"single_select"];
- if([single_select isEqualToString:@"true"])
- {
- NSDictionary* cadejson=[addjson objectForKey:@"cadedate"];
- int count = [[cadejson valueForKey:@"count"] intValue];
- bool setvalue = false;
- for(int cc=0;cc<count;cc++)
- {
- NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- if([[valjson valueForKey:@"check"]intValue]==1)
- {
- [upparam setValue:[valjson valueForKey:@"value_id"] forKey:[addjson valueForKey:@"name"]];
- setvalue=true;
- break;
- }
- }
- if([[addjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
- {
- self.cancommit = false;
-
-
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,addjson[@"aname"]];
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[addjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- else
- {
- //not support multi select for now;
- }
- }
- else if([[addjson valueForKey:@"control"] isEqualToString:@"action" ])
- {
- NSMutableDictionary * action_data = [[addjson objectForKey:@"data"] mutableCopy];
- int section_count=[[action_data valueForKey:@"section_count"] intValue];
-
-
-
-
- if([required isEqualToString: @"true"] && action_data==nil)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,addjson[@"aname"]];
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[addjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
-
- for(int i=0;i<section_count;i++)
- {
-
-
- NSMutableDictionary * sectionjson = [[action_data objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- NSString* key = [itemjson valueForKey:@"name"];
-
- if(key==nil || key.length==0)
- continue;
-
- if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
- {
- NSString* single_select = [itemjson valueForKey:@"single_select"];
- if([single_select isEqualToString:@"true"])
- {
- NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
- int count = [[cadejson valueForKey:@"count"] intValue];
- bool setvalue = false;
- for(int cc=0;cc<count;cc++)
- {
- NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- if([[valjson valueForKey:@"check"]intValue]==1)
- {
-
- [upparam setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
- setvalue=true;
- break;
- }
- }
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
-
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- else
- {
- //not support multi select for now;
- }
- /*
- upparams setValue:itemjson forKey:<#(NSString *)#>
-
- */
-
- }
- else
- {
- if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
- [upparam setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
-
- [fields addObject:mfield];
-
- NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
-
- subitem_data * data1=[self subitem_param:itemjson addto:upparam alert:alert];
- upparam= data1.params;
- fields=[[fields arrayByAddingObjectsFromArray:data1.missingfields] mutableCopy];
- // upparam= [self subitem_param:itemjson addto:upparam ];
- }
-
- }
-
- }
- else
- {
-
- if([addjson valueForKey:@"value"]!=nil && ![[addjson valueForKey:@"value"]isEqualToString:@""])
- [upparam setValue:[addjson valueForKey:@"value"] forKey:key];
- else
- {
- if([[addjson valueForKey:@"required"] isEqualToString: @"true"] )
- {
- self.cancommit = false;
- NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,addjson[@"aname"]];
-
- [fields addObject:mfield];
-
- NSIndexPath* indexpath =[self get_indexpath1:[addjson valueForKey:@"name"]];
- if(alert)
- [self unhide_section:(int)indexpath.section];
- if(fields.count==1)
- {
- self.first_miss_pos = indexpath;
-
- }
- }
- }
- }
-
- subitem_data * data2=[self subitem_param:addjson addto:upparam alert:alert];
- upparam= data2.params;
- fields=[[fields arrayByAddingObjectsFromArray:data2.missingfields] mutableCopy];
-
- //upparam=[self subitem_param:addjson addto:upparam];
- // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
- // item_count ++;
-
-
- // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
-
- }
-
- //break;
- }
-
-
-
- }
- }
-
- data.params = upparam;
- data.missingfields = fields;
- return data;
- }
- -(NSMutableArray*) add_subitem:(NSDictionary*) itemjson addto:(NSMutableArray*) sectionarr parent:(NSString*) parent
- {
- NSString * control_type = [itemjson valueForKey:@"control"];
- bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
- if([control_type isEqual:@"enum"] && single_select)
- {
- NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
-
- int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
-
- for(int k=0;k<cade_count;k++)
- {
- NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
- int check=[[valjson valueForKey:@"check"] intValue];
-
- NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
- bool active =[[valjson valueForKey:@"active"] boolValue];
- if(check==1 && subjson!=nil && !active)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
- NSString* subself=[NSString stringWithFormat:@"%@_%d_%d",parent,k,l ];
- [addjson setValue:subself forKey:@"subid"];
- [sectionarr addObject:addjson];
- [self add_subitem:addjson addto:sectionarr parent:subself];
- // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
- // item_count ++;
-
-
- // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
-
- }
- [valjson setValue:@"true" forKey:@"active"];
-
-
- [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
- //break;
- }
-
-
-
- }
- }
- else if([control_type isEqual:@"switch"])
- {
- NSString* value=[itemjson valueForKey:@"value"];
-
- NSMutableDictionary* subjson=nil;
- if([value isEqualToString:@"true"])
- subjson=[[[itemjson objectForKey:@"true"] objectForKey:@"sub_item"] mutableCopy];// [ mutableCopy];
- else
- subjson=[[[itemjson objectForKey:@"false"] objectForKey:@"sub_item"] mutableCopy];
-
-
- if( subjson!=nil /*&& !active*/)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
- NSString* subself=[NSString stringWithFormat:@"%@_%d",parent,l ];
- [addjson setValue:subself forKey:@"subid"];
- [sectionarr addObject:addjson];
- [self add_subitem:addjson addto:sectionarr parent:subself];
- // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
- // item_count ++;
-
-
- // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
-
- }
- // [valjson setValue:@"true" forKey:@"active"];
-
-
- // [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
- //break;
- }
-
- }
- return sectionarr;
- }
- -(NSMutableArray*) translate_json: (NSDictionary*) injson changed:(NSDictionary*) changed_value
- {
-
- @synchronized(self)
- {
- if(injson == nil)
- return nil;
-
- NSMutableArray * retarray= [[NSMutableArray alloc]init];
-
- int section_count=[[injson valueForKey:@"section_count"] intValue];
-
- for(int i=0;i<section_count;i++)
- {
- NSMutableArray * sectionarr= [[NSMutableArray alloc]init];
-
- NSMutableDictionary * sectionjson = [[injson objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- NSAssert(itemjson!=nil, @"Backend error, item is null section:%d item %d",i,item_count);
- [sectionarr addObject:itemjson];
- [self add_subitem:itemjson addto:sectionarr parent:[NSString stringWithFormat:@"%d_%d",i,j ]];
- // [itemjson setObject:cadedatejson forKey:@"cadedate"];
- // NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
-
- // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
-
- }
- // [sectionjson setValue:[NSString stringWithFormat:@"%d",item_count ] forKey:@"count"];
- // [retjson setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- [retarray addObject:sectionarr];
- }
-
- DebugLog(@"content control count = %ld",retarray.count);
- return retarray;
- // retjson setObject:sec forKey:<#(id<NSCopying>)#>
- // return nil;
- }
-
- }
- /*
- -(NSMutableDictionary*) translate_json: (NSDictionary*) injson
- {
- if(injson == nil)
- return nil;
-
- NSMutableDictionary * retjson= [injson mutableCopy];
-
- int section_count=[[retjson valueForKey:@"section_count"] intValue];
-
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[retjson objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- NSString * control_type = [itemjson valueForKey:@"control"];
- bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
- if([control_type isEqual:@"enum"] && single_select)
- {
- NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
-
- int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
-
- for(int k=0;k<cade_count;k++)
- {
- NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
- int check=[[valjson valueForKey:@"check"] intValue];
-
- NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
- bool active =[[valjson valueForKey:@"active"] boolValue];
- if(check==1 && subjson!=nil && !active)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
- [addjson setValue:[NSString stringWithFormat:@"%d_%d_%d",i,j,k ] forKey:@"parent"];
- [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
- item_count ++;
-
-
- // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
-
- }
- [valjson setValue:@"true" forKey:@"active"];
-
-
- [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
- //break;
- }
- if(check==0 && subjson!=nil)
- {
- int total_remove=0;
- for(int r=0;r<item_count;r++)
- {
- NSMutableDictionary * removejson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",r ]] mutableCopy];
- if(removejson==nil)
- continue;
- if([[removejson valueForKey:@"parent"] isEqualToString: [NSString stringWithFormat:@"%d_%d_%d",i,j,k ]])
- {
- [sectionjson removeObjectForKey:[NSString stringWithFormat:@"item_%d",r ]];
- total_remove++;
- // item_count--;
- // r--;
- }
- else
- {
- [sectionjson removeObjectForKey:[NSString stringWithFormat:@"item_%d",r ]];
- [sectionjson setObject:removejson forKey:[NSString stringWithFormat:@"item_%d",r-total_remove ]];
- }
-
-
- }
- [valjson setValue:@"false" forKey:@"active"];
-
-
- [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
- item_count-=total_remove;
- // remove sub item
-
- //break;
- }
-
-
- }
- [itemjson setObject:cadedatejson forKey:@"cadedate"];
- // NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
- }
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
-
- }
- [sectionjson setValue:[NSString stringWithFormat:@"%d",item_count ] forKey:@"count"];
- [retjson setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
-
- }
- return retjson;
- // retjson setObject:sec forKey:<#(id<NSCopying>)#>
- return nil;
- }*/
- //- (void)onCloseClick:(UIButton *)sender {
- // [self.navigationController dismissViewControllerAnimated:true completion:^{
- // ;
- // }];
- //}
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(void) prepareReturn:(NSMutableDictionary*) value
- {
-
- if(value==nil)
- value=[[NSMutableDictionary alloc]init];
- value[@"is_subaction"] = self.params[@"is_subaction"];
- value[@"subaction_tag"] = self.params[@"subaction_tag"];
-
- if (self.delegate && [self.delegate respondsToSelector:@selector(returnValue:indexPath:)]) {
- [self.delegate returnValue:value indexPath:self.from];
- }
- if(self.returnValue)
- self.returnValue(nil);
- }
- -(void) handle_action_return:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath action:(int) action_code
- {
- DebugLog(@"commoneditor return %ld_%ld",(long)indexPath.section,(long)indexPath.row);
- NSMutableDictionary* section_json=nil;
-
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- bool is_subaction = [value[@"is_subaction"] boolValue];
- int subaction_tag= [value[@"subaction_tag"] intValue];
- [value removeObjectForKey:@"is_subaction"];
- [value removeObjectForKey:@"subaction_tag"];
- if(is_subaction)
- {
- NSMutableDictionary* sub_action = [[item_json objectForKey:[NSString stringWithFormat:@"item_%d",subaction_tag]] mutableCopy];
- bool refresh = [[sub_action valueForKey:@"refresh"] boolValue];
- bool discardDirty = [[sub_action valueForKey:@"discard_dirty"] boolValue];
- NSString* refresh_trigger = [sub_action valueForKey:@"name"];
- NSDictionary * restore_json=[sub_action objectForKeyedSubscript:@"restore"];
-
-
-
- NSString* subid=[sub_action valueForKey:@"subid"];
-
- UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
-
- NSString* required = [sub_action valueForKey:@"required"];
- if([required isEqualToString:@"true"] && value.count==0)
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- if(value.count!=0)
- {
-
- if(action_code==ACTION_SAVE_DATA)
- {
- [sub_action setObject:value forKey:@"data"];
-
-
- if(subid==nil)
- {
- [sub_action setValue:@"true" forKey:@"dirty"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[sub_action valueForKey:@"name" ]])
- {
- // sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
- [item_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
- }
-
- }
- }
- else
- {
-
- NSAssert(true,@"not impl");
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- sub_action= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:sub_action step:2];
- [sub_action setValue:@"true" forKey:@"dirty"];
-
- [item_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
- }
- else if(action_code==ACTION_FILL_SECTION)
- {
-
- if(subid==nil)
- {
- NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int icount=[[section_json valueForKey:@"count"] intValue];
- for (int ic=0;ic<icount;ic++)
- {
- NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
-
- NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
-
- NSString* valuestr= [value valueForKey:valuefrom];
-
- if(valuestr !=nil)
- {
-
- [modify_item setValue:valuestr forKey:@"value"];
-
- [modify_item setValue:@"true" forKey:@"dirty"];
- [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
- }
- }
- }
- else
- {
-
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
- NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
- NSMutableDictionary* olditem_sub_action = [[olditem objectForKey:[NSString stringWithFormat:@"item_%d",subaction_tag]] mutableCopy];
-
- olditem_sub_action= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
-
-
- [olditem_sub_action setValue:@"true" forKey:@"dirty"];
- [olditem setObject:olditem_sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
- [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
-
-
-
- }
-
-
-
- // [section_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- }
-
- DebugLog(@"CONTENT UPDATE:%@",[RAConvertor DataTOjsonString:self.content_data_download]);
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
-
-
- if(refresh)
- {
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
-
- [self refresh:refresh_trigger discardDirty:discardDirty];
- return ;
- }
-
-
-
- // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- [self.editorTable reloadData ];
-
- }
- else
- {
-
-
-
- bool refresh = [[item_json valueForKey:@"refresh"] boolValue];
- bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
-
-
-
- NSString* subid=[item_json valueForKey:@"subid"];
-
- UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
-
- NSString* required = [item_json valueForKey:@"required"];
- if([required isEqualToString:@"true"] && value.count==0)
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- if(value.count!=0)
- {
-
- if(action_code==ACTION_SAVE_DATA)
- {
- [item_json setObject:value forKey:@"data"];
-
-
- if(subid==nil)
- {
- [item_json setValue:@"true" forKey:@"dirty"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
- }
- else
- {
-
- NSAssert(true,@"not impl");
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
- }
- else if(action_code==ACTION_FILL_SECTION)
- {
-
- if(subid==nil)
- {
- NSDictionary* jsonmap=[item_json valueForKey:@"key_map"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int icount=[[section_json valueForKey:@"count"] intValue];
- for (int ic=0;ic<icount;ic++)
- {
- NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
-
- NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
-
- NSString* valuestr= [value valueForKey:valuefrom];
-
- if(valuestr !=nil)
- {
- if([modify_item[@"control"] isEqualToString:@"enum"]&& valuefrom.length==0)
- {
- NSMutableDictionary* cadedate = modify_item[@"cadedate"];
- int ccount = [cadedate[@"count"] intValue];
- for(int jcc=0;jcc<ccount;jcc++)
- {
- NSMutableDictionary * cval=cadedate[[NSString stringWithFormat:@"val_%d",jcc]];
- cval[@"check"]=@0;
- cadedate[[NSString stringWithFormat:@"val_%d",jcc]]=cval;
- }
- modify_item[@"cadedate"]=cadedate;
- }
-
- [modify_item setValue:valuestr forKey:@"value"];
-
- [modify_item setValue:@"true" forKey:@"dirty"];
- [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
- }
- }
- }
- else
- {
-
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
- NSDictionary* jsonmap=[item_json valueForKey:@"key_map"];
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
-
- olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
-
-
- [olditem setValue:@"true" forKey:@"dirty"];
- [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
-
-
-
- }
-
-
-
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- }
-
- DebugLog(@"CONTENT UPDATE:%@",[RAConvertor DataTOjsonString:self.content_data_download]);
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
-
-
- if(refresh)
- {
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
- [self refresh:refresh_trigger discardDirty:discardDirty];
- return ;
- }
-
-
-
- // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- [self.editorTable reloadData ];
- }
- }
- -(NSString*) getValue:(NSString*)name
- {
- NSString* ret=nil;
- for(int i=0;i<self.content_data_control.count;i++)
- {
- NSMutableArray* items=(NSMutableArray*)self.content_data_control[i];
- for(int j=0;j<items.count;j++)
- {
- NSDictionary* item=items[j];
- NSString* item_name=[item valueForKey:@"name"];
- if([item_name isEqualToString:name])
- {
- NSString* control = [item valueForKey:@"control"];
-
- if([control isEqualToString:@"enum"])
- {
- NSDictionary* cadedate = [item objectForKey:@"cadedate"];
- int cc = [[cadedate valueForKey:@"count"] intValue];
- for(int l=0;l<cc;l++)
- {
- NSDictionary* val_json=[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]];
- if([[val_json valueForKey:@"check"]intValue]==1)
- return [val_json valueForKey:@"value_id"];
- }
-
- }
- else
-
- return [item valueForKey:@"value"];
- }
- }
- }
- return ret;
- }
- - (id)downloadValueForKey:(NSString *)key_name {
- __block id ret=nil;
- [self.content_data_download enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
-
- if (![key isEqualToString:@"section_count"] && [key hasPrefix:@"section_"]) {
-
- NSDictionary *section = (NSDictionary *)obj;
-
- [section enumerateKeysAndObjectsUsingBlock:^(id _Nonnull item_key, id _Nonnull item_obj, BOOL * _Nonnull stop) {
-
- if ([item_key hasPrefix:@"item_"]) {
-
- NSDictionary* item= (NSDictionary *)item_obj;
- NSString* item_name=[item valueForKey:@"name"];
- if([item_name isEqualToString:key_name])
- {
- NSString* control = [item valueForKey:@"control"];
-
- if([control isEqualToString:@"enum"])
- {
- NSDictionary* cadedate = [item objectForKey:@"cadedate"];
- int cc = [[cadedate valueForKey:@"count"] intValue];
- for(int l=0;l<cc;l++)
- {
- NSDictionary* val_json=[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]];
- if([[val_json valueForKey:@"check"]intValue]==1)
- ret = [val_json valueForKey:@"value_id"];
- }
-
- }
- else
-
- ret = [item valueForKey:@"value"];
- }
-
- }
-
- }];
-
- }
-
- }];
- return ret;
- }
- -(void) setValue:(NSString*)key value:(NSString*)val
- {
- // NSString* ret=nil;
- for(int i=0;i<self.content_data_control.count;i++)
- {
- NSMutableArray* items=(NSMutableArray*)self.content_data_control[i];
- for(int j=0;j<items.count;j++)
- {
- NSMutableDictionary* item=[items[j] mutableCopy];
- NSString* item_name=[item valueForKey:@"name"];
-
- NSUInteger ii[2] = {i,j};
- NSIndexPath * indexPath= [NSIndexPath indexPathWithIndexes:ii length:2];
- if([item_name isEqualToString:key])
- {
- NSString* control = [item valueForKey:@"control"];
-
- if([control isEqualToString:@"enum"])
- {
- NSMutableDictionary* cadedate = [[item objectForKey:@"cadedate"] mutableCopy];
- int cc = [[cadedate valueForKey:@"count"] intValue];
- for(int l=0;l<cc;l++)
- {
- NSMutableDictionary* val_json=[[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]] mutableCopy];
- if([[val_json valueForKey:@"value_id"] isEqualToString:val])
- {
- val_json[@"check"]=[NSNumber numberWithInt:1];
- }
- else
- {
- val_json[@"check"]=[NSNumber numberWithInt:0];
- }
- cadedate[[NSString stringWithFormat:@"val_%d",l]] = val_json;
-
- // return [val_json valueForKey:@"value_id"];
- }
- // item[@"cadedate"] = cadedate;
-
-
- [self setEnumValue:cadedate indexPath:indexPath];
-
- }
- else if([control isEqualToString:@"edit"])
- {
-
- [self textfieldSetValue:indexPath value:val];
- }
- }
- }
- }
- [self.editorTable reloadData ];
- // return ret;
- }
- -(void) textfieldSetValue:(NSIndexPath*) indexPath value:(NSString*) val
- {
-
- //用于会填 textfield 的值,textViewDidEndEditing 和 partial refresh 会调用。
-
-
- NSMutableDictionary* section_json=nil;
-
-
-
- val = [val stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
-
-
-
- //#ifdef DEBUG
-
- DebugLog(@"endedit %ld_%ld",indexPath.section,indexPath.row);
- DebugLog(@"endedit %@",[RAConvertor dict2string:self.content_data_control]);
-
- //#endif
-
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- NSString* subid=[item_json valueForKey:@"subid"];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSString* item_value = item_json[@"value"];
- if(item_value.length==0)
- item_value = @"";
- if(![val isEqualToString:item_value])
- {
- //值不相同才设置dirty
- [item_json setValue:@"true" forKey:@"dirty"];
- self.isdirty = true;
- }
- [item_json setValue:val forKey:@"value"];
- if([[item_json valueForKey:@"keyboard"] isEqualToString:@"number"])
- {
- float f = [ val floatValue];
- [item_json setValue:[NSString stringWithFormat:@"%.2f",f] forKey:@"value"];
-
- }
-
- // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
- bool refresh = [[item_json valueForKey:@"refresh"] boolValue];
- bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
- NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
- bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
- if(refresh)
- {
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
-
- [self refresh:refresh_trigger discardDirty:discardDirty];
-
- }
- else if(partial_refresh)
- {
- NSString* name = [item_json valueForKey:@"name"] ;
- NSString* url = [item_json valueForKey:@"data_interface"] ;
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
-
- [params setValue:val forKey:name];
-
- __weak typeof(self) weakself = self;
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{
- PopWaitAlert* pop = [RAUtils waiting_pop:self.loading_title completion:nil];
- [RADataProvider request_commoneditor_partialrefresh:params url:url completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* editor_json =result;
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- [pop hide];
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- int prcount = [[editor_json valueForKey:@"count"] intValue];
- for(int ipr=0;ipr<prcount;ipr++)
- {
- NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
- NSString* name = [pr_item valueForKey:@"name"];
- NSString* value = [pr_item valueForKey:@"value"];
-
- [weakself setValue:name value:value];
- }
-
-
- }
- else if([[editor_json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE)
- {
- [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:nil];
- }
- else
- {
- [RAUtils message_box:nil message:[editor_json valueForKey:@"err_msg"] completion:nil]; ;
-
- }
-
- // }];
-
-
-
- }];
- // }];
-
- // self.alert = waitalert;
-
- }
- self.lastedit = nil;
- self.lastedit_from=nil;
- return ;
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- NSString* control_type= [olditem valueForKey:@"control"];
- NSMutableDictionary* new_item=nil;
- [item_json setValue:@"true" forKey:@"dirty"];
- if([control_type isEqualToString:@"enum"])
- new_item= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- else if([control_type isEqualToString:@"switch"])
- new_item= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
-
- [section_json setObject:new_item forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
- bool refresh = [[item_json valueForKey:@"refresh"] boolValue];
- bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
- NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
- bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
- if(refresh)
- {
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
- [self refresh:refresh_trigger discardDirty:discardDirty];
-
- }
- else if(partial_refresh)
- {
- NSString* name = [item_json valueForKey:@"name"] ;
- NSString* url = [item_json valueForKey:@"data_interface"] ;
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
-
- [params setValue:val forKey:name];
-
- __weak typeof(self) weakself = self;
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{
- PopWaitAlert* pop = [RAUtils waiting_pop:self.loading_title completion:nil];
- [RADataProvider request_commoneditor_partialrefresh:params url:url completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* editor_json = result;
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- [pop hide];
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- int prcount = [[editor_json valueForKey:@"count"] intValue];
- for(int ipr=0;ipr<prcount;ipr++)
- {
- NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
- NSString* name = [pr_item valueForKey:@"name"];
- NSString* value = [pr_item valueForKey:@"value"];
-
- [weakself setValue:name value:value];
- }
-
- }
- else if([[editor_json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE)
- {
- [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:nil];
- }
- else
- {
- [RAUtils message_box:nil message:[editor_json valueForKey:@"err_msg"] completion:nil]; ;
- }
- // }];
-
-
-
-
- }];
- // }];
- // self.alert = waitalert;
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* editor_json = [RANetwork commoneditor_partialrefresh:params url:url];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- //
- //
- // if([[editor_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // int prcount = [[editor_json valueForKey:@"count"] intValue];
- // for(int ipr=0;ipr<prcount;ipr++)
- // {
- // NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
- // NSString* name = [pr_item valueForKey:@"name"];
- // NSString* value = [pr_item valueForKey:@"value"];
- //
- // [weakself setValue:name value:value];
- // }
- //
- // }
- // else
- // {
- // [RAUtils message_box:nil message:[editor_json valueForKey:@"err_msg"] completion:nil]; ;
- // }
- //
- //
- // });
- // });
-
-
-
- }
- self.lastedit = nil;
- self.lastedit_from=nil;
-
- return;
- }
-
-
-
-
- // return [item valueForKey:@"value"];
-
- }
- -(void) unhide_section:(int)isection
- {
-
-
- NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",isection]] mutableCopy];
- [section setValue:@"false" forKey:@"hide"];
- [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%d",isection]];
-
- }
- -(NSIndexPath*) get_indexpath1:(NSString*)name
- {
- if(self.first_miss_pos!=nil)
- return self.first_miss_pos;
- NSIndexPath* ret=nil;
- for(int i=0;i<self.content_data_control.count;i++)
- {
- NSMutableArray* items=(NSMutableArray*)self.content_data_control[i];
- for(int j=0;j<items.count;j++)
- {
- NSDictionary* item=items[j];
- NSString* item_name=[item valueForKey:@"name"];
- if([item_name isEqualToString:name])
- {
- NSUInteger ii[2] = {i,j};
- return [NSIndexPath indexPathWithIndexes:ii length:2];
- }
- }
- }
- return ret;
- }
- #pragma mark - hide section button clicked
- - (void)HideSction:(UIButton *)sender {
-
- NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)sender.tag]] mutableCopy];
- bool hide = [[section valueForKey:@"hide"]boolValue];
- if(hide)
- {
- [section setValue:@"false" forKey:@"hide"];
- [sender setTitle:@"Show" forState:UIControlStateNormal];
- }
- else{
- [section setValue:@"true" forKey:@"hide"];
- [sender setTitle:@"Hide" forState:UIControlStateNormal];
- }
-
- [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%ld",(long)sender.tag]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- // NSRange range = NSMakeRange(sender.tag, 1);
- // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
- // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
- [self.editorTable reloadData];
-
-
- }
- #pragma mark - commoneditor delegate
- -(void) returnValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
- {
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_SAVE_DATA];
- // DebugLog(@"commoneditor return %d_%d",indexPath.section,indexPath.row);
- //
- // NSMutableDictionary* section_json=nil;
- //
- // NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
- //
- //
- //
- // int refresh = [[item_json valueForKey:@"refresh"] intValue];
- //
- // NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
- //
- //
- //
- // NSString* subid=[item_json valueForKey:@"subid"];
- //
- // UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
- //
- // NSString* required = [item_json valueForKey:@"required"];
- // if([required isEqualToString:@"true"] && value==nil)
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor redColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- // else
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor clearColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- // if(value!=nil)
- // {
- // [item_json setObject:value forKey:@"data"];
- //
- //
- // if(subid==nil)
- // {
- // [item_json setValue:@"true" forKey:@"dirty"];
- // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- // int count=0;
- //
- // count=[[section_json valueForKey:@"count"] intValue];
- //
- // for(int i=0;i<count;i++)
- // {
- // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- // if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
- //
- //
- // }
- // }
- // else
- // {
- // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- // int section = [(NSString*)idarr[0] intValue];
- // int item=[(NSString*)idarr[1] intValue];
- //
- //
- // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- // item_json= [self subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- // [item_json setValue:@"true" forKey:@"dirty"];
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- //
- // }
- //
- //
- // // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
- //
- // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // }
- //
- // if(refresh)
- // {
- //
- // if(restore_json!=nil)
- // {
- // int rc=[[restore_json valueForKey:@"count"] intValue];
- // for(int ir=0;ir<rc;ir++)
- // {
- // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
- //
- //
- // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- // for(int i=0;i<section_count;i++)
- // {
- // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // int item_count = [[sectionjson valueForKey:@"count"] intValue];
- // for(int j=0;j<item_count;j++)
- // {
- // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- //
- // if([[itemjson valueForKey:@"name"] isEqualToString:name])
- // {
- // [itemjson removeObjectForKey:@"dirty"];
- // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- // }
- //
- // }
- // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- // }
- //
- //
- // }
- //
- // }
- // [self refresh] ;
- // return ;
- // }
- //
- //
- // DebugLog(@"CONTENT UPDATE:%@",[iSalesNetwork DataTOjsonString:self.content_data_download]);
- // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- //
- //
- // // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- // [self.editorTable reloadData ];
-
- }
- #pragma mark - Table view data source
- //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- //{
- // return 0;
- //}
- //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- //{
- // return 0;
- //}
- //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- //{
- // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- // return myView;
- //
- //}
- //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- //{
- // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 20, 10)];
- //// titleLabel.textColor=[UIColor whiteColor];
- //// titleLabel.backgroundColor = [UIColor clearColor];
- //// if(section==0)
- //// titleLabel.text=NSLocalizedString(@"display_items", nil);
- //// else
- //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
- //// [titleLabel sizeToFit];
- //// [myView addSubview:titleLabel];
- ////
- // return myView;
- //}
- //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- //
- // switch (section) {
- // case 0:
- // {
- // NSDictionary * section_json = [self.content_data objectForKey:@"info_section"];
- // return [section_json valueForKey:@"title"] ;
- // }
- // case 1:
- // {
- // NSDictionary * section_json = [self.content_data objectForKey:@"model_section"];
- // return [section_json valueForKey:@"title"] ;
- // }
- // default:
- // return nil;
- // }
- //
- //
- //}
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
-
- NSMutableDictionary* section_json = [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section ]];
- return [section_json valueForKey:@"title"];
-
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
-
- DebugLog(@"numberOfSectionsInTableView = %ld",self.content_data_control.count);
-
- // if(self.content_data_control.count>0)
- // return 1;
- return self.content_data_control.count;
- // int section_count =[[self.content_data valueForKey:@"section_count"] intValue];
- // return section_count;
- }
- //- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
- //{
- // DebugLog(@"canMoveRowAtIndexPath");
- //
- // if([tableView numberOfRowsInSection:indexPath.section]>1)
- // return true;
- // else
- // return false;
- //}
- //- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
- //{
- // NSMutableArray * from;
- // NSMutableArray * to ;
- // if(fromIndexPath.section==0)
- // from = self.displayfields;
- // else
- // from = self.hidefields;
- // if(toIndexPath.section==0)
- // to = self.displayfields;
- // else
- // to = self.hidefields;
- // id content=from[fromIndexPath.row];
- // [from removeObjectAtIndex:fromIndexPath.row];
- // [to insertObject:content atIndex:toIndexPath.row];
- //
- // [tableView reloadData];
- //
- //}
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- // if(self.content_data_control.count>0)
- // return 1;
-
-
-
- NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy];
- bool hide = [[sectionjson valueForKey:@"hide"]boolValue];
- if(hide)
- {
- return 0;
- // [sectionjson setValue:@"false" forKey:@"hide"];
- // [sender setTitle:@"Show" forState:UIControlStateNormal];
- }
- else{
- return ((NSMutableArray*)self.content_data_control[section]).count;
-
- // [sectionjson setValue:@"true" forKey:@"hide"];
- // [sender setTitle:@"Hide" forState:UIControlStateNormal];
- }
- // return 0;
-
- // if(section==4)
- // return 1;
- // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section ]];
- //
- // return [[section_json valueForKey:@"count" ] intValue];
-
-
-
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- if(section==0)
- return 44;
- return 33;
- }
- //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- //{
- // return 0.5;
- //}
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- {
-
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
-
- NSString* control = [item_json valueForKey:@"control"];
- NSString *model = [UIDevice currentDevice].model;
- if ([model isEqualToString:@"iPhone"]) {
- if([control isEqualToString:@"model"])
- return 140;
- else if([control isEqualToString:@"signature"])
- return 200;
- else if([control isEqualToString:@"text_view"])
- return 180;
- else if([control isEqualToString:@"img"])
- return 240;
- else if ([control isEqualToString:@"action"])
- return 44;
- else if ([control isEqualToString:@"text"])
- return 80;
- else if ([control isEqualToString:@"enum"])
- return 80;
- else if ([control isEqualToString:@"edit"])
- return 80;
- else if ([control isEqualToString:@"switch"])
- return 80;
- else if([control isEqualToString:@"multi_action"])
- {
- int count = [[item_json valueForKey:@"count"]intValue];
- if (count <= 2) {
- return 50;
- } else {
- return 100;
- }
- }
- else if ([control isEqualToString:@"webview"]) {
- id h_obj = [item_json objectForKey:@"height"];
- CGFloat height = [h_obj floatValue];
-
- if(height<44)
- height=44;
- return height;
- }
- else if ([control isEqualToString:@"banner"]) {
- return 200;
- }
- return 80;
- } else {
- if([control isEqualToString:@"model"])
- return 140;
- else if([control isEqualToString:@"signature"])
- return 140;
- else if([control isEqualToString:@"text_view"])
- return 140;
-
- else if([control isEqualToString:@"img"])
- return 123;
- return 44;
- }
-
-
- }
- //
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- bool readonly = [[self.content_data_download valueForKey:@"readonly"]boolValue];
- // int d=0;
- // if(indexPath.section==4)
- // d=0;
-
- // DebugLog(@"%d,%d",indexPath.section,indexPath.row);
- // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-
-
-
-
-
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
- NSString* control = [item_json valueForKey:@"control"];
-
- NSString* required = [item_json valueForKey:@"required"];
- NSString *CellIdentifier = @"";
-
-
-
- if([control isEqualToString:@"text_view"])
- {
- CellIdentifier = @"CommonEditorCellTextView";
- CommonEditorCellTextView * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- NSString* value =[item_json valueForKey:@"value"];
- NSString* align =[item_json valueForKey:@"align"];
-
- if([align isEqualToString:@"right"])
- cell.textview.textAlignment= NSTextAlignmentRight;
- else
- cell.textview.textAlignment =NSTextAlignmentRight;
-
- int capital =[[item_json valueForKey:@"capital"] intValue];
- switch (capital) {
- case 1:
- cell.textview.autocapitalizationType=UITextAutocapitalizationTypeWords;
- break;
- case 2:
- cell.textview.autocapitalizationType=UITextAutocapitalizationTypeSentences;
- break;
- case 3:
- cell.textview.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;
- break;
- default:
- cell.textview.autocapitalizationType=UITextAutocapitalizationTypeWords;//UITextAutocapitalizationTypeNone;
- break;
- }
-
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- {
- cell.textview.editable=NO;
- // cell.textfield.backgroundColor = [UIColor lightGrayColor];
- cell.textview.textColor= [UIColor lightGrayColor];
-
- }
- else
- {
- cell.textview.editable=YES;
- cell.textview.textColor= [UIColor blackColor];
- // cell.textfield.backgroundColor = [UIColor whiteColor];
- }
-
-
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
-
-
- cell.label_name.text=title;
-
- if([required isEqualToString:@"true"])
- {
- [cell.label_name sizeToFit];
- CGRect frame =cell.label_name.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.label_name sizeToFit];
- cell.starMark.hidden=true;
- }
-
-
- cell.textview.text = value;
- cell.textview.delegate = self;
- cell.accessoryType = UITableViewCellAccessoryNone;
-
-
-
-
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }else
- if([control isEqualToString:@"img"])
- {
- CellIdentifier = @"CommonEditorCellImg";
- CommonEditorCellImg * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.touchImageView0.contentMode = UIViewContentModeScaleAspectFit;
- cell.touchImageView1.contentMode = UIViewContentModeScaleAspectFit;
- cell.touchImageView2.contentMode = UIViewContentModeScaleAspectFit;
-
- NSString* title = [item_json valueForKey:@"aname"] ;
- NSString* value =[item_json valueForKey:@"value"];
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- {
- cell.editable=false;
- }
- else
- cell.editable=true;
- cell.labelTitle.text = title;
- cell.labelDescription.text = value;
- __weak typeof(self) weakself = self;
- cell.imgChanged = ^(NSString* url_down,NSString* url_up,int index ,NSString* url_index)
- {
- // NSMutableDictionary* editjson = [item_json mutableCopy];
- // editjson[@"img_url"]=url;
- [weakself imgIsChanged:url_down url_up:url_up indexPath:indexPath index:index url_index:url_index];
-
-
- };
-
- {
- NSString* img_url0 = [item_json valueForKey:@"img_url_0"];
- if(img_url0.length>0)
- {
- NSString* img_url_up=[item_json valueForKey:@"img_url_aname_0"];
- if(img_url_up.length==0)
- img_url_up=@"";
- cell.imgs[0]=img_url_up;
- NSString* file_name=[img_url0 lastPathComponent];
- NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url0];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
-
- cell.touchImageView0.image=img;
-
- cell.img_validate = true;
- // [cell.touchImageView setImage:img forState:UIControlStateNormal];
- }
- else
- {
- // __weak typeof(self) weakself = self;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url0]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url0];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.touchImageView0.image=img;
- cell.img_validate = true;
- }
- else
- {
- cell.touchImageView0.image=[UIImage imageNamed:@"notfound_s"];
-
- cell.img_validate = false;
- }
-
- });
- });
-
-
- }
- }
- else
- {
- cell.touchImageView0.image=[UIImage imageNamed:@"camera_s"];
- cell.imgs[0]=@"";
- }
- }
-
- {
- NSString* img_url1 = [item_json valueForKey:@"img_url_1"];
- if(img_url1.length>0)
- {
- NSString* img_url_up=[item_json valueForKey:@"img_url_aname_1"];
- if(img_url_up.length==0)
- img_url_up=@"";
-
- cell.imgs[1]=img_url_up;
- NSString* file_name=[img_url1 lastPathComponent];
- NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url1];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
-
-
- cell.touchImageView1.image=img;
-
- cell.img_validate = true;
- // [cell.touchImageView setImage:img forState:UIControlStateNormal];
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url1]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url1];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.touchImageView1.image=img;
- cell.img_validate = true;
- }
- else
- {
- cell.touchImageView1.image=[UIImage imageNamed:@"notfound_s"] ;
- cell.img_validate = false;
- }
-
- });
- });
-
-
- }
- }
- else
- {
- cell.touchImageView1.image=[UIImage imageNamed:@"camera_s"];
- cell.imgs[1]=@"";
- }
- }
- {
- NSString* img_url2 = [item_json valueForKey:@"img_url_2"];
- if(img_url2.length>0)
- {
- NSString* img_url_up=[item_json valueForKey:@"img_url_aname_2"];
- if(img_url_up.length==0)
- img_url_up=@"";
- cell.imgs[2]=img_url_up;
- NSString* file_name=[img_url2 lastPathComponent];
- NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url2];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
-
- cell.touchImageView2.image=img;
-
- cell.img_validate = true;
- // [cell.touchImageView setImage:img forState:UIControlStateNormal];
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url2]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url2];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.touchImageView2.image=img;
- cell.img_validate = true;
- }
- else
- {
- cell.touchImageView2.image=[UIImage imageNamed:@"notfound_s"] ;
- cell.img_validate = false;
- }
-
- });
- });
-
-
- }}
- else
- {
- cell.touchImageView2.image=[UIImage imageNamed:@"camera_s"];
- cell.imgs[2]=@"";
- }
- }
-
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
- }else
- if([control isEqualToString:@"edit"])
- {
- CellIdentifier = @"CommonEditorCellEdit";
- CommonEditorCellEdit * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
-
- // title =[[NSString stringWithFormat:@"<font size=\"5\" face=\"Helvetica\">%@</font>",title] mutableCopy];
- NSString* value =[item_json valueForKey:@"value"];
-
- NSString* align =[item_json valueForKey:@"align"];
-
- if([align isEqualToString:@"right"])
- cell.textfield.textAlignment= NSTextAlignmentRight;
- else
- cell.textfield.textAlignment =NSTextAlignmentLeft;
-
- int capital =[[item_json valueForKey:@"capital"] intValue];
- switch (capital) {
- case 1:
- cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeWords;
- break;
- case 2:
- cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeSentences;
- break;
- case 3:
- cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;
- break;
- default:
- cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeWords;//UITextAutocapitalizationTypeNone;
- break;
- }
-
-
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- {
-
- cell.textfield.enabled=NO;
- // cell.textfield.backgroundColor = [UIColor lightGrayColor];
- cell.textfield.textColor= [UIColor lightGrayColor];
-
- }
- else
- {
- cell.textfield.enabled=YES;
- cell.textfield.textColor= [UIColor blackColor];
- // cell.textfield.backgroundColor = [UIColor whiteColor];
- }
-
- NSString* keyboard = [item_json valueForKey:@"keyboard"];
-
- if([keyboard isEqualToString:@"number"])
- {
-
- // float f = [value floatValue];
-
- // value = [NSString stringWithFormat:@"%.2f",f];
-
-
- cell.textfield.keyboardType=UIKeyboardTypeDecimalPad;
- // cell.textfield.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
-
-
-
- }
- else if([keyboard isEqualToString:@"int"])
- {
-
- // float f = [value floatValue];
-
- // value = [NSString stringWithFormat:@"%.2f",f];
-
-
- cell.textfield.keyboardType=UIKeyboardTypeNumberPad;
- // cell.textfield.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
-
-
-
- }
- else if([keyboard isEqualToString:@"email"])
- {
- cell.textfield.keyboardType=UIKeyboardTypeEmailAddress;
- }
- else if([keyboard isEqualToString:@"phone"])
- {
- cell.textfield.keyboardType=UIKeyboardTypePhonePad;
- }
- else
- {
- cell.textfield.keyboardType=UIKeyboardTypeDefault;
- }
-
-
- // UIKIT_EXTERN NSString * const NSPlainTextDocumentType NS_AVAILABLE(10_0, 7_0);
- // UIKIT_EXTERN NSString * const NSRTFTextDocumentType NS_AVAILABLE(10_0, 7_0);
- // UIKIT_EXTERN NSString * const NSRTFDTextDocumentType NS_AVAILABLE(10_0, 7_0);
- // UIKIT_EXTERN NSString * const NSHTMLTextDocumentType NS_AVAILABLE(10_0, 7_0);
- //
-
- // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[title dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
- // UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];
- // myLabel.attributedText = attrStr;
-
- // cell.labelTitle.attributedText = attrStr;
- cell.labelTitle.text=title;
-
-
-
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
- cell.textfield.text = value;
- cell.textfield.delegate = self;
- cell.accessoryType = UITableViewCellAccessoryNone;
-
-
-
-
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
-
-
-
-
-
-
- CALayer *layer = cell.labelTitle.layer;
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
-
-
- layer = cell.starMark.layer;
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
-
-
- //UIImageView * iv =
- cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_attention_24"]];
- cell.textfield.rightViewMode=UITextFieldViewModeUnlessEditing;
- cell.textfield.layer.cornerRadius=8.0f;
- cell.textfield.layer.borderWidth= 1.0f;
- cell.textfield.layer.masksToBounds=YES;
- cell.textfield.layer.borderColor=[[UIColor redColor]CGColor];
- }
- else
- {
- CALayer *layer = cell.labelTitle.layer;//[cell.contentView layer];
-
-
-
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
-
-
- layer = cell.starMark.layer;//[cell.contentView layer];
-
-
-
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
-
-
- cell.textfield.rightViewMode=UITextFieldViewModeNever;
- //cell.textfield.layer.borderColor= [[UIColor lightGrayColor] CGColor];
- cell.textfield.rightView = nil;
- cell.textfield.layer.cornerRadius=8.0f;
- cell.textfield.layer.borderWidth= 1.0f;
- cell.textfield.layer.masksToBounds=YES;
- cell.textfield.layer.borderColor=[[UIColor lightGrayColor]CGColor];
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else
- if([control isEqualToString:@"text"])
- {
- CellIdentifier = @"CommonEditorCellLabel";
- CommonEditorCellLabel * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
-
- //CGRect titleframe = cell.labelTitle.frame;
-
- NSString* title = [item_json valueForKey:@"aname"] ;
- NSString* value =[item_json valueForKey:@"value"];
- NSString* color =[item_json valueForKey:@"color"];
- cell.labelValue.textColor = [RAUtils strColor:color];
- NSString* align =[item_json valueForKey:@"align"];
- if([align isEqualToString:@"right"])
- {
- cell.labelTitle.frame =CGRectMake(15,11,350,21);
- cell.labelValue.textAlignment= NSTextAlignmentRight;
- }
- else
- {
- cell.labelTitle.frame =CGRectMake(15,11,150,21);
- cell.labelValue.textAlignment =NSTextAlignmentLeft;
- }
-
- NSString* type=[item_json valueForKey:@"type"] ;
- // 此处应移动到erp mobile 项目内
- if([type isEqualToString:@"price"])
- {
- BOOL can_see_price = [[RASingleton.sharedInstance globalParameterForKey:@"can_see_price"] boolValue];
- BOOL price_hidden = [[RASingleton.sharedInstance globalParameterForKey:@"price_hidden"] boolValue];
-
- if(can_see_price&&price_hidden==false)
- {
-
- }
- else
- {
- value=nil;
- }
- }
-
-
-
- cell.labelTitle.text=title;
- cell.labelValue.text = value;
-
-
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else
- if([control isEqualToString:@"action"])
- {
-
-
-
- CellIdentifier = @"CommonEditorCellAction";
- CommonEditorCellAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
-
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- {
- cell.labelAction.textColor= [UIColor lightGrayColor];
-
- }
- else
- {
- cell.labelAction.textColor= [UIColor blackColor];
-
- }
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- NSString* value =[item_json valueForKey:@"value"];
- if([required isEqualToString:@"true"])
- {
- [title appendString:@"*"];
- }
- NSDictionary* data = [item_json objectForKey:@"data"];
-
- cell.labelAction.text=title;
- cell.action_code = value;
-
- //cell.labelValue.text = value;
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (data==nil))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- if([control isEqualToString:@"multi_action"])
- {
- CellIdentifier = @"CommonEditorCellMAction";
- CommonEditorCellMAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- int disabble = [[item_json objectForKey:@"disable"] intValue];
- int count = [[item_json valueForKey:@"count"]intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary* sub_action= [item_json objectForKey:[NSString stringWithFormat:@"item_%d",i]];
- NSString * title = [sub_action valueForKey:@"aname"];
- switch (i) {
- case 0:
- [cell.btn_action0 setTitle:title forState:UIControlStateNormal];
- [cell.btn_action0 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
- cell.btn_action0.hidden = NO;
- if (disabble==1 || readonly)
- cell.btn_action0.enabled =false;
- break;
- case 1:
- [cell.btn_action1 setTitle:title forState:UIControlStateNormal];
- [cell.btn_action1 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
- cell.btn_action1.hidden = NO;
- if (disabble==1 || readonly)
- cell.btn_action1.enabled =false;
- break;
- case 2:
- [cell.btn_action2 setTitle:title forState:UIControlStateNormal];
- [cell.btn_action2 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
- cell.btn_action2.hidden = NO;
- if (disabble==1 || readonly)
- cell.btn_action2.enabled =false;
- break;
- case 3:
- [cell.btn_action3 setTitle:title forState:UIControlStateNormal];
- [cell.btn_action3 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
- cell.btn_action3.hidden = NO;
- if (disabble==1 || readonly)
- cell.btn_action3.enabled =false;
- break;
- default:
- break;
- }
- }
-
- if (count<4)
- cell.btn_action3.hidden=YES;
- if (count<3)
- cell.btn_action2.hidden=YES;
- if (count<2)
- cell.btn_action1.hidden=YES;
- if (count<1)
- cell.btn_action0.hidden=YES;
-
- // NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- // NSString* value =[item_json valueForKey:@"value"];
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
- // NSDictionary* data = [item_json objectForKey:@"data"];
- //
- // cell.labelAction.text=title;
- // cell.action_code = value;
- //
- //
- // //cell.labelValue.text = value;
- //
- // if(self.cancommit==false && [required isEqualToString:@"true"] && (data==nil))
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor redColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else
- if([control isEqualToString:@"switch"])
- {
- CellIdentifier = @"CommonEditorCellSwitch";
- CommonEditorCellSwitch * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSString* title = [item_json valueForKey:@"aname"];
- NSString* value =[item_json valueForKey:@"value"];
- NSString* desc = [item_json valueForKey:@"desc"];
-
- cell.labelTitle.text=title;
- cell.labelDesc.text=desc;
-
- int disabble = [[item_json objectForKey:@"disable"] intValue];
- if (disabble==1 || readonly) {
- cell.switchCtrl.enabled = NO;
- } else {
- cell.switchCtrl.enabled = YES;
- }
-
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
-
-
- // CGSize asize=[cell.labelTitle sizeThatFits:cell.labelTitle.frame.size];
- //
- // cell.starMark.frame = CGRectMake(cell.labelTitle.frame.origin.x+asize.width, cell.labelTitle.frame.origin.y, 10, 21);
- // cell.starMark.hidden=false;
-
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
- [cell.switchCtrl addTarget:self
- action:@selector(switchIsChanged:)
- forControlEvents:UIControlEventValueChanged];
- if([[value lowercaseString] isEqualToString:@"true"])
- cell.switchCtrl.on = true;
- else
- cell.switchCtrl.on = false;
- cell.accessoryType = UITableViewCellAccessoryNone;
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
-
- }
- else if([control isEqualToString:@"editor"])
- {
- CellIdentifier = @"CommonEditorCellEditor";
- CommonEditorCellEditor * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSString* title = [[item_json valueForKey:@"aname"] stringValue];
- NSString* value = [[item_json valueForKey:@"value"] stringValue];
-
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- {
- cell.labelValue.textColor= [UIColor lightGrayColor];
-
- }
- else
- {
- cell.labelValue.textColor= [UIColor blackColor];
- // cell.textfield.backgroundColor = [UIColor whiteColor];
- }
-
-
- NSString* align =[item_json valueForKey:@"align"];
- if([align isEqualToString:@"right"])
- cell.labelValue.textAlignment= NSTextAlignmentRight;
- else
- cell.labelValue.textAlignment =NSTextAlignmentLeft;
-
- cell.labelName.text=title;
- cell.labelValue.text=value;
-
-
- // if([required isEqualToString:@"true"])
- // {
- // [cell.labelTitle sizeToFit];
- // CGRect frame =cell.labelTitle.frame;
- // frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- // cell.starMark.frame = frame;
- // cell.starMark.hidden=false;
- // // [title appendString:@"*"];
- //
- // // [title appendString:@"<font size=\"6\" >*</font>"];
- // // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- // }
- // else
- // {
- // [cell.labelTitle sizeToFit];
- // cell.starMark.hidden=true;
- // }
-
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else if([control isEqualToString:@"enum"])
- {
-
-
-
- CellIdentifier = @"CommonEditorCellEnum";
- CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- NSDictionary* cadedate_json =[item_json objectForKey:@"cadedate"];
-
- int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- {
- cell.labelValue.textColor= [UIColor lightGrayColor];
-
- }
- else
- {
- cell.labelValue.textColor= [UIColor blackColor];
- // cell.textfield.backgroundColor = [UIColor whiteColor];
- }
-
- NSString* align =[item_json valueForKey:@"align"];
- if([align isEqualToString:@"right"])
- cell.labelValue.textAlignment= NSTextAlignmentRight;
- else
- cell.labelValue.textAlignment =NSTextAlignmentLeft;
-
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
-
-
- NSString* value =@"";
- int count = [[cadedate_json valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSDictionary* val_json =[cadedate_json objectForKey:[NSString stringWithFormat:@"val_%d",i]];
- int check = [[val_json valueForKey:@"check"] intValue];
- if(check==1)
- {
- value = [value stringByAppendingString:[val_json valueForKey:@"value"]];
- value = [value stringByAppendingString:@"|"];
- }
- }
- if(value.length>=1)
- value=[value substringToIndex:value.length-1];
- cell.labelTitle.text=title;
-
-
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
- cell.labelValue.text = value;
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
- } else if([control isEqualToString:@"model"])
- {
- CommonEditorCellModel * cell= [tableView dequeueReusableCellWithIdentifier:@"CommonEditorCellModel" forIndexPath:indexPath];
-
- int count = [[item_json valueForKey:@"count"] intValue];
- NSDictionary * combine_json =[item_json objectForKey:@"combine"];
- cell.bundle_item=combine_json;
-
- NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
- if (cell.masterBtn != nil) {
- if (master_json == nil) {
- cell.masterBtn.hidden = YES;
- } else{
- cell.masterBtn.hidden = NO;
- cell.master_items = master_json;
- }
- }
-
- double dprice=0.0;
-
- if(cell.bundle_item!=nil)
- {
- int citem=0;
-
- int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
- for(int bc=0;bc<bcount;bc++)
- {
- NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
- int modulus= [[bitem valueForKey:@"modulus"] intValue];
- citem+= modulus;
- double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
- dprice+= uprice*modulus;
-
- }
- if(citem==1)
- [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
- else
- [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
-
- cell.buttonBundle.hidden = NO;
- }
- else
- {
- cell.buttonBundle.hidden = YES;
-
- }
-
- NSString *availability = [item_json objectForKey:@"quantity_available"];
- NSString *available_str = @"Available Now";
- if ([availability integerValue] > 0) {
- available_str = [NSString stringWithFormat:@"Available: %@",availability];
- } else {
- // available_str = @"Available: In Production";
- available_str = @"Available: Out of Stock";
- }
- cell.avalibilityLabel.text = available_str;
-
- NSString* img_url = [item_json valueForKey:@"img_url"];
- NSString* description = [item_json valueForKey:@"description"];
- // NSString* identifier = [item_json valueForKey:@"identifier"];
- // NSString* attribute = [item_json valueForKey:@"attribute"];
-
- // NSString* total_price = [item_json valueForKey:@"total_price"] ;
- // NSString* unit_price = [item_json valueForKey:@"unit_price"] ;
-
- // NSString* mp = [item_json valueForKey:@"stockUom"];
- double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
- int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
- int mPack =[[item_json valueForKey:@"mpack"] intValue];
- double discount =[[item_json valueForKey:@"discount"] doubleValue];
- NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
-
- NSString* oldprice =[RAConvertor currencyNumber:unitprice];//[NSString stringWithFormat:@"%.2f",unitprice];
-
- #ifdef SCANNER_ORDER
-
- if([item_json[@"is_showroom_order"] boolValue])
- {
- cell.labelBackOrder.hidden=false;
- cell.labelBackOrder.text = @"Showroom Order";
- cell.contentView.backgroundColor = UIColor.orangeColor;
- }
- else
- {
- if([item_json[@"is_back_order"] boolValue])
- {
- cell.labelBackOrder.hidden=false;
- cell.labelBackOrder.text = @"Backorder";
- cell.contentView.backgroundColor = UIColor.yellowColor;
- }
- else
- {
- cell.labelBackOrder.hidden=true;
- cell.contentView.backgroundColor = UIColor.whiteColor;
- }
- }
- #endif
- NSString* newunitprice=@"";
- if(dprice>0)
- newunitprice = [NSString stringWithFormat:@"%.2f+%.2f",unitprice* (1.0-discount/100),dprice];
- else
- newunitprice =[RAConvertor currencyNumber:unitprice* (1.0-discount/100)];// [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)];
- NSString* totalprice = [RAConvertor currencyNumber:(unitprice* (1.0-discount/100)+dprice)*count]; //[NSString stringWithFormat:@"%.2f",(unitprice* (1.0-discount/100)+dprice)*count];
-
-
-
- BOOL can_see_price = [[RASingleton.sharedInstance globalParameterForKey:@"can_see_price"] boolValue];
- BOOL price_hidden = [[RASingleton.sharedInstance globalParameterForKey:@"price_hidden"] boolValue];
-
- if(can_see_price&&price_hidden==false)
- {
-
- }
- else
- {
- oldprice=nil;
- newunitprice=nil;
- totalprice=nil;
- }
-
-
- cell.labelDiscount.text = discountstr;
- cell.labelOldPrice.text = oldprice;
- cell.labelMasterPack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
- cell.labelmPack.text =[NSString stringWithFormat:@"MPack:%d", mPack];
- #ifdef BUILD_CONTRAST
- cell.labelmPack.hidden = false;
- #endif
- bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
-
-
-
- if(isfree)
- {
- cell.labelOldPrice.hidden = false;
- cell.labelOldPrice.textColor = [UIColor redColor];
- cell.labelOldPrice.text=@"Free";
- cell.labelOldPrice.hideline = true;
-
- cell.labelDiscount.hidden = true;
- }
- else
- {
- cell.labelOldPrice.textColor = [UIColor blackColor];
- cell.labelOldPrice.hideline = false;
- if(discount==0)
- {
- cell.labelOldPrice.hidden = true;
- cell.labelDiscount.hidden = true;
-
- }
- else
- {
- cell.labelOldPrice.hidden = false;
- cell.labelDiscount.hidden = false;
- }
- }
- // if(discount==0)
- // {
- // cell.labelOldPrice.hidden = true;
- // cell.labelDiscount.hidden = true;
- //
- // }
- // else
- // {
- // cell.labelOldPrice.hidden = false;
- // cell.labelDiscount.hidden = false;
- // }
-
- // NSString* currency = [item_json valueForKey:@"currency"];
- // int count =[[item_json valueForKey:@"count"] intValue];
-
- cell.labelDescription.text = description;
- cell.labelCount.text = [NSString stringWithFormat:@"x %d",count];
- // cell.labelID.text = identifier;
- // cell.labelSubtype.text = attribute;
- cell.labelTotalPrice.text= totalprice;
- // cell.labelUnitPrice.text=unit_price;
-
- cell.labelUnitPrice.text = newunitprice;
- cell.imgModel.image = [UIImage imageNamed:@"loading_s"];
- cell.imgModel.contentMode = UIViewContentModeScaleAspectFit;
-
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
- cell.imgModel.image = img;
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.imgModel.image = img;
- }
- else
- cell.imgModel.image = [UIImage imageNamed:@"notfound_s"];
-
- });
- });
-
-
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
- }else if([control isEqualToString:@"datepicker"])
- {
-
- CellIdentifier = @"CommonEditorCellEnum";
- CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
-
- NSString* value =[item_json valueForKey:@"value"];
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
- cell.labelTitle.text=title;
-
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
- cell.labelValue.text = value;
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else if([control isEqualToString:@"monthpicker"])
- {
-
- CellIdentifier = @"CommonEditorCellEnum";
- CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
-
- NSString* value =[item_json valueForKey:@"value"];
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
- cell.labelTitle.text=title;
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
- cell.labelValue.text = value;
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
-
-
- if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else if([control isEqualToString:@"signature"])
- {
-
- CellIdentifier = @"CommonEditorCellSignature";
- CommonEditorCellSignature * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.imageviewSignature.contentMode = UIViewContentModeScaleAspectFit;
-
- NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- // if([required isEqualToString:@"true"])
- // {
- // [title appendString:@"*"];
- // }
-
- int disabble = [[item_json objectForKey:@"disable"] intValue];
- if (disabble==1 || readonly) {
- cell.imageviewSignature.userInteractionEnabled = NO;
- } else {
- cell.imageviewSignature.userInteractionEnabled = YES;
- }
-
-
- cell.labelTitle.text = title;
- if([required isEqualToString:@"true"])
- {
- [cell.labelTitle sizeToFit];
- CGRect frame =cell.labelTitle.frame;
- frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
- cell.starMark.frame = frame;
- cell.starMark.hidden=false;
- // [title appendString:@"*"];
-
- // [title appendString:@"<font size=\"6\" >*</font>"];
- // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
- }
- else
- {
- [cell.labelTitle sizeToFit];
- cell.starMark.hidden=true;
- }
-
-
- NSString* img_url = [item_json valueForKey:@"avalue"];
-
-
-
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
- cell.imageviewSignature.image=img ;
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.imageviewSignature.image=img ;
- }
- else
- cell.imageviewSignature.image=[UIImage imageNamed:@"taptosign_s"];
-
-
- });
- });
-
-
- } cell.backgroundColor = [UIColor whiteColor];
-
- return cell;
- // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
- //cell.imageviewSignature.image = image;
- }
- else if ([control isEqualToString:@"range"]) {
-
- NSString *type = [item_json objectForKey:@"type"];
- NSString *keyboard = [item_json objectForKey:@"keyboard"];
- NSString *title = [item_json objectForKey:@"aname"];
- NSString *min = [item_json objectForKey:@"min_value"];
- NSString *max = [item_json objectForKey:@"max_value"];
-
- CommonEditorRangeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorRangeCell" forIndexPath:indexPath];
- cell.indexPath = indexPath;
- cell.delegate = self;
- [cell setTitle:title];
- [cell setMinValue:min maxValue:max];
- if ([type isEqualToString:@"date"]) {
- [cell setType:CommonEditorRangeTypeDate];
- } else {
- [cell setType:CommonEditorRangeTypeDefault];
- }
- if([keyboard isEqualToString:@"number"]) {
- [cell setKeyboardType:UIKeyboardTypeDecimalPad];
- } else {
- [cell setKeyboardType:UIKeyboardTypeDefault];
- }
- return cell;
- }
- else if ([control isEqualToString:@"webview"]) {
-
- // CommonEditorWebCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorWebCell" forIndexPath:indexPath];
-
- CommonEditorWebCell * cell = [[NSBundle mainBundle] loadNibNamed:@"Phone_Web_Cell" owner:nil options:nil].firstObject;
-
- cell.webDelegate = self;
- NSString *html_str = [item_json objectForKey:@"value"];
-
-
- // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[html_str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
- //
- // cell.htmlLabel.attributedText = attrStr;
-
-
- [cell.wkwebview loadHTMLString:html_str baseURL:nil];
-
- return cell;
- }
- else if ([control isEqualToString:@"banner"]) {
- CommonEditorBannerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorBannerCell" forIndexPath:indexPath];
-
- // NSDictionary *item_json = @{
- // @"control" : @"banner",
- // @"item_4": @{
- // @"type" : @"image",
- // @"s": @"http://127.0.0.1/s2.jpg",
- // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7528.jpg"
- // },
- // @"count": @(5),
- // @"item_2": @{
- // @"type" : @"image",
- // @"s": @"http://127.0.0.1/s3.jpg",
- // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7526.jpg"
- // },
- // @"item_3": @{
- // @"type" : @"image",
- // @"s": @"http://127.0.0.1/s4.jpg",
- // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7527.jpg"
- // },
- // @"item_0": @{
- // @"type" : @"image",
- // @"s": @"http://127.0.0.1/s1.jpg",
- // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7524.jpg"
- // },
- // @"item_1": @{
- // @"type" : @"image",
- // @"s": @"http://127.0.0.1/s5.jpg",
- // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7525.jpg"
- // }
- // };
-
- [cell setContent:item_json];
- cell.delegate = self;
-
- return cell;
- }
- else
- {
- CellIdentifier = @"CommonEditorCellEdit";
- UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- }
- - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- // return [super tableview:tableView viewForHeaderInSection:section];
- NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
- if(value==nil)
- value=@"";
- unsigned long color = strtoul([value UTF8String],0,16);
-
-
- NSString* btntitle=nil ;
- NSString*labeltitle = nil;
- NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy];
-
- labeltitle= [sectionjson valueForKey:@"title"];
-
- bool hide = [[sectionjson valueForKey:@"hide"]boolValue];
- if(hide)
- {
- btntitle=@"Show";
- // [section setValue:@"false" forKey:@"hide"];
- // [sender setTitle:@"Show" forState:UIControlStateNormal];
- }
- else{
- btntitle=@"Hide";
- }
-
- DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- // myView.backgroundColor = [UIColor whiteColor];//UIColorFromRGB(0x996633);;
- myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
- myView.layer.shadowColor = [UIColor blackColor].CGColor;
- myView.layer.shadowOffset = CGSizeMake(0, 0);
- myView.layer.shadowOpacity = 0.5;
- myView.layer.shadowRadius = 2.0;
-
- int linespace=0;
- if(section==0)
- linespace=11;
-
- UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0+linespace, 50, 33)];
- btn.tag=section;
- // [btn setTitleColor:UIColorFromRGB(0x996633) forState:UIControlStateNormal];
- [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
- [btn setTitle:btntitle forState:UIControlStateNormal];
- [myView addSubview:btn];
-
-
- btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
- myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
-
-
- UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5+linespace, 200, 20)];
- titlelabel.textColor=UIColorFromRGB(color);//[UIColor whiteColor];
- titlelabel.backgroundColor = [UIColor clearColor];
- titlelabel.text=NSLocalizedString(labeltitle, nil);
- titlelabel.font = [UIFont boldSystemFontOfSize:20];
- [titlelabel sizeToFit];
- [myView addSubview:titlelabel];
- //
- // UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 0, 90, 22)];
- // contactlabel.textColor=[UIColor whiteColor];
- // contactlabel.backgroundColor = [UIColor clearColor];
- // contactlabel.text=NSLocalizedString(@"Contact", nil);
- // [contactlabel sizeToFit];
- // [myView addSubview:contactlabel];
- //
- //
- // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 0, 90, 22)];
- // modellabel.textColor=[UIColor whiteColor];
- // modellabel.backgroundColor = [UIColor clearColor];
- // modellabel.text=NSLocalizedString(@"Model", nil);
- // [modellabel sizeToFit];
- // [myView addSubview:modellabel];
- //
- // UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(500, 0, 90, 22)];
- // pricelabel.textColor=[UIColor whiteColor];
- // pricelabel.backgroundColor = [UIColor clearColor];
- // pricelabel.text=NSLocalizedString(@"Price", nil);
- // [pricelabel sizeToFit];
- // [myView addSubview:pricelabel];
- //
- //
- //
- // UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(630, 0, 90, 22)];
- // timelabel.textColor=[UIColor whiteColor];
- // timelabel.backgroundColor = [UIColor clearColor];
- // timelabel.text=NSLocalizedString(@"Create time", nil);
- // [timelabel sizeToFit];
- // [myView addSubview:timelabel];
- //
- //
- //
- // UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 60, 22)];
- // statuslabel.textColor=[UIColor whiteColor];
- // statuslabel.backgroundColor = [UIColor clearColor];
- // statuslabel.text=NSLocalizedString(@"Status", nil);
- // [statuslabel sizeToFit];
- // [myView addSubview:statuslabel];
- //
- myView.backgroundColor = UIColor.lightGrayColor;
- // UIColor * c=myView.backgroundColor;
- return myView;
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView
- {
- DebugLog(@"Did Scroll %f",scrollView.contentOffset.y);
- // CGPoint contentOffsetPoint = scrollView.contentOffset;
- CGRect f = self.autocompleteView.frame;
- CGRect rframe=[RAUtils relativeFrameForScreenWithView:self.lastedit];
- DebugLog(@"edit y %f",rframe.origin.y);
- self.autocompleteView.frame = CGRectMake(f.origin.x, rframe.origin.y+rframe.size.height, f.size.width, f.size.height);
-
- }
- //
- -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
- bool readonly = [[self.content_data_download valueForKey:@"readonly"]boolValue];
- int disable = [[item_json valueForKey:@"disable"] intValue];
-
- DebugLog(@"tableView willSelectRowAtIndexPath");
-
- //
- NSString* control = [item_json valueForKey:@"control"];
- if([control isEqualToString:@"enum"])//||[control isEqualToString:@"ui"])
- {
- // int disable = [[item_json valueForKey:@"disable"] intValue];
- if(disable==1||readonly)
- return nil;
- // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
- NSDictionary* cadedate_json = [item_json objectForKey:@"cadedate"];
- // NSDictionary* value_json = [item_json objectForKey:@"value"];
- NSString* single_select = [item_json valueForKey:@"single_select"];
- // NSString* required =[item_json valueForKey:@"required"];
- NSString* title = [item_json valueForKey:@"aname"];
-
- BOOL sort = [[item_json objectForKey:@"sort"] boolValue];
- if (sort) {
-
- EnumSelectAndSortViewController *vc = [[UIStoryboard storyboardWithName:@"EnumSelectAndSort" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectAndSortViewController"];
- vc.title = title;
- [vc setEnumDataSource:cadedate_json];
- vc.indexPath = indexPath;
- __weak typeof(self) weakSelf = self;
- vc.returnBlock = ^(NSDictionary *returnValue, NSIndexPath *idxPath) {
- [weakSelf EnumValueChanged:[returnValue mutableCopy] indexPath:idxPath];
- };
-
- [self.navigationController pushViewController:vc animated:YES];
-
- return nil;
- }
- BOOL online = [[item_json objectForKey:@"online"] boolValue];
- if (online)
- {
- int max_select = [[item_json valueForKey:@"max"] intValue];
-
- EnumSelectOnlineViewController* enumvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectOnlineViewController"];
- enumvc.delegate = self;
- enumvc.max_select = max_select;
- enumvc.updatePosition = indexPath;
- enumvc.online_params = item_json[@"params"];
- // if([[required lowercaseString] isEqualToString:@"true"])
- // enumvc.canbeEmpty = false;
- // else
- // enumvc.canbeEmpty =true;
- // enumvc.cadedate = [cadedate_json mutableCopy];
- enumvc.title = title;
- // enumvc.value = [value_json mutableCopy];
- enumvc.single_select =[[single_select lowercaseString] isEqualToString:@"true"];
-
- [self.navigationController pushViewController:enumvc animated:true];
- return nil;
- }
-
- int max_select = [[item_json valueForKey:@"max"] intValue];
-
- EnumSelectViewController* enumvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
- enumvc.delegate = self;
- enumvc.max_select = max_select;
- enumvc.updatePosition = indexPath;
- // if([[required lowercaseString] isEqualToString:@"true"])
- // enumvc.canbeEmpty = false;
- // else
- // enumvc.canbeEmpty =true;
- enumvc.cadedate = [cadedate_json mutableCopy];
- enumvc.title = title;
- // enumvc.value = [value_json mutableCopy];
- enumvc.single_select =[[single_select lowercaseString] isEqualToString:@"true"];
-
- [self.navigationController pushViewController:enumvc animated:true];
-
- }
- else if([control isEqualToString:@"editor"])
- {
- [self handle_editor_cell_select:tableView IndexPath:indexPath];
- }
- else if([control isEqualToString:@"action"])
- {
- if (disable || readonly) {
- return nil;
- }
- NSString* value = [item_json valueForKey:@"value"];
- [self commonAction:value index:indexPath data:[item_json mutableCopy]];
- }
- else if([control isEqualToString:@"datepicker"])
- {
- if (disable || readonly) {
- return nil;
- }
-
- // NSString* title = [item_json valueForKey:@"aname"];
-
- NSString* value =[item_json valueForKey:@"value"];
- NSString* type =[item_json valueForKey:@"type"];
-
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
-
-
-
- DatePickerViewController* dpvc =[ [UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"DatePickerViewController"];
- if([[type lowercaseString] isEqualToString:@"date"])
- {
- dpvc.pickerMode = UIDatePickerModeDate;
- [dateFormatter setDateFormat:@"MM/dd/yyyy"];
- }
- else if([[type lowercaseString] isEqualToString:@"time"])
- {
- dpvc.pickerMode = UIDatePickerModeTime;
- [dateFormatter setDateFormat:@"HH:mm:ss"];
- }
- else
- {
- dpvc.pickerMode = UIDatePickerModeDateAndTime;
- [dateFormatter setDateFormat:@"MM/dd/yyyy HH:mm:ss"];
- }
-
- __weak typeof(self) weakSelf = self;
-
- NSDate *date = [dateFormatter dateFromString:value];
- dpvc.date = date;
- dpvc.formatter = dateFormatter;
- dpvc.labelTime.text = value;
- dpvc.blk_Set=^(NSString *date)
- {
-
-
-
- [weakSelf DateTimeValueChanged:date indexPath:indexPath];
-
- };
- [self.navigationController pushViewController:dpvc animated:true];
-
- }else if([control isEqualToString:@"monthpicker"])
- {
- if (disable || readonly) {
- return nil;
- }
-
- // NSString* title = [item_json valueForKey:@"aname"];
-
- NSString* value =[item_json valueForKey:@"value"];
- if (value==nil || value.length==0)
- {
- NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
- formatter.dateFormat = @"MM/yyyy";
- NSDate *date = [NSDate date];
- value=[formatter stringFromDate:date];
- }
- // NSString* type =[item_json valueForKey:@"type"];
-
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
-
-
-
-
- MonthPickerViewController* mpvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"MonthPickerViewController"];
- // if([[type lowercaseString] isEqualToString:@"date"])
- // {
- // dpvc.pickerMode = UIDatePickerModeDate;
- [dateFormatter setDateFormat:@"MM/yyyy"];
- NSDate *date = [dateFormatter dateFromString:value];
-
- mpvc.current_date =date;
- mpvc.updatePosition = indexPath;
- mpvc.delegate = self;
- // }
- // else if([[type lowercaseString] isEqualToString:@"time"])
- // {
- // dpvc.pickerMode = UIDatePickerModeTime;
- // [dateFormatter setDateFormat:@"HH:mm:ss"];
- // }
- // else
- // {
- // dpvc.pickerMode = UIDatePickerModeDateAndTime;
- // [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
- // }
- // NSDate *date = [dateFormatter dateFromString:value];
- // dpvc.date = date;
- // dpvc.formatter = dateFormatter;
- // dpvc.labelTime.text = value;
- [self.navigationController pushViewController:mpvc animated:true];
-
- }
- else if([control isEqualToString:@"signature"])
- {
- // SignatureViewController * signvc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
- // signvc.title = [item_json valueForKey:@"aname"];
- // signvc.indexPath = indexPath;
- // // signvc.delegate = self;
- // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
- //
- // signvc.existSignature = cell.imageviewSignature.image ;
- //
- //
- //
- // [self.navigationController pushViewController:signvc animated:true];
-
- if (disable || readonly) {
- return nil;
- }
- __block UIImage* signimg=nil;
- SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
- __weak typeof(self) weakself = self;
- vc.onReturnImg = ^(UIImage* img)
- {
- signimg = img;
-
- if(signimg!=nil)
- {
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- #ifdef SCANNER_ORDER
- // if(RASingleton.sharedInstance.enable_OfflineOrder)
- {
-
-
-
- NSData *data = [OLDataProvider offline_saveBusinesscard:UIImageJPEGRepresentation(img,1.0f)];
-
- // 再将NSData转为字符串
- NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
-
- // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
-
- DebugLog(@"data string: %@",jsonStr);
- NSError *error=nil;
- NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
-
-
-
-
-
-
- //NSMutableArray* arr_ret = [[NSMutableArray alloc] init];
- if([[json valueForKey:@"result"] intValue]==2)
- {
- NSString* img_url_down = json[@"img_url_aname"];
- // if(img_url_down.length==0)
- // img_url_down=@"";
- NSString* img_url_up = json[@"img_url"];
- // if(img_url_up.length==0)
- // img_url_up=@"";
-
- NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
-
- [item_json setValue:img_url_down forKey:@"avalue"];
- [item_json setValue:img_url_up forKey:@"value"];
- [item_json setValue:@"true" forKey:@"dirty"];
- NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
-
- [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
-
-
- CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
-
- cell.imageviewSignature.image = signimg;
-
-
- }
- else
- {
- [RAUtils message_box:@"Upload Image" message:[json valueForKey:@"err_msg"] completion:nil]; ;
-
-
- }
- return;
- }
- #else
- #ifdef OFFLINE_MODE
- BOOL offline_mode = [[RASingleton.sharedInstance globalParameterForKey:@"offline_mode"] boolValue];
- if(offline_mode)
- {
-
-
-
- NSData *data = [OLDataProvider offline_saveBusinesscard:UIImageJPEGRepresentation(img,1.0f)];
-
- // 再将NSData转为字符串
- NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
-
- // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
-
- DebugLog(@"data string: %@",jsonStr);
- NSError *error=nil;
- NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
-
-
-
-
-
-
- //NSMutableArray* arr_ret = [[NSMutableArray alloc] init];
- if([[json valueForKey:@"result"] intValue]==2)
- {
- NSString* img_url_down = json[@"img_url_aname"];
- // if(img_url_down.length==0)
- // img_url_down=@"";
- NSString* img_url_up = json[@"img_url"];
- // if(img_url_up.length==0)
- // img_url_up=@"";
-
- NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
-
- [item_json setValue:img_url_down forKey:@"avalue"];
- [item_json setValue:img_url_up forKey:@"value"];
- [item_json setValue:@"true" forKey:@"dirty"];
- NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
-
- [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
-
-
- CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
-
- cell.imageviewSignature.image = signimg;
-
-
- }
- else
- {
- [RAUtils message_box:@"Upload Image" message:[json valueForKey:@"err_msg"] completion:nil]; ;
- }
- }
- else
- #endif
- {
- NSData *imageData = UIImagePNGRepresentation(img);
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSString *user = [RASingleton.sharedInstance globalParameterForKey:@"user"];
- NSString *password = [RASingleton.sharedInstance globalParameterForKey:@"password"];
-
- if(user!=nil)
- [params setValue:user forKey:@"user"];
- if(password!=nil)
- [params setValue:password forKey:@"password"];
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Upload Signature" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Upload Signature" completion:nil];
- [NetworkUtils upload:imageData FileName:@"test.jpg" Params:params ToHost:URL_UPLOAD_IMG Result:^(NSMutableDictionary *json) {
-
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- [pop hide];
- if([[json valueForKey:@"result"] intValue]==2)
- {
- NSString* img_url_down = json[@"img_url_aname"];
- NSString* img_url_up = json[@"img_url"];
-
- NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
-
- [item_json setValue:img_url_down forKey:@"avalue"];
- [item_json setValue:img_url_up forKey:@"value"];
- [item_json setValue:@"true" forKey:@"dirty"];
- NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
-
- [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
-
-
- CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
-
- cell.imageviewSignature.image = signimg;
-
-
- }
- else if([[json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE)
- {
- [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:nil];
- }
- else
- {
- [RAUtils message_box:@"Upload Image" message:[json valueForKey:@"err_msg"] completion:nil]; ;
- }
- // }];
-
-
- // });
-
- } Progress:nil DecryptHandler:nil];
- // }];
-
- // self.alert = waitalert;
-
-
- }
- #endif
- }
-
-
- };
-
-
- [self.navigationController pushViewController:vc animated:NO];
- }
- // else if([control isEqualToString:@"action "])
- // {
- //
- // DebugLog(@"action push");
- // // SignatureViewController * signvc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
- // // signvc.title = [item_json valueForKey:@"aname"];
- // // signvc.indexPath = indexPath;
- // // signvc.delegate = self;
- // // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
- // //
- // // signvc.existSignature = cell.imageviewSignature.image ;
- // //
- // //
- // //
- // // [self.navigationController pushViewController:signvc animated:true];
- // }
- return nil;
- }
- //- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- //{
- //
- // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
- //
- // NSString* orderid = [item_json valueForKey:@"id"];
- //
- // // if (self.delegate && [self.delegate respondsToSelector:@selector(SelectOrder:)]) {
- // // [self.delegate SelectOrder:orderid];
- // // }
- // //
- // // [self dismissViewControllerAnimated:YES
- // // completion:^{
- // // //一定要移除手势 否则下次 没有子视图的时候 点击 会崩溃拉
- // // AppDelegate *app = [[UIApplication sharedApplication] delegate];
- // // [app.window removeGestureRecognizer:self.tapGesture];
- // // }];
- // // [pvc categoryMenuSelected:indexPath.row];
- //}
- #pragma mark monthpicker ViewControllerDelegate
- -(void) MPValueChanged:(NSString *)value indexPath :(NSIndexPath*) indexPath
- {
- CommonEditorCellEnum * cell= (CommonEditorCellEnum*) [self.editorTable cellForRowAtIndexPath:indexPath];
-
- cell.labelValue.text = value;
-
-
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
-
-
- // NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
- // UITableViewCell *cell = (UITableViewCell *) paramSender.superview.superview;
- // NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
-
-
- NSMutableDictionary* section_json=nil;
-
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- // NSString* check=@"false";
- // if([paramSender isOn])
- // check=@"true";
- // [item_json setValue:value forKey:@"dirty"];
-
-
-
- NSString* subid=[item_json valueForKey:@"subid"];
- [item_json setValue:value forKey:@"value"];
-
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- NSString* control_type= [olditem valueForKey:@"control"];
- if([control_type isEqualToString:@"enum"])
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- else if([control_type isEqualToString:@"switch"])
- item_json= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- }
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- [self.editorTable reloadData ];
- }
- #pragma mark datetimeChanged
- -(void) DateTimeValueChanged:(NSString *)value indexPath :(NSIndexPath*) indexPath
- {
-
-
-
- NSMutableDictionary* section_json=nil;
-
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- bool refresh = [[item_json valueForKey:@"refresh"] boolValue];
- bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSString* subid=[item_json valueForKey:@"subid"];
-
-
- // NSArray* imgs=[RAUtils string2arr:url_up separator:@","];
-
-
- // imgs[index];
-
- item_json[@"value"]=value;
-
- [item_json setValue:@"true" forKey:@"dirty"];
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
-
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- }
-
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-
- self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
-
- // NSRange range = NSMakeRange(indexPath.section, 1);
- // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
- // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
-
-
- if(refresh)
- {
- [self refresh:refresh_trigger discardDirty:discardDirty];
- }
- [self.editorTable reloadData ];
- }
- #pragma mark EnumSelectViewControllerDelegate
- -(void) setEnumValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
- {
- NSMutableDictionary* section_json=nil;
-
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
-
-
-
- bool refresh = [[item_json valueForKey:@"refresh"] boolValue];
- bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
-
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSString* subid=[item_json valueForKey:@"subid"];
-
- [item_json setObject:value forKey:@"cadedate"];
-
-
- if(subid==nil)
- {
- [item_json setValue:@"true" forKey:@"dirty"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
-
-
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
-
-
- if(refresh)
- {
-
-
-
- if(restore_json!=nil)
- {
- int rc=[[restore_json valueForKey:@"count"] intValue];
- for(int ir=0;ir<rc;ir++)
- {
- NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
-
-
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
-
- if([[itemjson valueForKey:@"name"] isEqualToString:name])
- {
- [itemjson removeObjectForKey:@"dirty"];
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
- }
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
- }
-
-
- }
-
- }
- [self refresh:refresh_trigger discardDirty:discardDirty];
- return ;
- }
-
-
- DebugLog(@"CONTENT UPDATE:%@",[RAConvertor DataTOjsonString:self.content_data_download]);
-
-
-
- // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- [self.editorTable reloadData ];
- }
- -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
- {
-
-
- UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
-
-
- // if(/*self.cancommit==false &&*/ string.length==0 && (textField.text.length<=1|| textField.text==nil))
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor redColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- // else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
-
- DebugLog(@"enum changed %ld_%ld",(long)indexPath.section,(long)indexPath.row);
-
- [self setEnumValue:value indexPath:indexPath];
-
- }
- -(NSMutableDictionary*) enum_subitem_changed:(NSMutableDictionary *) item subid:(NSArray*) subid value:(NSMutableDictionary*)value step:(int) step
- {
- int index = [(NSString*)subid[step] intValue];
- NSMutableDictionary * cadedate= [[item objectForKey:@"cadedate"] mutableCopy];
- NSMutableDictionary * subitem= [[item objectForKey:@"sub_item"] mutableCopy];
- if(cadedate!=nil)
- {
- NSMutableDictionary * valjson=[[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",index]]mutableCopy];
- valjson= [self enum_subitem_changed:valjson subid:subid value:value step:step+1];
-
-
- [cadedate setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",index]];
- [item setObject:cadedate forKey:@"cadedate"];
- return item;
- }
- else if(subitem!=nil)
- {
- NSMutableDictionary * itemjson=[[subitem objectForKey:[NSString stringWithFormat:@"item_%d",index]] mutableCopy];
- if(step==subid.count-1)
- {
- itemjson =value;
-
- }
- else
- itemjson =[self enum_subitem_changed:itemjson subid:subid value:value step:step+1];
-
- [subitem setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",index]];
- [item setObject:subitem forKey:@"sub_item"];
- return item;
- }
- return nil;
-
- }
- //#pragma mark SignatureViewControllerDelegate
- ////-(void)SignatureVCReturnData:(NSData *)imagedata indexPath:(NSIndexPath *)indexPath
- ////{
- ////
- ////}
- //-(void)SignatureVCReturnImage:(UIImage *)image indexPath:(NSIndexPath *)indexPath
- //{
- //
- // // NSMutableDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
- // //
- // // if(image==nil)
- // // [item_json removeObjectForKey:@"signature"];
- // // else
- // // [item_json setObject:image forKey:@"signature"];
- // // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // // [self.content_data setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // //
- // //
- // //
- // // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
- // // cell.imageviewSignature.image = image;
- //}
- #pragma mark textView delegate
- //- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
- //- (BOOL)textViewShouldEndEditing:(UITextView *)textView;
- - (BOOL)textViewShouldBeginEditing:(UITextView *)textView
- {
-
- DebugLog(@"textViewShouldBeginEditing");
-
- self.editingcell = (UITableViewCell*)textView.superview.superview;
- return textView.editable;
- }
- - (void)textViewDidBeginEditing:(UITextView *)textView
- {
- self.lasttextview = textView;
-
- UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
- self.lasttextview_from = [self.editorTable indexPathForCell:cell];
-
-
-
- }
- - (void)textViewDidEndEditing:(UITextView *)textView
- {
- // UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
- NSIndexPath * indexPath = self.lasttextview_from;//[self.editorTable indexPathForCell:cell];
-
-
-
- NSMutableDictionary* section_json=nil;
-
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- NSString* subid=[item_json valueForKey:@"subid"];
-
-
- NSString* item_value = item_json[@"value"];
- if(item_value.length==0)
- item_value = @"";
- if(![textView.text isEqualToString:item_value])
- {
- //值不相同才设置dirty
- [item_json setValue:@"true" forKey:@"dirty"];
- self.isdirty = true;
- }
-
-
- // [item_json setValue:@"true" forKey:@"dirty"];
- [item_json setValue:textView.text forKey:@"value"];
-
-
- // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- NSString* control_type= [olditem valueForKey:@"control"];
- if([control_type isEqualToString:@"enum"])
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- else if([control_type isEqualToString:@"switch"])
- item_json= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- }
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
- self.lasttextview = nil;
- self.lasttextview_from=nil;
- // if(self.resize)
- // {
- // NSTimeInterval animationDuration = 0.30f;
- // CGRect frame = self.view.frame;
- // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
- // // { //还原界面
- // // moveY = prewMoveY;
- // frame.origin.y +=self.ioffset;
- // frame.size. height -=self.ioffset;
- // self.view.frame = frame;
- // // }
- // //self.view移回原位置
- // [UIView beginAnimations:@"ResizeView" context:nil];
- // [UIView setAnimationDuration:animationDuration];
- // self.view.frame = frame;
- // [UIView commitAnimations];
- // //[textField resignFirstResponder];
- // self.ioffset=0;
- // }
-
- }
- - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
- {
-
-
-
-
- UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
-
- NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
- // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
-
- NSString* required = [item_json valueForKey:@"required"];
-
- if([required isEqualToString:@"true"] && text.length==0 && (textView.text.length<=1|| textView.text==nil))
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
- else
- {
- CALayer *layer = [cell.contentView layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- }
-
- return YES;
- }
- //- (void)textViewDidChange:(UITextView *)textView;
- //
- //- (void)textViewDidChangeSelection:(UITextView *)textView;
- //
- //- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
- //- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
- #pragma mark textField delegate
- -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
-
- DebugLog(@"textField shouldChangeCharactersInRange");
- DebugLog(@"text:%@",textField.text);
-
-
-
-
-
- CommonEditorCellEdit *cell = (CommonEditorCellEdit *) textField.superview.superview;
-
- NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
- // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
-
- NSString* required = [item_json valueForKey:@"required"];
-
-
-
- if([required isEqualToString:@"true"] && string.length==0 && (textField.text.length<=1|| textField.text==nil))
- {
-
-
-
-
-
-
- CALayer *layer = cell.labelTitle.layer;
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
-
- layer = cell.starMark.layer;
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor redColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
- layer.shadowRadius = 2.0;
- //UIImageView * iv =
- cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_attention_24"]];
- cell.textfield.rightViewMode=UITextFieldViewModeUnlessEditing;
- textField.layer.cornerRadius=8.0f;
- textField.layer.borderWidth= 1.0f;
- textField.layer.masksToBounds=YES;
- textField.layer.borderColor=[[UIColor redColor]CGColor];
- }
- else
- {
- CALayer *layer = cell.labelTitle.layer;//[cell.contentView layer];
-
-
-
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 1.0;
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
-
-
- layer = cell.starMark.layer;//[cell.contentView layer];
-
-
-
- layer.shadowColor = [UIColor clearColor].CGColor;
- layer.shadowOffset = CGSizeMake(0, 0);
- layer.shadowOpacity = 1;
-
- //cell.textfield.layer.borderColor= [[UIColor lightGrayColor] CGColor];
- //UIImageView * iv =
- // cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_wish_16"]];
- cell.textfield.rightViewMode=UITextFieldViewModeNever;
- textField.layer.cornerRadius=8.0f;
- textField.layer.borderWidth= 1.0f;
- textField.layer.masksToBounds=YES;
- textField.layer.borderColor=[[UIColor lightGrayColor]CGColor];
- }
-
- //
- // if([required isEqualToString:@"true"] && string.length==0 && (textField.text.length<=1|| textField.text==nil))
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor redColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
- // else
- // {
- // CALayer *layer = [cell.contentView layer];
- // // layer.borderColor = [[UIColor redColor] CGColor];
- // // layer.borderWidth = 1.0;
- //
- // layer.shadowColor = [UIColor clearColor].CGColor;
- // layer.shadowOffset = CGSizeMake(0, 0);
- // layer.shadowOpacity = 1;
- // layer.shadowRadius = 2.0;
- // }
-
- int lenth = [[item_json valueForKey:@"length"] intValue];
-
- NSString* keyboard = [item_json valueForKey:@"keyboard"];
- if(![keyboard isEqualToString:@"number"] && ![keyboard isEqualToString:@"int"])
- {
- if(lenth==0)
- {
- if([item_json[@"autocomplete"] boolValue])
- {
-
- self.autocompleteView.hidden = false;
-
- CGRect f = self.autocompleteView.frame;
- CGRect rframe=[RAUtils relativeFrameForScreenWithView:textField];
- DebugLog(@"edit y %f",rframe.origin.y);
- self.autocompleteView.frame = CGRectMake(f.origin.x, rframe.origin.y+rframe.size.height, f.size.width, f.size.height);
- NSString *substring = [NSString stringWithString:textField.text];
- substring = [substring stringByReplacingCharactersInRange:range withString:string];
- if(substring.length>1)
- [self.autocompleteView performSearch:substring];
- else
- {
- [self.autocompleteView cancelSearch];
- }
- }
- return TRUE;
- }
- else
- {
- if([item_json[@"autocomplete"] boolValue])
- {
- self.autocompleteView.hidden = false;
-
- CGRect f = self.autocompleteView.frame;
- CGRect rframe=[RAUtils relativeFrameForScreenWithView:textField];
- DebugLog(@"edit y %f",rframe.origin.y);
- self.autocompleteView.frame = CGRectMake(f.origin.x, rframe.origin.y+rframe.size.height, f.size.width, f.size.height);
-
- NSString *substring = [NSString stringWithString:textField.text];
- substring = [substring stringByReplacingCharactersInRange:range withString:string];
- if(substring.length>1)
- [self.autocompleteView performSearch:substring];
- else
- {
- [self.autocompleteView cancelSearch];
- }
- }
- return (lenth>textField.text.length ||[string isEqualToString:@""]);
- }
- }
- NSCharacterSet *cs;
- if([keyboard isEqualToString:@"number"])
- cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
- else
- cs = [[NSCharacterSet characterSetWithCharactersInString:INTNUMBERS]invertedSet];
-
- NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
-
- BOOL canChange = [string isEqualToString:filtered];
-
-
- // if([item_json[@"autocomplete"] boolValue]==true&&canChange)
- // {
- //
- // }
-
- if(lenth==0)
- {
- if([item_json[@"autocomplete"] boolValue])
- {
- self.autocompleteView.hidden = false;
-
- CGRect f = self.autocompleteView.frame;
- CGRect rframe=[RAUtils relativeFrameForScreenWithView:textField];
- DebugLog(@"edit y %f",rframe.origin.y);
- self.autocompleteView.frame = CGRectMake(f.origin.x, rframe.origin.y+rframe.size.height, f.size.width, f.size.height);
-
- NSString *substring = [NSString stringWithString:textField.text];
- substring = [substring stringByReplacingCharactersInRange:range withString:string];
- if(substring.length>1)
- [self.autocompleteView performSearch:substring];
- else
- {
- [self.autocompleteView cancelSearch];
- }
-
- }
- return canChange;
- }
- else
- {
- if([item_json[@"autocomplete"] boolValue])
- {
- self.autocompleteView.hidden = false;
-
- CGRect f = self.autocompleteView.frame;
- CGRect rframe=[RAUtils relativeFrameForScreenWithView:textField];
- DebugLog(@"edit y %f",rframe.origin.y);
- self.autocompleteView.frame = CGRectMake(f.origin.x, rframe.origin.y+rframe.size.height, f.size.width, f.size.height);
-
- NSString *substring = [NSString stringWithString:textField.text];
- substring = [substring stringByReplacingCharactersInRange:range withString:string];
- if(substring.length>1)
- [self.autocompleteView performSearch:substring];
- else
- {
- [self.autocompleteView cancelSearch];
- // self.autocompleteView.arr_result = nil;
- // [self.autocompleteView.ResultTableView reloadData];
- }
- }
- return canChange&& (lenth>textField.text.length ||[string isEqualToString:@""]);
- }
- }
- //- (void)textFieldDidChangeSelection:(UITextField *)textField
- //{
- //
- //}
- - (void)textFieldDidEndEditing:(UITextField *)textField
- {
-
- DebugLog(@"textFieldDidEndEditing");
- // UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
- NSIndexPath * indexPath = self.lastedit_from;
-
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
- if ([item_json objectForKey:@"fill"]) {
- NSString *fillText = [item_json objectForKey:@"fill"];
-
- if (fillText && textField.text.length == 0) {
- textField.text = fillText;
- }
- }
- if([item_json[@"autocomplete"] boolValue])
- {
- self.autocompleteView.hidden = true;
- // self.autocompleteView.params = nil;
- }
- [self textfieldSetValue:indexPath value:textField.text];
-
-
-
- }
- - (void)textFieldDidBeginEditing:(UITextField *)textField
- {
- DebugLog(@"textField textFieldDidBeginEditing");
-
- self.lastedit = textField;
- UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
- self.lastedit_from = [self.editorTable indexPathForCell:cell];
-
- NSDictionary* item_json2 =((NSMutableArray*)self.content_data_control[self.lastedit_from.section])[self.lastedit_from.row];
-
- if ([item_json2 valueForKey:@"clear"]) {
- //开始编辑时清掉旧内容
- BOOL clear = [[item_json2 valueForKey:@"clear"] doubleValue] == [textField.text doubleValue];
-
- if (clear) {
- textField.text = nil;
- }
- }
-
-
-
- NSIndexPath* indexPath=[self.editorTable indexPathForCell:cell];
- // NSMutableDictionary* section_json=nil;
- NSMutableDictionary* item_json1 =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
- if([item_json1[@"autocomplete"] boolValue]==true)
- {
- int autocomplete_length =[item_json1[@"autocomplete_length"] intValue];
- if(autocomplete_length==0)
- {
- self.autocompleteView.hidden = false;
- CGRect f = self.autocompleteView.frame;
- CGRect rframe=[RAUtils relativeFrameForScreenWithView:textField];
- DebugLog(@"edit y %f",rframe.origin.y);
- self.autocompleteView.frame = CGRectMake(f.origin.x, rframe.origin.y+rframe.size.height, f.size.width, f.size.height);
-
-
- [self.autocompleteView performSearch:@""];
- }
- // return false;
- }
-
- }
- - (BOOL)textFieldShouldReturn:(UITextField *)textField
- {
- // [self searchAction];
- [textField resignFirstResponder];
- return YES;
- }
- - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
-
- self.editingcell = (UITableViewCell*)textField.superview.superview;
-
- NSIndexPath* indexPath=[self.editorTable indexPathForCell:self.editingcell];
- // NSMutableDictionary* section_json=nil;
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
- if([item_json[@"autocomplete"] boolValue]==true)
- {
- // [textField endEditing:true];
-
- // self.lastedit_from = [self.editorTable indexPathForCell:(UITableViewCell*) textField.superview.superview];
- self.autocompleteView.active_field = textField;
- // self.autocompleteView.hidden = false;
- self.autocompleteView.searchInput.keyboardType=textField.keyboardType;
- self.autocompleteView.searchInput.text= textField.text;
- // [self.autocompleteView.searchInput becomeFirstResponder];
- __weak typeof(self) weakself = self;
- NSMutableDictionary* params = [item_json[@"autocomplete_params"] mutableCopy];
- params[@"full_url"] = item_json[@"full_url"];
- params[@"url"] = item_json[@"url"];
- // int autocomplete_length =[item_json[@"autocomplete_length"] intValue];
- NSMutableDictionary* add_params = [item_json[@"autocomplete_addation_params"] mutableCopy];
- NSArray* add_key=[add_params allKeys];
- for(int i=0;i<add_key.count;i++)
- {
- NSString* key = (NSString*)add_key[i];
- NSString* val = nil;
-
- int sc = [self.content_data_download[@"section_count"] intValue];
- for(int is=0;is<sc;is++)
- {
- NSDictionary* section_json = [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)is ]];
- int icount=[[section_json valueForKey:@"count"] intValue];
- for (int ic=0;ic<icount;ic++)
- {
- NSDictionary* add_item= [section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]];
-
-
- NSString* mapto = [add_item valueForKey:@"name"];
- if([mapto isEqualToString:add_params[key]])
- {
- val = add_item[@"value"];
- params[key]=val;
- break;
- }
- }
- }
-
-
- }
-
- self.autocompleteView.params= params;
- self.autocompleteView.returnValue = ^(NSString *str) {
- //textField = true;
- // [textField endEditing:false];
- textField.text=str;
- // [textField endEditing:true];
-
- [weakself textFieldDidEndEditing:textField];
- };
-
- CGRect rframe=[RAUtils relativeFrameForScreenWithView:textField];
-
- self.autocompleteView.frame= CGRectMake(rframe.origin.x,rframe.origin.y+rframe.size.height,rframe.size.width,400);//CGRectMake(screenframe.origin.x, screenframe.origin.y, screenframe.size.width, end_y);
-
-
-
- // return false;
- }
-
- return YES;
- }
- #pragma mark- autocomplete //自动完成填空内容需要实现此协议
- -(void)sync_loadCadidate:(NSMutableDictionary*)params completionHandler:(resultHandler)result
- {
-
-
- [RADataProvider request_autocomplete:params completionHandler:result];
-
- // NSMutableArray* ret = [NSMutableArray new];
- // NSDictionary* obj = //@{@"name":@"",@"value":@"autocomplete datasource loadCadidate does not impl"};
- // [ret addObject:@"autocomplete datasource loadCadidate does not impl"];
- // return ret;
- }
- #pragma mark- img changed
- // image 改变时执行
- - (void) imgIsChanged:(NSString *)url_down url_up:(NSString *)url_up indexPath: (NSIndexPath *) indexPath index:(int)index url_index:(NSString* )url_index{
- // DebugLog(@"Sender is = %@", url);
-
-
-
-
- NSMutableDictionary* section_json=nil;
-
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- bool refresh = [[item_json valueForKey:@"refresh"] boolValue];
- bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSString* subid=[item_json valueForKey:@"subid"];
-
-
- // NSArray* imgs=[RAUtils string2arr:url_up separator:@","];
-
-
- // imgs[index];
- item_json[ [NSString stringWithFormat:@"img_url_%d",index]]=url_down;
- item_json[@"avalue"]=url_up;
- item_json[[NSString stringWithFormat:@"img_url_aname_%d",index]]=url_index;
- [item_json setValue:@"true" forKey:@"dirty"];
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
-
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- }
-
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-
- self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
-
- // NSRange range = NSMakeRange(indexPath.section, 1);
- // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
- // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
-
-
- if(refresh)
- {
- [self refresh:refresh_trigger discardDirty:discardDirty];
- }
- }
- #pragma mark- switch changed
- - (void) switchIsChanged:(UISwitch *)paramSender{
-
-
- // [self.switchlock lock];
- // DebugLog(@"switch lock");
-
-
- UITableViewCell *cell = (UITableViewCell *) paramSender.superview.superview;
- NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
- if(indexPath==nil)
- {
- [paramSender setOn:!paramSender.isOn];
- return ;
- }
-
- NSMutableDictionary* section_json=nil;
-
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- bool refresh = [[item_json valueForKey:@"refresh"] boolValue];
- bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSString* subid=[item_json valueForKey:@"subid"];
- NSString* check=@"false";
- if([paramSender isOn])
- check=@"true";
- [item_json setValue:@"true" forKey:@"dirty"];
- [item_json setValue:check forKey:@"value"];
-
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
-
- }
- else
- {
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
-
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- [item_json setValue:@"true" forKey:@"dirty"];
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
- }
-
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-
- self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
-
- NSRange range = NSMakeRange(indexPath.section, 1);
- NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
- [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
-
-
- if(refresh)
- {
- [self refresh:refresh_trigger discardDirty:discardDirty];
- }
- DebugLog(@"switch unlock");
- // [self.switchlock unlock];
- }
- -(NSMutableDictionary*) fill_switch_subitem:(NSMutableDictionary *) switch_item subid:(NSArray*) subid source:(NSMutableDictionary*)source mapping:(NSDictionary*)mapping //step:(int) step
- {
- NSString* value = [switch_item valueForKey:@"value"];
- NSMutableDictionary* boolitem=nil;
- NSMutableDictionary* subjson=nil;
- if([value isEqualToString:@"true"])
- {
- boolitem =[[switch_item objectForKey:@"true"] mutableCopy];
-
- }
- else
- {
- boolitem =[[switch_item objectForKey:@"false"] mutableCopy];
-
- }
- subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
- if( subjson!=nil /*&& !active*/)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
-
-
-
- // NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
- NSString* mapto = [modify_item valueForKey:@"name"];
- if(mapto.length==0)
- continue;
- NSString* valuefrom= [mapping valueForKey:[modify_item valueForKey:@"name"]];
- if(valuefrom==nil)
- continue;
- NSString* valuestr= [source valueForKey:valuefrom];
-
- if(TRUE)
- {
-
- if(valuestr.length>0)
- [modify_item setValue:valuestr forKey:@"value"];
- else
- [modify_item setValue:@"" forKey:@"value"];
-
- [modify_item setValue:@"true" forKey:@"dirty"];
- [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]];
- }
- }
-
- [boolitem setObject:subjson forKey:@"sub_item"];
-
- if([value isEqualToString:@"true"])
-
- [switch_item setObject:boolitem forKey:@"true"];
-
- else
- [switch_item setObject:boolitem forKey:@"false"];
-
- }
- return switch_item;
-
- }
- -(NSMutableDictionary*) fill_enum_subitem:(NSMutableDictionary *) enum_item subid:(NSArray*) subid source:(NSMutableDictionary*)source mapping:(NSDictionary*)mapping //step:(int) step
- {
- NSMutableDictionary* cadedatejson = [[enum_item objectForKey:@"cadedate"] mutableCopy];
- int count = [[cadedatejson valueForKey:@"count"]intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* val_json = [[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",i]] mutableCopy];
- int check = [[val_json valueForKey:@"check"] intValue];
- if(check==1)
- {
- NSMutableDictionary* subjson=[[val_json objectForKey:@"sub_item"] mutableCopy];
- if( subjson!=nil /*&& !active*/)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
- // NSString* subid=[modify_item valueForKey:@"subid"];
- //
- //
- // NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
-
- NSString* control_type = [modify_item valueForKey:@"control"];
- if([control_type isEqualToString:@"switch"])
- modify_item= [self fill_switch_subitem:modify_item subid:nil source:source mapping:mapping ];
- else if([control_type isEqualToString:@"enum"])
- {
- modify_item= [self fill_enum_subitem:modify_item subid:nil source:source mapping:mapping ];
-
- }
- else
- {
- NSString* mapto = [modify_item valueForKey:@"name"];
- if(mapto.length==0)
- continue;
- NSString* valuefrom= [mapping valueForKey:[modify_item valueForKey:@"name"]];
- if(valuefrom==nil)
- continue;
- NSString* valuestr= [source valueForKey:valuefrom];
-
- if(true)
- {
- if(valuestr.length>0)
- [modify_item setValue:valuestr forKey:@"value"];
- else
- [modify_item setValue:@"" forKey:@"value"];
- //[modify_item setValue:valuestr forKey:@"value"];
-
- // [modify_item setValue:@"true" forKey:@"dirty"];
-
- }
- }
-
- [modify_item setValue:@"true" forKey:@"dirty"];
- [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]];
- // [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
-
-
- // NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
-
-
- }
- [val_json setObject:subjson forKey:@"sub_item"];
- }
-
-
- }
- [cadedatejson setObject:val_json forKey:[NSString stringWithFormat:@"val_%d",i]];
-
- }
- [enum_item setObject:cadedatejson forKey:@"cadedate"];
- return enum_item;
-
- }
- -(NSMutableDictionary*) switch_subitem_changed:(NSMutableDictionary *) switch_item subid:(NSArray*) subid value:(NSMutableDictionary*)valuejson step:(int) step
- {
- int index = [(NSString*)subid[step] intValue];
- NSString* value = [switch_item valueForKey:@"value"];
-
- NSMutableDictionary* boolitem=nil;
- NSMutableDictionary* subjson=nil;
- if([value isEqualToString:@"true"])
- {
- boolitem =[[switch_item objectForKey:@"true"] mutableCopy];
-
- }
- else
- {
- boolitem =[[switch_item objectForKey:@"false"] mutableCopy];
-
- }
- subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
-
-
-
- if(subjson!=nil)
- {
- NSMutableDictionary * itemjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",index]] mutableCopy];
- if(step==subid.count-1)
- {
- itemjson =valuejson;
-
- }
- [subjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",index]];
- [boolitem setObject:subjson forKey:@"sub_item"];
-
- if([value isEqualToString:@"true"])
-
- [switch_item setObject:boolitem forKey:@"true"];
-
- else
- [switch_item setObject:boolitem forKey:@"false"];
-
-
- return switch_item;
- }
- return nil;
-
- }
- #pragma mark Request Editor
- //-(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
- //{
- // return [RANetwork request_Editor:request_url params:params];
- //}
- //
- //- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
- //{
- //
- // DebugLog(@"willDisplayCell");
- // NSString *cellclass;
- // const char *class_name_ch = object_getClassName([cell class]);
- // cellclass = [NSString stringWithUTF8String:class_name_ch];
- //
- // CommonEditorCellTextView * tvcell=nil;
- // if([cellclass isEqualToString:@"CommonEditorCellTextView"])
- // {
- // tvcell=(CommonEditorCellTextView*)self.editingcell;
- // tvcell.textview.scrollEnabled=true;
- //
- //
- // }
- //}
- //- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath
- //{
- //
- // DebugLog(@"didEndDisplayingCell");
- // NSString *cellclass;
- // const char *class_name_ch = object_getClassName([cell class]);
- // cellclass = [NSString stringWithUTF8String:class_name_ch];
- //
- // CommonEditorCellTextView * tvcell=nil;
- // if([cellclass isEqualToString:@"CommonEditorCellTextView"])
- // {
- // tvcell=(CommonEditorCellTextView*)self.editingcell;
- // tvcell.textview.scrollEnabled=false;
- //
- //
- // }
- //
- //}
- #pragma mark - Responding to keyboard events
- - (void)keyboardWillChangeFrame:(NSNotification *)notification {
- // return;
- DebugLog(@"keyboardWillChangeFrame");
-
- // 使用tableContainer计算frame 保证屏幕旋转后table height正确
- CGRect table_origin_screen_frame = [self.tableContainer convertRect:self.tableContainer.bounds toView:self.view.window];
-
- // NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
- // duration *= 0.0;
- CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
- CGFloat end_y = end.origin.y;
-
- // CGRect screenframe=[[UIScreen mainScreen] bounds];
- // CGRect controlframe= self.lastedit.frame;
- // self.autocompleteView.frame= CGRectMake(200,200,200,200);//CGRectMake(screenframe.origin.x, screenframe.origin.y, screenframe.size.width, end_y);
-
- // NSIndexPath *indexPath = [self.editorTable indexPathForCell:self.editingcell];
-
- CGRect table_frame = self.editorTable.frame;
- // table底部距离键盘顶部偏移
- CGFloat offset = CGRectGetMaxY(table_origin_screen_frame) - end_y;
- if (offset > 0) {
-
- // table -> top > offset: table.y = -offset
- // 事实上top:topLayoutGuide
- // self.additionalSafeAreaInsets
-
- float y0=self.view.safeAreaLayoutGuide.topAnchor.accessibilityActivationPoint.y;
- CGFloat topAvailableHeight = (CGRectGetMinY(table_origin_screen_frame) - y0);
- if (topAvailableHeight > 0 || true) {
- if (topAvailableHeight > offset) {
- table_frame.origin.y = -offset;
- } else {
- // 向上移动到topLayoutGuide,不足部分通过缩减高度到达keyboard顶部
- // table_frame.origin.y = -topAvailableHeight;
-
-
- // table_frame.size.height = (end_y - self.topLayoutGuide.length);
-
-
- for (NSLayoutConstraint *constraint in self.tableContainer.constraints) {
- if (constraint.firstAttribute == NSLayoutAttributeBottom) {
- // int a=0;
-
- [self.tableContainer removeConstraint:constraint];
- NSLayoutConstraint *bottom_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
- attribute:NSLayoutAttributeBottom
- relatedBy:NSLayoutRelationEqual
- toItem:self.tableContainer
- attribute:NSLayoutAttributeBottom
- multiplier:1
- constant:-end.size.height];
- self.tb_bottom_constraint = bottom_constraint;
- [self.tableContainer addConstraint:bottom_constraint];
- break;
- //
- }
- }
-
-
- }
- }
- // else {
- // // contentInset = (top = 64, left = 0, bottom = 0, right = 0),topAvailableHeight = -64
- // table_frame.size.height = table_origin_screen_frame.size.height - offset;
- // }
-
- // table_frame.size.height = CGRectGetHeight(table_origin_screen_frame) - (CGRectGetMaxY(table_origin_screen_frame) - end_y);
- } else {
- // table_frame.size.height = CGRectGetHeight(table_origin_screen_frame);
- // table_frame = self.tableContainer.bounds;
- for (NSLayoutConstraint *constraint in self.tableContainer.constraints) {
- if (constraint.firstAttribute == NSLayoutAttributeBottom) {
- // int a=0;
-
- [self.tableContainer removeConstraint:constraint];
- NSLayoutConstraint *bottom_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
- attribute:NSLayoutAttributeBottom
- relatedBy:NSLayoutRelationEqual
- toItem:self.tableContainer
- attribute:NSLayoutAttributeBottom
- multiplier:1
- constant:0];
- self.tb_bottom_constraint = bottom_constraint;
- [self.tableContainer addConstraint:bottom_constraint];
- break;
- //
- }
- }
- }
-
- self.editorTable.frame = table_frame;
-
- CGRect cell_screen_frame = [self.editingcell convertRect:self.editingcell.bounds toView:self.view.window];
- int cover =CGRectGetMaxY(cell_screen_frame) - end_y;
- if (cover>0) {
- // Cell 被键盘遮挡后才滚动
- DebugLog(@"scrollToRowAtIndexPath");
- NSString *cellclass;
- const char *class_name_ch = object_getClassName([self.editingcell class]);
- cellclass = [NSString stringWithUTF8String:class_name_ch];
-
- // CommonEditorCellTextView * tvcell=nil;
- // if([cellclass isEqualToString:@"CommonEditorCellTextView"])
- {
- // tvcell=(CommonEditorCellTextView*)self.editingcell;
- // tvcell.textview.scrollEnabled=false;
- CGPoint current_offset=self.editorTable.contentOffset;
-
- DebugLog(@"OFFSET %f",current_offset.y);
- CGPoint moveto= CGPointMake(self.editingcell.frame.origin.x,current_offset.y+cover);
- [self.editorTable setContentOffset:moveto];
- }
-
-
- ;
-
- // self.editorTable cell
- // self.editorTable scrollto
- // self.editorTable scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition) animated:<#(BOOL)#>
-
- // CGPoint current_offset=self.editorTable.contentOffset;
- //
- // DebugLog(@"OFFSET %f",current_offset.y);
- // CGPoint moveto= CGPointMake(self.editingcell.frame.origin.x,current_offset.y+cover);
- // [self.editorTable setContentOffset:self.editingcell.frame.origin];
- // [self.editorTable scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:NO];
- //
- }
- // ===============================================
- if (end_y >= [UIScreen mainScreen].bounds.size.height) {
- self.keyboard_show = NO;
- } else {
- self.keyboard_show = YES;
- }
-
- }
- - (void)keyboardDidChangeFrame:(NSNotification *)notification {
- DebugLog(@"keyboardDidChangeFrame");
- // NSString *cellclass;
- // const char *class_name_ch = object_getClassName([self.editingcell class]);
- // cellclass = [NSString stringWithUTF8String:class_name_ch];
- //
- // CommonEditorCellTextView * tvcell=nil;
- // if([cellclass isEqualToString:@"CommonEditorCellTextView"])
- // {
- //
- // tvcell=(CommonEditorCellTextView*)self.editingcell;
- // tvcell.textview.scrollEnabled=true;
- //
- //
- // }
- return;
- // // 使用tableContainer计算frame 保证屏幕旋转后table height正确
- // // CGRect table_origin_screen_frame = [self.tableContainer convertRect:self.tableContainer.bounds toView:self.view.window];
- //
- // CGRect screen_rect = [RAUtils relativeFrameForScreenWithView:self.editorTable];
- // //
- // // // NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
- // // // duration *= 0.0;
- // CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
- //// CGRect begin = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
- // float kbheight = end.size.height;
- // CGFloat keyboard_top = end.origin.y;
- // DebugLog(@"keyboard rect: %@",NSStringFromCGRect(end));
- //
- // DebugLog(@"view rect: %@",NSStringFromCGRect(self.view.frame));
- // DebugLog(@"view screen rect: %@",NSStringFromCGRect(screen_rect));
- //
- // // self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
- //
- // float dark = screen_rect.origin.y+screen_rect.size.height-keyboard_top;
- //
- // if(dark>0)
- // {
- //// self.editorTable.scrollEnabled = true;
- //// self.editorTable.contentSize = CGSizeMake(self.editorTable.frame.size.width, self.editorTable.frame.size.height+dark);
- //
- // self.editorTable.contentSize=CGSizeMake(self.editorTable.contentSize.width, self.editorTable.contentSize.height+kbheight);
- //
- // }
- // else
- // {
- //// self.editorTable.scrollEnabled = false;
- //// self.editorTable.contentSize = self.editorTable.frame.size;
- // self.editorTable.contentSize=CGSizeMake(self.editorTable.contentSize.width, self.editorTable.contentSize.height-kbheight);
- //
- // }
- }
- //static float table_origin_h = 0;
- //
- //- (void)keyboardWillShow:(NSNotification *)notification {
- // DebugLog(@"keyboardWillShow");
- ////
- //// if(self.keyboard_show)
- //// return;
- ////
- //// self.keyboard_show=true;
- //// /*
- //// Reduce the size of the text view so that it's not obscured by the keyboard.
- //// Animate the resize so that it's in sync with the appearance of the keyboard.
- //// */
- ////
- //// NSDictionary *userInfo = [notification userInfo];
- ////
- //// // Get the origin of the keyboard when it's displayed.
- //// NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
- ////
- //// // Get the top of the keyboard as the y coordinate of its origin in self's view's coordinate system. The bottom of the text view's frame should align with the top of the keyboard's final position.
- //// // CGRect keyboardRect = [aValue CGRectValue];
- //// CGSize keyboardSize = [aValue CGRectValue].size;
- //// DebugLog(@"keyboard height:%f",keyboardSize.height);
- //// // Get the duration of the animation.
- //// NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
- //// NSTimeInterval animationDuration;
- //// [animationDurationValue getValue:&animationDuration];
- ////
- ////
- //// // if(self.keyboard_h==0)
- //// // {
- //// self.keyboard_h =keyboardSize.height;
- //// CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:self.editingcell];
- //// CGRect rect_screen = [ UIScreen mainScreen ].bounds;
- ////
- //// // int vpos =self.view.frame.origin.y+self.view.frame.size.height;
- //// // int loginpos = self.editingcell.frame.origin.y+self.editingcell.frame.size.height;
- //// //
- //// int cellpos = cellrect_screen.origin.y+cellrect_screen.size.height;
- //// // screen.size.height-keyboardSize.height-(cellpos_screen.origin.x+cellpos_screen.size.height);
- //// self.ioffset = cellpos-(rect_screen.size.height-keyboardSize.height);//rect_screen.size.height-keyboardSize.height-(rect_screen.origin.y+rect_screen.size.height);//keyboardSize.height -(self.view.frame.size.height-loginpos);
- //// if(self.ioffset>0)
- //// {
- //// // self.resize = true;
- ////
- ////
- //// CGPoint contentOffsetPoint = self.editorTable.contentOffset;
- ////
- ////
- //// contentOffsetPoint.y+=self.ioffset;
- ////
- //// self.editorTable.contentOffset=contentOffsetPoint;
- ////
- ////
- //// // NSTimeInterval animationDuration = 0.30f;
- //// // CGRect frame = self.view.frame;
- //// // frame.origin.y -=self.ioffset;//view的Y轴上移
- //// // frame.size.height +=self.ioffset; //View的高度增加
- //// // self.view.frame = frame;
- //// // [UIView beginAnimations:@"ResizeView" context:nil];
- //// // [UIView setAnimationDuration:animationDuration];
- //// // self.view.frame = frame;
- //// // [UIView commitAnimations];//设置调整界面的动画效果
- //// }
- ////
- //// table_origin_h = self.editorTable.frame.size.height;
- //// self.editorTable.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, self.editorTable.frame.size.height-self.keyboard_h);
- ////
- //// // CGSize tablecontent =self.editorTable.contentSize;
- //// // tablecontent.height=tablecontent.height+self.keyboard_h;
- //// // self.editorTable.contentSize=tablecontent;
- //// // }
- //// // Animate the resize of the text view's frame in sync with the keyboard's appearance.
- //// // [self moveInputBarWithKeyboardHeight:keyboardRect.size.height withDuration:animationDuration];
- //}
- //- (void)keyboardWillHide:(NSNotification *)notification {
- // DebugLog(@"keyboardWillHide");
- //
- //// self.keyboard_show=false;
- //// NSDictionary* userInfo = [notification userInfo];
- ////
- //// /*
- //// Restore the size of the text view (fill self's view).
- //// Animate the resize so that it's in sync with the disappearance of the keyboard.
- //// */
- //// NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
- //// NSTimeInterval animationDuration;
- //// [animationDurationValue getValue:&animationDuration];
- //// CGSize tablecontent =self.editorTable.contentSize;
- //// tablecontent.height=tablecontent.height-self.keyboard_h;
- //// // self.editorTable.contentSize=tablecontent;
- ////
- //// self.editorTable.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, table_origin_h);
- ////
- //// self.keyboard_h= 0;
- //// DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
- ////
- ////
- //// // if(self.resize)
- //// // {
- //// // NSTimeInterval animationDuration = 0.30f;
- //// // CGRect frame = self.view.frame;
- //// // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
- //// // // { //还原界面
- //// // // moveY = prewMoveY;
- //// // frame.origin.y +=self.ioffset;
- //// // frame.size. height -=self.ioffset;
- //// // self.view.frame = frame;
- //// // // }
- //// // //self.view移回原位置
- //// // [UIView beginAnimations:@"ResizeView" context:nil];
- //// // [UIView setAnimationDuration:animationDuration];
- //// // self.view.frame = frame;
- //// // [UIView commitAnimations];
- //// // //[textField resignFirstResponder];
- //// // self.ioffset=0;
- //// // }
- ////
- ////
- //// // [self moveInputBarWithKeyboardHeight:0.0 withDuration:animationDuration];
- //}
- #pragma mark - RageCell Delegate
- - (void)commonEditorRangeCell:(CommonEditorRangeCell *)cell didChangeMinValue:(NSString *)minValue maxValue:(NSString *)maxValue atIndexPath:(NSIndexPath *)indexPath{
- if (indexPath == nil) {
- if (cell != nil) {
- indexPath = [self.editorTable indexPathForCell:cell];
- } else {
- return;
- }
-
- }
-
- if (indexPath == nil) {
- return;
- }
- NSString *section_key = [NSString stringWithFormat:@"section_%ld",indexPath.section];
- NSString *item_key = [NSString stringWithFormat:@"item_%ld",indexPath.row];
-
- NSMutableDictionary *section_json = [[self.content_data_download objectForKey:section_key] mutableCopy];
- NSMutableDictionary *item_json = [((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- [item_json setObject:minValue forKey:@"min_value"];
- [item_json setObject:maxValue forKey:@"max_value"];
-
- [section_json setObject:item_json forKey:item_key];
- [self.content_data_download setObject:section_json forKey:section_key];
- self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
-
- }
- #pragma mark - WebCell Delegate
- - (void)commonEditorWebCell:(CommonEditorWebCell *)cell didChangeContentHeight:(CGFloat)contentHeight {
-
- // return;
-
- NSIndexPath *indexPath = [self.editorTable indexPathForCell:cell];
- if (indexPath == nil) {
- return;
- }
-
-
- NSMutableDictionary* section_json=nil;
-
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
- NSString* subid=[item_json valueForKey:@"subid"];
-
- NSString* control = [item_json valueForKey:@"control"];
- id height_obj = [item_json objectForKey:@"height"];
-
- // DebugLog(@"indexPath: %@ origin height: %@ currentHeight: %f",indexPath,height_obj,contentHeight);
-
- if ([control isEqualToString:@"webview"] && [height_obj floatValue] != contentHeight)
- {
- [item_json setValue:@(contentHeight) forKey:@"height"];
- if(subid==nil)
- {
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
- if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
- [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
-
- }
-
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- }
- // else
- // {
- // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- // int section = [(NSString*)idarr[0] intValue];
- // int item=[(NSString*)idarr[1] intValue];
- //
- //
- // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
- //
- // NSString* control_type= [olditem valueForKey:@"control"];
- // NSMutableDictionary* new_item=nil;
- //// [item_json setValue:@"true" forKey:@"dirty"];
- // if([control_type isEqualToString:@"enum"])
- // new_item= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- // else if([control_type isEqualToString:@"switch"])
- // new_item= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
- //
- // [section_json setObject:new_item forKey:[NSString stringWithFormat:@"item_%d",item ]];
- //
- //
- // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- // }
-
- // // 更新数据
- // [item_json setObject:@(contentHeight) forKey:@"height"];
- //
- // NSMutableDictionary *section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
- // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- // self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
- //
- // // 调用 tableView 的 beginUpdates 和 endUpdates,更新 cell 的高度
- // [self.editorTable beginUpdates];
- // [self.editorTable endUpdates];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- // UI更新代码
- [self.editorTable reloadData];
- //[self.editorTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
- });
-
- }
-
- }
- - (void)MActionClicked:(UIButton *)sender {
-
-
- [RAUtils message_box:@"Warring" message:@"MActionClicked dose not impl" completion:nil];
- }
- #pragma mark - Banner Delegate
- - (void)commonEditorBannerCell:(CommonEditorBannerCell *)cell didClickItemAtIndexPath:(NSIndexPath *)indexPath {
- if ([[[cell content] objectForKey:@"count"] integerValue] == 0) {
- return;
- }
- ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
- preVC.content = [cell content];
- [preVC setOffset:indexPath.row];
- if (self.navigationController) {
- [self.navigationController pushViewController:preVC animated:YES];
- } else {
- [self presentViewController:preVC animated:true completion:nil];
- }
- }
- #pragma mark 为子类暴露的接口
- -(void) handle_editor_cell_select:(UITableView *)tableView IndexPath:(NSIndexPath *)indexPath
- {
-
-
- NSAssert(true, ([NSString stringWithFormat:@"%@ handle_editor_cell_select not impl",[self class_name]]));
-
- }
- @end
|