CommonEditorViewController.m 307 KB

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