CommonEditorViewController.m 314 KB

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