CommonEditorViewController.m 304 KB

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