CommonEditorViewController.m 269 KB

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