CommonEditorViewController.m 309 KB

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