CommonEditorViewController.m 305 KB

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