CommonEditorViewController.m 309 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125
  1. //
  2. // CommonEditorViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-7-16.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "CommonEditorViewController.h"
  9. #import "CommonEditorCellEdit.h"
  10. #import "RASingleton.h"
  11. //#import "RANetwork.h"
  12. #import "CommonEditorCellEnum.h"
  13. #import "CommonEditorCellEditor.h"
  14. #import "CommonEditorCellSwitch.h"
  15. #import "CommonEditorCellModel.h"
  16. #import "CommonEditorCellAction.h"
  17. #import "EnumSelectViewController.h"
  18. #import "DatePickerViewController.h"
  19. #import "SignatureViewController.h"
  20. #import "CommonEditorCellSignature.h"
  21. #import "CommonEditorCellLabel.h"
  22. //#import "AddressEditorViewController.h"
  23. //#import "CreditCardEditorViewController.h"
  24. #import "MonthPickerViewController.h"
  25. //#import "ContactListViewController.h"
  26. #import "CommonEditorCellMAction.h"
  27. #import "CommonEditorCellTextView.h"
  28. #import "RAUtils.h"
  29. #import "CommonEditorCellImg.h"
  30. #import "RAConvertor.h"
  31. //#import "AFHTTPSessionManager.h"
  32. //#import "NetworkUtils.h"
  33. #import "config.h"
  34. #import "CustomIOSAlertView.h"
  35. #import "DefaultAppearance.h"
  36. #import "DefaultTableHeaderView.h"
  37. #define INTNUMBERS @"0123456789\n"
  38. #define NUMBERS @"0123456789.\n"
  39. # ifdef OFFLINE_MODE
  40. #import "OLDataProvider.h"
  41. # endif
  42. #import <objc/objc.h>
  43. //#import "MainViewController.h"
  44. #import "AppDelegate.h"
  45. #import "FileCache.h"
  46. //#import "RAConvertor.h"
  47. #import "EnumSelectAndSortViewController.h"
  48. #import "CommonEditorRangeCell.h"
  49. #import "CommonEditorWebCell.h"
  50. #import "CommonEditorBannerCell.h"
  51. #import "ContentPreviewController.h"
  52. #import "NetworkUtils.h"
  53. #import "EnumSelectOnlineViewController.h"
  54. @interface subitem_data ()
  55. @end
  56. @implementation subitem_data
  57. @end
  58. @interface CommonEditorViewController ()<CommonEditorRangeDelegate,CommonEditorWebCellDelegate,CommonEditorBannerDelegate>
  59. @end
  60. @implementation CommonEditorViewController
  61. - (void)viewDidLayoutSubviews {
  62. [super viewDidLayoutSubviews];
  63. [self resize_tableHeader];
  64. }
  65. #pragma mark - Code TableView
  66. - (UIView*)get_tableHeader
  67. {
  68. return [UIView new];
  69. }
  70. -(void) resize_tableHeader
  71. {
  72. //利用systemLayoutSizeFittingSize:计算出真实高度
  73. CGFloat height = [self.editorTable.tableHeaderView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  74. CGRect headerFrame = self.editorTable.tableHeaderView.frame;
  75. headerFrame.size.height = height;//20是留的上下边距
  76. //修改tableHeaderView的frame
  77. self.editorTable.tableHeaderView.frame = headerFrame;
  78. }
  79. - (void)initTableView {
  80. self.editorTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  81. self.editorTable.translatesAutoresizingMaskIntoConstraints = NO;
  82. [self.tableContainer addSubview:self.editorTable];
  83. [self.tableContainer sendSubviewToBack:self.editorTable];
  84. NSLayoutConstraint *top_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
  85. attribute:NSLayoutAttributeTop
  86. relatedBy:NSLayoutRelationEqual
  87. toItem:self.tableContainer
  88. attribute:NSLayoutAttributeTop
  89. multiplier:1
  90. constant:0];
  91. self.tb_top_constraint = top_constraint;
  92. [self.tableContainer addConstraint:top_constraint];
  93. NSLayoutConstraint *left_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
  94. attribute:NSLayoutAttributeLeft
  95. relatedBy:NSLayoutRelationEqual
  96. toItem:self.tableContainer
  97. attribute:NSLayoutAttributeLeft
  98. multiplier:1
  99. constant:0];
  100. self.tb_left_constraint = left_constraint;
  101. [self.tableContainer addConstraint:left_constraint];
  102. NSLayoutConstraint *bottom_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
  103. attribute:NSLayoutAttributeBottom
  104. relatedBy:NSLayoutRelationEqual
  105. toItem:self.tableContainer
  106. attribute:NSLayoutAttributeBottom
  107. multiplier:1
  108. constant:0];
  109. self.tb_bottom_constraint = bottom_constraint;
  110. [self.tableContainer addConstraint:bottom_constraint];
  111. NSLayoutConstraint *right_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
  112. attribute:NSLayoutAttributeRight
  113. relatedBy:NSLayoutRelationEqual
  114. toItem:self.tableContainer
  115. attribute:NSLayoutAttributeRight
  116. multiplier:1
  117. constant:0];
  118. self.tb_right_constraint = right_constraint;
  119. [self.tableContainer addConstraint:right_constraint];
  120. self.editorTable.delegate = self;
  121. self.editorTable.dataSource = self;
  122. self.editorTable.tableFooterView = [UIView new];
  123. // self.editorTable.tableHeaderView = [UIView new];
  124. self.editorTable.tableHeaderView = [self get_tableHeader];
  125. }
  126. - (void)registerPhoneCell {
  127. [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Action_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellAction"];
  128. [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Edit_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEdit"];
  129. [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Enum_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEnum"];
  130. [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Image_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellImg"];
  131. [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Label_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellLabel"];
  132. [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_MAction_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellMAction"];
  133. [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Model_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellModel"];
  134. [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Signature_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSignature"];
  135. [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Switch_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSwitch"];
  136. [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_TextView_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellTextView"];
  137. [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Range_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorRangeCell"];
  138. [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Web_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorWebCell"];
  139. [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Banner_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorBannerCell"];
  140. [self.editorTable registerNib:[UINib nibWithNibName:@"Phone_Editor_Cell" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEditor"];
  141. }
  142. - (void)registerPadCell {
  143. [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellAction" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellAction"];
  144. [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellEdit" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEdit"];
  145. [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellEnum" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellEnum"];
  146. [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellImg" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellImg"];
  147. [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellLabel" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellLabel"];
  148. [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellMAction" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellMAction"];
  149. [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellModel" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellModel"];
  150. [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellSignature" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSignature"];
  151. [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellSwitch" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellSwitch"];
  152. [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorCellTextView" bundle:nil] forCellReuseIdentifier:@"CommonEditorCellTextView"];
  153. // [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorRangeCell" bundle:nil] forCellReuseIdentifier:@"CommonEditorRangeCell"];
  154. // [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorWebCell" bundle:nil] forCellReuseIdentifier:@"CommonEditorWebCell"];
  155. // [self.editorTable registerNib:[UINib nibWithNibName:@"iPadCommonEditorBannerCell" bundle:nil] forCellReuseIdentifier:@"CommonEditorBannerCell"];
  156. }
  157. - (void)setupEditorTable {
  158. [self initTableView];
  159. // Regist Nib Cell
  160. NSString *model = [UIDevice currentDevice].model;
  161. if ([model isEqualToString:@"iPhone"]) {
  162. [self registerPhoneCell];
  163. }
  164. else
  165. {
  166. [self registerPadCell];
  167. }
  168. }
  169. #pragma mark ==============
  170. -(void) commonAction:(NSString *)value index:(NSIndexPath*) indexPath data:(NSMutableDictionary*) item_json
  171. {
  172. NSAssert(true, ([NSString stringWithFormat:@"%@ commonAction not impl",[self class_name]]));
  173. }
  174. - (NSString *)class_name {
  175. if (!_class_name) {
  176. const char *class_name_ch = object_getClassName([self class]);
  177. _class_name = [NSString stringWithUTF8String:class_name_ch];
  178. }
  179. return _class_name;
  180. }
  181. - (NSString *)urgency_timer_name {
  182. if (!_urgency_timer_name) {
  183. _urgency_timer_name = [NSString stringWithFormat:@"%@_urgency_timer",self.class_name];
  184. }
  185. return _urgency_timer_name;
  186. }
  187. - (int)level {
  188. if (_level == -1) {
  189. __block AppDelegate *appDelegate = nil;
  190. dispatch_async(dispatch_get_main_queue(), ^{
  191. //some UI methods ej
  192. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  193. });
  194. // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  195. NSDictionary *urgencyDic = [RASingleton.sharedInstance globalParameterForKey:@"urgencyDic"];
  196. id count = [urgencyDic objectForKey:@"count"];
  197. _level = count == nil ? 0 : [count intValue];
  198. }
  199. return _level;
  200. }
  201. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  202. {
  203. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  204. if (self) {
  205. // Custom initialization
  206. }
  207. return self;
  208. }
  209. - (void) request_fill
  210. {
  211. }
  212. -(void) viewWillAppear:(BOOL)animated
  213. {
  214. [super viewWillAppear:animated];
  215. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  216. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  217. // 键盘高度变化通知,ios5.0新增的
  218. //#ifdef __IPHONE_5_0
  219. // float version = [[[UIDevice currentDevice] systemVersion] floatValue];
  220. // if (version >= 5.0) {
  221. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
  222. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];
  223. // }
  224. //#endif
  225. }
  226. -(void) viewWillDisappear:(BOOL)animated
  227. {
  228. [super viewWillDisappear:animated];
  229. [[NSNotificationCenter defaultCenter] removeObserver:self];
  230. if(!self.alert.isBeingDismissed)
  231. {
  232. [self.alert dismissViewControllerAnimated:YES completion:nil];
  233. NSLog(@"alert dismiss by viewwillDisapper %p",self.alert);
  234. }
  235. }
  236. -(void)manually_refresh
  237. {
  238. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  239. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  240. if ([self respondsToSelector:@selector(reload_data)])
  241. [self performSelector:@selector(reload_data) withObject:nil afterDelay:1];
  242. // DebugLog(@"refresh!!!!!!!!");
  243. }
  244. -(void)reload_data
  245. {
  246. [self.lastedit endEditing:true];
  247. [self.lasttextview endEditing:true];
  248. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  249. [reF endRefreshing];
  250. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  251. [self refresh:nil discardDirty:true];
  252. }
  253. - (void)alertMessage:(NSString *)msg {
  254. [RAUtils message_alert:msg title:nil controller:self] ;
  255. }
  256. -(void)dealloc
  257. {
  258. [self.autocompleteView removeFromSuperview];
  259. // [self.editorTable removeObserver:self forKeyPath:@"frame"];
  260. }
  261. //- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  262. //{
  263. // // 方式1.匹配keypath
  264. // if ([keyPath isEqualToString:@"frame"]) {
  265. //
  266. // self.autocompleteView.frame = self.editorTable.frame;
  267. // }
  268. //
  269. //
  270. //}
  271. - (void)viewDidLoad
  272. {
  273. [super viewDidLoad];
  274. NSString *model = [UIDevice currentDevice].model;
  275. if ([model isEqualToString:@"iPhone"]||true) {
  276. [self setupEditorTable];
  277. }
  278. // else {
  279. // // 在键盘事件中,使用tableContainer计算frame 保证屏幕旋转后table height正确
  280. // if (self.tableContainer == nil) {
  281. // self.tableContainer = [[CommonEditorTableContainerView alloc] initWithFrame:self.editorTable.frame];
  282. // self.tableContainer.autoresizingMask = self.editorTable.autoresizingMask;
  283. // CGRect frame = self.editorTable.frame;
  284. // frame.origin.x = 0;
  285. // frame.origin.y = 0;
  286. // [self.view addSubview:self.tableContainer];
  287. // [self.view sendSubviewToBack:self.tableContainer];
  288. // [self.tableContainer addSubview:self.editorTable];
  289. // }
  290. // }
  291. NSArray* nibView = [[NSBundle mainBundle] loadNibNamed:@"CommonEditorAutoCompleteView" owner:nil options:nil];
  292. self.autocompleteView = [nibView firstObject];
  293. self.autocompleteView.dataSource = self;
  294. // [self.tableContainer addSubview:self.autocompleteView];
  295. [self.navigationController.view addSubview:self.autocompleteView];
  296. self.autocompleteView.frame = self.navigationController.view.frame;
  297. // self.autocompleteView.frame = self.editorTable.frame;
  298. // [self.editorTable addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
  299. self.autocompleteView.hidden = true;
  300. // [self.view bringSubviewToFront:self.autocompleteView];
  301. //
  302. // self.switchlock = [[NSLock alloc] init];
  303. // [self.editorTable setExclusiveTouch:false];
  304. self.editable = NO;
  305. if(self.loading_msg==nil)
  306. self.loading_msg = @"Please Wait";
  307. if(self.loading_title==nil)
  308. self.loading_title = @"Loading...";
  309. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  310. ref.tag = 200 ;
  311. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  312. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  313. // ref.hidden = true;
  314. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  315. if(!self.disable_dropdown_refresh)
  316. [self.editorTable addSubview:ref];
  317. self.level = -1;
  318. if (!self.changed_data) {
  319. self.changed_data = [[NSMutableDictionary alloc] init];
  320. }
  321. // UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  322. // // closeButton.title = @"Close";
  323. //
  324. // self.navigationItem.leftBarButtonItem = closeButton;
  325. __weak typeof(self) weakself = self;
  326. if(self.url_type==URL_REMOTE)
  327. {
  328. __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{
  329. [RADataProvider request_editor:self.request_url params:self.params completionHandler:^(NSMutableDictionary *result) {
  330. NSMutableDictionary* editor_json = result;
  331. DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
  332. [waitalert dismissViewControllerAnimated:YES completion:^{
  333. if([[editor_json valueForKey:@"result"] intValue]==RESULT_TRUE)
  334. {
  335. NSArray* arr_menu =editor_json[@"menu"];
  336. if( arr_menu !=nil)
  337. {
  338. [self injectMenu:arr_menu];
  339. }
  340. weakself.content_data_download = [editor_json mutableCopy];
  341. weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
  342. // self.content_data = [editor_json mutableCopy];
  343. // self.content_data = [self translate_json:editor_json];
  344. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  345. [weakself download_success];
  346. [weakself.editorTable reloadData];
  347. // NSString * ttt=[self.content_data valueForKey:@"title"] ;
  348. weakself.navigationItem.title = [weakself.content_data_download valueForKey:@"title"] ;
  349. }
  350. else if([[editor_json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE)
  351. {
  352. [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:nil];
  353. }
  354. else
  355. {
  356. [weakself download_failed];
  357. [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
  358. }
  359. }];
  360. }];
  361. }];
  362. self.alert = waitalert;
  363. }
  364. else if(self.url_type== URL_LOCAL )
  365. {
  366. NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
  367. NSError *error=nil;
  368. self.content_data_download = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  369. self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
  370. self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  371. [self.editorTable reloadData];
  372. // NSString * ttt=[self.content_data valueForKey:@"title"] ;
  373. // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  374. }
  375. else
  376. {
  377. self.content_data_control=[self translate_json:self.content_data_download changed: self.changed_data];
  378. [self.editorTable reloadData];
  379. // NSString * ttt=[self.content_data valueForKey:@"title"] ;
  380. self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  381. }
  382. self.requried = [[NSMutableDictionary alloc] init];
  383. self.cancommit = true;
  384. // 恢复编辑后重置URL Type,避免刷新Crash
  385. if (self.url_type == URL_RESTORE) {
  386. self.url_type = URL_REMOTE;
  387. }
  388. }
  389. -(void) injectMenu:(NSArray* ) menu
  390. {
  391. UIBarButtonItem *menuItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_more_dot"] style:UIBarButtonItemStylePlain target:self action:@selector(menuItemClick:)];
  392. self.injectMenu = menu;
  393. // // closeButton.title = @"Close";
  394. //
  395. self.navigationItem.rightBarButtonItem = menuItem;
  396. }
  397. - (void)menuItemClick:(id)sender {
  398. NSAssert(true, ([NSString stringWithFormat:@"%@ menuItemClick not impl",[self class_name]]));
  399. }
  400. -(NSMutableDictionary*) check_cancommit :(bool) alert
  401. {
  402. [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
  403. // [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)];
  404. [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
  405. self.first_miss_pos = nil;
  406. self.cancommit=true;
  407. NSMutableArray* fields=[[NSMutableArray alloc] init];
  408. NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  409. // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  410. int section_count=(int)self.content_data_control.count;//[[self.content_data_download valueForKey:@"section_count"] intValue];
  411. // NSString* aaa = [RAUtils dict2string:self.content_data_control];
  412. for(int i=0;i<section_count;i++)
  413. {
  414. DebugLog(@"debug...section:%d",i);
  415. NSMutableArray * sectionjson = [self.content_data_control[i] mutableCopy];//[[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  416. int item_count = (int)sectionjson.count;//[[sectionjson valueForKey:@"count"] intValue];
  417. for(int j=0;j<item_count;j++)
  418. {
  419. NSMutableDictionary * itemjson=[sectionjson[j] mutableCopy];//[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  420. NSString* key = [itemjson valueForKey:@"name"];
  421. if(key==nil || key.length==0)
  422. continue;
  423. if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  424. {
  425. NSString* single_select = [itemjson valueForKey:@"single_select"];
  426. if([single_select isEqualToString:@"true"])
  427. {
  428. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  429. int count = [[cadejson valueForKey:@"count"] intValue];
  430. bool setvalue = false;
  431. for(int cc=0;cc<count;cc++)
  432. {
  433. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  434. if([[valjson valueForKey:@"check"]intValue]==1)
  435. {
  436. [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  437. setvalue=true;
  438. break;
  439. }
  440. }
  441. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  442. {
  443. self.cancommit = false;
  444. NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
  445. [fields addObject:mfield];
  446. NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
  447. if(alert)
  448. [self unhide_section:(int)indexpath.section];
  449. if(fields.count==1)
  450. {
  451. self.first_miss_pos = indexpath;
  452. }
  453. }
  454. }
  455. else //multiple select
  456. {
  457. NSMutableArray* checked = [[NSMutableArray alloc] init];
  458. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  459. int count = [[cadejson valueForKey:@"count"] intValue];
  460. for(int cc=0;cc<count;cc++)
  461. {
  462. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  463. if([[valjson valueForKey:@"check"]intValue]==1)
  464. {
  465. // [checked addObject:[NSNumber numberWithInt:[[valjson valueForKey:@"value_id"] intValue]]];
  466. [checked addObject:[NSString stringWithFormat:@"%@",[valjson valueForKey:@"value_id"]]];
  467. }
  468. }
  469. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"]&&checked.count==0)
  470. {
  471. self.cancommit = false;
  472. NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
  473. [fields addObject:mfield];
  474. NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
  475. if(alert)
  476. [self unhide_section:(int)indexpath.section];
  477. if(fields.count==1)
  478. {
  479. self.first_miss_pos = indexpath;
  480. }
  481. }
  482. else
  483. {
  484. NSString * string = [checked componentsJoinedByString:@","];
  485. [upparams setValue:string forKey:[itemjson valueForKey:@"name"]];
  486. }
  487. }
  488. /*
  489. upparams setValue:itemjson forKey:<#(NSString *)#>
  490. */
  491. }else
  492. if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  493. {
  494. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  495. {
  496. self.cancommit = false;
  497. NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
  498. [fields addObject:mfield];
  499. NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
  500. if(alert)
  501. [self unhide_section:(int)indexpath.section];
  502. if(fields.count==1)
  503. {
  504. self.first_miss_pos = indexpath;
  505. }
  506. }
  507. }
  508. else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  509. {
  510. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil)
  511. {
  512. self.cancommit = false;
  513. NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
  514. [fields addObject:mfield];
  515. NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
  516. if(alert)
  517. [self unhide_section:(int)indexpath.section];
  518. if(fields.count==1)
  519. {
  520. self.first_miss_pos = indexpath;
  521. }
  522. }
  523. NSString* valuestr = [itemjson valueForKey:@"value"];
  524. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  525. }
  526. else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  527. {
  528. NSString* valuestr = [itemjson valueForKey:@"value"];
  529. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  530. NSString* value = [itemjson valueForKey:@"value"];
  531. NSMutableDictionary* boolitem=nil;
  532. NSMutableDictionary* subjson=nil;
  533. if([value isEqualToString:@"true"])
  534. {
  535. boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  536. }
  537. else
  538. {
  539. boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  540. }
  541. subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  542. if( subjson!=nil /*&& !active*/)
  543. {
  544. int sub_count = [[subjson valueForKey:@"count"] intValue];
  545. for(int l=0;l<sub_count;l++)
  546. {
  547. NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  548. if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  549. [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  550. else
  551. {
  552. if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  553. {
  554. self.cancommit = false;
  555. NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
  556. [fields addObject:mfield];
  557. NSIndexPath* indexpath =[self get_indexpath1:[modify_item valueForKey:@"name"]];
  558. if(alert)
  559. [self unhide_section:(int)indexpath.section];
  560. if(fields.count==1)
  561. {
  562. self.first_miss_pos = indexpath;
  563. }
  564. }
  565. }
  566. }
  567. }
  568. }
  569. else if([[itemjson valueForKey:@"control"] isEqualToString:@"img"])
  570. {
  571. if([itemjson valueForKey:@"avalue"]!=nil && ![[itemjson valueForKey:@"avalue"]isEqualToString:@""])
  572. [upparams setValue:[itemjson valueForKey:@"avalue"] forKey:[itemjson valueForKey:@"name"]];
  573. else
  574. {
  575. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  576. {
  577. self.cancommit = false;
  578. NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
  579. [fields addObject:mfield];
  580. NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
  581. if(alert)
  582. [self unhide_section:(int)indexpath.section];
  583. if(fields.count==1)
  584. {
  585. self.first_miss_pos = indexpath;
  586. }
  587. }
  588. }
  589. }
  590. else if([[itemjson valueForKey:@"control"] isEqualToString:@"edit"])
  591. {
  592. int min_length = [[itemjson valueForKey:@"min_length"] intValue];
  593. NSString* check_len_val =itemjson[@"value"];
  594. if( check_len_val.length<min_length)
  595. {
  596. self.cancommit = false;
  597. NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is too short",fields.count+1,itemjson[@"aname"]];
  598. if(check_len_val.length==0 &&[[itemjson valueForKey:@"required"] isEqualToString: @"true"])
  599. mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
  600. [fields addObject:mfield];
  601. NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
  602. if(alert)
  603. [self unhide_section:(int)indexpath.section];
  604. if(fields.count==1)
  605. {
  606. self.first_miss_pos = indexpath;
  607. }
  608. }
  609. else if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""] )
  610. {
  611. NSString *keyboard_type = [itemjson objectForKey:@"keyboard"];
  612. BOOL check_max = [itemjson objectForKey:@"max_type"] != nil ? YES : NO;
  613. BOOL check_min = [itemjson objectForKey:@"min_type"] != nil ? YES : NO;
  614. if ([keyboard_type isEqualToString:@"number"] && (check_max || check_min)) {
  615. // 检查最大值最小值
  616. int max_type = [[itemjson objectForKey:@"max_type"] intValue];
  617. int min_type = [[itemjson objectForKey:@"min_type"] intValue];
  618. float max_value = MAXFLOAT;
  619. float min_value = 0;
  620. NSString *mfield = nil;
  621. float f_value = [check_len_val floatValue];
  622. if (check_max) {
  623. if (max_type > 0) {
  624. // key
  625. NSString *max_key = [itemjson objectForKey:@"max"];
  626. id max_obj = [self downloadValueForKey:max_key];
  627. if (max_obj) {
  628. max_value = [max_obj floatValue];
  629. }
  630. } else {
  631. // value
  632. id max_obj = [itemjson objectForKey:@"max"];
  633. if (max_obj != nil) {
  634. max_value = [max_obj floatValue];
  635. }
  636. }
  637. if (max_value < f_value) {
  638. mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not larger than %.2f",fields.count+1,itemjson[@"aname"],max_value];
  639. }
  640. }
  641. if (check_min) {
  642. if (min_type > 0) {
  643. // key
  644. NSString *min_key = [itemjson objectForKey:@"min"];
  645. id min_obj = [self downloadValueForKey:min_key];
  646. if (min_obj) {
  647. min_value = [min_obj floatValue];
  648. }
  649. } else {
  650. // value
  651. id min_obj = [itemjson objectForKey:@"min"];
  652. if (min_obj != nil) {
  653. min_value = [min_obj floatValue];
  654. }
  655. }
  656. if (min_value > f_value) {
  657. mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not smaller than %.2f",fields.count+1,itemjson[@"aname"],min_value];
  658. }
  659. }
  660. if (check_min && check_max) {
  661. if (f_value < min_value || f_value > max_value) {
  662. mfield =[NSString stringWithFormat:@"%ld. the value of %@ must between %.2f and %.2f",fields.count+1,itemjson[@"aname"],min_value,max_value];
  663. }
  664. }
  665. if (mfield != nil) {
  666. self.cancommit = false;
  667. [fields addObject:mfield];
  668. NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
  669. if(alert)
  670. [self unhide_section:(int)indexpath.section];
  671. if(fields.count==1)
  672. {
  673. self.first_miss_pos = indexpath;
  674. }
  675. } else {
  676. [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  677. }
  678. } else {
  679. [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  680. }
  681. }
  682. else
  683. {
  684. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  685. {
  686. self.cancommit = false;
  687. NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
  688. [fields addObject:mfield];
  689. NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
  690. if(alert)
  691. [self unhide_section:(int)indexpath.section];
  692. if(fields.count==1)
  693. {
  694. self.first_miss_pos = indexpath;
  695. }
  696. }
  697. }
  698. }
  699. else if ([[itemjson valueForKey:@"control"] isEqualToString:@"range"])
  700. {
  701. if([itemjson valueForKey:@"min_value"]!=nil && ![[itemjson valueForKey:@"min_value"]isEqualToString:@""] &&[itemjson valueForKey:@"max_value"]!=nil && ![[itemjson valueForKey:@"max_value"]isEqualToString:@""])
  702. {
  703. NSMutableDictionary* valjson = [NSMutableDictionary new];
  704. if([itemjson valueForKey:@"min_value"]!=nil && ![[itemjson valueForKey:@"min_value"]isEqualToString:@""])
  705. valjson[@"min"] = itemjson[@"min_value"];
  706. if([itemjson valueForKey:@"max_value"]!=nil && ![[itemjson valueForKey:@"max_value"]isEqualToString:@""])
  707. valjson[@"max"] = itemjson[@"max_value"];
  708. NSString* val=[RAConvertor dict2string:valjson];
  709. // NSString *keyboard_type = [itemjson objectForKey:@"keyboard"];
  710. // BOOL check_max = [itemjson objectForKey:@"max_type"] != nil ? YES : NO;
  711. // BOOL check_min = [itemjson objectForKey:@"min_type"] != nil ? YES : NO;
  712. // if ([keyboard_type isEqualToString:@"number"] && (check_max || check_min)) {
  713. // // 检查最大值最小值
  714. // int max_type = [[itemjson objectForKey:@"max_type"] intValue];
  715. // int min_type = [[itemjson objectForKey:@"min_type"] intValue];
  716. //
  717. // float max_value = MAXFLOAT;
  718. // float min_value = 0;
  719. //
  720. // NSString *mfield = nil;
  721. //// float f_value = [check_len_val floatValue];
  722. ////
  723. //// if (check_max) {
  724. ////
  725. //// if (max_type > 0) {
  726. //// // key
  727. //// NSString *max_key = [itemjson objectForKey:@"max"];
  728. //// id max_obj = [self downloadValueForKey:max_key];
  729. //// if (max_obj) {
  730. //// max_value = [max_obj floatValue];
  731. //// }
  732. ////
  733. //// } else {
  734. //// // value
  735. //// id max_obj = [itemjson objectForKey:@"max"];
  736. //// if (max_obj != nil) {
  737. //// max_value = [max_obj floatValue];
  738. //// }
  739. ////
  740. //// }
  741. ////
  742. //// if (max_value < f_value) {
  743. //// mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not larger than %.2f",fields.count+1,itemjson[@"aname"],max_value];
  744. //// }
  745. //// }
  746. //
  747. //// if (check_min) {
  748. ////
  749. //// if (min_type > 0) {
  750. //// // key
  751. //// NSString *min_key = [itemjson objectForKey:@"min"];
  752. //// id min_obj = [self downloadValueForKey:min_key];
  753. //// if (min_obj) {
  754. //// min_value = [min_obj floatValue];
  755. //// }
  756. //// } else {
  757. //// // value
  758. //// id min_obj = [itemjson objectForKey:@"min"];
  759. //// if (min_obj != nil) {
  760. //// min_value = [min_obj floatValue];
  761. //// }
  762. //// }
  763. ////
  764. //// if (min_value > f_value) {
  765. //// mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not smaller than %.2f",fields.count+1,itemjson[@"aname"],min_value];
  766. //// }
  767. //// }
  768. //
  769. //
  770. //// if (check_min && check_max) {
  771. //// if (f_value < min_value || f_value > max_value) {
  772. //// mfield =[NSString stringWithFormat:@"%ld. the value of %@ must between %.2f and %.2f",fields.count+1,itemjson[@"aname"],min_value,max_value];
  773. //// }
  774. //// }
  775. //
  776. // if (mfield != nil) {
  777. // self.cancommit = false;
  778. // [fields addObject:mfield];
  779. // NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
  780. // if(alert)
  781. // [self unhide_section:(int)indexpath.section];
  782. // if(fields.count==1)
  783. // {
  784. // self.first_miss_pos = indexpath;
  785. //
  786. // }
  787. // } else {
  788. // [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  789. // }
  790. //
  791. // } else
  792. // {
  793. [upparams setValue:val forKey:[itemjson valueForKey:@"name"]];
  794. // }
  795. }
  796. else
  797. {
  798. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  799. {
  800. self.cancommit = false;
  801. NSString* mfield =[NSString stringWithFormat:@"%lu. %@ is missing",fields.count+1,itemjson[@"aname"]];
  802. [fields addObject:mfield];
  803. NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
  804. if(alert)
  805. [self unhide_section:(int)indexpath.section];
  806. if(fields.count==1)
  807. {
  808. self.first_miss_pos = indexpath;
  809. }
  810. }
  811. }
  812. }
  813. else
  814. {
  815. if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  816. [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  817. else
  818. {
  819. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  820. {
  821. self.cancommit = false;
  822. NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
  823. [fields addObject:mfield];
  824. NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
  825. if(alert)
  826. [self unhide_section:(int)indexpath.section];
  827. if(fields.count==1)
  828. {
  829. self.first_miss_pos = indexpath;
  830. }
  831. }
  832. }
  833. }
  834. // subitem_data * data=[self subitem_param:itemjson addto:upparams alert:alert];
  835. // upparams= data.params;
  836. // fields=[[fields arrayByAddingObjectsFromArray:data.missingfields] mutableCopy];
  837. }
  838. }
  839. if(self.cancommit==false && alert)
  840. {
  841. NSString* missfields=[fields componentsJoinedByString:@"\n"];
  842. NSString* msg = [NSString stringWithFormat:@"%@",missfields];
  843. CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
  844. // Add some custom content to the alert view
  845. [alertView setContainerView:[self createDemoView:msg]];
  846. // Modify the parameters
  847. [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"OK", nil]];
  848. //[alertView setDelegate:self];
  849. // You may use a Block, rather than a delegate.
  850. [alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
  851. // DebugLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, (int)[alertView tag]);
  852. [alertView close];
  853. }];
  854. // [alertView setUseMotionEffects:true];
  855. // And launch the dialog
  856. [alertView sizeToFit];
  857. [alertView show];
  858. // [RAUtils alert_view:msg title:@"Please complete missing fields:"];
  859. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  860. [self.editorTable reloadData];
  861. [self.editorTable scrollToRowAtIndexPath:self.first_miss_pos atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
  862. return upparams;
  863. }
  864. else
  865. {
  866. self.cancommit=true;
  867. //[self.editorTable reloadData];
  868. }
  869. return upparams;
  870. }
  871. - (UIView *)createDemoView:(NSString*) msg
  872. {
  873. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
  874. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  875. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  876. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
  877. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  878. titleLabel.text=@"Please complete missing fields:";
  879. titleLabel.numberOfLines = 0;
  880. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  881. // titleLabel.textAlignment = NSTextAlignmentRight;
  882. titleLabel.textAlignment = NSTextAlignmentCenter;
  883. CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
  884. // CGSize sizetitle = [@"Please complete missing fields:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  885. //
  886. CGSize sizetitle = [RAUtils sizeWithFont:@"Please complete missing fields:" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  887. //[titleLabel sizeToFit];
  888. // titleLabel.center.x = demoView.center.x;
  889. titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
  890. [demoView addSubview:titleLabel];
  891. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
  892. lineLabel.font = [UIFont boldSystemFontOfSize:17];
  893. lineLabel.text=msg;
  894. lineLabel.numberOfLines = 0;
  895. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  896. // CGSize sizemsg = [msg sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  897. CGSize sizemsg = [RAUtils sizeWithFont:msg font:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  898. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
  899. //[lineLabel sizeToFit];
  900. [demoView addSubview:lineLabel];
  901. demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  902. return demoView;
  903. }
  904. //- (void)willPresentAlertView:(UIAlertView *)alertView{
  905. //
  906. //
  907. // alertView set
  908. // for( UIView * view in alertView.subviews )
  909. //
  910. // { if( [view isKindOfClass:[UILabel class]] )
  911. //
  912. // { UILabel* label = (UILabel*) view;
  913. //
  914. // label.textAlignment = NSTextAlignmentLeft; }
  915. //
  916. // }
  917. //
  918. //}
  919. //-(bool) action_btn_passed_check:(NSDictionary* ) data;
  920. //{
  921. // if(data == nil)
  922. // return false;
  923. // int section_count=[[data valueForKey:@"section_count"] intValue];
  924. //
  925. // for(int sc=0;sc<section_count)
  926. //
  927. //}
  928. //-(NSString*) get_param:(NSString*)param_name content_item:(NSDictionary*)itemjson
  929. //{
  930. //
  931. // NSString * item_name = [itemjson valueForKey:@"name"];
  932. // NSDictionary* cadejson= [itemjson objectForKey:@"cadedate"];
  933. // int cade_count = [[cadejson valueForKey:@"count"] intValue];
  934. // if([item_name isEqualToString:param_name] )
  935. // {
  936. // NSString* param_val=nil;
  937. //
  938. // bool single_select =[[itemjson valueForKey:@"single_select"] boolValue];
  939. //
  940. // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
  941. //
  942. //
  943. // for(int cc=0;cc<cade_count;cc++)
  944. // {
  945. // NSDictionary * valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
  946. // if([[valjson valueForKey:@"check"] boolValue])
  947. // {
  948. // NSString * valueid=[valjson valueForKey:@"value_id"];
  949. // if(valueid!=nil)
  950. // [arr_val addObject: valueid];
  951. // if(single_select)
  952. // break;
  953. // }
  954. //
  955. // }
  956. //
  957. // param_val = [arr_val componentsJoinedByString:@","];
  958. //
  959. // return param_val;
  960. // //[self.params setValue:param_val forKey:param_name];
  961. //
  962. // }
  963. // else
  964. // {
  965. // for(int cc=0;cc<cade_count;cc++)
  966. // {
  967. // NSDictionary * valjson=[itemjson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
  968. // NSDictionary* subitems=[valjson objectForKey:@"sub_item"];
  969. // if(subitems==nil)
  970. // continue;
  971. // int subcount=[[subitems valueForKey:@"count"] intValue];
  972. // for(int sc=0;sc<subcount;sc++)
  973. // {
  974. // NSDictionary* subitem = [subitems objectForKey:[NSString stringWithFormat:@"item_%d",sc]];
  975. // NSString* subval=[self get_param:param_name content_item:subitem];
  976. // if(subval!=nil)
  977. // return subval;
  978. // }
  979. //
  980. //
  981. // }
  982. //
  983. //
  984. // }
  985. // return nil;
  986. //
  987. //}
  988. -(void) download_success
  989. {
  990. // 用于处理不同child,在成功去的数据后,需要附加的操作。
  991. }
  992. - (void)download_failed {
  993. // 用于不同Child 处理失败
  994. }
  995. -(NSDictionary*) get_refresh_param
  996. {
  997. NSMutableDictionary* params= [[NSMutableDictionary alloc]init];
  998. NSDictionary * param_names = [self.content_data_download objectForKey:@"up_params"];
  999. int param_count=[[param_names valueForKey:@"count"] intValue];
  1000. for(int pc=0;pc<param_count;pc++)
  1001. {
  1002. NSString* param_name = [param_names valueForKey:[NSString stringWithFormat:@"val_%d",pc]];
  1003. NSString* param_val = [self getValue:param_name];
  1004. [self.params setValue:param_val forKey:param_name];
  1005. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  1006. //
  1007. // for(int i=0;i<section_count;i++)
  1008. // {
  1009. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1010. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  1011. // for(int j=0;j<item_count;j++)
  1012. // {
  1013. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1014. //
  1015. // NSString * control_type = [itemjson valueForKey:@"control"];
  1016. // // NSString * item_name = [itemjson valueForKey:@"name"];
  1017. // if([control_type isEqualToString:@"enum"])
  1018. // {
  1019. // NSString* subval= [self get_param:param_name content_item:itemjson];
  1020. // if(subval!=nil)
  1021. // {
  1022. // [self.params setValue:subval forKey:param_name];
  1023. // break;
  1024. // }
  1025. // // if([item_name isEqualToString:param_name] )
  1026. // // {
  1027. // // NSString* param_val=nil;
  1028. // //
  1029. // // bool single_select =[[itemjson valueForKey:@"single_select"] boolValue];
  1030. // //
  1031. // // int cade_count = [[itemjson valueForKey:@"count"] intValue];
  1032. // //
  1033. // // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
  1034. // //
  1035. // //
  1036. // // for(int cc=0;cc<cade_count;cc++)
  1037. // // {
  1038. // // NSDictionary * valjson=[itemjson objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
  1039. // // if([[valjson valueForKey:@"check"] boolValue])
  1040. // // {
  1041. // // [arr_val addObject: [valjson valueForKey:@"value_id"]];
  1042. // // if(single_select)
  1043. // // break;
  1044. // // }
  1045. // //
  1046. // // }
  1047. // //
  1048. // // param_val = [arr_val componentsJoinedByString:@","];
  1049. // //
  1050. // // [self.params setValue:param_val forKey:param_name];
  1051. // // break;
  1052. // // }
  1053. // // else
  1054. // // {
  1055. // // NSString* subval= [self get_param:param_name content_item:itemjson];
  1056. // // if(subval!=nil)
  1057. // // {
  1058. // // [self.params setValue:subval forKey:param_name];
  1059. // // break;
  1060. // // }
  1061. // // }
  1062. // }
  1063. // }
  1064. // }
  1065. }
  1066. return params;
  1067. // NSString* param_name=[item_json valueForKey:@"name"];
  1068. // NSString* param_val=nil;
  1069. //
  1070. // bool single_select =[[item_json valueForKey:@"single_select"] boolValue];
  1071. //
  1072. // int cade_count = [[value valueForKey:@"count"] intValue];
  1073. //
  1074. // NSMutableArray* arr_val = [[NSMutableArray alloc] init];
  1075. //
  1076. //
  1077. // for(int cc=0;cc<cade_count;cc++)
  1078. // {
  1079. // NSDictionary * valjson=[value objectForKey:[NSString stringWithFormat:@"val_%d",cc ]];
  1080. // if([[valjson valueForKey:@"check"] boolValue])
  1081. // {
  1082. // [arr_val addObject: [valjson valueForKey:@"value_id"]];
  1083. // if(single_select)
  1084. // break;
  1085. // }
  1086. //
  1087. // }
  1088. //
  1089. // param_val = [arr_val componentsJoinedByString:@","];
  1090. //
  1091. // [self.changed_data setObject:param_val forKey:param_name];
  1092. }
  1093. -(NSMutableDictionary*) CopyDirty:(NSDictionary*) dirty to:(NSMutableDictionary*) to
  1094. {
  1095. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  1096. for(int i=0;i<section_count;i++)
  1097. {
  1098. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1099. NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1100. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  1101. for(int j=0;j<item_count;j++)
  1102. {
  1103. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1104. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1105. if([[itemjson valueForKey:@"dirty"] isEqualToString:@"true"])
  1106. {
  1107. int toindex = -1;
  1108. for(int l=0;l<[to_sectionjson[@"count"] intValue];l++)
  1109. {
  1110. NSDictionary* lobject = to_sectionjson[[NSString stringWithFormat:@"item_%d",l]];
  1111. if([[lobject[@"name"] stringValue] isEqualToString:[itemjson[@"name"]stringValue]])
  1112. {
  1113. toindex = l;
  1114. break;
  1115. }
  1116. }
  1117. [to_sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",toindex ]];
  1118. }
  1119. }
  1120. [to setObject:to_sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  1121. }
  1122. return to;
  1123. }
  1124. //-(void) refresh:(NSString*) trigger
  1125. //{
  1126. // [self refresh:trigger discardDirty:false];
  1127. //}
  1128. -(void) refresh:(NSString*) trigger discardDirty:(bool) discardDirty
  1129. {
  1130. [self.lastedit endEditing:true];
  1131. [self.lasttextview endEditing:true];
  1132. if(self.url_type==URL_REMOTE)
  1133. {
  1134. self.params[@"refresh_trigger"]=trigger;
  1135. __weak typeof(self) weakself = self;
  1136. NSDictionary* refresh_params=[self get_refresh_param];
  1137. NSArray* changed_key=[refresh_params allKeys];
  1138. for(int i=0;i<changed_key.count;i++)
  1139. {
  1140. NSString* obj_str=[NSString stringWithFormat:@"%@",[refresh_params valueForKey:(NSString*)changed_key[i]]];
  1141. [self.params setObject:obj_str forKey:(NSString*)changed_key[i]];
  1142. }
  1143. __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{
  1144. [RADataProvider request_editor:self.request_url params:self.params completionHandler:^(NSMutableDictionary *result) {
  1145. NSMutableDictionary* editor_json = result;
  1146. DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
  1147. [waitalert dismissViewControllerAnimated:YES completion:^{
  1148. NSLog(@"alert dismiss by network return %p",waitalert);
  1149. if([[editor_json valueForKey:@"result"] intValue]==2)
  1150. {
  1151. if(!discardDirty)
  1152. {
  1153. weakself.content_data_download = [weakself CopyDirty:weakself.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
  1154. }
  1155. weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
  1156. [weakself download_success];
  1157. [weakself.editorTable reloadData];
  1158. }
  1159. else if([[editor_json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE)
  1160. {
  1161. [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:editor_json[@"err_msg"]];
  1162. }
  1163. else
  1164. {
  1165. [weakself download_failed];
  1166. [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
  1167. }
  1168. }];
  1169. }];
  1170. }];
  1171. self.alert = waitalert;
  1172. }
  1173. else
  1174. {
  1175. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
  1176. NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
  1177. NSError *error=nil;
  1178. self.content_data_download = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1179. [self request_fill];
  1180. self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
  1181. [self.editorTable reloadData];
  1182. // NSString * ttt=[self.content_data valueForKey:@"title"] ;
  1183. // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  1184. }
  1185. }
  1186. -(subitem_data*) subitem_param:(NSDictionary*) itemjson addto:(NSMutableDictionary*) upparam alert:(bool)alert
  1187. {
  1188. subitem_data * data = [[subitem_data alloc] init];
  1189. NSMutableArray * fields = [[NSMutableArray alloc]init];
  1190. NSString * control_type = [itemjson valueForKey:@"control"];
  1191. bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
  1192. if([control_type isEqual:@"enum"] && single_select)
  1193. {
  1194. NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
  1195. int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
  1196. for(int k=0;k<cade_count;k++)
  1197. {
  1198. NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
  1199. int check=[[valjson valueForKey:@"check"] intValue];
  1200. NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
  1201. bool active =[[valjson valueForKey:@"active"] boolValue];
  1202. if(check==1 && subjson!=nil && !active)
  1203. {
  1204. int sub_count = [[subjson valueForKey:@"count"] intValue];
  1205. for(int l=0;l<sub_count;l++)
  1206. {
  1207. NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  1208. NSString* required = [addjson valueForKey:@"required"];
  1209. NSString* key=[addjson valueForKey:@"name"];
  1210. if(key==nil || key.length==0)
  1211. continue;
  1212. if([[addjson valueForKey:@"control"] isEqualToString:@"enum" ])
  1213. {
  1214. NSString* single_select = [addjson valueForKey:@"single_select"];
  1215. if([single_select isEqualToString:@"true"])
  1216. {
  1217. NSDictionary* cadejson=[addjson objectForKey:@"cadedate"];
  1218. int count = [[cadejson valueForKey:@"count"] intValue];
  1219. bool setvalue = false;
  1220. for(int cc=0;cc<count;cc++)
  1221. {
  1222. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  1223. if([[valjson valueForKey:@"check"]intValue]==1)
  1224. {
  1225. [upparam setValue:[valjson valueForKey:@"value_id"] forKey:[addjson valueForKey:@"name"]];
  1226. setvalue=true;
  1227. break;
  1228. }
  1229. }
  1230. if([[addjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  1231. {
  1232. self.cancommit = false;
  1233. NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,addjson[@"aname"]];
  1234. [fields addObject:mfield];
  1235. NSIndexPath* indexpath =[self get_indexpath1:[addjson valueForKey:@"name"]];
  1236. if(alert)
  1237. [self unhide_section:(int)indexpath.section];
  1238. if(fields.count==1)
  1239. {
  1240. self.first_miss_pos = indexpath;
  1241. }
  1242. }
  1243. }
  1244. else
  1245. {
  1246. //not support multi select for now;
  1247. }
  1248. }
  1249. else if([[addjson valueForKey:@"control"] isEqualToString:@"action" ])
  1250. {
  1251. NSMutableDictionary * action_data = [[addjson objectForKey:@"data"] mutableCopy];
  1252. int section_count=[[action_data valueForKey:@"section_count"] intValue];
  1253. if([required isEqualToString: @"true"] && action_data==nil)
  1254. {
  1255. self.cancommit = false;
  1256. NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,addjson[@"aname"]];
  1257. [fields addObject:mfield];
  1258. NSIndexPath* indexpath =[self get_indexpath1:[addjson valueForKey:@"name"]];
  1259. if(alert)
  1260. [self unhide_section:(int)indexpath.section];
  1261. if(fields.count==1)
  1262. {
  1263. self.first_miss_pos = indexpath;
  1264. }
  1265. }
  1266. for(int i=0;i<section_count;i++)
  1267. {
  1268. NSMutableDictionary * sectionjson = [[action_data objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1269. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  1270. for(int j=0;j<item_count;j++)
  1271. {
  1272. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1273. NSString* key = [itemjson valueForKey:@"name"];
  1274. if(key==nil || key.length==0)
  1275. continue;
  1276. if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  1277. {
  1278. NSString* single_select = [itemjson valueForKey:@"single_select"];
  1279. if([single_select isEqualToString:@"true"])
  1280. {
  1281. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  1282. int count = [[cadejson valueForKey:@"count"] intValue];
  1283. bool setvalue = false;
  1284. for(int cc=0;cc<count;cc++)
  1285. {
  1286. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  1287. if([[valjson valueForKey:@"check"]intValue]==1)
  1288. {
  1289. [upparam setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  1290. setvalue=true;
  1291. break;
  1292. }
  1293. }
  1294. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  1295. {
  1296. self.cancommit = false;
  1297. NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
  1298. [fields addObject:mfield];
  1299. NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
  1300. if(alert)
  1301. [self unhide_section:(int)indexpath.section];
  1302. if(fields.count==1)
  1303. {
  1304. self.first_miss_pos = indexpath;
  1305. }
  1306. }
  1307. }
  1308. else
  1309. {
  1310. //not support multi select for now;
  1311. }
  1312. /*
  1313. upparams setValue:itemjson forKey:<#(NSString *)#>
  1314. */
  1315. }
  1316. else
  1317. {
  1318. if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  1319. [upparam setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  1320. else
  1321. {
  1322. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  1323. {
  1324. self.cancommit = false;
  1325. NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,itemjson[@"aname"]];
  1326. [fields addObject:mfield];
  1327. NSIndexPath* indexpath =[self get_indexpath1:[itemjson valueForKey:@"name"]];
  1328. if(alert)
  1329. [self unhide_section:(int)indexpath.section];
  1330. if(fields.count==1)
  1331. {
  1332. self.first_miss_pos = indexpath;
  1333. }
  1334. }
  1335. }
  1336. }
  1337. subitem_data * data1=[self subitem_param:itemjson addto:upparam alert:alert];
  1338. upparam= data1.params;
  1339. fields=[[fields arrayByAddingObjectsFromArray:data1.missingfields] mutableCopy];
  1340. // upparam= [self subitem_param:itemjson addto:upparam ];
  1341. }
  1342. }
  1343. }
  1344. else
  1345. {
  1346. if([addjson valueForKey:@"value"]!=nil && ![[addjson valueForKey:@"value"]isEqualToString:@""])
  1347. [upparam setValue:[addjson valueForKey:@"value"] forKey:key];
  1348. else
  1349. {
  1350. if([[addjson valueForKey:@"required"] isEqualToString: @"true"] )
  1351. {
  1352. self.cancommit = false;
  1353. NSString* mfield =[NSString stringWithFormat:@"%ld. %@ is missing",fields.count+1,addjson[@"aname"]];
  1354. [fields addObject:mfield];
  1355. NSIndexPath* indexpath =[self get_indexpath1:[addjson valueForKey:@"name"]];
  1356. if(alert)
  1357. [self unhide_section:(int)indexpath.section];
  1358. if(fields.count==1)
  1359. {
  1360. self.first_miss_pos = indexpath;
  1361. }
  1362. }
  1363. }
  1364. }
  1365. subitem_data * data2=[self subitem_param:addjson addto:upparam alert:alert];
  1366. upparam= data2.params;
  1367. fields=[[fields arrayByAddingObjectsFromArray:data2.missingfields] mutableCopy];
  1368. //upparam=[self subitem_param:addjson addto:upparam];
  1369. // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
  1370. // item_count ++;
  1371. // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
  1372. }
  1373. //break;
  1374. }
  1375. }
  1376. }
  1377. data.params = upparam;
  1378. data.missingfields = fields;
  1379. return data;
  1380. }
  1381. -(NSMutableArray*) add_subitem:(NSDictionary*) itemjson addto:(NSMutableArray*) sectionarr parent:(NSString*) parent
  1382. {
  1383. NSString * control_type = [itemjson valueForKey:@"control"];
  1384. bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
  1385. if([control_type isEqual:@"enum"] && single_select)
  1386. {
  1387. NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
  1388. int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
  1389. for(int k=0;k<cade_count;k++)
  1390. {
  1391. NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
  1392. int check=[[valjson valueForKey:@"check"] intValue];
  1393. NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
  1394. bool active =[[valjson valueForKey:@"active"] boolValue];
  1395. if(check==1 && subjson!=nil && !active)
  1396. {
  1397. int sub_count = [[subjson valueForKey:@"count"] intValue];
  1398. for(int l=0;l<sub_count;l++)
  1399. {
  1400. NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  1401. NSString* subself=[NSString stringWithFormat:@"%@_%d_%d",parent,k,l ];
  1402. [addjson setValue:subself forKey:@"subid"];
  1403. [sectionarr addObject:addjson];
  1404. [self add_subitem:addjson addto:sectionarr parent:subself];
  1405. // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
  1406. // item_count ++;
  1407. // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
  1408. }
  1409. [valjson setValue:@"true" forKey:@"active"];
  1410. [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
  1411. //break;
  1412. }
  1413. }
  1414. }
  1415. else if([control_type isEqual:@"switch"])
  1416. {
  1417. NSString* value=[itemjson valueForKey:@"value"];
  1418. NSMutableDictionary* subjson=nil;
  1419. if([value isEqualToString:@"true"])
  1420. subjson=[[[itemjson objectForKey:@"true"] objectForKey:@"sub_item"] mutableCopy];// [ mutableCopy];
  1421. else
  1422. subjson=[[[itemjson objectForKey:@"false"] objectForKey:@"sub_item"] mutableCopy];
  1423. if( subjson!=nil /*&& !active*/)
  1424. {
  1425. int sub_count = [[subjson valueForKey:@"count"] intValue];
  1426. for(int l=0;l<sub_count;l++)
  1427. {
  1428. NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  1429. NSString* subself=[NSString stringWithFormat:@"%@_%d",parent,l ];
  1430. [addjson setValue:subself forKey:@"subid"];
  1431. [sectionarr addObject:addjson];
  1432. [self add_subitem:addjson addto:sectionarr parent:subself];
  1433. // [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
  1434. // item_count ++;
  1435. // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
  1436. }
  1437. // [valjson setValue:@"true" forKey:@"active"];
  1438. // [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
  1439. //break;
  1440. }
  1441. }
  1442. return sectionarr;
  1443. }
  1444. -(NSMutableArray*) translate_json: (NSDictionary*) injson changed:(NSDictionary*) changed_value
  1445. {
  1446. @synchronized(self)
  1447. {
  1448. if(injson == nil)
  1449. return nil;
  1450. NSMutableArray * retarray= [[NSMutableArray alloc]init];
  1451. int section_count=[[injson valueForKey:@"section_count"] intValue];
  1452. for(int i=0;i<section_count;i++)
  1453. {
  1454. NSMutableArray * sectionarr= [[NSMutableArray alloc]init];
  1455. NSMutableDictionary * sectionjson = [[injson objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1456. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  1457. for(int j=0;j<item_count;j++)
  1458. {
  1459. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1460. NSAssert(itemjson!=nil, @"Backend error, item is null section:%d item %d",i,item_count);
  1461. [sectionarr addObject:itemjson];
  1462. [self add_subitem:itemjson addto:sectionarr parent:[NSString stringWithFormat:@"%d_%d",i,j ]];
  1463. // [itemjson setObject:cadedatejson forKey:@"cadedate"];
  1464. // NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
  1465. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  1466. }
  1467. // [sectionjson setValue:[NSString stringWithFormat:@"%d",item_count ] forKey:@"count"];
  1468. // [retjson setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  1469. [retarray addObject:sectionarr];
  1470. }
  1471. NSLog(@"content control count = %ld",retarray.count);
  1472. return retarray;
  1473. // retjson setObject:sec forKey:<#(id<NSCopying>)#>
  1474. // return nil;
  1475. }
  1476. }
  1477. /*
  1478. -(NSMutableDictionary*) translate_json: (NSDictionary*) injson
  1479. {
  1480. if(injson == nil)
  1481. return nil;
  1482. NSMutableDictionary * retjson= [injson mutableCopy];
  1483. int section_count=[[retjson valueForKey:@"section_count"] intValue];
  1484. for(int i=0;i<section_count;i++)
  1485. {
  1486. NSMutableDictionary * sectionjson = [[retjson objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1487. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  1488. for(int j=0;j<item_count;j++)
  1489. {
  1490. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1491. NSString * control_type = [itemjson valueForKey:@"control"];
  1492. bool single_select = [[itemjson valueForKey:@"single_select"] boolValue];
  1493. if([control_type isEqual:@"enum"] && single_select)
  1494. {
  1495. NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
  1496. int cade_count = [[cadedatejson valueForKey:@"count"] intValue];
  1497. for(int k=0;k<cade_count;k++)
  1498. {
  1499. NSMutableDictionary * valjson=[[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",k ]] mutableCopy];
  1500. int check=[[valjson valueForKey:@"check"] intValue];
  1501. NSMutableDictionary * subjson=[[valjson objectForKey:@"sub_item"] mutableCopy];
  1502. bool active =[[valjson valueForKey:@"active"] boolValue];
  1503. if(check==1 && subjson!=nil && !active)
  1504. {
  1505. int sub_count = [[subjson valueForKey:@"count"] intValue];
  1506. for(int l=0;l<sub_count;l++)
  1507. {
  1508. NSMutableDictionary * addjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  1509. [addjson setValue:[NSString stringWithFormat:@"%d_%d_%d",i,j,k ] forKey:@"parent"];
  1510. [sectionjson setObject: addjson forKey:[NSString stringWithFormat:@"item_%d",item_count ]];
  1511. item_count ++;
  1512. // [addjson setValue:[NSString stringWithFormat:@"val_%d",k ]] forKey:@"parent"];
  1513. }
  1514. [valjson setValue:@"true" forKey:@"active"];
  1515. [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
  1516. //break;
  1517. }
  1518. if(check==0 && subjson!=nil)
  1519. {
  1520. int total_remove=0;
  1521. for(int r=0;r<item_count;r++)
  1522. {
  1523. NSMutableDictionary * removejson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",r ]] mutableCopy];
  1524. if(removejson==nil)
  1525. continue;
  1526. if([[removejson valueForKey:@"parent"] isEqualToString: [NSString stringWithFormat:@"%d_%d_%d",i,j,k ]])
  1527. {
  1528. [sectionjson removeObjectForKey:[NSString stringWithFormat:@"item_%d",r ]];
  1529. total_remove++;
  1530. // item_count--;
  1531. // r--;
  1532. }
  1533. else
  1534. {
  1535. [sectionjson removeObjectForKey:[NSString stringWithFormat:@"item_%d",r ]];
  1536. [sectionjson setObject:removejson forKey:[NSString stringWithFormat:@"item_%d",r-total_remove ]];
  1537. }
  1538. }
  1539. [valjson setValue:@"false" forKey:@"active"];
  1540. [cadedatejson setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",k ]];
  1541. item_count-=total_remove;
  1542. // remove sub item
  1543. //break;
  1544. }
  1545. }
  1546. [itemjson setObject:cadedatejson forKey:@"cadedate"];
  1547. // NSMutableDictionary * cadedatejson=[[itemjson objectForKey:@"cadedate"] mutableCopy];
  1548. }
  1549. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  1550. }
  1551. [sectionjson setValue:[NSString stringWithFormat:@"%d",item_count ] forKey:@"count"];
  1552. [retjson setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  1553. }
  1554. return retjson;
  1555. // retjson setObject:sec forKey:<#(id<NSCopying>)#>
  1556. return nil;
  1557. }*/
  1558. //- (void)onCloseClick:(UIButton *)sender {
  1559. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1560. // ;
  1561. // }];
  1562. //}
  1563. - (void)didReceiveMemoryWarning
  1564. {
  1565. [super didReceiveMemoryWarning];
  1566. // Dispose of any resources that can be recreated.
  1567. }
  1568. -(void) prepareReturn:(NSMutableDictionary*) value
  1569. {
  1570. if(value==nil)
  1571. value=[[NSMutableDictionary alloc]init];
  1572. value[@"is_subaction"] = self.params[@"is_subaction"];
  1573. value[@"subaction_tag"] = self.params[@"subaction_tag"];
  1574. if (self.delegate && [self.delegate respondsToSelector:@selector(returnValue:indexPath:)]) {
  1575. [self.delegate returnValue:value indexPath:self.from];
  1576. }
  1577. if(self.returnValue)
  1578. self.returnValue(nil);
  1579. }
  1580. -(void) handle_action_return:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath action:(int) action_code
  1581. {
  1582. DebugLog(@"commoneditor return %ld_%ld",(long)indexPath.section,(long)indexPath.row);
  1583. NSMutableDictionary* section_json=nil;
  1584. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1585. bool is_subaction = [value[@"is_subaction"] boolValue];
  1586. int subaction_tag= [value[@"subaction_tag"] intValue];
  1587. [value removeObjectForKey:@"is_subaction"];
  1588. [value removeObjectForKey:@"subaction_tag"];
  1589. if(is_subaction)
  1590. {
  1591. NSMutableDictionary* sub_action = [[item_json objectForKey:[NSString stringWithFormat:@"item_%d",subaction_tag]] mutableCopy];
  1592. int refresh = [[sub_action valueForKey:@"refresh"] intValue];
  1593. bool discardDirty = [[sub_action valueForKey:@"discard_dirty"] boolValue];
  1594. NSString* refresh_trigger = [sub_action valueForKey:@"name"];
  1595. NSDictionary * restore_json=[sub_action objectForKeyedSubscript:@"restore"];
  1596. NSString* subid=[sub_action valueForKey:@"subid"];
  1597. UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
  1598. NSString* required = [sub_action valueForKey:@"required"];
  1599. if([required isEqualToString:@"true"] && value.count==0)
  1600. {
  1601. CALayer *layer = [cell.contentView layer];
  1602. // layer.borderColor = [[UIColor redColor] CGColor];
  1603. // layer.borderWidth = 1.0;
  1604. layer.shadowColor = [UIColor redColor].CGColor;
  1605. layer.shadowOffset = CGSizeMake(0, 0);
  1606. layer.shadowOpacity = 1;
  1607. layer.shadowRadius = 2.0;
  1608. }
  1609. else
  1610. {
  1611. CALayer *layer = [cell.contentView layer];
  1612. // layer.borderColor = [[UIColor redColor] CGColor];
  1613. // layer.borderWidth = 1.0;
  1614. layer.shadowColor = [UIColor clearColor].CGColor;
  1615. layer.shadowOffset = CGSizeMake(0, 0);
  1616. layer.shadowOpacity = 1;
  1617. layer.shadowRadius = 2.0;
  1618. }
  1619. if(value.count!=0)
  1620. {
  1621. if(action_code==ACTION_SAVE_DATA)
  1622. {
  1623. [sub_action setObject:value forKey:@"data"];
  1624. if(subid==nil)
  1625. {
  1626. [sub_action setValue:@"true" forKey:@"dirty"];
  1627. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1628. int count=0;
  1629. count=[[section_json valueForKey:@"count"] intValue];
  1630. for(int i=0;i<count;i++)
  1631. {
  1632. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  1633. if([[olditem valueForKey:@"name"] isEqualToString:[sub_action valueForKey:@"name" ]])
  1634. {
  1635. // sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
  1636. [item_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
  1637. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  1638. }
  1639. }
  1640. }
  1641. else
  1642. {
  1643. NSAssert(true,@"not impl");
  1644. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  1645. int section = [(NSString*)idarr[0] intValue];
  1646. int item=[(NSString*)idarr[1] intValue];
  1647. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  1648. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  1649. sub_action= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:sub_action step:2];
  1650. [sub_action setValue:@"true" forKey:@"dirty"];
  1651. [item_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
  1652. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  1653. }
  1654. }
  1655. else if(action_code==ACTION_FILL_SECTION)
  1656. {
  1657. if(subid==nil)
  1658. {
  1659. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1660. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1661. int icount=[[section_json valueForKey:@"count"] intValue];
  1662. for (int ic=0;ic<icount;ic++)
  1663. {
  1664. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  1665. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  1666. NSString* valuestr= [value valueForKey:valuefrom];
  1667. if(valuestr !=nil)
  1668. {
  1669. [modify_item setValue:valuestr forKey:@"value"];
  1670. [modify_item setValue:@"true" forKey:@"dirty"];
  1671. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  1672. }
  1673. }
  1674. }
  1675. else
  1676. {
  1677. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  1678. int section = [(NSString*)idarr[0] intValue];
  1679. int item=[(NSString*)idarr[1] intValue];
  1680. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1681. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  1682. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  1683. NSMutableDictionary* olditem_sub_action = [[olditem objectForKey:[NSString stringWithFormat:@"item_%d",subaction_tag]] mutableCopy];
  1684. olditem_sub_action= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1685. [olditem_sub_action setValue:@"true" forKey:@"dirty"];
  1686. [olditem setObject:olditem_sub_action forKey:[NSString stringWithFormat:@"item_%d",[value[@"subaction_tag"] intValue]]];
  1687. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  1688. }
  1689. }
  1690. // [section_json setObject:sub_action forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  1691. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1692. }
  1693. DebugLog(@"CONTENT UPDATE:%@",[RAConvertor DataTOjsonString:self.content_data_download]);
  1694. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1695. if(refresh==1)
  1696. {
  1697. if(restore_json!=nil)
  1698. {
  1699. int rc=[[restore_json valueForKey:@"count"] intValue];
  1700. for(int ir=0;ir<rc;ir++)
  1701. {
  1702. NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  1703. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  1704. for(int i=0;i<section_count;i++)
  1705. {
  1706. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1707. // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1708. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  1709. for(int j=0;j<item_count;j++)
  1710. {
  1711. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1712. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1713. if([[itemjson valueForKey:@"name"] isEqualToString:name])
  1714. {
  1715. [itemjson removeObjectForKey:@"dirty"];
  1716. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  1717. }
  1718. }
  1719. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  1720. }
  1721. }
  1722. }
  1723. [self refresh:refresh_trigger discardDirty:discardDirty];
  1724. return ;
  1725. }
  1726. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  1727. [self.editorTable reloadData ];
  1728. }
  1729. else
  1730. {
  1731. int refresh = [[item_json valueForKey:@"refresh"] intValue];
  1732. bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
  1733. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  1734. NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  1735. NSString* subid=[item_json valueForKey:@"subid"];
  1736. UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
  1737. NSString* required = [item_json valueForKey:@"required"];
  1738. if([required isEqualToString:@"true"] && value.count==0)
  1739. {
  1740. CALayer *layer = [cell.contentView layer];
  1741. // layer.borderColor = [[UIColor redColor] CGColor];
  1742. // layer.borderWidth = 1.0;
  1743. layer.shadowColor = [UIColor redColor].CGColor;
  1744. layer.shadowOffset = CGSizeMake(0, 0);
  1745. layer.shadowOpacity = 1;
  1746. layer.shadowRadius = 2.0;
  1747. }
  1748. else
  1749. {
  1750. CALayer *layer = [cell.contentView layer];
  1751. // layer.borderColor = [[UIColor redColor] CGColor];
  1752. // layer.borderWidth = 1.0;
  1753. layer.shadowColor = [UIColor clearColor].CGColor;
  1754. layer.shadowOffset = CGSizeMake(0, 0);
  1755. layer.shadowOpacity = 1;
  1756. layer.shadowRadius = 2.0;
  1757. }
  1758. if(value.count!=0)
  1759. {
  1760. if(action_code==ACTION_SAVE_DATA)
  1761. {
  1762. [item_json setObject:value forKey:@"data"];
  1763. if(subid==nil)
  1764. {
  1765. [item_json setValue:@"true" forKey:@"dirty"];
  1766. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1767. int count=0;
  1768. count=[[section_json valueForKey:@"count"] intValue];
  1769. for(int i=0;i<count;i++)
  1770. {
  1771. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  1772. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  1773. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  1774. }
  1775. }
  1776. else
  1777. {
  1778. NSAssert(true,@"not impl");
  1779. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  1780. int section = [(NSString*)idarr[0] intValue];
  1781. int item=[(NSString*)idarr[1] intValue];
  1782. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  1783. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  1784. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  1785. [item_json setValue:@"true" forKey:@"dirty"];
  1786. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  1787. }
  1788. }
  1789. else if(action_code==ACTION_FILL_SECTION)
  1790. {
  1791. if(subid==nil)
  1792. {
  1793. NSDictionary* jsonmap=[item_json valueForKey:@"key_map"];
  1794. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1795. int icount=[[section_json valueForKey:@"count"] intValue];
  1796. for (int ic=0;ic<icount;ic++)
  1797. {
  1798. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  1799. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  1800. NSString* valuestr= [value valueForKey:valuefrom];
  1801. if(valuestr !=nil)
  1802. {
  1803. [modify_item setValue:valuestr forKey:@"value"];
  1804. [modify_item setValue:@"true" forKey:@"dirty"];
  1805. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  1806. }
  1807. }
  1808. }
  1809. else
  1810. {
  1811. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  1812. int section = [(NSString*)idarr[0] intValue];
  1813. int item=[(NSString*)idarr[1] intValue];
  1814. NSDictionary* jsonmap=[item_json valueForKey:@"key_map"];
  1815. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  1816. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  1817. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1818. [olditem setValue:@"true" forKey:@"dirty"];
  1819. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  1820. }
  1821. }
  1822. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  1823. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1824. }
  1825. DebugLog(@"CONTENT UPDATE:%@",[RAConvertor DataTOjsonString:self.content_data_download]);
  1826. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1827. if(refresh==1)
  1828. {
  1829. if(restore_json!=nil)
  1830. {
  1831. int rc=[[restore_json valueForKey:@"count"] intValue];
  1832. for(int ir=0;ir<rc;ir++)
  1833. {
  1834. NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  1835. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  1836. for(int i=0;i<section_count;i++)
  1837. {
  1838. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1839. // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1840. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  1841. for(int j=0;j<item_count;j++)
  1842. {
  1843. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1844. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1845. if([[itemjson valueForKey:@"name"] isEqualToString:name])
  1846. {
  1847. [itemjson removeObjectForKey:@"dirty"];
  1848. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  1849. }
  1850. }
  1851. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  1852. }
  1853. }
  1854. }
  1855. [self refresh:refresh_trigger discardDirty:discardDirty];
  1856. return ;
  1857. }
  1858. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  1859. [self.editorTable reloadData ];
  1860. }
  1861. }
  1862. -(NSString*) getValue:(NSString*)name
  1863. {
  1864. NSString* ret=nil;
  1865. for(int i=0;i<self.content_data_control.count;i++)
  1866. {
  1867. NSMutableArray* items=(NSMutableArray*)self.content_data_control[i];
  1868. for(int j=0;j<items.count;j++)
  1869. {
  1870. NSDictionary* item=items[j];
  1871. NSString* item_name=[item valueForKey:@"name"];
  1872. if([item_name isEqualToString:name])
  1873. {
  1874. NSString* control = [item valueForKey:@"control"];
  1875. if([control isEqualToString:@"enum"])
  1876. {
  1877. NSDictionary* cadedate = [item objectForKey:@"cadedate"];
  1878. int cc = [[cadedate valueForKey:@"count"] intValue];
  1879. for(int l=0;l<cc;l++)
  1880. {
  1881. NSDictionary* val_json=[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]];
  1882. if([[val_json valueForKey:@"check"]intValue]==1)
  1883. return [val_json valueForKey:@"value_id"];
  1884. }
  1885. }
  1886. else
  1887. return [item valueForKey:@"value"];
  1888. }
  1889. }
  1890. }
  1891. return ret;
  1892. }
  1893. - (id)downloadValueForKey:(NSString *)key_name {
  1894. __block id ret=nil;
  1895. [self.content_data_download enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  1896. if (![key isEqualToString:@"section_count"] && [key hasPrefix:@"section_"]) {
  1897. NSDictionary *section = (NSDictionary *)obj;
  1898. [section enumerateKeysAndObjectsUsingBlock:^(id _Nonnull item_key, id _Nonnull item_obj, BOOL * _Nonnull stop) {
  1899. if ([item_key hasPrefix:@"item_"]) {
  1900. NSDictionary* item= (NSDictionary *)item_obj;
  1901. NSString* item_name=[item valueForKey:@"name"];
  1902. if([item_name isEqualToString:key_name])
  1903. {
  1904. NSString* control = [item valueForKey:@"control"];
  1905. if([control isEqualToString:@"enum"])
  1906. {
  1907. NSDictionary* cadedate = [item objectForKey:@"cadedate"];
  1908. int cc = [[cadedate valueForKey:@"count"] intValue];
  1909. for(int l=0;l<cc;l++)
  1910. {
  1911. NSDictionary* val_json=[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]];
  1912. if([[val_json valueForKey:@"check"]intValue]==1)
  1913. ret = [val_json valueForKey:@"value_id"];
  1914. }
  1915. }
  1916. else
  1917. ret = [item valueForKey:@"value"];
  1918. }
  1919. }
  1920. }];
  1921. }
  1922. }];
  1923. return ret;
  1924. }
  1925. -(void) setValue:(NSString*)key value:(NSString*)val
  1926. {
  1927. // NSString* ret=nil;
  1928. for(int i=0;i<self.content_data_control.count;i++)
  1929. {
  1930. NSMutableArray* items=(NSMutableArray*)self.content_data_control[i];
  1931. for(int j=0;j<items.count;j++)
  1932. {
  1933. NSMutableDictionary* item=[items[j] mutableCopy];
  1934. NSString* item_name=[item valueForKey:@"name"];
  1935. NSUInteger ii[2] = {i,j};
  1936. NSIndexPath * indexPath= [NSIndexPath indexPathWithIndexes:ii length:2];
  1937. if([item_name isEqualToString:key])
  1938. {
  1939. NSString* control = [item valueForKey:@"control"];
  1940. if([control isEqualToString:@"enum"])
  1941. {
  1942. NSMutableDictionary* cadedate = [[item objectForKey:@"cadedate"] mutableCopy];
  1943. int cc = [[cadedate valueForKey:@"count"] intValue];
  1944. for(int l=0;l<cc;l++)
  1945. {
  1946. NSMutableDictionary* val_json=[[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]] mutableCopy];
  1947. if([[val_json valueForKey:@"value_id"] isEqualToString:val])
  1948. {
  1949. val_json[@"check"]=[NSNumber numberWithInt:1];
  1950. }
  1951. else
  1952. {
  1953. val_json[@"check"]=[NSNumber numberWithInt:0];
  1954. }
  1955. cadedate[[NSString stringWithFormat:@"val_%d",l]] = val_json;
  1956. // return [val_json valueForKey:@"value_id"];
  1957. }
  1958. // item[@"cadedate"] = cadedate;
  1959. [self setEnumValue:cadedate indexPath:indexPath];
  1960. }
  1961. else if([control isEqualToString:@"edit"])
  1962. {
  1963. [self textfieldSetValue:indexPath value:val];
  1964. }
  1965. }
  1966. }
  1967. }
  1968. [self.editorTable reloadData ];
  1969. // return ret;
  1970. }
  1971. -(void) textfieldSetValue:(NSIndexPath*) indexPath value:(NSString*) val
  1972. {
  1973. //用于会填 textfield 的值,textViewDidEndEditing 和 partial refresh 会调用。
  1974. // DebugLog(@"textFieldDidEndEditing");
  1975. // // UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  1976. // NSIndexPath * indexPath = self.lastedit_from;
  1977. //
  1978. NSMutableDictionary* section_json=nil;
  1979. val = [val stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  1980. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  1981. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1982. NSString* subid=[item_json valueForKey:@"subid"];
  1983. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  1984. [item_json setValue:@"true" forKey:@"dirty"];
  1985. [item_json setValue:val forKey:@"value"];
  1986. if([[item_json valueForKey:@"keyboard"] isEqualToString:@"number"])
  1987. {
  1988. float f = [ val floatValue];
  1989. [item_json setValue:[NSString stringWithFormat:@"%.2f",f] forKey:@"value"];
  1990. }
  1991. // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
  1992. if(subid==nil)
  1993. {
  1994. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1995. int count=0;
  1996. count=[[section_json valueForKey:@"count"] intValue];
  1997. for(int i=0;i<count;i++)
  1998. {
  1999. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  2000. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  2001. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  2002. }
  2003. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  2004. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  2005. int refresh = [[item_json valueForKey:@"refresh"] intValue];
  2006. bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
  2007. NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  2008. bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
  2009. if(refresh==1)
  2010. {
  2011. if(restore_json!=nil)
  2012. {
  2013. int rc=[[restore_json valueForKey:@"count"] intValue];
  2014. for(int ir=0;ir<rc;ir++)
  2015. {
  2016. NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  2017. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  2018. for(int i=0;i<section_count;i++)
  2019. {
  2020. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2021. // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2022. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  2023. for(int j=0;j<item_count;j++)
  2024. {
  2025. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2026. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2027. if([[itemjson valueForKey:@"name"] isEqualToString:name])
  2028. {
  2029. [itemjson removeObjectForKey:@"dirty"];
  2030. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  2031. }
  2032. }
  2033. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  2034. }
  2035. }
  2036. }
  2037. [self refresh:refresh_trigger discardDirty:discardDirty];
  2038. }
  2039. else if(partial_refresh)
  2040. {
  2041. NSString* name = [item_json valueForKey:@"name"] ;
  2042. NSString* url = [item_json valueForKey:@"data_interface"] ;
  2043. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2044. [params setValue:val forKey:name];
  2045. __weak typeof(self) weakself = self;
  2046. __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{
  2047. [RADataProvider request_commoneditor_partialrefresh:params url:url completionHandler:^(NSMutableDictionary *result) {
  2048. NSDictionary* editor_json =result;
  2049. [waitalert dismissViewControllerAnimated:YES completion:^{
  2050. if([[editor_json valueForKey:@"result"] intValue]==2)
  2051. {
  2052. int prcount = [[editor_json valueForKey:@"count"] intValue];
  2053. for(int ipr=0;ipr<prcount;ipr++)
  2054. {
  2055. NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
  2056. NSString* name = [pr_item valueForKey:@"name"];
  2057. NSString* value = [pr_item valueForKey:@"value"];
  2058. [weakself setValue:name value:value];
  2059. }
  2060. }
  2061. else if([[editor_json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE)
  2062. {
  2063. [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:nil];
  2064. }
  2065. else
  2066. {
  2067. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:weakself] ;
  2068. }
  2069. }];
  2070. }];
  2071. }];
  2072. self.alert = waitalert;
  2073. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2074. //
  2075. // NSDictionary* editor_json = [RANetwork commoneditor_partialrefresh:params url:url];
  2076. //
  2077. // dispatch_async(dispatch_get_main_queue(), ^{
  2078. //
  2079. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2080. //
  2081. //
  2082. // if([[editor_json valueForKey:@"result"] intValue]==2)
  2083. // {
  2084. //
  2085. // int prcount = [[editor_json valueForKey:@"count"] intValue];
  2086. // for(int ipr=0;ipr<prcount;ipr++)
  2087. // {
  2088. // NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
  2089. // NSString* name = [pr_item valueForKey:@"name"];
  2090. // NSString* value = [pr_item valueForKey:@"value"];
  2091. //
  2092. // [weakself setValue:name value:value];
  2093. // }
  2094. //
  2095. //
  2096. // }
  2097. // else
  2098. // {
  2099. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:weakself] ;
  2100. // }
  2101. //
  2102. //
  2103. // });
  2104. // });
  2105. }
  2106. self.lastedit = nil;
  2107. self.lastedit_from=nil;
  2108. return ;
  2109. }
  2110. else
  2111. {
  2112. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  2113. int section = [(NSString*)idarr[0] intValue];
  2114. int item=[(NSString*)idarr[1] intValue];
  2115. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  2116. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  2117. NSString* control_type= [olditem valueForKey:@"control"];
  2118. NSMutableDictionary* new_item=nil;
  2119. [item_json setValue:@"true" forKey:@"dirty"];
  2120. if([control_type isEqualToString:@"enum"])
  2121. new_item= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  2122. else if([control_type isEqualToString:@"switch"])
  2123. new_item= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  2124. [section_json setObject:new_item forKey:[NSString stringWithFormat:@"item_%d",item ]];
  2125. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  2126. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  2127. int refresh = [[item_json valueForKey:@"refresh"] intValue];
  2128. bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
  2129. NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  2130. bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
  2131. if(refresh==1)
  2132. {
  2133. if(restore_json!=nil)
  2134. {
  2135. int rc=[[restore_json valueForKey:@"count"] intValue];
  2136. for(int ir=0;ir<rc;ir++)
  2137. {
  2138. NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  2139. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  2140. for(int i=0;i<section_count;i++)
  2141. {
  2142. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2143. // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2144. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  2145. for(int j=0;j<item_count;j++)
  2146. {
  2147. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2148. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2149. if([[itemjson valueForKey:@"name"] isEqualToString:name])
  2150. {
  2151. [itemjson removeObjectForKey:@"dirty"];
  2152. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  2153. }
  2154. }
  2155. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  2156. }
  2157. }
  2158. }
  2159. [self refresh:refresh_trigger discardDirty:discardDirty];
  2160. }
  2161. else if(partial_refresh)
  2162. {
  2163. NSString* name = [item_json valueForKey:@"name"] ;
  2164. NSString* url = [item_json valueForKey:@"data_interface"] ;
  2165. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2166. [params setValue:val forKey:name];
  2167. __weak typeof(self) weakself = self;
  2168. __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{
  2169. [RADataProvider request_commoneditor_partialrefresh:params url:url completionHandler:^(NSMutableDictionary *result) {
  2170. NSDictionary* editor_json = result;
  2171. [waitalert dismissViewControllerAnimated:YES completion:^{
  2172. if([[editor_json valueForKey:@"result"] intValue]==2)
  2173. {
  2174. int prcount = [[editor_json valueForKey:@"count"] intValue];
  2175. for(int ipr=0;ipr<prcount;ipr++)
  2176. {
  2177. NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
  2178. NSString* name = [pr_item valueForKey:@"name"];
  2179. NSString* value = [pr_item valueForKey:@"value"];
  2180. [weakself setValue:name value:value];
  2181. }
  2182. }
  2183. else if([[editor_json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE)
  2184. {
  2185. [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:nil];
  2186. }
  2187. else
  2188. {
  2189. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:weakself] ;
  2190. }
  2191. }];
  2192. }];
  2193. }];
  2194. self.alert = waitalert;
  2195. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2196. //
  2197. // NSDictionary* editor_json = [RANetwork commoneditor_partialrefresh:params url:url];
  2198. //
  2199. // dispatch_async(dispatch_get_main_queue(), ^{
  2200. //
  2201. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2202. //
  2203. //
  2204. // if([[editor_json valueForKey:@"result"] intValue]==2)
  2205. // {
  2206. //
  2207. // int prcount = [[editor_json valueForKey:@"count"] intValue];
  2208. // for(int ipr=0;ipr<prcount;ipr++)
  2209. // {
  2210. // NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
  2211. // NSString* name = [pr_item valueForKey:@"name"];
  2212. // NSString* value = [pr_item valueForKey:@"value"];
  2213. //
  2214. // [weakself setValue:name value:value];
  2215. // }
  2216. //
  2217. // }
  2218. // else
  2219. // {
  2220. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:weakself] ;
  2221. // }
  2222. //
  2223. //
  2224. // });
  2225. // });
  2226. }
  2227. self.lastedit = nil;
  2228. self.lastedit_from=nil;
  2229. return;
  2230. }
  2231. // return [item valueForKey:@"value"];
  2232. }
  2233. -(void) unhide_section:(int)isection
  2234. {
  2235. NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",isection]] mutableCopy];
  2236. [section setValue:@"false" forKey:@"hide"];
  2237. [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%d",isection]];
  2238. }
  2239. -(NSIndexPath*) get_indexpath1:(NSString*)name
  2240. {
  2241. if(self.first_miss_pos!=nil)
  2242. return self.first_miss_pos;
  2243. NSIndexPath* ret=nil;
  2244. for(int i=0;i<self.content_data_control.count;i++)
  2245. {
  2246. NSMutableArray* items=(NSMutableArray*)self.content_data_control[i];
  2247. for(int j=0;j<items.count;j++)
  2248. {
  2249. NSDictionary* item=items[j];
  2250. NSString* item_name=[item valueForKey:@"name"];
  2251. if([item_name isEqualToString:name])
  2252. {
  2253. NSUInteger ii[2] = {i,j};
  2254. return [NSIndexPath indexPathWithIndexes:ii length:2];
  2255. }
  2256. }
  2257. }
  2258. return ret;
  2259. }
  2260. #pragma mark - hide section button clicked
  2261. - (void)HideSction:(UIButton *)sender {
  2262. NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)sender.tag]] mutableCopy];
  2263. bool hide = [[section valueForKey:@"hide"]boolValue];
  2264. if(hide)
  2265. {
  2266. [section setValue:@"false" forKey:@"hide"];
  2267. [sender setTitle:@"Show" forState:UIControlStateNormal];
  2268. }
  2269. else{
  2270. [section setValue:@"true" forKey:@"hide"];
  2271. [sender setTitle:@"Hide" forState:UIControlStateNormal];
  2272. }
  2273. [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%ld",(long)sender.tag]];
  2274. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  2275. // NSRange range = NSMakeRange(sender.tag, 1);
  2276. // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  2277. // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  2278. [self.editorTable reloadData];
  2279. }
  2280. #pragma mark - commoneditor delegate
  2281. -(void) returnValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  2282. {
  2283. [self handle_action_return:value indexPath:indexPath action:ACTION_SAVE_DATA];
  2284. // DebugLog(@"commoneditor return %d_%d",indexPath.section,indexPath.row);
  2285. //
  2286. // NSMutableDictionary* section_json=nil;
  2287. //
  2288. // NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  2289. //
  2290. //
  2291. //
  2292. // int refresh = [[item_json valueForKey:@"refresh"] intValue];
  2293. //
  2294. // NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  2295. //
  2296. //
  2297. //
  2298. // NSString* subid=[item_json valueForKey:@"subid"];
  2299. //
  2300. // UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
  2301. //
  2302. // NSString* required = [item_json valueForKey:@"required"];
  2303. // if([required isEqualToString:@"true"] && value==nil)
  2304. // {
  2305. // CALayer *layer = [cell.contentView layer];
  2306. // // layer.borderColor = [[UIColor redColor] CGColor];
  2307. // // layer.borderWidth = 1.0;
  2308. //
  2309. // layer.shadowColor = [UIColor redColor].CGColor;
  2310. // layer.shadowOffset = CGSizeMake(0, 0);
  2311. // layer.shadowOpacity = 1;
  2312. // layer.shadowRadius = 2.0;
  2313. // }
  2314. // else
  2315. // {
  2316. // CALayer *layer = [cell.contentView layer];
  2317. // // layer.borderColor = [[UIColor redColor] CGColor];
  2318. // // layer.borderWidth = 1.0;
  2319. //
  2320. // layer.shadowColor = [UIColor clearColor].CGColor;
  2321. // layer.shadowOffset = CGSizeMake(0, 0);
  2322. // layer.shadowOpacity = 1;
  2323. // layer.shadowRadius = 2.0;
  2324. // }
  2325. // if(value!=nil)
  2326. // {
  2327. // [item_json setObject:value forKey:@"data"];
  2328. //
  2329. //
  2330. // if(subid==nil)
  2331. // {
  2332. // [item_json setValue:@"true" forKey:@"dirty"];
  2333. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  2334. // int count=0;
  2335. //
  2336. // count=[[section_json valueForKey:@"count"] intValue];
  2337. //
  2338. // for(int i=0;i<count;i++)
  2339. // {
  2340. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  2341. // if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  2342. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  2343. //
  2344. //
  2345. // }
  2346. // }
  2347. // else
  2348. // {
  2349. // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  2350. // int section = [(NSString*)idarr[0] intValue];
  2351. // int item=[(NSString*)idarr[1] intValue];
  2352. //
  2353. //
  2354. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  2355. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  2356. // item_json= [self subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  2357. // [item_json setValue:@"true" forKey:@"dirty"];
  2358. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  2359. //
  2360. // }
  2361. //
  2362. //
  2363. // // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  2364. //
  2365. // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  2366. // }
  2367. //
  2368. // if(refresh==1)
  2369. // {
  2370. //
  2371. // if(restore_json!=nil)
  2372. // {
  2373. // int rc=[[restore_json valueForKey:@"count"] intValue];
  2374. // for(int ir=0;ir<rc;ir++)
  2375. // {
  2376. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  2377. //
  2378. //
  2379. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  2380. // for(int i=0;i<section_count;i++)
  2381. // {
  2382. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2383. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2384. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  2385. // for(int j=0;j<item_count;j++)
  2386. // {
  2387. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2388. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2389. //
  2390. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  2391. // {
  2392. // [itemjson removeObjectForKey:@"dirty"];
  2393. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  2394. // }
  2395. //
  2396. // }
  2397. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  2398. // }
  2399. //
  2400. //
  2401. // }
  2402. //
  2403. // }
  2404. // [self refresh] ;
  2405. // return ;
  2406. // }
  2407. //
  2408. //
  2409. // DebugLog(@"CONTENT UPDATE:%@",[iSalesNetwork DataTOjsonString:self.content_data_download]);
  2410. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  2411. //
  2412. //
  2413. // // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  2414. // [self.editorTable reloadData ];
  2415. }
  2416. #pragma mark - Table view data source
  2417. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  2418. //{
  2419. // return 0;
  2420. //}
  2421. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  2422. //{
  2423. // return 0;
  2424. //}
  2425. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  2426. //{
  2427. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  2428. // return myView;
  2429. //
  2430. //}
  2431. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  2432. //{
  2433. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  2434. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  2435. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 20, 10)];
  2436. //// titleLabel.textColor=[UIColor whiteColor];
  2437. //// titleLabel.backgroundColor = [UIColor clearColor];
  2438. //// if(section==0)
  2439. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  2440. //// else
  2441. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  2442. //// [titleLabel sizeToFit];
  2443. //// [myView addSubview:titleLabel];
  2444. ////
  2445. // return myView;
  2446. //}
  2447. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  2448. //
  2449. // switch (section) {
  2450. // case 0:
  2451. // {
  2452. // NSDictionary * section_json = [self.content_data objectForKey:@"info_section"];
  2453. // return [section_json valueForKey:@"title"] ;
  2454. // }
  2455. // case 1:
  2456. // {
  2457. // NSDictionary * section_json = [self.content_data objectForKey:@"model_section"];
  2458. // return [section_json valueForKey:@"title"] ;
  2459. // }
  2460. // default:
  2461. // return nil;
  2462. // }
  2463. //
  2464. //
  2465. //}
  2466. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  2467. NSMutableDictionary* section_json = [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section ]];
  2468. return [section_json valueForKey:@"title"];
  2469. }
  2470. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  2471. {
  2472. NSLog(@"numberOfSectionsInTableView = %ld",self.content_data_control.count);
  2473. // if(self.content_data_control.count>0)
  2474. // return 1;
  2475. return self.content_data_control.count;
  2476. // int section_count =[[self.content_data valueForKey:@"section_count"] intValue];
  2477. // return section_count;
  2478. }
  2479. //- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  2480. //{
  2481. // DebugLog(@"canMoveRowAtIndexPath");
  2482. //
  2483. // if([tableView numberOfRowsInSection:indexPath.section]>1)
  2484. // return true;
  2485. // else
  2486. // return false;
  2487. //}
  2488. //- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
  2489. //{
  2490. // NSMutableArray * from;
  2491. // NSMutableArray * to ;
  2492. // if(fromIndexPath.section==0)
  2493. // from = self.displayfields;
  2494. // else
  2495. // from = self.hidefields;
  2496. // if(toIndexPath.section==0)
  2497. // to = self.displayfields;
  2498. // else
  2499. // to = self.hidefields;
  2500. // id content=from[fromIndexPath.row];
  2501. // [from removeObjectAtIndex:fromIndexPath.row];
  2502. // [to insertObject:content atIndex:toIndexPath.row];
  2503. //
  2504. // [tableView reloadData];
  2505. //
  2506. //}
  2507. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  2508. {
  2509. // if(self.content_data_control.count>0)
  2510. // return 1;
  2511. NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy];
  2512. bool hide = [[sectionjson valueForKey:@"hide"]boolValue];
  2513. if(hide)
  2514. {
  2515. return 0;
  2516. // [sectionjson setValue:@"false" forKey:@"hide"];
  2517. // [sender setTitle:@"Show" forState:UIControlStateNormal];
  2518. }
  2519. else{
  2520. return ((NSMutableArray*)self.content_data_control[section]).count;
  2521. // [sectionjson setValue:@"true" forKey:@"hide"];
  2522. // [sender setTitle:@"Hide" forState:UIControlStateNormal];
  2523. }
  2524. // return 0;
  2525. // if(section==4)
  2526. // return 1;
  2527. // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section ]];
  2528. //
  2529. // return [[section_json valueForKey:@"count" ] intValue];
  2530. }
  2531. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  2532. {
  2533. if(section==0)
  2534. return 44;
  2535. return 33;
  2536. }
  2537. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  2538. //{
  2539. // return 0.5;
  2540. //}
  2541. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  2542. {
  2543. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  2544. NSString* control = [item_json valueForKey:@"control"];
  2545. NSString *model = [UIDevice currentDevice].model;
  2546. if ([model isEqualToString:@"iPhone"]) {
  2547. if([control isEqualToString:@"model"])
  2548. return 140;
  2549. else if([control isEqualToString:@"signature"])
  2550. return 200;
  2551. else if([control isEqualToString:@"text_view"])
  2552. return 180;
  2553. else if([control isEqualToString:@"img"])
  2554. return 240;
  2555. else if ([control isEqualToString:@"action"])
  2556. return 44;
  2557. else if ([control isEqualToString:@"text"])
  2558. return 80;
  2559. else if ([control isEqualToString:@"enum"])
  2560. return 80;
  2561. else if ([control isEqualToString:@"edit"])
  2562. return 80;
  2563. else if ([control isEqualToString:@"switch"])
  2564. return 80;
  2565. else if([control isEqualToString:@"multi_action"])
  2566. {
  2567. int count = [[item_json valueForKey:@"count"]intValue];
  2568. if (count <= 2) {
  2569. return 50;
  2570. } else {
  2571. return 100;
  2572. }
  2573. }
  2574. else if ([control isEqualToString:@"webview"]) {
  2575. id h_obj = [item_json objectForKey:@"height"];
  2576. CGFloat height = [h_obj floatValue];
  2577. if(height<44)
  2578. height=44;
  2579. return height;
  2580. }
  2581. else if ([control isEqualToString:@"banner"]) {
  2582. return 200;
  2583. }
  2584. return 80;
  2585. } else {
  2586. if([control isEqualToString:@"model"])
  2587. return 140;
  2588. else if([control isEqualToString:@"signature"])
  2589. return 140;
  2590. else if([control isEqualToString:@"text_view"])
  2591. return 140;
  2592. else if([control isEqualToString:@"img"])
  2593. return 123;
  2594. return 44;
  2595. }
  2596. }
  2597. //
  2598. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2599. {
  2600. bool readonly = [[self.content_data_download valueForKey:@"readonly"]boolValue];
  2601. // int d=0;
  2602. // if(indexPath.section==4)
  2603. // d=0;
  2604. // DebugLog(@"%d,%d",indexPath.section,indexPath.row);
  2605. // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  2606. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2607. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  2608. NSString* control = [item_json valueForKey:@"control"];
  2609. NSString* required = [item_json valueForKey:@"required"];
  2610. NSString *CellIdentifier = @"";
  2611. if([control isEqualToString:@"text_view"])
  2612. {
  2613. CellIdentifier = @"CommonEditorCellTextView";
  2614. CommonEditorCellTextView * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2615. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  2616. NSString* value =[item_json valueForKey:@"value"];
  2617. NSString* align =[item_json valueForKey:@"align"];
  2618. if([align isEqualToString:@"right"])
  2619. cell.textview.textAlignment= kCTTextAlignmentRight;
  2620. else
  2621. cell.textview.textAlignment =kCTTextAlignmentLeft;
  2622. int capital =[[item_json valueForKey:@"capital"] intValue];
  2623. switch (capital) {
  2624. case 1:
  2625. cell.textview.autocapitalizationType=UITextAutocapitalizationTypeWords;
  2626. break;
  2627. case 2:
  2628. cell.textview.autocapitalizationType=UITextAutocapitalizationTypeSentences;
  2629. break;
  2630. case 3:
  2631. cell.textview.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;
  2632. break;
  2633. default:
  2634. cell.textview.autocapitalizationType=UITextAutocapitalizationTypeWords;//UITextAutocapitalizationTypeNone;
  2635. break;
  2636. }
  2637. int disable = [[item_json valueForKey:@"disable"] intValue];
  2638. if(disable==1||readonly)
  2639. {
  2640. cell.textview.editable=NO;
  2641. // cell.textfield.backgroundColor = [UIColor lightGrayColor];
  2642. cell.textview.textColor= [UIColor lightGrayColor];
  2643. }
  2644. else
  2645. {
  2646. cell.textview.editable=YES;
  2647. cell.textview.textColor= [UIColor blackColor];
  2648. // cell.textfield.backgroundColor = [UIColor whiteColor];
  2649. }
  2650. // if([required isEqualToString:@"true"])
  2651. // {
  2652. // [title appendString:@"*"];
  2653. // }
  2654. cell.label_name.text=title;
  2655. if([required isEqualToString:@"true"])
  2656. {
  2657. [cell.label_name sizeToFit];
  2658. CGRect frame =cell.label_name.frame;
  2659. frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  2660. cell.starMark.frame = frame;
  2661. cell.starMark.hidden=false;
  2662. // [title appendString:@"*"];
  2663. // [title appendString:@"<font size=\"6\" >*</font>"];
  2664. // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  2665. }
  2666. else
  2667. {
  2668. [cell.label_name sizeToFit];
  2669. cell.starMark.hidden=true;
  2670. }
  2671. cell.textview.text = value;
  2672. cell.textview.delegate = self;
  2673. cell.accessoryType = UITableViewCellAccessoryNone;
  2674. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  2675. {
  2676. CALayer *layer = [cell.contentView layer];
  2677. // layer.borderColor = [[UIColor redColor] CGColor];
  2678. // layer.borderWidth = 1.0;
  2679. layer.shadowColor = [UIColor redColor].CGColor;
  2680. layer.shadowOffset = CGSizeMake(0, 0);
  2681. layer.shadowOpacity = 1;
  2682. layer.shadowRadius = 2.0;
  2683. }
  2684. else
  2685. {
  2686. CALayer *layer = [cell.contentView layer];
  2687. // layer.borderColor = [[UIColor redColor] CGColor];
  2688. // layer.borderWidth = 1.0;
  2689. layer.shadowColor = [UIColor clearColor].CGColor;
  2690. layer.shadowOffset = CGSizeMake(0, 0);
  2691. layer.shadowOpacity = 1;
  2692. }
  2693. cell.backgroundColor = [UIColor whiteColor];
  2694. return cell;
  2695. }else
  2696. if([control isEqualToString:@"img"])
  2697. {
  2698. CellIdentifier = @"CommonEditorCellImg";
  2699. CommonEditorCellImg * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2700. cell.touchImageView0.contentMode = UIViewContentModeScaleAspectFit;
  2701. cell.touchImageView1.contentMode = UIViewContentModeScaleAspectFit;
  2702. cell.touchImageView2.contentMode = UIViewContentModeScaleAspectFit;
  2703. NSString* title = [item_json valueForKey:@"aname"] ;
  2704. NSString* value =[item_json valueForKey:@"value"];
  2705. int disable = [[item_json valueForKey:@"disable"] intValue];
  2706. if(disable==1||readonly)
  2707. {
  2708. cell.editable=false;
  2709. }
  2710. else
  2711. cell.editable=true;
  2712. cell.labelTitle.text = title;
  2713. cell.labelDescription.text = value;
  2714. __weak typeof(self) weakself = self;
  2715. cell.imgChanged = ^(NSString* url_down,NSString* url_up,int index ,NSString* url_index)
  2716. {
  2717. // NSMutableDictionary* editjson = [item_json mutableCopy];
  2718. // editjson[@"img_url"]=url;
  2719. [weakself imgIsChanged:url_down url_up:url_up indexPath:indexPath index:index url_index:url_index];
  2720. };
  2721. {
  2722. NSString* img_url0 = [item_json valueForKey:@"img_url_0"];
  2723. if(img_url0.length>0)
  2724. {
  2725. NSString* img_url_up=[item_json valueForKey:@"img_url_aname_0"];
  2726. if(img_url_up.length==0)
  2727. img_url_up=@"";
  2728. cell.imgs[0]=img_url_up;
  2729. NSString* file_name=[img_url0 lastPathComponent];
  2730. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url0];
  2731. if(img_data!=nil)
  2732. {
  2733. UIImage * img =[UIImage imageWithData:img_data];
  2734. cell.touchImageView0.image=img;
  2735. cell.img_validate = true;
  2736. // [cell.touchImageView setImage:img forState:UIControlStateNormal];
  2737. }
  2738. else
  2739. {
  2740. // __weak typeof(self) weakself = self;
  2741. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2742. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url0]];
  2743. dispatch_async(dispatch_get_main_queue(), ^{
  2744. if(downloadimg_data!=nil)
  2745. {
  2746. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url0];
  2747. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2748. cell.touchImageView0.image=img;
  2749. cell.img_validate = true;
  2750. }
  2751. else
  2752. {
  2753. cell.touchImageView0.image=[UIImage imageNamed:@"notfound_s"];
  2754. cell.img_validate = false;
  2755. }
  2756. });
  2757. });
  2758. }
  2759. }
  2760. else
  2761. {
  2762. cell.touchImageView0.image=nil;
  2763. cell.imgs[0]=@"";
  2764. }
  2765. }
  2766. {
  2767. NSString* img_url1 = [item_json valueForKey:@"img_url_1"];
  2768. if(img_url1.length>0)
  2769. {
  2770. NSString* img_url_up=[item_json valueForKey:@"img_url_aname_1"];
  2771. if(img_url_up.length==0)
  2772. img_url_up=@"";
  2773. cell.imgs[1]=img_url_up;
  2774. NSString* file_name=[img_url1 lastPathComponent];
  2775. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url1];
  2776. if(img_data!=nil)
  2777. {
  2778. UIImage * img =[UIImage imageWithData:img_data];
  2779. cell.touchImageView1.image=img;
  2780. cell.img_validate = true;
  2781. // [cell.touchImageView setImage:img forState:UIControlStateNormal];
  2782. }
  2783. else
  2784. {
  2785. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2786. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url1]];
  2787. dispatch_async(dispatch_get_main_queue(), ^{
  2788. if(downloadimg_data!=nil)
  2789. {
  2790. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url1];
  2791. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2792. cell.touchImageView1.image=img;
  2793. cell.img_validate = true;
  2794. }
  2795. else
  2796. {
  2797. cell.touchImageView1.image=[UIImage imageNamed:@"notfound_s"] ;
  2798. cell.img_validate = false;
  2799. }
  2800. });
  2801. });
  2802. }
  2803. }
  2804. else
  2805. {
  2806. cell.touchImageView1.image=nil;
  2807. cell.imgs[1]=@"";
  2808. }
  2809. }
  2810. {
  2811. NSString* img_url2 = [item_json valueForKey:@"img_url_2"];
  2812. if(img_url2.length>0)
  2813. {
  2814. NSString* img_url_up=[item_json valueForKey:@"img_url_aname_2"];
  2815. if(img_url_up.length==0)
  2816. img_url_up=@"";
  2817. cell.imgs[2]=img_url_up;
  2818. NSString* file_name=[img_url2 lastPathComponent];
  2819. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url2];
  2820. if(img_data!=nil)
  2821. {
  2822. UIImage * img =[UIImage imageWithData:img_data];
  2823. cell.touchImageView2.image=img;
  2824. cell.img_validate = true;
  2825. // [cell.touchImageView setImage:img forState:UIControlStateNormal];
  2826. }
  2827. else
  2828. {
  2829. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2830. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url2]];
  2831. dispatch_async(dispatch_get_main_queue(), ^{
  2832. if(downloadimg_data!=nil)
  2833. {
  2834. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url2];
  2835. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2836. cell.touchImageView2.image=img;
  2837. cell.img_validate = true;
  2838. }
  2839. else
  2840. {
  2841. cell.touchImageView2.image=[UIImage imageNamed:@"notfound_s"] ;
  2842. cell.img_validate = false;
  2843. }
  2844. });
  2845. });
  2846. }}
  2847. else
  2848. {
  2849. cell.touchImageView2.image=nil;
  2850. cell.imgs[2]=@"";
  2851. }
  2852. }
  2853. cell.backgroundColor = [UIColor whiteColor];
  2854. return cell;
  2855. }else
  2856. if([control isEqualToString:@"edit"])
  2857. {
  2858. CellIdentifier = @"CommonEditorCellEdit";
  2859. CommonEditorCellEdit * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2860. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  2861. // title =[[NSString stringWithFormat:@"<font size=\"5\" face=\"Helvetica\">%@</font>",title] mutableCopy];
  2862. NSString* value =[item_json valueForKey:@"value"];
  2863. NSString* align =[item_json valueForKey:@"align"];
  2864. if([align isEqualToString:@"right"])
  2865. cell.textfield.textAlignment= NSTextAlignmentRight;
  2866. else
  2867. cell.textfield.textAlignment =NSTextAlignmentLeft;
  2868. int capital =[[item_json valueForKey:@"capital"] intValue];
  2869. switch (capital) {
  2870. case 1:
  2871. cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeWords;
  2872. break;
  2873. case 2:
  2874. cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeSentences;
  2875. break;
  2876. case 3:
  2877. cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;
  2878. break;
  2879. default:
  2880. cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeWords;//UITextAutocapitalizationTypeNone;
  2881. break;
  2882. }
  2883. int disable = [[item_json valueForKey:@"disable"] intValue];
  2884. if(disable==1||readonly)
  2885. {
  2886. cell.textfield.enabled=NO;
  2887. // cell.textfield.backgroundColor = [UIColor lightGrayColor];
  2888. cell.textfield.textColor= [UIColor lightGrayColor];
  2889. }
  2890. else
  2891. {
  2892. cell.textfield.enabled=YES;
  2893. cell.textfield.textColor= [UIColor blackColor];
  2894. // cell.textfield.backgroundColor = [UIColor whiteColor];
  2895. }
  2896. NSString* keyboard = [item_json valueForKey:@"keyboard"];
  2897. if([keyboard isEqualToString:@"number"])
  2898. {
  2899. // float f = [value floatValue];
  2900. // value = [NSString stringWithFormat:@"%.2f",f];
  2901. cell.textfield.keyboardType=UIKeyboardTypeDecimalPad;
  2902. // cell.textfield.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
  2903. }
  2904. else if([keyboard isEqualToString:@"int"])
  2905. {
  2906. // float f = [value floatValue];
  2907. // value = [NSString stringWithFormat:@"%.2f",f];
  2908. cell.textfield.keyboardType=UIKeyboardTypeNumberPad;
  2909. // cell.textfield.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
  2910. }
  2911. else if([keyboard isEqualToString:@"email"])
  2912. {
  2913. cell.textfield.keyboardType=UIKeyboardTypeEmailAddress;
  2914. }
  2915. else if([keyboard isEqualToString:@"phone"])
  2916. {
  2917. cell.textfield.keyboardType=UIKeyboardTypePhonePad;
  2918. }
  2919. else
  2920. {
  2921. cell.textfield.keyboardType=UIKeyboardTypeDefault;
  2922. }
  2923. // UIKIT_EXTERN NSString * const NSPlainTextDocumentType NS_AVAILABLE(10_0, 7_0);
  2924. // UIKIT_EXTERN NSString * const NSRTFTextDocumentType NS_AVAILABLE(10_0, 7_0);
  2925. // UIKIT_EXTERN NSString * const NSRTFDTextDocumentType NS_AVAILABLE(10_0, 7_0);
  2926. // UIKIT_EXTERN NSString * const NSHTMLTextDocumentType NS_AVAILABLE(10_0, 7_0);
  2927. //
  2928. // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[title dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
  2929. // UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];
  2930. // myLabel.attributedText = attrStr;
  2931. // cell.labelTitle.attributedText = attrStr;
  2932. cell.labelTitle.text=title;
  2933. if([required isEqualToString:@"true"])
  2934. {
  2935. [cell.labelTitle sizeToFit];
  2936. CGRect frame =cell.labelTitle.frame;
  2937. frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  2938. cell.starMark.frame = frame;
  2939. cell.starMark.hidden=false;
  2940. // [title appendString:@"*"];
  2941. // [title appendString:@"<font size=\"6\" >*</font>"];
  2942. // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  2943. }
  2944. else
  2945. {
  2946. [cell.labelTitle sizeToFit];
  2947. cell.starMark.hidden=true;
  2948. }
  2949. cell.textfield.text = value;
  2950. cell.textfield.delegate = self;
  2951. cell.accessoryType = UITableViewCellAccessoryNone;
  2952. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  2953. {
  2954. CALayer *layer = cell.labelTitle.layer;
  2955. // layer.borderColor = [[UIColor redColor] CGColor];
  2956. // layer.borderWidth = 1.0;
  2957. layer.shadowColor = [UIColor redColor].CGColor;
  2958. layer.shadowOffset = CGSizeMake(0, 0);
  2959. layer.shadowOpacity = 1;
  2960. layer.shadowRadius = 2.0;
  2961. layer = cell.starMark.layer;
  2962. // layer.borderColor = [[UIColor redColor] CGColor];
  2963. // layer.borderWidth = 1.0;
  2964. layer.shadowColor = [UIColor redColor].CGColor;
  2965. layer.shadowOffset = CGSizeMake(0, 0);
  2966. layer.shadowOpacity = 1;
  2967. layer.shadowRadius = 2.0;
  2968. //UIImageView * iv =
  2969. cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_attention_24"]];
  2970. cell.textfield.rightViewMode=UITextFieldViewModeUnlessEditing;
  2971. cell.textfield.layer.cornerRadius=8.0f;
  2972. cell.textfield.layer.borderWidth= 1.0f;
  2973. cell.textfield.layer.masksToBounds=YES;
  2974. cell.textfield.layer.borderColor=[[UIColor redColor]CGColor];
  2975. }
  2976. else
  2977. {
  2978. CALayer *layer = cell.labelTitle.layer;//[cell.contentView layer];
  2979. // layer.borderColor = [[UIColor redColor] CGColor];
  2980. // layer.borderWidth = 1.0;
  2981. layer.shadowColor = [UIColor clearColor].CGColor;
  2982. layer.shadowOffset = CGSizeMake(0, 0);
  2983. layer.shadowOpacity = 1;
  2984. layer = cell.starMark.layer;//[cell.contentView layer];
  2985. // layer.borderColor = [[UIColor redColor] CGColor];
  2986. // layer.borderWidth = 1.0;
  2987. layer.shadowColor = [UIColor clearColor].CGColor;
  2988. layer.shadowOffset = CGSizeMake(0, 0);
  2989. layer.shadowOpacity = 1;
  2990. cell.textfield.rightViewMode=UITextFieldViewModeNever;
  2991. //cell.textfield.layer.borderColor= [[UIColor lightGrayColor] CGColor];
  2992. cell.textfield.rightView = nil;
  2993. cell.textfield.layer.cornerRadius=8.0f;
  2994. cell.textfield.layer.borderWidth= 1.0f;
  2995. cell.textfield.layer.masksToBounds=YES;
  2996. cell.textfield.layer.borderColor=[[UIColor lightGrayColor]CGColor];
  2997. }
  2998. cell.backgroundColor = [UIColor whiteColor];
  2999. return cell;
  3000. }
  3001. else
  3002. if([control isEqualToString:@"text"])
  3003. {
  3004. CellIdentifier = @"CommonEditorCellLabel";
  3005. CommonEditorCellLabel * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3006. //CGRect titleframe = cell.labelTitle.frame;
  3007. NSString* title = [item_json valueForKey:@"aname"] ;
  3008. NSString* value =[item_json valueForKey:@"value"];
  3009. NSString* color =[item_json valueForKey:@"color"];
  3010. cell.labelValue.textColor = [RAUtils strColor:color];
  3011. NSString* align =[item_json valueForKey:@"align"];
  3012. if([align isEqualToString:@"right"])
  3013. {
  3014. cell.labelTitle.frame =CGRectMake(15,11,350,21);
  3015. cell.labelValue.textAlignment= NSTextAlignmentRight;
  3016. }
  3017. else
  3018. {
  3019. cell.labelTitle.frame =CGRectMake(15,11,150,21);
  3020. cell.labelValue.textAlignment =NSTextAlignmentLeft;
  3021. }
  3022. NSString* type=[item_json valueForKey:@"type"] ;
  3023. // 此处应移动到erp mobile 项目内
  3024. if([type isEqualToString:@"price"])
  3025. {
  3026. BOOL can_see_price = [[RASingleton.sharedInstance globalParameterForKey:@"can_see_price"] boolValue];
  3027. BOOL price_hidden = [[RASingleton.sharedInstance globalParameterForKey:@"price_hidden"] boolValue];
  3028. if(can_see_price&&price_hidden==false)
  3029. {
  3030. }
  3031. else
  3032. {
  3033. value=nil;
  3034. }
  3035. }
  3036. cell.labelTitle.text=title;
  3037. cell.labelValue.text = value;
  3038. cell.backgroundColor = [UIColor whiteColor];
  3039. return cell;
  3040. }
  3041. else
  3042. if([control isEqualToString:@"action"])
  3043. {
  3044. CellIdentifier = @"CommonEditorCellAction";
  3045. CommonEditorCellAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3046. int disable = [[item_json valueForKey:@"disable"] intValue];
  3047. if(disable==1||readonly)
  3048. {
  3049. cell.labelAction.textColor= [UIColor lightGrayColor];
  3050. }
  3051. else
  3052. {
  3053. cell.labelAction.textColor= [UIColor blackColor];
  3054. }
  3055. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  3056. NSString* value =[item_json valueForKey:@"value"];
  3057. if([required isEqualToString:@"true"])
  3058. {
  3059. [title appendString:@"*"];
  3060. }
  3061. NSDictionary* data = [item_json objectForKey:@"data"];
  3062. cell.labelAction.text=title;
  3063. cell.action_code = value;
  3064. //cell.labelValue.text = value;
  3065. if(self.cancommit==false && [required isEqualToString:@"true"] && (data==nil))
  3066. {
  3067. CALayer *layer = [cell.contentView layer];
  3068. // layer.borderColor = [[UIColor redColor] CGColor];
  3069. // layer.borderWidth = 1.0;
  3070. layer.shadowColor = [UIColor redColor].CGColor;
  3071. layer.shadowOffset = CGSizeMake(0, 0);
  3072. layer.shadowOpacity = 1;
  3073. layer.shadowRadius = 2.0;
  3074. }
  3075. else
  3076. {
  3077. CALayer *layer = [cell.contentView layer];
  3078. // layer.borderColor = [[UIColor redColor] CGColor];
  3079. // layer.borderWidth = 1.0;
  3080. layer.shadowColor = [UIColor clearColor].CGColor;
  3081. layer.shadowOffset = CGSizeMake(0, 0);
  3082. layer.shadowOpacity = 1;
  3083. }
  3084. cell.backgroundColor = [UIColor whiteColor];
  3085. return cell;
  3086. }
  3087. if([control isEqualToString:@"multi_action"])
  3088. {
  3089. CellIdentifier = @"CommonEditorCellMAction";
  3090. CommonEditorCellMAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3091. int count = [[item_json valueForKey:@"count"]intValue];
  3092. for(int i=0;i<count;i++)
  3093. {
  3094. NSDictionary* sub_action= [item_json objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  3095. NSString * title = [sub_action valueForKey:@"aname"];
  3096. switch (i) {
  3097. case 0:
  3098. [cell.btn_action0 setTitle:title forState:UIControlStateNormal];
  3099. [cell.btn_action0 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
  3100. cell.btn_action0.hidden = NO;
  3101. break;
  3102. case 1:
  3103. [cell.btn_action1 setTitle:title forState:UIControlStateNormal];
  3104. [cell.btn_action1 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
  3105. cell.btn_action1.hidden = NO;
  3106. break;
  3107. case 2:
  3108. [cell.btn_action2 setTitle:title forState:UIControlStateNormal];
  3109. [cell.btn_action2 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
  3110. cell.btn_action2.hidden = NO;
  3111. break;
  3112. case 3:
  3113. [cell.btn_action3 setTitle:title forState:UIControlStateNormal];
  3114. [cell.btn_action3 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
  3115. cell.btn_action3.hidden = NO;
  3116. break;
  3117. default:
  3118. break;
  3119. }
  3120. }
  3121. if (count<4)
  3122. cell.btn_action3.hidden=YES;
  3123. if (count<3)
  3124. cell.btn_action2.hidden=YES;
  3125. if (count<2)
  3126. cell.btn_action1.hidden=YES;
  3127. if (count<1)
  3128. cell.btn_action0.hidden=YES;
  3129. // NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  3130. // NSString* value =[item_json valueForKey:@"value"];
  3131. // if([required isEqualToString:@"true"])
  3132. // {
  3133. // [title appendString:@"*"];
  3134. // }
  3135. // NSDictionary* data = [item_json objectForKey:@"data"];
  3136. //
  3137. // cell.labelAction.text=title;
  3138. // cell.action_code = value;
  3139. //
  3140. //
  3141. // //cell.labelValue.text = value;
  3142. //
  3143. // if(self.cancommit==false && [required isEqualToString:@"true"] && (data==nil))
  3144. // {
  3145. // CALayer *layer = [cell.contentView layer];
  3146. // // layer.borderColor = [[UIColor redColor] CGColor];
  3147. // // layer.borderWidth = 1.0;
  3148. //
  3149. // layer.shadowColor = [UIColor redColor].CGColor;
  3150. // layer.shadowOffset = CGSizeMake(0, 0);
  3151. // layer.shadowOpacity = 1;
  3152. // layer.shadowRadius = 2.0;
  3153. // }
  3154. cell.backgroundColor = [UIColor whiteColor];
  3155. return cell;
  3156. }
  3157. else
  3158. if([control isEqualToString:@"switch"])
  3159. {
  3160. CellIdentifier = @"CommonEditorCellSwitch";
  3161. CommonEditorCellSwitch * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3162. NSString* title = [item_json valueForKey:@"aname"];
  3163. NSString* value =[item_json valueForKey:@"value"];
  3164. cell.labelTitle.text=title;
  3165. int disabble = [[item_json objectForKey:@"disable"] intValue];
  3166. if (disabble==1 || readonly) {
  3167. cell.switchCtrl.enabled = NO;
  3168. } else {
  3169. cell.switchCtrl.enabled = YES;
  3170. }
  3171. if([required isEqualToString:@"true"])
  3172. {
  3173. [cell.labelTitle sizeToFit];
  3174. CGRect frame =cell.labelTitle.frame;
  3175. frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  3176. cell.starMark.frame = frame;
  3177. cell.starMark.hidden=false;
  3178. // CGSize asize=[cell.labelTitle sizeThatFits:cell.labelTitle.frame.size];
  3179. //
  3180. // cell.starMark.frame = CGRectMake(cell.labelTitle.frame.origin.x+asize.width, cell.labelTitle.frame.origin.y, 10, 21);
  3181. // cell.starMark.hidden=false;
  3182. // [title appendString:@"*"];
  3183. // [title appendString:@"<font size=\"6\" >*</font>"];
  3184. // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  3185. }
  3186. else
  3187. {
  3188. [cell.labelTitle sizeToFit];
  3189. cell.starMark.hidden=true;
  3190. }
  3191. [cell.switchCtrl addTarget:self
  3192. action:@selector(switchIsChanged:)
  3193. forControlEvents:UIControlEventValueChanged];
  3194. if([[value lowercaseString] isEqualToString:@"true"])
  3195. cell.switchCtrl.on = true;
  3196. else
  3197. cell.switchCtrl.on = false;
  3198. cell.accessoryType = UITableViewCellAccessoryNone;
  3199. cell.backgroundColor = [UIColor whiteColor];
  3200. return cell;
  3201. }
  3202. else if([control isEqualToString:@"editor"])
  3203. {
  3204. CellIdentifier = @"CommonEditorCellEditor";
  3205. CommonEditorCellEditor * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3206. NSString* title = [[item_json valueForKey:@"aname"] stringValue];
  3207. NSString* value = [[item_json valueForKey:@"value"] stringValue];
  3208. int disable = [[item_json valueForKey:@"disable"] intValue];
  3209. if(disable==1||readonly)
  3210. {
  3211. cell.labelValue.textColor= [UIColor lightGrayColor];
  3212. }
  3213. else
  3214. {
  3215. cell.labelValue.textColor= [UIColor blackColor];
  3216. // cell.textfield.backgroundColor = [UIColor whiteColor];
  3217. }
  3218. NSString* align =[item_json valueForKey:@"align"];
  3219. if([align isEqualToString:@"right"])
  3220. cell.labelValue.textAlignment= NSTextAlignmentRight;
  3221. else
  3222. cell.labelValue.textAlignment =NSTextAlignmentLeft;
  3223. cell.labelName.text=title;
  3224. cell.labelValue.text=value;
  3225. // if([required isEqualToString:@"true"])
  3226. // {
  3227. // [cell.labelTitle sizeToFit];
  3228. // CGRect frame =cell.labelTitle.frame;
  3229. // frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  3230. // cell.starMark.frame = frame;
  3231. // cell.starMark.hidden=false;
  3232. // // [title appendString:@"*"];
  3233. //
  3234. // // [title appendString:@"<font size=\"6\" >*</font>"];
  3235. // // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  3236. // }
  3237. // else
  3238. // {
  3239. // [cell.labelTitle sizeToFit];
  3240. // cell.starMark.hidden=true;
  3241. // }
  3242. cell.backgroundColor = [UIColor whiteColor];
  3243. return cell;
  3244. }
  3245. else if([control isEqualToString:@"enum"])
  3246. {
  3247. CellIdentifier = @"CommonEditorCellEnum";
  3248. CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3249. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  3250. NSDictionary* cadedate_json =[item_json objectForKey:@"cadedate"];
  3251. int disable = [[item_json valueForKey:@"disable"] intValue];
  3252. if(disable==1||readonly)
  3253. {
  3254. cell.labelValue.textColor= [UIColor lightGrayColor];
  3255. }
  3256. else
  3257. {
  3258. cell.labelValue.textColor= [UIColor blackColor];
  3259. // cell.textfield.backgroundColor = [UIColor whiteColor];
  3260. }
  3261. NSString* align =[item_json valueForKey:@"align"];
  3262. if([align isEqualToString:@"right"])
  3263. cell.labelValue.textAlignment= NSTextAlignmentRight;
  3264. else
  3265. cell.labelValue.textAlignment =NSTextAlignmentLeft;
  3266. // if([required isEqualToString:@"true"])
  3267. // {
  3268. // [title appendString:@"*"];
  3269. // }
  3270. NSString* value =@"";
  3271. int count = [[cadedate_json valueForKey:@"count"] intValue];
  3272. for(int i=0;i<count;i++)
  3273. {
  3274. NSDictionary* val_json =[cadedate_json objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  3275. int check = [[val_json valueForKey:@"check"] intValue];
  3276. if(check==1)
  3277. {
  3278. value = [value stringByAppendingString:[val_json valueForKey:@"value"]];
  3279. value = [value stringByAppendingString:@"|"];
  3280. }
  3281. }
  3282. if(value.length>=1)
  3283. value=[value substringToIndex:value.length-1];
  3284. cell.labelTitle.text=title;
  3285. if([required isEqualToString:@"true"])
  3286. {
  3287. [cell.labelTitle sizeToFit];
  3288. CGRect frame =cell.labelTitle.frame;
  3289. frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  3290. cell.starMark.frame = frame;
  3291. cell.starMark.hidden=false;
  3292. // [title appendString:@"*"];
  3293. // [title appendString:@"<font size=\"6\" >*</font>"];
  3294. // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  3295. }
  3296. else
  3297. {
  3298. [cell.labelTitle sizeToFit];
  3299. cell.starMark.hidden=true;
  3300. }
  3301. cell.labelValue.text = value;
  3302. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  3303. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  3304. {
  3305. CALayer *layer = [cell.contentView layer];
  3306. // layer.borderColor = [[UIColor redColor] CGColor];
  3307. // layer.borderWidth = 1.0;
  3308. layer.shadowColor = [UIColor redColor].CGColor;
  3309. layer.shadowOffset = CGSizeMake(0, 0);
  3310. layer.shadowOpacity = 1;
  3311. layer.shadowRadius = 2.0;
  3312. }
  3313. else
  3314. {
  3315. CALayer *layer = [cell.contentView layer];
  3316. // layer.borderColor = [[UIColor redColor] CGColor];
  3317. // layer.borderWidth = 1.0;
  3318. layer.shadowColor = [UIColor clearColor].CGColor;
  3319. layer.shadowOffset = CGSizeMake(0, 0);
  3320. layer.shadowOpacity = 1;
  3321. }
  3322. cell.backgroundColor = [UIColor whiteColor];
  3323. return cell;
  3324. } else if([control isEqualToString:@"model"])
  3325. {
  3326. CommonEditorCellModel * cell= [tableView dequeueReusableCellWithIdentifier:@"CommonEditorCellModel" forIndexPath:indexPath];
  3327. int count = [[item_json valueForKey:@"count"] intValue];
  3328. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  3329. cell.bundle_item=combine_json;
  3330. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  3331. if (cell.masterBtn != nil) {
  3332. if (master_json == nil) {
  3333. cell.masterBtn.hidden = YES;
  3334. } else{
  3335. cell.masterBtn.hidden = NO;
  3336. cell.master_items = master_json;
  3337. }
  3338. }
  3339. double dprice=0.0;
  3340. if(cell.bundle_item!=nil)
  3341. {
  3342. int citem=0;
  3343. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  3344. for(int bc=0;bc<bcount;bc++)
  3345. {
  3346. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  3347. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  3348. citem+= modulus;
  3349. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  3350. dprice+= uprice*modulus;
  3351. }
  3352. if(citem==1)
  3353. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  3354. else
  3355. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  3356. cell.buttonBundle.hidden = NO;
  3357. }
  3358. else
  3359. {
  3360. cell.buttonBundle.hidden = YES;
  3361. }
  3362. NSString *availability = [item_json objectForKey:@"quantity_available"];
  3363. NSString *available_str = @"Available Now";
  3364. if ([availability integerValue] > 0) {
  3365. available_str = [NSString stringWithFormat:@"Available: %@",availability];
  3366. } else {
  3367. // available_str = @"Available: In Production";
  3368. available_str = @"Available: Out of Stock";
  3369. }
  3370. cell.avalibilityLabel.text = available_str;
  3371. NSString* img_url = [item_json valueForKey:@"img_url"];
  3372. NSString* description = [item_json valueForKey:@"description"];
  3373. // NSString* identifier = [item_json valueForKey:@"identifier"];
  3374. // NSString* attribute = [item_json valueForKey:@"attribute"];
  3375. // NSString* total_price = [item_json valueForKey:@"total_price"] ;
  3376. // NSString* unit_price = [item_json valueForKey:@"unit_price"] ;
  3377. // NSString* mp = [item_json valueForKey:@"stockUom"];
  3378. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  3379. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  3380. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  3381. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  3382. NSString* oldprice =[NSString stringWithFormat:@"%.2f",unitprice];
  3383. NSString* newunitprice=@"";
  3384. if(dprice>0)
  3385. newunitprice = [NSString stringWithFormat:@"%.2f+%.2f",unitprice* (1.0-discount/100),dprice];
  3386. else
  3387. newunitprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)];
  3388. NSString* totalprice = [NSString stringWithFormat:@"%.2f",(unitprice* (1.0-discount/100)+dprice)*count];
  3389. BOOL can_see_price = [[RASingleton.sharedInstance globalParameterForKey:@"can_see_price"] boolValue];
  3390. BOOL price_hidden = [[RASingleton.sharedInstance globalParameterForKey:@"price_hidden"] boolValue];
  3391. if(can_see_price&&price_hidden==false)
  3392. {
  3393. }
  3394. else
  3395. {
  3396. oldprice=nil;
  3397. newunitprice=nil;
  3398. totalprice=nil;
  3399. }
  3400. cell.labelDiscount.text = discountstr;
  3401. cell.labelOldPrice.text = oldprice;
  3402. cell.labelMasterPack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
  3403. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  3404. if(isfree)
  3405. {
  3406. cell.labelOldPrice.hidden = false;
  3407. cell.labelOldPrice.textColor = [UIColor redColor];
  3408. cell.labelOldPrice.text=@"Free";
  3409. cell.labelOldPrice.hideline = true;
  3410. cell.labelDiscount.hidden = true;
  3411. }
  3412. else
  3413. {
  3414. cell.labelOldPrice.textColor = [UIColor blackColor];
  3415. cell.labelOldPrice.hideline = false;
  3416. if(discount==0)
  3417. {
  3418. cell.labelOldPrice.hidden = true;
  3419. cell.labelDiscount.hidden = true;
  3420. }
  3421. else
  3422. {
  3423. cell.labelOldPrice.hidden = false;
  3424. cell.labelDiscount.hidden = false;
  3425. }
  3426. }
  3427. // if(discount==0)
  3428. // {
  3429. // cell.labelOldPrice.hidden = true;
  3430. // cell.labelDiscount.hidden = true;
  3431. //
  3432. // }
  3433. // else
  3434. // {
  3435. // cell.labelOldPrice.hidden = false;
  3436. // cell.labelDiscount.hidden = false;
  3437. // }
  3438. // NSString* currency = [item_json valueForKey:@"currency"];
  3439. // int count =[[item_json valueForKey:@"count"] intValue];
  3440. cell.labelDescription.text = description;
  3441. cell.labelCount.text = [NSString stringWithFormat:@"x %d",count];
  3442. // cell.labelID.text = identifier;
  3443. // cell.labelSubtype.text = attribute;
  3444. cell.labelTotalPrice.text= totalprice;
  3445. // cell.labelUnitPrice.text=unit_price;
  3446. cell.labelUnitPrice.text = newunitprice;
  3447. cell.imgModel.image = [UIImage imageNamed:@"loading_s"];
  3448. cell.imgModel.contentMode = UIViewContentModeScaleAspectFit;
  3449. NSString* file_name=[img_url lastPathComponent];
  3450. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
  3451. if(img_data!=nil)
  3452. {
  3453. UIImage * img =[UIImage imageWithData:img_data];
  3454. cell.imgModel.image = img;
  3455. }
  3456. else
  3457. {
  3458. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3459. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  3460. dispatch_async(dispatch_get_main_queue(), ^{
  3461. if(downloadimg_data!=nil)
  3462. {
  3463. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  3464. UIImage * img =[UIImage imageWithData:downloadimg_data];
  3465. cell.imgModel.image = img;
  3466. }
  3467. else
  3468. cell.imgModel.image = [UIImage imageNamed:@"notfound_s"];
  3469. });
  3470. });
  3471. }
  3472. cell.backgroundColor = [UIColor whiteColor];
  3473. return cell;
  3474. }else if([control isEqualToString:@"datepicker"])
  3475. {
  3476. CellIdentifier = @"CommonEditorCellEnum";
  3477. CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3478. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  3479. NSString* value =[item_json valueForKey:@"value"];
  3480. // if([required isEqualToString:@"true"])
  3481. // {
  3482. // [title appendString:@"*"];
  3483. // }
  3484. cell.labelTitle.text=title;
  3485. if([required isEqualToString:@"true"])
  3486. {
  3487. [cell.labelTitle sizeToFit];
  3488. CGRect frame =cell.labelTitle.frame;
  3489. frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  3490. cell.starMark.frame = frame;
  3491. cell.starMark.hidden=false;
  3492. // [title appendString:@"*"];
  3493. // [title appendString:@"<font size=\"6\" >*</font>"];
  3494. // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  3495. }
  3496. else
  3497. {
  3498. [cell.labelTitle sizeToFit];
  3499. cell.starMark.hidden=true;
  3500. }
  3501. cell.labelValue.text = value;
  3502. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  3503. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  3504. {
  3505. CALayer *layer = [cell.contentView layer];
  3506. // layer.borderColor = [[UIColor redColor] CGColor];
  3507. // layer.borderWidth = 1.0;
  3508. layer.shadowColor = [UIColor redColor].CGColor;
  3509. layer.shadowOffset = CGSizeMake(0, 0);
  3510. layer.shadowOpacity = 1;
  3511. layer.shadowRadius = 2.0;
  3512. }
  3513. else
  3514. {
  3515. CALayer *layer = [cell.contentView layer];
  3516. // layer.borderColor = [[UIColor redColor] CGColor];
  3517. // layer.borderWidth = 1.0;
  3518. layer.shadowColor = [UIColor clearColor].CGColor;
  3519. layer.shadowOffset = CGSizeMake(0, 0);
  3520. layer.shadowOpacity = 1;
  3521. }
  3522. cell.backgroundColor = [UIColor whiteColor];
  3523. return cell;
  3524. }
  3525. else if([control isEqualToString:@"monthpicker"])
  3526. {
  3527. CellIdentifier = @"CommonEditorCellEnum";
  3528. CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3529. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  3530. NSString* value =[item_json valueForKey:@"value"];
  3531. // if([required isEqualToString:@"true"])
  3532. // {
  3533. // [title appendString:@"*"];
  3534. // }
  3535. cell.labelTitle.text=title;
  3536. if([required isEqualToString:@"true"])
  3537. {
  3538. [cell.labelTitle sizeToFit];
  3539. CGRect frame =cell.labelTitle.frame;
  3540. frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  3541. cell.starMark.frame = frame;
  3542. cell.starMark.hidden=false;
  3543. // [title appendString:@"*"];
  3544. // [title appendString:@"<font size=\"6\" >*</font>"];
  3545. // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  3546. }
  3547. else
  3548. {
  3549. [cell.labelTitle sizeToFit];
  3550. cell.starMark.hidden=true;
  3551. }
  3552. cell.labelValue.text = value;
  3553. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  3554. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  3555. {
  3556. CALayer *layer = [cell.contentView layer];
  3557. // layer.borderColor = [[UIColor redColor] CGColor];
  3558. // layer.borderWidth = 1.0;
  3559. layer.shadowColor = [UIColor redColor].CGColor;
  3560. layer.shadowOffset = CGSizeMake(0, 0);
  3561. layer.shadowOpacity = 1;
  3562. layer.shadowRadius = 2.0;
  3563. }
  3564. else
  3565. {
  3566. CALayer *layer = [cell.contentView layer];
  3567. // layer.borderColor = [[UIColor redColor] CGColor];
  3568. // layer.borderWidth = 1.0;
  3569. layer.shadowColor = [UIColor clearColor].CGColor;
  3570. layer.shadowOffset = CGSizeMake(0, 0);
  3571. layer.shadowOpacity = 1;
  3572. }
  3573. cell.backgroundColor = [UIColor whiteColor];
  3574. return cell;
  3575. }
  3576. else if([control isEqualToString:@"signature"])
  3577. {
  3578. CellIdentifier = @"CommonEditorCellSignature";
  3579. CommonEditorCellSignature * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3580. cell.imageviewSignature.contentMode = UIViewContentModeScaleAspectFit;
  3581. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  3582. // if([required isEqualToString:@"true"])
  3583. // {
  3584. // [title appendString:@"*"];
  3585. // }
  3586. int disabble = [[item_json objectForKey:@"disable"] intValue];
  3587. if (disabble==1 || readonly) {
  3588. cell.imageviewSignature.userInteractionEnabled = NO;
  3589. } else {
  3590. cell.imageviewSignature.userInteractionEnabled = YES;
  3591. }
  3592. cell.labelTitle.text = title;
  3593. if([required isEqualToString:@"true"])
  3594. {
  3595. [cell.labelTitle sizeToFit];
  3596. CGRect frame =cell.labelTitle.frame;
  3597. frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  3598. cell.starMark.frame = frame;
  3599. cell.starMark.hidden=false;
  3600. // [title appendString:@"*"];
  3601. // [title appendString:@"<font size=\"6\" >*</font>"];
  3602. // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  3603. }
  3604. else
  3605. {
  3606. [cell.labelTitle sizeToFit];
  3607. cell.starMark.hidden=true;
  3608. }
  3609. NSString* img_url = [item_json valueForKey:@"avalue"];
  3610. NSString* file_name=[img_url lastPathComponent];
  3611. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
  3612. if(img_data!=nil)
  3613. {
  3614. UIImage * img =[UIImage imageWithData:img_data];
  3615. cell.imageviewSignature.image=img ;
  3616. }
  3617. else
  3618. {
  3619. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3620. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  3621. dispatch_async(dispatch_get_main_queue(), ^{
  3622. if(downloadimg_data!=nil)
  3623. {
  3624. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  3625. UIImage * img =[UIImage imageWithData:downloadimg_data];
  3626. cell.imageviewSignature.image=img ;
  3627. }
  3628. else
  3629. cell.imageviewSignature.image=[UIImage imageNamed:@"taptosign_s"];
  3630. });
  3631. });
  3632. } cell.backgroundColor = [UIColor whiteColor];
  3633. return cell;
  3634. // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
  3635. //cell.imageviewSignature.image = image;
  3636. }
  3637. else if ([control isEqualToString:@"range"]) {
  3638. NSString *type = [item_json objectForKey:@"type"];
  3639. NSString *keyboard = [item_json objectForKey:@"keyboard"];
  3640. NSString *title = [item_json objectForKey:@"aname"];
  3641. NSString *min = [item_json objectForKey:@"min_value"];
  3642. NSString *max = [item_json objectForKey:@"max_value"];
  3643. CommonEditorRangeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorRangeCell" forIndexPath:indexPath];
  3644. cell.indexPath = indexPath;
  3645. cell.delegate = self;
  3646. [cell setTitle:title];
  3647. [cell setMinValue:min maxValue:max];
  3648. if ([type isEqualToString:@"date"]) {
  3649. [cell setType:CommonEditorRangeTypeDate];
  3650. } else {
  3651. [cell setType:CommonEditorRangeTypeDefault];
  3652. }
  3653. if([keyboard isEqualToString:@"number"]) {
  3654. [cell setKeyboardType:UIKeyboardTypeDecimalPad];
  3655. } else {
  3656. [cell setKeyboardType:UIKeyboardTypeDefault];
  3657. }
  3658. return cell;
  3659. }
  3660. else if ([control isEqualToString:@"webview"]) {
  3661. // CommonEditorWebCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorWebCell" forIndexPath:indexPath];
  3662. CommonEditorWebCell * cell = [[NSBundle mainBundle] loadNibNamed:@"Phone_Web_Cell" owner:nil options:nil].firstObject;
  3663. cell.webDelegate = self;
  3664. NSString *html_str = [item_json objectForKey:@"value"];
  3665. // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[html_str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
  3666. //
  3667. // cell.htmlLabel.attributedText = attrStr;
  3668. // [cell.webview stopLoading];
  3669. [cell.webview loadHTMLString:html_str baseURL:nil];
  3670. // [cell.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.baidu.com/"]]];
  3671. return cell;
  3672. }
  3673. else if ([control isEqualToString:@"banner"]) {
  3674. CommonEditorBannerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorBannerCell" forIndexPath:indexPath];
  3675. // NSDictionary *item_json = @{
  3676. // @"control" : @"banner",
  3677. // @"item_4": @{
  3678. // @"type" : @"image",
  3679. // @"s": @"http://127.0.0.1/s2.jpg",
  3680. // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7528.jpg"
  3681. // },
  3682. // @"count": @(5),
  3683. // @"item_2": @{
  3684. // @"type" : @"image",
  3685. // @"s": @"http://127.0.0.1/s3.jpg",
  3686. // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7526.jpg"
  3687. // },
  3688. // @"item_3": @{
  3689. // @"type" : @"image",
  3690. // @"s": @"http://127.0.0.1/s4.jpg",
  3691. // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7527.jpg"
  3692. // },
  3693. // @"item_0": @{
  3694. // @"type" : @"image",
  3695. // @"s": @"http://127.0.0.1/s1.jpg",
  3696. // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7524.jpg"
  3697. // },
  3698. // @"item_1": @{
  3699. // @"type" : @"image",
  3700. // @"s": @"http://127.0.0.1/s5.jpg",
  3701. // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7525.jpg"
  3702. // }
  3703. // };
  3704. [cell setContent:item_json];
  3705. cell.delegate = self;
  3706. return cell;
  3707. }
  3708. else
  3709. {
  3710. CellIdentifier = @"CommonEditorCellEdit";
  3711. UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3712. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  3713. cell.backgroundColor = [UIColor whiteColor];
  3714. return cell;
  3715. }
  3716. }
  3717. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  3718. {
  3719. // return [super tableview:tableView viewForHeaderInSection:section];
  3720. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  3721. if(value==nil)
  3722. value=@"";
  3723. unsigned long color = strtoul([value UTF8String],0,16);
  3724. NSString* btntitle=nil ;
  3725. NSString*labeltitle = nil;
  3726. NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy];
  3727. labeltitle= [sectionjson valueForKey:@"title"];
  3728. bool hide = [[sectionjson valueForKey:@"hide"]boolValue];
  3729. if(hide)
  3730. {
  3731. btntitle=@"Show";
  3732. // [section setValue:@"false" forKey:@"hide"];
  3733. // [sender setTitle:@"Show" forState:UIControlStateNormal];
  3734. }
  3735. else{
  3736. btntitle=@"Hide";
  3737. }
  3738. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  3739. // myView.backgroundColor = [UIColor whiteColor];//UIColorFromRGB(0x996633);;
  3740. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  3741. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  3742. myView.layer.shadowOffset = CGSizeMake(0, 0);
  3743. myView.layer.shadowOpacity = 0.5;
  3744. myView.layer.shadowRadius = 2.0;
  3745. int linespace=0;
  3746. if(section==0)
  3747. linespace=11;
  3748. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0+linespace, 50, 33)];
  3749. btn.tag=section;
  3750. // [btn setTitleColor:UIColorFromRGB(0x996633) forState:UIControlStateNormal];
  3751. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  3752. [btn setTitle:btntitle forState:UIControlStateNormal];
  3753. [myView addSubview:btn];
  3754. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  3755. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3756. UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5+linespace, 200, 20)];
  3757. titlelabel.textColor=UIColorFromRGB(color);//[UIColor whiteColor];
  3758. titlelabel.backgroundColor = [UIColor clearColor];
  3759. titlelabel.text=NSLocalizedString(labeltitle, nil);
  3760. titlelabel.font = [UIFont boldSystemFontOfSize:20];
  3761. [titlelabel sizeToFit];
  3762. [myView addSubview:titlelabel];
  3763. //
  3764. // UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 0, 90, 22)];
  3765. // contactlabel.textColor=[UIColor whiteColor];
  3766. // contactlabel.backgroundColor = [UIColor clearColor];
  3767. // contactlabel.text=NSLocalizedString(@"Contact", nil);
  3768. // [contactlabel sizeToFit];
  3769. // [myView addSubview:contactlabel];
  3770. //
  3771. //
  3772. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 0, 90, 22)];
  3773. // modellabel.textColor=[UIColor whiteColor];
  3774. // modellabel.backgroundColor = [UIColor clearColor];
  3775. // modellabel.text=NSLocalizedString(@"Model", nil);
  3776. // [modellabel sizeToFit];
  3777. // [myView addSubview:modellabel];
  3778. //
  3779. // UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(500, 0, 90, 22)];
  3780. // pricelabel.textColor=[UIColor whiteColor];
  3781. // pricelabel.backgroundColor = [UIColor clearColor];
  3782. // pricelabel.text=NSLocalizedString(@"Price", nil);
  3783. // [pricelabel sizeToFit];
  3784. // [myView addSubview:pricelabel];
  3785. //
  3786. //
  3787. //
  3788. // UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(630, 0, 90, 22)];
  3789. // timelabel.textColor=[UIColor whiteColor];
  3790. // timelabel.backgroundColor = [UIColor clearColor];
  3791. // timelabel.text=NSLocalizedString(@"Create time", nil);
  3792. // [timelabel sizeToFit];
  3793. // [myView addSubview:timelabel];
  3794. //
  3795. //
  3796. //
  3797. // UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 60, 22)];
  3798. // statuslabel.textColor=[UIColor whiteColor];
  3799. // statuslabel.backgroundColor = [UIColor clearColor];
  3800. // statuslabel.text=NSLocalizedString(@"Status", nil);
  3801. // [statuslabel sizeToFit];
  3802. // [myView addSubview:statuslabel];
  3803. //
  3804. myView.backgroundColor = UIColor.lightGrayColor;
  3805. UIColor * c=myView.backgroundColor;
  3806. return myView;
  3807. }
  3808. //
  3809. -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
  3810. {
  3811. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  3812. bool readonly = [[self.content_data_download valueForKey:@"readonly"]boolValue];
  3813. int disable = [[item_json valueForKey:@"disable"] intValue];
  3814. DebugLog(@"tableView willSelectRowAtIndexPath");
  3815. //
  3816. NSString* control = [item_json valueForKey:@"control"];
  3817. if([control isEqualToString:@"enum"])//||[control isEqualToString:@"ui"])
  3818. {
  3819. // int disable = [[item_json valueForKey:@"disable"] intValue];
  3820. if(disable==1||readonly)
  3821. return nil;
  3822. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
  3823. NSDictionary* cadedate_json = [item_json objectForKey:@"cadedate"];
  3824. // NSDictionary* value_json = [item_json objectForKey:@"value"];
  3825. NSString* single_select = [item_json valueForKey:@"single_select"];
  3826. // NSString* required =[item_json valueForKey:@"required"];
  3827. NSString* title = [item_json valueForKey:@"aname"];
  3828. BOOL sort = [[item_json objectForKey:@"sort"] boolValue];
  3829. if (sort) {
  3830. EnumSelectAndSortViewController *vc = [[UIStoryboard storyboardWithName:@"EnumSelectAndSort" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectAndSortViewController"];
  3831. vc.title = title;
  3832. [vc setEnumDataSource:cadedate_json];
  3833. vc.indexPath = indexPath;
  3834. __weak typeof(self) weakSelf = self;
  3835. vc.returnBlock = ^(NSDictionary *returnValue, NSIndexPath *idxPath) {
  3836. [weakSelf EnumValueChanged:[returnValue mutableCopy] indexPath:idxPath];
  3837. };
  3838. [self.navigationController pushViewController:vc animated:YES];
  3839. return nil;
  3840. }
  3841. BOOL online = [[item_json objectForKey:@"online"] boolValue];
  3842. if (online)
  3843. {
  3844. int max_select = [[item_json valueForKey:@"max"] intValue];
  3845. EnumSelectOnlineViewController* enumvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectOnlineViewController"];
  3846. enumvc.delegate = self;
  3847. enumvc.max_select = max_select;
  3848. enumvc.updatePosition = indexPath;
  3849. enumvc.online_params = item_json[@"params"];
  3850. // if([[required lowercaseString] isEqualToString:@"true"])
  3851. // enumvc.canbeEmpty = false;
  3852. // else
  3853. // enumvc.canbeEmpty =true;
  3854. // enumvc.cadedate = [cadedate_json mutableCopy];
  3855. enumvc.title = title;
  3856. // enumvc.value = [value_json mutableCopy];
  3857. enumvc.single_select =[[single_select lowercaseString] isEqualToString:@"true"];
  3858. [self.navigationController pushViewController:enumvc animated:true];
  3859. return nil;
  3860. }
  3861. int max_select = [[item_json valueForKey:@"max"] intValue];
  3862. EnumSelectViewController* enumvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
  3863. enumvc.delegate = self;
  3864. enumvc.max_select = max_select;
  3865. enumvc.updatePosition = indexPath;
  3866. // if([[required lowercaseString] isEqualToString:@"true"])
  3867. // enumvc.canbeEmpty = false;
  3868. // else
  3869. // enumvc.canbeEmpty =true;
  3870. enumvc.cadedate = [cadedate_json mutableCopy];
  3871. enumvc.title = title;
  3872. // enumvc.value = [value_json mutableCopy];
  3873. enumvc.single_select =[[single_select lowercaseString] isEqualToString:@"true"];
  3874. [self.navigationController pushViewController:enumvc animated:true];
  3875. }
  3876. else if([control isEqualToString:@"editor"])
  3877. {
  3878. [self handle_editor_cell_select:tableView IndexPath:indexPath];
  3879. }
  3880. else if([control isEqualToString:@"action"])
  3881. {
  3882. if (disable || readonly) {
  3883. return nil;
  3884. }
  3885. NSString* value = [item_json valueForKey:@"value"];
  3886. [self commonAction:value index:indexPath data:[item_json mutableCopy]];
  3887. }
  3888. else if([control isEqualToString:@"datepicker"])
  3889. {
  3890. if (disable || readonly) {
  3891. return nil;
  3892. }
  3893. // NSString* title = [item_json valueForKey:@"aname"];
  3894. NSString* value =[item_json valueForKey:@"value"];
  3895. NSString* type =[item_json valueForKey:@"type"];
  3896. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  3897. DatePickerViewController* dpvc =[ [UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"DatePickerViewController"];
  3898. if([[type lowercaseString] isEqualToString:@"date"])
  3899. {
  3900. dpvc.pickerMode = UIDatePickerModeDate;
  3901. [dateFormatter setDateFormat:@"yyyy/MM/dd"];
  3902. }
  3903. else if([[type lowercaseString] isEqualToString:@"time"])
  3904. {
  3905. dpvc.pickerMode = UIDatePickerModeTime;
  3906. [dateFormatter setDateFormat:@"HH:mm:ss"];
  3907. }
  3908. else
  3909. {
  3910. dpvc.pickerMode = UIDatePickerModeDateAndTime;
  3911. [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
  3912. }
  3913. __weak typeof(self) weakSelf = self;
  3914. NSDate *date = [dateFormatter dateFromString:value];
  3915. dpvc.date = date;
  3916. dpvc.formatter = dateFormatter;
  3917. dpvc.labelTime.text = value;
  3918. dpvc.blk_Set=^(NSString *date)
  3919. {
  3920. [weakSelf DateTimeValueChanged:date indexPath:indexPath];
  3921. };
  3922. [self.navigationController pushViewController:dpvc animated:true];
  3923. }else if([control isEqualToString:@"monthpicker"])
  3924. {
  3925. if (disable || readonly) {
  3926. return nil;
  3927. }
  3928. // NSString* title = [item_json valueForKey:@"aname"];
  3929. NSString* value =[item_json valueForKey:@"value"];
  3930. if (value==nil || value.length==0)
  3931. {
  3932. value=@"1/2015";
  3933. }
  3934. // NSString* type =[item_json valueForKey:@"type"];
  3935. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  3936. MonthPickerViewController* mpvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"MonthPickerViewController"];
  3937. // if([[type lowercaseString] isEqualToString:@"date"])
  3938. // {
  3939. // dpvc.pickerMode = UIDatePickerModeDate;
  3940. [dateFormatter setDateFormat:@"MM/yyyy"];
  3941. NSDate *date = [dateFormatter dateFromString:value];
  3942. mpvc.current_date =date;
  3943. mpvc.updatePosition = indexPath;
  3944. mpvc.delegate = self;
  3945. // }
  3946. // else if([[type lowercaseString] isEqualToString:@"time"])
  3947. // {
  3948. // dpvc.pickerMode = UIDatePickerModeTime;
  3949. // [dateFormatter setDateFormat:@"HH:mm:ss"];
  3950. // }
  3951. // else
  3952. // {
  3953. // dpvc.pickerMode = UIDatePickerModeDateAndTime;
  3954. // [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
  3955. // }
  3956. // NSDate *date = [dateFormatter dateFromString:value];
  3957. // dpvc.date = date;
  3958. // dpvc.formatter = dateFormatter;
  3959. // dpvc.labelTime.text = value;
  3960. [self.navigationController pushViewController:mpvc animated:true];
  3961. }
  3962. else if([control isEqualToString:@"signature"])
  3963. {
  3964. // SignatureViewController * signvc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  3965. // signvc.title = [item_json valueForKey:@"aname"];
  3966. // signvc.indexPath = indexPath;
  3967. // // signvc.delegate = self;
  3968. // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
  3969. //
  3970. // signvc.existSignature = cell.imageviewSignature.image ;
  3971. //
  3972. //
  3973. //
  3974. // [self.navigationController pushViewController:signvc animated:true];
  3975. if (disable || readonly) {
  3976. return nil;
  3977. }
  3978. __block UIImage* signimg=nil;
  3979. SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  3980. __weak typeof(self) weakself = self;
  3981. vc.onReturnImg = ^(UIImage* img)
  3982. {
  3983. signimg = img;
  3984. if(signimg!=nil)
  3985. {
  3986. #ifdef OFFLINE_MODE
  3987. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3988. BOOL offline_mode = [[appDelegate globalParameterForKey:@"offline_mode"] boolValue];
  3989. if(offline_mode)
  3990. {
  3991. NSData *data = [OLDataProvider offline_saveBusinesscard:UIImagePNGRepresentation(img)];
  3992. // 再将NSData转为字符串
  3993. NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  3994. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  3995. DebugLog(@"data string: %@",jsonStr);
  3996. NSError *error=nil;
  3997. NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
  3998. //NSMutableArray* arr_ret = [[NSMutableArray alloc] init];
  3999. if([[json valueForKey:@"result"] intValue]==2)
  4000. {
  4001. NSString* img_url_down = json[@"img_url_aname"];
  4002. // if(img_url_down.length==0)
  4003. // img_url_down=@"";
  4004. NSString* img_url_up = json[@"img_url"];
  4005. // if(img_url_up.length==0)
  4006. // img_url_up=@"";
  4007. NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
  4008. [item_json setValue:img_url_down forKey:@"avalue"];
  4009. [item_json setValue:img_url_up forKey:@"value"];
  4010. [item_json setValue:@"true" forKey:@"dirty"];
  4011. NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4012. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  4013. [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4014. weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
  4015. CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
  4016. cell.imageviewSignature.image = signimg;
  4017. }
  4018. else
  4019. {
  4020. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ;
  4021. }
  4022. }
  4023. else
  4024. #endif
  4025. {
  4026. NSData *imageData = UIImagePNGRepresentation(img);
  4027. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4028. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4029. NSString *user = [RASingleton.sharedInstance globalParameterForKey:@"user"];
  4030. NSString *password = [RASingleton.sharedInstance globalParameterForKey:@"password"];
  4031. if(user!=nil)
  4032. [params setValue:user forKey:@"user"];
  4033. if(password!=nil)
  4034. [params setValue:password forKey:@"password"];
  4035. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Upload Signature" completion:^{
  4036. [NetworkUtils upload:imageData FileName:@"test.jpg" Params:params ToHost:URL_UPLOAD_IMG Result:^(NSMutableDictionary *json) {
  4037. // dispatch_async(dispatch_get_main_queue(), ^{
  4038. [waitalert dismissViewControllerAnimated:YES completion:^{
  4039. if([[json valueForKey:@"result"] intValue]==2)
  4040. {
  4041. NSString* img_url_down = json[@"img_url_aname"];
  4042. NSString* img_url_up = json[@"img_url"];
  4043. NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
  4044. [item_json setValue:img_url_down forKey:@"avalue"];
  4045. [item_json setValue:img_url_up forKey:@"value"];
  4046. [item_json setValue:@"true" forKey:@"dirty"];
  4047. NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4048. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  4049. [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4050. weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
  4051. CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
  4052. cell.imageviewSignature.image = signimg;
  4053. }
  4054. else if([[json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE)
  4055. {
  4056. [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:nil];
  4057. }
  4058. else
  4059. {
  4060. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ;
  4061. }
  4062. }];
  4063. // });
  4064. } Progress:nil DecryptHandler:nil];
  4065. }];
  4066. self.alert = waitalert;
  4067. // AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
  4068. //
  4069. // NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:URL_UPLOAD_IMG parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
  4070. // [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test.jpg" mimeType:@"image/png"];
  4071. // } error:nil];
  4072. //
  4073. //
  4074. //
  4075. // AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  4076. //
  4077. //
  4078. //
  4079. //
  4080. // NSProgress *progress = nil;
  4081. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Upload Signature"];
  4082. // NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
  4083. //
  4084. // // [progress removeObserver:self forKeyPath:@"fractionCompleted"];
  4085. //
  4086. //
  4087. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  4088. //
  4089. // if (error) {
  4090. //
  4091. // NSString* err_msg = [error localizedDescription];
  4092. // DebugLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]];
  4093. //
  4094. //
  4095. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  4096. //
  4097. // DebugLog(@"data string: %@",str);
  4098. //
  4099. // [RAUtils message_alert:@"Can not connect to server please try again." title:@"Upload Image" controller:weakself] ;
  4100. //
  4101. // } else {
  4102. // DebugLog(@"response ");
  4103. //
  4104. //
  4105. //
  4106. // NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil];
  4107. //
  4108. // // 再将NSData转为字符串
  4109. // NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  4110. //
  4111. // // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  4112. //
  4113. // DebugLog(@"data string: %@",jsonStr);
  4114. //
  4115. // NSDictionary* json = responseObject;
  4116. //
  4117. //
  4118. // //NSMutableArray* arr_ret = [[NSMutableArray alloc] init];
  4119. // if([[json valueForKey:@"result"] intValue]==2)
  4120. // {
  4121. // NSString* img_url_down = json[@"img_url_aname"];
  4122. // // if(img_url_down.length==0)
  4123. // // img_url_down=@"";
  4124. // NSString* img_url_up = json[@"img_url"];
  4125. // // if(img_url_up.length==0)
  4126. // // img_url_up=@"";
  4127. //
  4128. // NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
  4129. //
  4130. // [item_json setValue:img_url_down forKey:@"avalue"];
  4131. // [item_json setValue:img_url_up forKey:@"value"];
  4132. // [item_json setValue:@"true" forKey:@"dirty"];
  4133. // NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4134. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
  4135. //
  4136. // [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4137. // weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
  4138. //
  4139. //
  4140. // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
  4141. //
  4142. // cell.imageviewSignature.image = signimg;
  4143. //
  4144. //
  4145. // }
  4146. // else
  4147. // {
  4148. // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ;
  4149. // }
  4150. //
  4151. //
  4152. //
  4153. //
  4154. //
  4155. //
  4156. // }
  4157. // //
  4158. // }];
  4159. //
  4160. // [uploadTask resume];
  4161. }
  4162. }
  4163. };
  4164. [self.navigationController pushViewController:vc animated:NO];
  4165. }
  4166. // else if([control isEqualToString:@"action "])
  4167. // {
  4168. //
  4169. // DebugLog(@"action push");
  4170. // // SignatureViewController * signvc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  4171. // // signvc.title = [item_json valueForKey:@"aname"];
  4172. // // signvc.indexPath = indexPath;
  4173. // // signvc.delegate = self;
  4174. // // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
  4175. // //
  4176. // // signvc.existSignature = cell.imageviewSignature.image ;
  4177. // //
  4178. // //
  4179. // //
  4180. // // [self.navigationController pushViewController:signvc animated:true];
  4181. // }
  4182. return nil;
  4183. }
  4184. //- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  4185. //{
  4186. //
  4187. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
  4188. //
  4189. // NSString* orderid = [item_json valueForKey:@"id"];
  4190. //
  4191. // // if (self.delegate && [self.delegate respondsToSelector:@selector(SelectOrder:)]) {
  4192. // // [self.delegate SelectOrder:orderid];
  4193. // // }
  4194. // //
  4195. // // [self dismissViewControllerAnimated:YES
  4196. // // completion:^{
  4197. // // //一定要移除手势 否则下次 没有子视图的时候 点击 会崩溃拉
  4198. // // AppDelegate *app = [[UIApplication sharedApplication] delegate];
  4199. // // [app.window removeGestureRecognizer:self.tapGesture];
  4200. // // }];
  4201. // // [pvc categoryMenuSelected:indexPath.row];
  4202. //}
  4203. #pragma mark monthpicker ViewControllerDelegate
  4204. -(void) MPValueChanged:(NSString *)value indexPath :(NSIndexPath*) indexPath
  4205. {
  4206. CommonEditorCellEnum * cell= (CommonEditorCellEnum*) [self.editorTable cellForRowAtIndexPath:indexPath];
  4207. cell.labelValue.text = value;
  4208. {
  4209. CALayer *layer = [cell.contentView layer];
  4210. // layer.borderColor = [[UIColor redColor] CGColor];
  4211. // layer.borderWidth = 1.0;
  4212. layer.shadowColor = [UIColor clearColor].CGColor;
  4213. layer.shadowOffset = CGSizeMake(0, 0);
  4214. layer.shadowOpacity = 1;
  4215. layer.shadowRadius = 2.0;
  4216. }
  4217. // NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  4218. // UITableViewCell *cell = (UITableViewCell *) paramSender.superview.superview;
  4219. // NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  4220. NSMutableDictionary* section_json=nil;
  4221. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  4222. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  4223. // NSString* check=@"false";
  4224. // if([paramSender isOn])
  4225. // check=@"true";
  4226. // [item_json setValue:value forKey:@"dirty"];
  4227. NSString* subid=[item_json valueForKey:@"subid"];
  4228. [item_json setValue:value forKey:@"value"];
  4229. if(subid==nil)
  4230. {
  4231. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4232. int count=0;
  4233. count=[[section_json valueForKey:@"count"] intValue];
  4234. for(int i=0;i<count;i++)
  4235. {
  4236. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  4237. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  4238. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  4239. }
  4240. }
  4241. else
  4242. {
  4243. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  4244. int section = [(NSString*)idarr[0] intValue];
  4245. int item=[(NSString*)idarr[1] intValue];
  4246. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  4247. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  4248. NSString* control_type= [olditem valueForKey:@"control"];
  4249. if([control_type isEqualToString:@"enum"])
  4250. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  4251. else if([control_type isEqualToString:@"switch"])
  4252. item_json= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  4253. [item_json setValue:@"true" forKey:@"dirty"];
  4254. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  4255. }
  4256. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4257. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  4258. [self.editorTable reloadData ];
  4259. }
  4260. #pragma mark datetimeChanged
  4261. -(void) DateTimeValueChanged:(NSString *)value indexPath :(NSIndexPath*) indexPath
  4262. {
  4263. NSMutableDictionary* section_json=nil;
  4264. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  4265. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  4266. int refresh = [[item_json valueForKey:@"refresh"] intValue];
  4267. bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
  4268. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  4269. NSString* subid=[item_json valueForKey:@"subid"];
  4270. // NSArray* imgs=[RAUtils string2arr:url_up separator:@","];
  4271. // imgs[index];
  4272. item_json[@"value"]=value;
  4273. [item_json setValue:@"true" forKey:@"dirty"];
  4274. if(subid==nil)
  4275. {
  4276. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4277. int count=0;
  4278. count=[[section_json valueForKey:@"count"] intValue];
  4279. for(int i=0;i<count;i++)
  4280. {
  4281. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  4282. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  4283. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  4284. }
  4285. }
  4286. else
  4287. {
  4288. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  4289. int section = [(NSString*)idarr[0] intValue];
  4290. int item=[(NSString*)idarr[1] intValue];
  4291. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  4292. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  4293. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  4294. [item_json setValue:@"true" forKey:@"dirty"];
  4295. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  4296. }
  4297. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4298. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  4299. // NSRange range = NSMakeRange(indexPath.section, 1);
  4300. // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  4301. // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  4302. if(refresh==1)
  4303. {
  4304. [self refresh:refresh_trigger discardDirty:discardDirty];
  4305. }
  4306. [self.editorTable reloadData ];
  4307. }
  4308. #pragma mark EnumSelectViewControllerDelegate
  4309. -(void) setEnumValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  4310. {
  4311. NSMutableDictionary* section_json=nil;
  4312. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  4313. int refresh = [[item_json valueForKey:@"refresh"] intValue];
  4314. bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
  4315. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  4316. NSString* subid=[item_json valueForKey:@"subid"];
  4317. [item_json setObject:value forKey:@"cadedate"];
  4318. if(subid==nil)
  4319. {
  4320. [item_json setValue:@"true" forKey:@"dirty"];
  4321. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4322. int count=0;
  4323. count=[[section_json valueForKey:@"count"] intValue];
  4324. for(int i=0;i<count;i++)
  4325. {
  4326. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  4327. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  4328. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  4329. }
  4330. }
  4331. else
  4332. {
  4333. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  4334. int section = [(NSString*)idarr[0] intValue];
  4335. int item=[(NSString*)idarr[1] intValue];
  4336. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  4337. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  4338. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  4339. [item_json setValue:@"true" forKey:@"dirty"];
  4340. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  4341. }
  4342. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  4343. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4344. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  4345. NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  4346. if(refresh==1)
  4347. {
  4348. if(restore_json!=nil)
  4349. {
  4350. int rc=[[restore_json valueForKey:@"count"] intValue];
  4351. for(int ir=0;ir<rc;ir++)
  4352. {
  4353. NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  4354. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  4355. for(int i=0;i<section_count;i++)
  4356. {
  4357. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  4358. // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  4359. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  4360. for(int j=0;j<item_count;j++)
  4361. {
  4362. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  4363. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  4364. if([[itemjson valueForKey:@"name"] isEqualToString:name])
  4365. {
  4366. [itemjson removeObjectForKey:@"dirty"];
  4367. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  4368. }
  4369. }
  4370. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  4371. }
  4372. }
  4373. }
  4374. [self refresh:refresh_trigger discardDirty:discardDirty];
  4375. return ;
  4376. }
  4377. DebugLog(@"CONTENT UPDATE:%@",[RAConvertor DataTOjsonString:self.content_data_download]);
  4378. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  4379. [self.editorTable reloadData ];
  4380. }
  4381. -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  4382. {
  4383. UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
  4384. // if(/*self.cancommit==false &&*/ string.length==0 && (textField.text.length<=1|| textField.text==nil))
  4385. // {
  4386. // CALayer *layer = [cell.contentView layer];
  4387. // // layer.borderColor = [[UIColor redColor] CGColor];
  4388. // // layer.borderWidth = 1.0;
  4389. //
  4390. // layer.shadowColor = [UIColor redColor].CGColor;
  4391. // layer.shadowOffset = CGSizeMake(0, 0);
  4392. // layer.shadowOpacity = 1;
  4393. // layer.shadowRadius = 2.0;
  4394. // }
  4395. // else
  4396. {
  4397. CALayer *layer = [cell.contentView layer];
  4398. // layer.borderColor = [[UIColor redColor] CGColor];
  4399. // layer.borderWidth = 1.0;
  4400. layer.shadowColor = [UIColor clearColor].CGColor;
  4401. layer.shadowOffset = CGSizeMake(0, 0);
  4402. layer.shadowOpacity = 1;
  4403. layer.shadowRadius = 2.0;
  4404. }
  4405. DebugLog(@"enum changed %ld_%ld",(long)indexPath.section,(long)indexPath.row);
  4406. [self setEnumValue:value indexPath:indexPath];
  4407. }
  4408. -(NSMutableDictionary*) enum_subitem_changed:(NSMutableDictionary *) item subid:(NSArray*) subid value:(NSMutableDictionary*)value step:(int) step
  4409. {
  4410. int index = [(NSString*)subid[step] intValue];
  4411. NSMutableDictionary * cadedate= [[item objectForKey:@"cadedate"] mutableCopy];
  4412. NSMutableDictionary * subitem= [[item objectForKey:@"sub_item"] mutableCopy];
  4413. if(cadedate!=nil)
  4414. {
  4415. NSMutableDictionary * valjson=[[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",index]]mutableCopy];
  4416. valjson= [self enum_subitem_changed:valjson subid:subid value:value step:step+1];
  4417. [cadedate setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",index]];
  4418. [item setObject:cadedate forKey:@"cadedate"];
  4419. return item;
  4420. }
  4421. else if(subitem!=nil)
  4422. {
  4423. NSMutableDictionary * itemjson=[[subitem objectForKey:[NSString stringWithFormat:@"item_%d",index]] mutableCopy];
  4424. if(step==subid.count-1)
  4425. {
  4426. itemjson =value;
  4427. }
  4428. else
  4429. itemjson =[self enum_subitem_changed:itemjson subid:subid value:value step:step+1];
  4430. [subitem setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",index]];
  4431. [item setObject:subitem forKey:@"sub_item"];
  4432. return item;
  4433. }
  4434. return nil;
  4435. }
  4436. //#pragma mark SignatureViewControllerDelegate
  4437. ////-(void)SignatureVCReturnData:(NSData *)imagedata indexPath:(NSIndexPath *)indexPath
  4438. ////{
  4439. ////
  4440. ////}
  4441. //-(void)SignatureVCReturnImage:(UIImage *)image indexPath:(NSIndexPath *)indexPath
  4442. //{
  4443. //
  4444. // // NSMutableDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  4445. // //
  4446. // // if(image==nil)
  4447. // // [item_json removeObjectForKey:@"signature"];
  4448. // // else
  4449. // // [item_json setObject:image forKey:@"signature"];
  4450. // // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4451. // // [self.content_data setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4452. // //
  4453. // //
  4454. // //
  4455. // // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
  4456. // // cell.imageviewSignature.image = image;
  4457. //}
  4458. #pragma mark textView delegate
  4459. //- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
  4460. //- (BOOL)textViewShouldEndEditing:(UITextView *)textView;
  4461. - (BOOL)textViewShouldBeginEditing:(UITextView *)textView
  4462. {
  4463. DebugLog(@"textViewShouldBeginEditing");
  4464. self.editingcell = (UITableViewCell*)textView.superview.superview;
  4465. return textView.editable;
  4466. }
  4467. - (void)textViewDidBeginEditing:(UITextView *)textView
  4468. {
  4469. self.lasttextview = textView;
  4470. UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
  4471. self.lasttextview_from = [self.editorTable indexPathForCell:cell];
  4472. }
  4473. - (void)textViewDidEndEditing:(UITextView *)textView
  4474. {
  4475. // UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
  4476. NSIndexPath * indexPath = self.lasttextview_from;//[self.editorTable indexPathForCell:cell];
  4477. NSMutableDictionary* section_json=nil;
  4478. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  4479. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  4480. NSString* subid=[item_json valueForKey:@"subid"];
  4481. [item_json setValue:@"true" forKey:@"dirty"];
  4482. [item_json setValue:textView.text forKey:@"value"];
  4483. // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
  4484. if(subid==nil)
  4485. {
  4486. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4487. int count=0;
  4488. count=[[section_json valueForKey:@"count"] intValue];
  4489. for(int i=0;i<count;i++)
  4490. {
  4491. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  4492. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  4493. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  4494. }
  4495. }
  4496. else
  4497. {
  4498. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  4499. int section = [(NSString*)idarr[0] intValue];
  4500. int item=[(NSString*)idarr[1] intValue];
  4501. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  4502. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  4503. NSString* control_type= [olditem valueForKey:@"control"];
  4504. if([control_type isEqualToString:@"enum"])
  4505. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  4506. else if([control_type isEqualToString:@"switch"])
  4507. item_json= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  4508. [item_json setValue:@"true" forKey:@"dirty"];
  4509. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  4510. }
  4511. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4512. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  4513. self.lasttextview = nil;
  4514. self.lasttextview_from=nil;
  4515. // if(self.resize)
  4516. // {
  4517. // NSTimeInterval animationDuration = 0.30f;
  4518. // CGRect frame = self.view.frame;
  4519. // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
  4520. // // { //还原界面
  4521. // // moveY = prewMoveY;
  4522. // frame.origin.y +=self.ioffset;
  4523. // frame.size. height -=self.ioffset;
  4524. // self.view.frame = frame;
  4525. // // }
  4526. // //self.view移回原位置
  4527. // [UIView beginAnimations:@"ResizeView" context:nil];
  4528. // [UIView setAnimationDuration:animationDuration];
  4529. // self.view.frame = frame;
  4530. // [UIView commitAnimations];
  4531. // //[textField resignFirstResponder];
  4532. // self.ioffset=0;
  4533. // }
  4534. }
  4535. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  4536. {
  4537. UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
  4538. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  4539. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  4540. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  4541. NSString* required = [item_json valueForKey:@"required"];
  4542. if([required isEqualToString:@"true"] && text.length==0 && (textView.text.length<=1|| textView.text==nil))
  4543. {
  4544. CALayer *layer = [cell.contentView layer];
  4545. // layer.borderColor = [[UIColor redColor] CGColor];
  4546. // layer.borderWidth = 1.0;
  4547. layer.shadowColor = [UIColor redColor].CGColor;
  4548. layer.shadowOffset = CGSizeMake(0, 0);
  4549. layer.shadowOpacity = 1;
  4550. layer.shadowRadius = 2.0;
  4551. }
  4552. else
  4553. {
  4554. CALayer *layer = [cell.contentView layer];
  4555. // layer.borderColor = [[UIColor redColor] CGColor];
  4556. // layer.borderWidth = 1.0;
  4557. layer.shadowColor = [UIColor clearColor].CGColor;
  4558. layer.shadowOffset = CGSizeMake(0, 0);
  4559. layer.shadowOpacity = 1;
  4560. layer.shadowRadius = 2.0;
  4561. }
  4562. return YES;
  4563. }
  4564. //- (void)textViewDidChange:(UITextView *)textView;
  4565. //
  4566. //- (void)textViewDidChangeSelection:(UITextView *)textView;
  4567. //
  4568. //- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
  4569. //- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
  4570. #pragma mark textField delegate
  4571. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  4572. DebugLog(@"textField shouldChangeCharactersInRange");
  4573. DebugLog(@"text:%@",textField.text);
  4574. CommonEditorCellEdit *cell = (CommonEditorCellEdit *) textField.superview.superview;
  4575. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  4576. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  4577. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  4578. NSString* required = [item_json valueForKey:@"required"];
  4579. if([required isEqualToString:@"true"] && string.length==0 && (textField.text.length<=1|| textField.text==nil))
  4580. {
  4581. CALayer *layer = cell.labelTitle.layer;
  4582. // layer.borderColor = [[UIColor redColor] CGColor];
  4583. // layer.borderWidth = 1.0;
  4584. layer.shadowColor = [UIColor redColor].CGColor;
  4585. layer.shadowOffset = CGSizeMake(0, 0);
  4586. layer.shadowOpacity = 1;
  4587. layer.shadowRadius = 2.0;
  4588. layer = cell.starMark.layer;
  4589. // layer.borderColor = [[UIColor redColor] CGColor];
  4590. // layer.borderWidth = 1.0;
  4591. layer.shadowColor = [UIColor redColor].CGColor;
  4592. layer.shadowOffset = CGSizeMake(0, 0);
  4593. layer.shadowOpacity = 1;
  4594. layer.shadowRadius = 2.0;
  4595. //UIImageView * iv =
  4596. cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_attention_24"]];
  4597. cell.textfield.rightViewMode=UITextFieldViewModeUnlessEditing;
  4598. textField.layer.cornerRadius=8.0f;
  4599. textField.layer.borderWidth= 1.0f;
  4600. textField.layer.masksToBounds=YES;
  4601. textField.layer.borderColor=[[UIColor redColor]CGColor];
  4602. }
  4603. else
  4604. {
  4605. CALayer *layer = cell.labelTitle.layer;//[cell.contentView layer];
  4606. // layer.borderColor = [[UIColor redColor] CGColor];
  4607. // layer.borderWidth = 1.0;
  4608. layer.shadowColor = [UIColor clearColor].CGColor;
  4609. layer.shadowOffset = CGSizeMake(0, 0);
  4610. layer.shadowOpacity = 1;
  4611. layer = cell.starMark.layer;//[cell.contentView layer];
  4612. layer.shadowColor = [UIColor clearColor].CGColor;
  4613. layer.shadowOffset = CGSizeMake(0, 0);
  4614. layer.shadowOpacity = 1;
  4615. //cell.textfield.layer.borderColor= [[UIColor lightGrayColor] CGColor];
  4616. //UIImageView * iv =
  4617. // cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_wish_16"]];
  4618. cell.textfield.rightViewMode=UITextFieldViewModeNever;
  4619. textField.layer.cornerRadius=8.0f;
  4620. textField.layer.borderWidth= 1.0f;
  4621. textField.layer.masksToBounds=YES;
  4622. textField.layer.borderColor=[[UIColor lightGrayColor]CGColor];
  4623. }
  4624. //
  4625. // if([required isEqualToString:@"true"] && string.length==0 && (textField.text.length<=1|| textField.text==nil))
  4626. // {
  4627. // CALayer *layer = [cell.contentView layer];
  4628. // // layer.borderColor = [[UIColor redColor] CGColor];
  4629. // // layer.borderWidth = 1.0;
  4630. //
  4631. // layer.shadowColor = [UIColor redColor].CGColor;
  4632. // layer.shadowOffset = CGSizeMake(0, 0);
  4633. // layer.shadowOpacity = 1;
  4634. // layer.shadowRadius = 2.0;
  4635. // }
  4636. // else
  4637. // {
  4638. // CALayer *layer = [cell.contentView layer];
  4639. // // layer.borderColor = [[UIColor redColor] CGColor];
  4640. // // layer.borderWidth = 1.0;
  4641. //
  4642. // layer.shadowColor = [UIColor clearColor].CGColor;
  4643. // layer.shadowOffset = CGSizeMake(0, 0);
  4644. // layer.shadowOpacity = 1;
  4645. // layer.shadowRadius = 2.0;
  4646. // }
  4647. NSString* keyboard = [item_json valueForKey:@"keyboard"];
  4648. if(![keyboard isEqualToString:@"number"] && ![keyboard isEqualToString:@"int"])
  4649. return TRUE;
  4650. NSCharacterSet *cs;
  4651. if([keyboard isEqualToString:@"number"])
  4652. cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
  4653. else
  4654. cs = [[NSCharacterSet characterSetWithCharactersInString:INTNUMBERS]invertedSet];
  4655. NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
  4656. BOOL canChange = [string isEqualToString:filtered];
  4657. int lenth = [[item_json valueForKey:@"length"] intValue];
  4658. if(lenth==0)
  4659. return canChange;
  4660. else
  4661. {
  4662. return canChange&& (lenth>textField.text.length ||[string isEqualToString:@""]);
  4663. }
  4664. }
  4665. - (void)textFieldDidEndEditing:(UITextField *)textField
  4666. {
  4667. DebugLog(@"textFieldDidEndEditing");
  4668. // UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  4669. NSIndexPath * indexPath = self.lastedit_from;
  4670. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  4671. if ([item_json objectForKey:@"fill"]) {
  4672. NSString *fillText = [item_json objectForKey:@"fill"];
  4673. if (fillText && textField.text.length == 0) {
  4674. textField.text = fillText;
  4675. }
  4676. }
  4677. [self textfieldSetValue:indexPath value:textField.text];
  4678. // NSMutableDictionary* section_json=nil;
  4679. //
  4680. //
  4681. //
  4682. // textField.text = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  4683. //
  4684. // // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  4685. // NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  4686. //
  4687. // NSString* subid=[item_json valueForKey:@"subid"];
  4688. // NSString* refresh_trigger = [item_json valueForKey:@"name"];
  4689. //
  4690. // [item_json setValue:@"true" forKey:@"dirty"];
  4691. // [item_json setValue:textField.text forKey:@"value"];
  4692. // if([[item_json valueForKey:@"keyboard"] isEqualToString:@"number"])
  4693. // {
  4694. // float f = [ textField.text floatValue];
  4695. // [item_json setValue:[NSString stringWithFormat:@"%.2f",f] forKey:@"value"];
  4696. //
  4697. // }
  4698. //
  4699. // // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
  4700. // if(subid==nil)
  4701. // {
  4702. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4703. // int count=0;
  4704. //
  4705. // count=[[section_json valueForKey:@"count"] intValue];
  4706. //
  4707. // for(int i=0;i<count;i++)
  4708. // {
  4709. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  4710. // if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  4711. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  4712. //
  4713. //
  4714. // }
  4715. //
  4716. //
  4717. // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4718. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  4719. //
  4720. // int refresh = [[item_json valueForKey:@"refresh"] intValue];
  4721. //
  4722. // NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  4723. // bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
  4724. // if(refresh==1)
  4725. // {
  4726. //
  4727. // if(restore_json!=nil)
  4728. // {
  4729. // int rc=[[restore_json valueForKey:@"count"] intValue];
  4730. // for(int ir=0;ir<rc;ir++)
  4731. // {
  4732. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  4733. //
  4734. //
  4735. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  4736. // for(int i=0;i<section_count;i++)
  4737. // {
  4738. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  4739. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  4740. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  4741. // for(int j=0;j<item_count;j++)
  4742. // {
  4743. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  4744. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  4745. //
  4746. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  4747. // {
  4748. // [itemjson removeObjectForKey:@"dirty"];
  4749. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  4750. // }
  4751. //
  4752. // }
  4753. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  4754. // }
  4755. //
  4756. //
  4757. // }
  4758. //
  4759. // }
  4760. // [self refresh:refresh_trigger] ;
  4761. //
  4762. // }
  4763. // else if(partial_refresh)
  4764. // {
  4765. // NSString* name = [item_json valueForKey:@"name"] ;
  4766. // NSString* url = [item_json valueForKey:@"data_interface"] ;
  4767. //
  4768. //
  4769. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4770. //
  4771. // [params setValue:textField.text forKey:name];
  4772. //
  4773. //
  4774. // UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
  4775. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4776. //
  4777. // NSDictionary* editor_json = [iSalesNetwork commoneditor_partialrefresh:params url:url];
  4778. //
  4779. // dispatch_async(dispatch_get_main_queue(), ^{
  4780. //
  4781. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  4782. //
  4783. //
  4784. // if([[editor_json valueForKey:@"result"] intValue]==2)
  4785. // {
  4786. //
  4787. // int prcount = [[editor_json valueForKey:@"count"] intValue];
  4788. // for(int ipr=0;ipr<prcount;ipr++)
  4789. // {
  4790. // NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
  4791. // NSString* name = [pr_item valueForKey:@"name"];
  4792. // NSString* value = [pr_item valueForKey:@"value"];
  4793. //
  4794. // [self setValue:name value:value];
  4795. // }
  4796. //
  4797. //
  4798. // }
  4799. // else
  4800. // {
  4801. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
  4802. // }
  4803. //
  4804. //
  4805. // });
  4806. // });
  4807. //
  4808. //
  4809. //
  4810. // }
  4811. // self.lastedit = nil;
  4812. // self.lastedit_from=nil;
  4813. // return ;
  4814. // }
  4815. // else
  4816. // {
  4817. // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  4818. // int section = [(NSString*)idarr[0] intValue];
  4819. // int item=[(NSString*)idarr[1] intValue];
  4820. //
  4821. //
  4822. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  4823. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  4824. //
  4825. // NSString* control_type= [olditem valueForKey:@"control"];
  4826. // NSMutableDictionary* new_item=nil;
  4827. // [item_json setValue:@"true" forKey:@"dirty"];
  4828. // if([control_type isEqualToString:@"enum"])
  4829. // new_item= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  4830. // else if([control_type isEqualToString:@"switch"])
  4831. // new_item= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  4832. //
  4833. // [section_json setObject:new_item forKey:[NSString stringWithFormat:@"item_%d",item ]];
  4834. //
  4835. //
  4836. // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4837. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  4838. //
  4839. // int refresh = [[item_json valueForKey:@"refresh"] intValue];
  4840. //
  4841. // NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  4842. // bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
  4843. // if(refresh==1)
  4844. // {
  4845. //
  4846. // if(restore_json!=nil)
  4847. // {
  4848. // int rc=[[restore_json valueForKey:@"count"] intValue];
  4849. // for(int ir=0;ir<rc;ir++)
  4850. // {
  4851. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  4852. //
  4853. //
  4854. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  4855. // for(int i=0;i<section_count;i++)
  4856. // {
  4857. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  4858. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  4859. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  4860. // for(int j=0;j<item_count;j++)
  4861. // {
  4862. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  4863. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  4864. //
  4865. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  4866. // {
  4867. // [itemjson removeObjectForKey:@"dirty"];
  4868. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  4869. // }
  4870. //
  4871. // }
  4872. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  4873. // }
  4874. //
  4875. //
  4876. // }
  4877. //
  4878. // }
  4879. // [self refresh:refresh_trigger] ;
  4880. //
  4881. // }
  4882. // else if(partial_refresh)
  4883. // {
  4884. // NSString* name = [item_json valueForKey:@"name"] ;
  4885. // NSString* url = [item_json valueForKey:@"data_interface"] ;
  4886. //
  4887. //
  4888. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4889. //
  4890. // [params setValue:textField.text forKey:name];
  4891. //
  4892. //
  4893. // UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
  4894. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4895. //
  4896. // NSDictionary* editor_json = [iSalesNetwork commoneditor_partialrefresh:params url:url];
  4897. //
  4898. // dispatch_async(dispatch_get_main_queue(), ^{
  4899. //
  4900. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  4901. //
  4902. //
  4903. // if([[editor_json valueForKey:@"result"] intValue]==2)
  4904. // {
  4905. //
  4906. // int prcount = [[editor_json valueForKey:@"count"] intValue];
  4907. // for(int ipr=0;ipr<prcount;ipr++)
  4908. // {
  4909. // NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
  4910. // NSString* name = [pr_item valueForKey:@"name"];
  4911. // NSString* value = [pr_item valueForKey:@"value"];
  4912. //
  4913. // [self setValue:name value:value];
  4914. // }
  4915. //
  4916. // }
  4917. // else
  4918. // {
  4919. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
  4920. // }
  4921. //
  4922. //
  4923. // });
  4924. // });
  4925. //
  4926. //
  4927. //
  4928. // }
  4929. // self.lastedit = nil;
  4930. // self.lastedit_from=nil;
  4931. //
  4932. // return;
  4933. // }
  4934. //
  4935. }
  4936. - (void)textFieldDidBeginEditing:(UITextField *)textField
  4937. {
  4938. DebugLog(@"textField textFieldDidBeginEditing");
  4939. self.lastedit = textField;
  4940. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  4941. self.lastedit_from = [self.editorTable indexPathForCell:cell];
  4942. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[self.lastedit_from.section])[self.lastedit_from.row];
  4943. if ([item_json valueForKey:@"clear"]) {
  4944. //开始编辑时清掉旧内容
  4945. BOOL clear = [[item_json valueForKey:@"clear"] doubleValue] == [textField.text doubleValue];
  4946. if (clear) {
  4947. textField.text = nil;
  4948. }
  4949. }
  4950. }
  4951. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  4952. self.editingcell = (UITableViewCell*)textField.superview.superview;
  4953. NSIndexPath* indexPath=[self.editorTable indexPathForCell:self.editingcell];
  4954. // NSMutableDictionary* section_json=nil;
  4955. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  4956. if([item_json[@"autocomplete"] boolValue]==true)
  4957. {
  4958. // [textField endEditing:true];
  4959. self.lastedit_from = [self.editorTable indexPathForCell:(UITableViewCell*) textField.superview.superview];
  4960. self.autocompleteView.active_field = textField;
  4961. self.autocompleteView.hidden = false;
  4962. self.autocompleteView.searchInput.keyboardType=textField.keyboardType;
  4963. self.autocompleteView.searchInput.text= textField.text;
  4964. [self.autocompleteView.searchInput becomeFirstResponder];
  4965. __weak typeof(self) weakself = self;
  4966. self.autocompleteView.returnValue = ^(NSString *str) {
  4967. //textField = true;
  4968. // [textField endEditing:false];
  4969. textField.text=str;
  4970. // [textField endEditing:true];
  4971. [weakself textFieldDidEndEditing:textField];
  4972. };
  4973. return false;
  4974. }
  4975. return YES;
  4976. }
  4977. #pragma mark- autocomplete //自动完成填空内容需要实现此协议
  4978. -(nullable NSArray*)sync_loadCadidate:(nonnull NSString*)str
  4979. {
  4980. NSMutableArray* ret = [NSMutableArray new];
  4981. NSDictionary* obj = @{@"name":@"",@"value":@"autocomplete datasource loadCadidate does not impl"};
  4982. [ret addObject:obj];
  4983. return ret;
  4984. }
  4985. #pragma mark- img changed
  4986. // image 改变时执行
  4987. - (void) imgIsChanged:(NSString *)url_down url_up:(NSString *)url_up indexPath: (NSIndexPath *) indexPath index:(int)index url_index:(NSString* )url_index{
  4988. // DebugLog(@"Sender is = %@", url);
  4989. NSMutableDictionary* section_json=nil;
  4990. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  4991. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  4992. int refresh = [[item_json valueForKey:@"refresh"] intValue];
  4993. bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
  4994. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  4995. NSString* subid=[item_json valueForKey:@"subid"];
  4996. // NSArray* imgs=[RAUtils string2arr:url_up separator:@","];
  4997. // imgs[index];
  4998. item_json[ [NSString stringWithFormat:@"img_url_%d",index]]=url_down;
  4999. item_json[@"avalue"]=url_up;
  5000. item_json[[NSString stringWithFormat:@"img_url_aname_%d",index]]=url_index;
  5001. [item_json setValue:@"true" forKey:@"dirty"];
  5002. if(subid==nil)
  5003. {
  5004. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  5005. int count=0;
  5006. count=[[section_json valueForKey:@"count"] intValue];
  5007. for(int i=0;i<count;i++)
  5008. {
  5009. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  5010. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  5011. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  5012. }
  5013. }
  5014. else
  5015. {
  5016. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  5017. int section = [(NSString*)idarr[0] intValue];
  5018. int item=[(NSString*)idarr[1] intValue];
  5019. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  5020. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  5021. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  5022. [item_json setValue:@"true" forKey:@"dirty"];
  5023. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  5024. }
  5025. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  5026. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  5027. // NSRange range = NSMakeRange(indexPath.section, 1);
  5028. // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  5029. // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  5030. if(refresh==1)
  5031. {
  5032. [self refresh:refresh_trigger discardDirty:discardDirty];
  5033. }
  5034. }
  5035. #pragma mark- switch changed
  5036. - (void) switchIsChanged:(UISwitch *)paramSender{
  5037. // [self.switchlock lock];
  5038. // DebugLog(@"switch lock");
  5039. UITableViewCell *cell = (UITableViewCell *) paramSender.superview.superview;
  5040. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  5041. if(indexPath==nil)
  5042. {
  5043. [paramSender setOn:!paramSender.isOn];
  5044. return ;
  5045. }
  5046. NSMutableDictionary* section_json=nil;
  5047. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  5048. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  5049. int refresh = [[item_json valueForKey:@"refresh"] intValue];
  5050. bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
  5051. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  5052. NSString* subid=[item_json valueForKey:@"subid"];
  5053. NSString* check=@"false";
  5054. if([paramSender isOn])
  5055. check=@"true";
  5056. [item_json setValue:@"true" forKey:@"dirty"];
  5057. [item_json setValue:check forKey:@"value"];
  5058. if(subid==nil)
  5059. {
  5060. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  5061. int count=0;
  5062. count=[[section_json valueForKey:@"count"] intValue];
  5063. for(int i=0;i<count;i++)
  5064. {
  5065. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  5066. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  5067. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  5068. }
  5069. }
  5070. else
  5071. {
  5072. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  5073. int section = [(NSString*)idarr[0] intValue];
  5074. int item=[(NSString*)idarr[1] intValue];
  5075. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  5076. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  5077. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  5078. [item_json setValue:@"true" forKey:@"dirty"];
  5079. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  5080. }
  5081. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  5082. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  5083. NSRange range = NSMakeRange(indexPath.section, 1);
  5084. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  5085. [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  5086. if(refresh==1)
  5087. {
  5088. [self refresh:refresh_trigger discardDirty:discardDirty];
  5089. }
  5090. DebugLog(@"switch unlock");
  5091. // [self.switchlock unlock];
  5092. }
  5093. -(NSMutableDictionary*) fill_switch_subitem:(NSMutableDictionary *) switch_item subid:(NSArray*) subid source:(NSMutableDictionary*)source mapping:(NSDictionary*)mapping //step:(int) step
  5094. {
  5095. NSString* value = [switch_item valueForKey:@"value"];
  5096. NSMutableDictionary* boolitem=nil;
  5097. NSMutableDictionary* subjson=nil;
  5098. if([value isEqualToString:@"true"])
  5099. {
  5100. boolitem =[[switch_item objectForKey:@"true"] mutableCopy];
  5101. }
  5102. else
  5103. {
  5104. boolitem =[[switch_item objectForKey:@"false"] mutableCopy];
  5105. }
  5106. subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  5107. if( subjson!=nil /*&& !active*/)
  5108. {
  5109. int sub_count = [[subjson valueForKey:@"count"] intValue];
  5110. for(int l=0;l<sub_count;l++)
  5111. {
  5112. NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  5113. // NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  5114. NSString* mapto = [modify_item valueForKey:@"name"];
  5115. if(mapto.length==0)
  5116. continue;
  5117. NSString* valuefrom= [mapping valueForKey:[modify_item valueForKey:@"name"]];
  5118. if(valuefrom==nil)
  5119. continue;
  5120. NSString* valuestr= [source valueForKey:valuefrom];
  5121. if(TRUE)
  5122. {
  5123. if(valuestr.length>0)
  5124. [modify_item setValue:valuestr forKey:@"value"];
  5125. else
  5126. [modify_item setValue:@"" forKey:@"value"];
  5127. [modify_item setValue:@"true" forKey:@"dirty"];
  5128. [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]];
  5129. }
  5130. }
  5131. [boolitem setObject:subjson forKey:@"sub_item"];
  5132. if([value isEqualToString:@"true"])
  5133. [switch_item setObject:boolitem forKey:@"true"];
  5134. else
  5135. [switch_item setObject:boolitem forKey:@"false"];
  5136. }
  5137. return switch_item;
  5138. }
  5139. -(NSMutableDictionary*) fill_enum_subitem:(NSMutableDictionary *) enum_item subid:(NSArray*) subid source:(NSMutableDictionary*)source mapping:(NSDictionary*)mapping //step:(int) step
  5140. {
  5141. NSMutableDictionary* cadedatejson = [[enum_item objectForKey:@"cadedate"] mutableCopy];
  5142. int count = [[cadedatejson valueForKey:@"count"]intValue];
  5143. for(int i=0;i<count;i++)
  5144. {
  5145. NSMutableDictionary* val_json = [[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",i]] mutableCopy];
  5146. int check = [[val_json valueForKey:@"check"] intValue];
  5147. if(check==1)
  5148. {
  5149. NSMutableDictionary* subjson=[[val_json objectForKey:@"sub_item"] mutableCopy];
  5150. if( subjson!=nil /*&& !active*/)
  5151. {
  5152. int sub_count = [[subjson valueForKey:@"count"] intValue];
  5153. for(int l=0;l<sub_count;l++)
  5154. {
  5155. NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  5156. // NSString* subid=[modify_item valueForKey:@"subid"];
  5157. //
  5158. //
  5159. // NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  5160. NSString* control_type = [modify_item valueForKey:@"control"];
  5161. if([control_type isEqualToString:@"switch"])
  5162. modify_item= [self fill_switch_subitem:modify_item subid:nil source:source mapping:mapping ];
  5163. else if([control_type isEqualToString:@"enum"])
  5164. {
  5165. modify_item= [self fill_enum_subitem:modify_item subid:nil source:source mapping:mapping ];
  5166. }
  5167. else
  5168. {
  5169. NSString* mapto = [modify_item valueForKey:@"name"];
  5170. if(mapto.length==0)
  5171. continue;
  5172. NSString* valuefrom= [mapping valueForKey:[modify_item valueForKey:@"name"]];
  5173. if(valuefrom==nil)
  5174. continue;
  5175. NSString* valuestr= [source valueForKey:valuefrom];
  5176. if(true)
  5177. {
  5178. if(valuestr.length>0)
  5179. [modify_item setValue:valuestr forKey:@"value"];
  5180. else
  5181. [modify_item setValue:@"" forKey:@"value"];
  5182. //[modify_item setValue:valuestr forKey:@"value"];
  5183. // [modify_item setValue:@"true" forKey:@"dirty"];
  5184. }
  5185. }
  5186. [modify_item setValue:@"true" forKey:@"dirty"];
  5187. [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]];
  5188. // [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  5189. // NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  5190. }
  5191. [val_json setObject:subjson forKey:@"sub_item"];
  5192. }
  5193. }
  5194. [cadedatejson setObject:val_json forKey:[NSString stringWithFormat:@"val_%d",i]];
  5195. }
  5196. [enum_item setObject:cadedatejson forKey:@"cadedate"];
  5197. return enum_item;
  5198. }
  5199. -(NSMutableDictionary*) switch_subitem_changed:(NSMutableDictionary *) switch_item subid:(NSArray*) subid value:(NSMutableDictionary*)valuejson step:(int) step
  5200. {
  5201. int index = [(NSString*)subid[step] intValue];
  5202. NSString* value = [switch_item valueForKey:@"value"];
  5203. NSMutableDictionary* boolitem=nil;
  5204. NSMutableDictionary* subjson=nil;
  5205. if([value isEqualToString:@"true"])
  5206. {
  5207. boolitem =[[switch_item objectForKey:@"true"] mutableCopy];
  5208. }
  5209. else
  5210. {
  5211. boolitem =[[switch_item objectForKey:@"false"] mutableCopy];
  5212. }
  5213. subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  5214. if(subjson!=nil)
  5215. {
  5216. NSMutableDictionary * itemjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",index]] mutableCopy];
  5217. if(step==subid.count-1)
  5218. {
  5219. itemjson =valuejson;
  5220. }
  5221. [subjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",index]];
  5222. [boolitem setObject:subjson forKey:@"sub_item"];
  5223. if([value isEqualToString:@"true"])
  5224. [switch_item setObject:boolitem forKey:@"true"];
  5225. else
  5226. [switch_item setObject:boolitem forKey:@"false"];
  5227. return switch_item;
  5228. }
  5229. return nil;
  5230. }
  5231. #pragma mark Request Editor
  5232. //-(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  5233. //{
  5234. // return [RANetwork request_Editor:request_url params:params];
  5235. //}
  5236. //
  5237. //- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  5238. //{
  5239. //
  5240. // NSLog(@"willDisplayCell");
  5241. // NSString *cellclass;
  5242. // const char *class_name_ch = object_getClassName([cell class]);
  5243. // cellclass = [NSString stringWithUTF8String:class_name_ch];
  5244. //
  5245. // CommonEditorCellTextView * tvcell=nil;
  5246. // if([cellclass isEqualToString:@"CommonEditorCellTextView"])
  5247. // {
  5248. // tvcell=(CommonEditorCellTextView*)self.editingcell;
  5249. // tvcell.textview.scrollEnabled=true;
  5250. //
  5251. //
  5252. // }
  5253. //}
  5254. //- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath
  5255. //{
  5256. //
  5257. // NSLog(@"didEndDisplayingCell");
  5258. // NSString *cellclass;
  5259. // const char *class_name_ch = object_getClassName([cell class]);
  5260. // cellclass = [NSString stringWithUTF8String:class_name_ch];
  5261. //
  5262. // CommonEditorCellTextView * tvcell=nil;
  5263. // if([cellclass isEqualToString:@"CommonEditorCellTextView"])
  5264. // {
  5265. // tvcell=(CommonEditorCellTextView*)self.editingcell;
  5266. // tvcell.textview.scrollEnabled=false;
  5267. //
  5268. //
  5269. // }
  5270. //
  5271. //}
  5272. #pragma mark - Responding to keyboard events
  5273. - (void)keyboardWillChangeFrame:(NSNotification *)notification {
  5274. // return;
  5275. DebugLog(@"keyboardWillChangeFrame");
  5276. // 使用tableContainer计算frame 保证屏幕旋转后table height正确
  5277. CGRect table_origin_screen_frame = [self.tableContainer convertRect:self.tableContainer.bounds toView:self.view.window];
  5278. // NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
  5279. // duration *= 0.0;
  5280. CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  5281. CGFloat end_y = end.origin.y;
  5282. CGRect screenframe=[[UIScreen mainScreen] bounds];
  5283. self.autocompleteView.frame= CGRectMake(screenframe.origin.x, screenframe.origin.y, screenframe.size.width, end_y);
  5284. NSIndexPath *indexPath = [self.editorTable indexPathForCell:self.editingcell];
  5285. CGRect table_frame = self.editorTable.frame;
  5286. // table底部距离键盘顶部偏移
  5287. CGFloat offset = CGRectGetMaxY(table_origin_screen_frame) - end_y;
  5288. if (offset > 0) {
  5289. // table -> top > offset: table.y = -offset
  5290. // 事实上top:topLayoutGuide
  5291. // self.additionalSafeAreaInsets
  5292. float y0=self.view.safeAreaLayoutGuide.topAnchor.accessibilityActivationPoint.y;
  5293. CGFloat topAvailableHeight = (CGRectGetMinY(table_origin_screen_frame) - y0);
  5294. if (topAvailableHeight > 0) {
  5295. if (topAvailableHeight > offset) {
  5296. table_frame.origin.y = -offset;
  5297. } else {
  5298. // 向上移动到topLayoutGuide,不足部分通过缩减高度到达keyboard顶部
  5299. // table_frame.origin.y = -topAvailableHeight;
  5300. // table_frame.size.height = (end_y - self.topLayoutGuide.length);
  5301. for (NSLayoutConstraint *constraint in self.tableContainer.constraints) {
  5302. if (constraint.firstAttribute == NSLayoutAttributeBottom) {
  5303. // int a=0;
  5304. [self.tableContainer removeConstraint:constraint];
  5305. NSLayoutConstraint *bottom_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
  5306. attribute:NSLayoutAttributeBottom
  5307. relatedBy:NSLayoutRelationEqual
  5308. toItem:self.tableContainer
  5309. attribute:NSLayoutAttributeBottom
  5310. multiplier:1
  5311. constant:-end.size.height];
  5312. self.tb_bottom_constraint = bottom_constraint;
  5313. [self.tableContainer addConstraint:bottom_constraint];
  5314. break;
  5315. //
  5316. }
  5317. }
  5318. }
  5319. } else {
  5320. // contentInset = (top = 64, left = 0, bottom = 0, right = 0),topAvailableHeight = -64
  5321. table_frame.size.height = table_origin_screen_frame.size.height - offset;
  5322. }
  5323. // table_frame.size.height = CGRectGetHeight(table_origin_screen_frame) - (CGRectGetMaxY(table_origin_screen_frame) - end_y);
  5324. } else {
  5325. // table_frame.size.height = CGRectGetHeight(table_origin_screen_frame);
  5326. // table_frame = self.tableContainer.bounds;
  5327. for (NSLayoutConstraint *constraint in self.tableContainer.constraints) {
  5328. if (constraint.firstAttribute == NSLayoutAttributeBottom) {
  5329. // int a=0;
  5330. [self.tableContainer removeConstraint:constraint];
  5331. NSLayoutConstraint *bottom_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
  5332. attribute:NSLayoutAttributeBottom
  5333. relatedBy:NSLayoutRelationEqual
  5334. toItem:self.tableContainer
  5335. attribute:NSLayoutAttributeBottom
  5336. multiplier:1
  5337. constant:0];
  5338. self.tb_bottom_constraint = bottom_constraint;
  5339. [self.tableContainer addConstraint:bottom_constraint];
  5340. break;
  5341. //
  5342. }
  5343. }
  5344. }
  5345. self.editorTable.frame = table_frame;
  5346. CGRect cell_screen_frame = [self.editingcell convertRect:self.editingcell.bounds toView:self.view.window];
  5347. int cover =CGRectGetMaxY(cell_screen_frame) - end_y;
  5348. if (cover>0) {
  5349. // Cell 被键盘遮挡后才滚动
  5350. NSLog(@"scrollToRowAtIndexPath");
  5351. NSString *cellclass;
  5352. const char *class_name_ch = object_getClassName([self.editingcell class]);
  5353. cellclass = [NSString stringWithUTF8String:class_name_ch];
  5354. CommonEditorCellTextView * tvcell=nil;
  5355. // if([cellclass isEqualToString:@"CommonEditorCellTextView"])
  5356. {
  5357. // tvcell=(CommonEditorCellTextView*)self.editingcell;
  5358. // tvcell.textview.scrollEnabled=false;
  5359. CGPoint current_offset=self.editorTable.contentOffset;
  5360. NSLog(@"OFFSET %f",current_offset.y);
  5361. CGPoint moveto= CGPointMake(self.editingcell.frame.origin.x,current_offset.y+cover);
  5362. [self.editorTable setContentOffset:moveto];
  5363. }
  5364. ;
  5365. // self.editorTable cell
  5366. // self.editorTable scrollto
  5367. // self.editorTable scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition) animated:<#(BOOL)#>
  5368. // CGPoint current_offset=self.editorTable.contentOffset;
  5369. //
  5370. // NSLog(@"OFFSET %f",current_offset.y);
  5371. // CGPoint moveto= CGPointMake(self.editingcell.frame.origin.x,current_offset.y+cover);
  5372. // [self.editorTable setContentOffset:self.editingcell.frame.origin];
  5373. // [self.editorTable scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:NO];
  5374. //
  5375. }
  5376. // ===============================================
  5377. if (end_y >= [UIScreen mainScreen].bounds.size.height) {
  5378. self.keyboard_show = NO;
  5379. } else {
  5380. self.keyboard_show = YES;
  5381. }
  5382. }
  5383. - (void)keyboardDidChangeFrame:(NSNotification *)notification {
  5384. NSLog(@"keyboardDidChangeFrame");
  5385. // NSString *cellclass;
  5386. // const char *class_name_ch = object_getClassName([self.editingcell class]);
  5387. // cellclass = [NSString stringWithUTF8String:class_name_ch];
  5388. //
  5389. // CommonEditorCellTextView * tvcell=nil;
  5390. // if([cellclass isEqualToString:@"CommonEditorCellTextView"])
  5391. // {
  5392. //
  5393. // tvcell=(CommonEditorCellTextView*)self.editingcell;
  5394. // tvcell.textview.scrollEnabled=true;
  5395. //
  5396. //
  5397. // }
  5398. return;
  5399. // 使用tableContainer计算frame 保证屏幕旋转后table height正确
  5400. // CGRect table_origin_screen_frame = [self.tableContainer convertRect:self.tableContainer.bounds toView:self.view.window];
  5401. CGRect screen_rect = [RAUtils relativeFrameForScreenWithView:self.editorTable];
  5402. //
  5403. // // NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
  5404. // // duration *= 0.0;
  5405. CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  5406. // CGRect begin = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
  5407. float kbheight = end.size.height;
  5408. CGFloat keyboard_top = end.origin.y;
  5409. NSLog(@"keyboard rect: %@",NSStringFromCGRect(end));
  5410. NSLog(@"view rect: %@",NSStringFromCGRect(self.view.frame));
  5411. NSLog(@"view screen rect: %@",NSStringFromCGRect(screen_rect));
  5412. // self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
  5413. float dark = screen_rect.origin.y+screen_rect.size.height-keyboard_top;
  5414. if(dark>0)
  5415. {
  5416. // self.editorTable.scrollEnabled = true;
  5417. // self.editorTable.contentSize = CGSizeMake(self.editorTable.frame.size.width, self.editorTable.frame.size.height+dark);
  5418. self.editorTable.contentSize=CGSizeMake(self.editorTable.contentSize.width, self.editorTable.contentSize.height+kbheight);
  5419. }
  5420. else
  5421. {
  5422. // self.editorTable.scrollEnabled = false;
  5423. // self.editorTable.contentSize = self.editorTable.frame.size;
  5424. self.editorTable.contentSize=CGSizeMake(self.editorTable.contentSize.width, self.editorTable.contentSize.height-kbheight);
  5425. }
  5426. }
  5427. //static float table_origin_h = 0;
  5428. //
  5429. //- (void)keyboardWillShow:(NSNotification *)notification {
  5430. // DebugLog(@"keyboardWillShow");
  5431. ////
  5432. //// if(self.keyboard_show)
  5433. //// return;
  5434. ////
  5435. //// self.keyboard_show=true;
  5436. //// /*
  5437. //// Reduce the size of the text view so that it's not obscured by the keyboard.
  5438. //// Animate the resize so that it's in sync with the appearance of the keyboard.
  5439. //// */
  5440. ////
  5441. //// NSDictionary *userInfo = [notification userInfo];
  5442. ////
  5443. //// // Get the origin of the keyboard when it's displayed.
  5444. //// NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  5445. ////
  5446. //// // 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.
  5447. //// // CGRect keyboardRect = [aValue CGRectValue];
  5448. //// CGSize keyboardSize = [aValue CGRectValue].size;
  5449. //// DebugLog(@"keyboard height:%f",keyboardSize.height);
  5450. //// // Get the duration of the animation.
  5451. //// NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
  5452. //// NSTimeInterval animationDuration;
  5453. //// [animationDurationValue getValue:&animationDuration];
  5454. ////
  5455. ////
  5456. //// // if(self.keyboard_h==0)
  5457. //// // {
  5458. //// self.keyboard_h =keyboardSize.height;
  5459. //// CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:self.editingcell];
  5460. //// CGRect rect_screen = [ UIScreen mainScreen ].bounds;
  5461. ////
  5462. //// // int vpos =self.view.frame.origin.y+self.view.frame.size.height;
  5463. //// // int loginpos = self.editingcell.frame.origin.y+self.editingcell.frame.size.height;
  5464. //// //
  5465. //// int cellpos = cellrect_screen.origin.y+cellrect_screen.size.height;
  5466. //// // screen.size.height-keyboardSize.height-(cellpos_screen.origin.x+cellpos_screen.size.height);
  5467. //// 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);
  5468. //// if(self.ioffset>0)
  5469. //// {
  5470. //// // self.resize = true;
  5471. ////
  5472. ////
  5473. //// CGPoint contentOffsetPoint = self.editorTable.contentOffset;
  5474. ////
  5475. ////
  5476. //// contentOffsetPoint.y+=self.ioffset;
  5477. ////
  5478. //// self.editorTable.contentOffset=contentOffsetPoint;
  5479. ////
  5480. ////
  5481. //// // NSTimeInterval animationDuration = 0.30f;
  5482. //// // CGRect frame = self.view.frame;
  5483. //// // frame.origin.y -=self.ioffset;//view的Y轴上移
  5484. //// // frame.size.height +=self.ioffset; //View的高度增加
  5485. //// // self.view.frame = frame;
  5486. //// // [UIView beginAnimations:@"ResizeView" context:nil];
  5487. //// // [UIView setAnimationDuration:animationDuration];
  5488. //// // self.view.frame = frame;
  5489. //// // [UIView commitAnimations];//设置调整界面的动画效果
  5490. //// }
  5491. ////
  5492. //// table_origin_h = self.editorTable.frame.size.height;
  5493. //// self.editorTable.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, self.editorTable.frame.size.height-self.keyboard_h);
  5494. ////
  5495. //// // CGSize tablecontent =self.editorTable.contentSize;
  5496. //// // tablecontent.height=tablecontent.height+self.keyboard_h;
  5497. //// // self.editorTable.contentSize=tablecontent;
  5498. //// // }
  5499. //// // Animate the resize of the text view's frame in sync with the keyboard's appearance.
  5500. //// // [self moveInputBarWithKeyboardHeight:keyboardRect.size.height withDuration:animationDuration];
  5501. //}
  5502. //- (void)keyboardWillHide:(NSNotification *)notification {
  5503. // DebugLog(@"keyboardWillHide");
  5504. //
  5505. //// self.keyboard_show=false;
  5506. //// NSDictionary* userInfo = [notification userInfo];
  5507. ////
  5508. //// /*
  5509. //// Restore the size of the text view (fill self's view).
  5510. //// Animate the resize so that it's in sync with the disappearance of the keyboard.
  5511. //// */
  5512. //// NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
  5513. //// NSTimeInterval animationDuration;
  5514. //// [animationDurationValue getValue:&animationDuration];
  5515. //// CGSize tablecontent =self.editorTable.contentSize;
  5516. //// tablecontent.height=tablecontent.height-self.keyboard_h;
  5517. //// // self.editorTable.contentSize=tablecontent;
  5518. ////
  5519. //// self.editorTable.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, table_origin_h);
  5520. ////
  5521. //// self.keyboard_h= 0;
  5522. //// DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  5523. ////
  5524. ////
  5525. //// // if(self.resize)
  5526. //// // {
  5527. //// // NSTimeInterval animationDuration = 0.30f;
  5528. //// // CGRect frame = self.view.frame;
  5529. //// // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
  5530. //// // // { //还原界面
  5531. //// // // moveY = prewMoveY;
  5532. //// // frame.origin.y +=self.ioffset;
  5533. //// // frame.size. height -=self.ioffset;
  5534. //// // self.view.frame = frame;
  5535. //// // // }
  5536. //// // //self.view移回原位置
  5537. //// // [UIView beginAnimations:@"ResizeView" context:nil];
  5538. //// // [UIView setAnimationDuration:animationDuration];
  5539. //// // self.view.frame = frame;
  5540. //// // [UIView commitAnimations];
  5541. //// // //[textField resignFirstResponder];
  5542. //// // self.ioffset=0;
  5543. //// // }
  5544. ////
  5545. ////
  5546. //// // [self moveInputBarWithKeyboardHeight:0.0 withDuration:animationDuration];
  5547. //}
  5548. #pragma mark - RageCell Delegate
  5549. - (void)commonEditorRangeCell:(CommonEditorRangeCell *)cell didChangeMinValue:(NSString *)minValue maxValue:(NSString *)maxValue atIndexPath:(NSIndexPath *)indexPath{
  5550. if (indexPath == nil) {
  5551. if (cell != nil) {
  5552. indexPath = [self.editorTable indexPathForCell:cell];
  5553. } else {
  5554. return;
  5555. }
  5556. }
  5557. if (indexPath == nil) {
  5558. return;
  5559. }
  5560. NSString *section_key = [NSString stringWithFormat:@"section_%ld",indexPath.section];
  5561. NSString *item_key = [NSString stringWithFormat:@"item_%ld",indexPath.row];
  5562. NSMutableDictionary *section_json = [[self.content_data_download objectForKey:section_key] mutableCopy];
  5563. NSMutableDictionary *item_json = [((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  5564. [item_json setObject:minValue forKey:@"min_value"];
  5565. [item_json setObject:maxValue forKey:@"max_value"];
  5566. [section_json setObject:item_json forKey:item_key];
  5567. [self.content_data_download setObject:section_json forKey:section_key];
  5568. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  5569. }
  5570. #pragma mark - WebCell Delegate
  5571. - (void)commonEditorWebCell:(CommonEditorWebCell *)cell didChangeContentHeight:(CGFloat)contentHeight {
  5572. // return;
  5573. NSIndexPath *indexPath = [self.editorTable indexPathForCell:cell];
  5574. if (indexPath == nil) {
  5575. return;
  5576. }
  5577. NSMutableDictionary* section_json=nil;
  5578. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  5579. NSString* subid=[item_json valueForKey:@"subid"];
  5580. NSString* control = [item_json valueForKey:@"control"];
  5581. id height_obj = [item_json objectForKey:@"height"];
  5582. // NSLog(@"indexPath: %@ origin height: %@ currentHeight: %f",indexPath,height_obj,contentHeight);
  5583. if ([control isEqualToString:@"webview"] && [height_obj floatValue] != contentHeight)
  5584. {
  5585. [item_json setValue:@(contentHeight) forKey:@"height"];
  5586. if(subid==nil)
  5587. {
  5588. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  5589. int count=0;
  5590. count=[[section_json valueForKey:@"count"] intValue];
  5591. for(int i=0;i<count;i++)
  5592. {
  5593. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  5594. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  5595. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  5596. }
  5597. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  5598. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  5599. }
  5600. // else
  5601. // {
  5602. // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  5603. // int section = [(NSString*)idarr[0] intValue];
  5604. // int item=[(NSString*)idarr[1] intValue];
  5605. //
  5606. //
  5607. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  5608. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  5609. //
  5610. // NSString* control_type= [olditem valueForKey:@"control"];
  5611. // NSMutableDictionary* new_item=nil;
  5612. //// [item_json setValue:@"true" forKey:@"dirty"];
  5613. // if([control_type isEqualToString:@"enum"])
  5614. // new_item= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  5615. // else if([control_type isEqualToString:@"switch"])
  5616. // new_item= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  5617. //
  5618. // [section_json setObject:new_item forKey:[NSString stringWithFormat:@"item_%d",item ]];
  5619. //
  5620. //
  5621. // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  5622. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  5623. // }
  5624. // // 更新数据
  5625. // [item_json setObject:@(contentHeight) forKey:@"height"];
  5626. //
  5627. // NSMutableDictionary *section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  5628. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  5629. // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  5630. // self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  5631. //
  5632. // // 调用 tableView 的 beginUpdates 和 endUpdates,更新 cell 的高度
  5633. // [self.editorTable beginUpdates];
  5634. // [self.editorTable endUpdates];
  5635. dispatch_async(dispatch_get_main_queue(), ^{
  5636. // UI更新代码
  5637. [self.editorTable reloadData];
  5638. //[self.editorTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  5639. });
  5640. }
  5641. }
  5642. - (void)MActionClicked:(UIButton *)sender {
  5643. [RAUtils message_alert:@"MActionClicked dose not impl" title:@"Warring" controller:self];
  5644. }
  5645. #pragma mark - Banner Delegate
  5646. - (void)commonEditorBannerCell:(CommonEditorBannerCell *)cell didClickItemAtIndexPath:(NSIndexPath *)indexPath {
  5647. if ([[[cell content] objectForKey:@"count"] integerValue] == 0) {
  5648. return;
  5649. }
  5650. ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
  5651. preVC.content = [cell content];
  5652. [preVC setOffset:indexPath.row];
  5653. if (self.navigationController) {
  5654. [self.navigationController pushViewController:preVC animated:YES];
  5655. } else {
  5656. [self presentViewController:preVC animated:true completion:nil];
  5657. }
  5658. }
  5659. #pragma mark 为子类暴露的接口
  5660. -(void) handle_editor_cell_select:(UITableView *)tableView IndexPath:(NSIndexPath *)indexPath
  5661. {
  5662. NSAssert(true, ([NSString stringWithFormat:@"%@ handle_editor_cell_select not impl",[self class_name]]));
  5663. }
  5664. @end