CommonEditorViewController.m 310 KB

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