CommonEditorViewController.m 319 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356
  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. NSString* item_value = item_json[@"value"];
  2006. if(item_value.length==0)
  2007. item_value = @"";
  2008. if(![val isEqualToString:item_value])
  2009. {
  2010. //值不相同才设置dirty
  2011. [item_json setValue:@"true" forKey:@"dirty"];
  2012. self.isdirty = true;
  2013. }
  2014. [item_json setValue:val forKey:@"value"];
  2015. if([[item_json valueForKey:@"keyboard"] isEqualToString:@"number"])
  2016. {
  2017. float f = [ val floatValue];
  2018. [item_json setValue:[NSString stringWithFormat:@"%.2f",f] forKey:@"value"];
  2019. }
  2020. // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
  2021. if(subid==nil)
  2022. {
  2023. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  2024. int count=0;
  2025. count=[[section_json valueForKey:@"count"] intValue];
  2026. for(int i=0;i<count;i++)
  2027. {
  2028. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  2029. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  2030. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  2031. }
  2032. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  2033. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  2034. bool refresh = [[item_json valueForKey:@"refresh"] boolValue];
  2035. bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
  2036. NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  2037. bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
  2038. if(refresh)
  2039. {
  2040. if(restore_json!=nil)
  2041. {
  2042. int rc=[[restore_json valueForKey:@"count"] intValue];
  2043. for(int ir=0;ir<rc;ir++)
  2044. {
  2045. NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  2046. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  2047. for(int i=0;i<section_count;i++)
  2048. {
  2049. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2050. // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2051. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  2052. for(int j=0;j<item_count;j++)
  2053. {
  2054. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2055. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2056. if([[itemjson valueForKey:@"name"] isEqualToString:name])
  2057. {
  2058. [itemjson removeObjectForKey:@"dirty"];
  2059. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  2060. }
  2061. }
  2062. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  2063. }
  2064. }
  2065. }
  2066. [self refresh:refresh_trigger discardDirty:discardDirty];
  2067. }
  2068. else if(partial_refresh)
  2069. {
  2070. NSString* name = [item_json valueForKey:@"name"] ;
  2071. NSString* url = [item_json valueForKey:@"data_interface"] ;
  2072. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2073. [params setValue:val forKey:name];
  2074. __weak typeof(self) weakself = self;
  2075. __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{
  2076. [RADataProvider request_commoneditor_partialrefresh:params url:url completionHandler:^(NSMutableDictionary *result) {
  2077. NSDictionary* editor_json =result;
  2078. [waitalert dismissViewControllerAnimated:YES completion:^{
  2079. if([[editor_json valueForKey:@"result"] intValue]==2)
  2080. {
  2081. int prcount = [[editor_json valueForKey:@"count"] intValue];
  2082. for(int ipr=0;ipr<prcount;ipr++)
  2083. {
  2084. NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
  2085. NSString* name = [pr_item valueForKey:@"name"];
  2086. NSString* value = [pr_item valueForKey:@"value"];
  2087. [weakself setValue:name value:value];
  2088. }
  2089. }
  2090. else if([[editor_json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE)
  2091. {
  2092. [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:nil];
  2093. }
  2094. else
  2095. {
  2096. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:weakself] ;
  2097. }
  2098. }];
  2099. }];
  2100. }];
  2101. self.alert = waitalert;
  2102. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2103. //
  2104. // NSDictionary* editor_json = [RANetwork commoneditor_partialrefresh:params url:url];
  2105. //
  2106. // dispatch_async(dispatch_get_main_queue(), ^{
  2107. //
  2108. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2109. //
  2110. //
  2111. // if([[editor_json valueForKey:@"result"] intValue]==2)
  2112. // {
  2113. //
  2114. // int prcount = [[editor_json valueForKey:@"count"] intValue];
  2115. // for(int ipr=0;ipr<prcount;ipr++)
  2116. // {
  2117. // NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
  2118. // NSString* name = [pr_item valueForKey:@"name"];
  2119. // NSString* value = [pr_item valueForKey:@"value"];
  2120. //
  2121. // [weakself setValue:name value:value];
  2122. // }
  2123. //
  2124. //
  2125. // }
  2126. // else
  2127. // {
  2128. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:weakself] ;
  2129. // }
  2130. //
  2131. //
  2132. // });
  2133. // });
  2134. }
  2135. self.lastedit = nil;
  2136. self.lastedit_from=nil;
  2137. return ;
  2138. }
  2139. else
  2140. {
  2141. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  2142. int section = [(NSString*)idarr[0] intValue];
  2143. int item=[(NSString*)idarr[1] intValue];
  2144. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  2145. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  2146. NSString* control_type= [olditem valueForKey:@"control"];
  2147. NSMutableDictionary* new_item=nil;
  2148. [item_json setValue:@"true" forKey:@"dirty"];
  2149. if([control_type isEqualToString:@"enum"])
  2150. new_item= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  2151. else if([control_type isEqualToString:@"switch"])
  2152. new_item= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  2153. [section_json setObject:new_item forKey:[NSString stringWithFormat:@"item_%d",item ]];
  2154. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  2155. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  2156. bool refresh = [[item_json valueForKey:@"refresh"] boolValue];
  2157. bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
  2158. NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  2159. bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
  2160. if(refresh)
  2161. {
  2162. if(restore_json!=nil)
  2163. {
  2164. int rc=[[restore_json valueForKey:@"count"] intValue];
  2165. for(int ir=0;ir<rc;ir++)
  2166. {
  2167. NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  2168. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  2169. for(int i=0;i<section_count;i++)
  2170. {
  2171. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2172. // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2173. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  2174. for(int j=0;j<item_count;j++)
  2175. {
  2176. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2177. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2178. if([[itemjson valueForKey:@"name"] isEqualToString:name])
  2179. {
  2180. [itemjson removeObjectForKey:@"dirty"];
  2181. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  2182. }
  2183. }
  2184. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  2185. }
  2186. }
  2187. }
  2188. [self refresh:refresh_trigger discardDirty:discardDirty];
  2189. }
  2190. else if(partial_refresh)
  2191. {
  2192. NSString* name = [item_json valueForKey:@"name"] ;
  2193. NSString* url = [item_json valueForKey:@"data_interface"] ;
  2194. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2195. [params setValue:val forKey:name];
  2196. __weak typeof(self) weakself = self;
  2197. __block UIAlertController * waitalert = [RAUtils waiting_alert:self message:self.loading_msg title:self.loading_title completion:^{
  2198. [RADataProvider request_commoneditor_partialrefresh:params url:url completionHandler:^(NSMutableDictionary *result) {
  2199. NSDictionary* editor_json = result;
  2200. [waitalert dismissViewControllerAnimated:YES completion:^{
  2201. if([[editor_json valueForKey:@"result"] intValue]==2)
  2202. {
  2203. int prcount = [[editor_json valueForKey:@"count"] intValue];
  2204. for(int ipr=0;ipr<prcount;ipr++)
  2205. {
  2206. NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
  2207. NSString* name = [pr_item valueForKey:@"name"];
  2208. NSString* value = [pr_item valueForKey:@"value"];
  2209. [weakself setValue:name value:value];
  2210. }
  2211. }
  2212. else if([[editor_json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE)
  2213. {
  2214. [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:nil];
  2215. }
  2216. else
  2217. {
  2218. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:weakself] ;
  2219. }
  2220. }];
  2221. }];
  2222. }];
  2223. self.alert = waitalert;
  2224. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2225. //
  2226. // NSDictionary* editor_json = [RANetwork commoneditor_partialrefresh:params url:url];
  2227. //
  2228. // dispatch_async(dispatch_get_main_queue(), ^{
  2229. //
  2230. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2231. //
  2232. //
  2233. // if([[editor_json valueForKey:@"result"] intValue]==2)
  2234. // {
  2235. //
  2236. // int prcount = [[editor_json valueForKey:@"count"] intValue];
  2237. // for(int ipr=0;ipr<prcount;ipr++)
  2238. // {
  2239. // NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
  2240. // NSString* name = [pr_item valueForKey:@"name"];
  2241. // NSString* value = [pr_item valueForKey:@"value"];
  2242. //
  2243. // [weakself setValue:name value:value];
  2244. // }
  2245. //
  2246. // }
  2247. // else
  2248. // {
  2249. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:weakself] ;
  2250. // }
  2251. //
  2252. //
  2253. // });
  2254. // });
  2255. }
  2256. self.lastedit = nil;
  2257. self.lastedit_from=nil;
  2258. return;
  2259. }
  2260. // return [item valueForKey:@"value"];
  2261. }
  2262. -(void) unhide_section:(int)isection
  2263. {
  2264. NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",isection]] mutableCopy];
  2265. [section setValue:@"false" forKey:@"hide"];
  2266. [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%d",isection]];
  2267. }
  2268. -(NSIndexPath*) get_indexpath1:(NSString*)name
  2269. {
  2270. if(self.first_miss_pos!=nil)
  2271. return self.first_miss_pos;
  2272. NSIndexPath* ret=nil;
  2273. for(int i=0;i<self.content_data_control.count;i++)
  2274. {
  2275. NSMutableArray* items=(NSMutableArray*)self.content_data_control[i];
  2276. for(int j=0;j<items.count;j++)
  2277. {
  2278. NSDictionary* item=items[j];
  2279. NSString* item_name=[item valueForKey:@"name"];
  2280. if([item_name isEqualToString:name])
  2281. {
  2282. NSUInteger ii[2] = {i,j};
  2283. return [NSIndexPath indexPathWithIndexes:ii length:2];
  2284. }
  2285. }
  2286. }
  2287. return ret;
  2288. }
  2289. #pragma mark - hide section button clicked
  2290. - (void)HideSction:(UIButton *)sender {
  2291. NSMutableDictionary* section= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)sender.tag]] mutableCopy];
  2292. bool hide = [[section valueForKey:@"hide"]boolValue];
  2293. if(hide)
  2294. {
  2295. [section setValue:@"false" forKey:@"hide"];
  2296. [sender setTitle:@"Show" forState:UIControlStateNormal];
  2297. }
  2298. else{
  2299. [section setValue:@"true" forKey:@"hide"];
  2300. [sender setTitle:@"Hide" forState:UIControlStateNormal];
  2301. }
  2302. [self.content_data_download setObject:section forKey:[NSString stringWithFormat:@"section_%ld",(long)sender.tag]];
  2303. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  2304. // NSRange range = NSMakeRange(sender.tag, 1);
  2305. // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  2306. // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  2307. [self.editorTable reloadData];
  2308. }
  2309. #pragma mark - commoneditor delegate
  2310. -(void) returnValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  2311. {
  2312. [self handle_action_return:value indexPath:indexPath action:ACTION_SAVE_DATA];
  2313. // DebugLog(@"commoneditor return %d_%d",indexPath.section,indexPath.row);
  2314. //
  2315. // NSMutableDictionary* section_json=nil;
  2316. //
  2317. // NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  2318. //
  2319. //
  2320. //
  2321. // int refresh = [[item_json valueForKey:@"refresh"] intValue];
  2322. //
  2323. // NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  2324. //
  2325. //
  2326. //
  2327. // NSString* subid=[item_json valueForKey:@"subid"];
  2328. //
  2329. // UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
  2330. //
  2331. // NSString* required = [item_json valueForKey:@"required"];
  2332. // if([required isEqualToString:@"true"] && value==nil)
  2333. // {
  2334. // CALayer *layer = [cell.contentView layer];
  2335. // // layer.borderColor = [[UIColor redColor] CGColor];
  2336. // // layer.borderWidth = 1.0;
  2337. //
  2338. // layer.shadowColor = [UIColor redColor].CGColor;
  2339. // layer.shadowOffset = CGSizeMake(0, 0);
  2340. // layer.shadowOpacity = 1;
  2341. // layer.shadowRadius = 2.0;
  2342. // }
  2343. // else
  2344. // {
  2345. // CALayer *layer = [cell.contentView layer];
  2346. // // layer.borderColor = [[UIColor redColor] CGColor];
  2347. // // layer.borderWidth = 1.0;
  2348. //
  2349. // layer.shadowColor = [UIColor clearColor].CGColor;
  2350. // layer.shadowOffset = CGSizeMake(0, 0);
  2351. // layer.shadowOpacity = 1;
  2352. // layer.shadowRadius = 2.0;
  2353. // }
  2354. // if(value!=nil)
  2355. // {
  2356. // [item_json setObject:value forKey:@"data"];
  2357. //
  2358. //
  2359. // if(subid==nil)
  2360. // {
  2361. // [item_json setValue:@"true" forKey:@"dirty"];
  2362. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  2363. // int count=0;
  2364. //
  2365. // count=[[section_json valueForKey:@"count"] intValue];
  2366. //
  2367. // for(int i=0;i<count;i++)
  2368. // {
  2369. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  2370. // if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  2371. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  2372. //
  2373. //
  2374. // }
  2375. // }
  2376. // else
  2377. // {
  2378. // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  2379. // int section = [(NSString*)idarr[0] intValue];
  2380. // int item=[(NSString*)idarr[1] intValue];
  2381. //
  2382. //
  2383. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  2384. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  2385. // item_json= [self subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  2386. // [item_json setValue:@"true" forKey:@"dirty"];
  2387. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  2388. //
  2389. // }
  2390. //
  2391. //
  2392. // // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  2393. //
  2394. // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  2395. // }
  2396. //
  2397. // if(refresh)
  2398. // {
  2399. //
  2400. // if(restore_json!=nil)
  2401. // {
  2402. // int rc=[[restore_json valueForKey:@"count"] intValue];
  2403. // for(int ir=0;ir<rc;ir++)
  2404. // {
  2405. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  2406. //
  2407. //
  2408. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  2409. // for(int i=0;i<section_count;i++)
  2410. // {
  2411. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2412. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2413. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  2414. // for(int j=0;j<item_count;j++)
  2415. // {
  2416. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2417. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2418. //
  2419. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  2420. // {
  2421. // [itemjson removeObjectForKey:@"dirty"];
  2422. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  2423. // }
  2424. //
  2425. // }
  2426. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  2427. // }
  2428. //
  2429. //
  2430. // }
  2431. //
  2432. // }
  2433. // [self refresh] ;
  2434. // return ;
  2435. // }
  2436. //
  2437. //
  2438. // DebugLog(@"CONTENT UPDATE:%@",[iSalesNetwork DataTOjsonString:self.content_data_download]);
  2439. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  2440. //
  2441. //
  2442. // // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  2443. // [self.editorTable reloadData ];
  2444. }
  2445. #pragma mark - Table view data source
  2446. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  2447. //{
  2448. // return 0;
  2449. //}
  2450. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  2451. //{
  2452. // return 0;
  2453. //}
  2454. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  2455. //{
  2456. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  2457. // return myView;
  2458. //
  2459. //}
  2460. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  2461. //{
  2462. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  2463. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  2464. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 20, 10)];
  2465. //// titleLabel.textColor=[UIColor whiteColor];
  2466. //// titleLabel.backgroundColor = [UIColor clearColor];
  2467. //// if(section==0)
  2468. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  2469. //// else
  2470. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  2471. //// [titleLabel sizeToFit];
  2472. //// [myView addSubview:titleLabel];
  2473. ////
  2474. // return myView;
  2475. //}
  2476. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  2477. //
  2478. // switch (section) {
  2479. // case 0:
  2480. // {
  2481. // NSDictionary * section_json = [self.content_data objectForKey:@"info_section"];
  2482. // return [section_json valueForKey:@"title"] ;
  2483. // }
  2484. // case 1:
  2485. // {
  2486. // NSDictionary * section_json = [self.content_data objectForKey:@"model_section"];
  2487. // return [section_json valueForKey:@"title"] ;
  2488. // }
  2489. // default:
  2490. // return nil;
  2491. // }
  2492. //
  2493. //
  2494. //}
  2495. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  2496. NSMutableDictionary* section_json = [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section ]];
  2497. return [section_json valueForKey:@"title"];
  2498. }
  2499. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  2500. {
  2501. NSLog(@"numberOfSectionsInTableView = %ld",self.content_data_control.count);
  2502. // if(self.content_data_control.count>0)
  2503. // return 1;
  2504. return self.content_data_control.count;
  2505. // int section_count =[[self.content_data valueForKey:@"section_count"] intValue];
  2506. // return section_count;
  2507. }
  2508. //- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  2509. //{
  2510. // DebugLog(@"canMoveRowAtIndexPath");
  2511. //
  2512. // if([tableView numberOfRowsInSection:indexPath.section]>1)
  2513. // return true;
  2514. // else
  2515. // return false;
  2516. //}
  2517. //- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
  2518. //{
  2519. // NSMutableArray * from;
  2520. // NSMutableArray * to ;
  2521. // if(fromIndexPath.section==0)
  2522. // from = self.displayfields;
  2523. // else
  2524. // from = self.hidefields;
  2525. // if(toIndexPath.section==0)
  2526. // to = self.displayfields;
  2527. // else
  2528. // to = self.hidefields;
  2529. // id content=from[fromIndexPath.row];
  2530. // [from removeObjectAtIndex:fromIndexPath.row];
  2531. // [to insertObject:content atIndex:toIndexPath.row];
  2532. //
  2533. // [tableView reloadData];
  2534. //
  2535. //}
  2536. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  2537. {
  2538. // if(self.content_data_control.count>0)
  2539. // return 1;
  2540. NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy];
  2541. bool hide = [[sectionjson valueForKey:@"hide"]boolValue];
  2542. if(hide)
  2543. {
  2544. return 0;
  2545. // [sectionjson setValue:@"false" forKey:@"hide"];
  2546. // [sender setTitle:@"Show" forState:UIControlStateNormal];
  2547. }
  2548. else{
  2549. return ((NSMutableArray*)self.content_data_control[section]).count;
  2550. // [sectionjson setValue:@"true" forKey:@"hide"];
  2551. // [sender setTitle:@"Hide" forState:UIControlStateNormal];
  2552. }
  2553. // return 0;
  2554. // if(section==4)
  2555. // return 1;
  2556. // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section ]];
  2557. //
  2558. // return [[section_json valueForKey:@"count" ] intValue];
  2559. }
  2560. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  2561. {
  2562. if(section==0)
  2563. return 44;
  2564. return 33;
  2565. }
  2566. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  2567. //{
  2568. // return 0.5;
  2569. //}
  2570. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  2571. {
  2572. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  2573. NSString* control = [item_json valueForKey:@"control"];
  2574. NSString *model = [UIDevice currentDevice].model;
  2575. if ([model isEqualToString:@"iPhone"]) {
  2576. if([control isEqualToString:@"model"])
  2577. return 140;
  2578. else if([control isEqualToString:@"signature"])
  2579. return 200;
  2580. else if([control isEqualToString:@"text_view"])
  2581. return 180;
  2582. else if([control isEqualToString:@"img"])
  2583. return 240;
  2584. else if ([control isEqualToString:@"action"])
  2585. return 44;
  2586. else if ([control isEqualToString:@"text"])
  2587. return 80;
  2588. else if ([control isEqualToString:@"enum"])
  2589. return 80;
  2590. else if ([control isEqualToString:@"edit"])
  2591. return 80;
  2592. else if ([control isEqualToString:@"switch"])
  2593. return 80;
  2594. else if([control isEqualToString:@"multi_action"])
  2595. {
  2596. int count = [[item_json valueForKey:@"count"]intValue];
  2597. if (count <= 2) {
  2598. return 50;
  2599. } else {
  2600. return 100;
  2601. }
  2602. }
  2603. else if ([control isEqualToString:@"webview"]) {
  2604. id h_obj = [item_json objectForKey:@"height"];
  2605. CGFloat height = [h_obj floatValue];
  2606. if(height<44)
  2607. height=44;
  2608. return height;
  2609. }
  2610. else if ([control isEqualToString:@"banner"]) {
  2611. return 200;
  2612. }
  2613. return 80;
  2614. } else {
  2615. if([control isEqualToString:@"model"])
  2616. return 140;
  2617. else if([control isEqualToString:@"signature"])
  2618. return 140;
  2619. else if([control isEqualToString:@"text_view"])
  2620. return 140;
  2621. else if([control isEqualToString:@"img"])
  2622. return 123;
  2623. return 44;
  2624. }
  2625. }
  2626. //
  2627. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2628. {
  2629. bool readonly = [[self.content_data_download valueForKey:@"readonly"]boolValue];
  2630. // int d=0;
  2631. // if(indexPath.section==4)
  2632. // d=0;
  2633. // DebugLog(@"%d,%d",indexPath.section,indexPath.row);
  2634. // NSMutableDictionary* section_json = [self.content_data objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  2635. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2636. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  2637. NSString* control = [item_json valueForKey:@"control"];
  2638. NSString* required = [item_json valueForKey:@"required"];
  2639. NSString *CellIdentifier = @"";
  2640. if([control isEqualToString:@"text_view"])
  2641. {
  2642. CellIdentifier = @"CommonEditorCellTextView";
  2643. CommonEditorCellTextView * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2644. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  2645. NSString* value =[item_json valueForKey:@"value"];
  2646. NSString* align =[item_json valueForKey:@"align"];
  2647. if([align isEqualToString:@"right"])
  2648. cell.textview.textAlignment= kCTTextAlignmentRight;
  2649. else
  2650. cell.textview.textAlignment =kCTTextAlignmentLeft;
  2651. int capital =[[item_json valueForKey:@"capital"] intValue];
  2652. switch (capital) {
  2653. case 1:
  2654. cell.textview.autocapitalizationType=UITextAutocapitalizationTypeWords;
  2655. break;
  2656. case 2:
  2657. cell.textview.autocapitalizationType=UITextAutocapitalizationTypeSentences;
  2658. break;
  2659. case 3:
  2660. cell.textview.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;
  2661. break;
  2662. default:
  2663. cell.textview.autocapitalizationType=UITextAutocapitalizationTypeWords;//UITextAutocapitalizationTypeNone;
  2664. break;
  2665. }
  2666. int disable = [[item_json valueForKey:@"disable"] intValue];
  2667. if(disable==1||readonly)
  2668. {
  2669. cell.textview.editable=NO;
  2670. // cell.textfield.backgroundColor = [UIColor lightGrayColor];
  2671. cell.textview.textColor= [UIColor lightGrayColor];
  2672. }
  2673. else
  2674. {
  2675. cell.textview.editable=YES;
  2676. cell.textview.textColor= [UIColor blackColor];
  2677. // cell.textfield.backgroundColor = [UIColor whiteColor];
  2678. }
  2679. // if([required isEqualToString:@"true"])
  2680. // {
  2681. // [title appendString:@"*"];
  2682. // }
  2683. cell.label_name.text=title;
  2684. if([required isEqualToString:@"true"])
  2685. {
  2686. [cell.label_name sizeToFit];
  2687. CGRect frame =cell.label_name.frame;
  2688. frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  2689. cell.starMark.frame = frame;
  2690. cell.starMark.hidden=false;
  2691. // [title appendString:@"*"];
  2692. // [title appendString:@"<font size=\"6\" >*</font>"];
  2693. // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  2694. }
  2695. else
  2696. {
  2697. [cell.label_name sizeToFit];
  2698. cell.starMark.hidden=true;
  2699. }
  2700. cell.textview.text = value;
  2701. cell.textview.delegate = self;
  2702. cell.accessoryType = UITableViewCellAccessoryNone;
  2703. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  2704. {
  2705. CALayer *layer = [cell.contentView layer];
  2706. // layer.borderColor = [[UIColor redColor] CGColor];
  2707. // layer.borderWidth = 1.0;
  2708. layer.shadowColor = [UIColor redColor].CGColor;
  2709. layer.shadowOffset = CGSizeMake(0, 0);
  2710. layer.shadowOpacity = 1;
  2711. layer.shadowRadius = 2.0;
  2712. }
  2713. else
  2714. {
  2715. CALayer *layer = [cell.contentView layer];
  2716. // layer.borderColor = [[UIColor redColor] CGColor];
  2717. // layer.borderWidth = 1.0;
  2718. layer.shadowColor = [UIColor clearColor].CGColor;
  2719. layer.shadowOffset = CGSizeMake(0, 0);
  2720. layer.shadowOpacity = 1;
  2721. }
  2722. cell.backgroundColor = [UIColor whiteColor];
  2723. return cell;
  2724. }else
  2725. if([control isEqualToString:@"img"])
  2726. {
  2727. CellIdentifier = @"CommonEditorCellImg";
  2728. CommonEditorCellImg * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2729. cell.touchImageView0.contentMode = UIViewContentModeScaleAspectFit;
  2730. cell.touchImageView1.contentMode = UIViewContentModeScaleAspectFit;
  2731. cell.touchImageView2.contentMode = UIViewContentModeScaleAspectFit;
  2732. NSString* title = [item_json valueForKey:@"aname"] ;
  2733. NSString* value =[item_json valueForKey:@"value"];
  2734. int disable = [[item_json valueForKey:@"disable"] intValue];
  2735. if(disable==1||readonly)
  2736. {
  2737. cell.editable=false;
  2738. }
  2739. else
  2740. cell.editable=true;
  2741. cell.labelTitle.text = title;
  2742. cell.labelDescription.text = value;
  2743. __weak typeof(self) weakself = self;
  2744. cell.imgChanged = ^(NSString* url_down,NSString* url_up,int index ,NSString* url_index)
  2745. {
  2746. // NSMutableDictionary* editjson = [item_json mutableCopy];
  2747. // editjson[@"img_url"]=url;
  2748. [weakself imgIsChanged:url_down url_up:url_up indexPath:indexPath index:index url_index:url_index];
  2749. };
  2750. {
  2751. NSString* img_url0 = [item_json valueForKey:@"img_url_0"];
  2752. if(img_url0.length>0)
  2753. {
  2754. NSString* img_url_up=[item_json valueForKey:@"img_url_aname_0"];
  2755. if(img_url_up.length==0)
  2756. img_url_up=@"";
  2757. cell.imgs[0]=img_url_up;
  2758. NSString* file_name=[img_url0 lastPathComponent];
  2759. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url0];
  2760. if(img_data!=nil)
  2761. {
  2762. UIImage * img =[UIImage imageWithData:img_data];
  2763. cell.touchImageView0.image=img;
  2764. cell.img_validate = true;
  2765. // [cell.touchImageView setImage:img forState:UIControlStateNormal];
  2766. }
  2767. else
  2768. {
  2769. // __weak typeof(self) weakself = self;
  2770. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2771. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url0]];
  2772. dispatch_async(dispatch_get_main_queue(), ^{
  2773. if(downloadimg_data!=nil)
  2774. {
  2775. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url0];
  2776. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2777. cell.touchImageView0.image=img;
  2778. cell.img_validate = true;
  2779. }
  2780. else
  2781. {
  2782. cell.touchImageView0.image=[UIImage imageNamed:@"notfound_s"];
  2783. cell.img_validate = false;
  2784. }
  2785. });
  2786. });
  2787. }
  2788. }
  2789. else
  2790. {
  2791. cell.touchImageView0.image=[UIImage imageNamed:@"camera_s"];
  2792. cell.imgs[0]=@"";
  2793. }
  2794. }
  2795. {
  2796. NSString* img_url1 = [item_json valueForKey:@"img_url_1"];
  2797. if(img_url1.length>0)
  2798. {
  2799. NSString* img_url_up=[item_json valueForKey:@"img_url_aname_1"];
  2800. if(img_url_up.length==0)
  2801. img_url_up=@"";
  2802. cell.imgs[1]=img_url_up;
  2803. NSString* file_name=[img_url1 lastPathComponent];
  2804. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url1];
  2805. if(img_data!=nil)
  2806. {
  2807. UIImage * img =[UIImage imageWithData:img_data];
  2808. cell.touchImageView1.image=img;
  2809. cell.img_validate = true;
  2810. // [cell.touchImageView setImage:img forState:UIControlStateNormal];
  2811. }
  2812. else
  2813. {
  2814. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2815. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url1]];
  2816. dispatch_async(dispatch_get_main_queue(), ^{
  2817. if(downloadimg_data!=nil)
  2818. {
  2819. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url1];
  2820. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2821. cell.touchImageView1.image=img;
  2822. cell.img_validate = true;
  2823. }
  2824. else
  2825. {
  2826. cell.touchImageView1.image=[UIImage imageNamed:@"notfound_s"] ;
  2827. cell.img_validate = false;
  2828. }
  2829. });
  2830. });
  2831. }
  2832. }
  2833. else
  2834. {
  2835. cell.touchImageView1.image=[UIImage imageNamed:@"camera_s"];
  2836. cell.imgs[1]=@"";
  2837. }
  2838. }
  2839. {
  2840. NSString* img_url2 = [item_json valueForKey:@"img_url_2"];
  2841. if(img_url2.length>0)
  2842. {
  2843. NSString* img_url_up=[item_json valueForKey:@"img_url_aname_2"];
  2844. if(img_url_up.length==0)
  2845. img_url_up=@"";
  2846. cell.imgs[2]=img_url_up;
  2847. NSString* file_name=[img_url2 lastPathComponent];
  2848. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url2];
  2849. if(img_data!=nil)
  2850. {
  2851. UIImage * img =[UIImage imageWithData:img_data];
  2852. cell.touchImageView2.image=img;
  2853. cell.img_validate = true;
  2854. // [cell.touchImageView setImage:img forState:UIControlStateNormal];
  2855. }
  2856. else
  2857. {
  2858. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2859. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url2]];
  2860. dispatch_async(dispatch_get_main_queue(), ^{
  2861. if(downloadimg_data!=nil)
  2862. {
  2863. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url2];
  2864. UIImage * img =[UIImage imageWithData:downloadimg_data];
  2865. cell.touchImageView2.image=img;
  2866. cell.img_validate = true;
  2867. }
  2868. else
  2869. {
  2870. cell.touchImageView2.image=[UIImage imageNamed:@"notfound_s"] ;
  2871. cell.img_validate = false;
  2872. }
  2873. });
  2874. });
  2875. }}
  2876. else
  2877. {
  2878. cell.touchImageView2.image=[UIImage imageNamed:@"camera_s"];
  2879. cell.imgs[2]=@"";
  2880. }
  2881. }
  2882. cell.backgroundColor = [UIColor whiteColor];
  2883. return cell;
  2884. }else
  2885. if([control isEqualToString:@"edit"])
  2886. {
  2887. CellIdentifier = @"CommonEditorCellEdit";
  2888. CommonEditorCellEdit * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2889. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  2890. // title =[[NSString stringWithFormat:@"<font size=\"5\" face=\"Helvetica\">%@</font>",title] mutableCopy];
  2891. NSString* value =[item_json valueForKey:@"value"];
  2892. NSString* align =[item_json valueForKey:@"align"];
  2893. if([align isEqualToString:@"right"])
  2894. cell.textfield.textAlignment= NSTextAlignmentRight;
  2895. else
  2896. cell.textfield.textAlignment =NSTextAlignmentLeft;
  2897. int capital =[[item_json valueForKey:@"capital"] intValue];
  2898. switch (capital) {
  2899. case 1:
  2900. cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeWords;
  2901. break;
  2902. case 2:
  2903. cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeSentences;
  2904. break;
  2905. case 3:
  2906. cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;
  2907. break;
  2908. default:
  2909. cell.textfield.autocapitalizationType=UITextAutocapitalizationTypeWords;//UITextAutocapitalizationTypeNone;
  2910. break;
  2911. }
  2912. int disable = [[item_json valueForKey:@"disable"] intValue];
  2913. if(disable==1||readonly)
  2914. {
  2915. cell.textfield.enabled=NO;
  2916. // cell.textfield.backgroundColor = [UIColor lightGrayColor];
  2917. cell.textfield.textColor= [UIColor lightGrayColor];
  2918. }
  2919. else
  2920. {
  2921. cell.textfield.enabled=YES;
  2922. cell.textfield.textColor= [UIColor blackColor];
  2923. // cell.textfield.backgroundColor = [UIColor whiteColor];
  2924. }
  2925. NSString* keyboard = [item_json valueForKey:@"keyboard"];
  2926. if([keyboard isEqualToString:@"number"])
  2927. {
  2928. // float f = [value floatValue];
  2929. // value = [NSString stringWithFormat:@"%.2f",f];
  2930. cell.textfield.keyboardType=UIKeyboardTypeDecimalPad;
  2931. // cell.textfield.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
  2932. }
  2933. else if([keyboard isEqualToString:@"int"])
  2934. {
  2935. // float f = [value floatValue];
  2936. // value = [NSString stringWithFormat:@"%.2f",f];
  2937. cell.textfield.keyboardType=UIKeyboardTypeNumberPad;
  2938. // cell.textfield.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
  2939. }
  2940. else if([keyboard isEqualToString:@"email"])
  2941. {
  2942. cell.textfield.keyboardType=UIKeyboardTypeEmailAddress;
  2943. }
  2944. else if([keyboard isEqualToString:@"phone"])
  2945. {
  2946. cell.textfield.keyboardType=UIKeyboardTypePhonePad;
  2947. }
  2948. else
  2949. {
  2950. cell.textfield.keyboardType=UIKeyboardTypeDefault;
  2951. }
  2952. // UIKIT_EXTERN NSString * const NSPlainTextDocumentType NS_AVAILABLE(10_0, 7_0);
  2953. // UIKIT_EXTERN NSString * const NSRTFTextDocumentType NS_AVAILABLE(10_0, 7_0);
  2954. // UIKIT_EXTERN NSString * const NSRTFDTextDocumentType NS_AVAILABLE(10_0, 7_0);
  2955. // UIKIT_EXTERN NSString * const NSHTMLTextDocumentType NS_AVAILABLE(10_0, 7_0);
  2956. //
  2957. // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[title dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
  2958. // UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];
  2959. // myLabel.attributedText = attrStr;
  2960. // cell.labelTitle.attributedText = attrStr;
  2961. cell.labelTitle.text=title;
  2962. if([required isEqualToString:@"true"])
  2963. {
  2964. [cell.labelTitle sizeToFit];
  2965. CGRect frame =cell.labelTitle.frame;
  2966. frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  2967. cell.starMark.frame = frame;
  2968. cell.starMark.hidden=false;
  2969. // [title appendString:@"*"];
  2970. // [title appendString:@"<font size=\"6\" >*</font>"];
  2971. // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  2972. }
  2973. else
  2974. {
  2975. [cell.labelTitle sizeToFit];
  2976. cell.starMark.hidden=true;
  2977. }
  2978. cell.textfield.text = value;
  2979. cell.textfield.delegate = self;
  2980. cell.accessoryType = UITableViewCellAccessoryNone;
  2981. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  2982. {
  2983. CALayer *layer = cell.labelTitle.layer;
  2984. // layer.borderColor = [[UIColor redColor] CGColor];
  2985. // layer.borderWidth = 1.0;
  2986. layer.shadowColor = [UIColor redColor].CGColor;
  2987. layer.shadowOffset = CGSizeMake(0, 0);
  2988. layer.shadowOpacity = 1;
  2989. layer.shadowRadius = 2.0;
  2990. layer = cell.starMark.layer;
  2991. // layer.borderColor = [[UIColor redColor] CGColor];
  2992. // layer.borderWidth = 1.0;
  2993. layer.shadowColor = [UIColor redColor].CGColor;
  2994. layer.shadowOffset = CGSizeMake(0, 0);
  2995. layer.shadowOpacity = 1;
  2996. layer.shadowRadius = 2.0;
  2997. //UIImageView * iv =
  2998. cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_attention_24"]];
  2999. cell.textfield.rightViewMode=UITextFieldViewModeUnlessEditing;
  3000. cell.textfield.layer.cornerRadius=8.0f;
  3001. cell.textfield.layer.borderWidth= 1.0f;
  3002. cell.textfield.layer.masksToBounds=YES;
  3003. cell.textfield.layer.borderColor=[[UIColor redColor]CGColor];
  3004. }
  3005. else
  3006. {
  3007. CALayer *layer = cell.labelTitle.layer;//[cell.contentView layer];
  3008. // layer.borderColor = [[UIColor redColor] CGColor];
  3009. // layer.borderWidth = 1.0;
  3010. layer.shadowColor = [UIColor clearColor].CGColor;
  3011. layer.shadowOffset = CGSizeMake(0, 0);
  3012. layer.shadowOpacity = 1;
  3013. layer = cell.starMark.layer;//[cell.contentView layer];
  3014. // layer.borderColor = [[UIColor redColor] CGColor];
  3015. // layer.borderWidth = 1.0;
  3016. layer.shadowColor = [UIColor clearColor].CGColor;
  3017. layer.shadowOffset = CGSizeMake(0, 0);
  3018. layer.shadowOpacity = 1;
  3019. cell.textfield.rightViewMode=UITextFieldViewModeNever;
  3020. //cell.textfield.layer.borderColor= [[UIColor lightGrayColor] CGColor];
  3021. cell.textfield.rightView = nil;
  3022. cell.textfield.layer.cornerRadius=8.0f;
  3023. cell.textfield.layer.borderWidth= 1.0f;
  3024. cell.textfield.layer.masksToBounds=YES;
  3025. cell.textfield.layer.borderColor=[[UIColor lightGrayColor]CGColor];
  3026. }
  3027. cell.backgroundColor = [UIColor whiteColor];
  3028. return cell;
  3029. }
  3030. else
  3031. if([control isEqualToString:@"text"])
  3032. {
  3033. CellIdentifier = @"CommonEditorCellLabel";
  3034. CommonEditorCellLabel * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3035. //CGRect titleframe = cell.labelTitle.frame;
  3036. NSString* title = [item_json valueForKey:@"aname"] ;
  3037. NSString* value =[item_json valueForKey:@"value"];
  3038. NSString* color =[item_json valueForKey:@"color"];
  3039. cell.labelValue.textColor = [RAUtils strColor:color];
  3040. NSString* align =[item_json valueForKey:@"align"];
  3041. if([align isEqualToString:@"right"])
  3042. {
  3043. cell.labelTitle.frame =CGRectMake(15,11,350,21);
  3044. cell.labelValue.textAlignment= NSTextAlignmentRight;
  3045. }
  3046. else
  3047. {
  3048. cell.labelTitle.frame =CGRectMake(15,11,150,21);
  3049. cell.labelValue.textAlignment =NSTextAlignmentLeft;
  3050. }
  3051. NSString* type=[item_json valueForKey:@"type"] ;
  3052. // 此处应移动到erp mobile 项目内
  3053. if([type isEqualToString:@"price"])
  3054. {
  3055. BOOL can_see_price = [[RASingleton.sharedInstance globalParameterForKey:@"can_see_price"] boolValue];
  3056. BOOL price_hidden = [[RASingleton.sharedInstance globalParameterForKey:@"price_hidden"] boolValue];
  3057. if(can_see_price&&price_hidden==false)
  3058. {
  3059. }
  3060. else
  3061. {
  3062. value=nil;
  3063. }
  3064. }
  3065. cell.labelTitle.text=title;
  3066. cell.labelValue.text = value;
  3067. cell.backgroundColor = [UIColor whiteColor];
  3068. return cell;
  3069. }
  3070. else
  3071. if([control isEqualToString:@"action"])
  3072. {
  3073. CellIdentifier = @"CommonEditorCellAction";
  3074. CommonEditorCellAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3075. int disable = [[item_json valueForKey:@"disable"] intValue];
  3076. if(disable==1||readonly)
  3077. {
  3078. cell.labelAction.textColor= [UIColor lightGrayColor];
  3079. }
  3080. else
  3081. {
  3082. cell.labelAction.textColor= [UIColor blackColor];
  3083. }
  3084. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  3085. NSString* value =[item_json valueForKey:@"value"];
  3086. if([required isEqualToString:@"true"])
  3087. {
  3088. [title appendString:@"*"];
  3089. }
  3090. NSDictionary* data = [item_json objectForKey:@"data"];
  3091. cell.labelAction.text=title;
  3092. cell.action_code = value;
  3093. //cell.labelValue.text = value;
  3094. if(self.cancommit==false && [required isEqualToString:@"true"] && (data==nil))
  3095. {
  3096. CALayer *layer = [cell.contentView layer];
  3097. // layer.borderColor = [[UIColor redColor] CGColor];
  3098. // layer.borderWidth = 1.0;
  3099. layer.shadowColor = [UIColor redColor].CGColor;
  3100. layer.shadowOffset = CGSizeMake(0, 0);
  3101. layer.shadowOpacity = 1;
  3102. layer.shadowRadius = 2.0;
  3103. }
  3104. else
  3105. {
  3106. CALayer *layer = [cell.contentView layer];
  3107. // layer.borderColor = [[UIColor redColor] CGColor];
  3108. // layer.borderWidth = 1.0;
  3109. layer.shadowColor = [UIColor clearColor].CGColor;
  3110. layer.shadowOffset = CGSizeMake(0, 0);
  3111. layer.shadowOpacity = 1;
  3112. }
  3113. cell.backgroundColor = [UIColor whiteColor];
  3114. return cell;
  3115. }
  3116. if([control isEqualToString:@"multi_action"])
  3117. {
  3118. CellIdentifier = @"CommonEditorCellMAction";
  3119. CommonEditorCellMAction * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3120. int disabble = [[item_json objectForKey:@"disable"] intValue];
  3121. int count = [[item_json valueForKey:@"count"]intValue];
  3122. for(int i=0;i<count;i++)
  3123. {
  3124. NSDictionary* sub_action= [item_json objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  3125. NSString * title = [sub_action valueForKey:@"aname"];
  3126. switch (i) {
  3127. case 0:
  3128. [cell.btn_action0 setTitle:title forState:UIControlStateNormal];
  3129. [cell.btn_action0 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
  3130. cell.btn_action0.hidden = NO;
  3131. if (disabble==1 || readonly)
  3132. cell.btn_action0.enabled =false;
  3133. break;
  3134. case 1:
  3135. [cell.btn_action1 setTitle:title forState:UIControlStateNormal];
  3136. [cell.btn_action1 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
  3137. cell.btn_action1.hidden = NO;
  3138. if (disabble==1 || readonly)
  3139. cell.btn_action1.enabled =false;
  3140. break;
  3141. case 2:
  3142. [cell.btn_action2 setTitle:title forState:UIControlStateNormal];
  3143. [cell.btn_action2 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
  3144. cell.btn_action2.hidden = NO;
  3145. if (disabble==1 || readonly)
  3146. cell.btn_action2.enabled =false;
  3147. break;
  3148. case 3:
  3149. [cell.btn_action3 setTitle:title forState:UIControlStateNormal];
  3150. [cell.btn_action3 addTarget:self action:@selector(MActionClicked:) forControlEvents:UIControlEventTouchUpInside];
  3151. cell.btn_action3.hidden = NO;
  3152. if (disabble==1 || readonly)
  3153. cell.btn_action3.enabled =false;
  3154. break;
  3155. default:
  3156. break;
  3157. }
  3158. }
  3159. if (count<4)
  3160. cell.btn_action3.hidden=YES;
  3161. if (count<3)
  3162. cell.btn_action2.hidden=YES;
  3163. if (count<2)
  3164. cell.btn_action1.hidden=YES;
  3165. if (count<1)
  3166. cell.btn_action0.hidden=YES;
  3167. // NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  3168. // NSString* value =[item_json valueForKey:@"value"];
  3169. // if([required isEqualToString:@"true"])
  3170. // {
  3171. // [title appendString:@"*"];
  3172. // }
  3173. // NSDictionary* data = [item_json objectForKey:@"data"];
  3174. //
  3175. // cell.labelAction.text=title;
  3176. // cell.action_code = value;
  3177. //
  3178. //
  3179. // //cell.labelValue.text = value;
  3180. //
  3181. // if(self.cancommit==false && [required isEqualToString:@"true"] && (data==nil))
  3182. // {
  3183. // CALayer *layer = [cell.contentView layer];
  3184. // // layer.borderColor = [[UIColor redColor] CGColor];
  3185. // // layer.borderWidth = 1.0;
  3186. //
  3187. // layer.shadowColor = [UIColor redColor].CGColor;
  3188. // layer.shadowOffset = CGSizeMake(0, 0);
  3189. // layer.shadowOpacity = 1;
  3190. // layer.shadowRadius = 2.0;
  3191. // }
  3192. cell.backgroundColor = [UIColor whiteColor];
  3193. return cell;
  3194. }
  3195. else
  3196. if([control isEqualToString:@"switch"])
  3197. {
  3198. CellIdentifier = @"CommonEditorCellSwitch";
  3199. CommonEditorCellSwitch * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3200. NSString* title = [item_json valueForKey:@"aname"];
  3201. NSString* value =[item_json valueForKey:@"value"];
  3202. NSString* desc = [item_json valueForKey:@"desc"];
  3203. cell.labelTitle.text=title;
  3204. cell.labelDesc.text=desc;
  3205. int disabble = [[item_json objectForKey:@"disable"] intValue];
  3206. if (disabble==1 || readonly) {
  3207. cell.switchCtrl.enabled = NO;
  3208. } else {
  3209. cell.switchCtrl.enabled = YES;
  3210. }
  3211. if([required isEqualToString:@"true"])
  3212. {
  3213. [cell.labelTitle sizeToFit];
  3214. CGRect frame =cell.labelTitle.frame;
  3215. frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  3216. cell.starMark.frame = frame;
  3217. cell.starMark.hidden=false;
  3218. // CGSize asize=[cell.labelTitle sizeThatFits:cell.labelTitle.frame.size];
  3219. //
  3220. // cell.starMark.frame = CGRectMake(cell.labelTitle.frame.origin.x+asize.width, cell.labelTitle.frame.origin.y, 10, 21);
  3221. // cell.starMark.hidden=false;
  3222. // [title appendString:@"*"];
  3223. // [title appendString:@"<font size=\"6\" >*</font>"];
  3224. // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  3225. }
  3226. else
  3227. {
  3228. [cell.labelTitle sizeToFit];
  3229. cell.starMark.hidden=true;
  3230. }
  3231. [cell.switchCtrl addTarget:self
  3232. action:@selector(switchIsChanged:)
  3233. forControlEvents:UIControlEventValueChanged];
  3234. if([[value lowercaseString] isEqualToString:@"true"])
  3235. cell.switchCtrl.on = true;
  3236. else
  3237. cell.switchCtrl.on = false;
  3238. cell.accessoryType = UITableViewCellAccessoryNone;
  3239. cell.backgroundColor = [UIColor whiteColor];
  3240. return cell;
  3241. }
  3242. else if([control isEqualToString:@"editor"])
  3243. {
  3244. CellIdentifier = @"CommonEditorCellEditor";
  3245. CommonEditorCellEditor * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3246. NSString* title = [[item_json valueForKey:@"aname"] stringValue];
  3247. NSString* value = [[item_json valueForKey:@"value"] stringValue];
  3248. int disable = [[item_json valueForKey:@"disable"] intValue];
  3249. if(disable==1||readonly)
  3250. {
  3251. cell.labelValue.textColor= [UIColor lightGrayColor];
  3252. }
  3253. else
  3254. {
  3255. cell.labelValue.textColor= [UIColor blackColor];
  3256. // cell.textfield.backgroundColor = [UIColor whiteColor];
  3257. }
  3258. NSString* align =[item_json valueForKey:@"align"];
  3259. if([align isEqualToString:@"right"])
  3260. cell.labelValue.textAlignment= NSTextAlignmentRight;
  3261. else
  3262. cell.labelValue.textAlignment =NSTextAlignmentLeft;
  3263. cell.labelName.text=title;
  3264. cell.labelValue.text=value;
  3265. // if([required isEqualToString:@"true"])
  3266. // {
  3267. // [cell.labelTitle sizeToFit];
  3268. // CGRect frame =cell.labelTitle.frame;
  3269. // frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  3270. // cell.starMark.frame = frame;
  3271. // cell.starMark.hidden=false;
  3272. // // [title appendString:@"*"];
  3273. //
  3274. // // [title appendString:@"<font size=\"6\" >*</font>"];
  3275. // // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  3276. // }
  3277. // else
  3278. // {
  3279. // [cell.labelTitle sizeToFit];
  3280. // cell.starMark.hidden=true;
  3281. // }
  3282. cell.backgroundColor = [UIColor whiteColor];
  3283. return cell;
  3284. }
  3285. else if([control isEqualToString:@"enum"])
  3286. {
  3287. CellIdentifier = @"CommonEditorCellEnum";
  3288. CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3289. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  3290. NSDictionary* cadedate_json =[item_json objectForKey:@"cadedate"];
  3291. int disable = [[item_json valueForKey:@"disable"] intValue];
  3292. if(disable==1||readonly)
  3293. {
  3294. cell.labelValue.textColor= [UIColor lightGrayColor];
  3295. }
  3296. else
  3297. {
  3298. cell.labelValue.textColor= [UIColor blackColor];
  3299. // cell.textfield.backgroundColor = [UIColor whiteColor];
  3300. }
  3301. NSString* align =[item_json valueForKey:@"align"];
  3302. if([align isEqualToString:@"right"])
  3303. cell.labelValue.textAlignment= NSTextAlignmentRight;
  3304. else
  3305. cell.labelValue.textAlignment =NSTextAlignmentLeft;
  3306. // if([required isEqualToString:@"true"])
  3307. // {
  3308. // [title appendString:@"*"];
  3309. // }
  3310. NSString* value =@"";
  3311. int count = [[cadedate_json valueForKey:@"count"] intValue];
  3312. for(int i=0;i<count;i++)
  3313. {
  3314. NSDictionary* val_json =[cadedate_json objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  3315. int check = [[val_json valueForKey:@"check"] intValue];
  3316. if(check==1)
  3317. {
  3318. value = [value stringByAppendingString:[val_json valueForKey:@"value"]];
  3319. value = [value stringByAppendingString:@"|"];
  3320. }
  3321. }
  3322. if(value.length>=1)
  3323. value=[value substringToIndex:value.length-1];
  3324. cell.labelTitle.text=title;
  3325. if([required isEqualToString:@"true"])
  3326. {
  3327. [cell.labelTitle sizeToFit];
  3328. CGRect frame =cell.labelTitle.frame;
  3329. frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  3330. cell.starMark.frame = frame;
  3331. cell.starMark.hidden=false;
  3332. // [title appendString:@"*"];
  3333. // [title appendString:@"<font size=\"6\" >*</font>"];
  3334. // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  3335. }
  3336. else
  3337. {
  3338. [cell.labelTitle sizeToFit];
  3339. cell.starMark.hidden=true;
  3340. }
  3341. cell.labelValue.text = value;
  3342. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  3343. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  3344. {
  3345. CALayer *layer = [cell.contentView layer];
  3346. // layer.borderColor = [[UIColor redColor] CGColor];
  3347. // layer.borderWidth = 1.0;
  3348. layer.shadowColor = [UIColor redColor].CGColor;
  3349. layer.shadowOffset = CGSizeMake(0, 0);
  3350. layer.shadowOpacity = 1;
  3351. layer.shadowRadius = 2.0;
  3352. }
  3353. else
  3354. {
  3355. CALayer *layer = [cell.contentView layer];
  3356. // layer.borderColor = [[UIColor redColor] CGColor];
  3357. // layer.borderWidth = 1.0;
  3358. layer.shadowColor = [UIColor clearColor].CGColor;
  3359. layer.shadowOffset = CGSizeMake(0, 0);
  3360. layer.shadowOpacity = 1;
  3361. }
  3362. cell.backgroundColor = [UIColor whiteColor];
  3363. return cell;
  3364. } else if([control isEqualToString:@"model"])
  3365. {
  3366. CommonEditorCellModel * cell= [tableView dequeueReusableCellWithIdentifier:@"CommonEditorCellModel" forIndexPath:indexPath];
  3367. int count = [[item_json valueForKey:@"count"] intValue];
  3368. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  3369. cell.bundle_item=combine_json;
  3370. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  3371. if (cell.masterBtn != nil) {
  3372. if (master_json == nil) {
  3373. cell.masterBtn.hidden = YES;
  3374. } else{
  3375. cell.masterBtn.hidden = NO;
  3376. cell.master_items = master_json;
  3377. }
  3378. }
  3379. double dprice=0.0;
  3380. if(cell.bundle_item!=nil)
  3381. {
  3382. int citem=0;
  3383. int bcount=[[cell.bundle_item valueForKey:@"count"] intValue];
  3384. for(int bc=0;bc<bcount;bc++)
  3385. {
  3386. NSDictionary * bitem = [cell.bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  3387. int modulus= [[bitem valueForKey:@"modulus"] intValue];
  3388. citem+= modulus;
  3389. double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  3390. dprice+= uprice*modulus;
  3391. }
  3392. if(citem==1)
  3393. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle item with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  3394. else
  3395. [ cell.buttonBundle setTitle:[NSString stringWithFormat: @"%d bundle items with price of $ %.2f",citem,dprice ]forState:UIControlStateNormal];
  3396. cell.buttonBundle.hidden = NO;
  3397. }
  3398. else
  3399. {
  3400. cell.buttonBundle.hidden = YES;
  3401. }
  3402. NSString *availability = [item_json objectForKey:@"quantity_available"];
  3403. NSString *available_str = @"Available Now";
  3404. if ([availability integerValue] > 0) {
  3405. available_str = [NSString stringWithFormat:@"Available: %@",availability];
  3406. } else {
  3407. // available_str = @"Available: In Production";
  3408. available_str = @"Available: Out of Stock";
  3409. }
  3410. cell.avalibilityLabel.text = available_str;
  3411. NSString* img_url = [item_json valueForKey:@"img_url"];
  3412. NSString* description = [item_json valueForKey:@"description"];
  3413. // NSString* identifier = [item_json valueForKey:@"identifier"];
  3414. // NSString* attribute = [item_json valueForKey:@"attribute"];
  3415. // NSString* total_price = [item_json valueForKey:@"total_price"] ;
  3416. // NSString* unit_price = [item_json valueForKey:@"unit_price"] ;
  3417. // NSString* mp = [item_json valueForKey:@"stockUom"];
  3418. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  3419. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  3420. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  3421. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  3422. NSString* oldprice =[RAConvertor currencyNumber:unitprice];//[NSString stringWithFormat:@"%.2f",unitprice];
  3423. #ifdef SCANNER_ORDER
  3424. if([item_json[@"is_showroom_order"] boolValue])
  3425. {
  3426. cell.labelBackOrder.hidden=false;
  3427. cell.labelBackOrder.text = @"Showroom Order";
  3428. cell.contentView.backgroundColor = UIColor.orangeColor;
  3429. }
  3430. else
  3431. {
  3432. if([item_json[@"is_back_order"] boolValue])
  3433. {
  3434. cell.labelBackOrder.hidden=false;
  3435. cell.labelBackOrder.text = @"Backorder";
  3436. cell.contentView.backgroundColor = UIColor.yellowColor;
  3437. }
  3438. else
  3439. {
  3440. cell.labelBackOrder.hidden=true;
  3441. cell.contentView.backgroundColor = UIColor.whiteColor;
  3442. }
  3443. }
  3444. #endif
  3445. NSString* newunitprice=@"";
  3446. if(dprice>0)
  3447. newunitprice = [NSString stringWithFormat:@"%.2f+%.2f",unitprice* (1.0-discount/100),dprice];
  3448. else
  3449. newunitprice =[RAConvertor currencyNumber:unitprice* (1.0-discount/100)];// [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)];
  3450. NSString* totalprice = [RAConvertor currencyNumber:(unitprice* (1.0-discount/100)+dprice)*count]; //[NSString stringWithFormat:@"%.2f",(unitprice* (1.0-discount/100)+dprice)*count];
  3451. BOOL can_see_price = [[RASingleton.sharedInstance globalParameterForKey:@"can_see_price"] boolValue];
  3452. BOOL price_hidden = [[RASingleton.sharedInstance globalParameterForKey:@"price_hidden"] boolValue];
  3453. if(can_see_price&&price_hidden==false)
  3454. {
  3455. }
  3456. else
  3457. {
  3458. oldprice=nil;
  3459. newunitprice=nil;
  3460. totalprice=nil;
  3461. }
  3462. cell.labelDiscount.text = discountstr;
  3463. cell.labelOldPrice.text = oldprice;
  3464. cell.labelMasterPack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
  3465. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  3466. if(isfree)
  3467. {
  3468. cell.labelOldPrice.hidden = false;
  3469. cell.labelOldPrice.textColor = [UIColor redColor];
  3470. cell.labelOldPrice.text=@"Free";
  3471. cell.labelOldPrice.hideline = true;
  3472. cell.labelDiscount.hidden = true;
  3473. }
  3474. else
  3475. {
  3476. cell.labelOldPrice.textColor = [UIColor blackColor];
  3477. cell.labelOldPrice.hideline = false;
  3478. if(discount==0)
  3479. {
  3480. cell.labelOldPrice.hidden = true;
  3481. cell.labelDiscount.hidden = true;
  3482. }
  3483. else
  3484. {
  3485. cell.labelOldPrice.hidden = false;
  3486. cell.labelDiscount.hidden = false;
  3487. }
  3488. }
  3489. // if(discount==0)
  3490. // {
  3491. // cell.labelOldPrice.hidden = true;
  3492. // cell.labelDiscount.hidden = true;
  3493. //
  3494. // }
  3495. // else
  3496. // {
  3497. // cell.labelOldPrice.hidden = false;
  3498. // cell.labelDiscount.hidden = false;
  3499. // }
  3500. // NSString* currency = [item_json valueForKey:@"currency"];
  3501. // int count =[[item_json valueForKey:@"count"] intValue];
  3502. cell.labelDescription.text = description;
  3503. cell.labelCount.text = [NSString stringWithFormat:@"x %d",count];
  3504. // cell.labelID.text = identifier;
  3505. // cell.labelSubtype.text = attribute;
  3506. cell.labelTotalPrice.text= totalprice;
  3507. // cell.labelUnitPrice.text=unit_price;
  3508. cell.labelUnitPrice.text = newunitprice;
  3509. cell.imgModel.image = [UIImage imageNamed:@"loading_s"];
  3510. cell.imgModel.contentMode = UIViewContentModeScaleAspectFit;
  3511. NSString* file_name=[img_url lastPathComponent];
  3512. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
  3513. if(img_data!=nil)
  3514. {
  3515. UIImage * img =[UIImage imageWithData:img_data];
  3516. cell.imgModel.image = img;
  3517. }
  3518. else
  3519. {
  3520. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3521. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  3522. dispatch_async(dispatch_get_main_queue(), ^{
  3523. if(downloadimg_data!=nil)
  3524. {
  3525. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  3526. UIImage * img =[UIImage imageWithData:downloadimg_data];
  3527. cell.imgModel.image = img;
  3528. }
  3529. else
  3530. cell.imgModel.image = [UIImage imageNamed:@"notfound_s"];
  3531. });
  3532. });
  3533. }
  3534. cell.backgroundColor = [UIColor whiteColor];
  3535. return cell;
  3536. }else if([control isEqualToString:@"datepicker"])
  3537. {
  3538. CellIdentifier = @"CommonEditorCellEnum";
  3539. CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3540. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  3541. NSString* value =[item_json valueForKey:@"value"];
  3542. // if([required isEqualToString:@"true"])
  3543. // {
  3544. // [title appendString:@"*"];
  3545. // }
  3546. cell.labelTitle.text=title;
  3547. if([required isEqualToString:@"true"])
  3548. {
  3549. [cell.labelTitle sizeToFit];
  3550. CGRect frame =cell.labelTitle.frame;
  3551. frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  3552. cell.starMark.frame = frame;
  3553. cell.starMark.hidden=false;
  3554. // [title appendString:@"*"];
  3555. // [title appendString:@"<font size=\"6\" >*</font>"];
  3556. // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  3557. }
  3558. else
  3559. {
  3560. [cell.labelTitle sizeToFit];
  3561. cell.starMark.hidden=true;
  3562. }
  3563. cell.labelValue.text = value;
  3564. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  3565. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  3566. {
  3567. CALayer *layer = [cell.contentView layer];
  3568. // layer.borderColor = [[UIColor redColor] CGColor];
  3569. // layer.borderWidth = 1.0;
  3570. layer.shadowColor = [UIColor redColor].CGColor;
  3571. layer.shadowOffset = CGSizeMake(0, 0);
  3572. layer.shadowOpacity = 1;
  3573. layer.shadowRadius = 2.0;
  3574. }
  3575. else
  3576. {
  3577. CALayer *layer = [cell.contentView layer];
  3578. // layer.borderColor = [[UIColor redColor] CGColor];
  3579. // layer.borderWidth = 1.0;
  3580. layer.shadowColor = [UIColor clearColor].CGColor;
  3581. layer.shadowOffset = CGSizeMake(0, 0);
  3582. layer.shadowOpacity = 1;
  3583. }
  3584. cell.backgroundColor = [UIColor whiteColor];
  3585. return cell;
  3586. }
  3587. else if([control isEqualToString:@"monthpicker"])
  3588. {
  3589. CellIdentifier = @"CommonEditorCellEnum";
  3590. CommonEditorCellEnum * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3591. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  3592. NSString* value =[item_json valueForKey:@"value"];
  3593. // if([required isEqualToString:@"true"])
  3594. // {
  3595. // [title appendString:@"*"];
  3596. // }
  3597. cell.labelTitle.text=title;
  3598. if([required isEqualToString:@"true"])
  3599. {
  3600. [cell.labelTitle sizeToFit];
  3601. CGRect frame =cell.labelTitle.frame;
  3602. frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  3603. cell.starMark.frame = frame;
  3604. cell.starMark.hidden=false;
  3605. // [title appendString:@"*"];
  3606. // [title appendString:@"<font size=\"6\" >*</font>"];
  3607. // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  3608. }
  3609. else
  3610. {
  3611. [cell.labelTitle sizeToFit];
  3612. cell.starMark.hidden=true;
  3613. }
  3614. cell.labelValue.text = value;
  3615. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  3616. if(self.cancommit==false && [required isEqualToString:@"true"] && (value==nil || value.length==0))
  3617. {
  3618. CALayer *layer = [cell.contentView layer];
  3619. // layer.borderColor = [[UIColor redColor] CGColor];
  3620. // layer.borderWidth = 1.0;
  3621. layer.shadowColor = [UIColor redColor].CGColor;
  3622. layer.shadowOffset = CGSizeMake(0, 0);
  3623. layer.shadowOpacity = 1;
  3624. layer.shadowRadius = 2.0;
  3625. }
  3626. else
  3627. {
  3628. CALayer *layer = [cell.contentView layer];
  3629. // layer.borderColor = [[UIColor redColor] CGColor];
  3630. // layer.borderWidth = 1.0;
  3631. layer.shadowColor = [UIColor clearColor].CGColor;
  3632. layer.shadowOffset = CGSizeMake(0, 0);
  3633. layer.shadowOpacity = 1;
  3634. }
  3635. cell.backgroundColor = [UIColor whiteColor];
  3636. return cell;
  3637. }
  3638. else if([control isEqualToString:@"signature"])
  3639. {
  3640. CellIdentifier = @"CommonEditorCellSignature";
  3641. CommonEditorCellSignature * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3642. cell.imageviewSignature.contentMode = UIViewContentModeScaleAspectFit;
  3643. NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  3644. // if([required isEqualToString:@"true"])
  3645. // {
  3646. // [title appendString:@"*"];
  3647. // }
  3648. int disabble = [[item_json objectForKey:@"disable"] intValue];
  3649. if (disabble==1 || readonly) {
  3650. cell.imageviewSignature.userInteractionEnabled = NO;
  3651. } else {
  3652. cell.imageviewSignature.userInteractionEnabled = YES;
  3653. }
  3654. cell.labelTitle.text = title;
  3655. if([required isEqualToString:@"true"])
  3656. {
  3657. [cell.labelTitle sizeToFit];
  3658. CGRect frame =cell.labelTitle.frame;
  3659. frame= CGRectMake(frame.origin.x+frame.size.width, frame.origin.y, 10, 21);
  3660. cell.starMark.frame = frame;
  3661. cell.starMark.hidden=false;
  3662. // [title appendString:@"*"];
  3663. // [title appendString:@"<font size=\"6\" >*</font>"];
  3664. // NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
  3665. }
  3666. else
  3667. {
  3668. [cell.labelTitle sizeToFit];
  3669. cell.starMark.hidden=true;
  3670. }
  3671. NSString* img_url = [item_json valueForKey:@"avalue"];
  3672. NSString* file_name=[img_url lastPathComponent];
  3673. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
  3674. if(img_data!=nil)
  3675. {
  3676. UIImage * img =[UIImage imageWithData:img_data];
  3677. cell.imageviewSignature.image=img ;
  3678. }
  3679. else
  3680. {
  3681. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3682. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  3683. dispatch_async(dispatch_get_main_queue(), ^{
  3684. if(downloadimg_data!=nil)
  3685. {
  3686. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  3687. UIImage * img =[UIImage imageWithData:downloadimg_data];
  3688. cell.imageviewSignature.image=img ;
  3689. }
  3690. else
  3691. cell.imageviewSignature.image=[UIImage imageNamed:@"taptosign_s"];
  3692. });
  3693. });
  3694. } cell.backgroundColor = [UIColor whiteColor];
  3695. return cell;
  3696. // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
  3697. //cell.imageviewSignature.image = image;
  3698. }
  3699. else if ([control isEqualToString:@"range"]) {
  3700. NSString *type = [item_json objectForKey:@"type"];
  3701. NSString *keyboard = [item_json objectForKey:@"keyboard"];
  3702. NSString *title = [item_json objectForKey:@"aname"];
  3703. NSString *min = [item_json objectForKey:@"min_value"];
  3704. NSString *max = [item_json objectForKey:@"max_value"];
  3705. CommonEditorRangeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorRangeCell" forIndexPath:indexPath];
  3706. cell.indexPath = indexPath;
  3707. cell.delegate = self;
  3708. [cell setTitle:title];
  3709. [cell setMinValue:min maxValue:max];
  3710. if ([type isEqualToString:@"date"]) {
  3711. [cell setType:CommonEditorRangeTypeDate];
  3712. } else {
  3713. [cell setType:CommonEditorRangeTypeDefault];
  3714. }
  3715. if([keyboard isEqualToString:@"number"]) {
  3716. [cell setKeyboardType:UIKeyboardTypeDecimalPad];
  3717. } else {
  3718. [cell setKeyboardType:UIKeyboardTypeDefault];
  3719. }
  3720. return cell;
  3721. }
  3722. else if ([control isEqualToString:@"webview"]) {
  3723. // CommonEditorWebCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorWebCell" forIndexPath:indexPath];
  3724. CommonEditorWebCell * cell = [[NSBundle mainBundle] loadNibNamed:@"Phone_Web_Cell" owner:nil options:nil].firstObject;
  3725. cell.webDelegate = self;
  3726. NSString *html_str = [item_json objectForKey:@"value"];
  3727. // NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[html_str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
  3728. //
  3729. // cell.htmlLabel.attributedText = attrStr;
  3730. // [cell.webview stopLoading];
  3731. [cell.webview loadHTMLString:html_str baseURL:nil];
  3732. // [cell.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.baidu.com/"]]];
  3733. return cell;
  3734. }
  3735. else if ([control isEqualToString:@"banner"]) {
  3736. CommonEditorBannerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonEditorBannerCell" forIndexPath:indexPath];
  3737. // NSDictionary *item_json = @{
  3738. // @"control" : @"banner",
  3739. // @"item_4": @{
  3740. // @"type" : @"image",
  3741. // @"s": @"http://127.0.0.1/s2.jpg",
  3742. // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7528.jpg"
  3743. // },
  3744. // @"count": @(5),
  3745. // @"item_2": @{
  3746. // @"type" : @"image",
  3747. // @"s": @"http://127.0.0.1/s3.jpg",
  3748. // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7526.jpg"
  3749. // },
  3750. // @"item_3": @{
  3751. // @"type" : @"image",
  3752. // @"s": @"http://127.0.0.1/s4.jpg",
  3753. // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7527.jpg"
  3754. // },
  3755. // @"item_0": @{
  3756. // @"type" : @"image",
  3757. // @"s": @"http://127.0.0.1/s1.jpg",
  3758. // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7524.jpg"
  3759. // },
  3760. // @"item_1": @{
  3761. // @"type" : @"image",
  3762. // @"s": @"http://127.0.0.1/s5.jpg",
  3763. // @"l": @"http://192.168.0.133:8080/site/u/NPD/20160615/108237-318N_7525.jpg"
  3764. // }
  3765. // };
  3766. [cell setContent:item_json];
  3767. cell.delegate = self;
  3768. return cell;
  3769. }
  3770. else
  3771. {
  3772. CellIdentifier = @"CommonEditorCellEdit";
  3773. UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3774. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  3775. cell.backgroundColor = [UIColor whiteColor];
  3776. return cell;
  3777. }
  3778. }
  3779. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  3780. {
  3781. // return [super tableview:tableView viewForHeaderInSection:section];
  3782. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  3783. if(value==nil)
  3784. value=@"";
  3785. unsigned long color = strtoul([value UTF8String],0,16);
  3786. NSString* btntitle=nil ;
  3787. NSString*labeltitle = nil;
  3788. NSMutableDictionary* sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)section]] mutableCopy];
  3789. labeltitle= [sectionjson valueForKey:@"title"];
  3790. bool hide = [[sectionjson valueForKey:@"hide"]boolValue];
  3791. if(hide)
  3792. {
  3793. btntitle=@"Show";
  3794. // [section setValue:@"false" forKey:@"hide"];
  3795. // [sender setTitle:@"Show" forState:UIControlStateNormal];
  3796. }
  3797. else{
  3798. btntitle=@"Hide";
  3799. }
  3800. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  3801. // myView.backgroundColor = [UIColor whiteColor];//UIColorFromRGB(0x996633);;
  3802. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  3803. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  3804. myView.layer.shadowOffset = CGSizeMake(0, 0);
  3805. myView.layer.shadowOpacity = 0.5;
  3806. myView.layer.shadowRadius = 2.0;
  3807. int linespace=0;
  3808. if(section==0)
  3809. linespace=11;
  3810. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0+linespace, 50, 33)];
  3811. btn.tag=section;
  3812. // [btn setTitleColor:UIColorFromRGB(0x996633) forState:UIControlStateNormal];
  3813. [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
  3814. [btn setTitle:btntitle forState:UIControlStateNormal];
  3815. [myView addSubview:btn];
  3816. btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  3817. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  3818. UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5+linespace, 200, 20)];
  3819. titlelabel.textColor=UIColorFromRGB(color);//[UIColor whiteColor];
  3820. titlelabel.backgroundColor = [UIColor clearColor];
  3821. titlelabel.text=NSLocalizedString(labeltitle, nil);
  3822. titlelabel.font = [UIFont boldSystemFontOfSize:20];
  3823. [titlelabel sizeToFit];
  3824. [myView addSubview:titlelabel];
  3825. //
  3826. // UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 0, 90, 22)];
  3827. // contactlabel.textColor=[UIColor whiteColor];
  3828. // contactlabel.backgroundColor = [UIColor clearColor];
  3829. // contactlabel.text=NSLocalizedString(@"Contact", nil);
  3830. // [contactlabel sizeToFit];
  3831. // [myView addSubview:contactlabel];
  3832. //
  3833. //
  3834. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 0, 90, 22)];
  3835. // modellabel.textColor=[UIColor whiteColor];
  3836. // modellabel.backgroundColor = [UIColor clearColor];
  3837. // modellabel.text=NSLocalizedString(@"Model", nil);
  3838. // [modellabel sizeToFit];
  3839. // [myView addSubview:modellabel];
  3840. //
  3841. // UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(500, 0, 90, 22)];
  3842. // pricelabel.textColor=[UIColor whiteColor];
  3843. // pricelabel.backgroundColor = [UIColor clearColor];
  3844. // pricelabel.text=NSLocalizedString(@"Price", nil);
  3845. // [pricelabel sizeToFit];
  3846. // [myView addSubview:pricelabel];
  3847. //
  3848. //
  3849. //
  3850. // UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(630, 0, 90, 22)];
  3851. // timelabel.textColor=[UIColor whiteColor];
  3852. // timelabel.backgroundColor = [UIColor clearColor];
  3853. // timelabel.text=NSLocalizedString(@"Create time", nil);
  3854. // [timelabel sizeToFit];
  3855. // [myView addSubview:timelabel];
  3856. //
  3857. //
  3858. //
  3859. // UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 60, 22)];
  3860. // statuslabel.textColor=[UIColor whiteColor];
  3861. // statuslabel.backgroundColor = [UIColor clearColor];
  3862. // statuslabel.text=NSLocalizedString(@"Status", nil);
  3863. // [statuslabel sizeToFit];
  3864. // [myView addSubview:statuslabel];
  3865. //
  3866. myView.backgroundColor = UIColor.lightGrayColor;
  3867. UIColor * c=myView.backgroundColor;
  3868. return myView;
  3869. }
  3870. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  3871. {
  3872. NSLog(@"Did Scroll %f",scrollView.contentOffset.y);
  3873. // CGPoint contentOffsetPoint = scrollView.contentOffset;
  3874. CGRect f = self.autocompleteView.frame;
  3875. CGRect rframe=[RAUtils relativeFrameForScreenWithView:self.lastedit];
  3876. NSLog(@"edit y %f",rframe.origin.y);
  3877. self.autocompleteView.frame = CGRectMake(f.origin.x, rframe.origin.y+rframe.size.height, f.size.width, f.size.height);
  3878. }
  3879. //
  3880. -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
  3881. {
  3882. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  3883. bool readonly = [[self.content_data_download valueForKey:@"readonly"]boolValue];
  3884. int disable = [[item_json valueForKey:@"disable"] intValue];
  3885. DebugLog(@"tableView willSelectRowAtIndexPath");
  3886. //
  3887. NSString* control = [item_json valueForKey:@"control"];
  3888. if([control isEqualToString:@"enum"])//||[control isEqualToString:@"ui"])
  3889. {
  3890. // int disable = [[item_json valueForKey:@"disable"] intValue];
  3891. if(disable==1||readonly)
  3892. return nil;
  3893. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
  3894. NSDictionary* cadedate_json = [item_json objectForKey:@"cadedate"];
  3895. // NSDictionary* value_json = [item_json objectForKey:@"value"];
  3896. NSString* single_select = [item_json valueForKey:@"single_select"];
  3897. // NSString* required =[item_json valueForKey:@"required"];
  3898. NSString* title = [item_json valueForKey:@"aname"];
  3899. BOOL sort = [[item_json objectForKey:@"sort"] boolValue];
  3900. if (sort) {
  3901. EnumSelectAndSortViewController *vc = [[UIStoryboard storyboardWithName:@"EnumSelectAndSort" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectAndSortViewController"];
  3902. vc.title = title;
  3903. [vc setEnumDataSource:cadedate_json];
  3904. vc.indexPath = indexPath;
  3905. __weak typeof(self) weakSelf = self;
  3906. vc.returnBlock = ^(NSDictionary *returnValue, NSIndexPath *idxPath) {
  3907. [weakSelf EnumValueChanged:[returnValue mutableCopy] indexPath:idxPath];
  3908. };
  3909. [self.navigationController pushViewController:vc animated:YES];
  3910. return nil;
  3911. }
  3912. BOOL online = [[item_json objectForKey:@"online"] boolValue];
  3913. if (online)
  3914. {
  3915. int max_select = [[item_json valueForKey:@"max"] intValue];
  3916. EnumSelectOnlineViewController* enumvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectOnlineViewController"];
  3917. enumvc.delegate = self;
  3918. enumvc.max_select = max_select;
  3919. enumvc.updatePosition = indexPath;
  3920. enumvc.online_params = item_json[@"params"];
  3921. // if([[required lowercaseString] isEqualToString:@"true"])
  3922. // enumvc.canbeEmpty = false;
  3923. // else
  3924. // enumvc.canbeEmpty =true;
  3925. // enumvc.cadedate = [cadedate_json mutableCopy];
  3926. enumvc.title = title;
  3927. // enumvc.value = [value_json mutableCopy];
  3928. enumvc.single_select =[[single_select lowercaseString] isEqualToString:@"true"];
  3929. [self.navigationController pushViewController:enumvc animated:true];
  3930. return nil;
  3931. }
  3932. int max_select = [[item_json valueForKey:@"max"] intValue];
  3933. EnumSelectViewController* enumvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
  3934. enumvc.delegate = self;
  3935. enumvc.max_select = max_select;
  3936. enumvc.updatePosition = indexPath;
  3937. // if([[required lowercaseString] isEqualToString:@"true"])
  3938. // enumvc.canbeEmpty = false;
  3939. // else
  3940. // enumvc.canbeEmpty =true;
  3941. enumvc.cadedate = [cadedate_json mutableCopy];
  3942. enumvc.title = title;
  3943. // enumvc.value = [value_json mutableCopy];
  3944. enumvc.single_select =[[single_select lowercaseString] isEqualToString:@"true"];
  3945. [self.navigationController pushViewController:enumvc animated:true];
  3946. }
  3947. else if([control isEqualToString:@"editor"])
  3948. {
  3949. [self handle_editor_cell_select:tableView IndexPath:indexPath];
  3950. }
  3951. else if([control isEqualToString:@"action"])
  3952. {
  3953. if (disable || readonly) {
  3954. return nil;
  3955. }
  3956. NSString* value = [item_json valueForKey:@"value"];
  3957. [self commonAction:value index:indexPath data:[item_json mutableCopy]];
  3958. }
  3959. else if([control isEqualToString:@"datepicker"])
  3960. {
  3961. if (disable || readonly) {
  3962. return nil;
  3963. }
  3964. // NSString* title = [item_json valueForKey:@"aname"];
  3965. NSString* value =[item_json valueForKey:@"value"];
  3966. NSString* type =[item_json valueForKey:@"type"];
  3967. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  3968. DatePickerViewController* dpvc =[ [UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"DatePickerViewController"];
  3969. if([[type lowercaseString] isEqualToString:@"date"])
  3970. {
  3971. dpvc.pickerMode = UIDatePickerModeDate;
  3972. [dateFormatter setDateFormat:@"MM/dd/yyyy"];
  3973. }
  3974. else if([[type lowercaseString] isEqualToString:@"time"])
  3975. {
  3976. dpvc.pickerMode = UIDatePickerModeTime;
  3977. [dateFormatter setDateFormat:@"HH:mm:ss"];
  3978. }
  3979. else
  3980. {
  3981. dpvc.pickerMode = UIDatePickerModeDateAndTime;
  3982. [dateFormatter setDateFormat:@"MM/dd/yyyy HH:mm:ss"];
  3983. }
  3984. __weak typeof(self) weakSelf = self;
  3985. NSDate *date = [dateFormatter dateFromString:value];
  3986. dpvc.date = date;
  3987. dpvc.formatter = dateFormatter;
  3988. dpvc.labelTime.text = value;
  3989. dpvc.blk_Set=^(NSString *date)
  3990. {
  3991. [weakSelf DateTimeValueChanged:date indexPath:indexPath];
  3992. };
  3993. [self.navigationController pushViewController:dpvc animated:true];
  3994. }else if([control isEqualToString:@"monthpicker"])
  3995. {
  3996. if (disable || readonly) {
  3997. return nil;
  3998. }
  3999. // NSString* title = [item_json valueForKey:@"aname"];
  4000. NSString* value =[item_json valueForKey:@"value"];
  4001. if (value==nil || value.length==0)
  4002. {
  4003. NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
  4004. formatter.dateFormat = @"MM/yyyy";
  4005. NSDate *date = [NSDate date];
  4006. value=[formatter stringFromDate:date];
  4007. }
  4008. // NSString* type =[item_json valueForKey:@"type"];
  4009. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  4010. MonthPickerViewController* mpvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"MonthPickerViewController"];
  4011. // if([[type lowercaseString] isEqualToString:@"date"])
  4012. // {
  4013. // dpvc.pickerMode = UIDatePickerModeDate;
  4014. [dateFormatter setDateFormat:@"MM/yyyy"];
  4015. NSDate *date = [dateFormatter dateFromString:value];
  4016. mpvc.current_date =date;
  4017. mpvc.updatePosition = indexPath;
  4018. mpvc.delegate = self;
  4019. // }
  4020. // else if([[type lowercaseString] isEqualToString:@"time"])
  4021. // {
  4022. // dpvc.pickerMode = UIDatePickerModeTime;
  4023. // [dateFormatter setDateFormat:@"HH:mm:ss"];
  4024. // }
  4025. // else
  4026. // {
  4027. // dpvc.pickerMode = UIDatePickerModeDateAndTime;
  4028. // [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
  4029. // }
  4030. // NSDate *date = [dateFormatter dateFromString:value];
  4031. // dpvc.date = date;
  4032. // dpvc.formatter = dateFormatter;
  4033. // dpvc.labelTime.text = value;
  4034. [self.navigationController pushViewController:mpvc animated:true];
  4035. }
  4036. else if([control isEqualToString:@"signature"])
  4037. {
  4038. // SignatureViewController * signvc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  4039. // signvc.title = [item_json valueForKey:@"aname"];
  4040. // signvc.indexPath = indexPath;
  4041. // // signvc.delegate = self;
  4042. // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
  4043. //
  4044. // signvc.existSignature = cell.imageviewSignature.image ;
  4045. //
  4046. //
  4047. //
  4048. // [self.navigationController pushViewController:signvc animated:true];
  4049. if (disable || readonly) {
  4050. return nil;
  4051. }
  4052. __block UIImage* signimg=nil;
  4053. SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  4054. __weak typeof(self) weakself = self;
  4055. vc.onReturnImg = ^(UIImage* img)
  4056. {
  4057. signimg = img;
  4058. if(signimg!=nil)
  4059. {
  4060. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4061. #ifdef SCANNER_ORDER
  4062. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  4063. {
  4064. NSData *data = [OLDataProvider offline_saveBusinesscard:UIImageJPEGRepresentation(img,1.0f)];
  4065. // 再将NSData转为字符串
  4066. NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  4067. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  4068. DebugLog(@"data string: %@",jsonStr);
  4069. NSError *error=nil;
  4070. NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
  4071. //NSMutableArray* arr_ret = [[NSMutableArray alloc] init];
  4072. if([[json valueForKey:@"result"] intValue]==2)
  4073. {
  4074. NSString* img_url_down = json[@"img_url_aname"];
  4075. // if(img_url_down.length==0)
  4076. // img_url_down=@"";
  4077. NSString* img_url_up = json[@"img_url"];
  4078. // if(img_url_up.length==0)
  4079. // img_url_up=@"";
  4080. NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
  4081. [item_json setValue:img_url_down forKey:@"avalue"];
  4082. [item_json setValue:img_url_up forKey:@"value"];
  4083. [item_json setValue:@"true" forKey:@"dirty"];
  4084. NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4085. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  4086. [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4087. weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
  4088. CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
  4089. cell.imageviewSignature.image = signimg;
  4090. }
  4091. else
  4092. {
  4093. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ;
  4094. }
  4095. return;
  4096. }
  4097. #endif
  4098. #ifdef OFFLINE_MODE
  4099. BOOL offline_mode = [[RASingleton.sharedInstance globalParameterForKey:@"offline_mode"] boolValue];
  4100. if(offline_mode)
  4101. {
  4102. NSData *data = [OLDataProvider offline_saveBusinesscard:UIImageJPEGRepresentation(img,1.0f)];
  4103. // 再将NSData转为字符串
  4104. NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  4105. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  4106. DebugLog(@"data string: %@",jsonStr);
  4107. NSError *error=nil;
  4108. NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
  4109. //NSMutableArray* arr_ret = [[NSMutableArray alloc] init];
  4110. if([[json valueForKey:@"result"] intValue]==2)
  4111. {
  4112. NSString* img_url_down = json[@"img_url_aname"];
  4113. // if(img_url_down.length==0)
  4114. // img_url_down=@"";
  4115. NSString* img_url_up = json[@"img_url"];
  4116. // if(img_url_up.length==0)
  4117. // img_url_up=@"";
  4118. NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
  4119. [item_json setValue:img_url_down forKey:@"avalue"];
  4120. [item_json setValue:img_url_up forKey:@"value"];
  4121. [item_json setValue:@"true" forKey:@"dirty"];
  4122. NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4123. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  4124. [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4125. weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
  4126. CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
  4127. cell.imageviewSignature.image = signimg;
  4128. }
  4129. else
  4130. {
  4131. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ;
  4132. }
  4133. }
  4134. else
  4135. #endif
  4136. {
  4137. NSData *imageData = UIImagePNGRepresentation(img);
  4138. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4139. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4140. NSString *user = [RASingleton.sharedInstance globalParameterForKey:@"user"];
  4141. NSString *password = [RASingleton.sharedInstance globalParameterForKey:@"password"];
  4142. if(user!=nil)
  4143. [params setValue:user forKey:@"user"];
  4144. if(password!=nil)
  4145. [params setValue:password forKey:@"password"];
  4146. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Upload Signature" completion:^{
  4147. [NetworkUtils upload:imageData FileName:@"test.jpg" Params:params ToHost:URL_UPLOAD_IMG Result:^(NSMutableDictionary *json) {
  4148. // dispatch_async(dispatch_get_main_queue(), ^{
  4149. [waitalert dismissViewControllerAnimated:YES completion:^{
  4150. if([[json valueForKey:@"result"] intValue]==2)
  4151. {
  4152. NSString* img_url_down = json[@"img_url_aname"];
  4153. NSString* img_url_up = json[@"img_url"];
  4154. NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
  4155. [item_json setValue:img_url_down forKey:@"avalue"];
  4156. [item_json setValue:img_url_up forKey:@"value"];
  4157. [item_json setValue:@"true" forKey:@"dirty"];
  4158. NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4159. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  4160. [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4161. weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
  4162. CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
  4163. cell.imageviewSignature.image = signimg;
  4164. }
  4165. else if([[json valueForKey:@"result"] intValue]==RESULT_LOGIN_ON_OTHER_DEVICE)
  4166. {
  4167. [[NSNotificationCenter defaultCenter] postNotificationName:RA_NOTIFICATION_KICKOUT object:nil];
  4168. }
  4169. else
  4170. {
  4171. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ;
  4172. }
  4173. }];
  4174. // });
  4175. } Progress:nil DecryptHandler:nil];
  4176. }];
  4177. self.alert = waitalert;
  4178. // AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
  4179. //
  4180. // NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:URL_UPLOAD_IMG parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
  4181. // [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test.jpg" mimeType:@"image/png"];
  4182. // } error:nil];
  4183. //
  4184. //
  4185. //
  4186. // AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  4187. //
  4188. //
  4189. //
  4190. //
  4191. // NSProgress *progress = nil;
  4192. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Upload Signature"];
  4193. // NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
  4194. //
  4195. // // [progress removeObserver:self forKeyPath:@"fractionCompleted"];
  4196. //
  4197. //
  4198. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  4199. //
  4200. // if (error) {
  4201. //
  4202. // NSString* err_msg = [error localizedDescription];
  4203. // DebugLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]];
  4204. //
  4205. //
  4206. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  4207. //
  4208. // DebugLog(@"data string: %@",str);
  4209. //
  4210. // [RAUtils message_alert:@"Can not connect to server please try again." title:@"Upload Image" controller:weakself] ;
  4211. //
  4212. // } else {
  4213. // DebugLog(@"response ");
  4214. //
  4215. //
  4216. //
  4217. // NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil];
  4218. //
  4219. // // 再将NSData转为字符串
  4220. // NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  4221. //
  4222. // // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
  4223. //
  4224. // DebugLog(@"data string: %@",jsonStr);
  4225. //
  4226. // NSDictionary* json = responseObject;
  4227. //
  4228. //
  4229. // //NSMutableArray* arr_ret = [[NSMutableArray alloc] init];
  4230. // if([[json valueForKey:@"result"] intValue]==2)
  4231. // {
  4232. // NSString* img_url_down = json[@"img_url_aname"];
  4233. // // if(img_url_down.length==0)
  4234. // // img_url_down=@"";
  4235. // NSString* img_url_up = json[@"img_url"];
  4236. // // if(img_url_up.length==0)
  4237. // // img_url_up=@"";
  4238. //
  4239. // NSMutableDictionary* item_json =((NSMutableArray*)weakself.content_data_control[indexPath.section])[indexPath.row];
  4240. //
  4241. // [item_json setValue:img_url_down forKey:@"avalue"];
  4242. // [item_json setValue:img_url_up forKey:@"value"];
  4243. // [item_json setValue:@"true" forKey:@"dirty"];
  4244. // NSMutableDictionary* section_json = [[weakself.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4245. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
  4246. //
  4247. // [weakself.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4248. // weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed:weakself.changed_data];
  4249. //
  4250. //
  4251. // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [weakself.editorTable cellForRowAtIndexPath:indexPath];
  4252. //
  4253. // cell.imageviewSignature.image = signimg;
  4254. //
  4255. //
  4256. // }
  4257. // else
  4258. // {
  4259. // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:weakself] ;
  4260. // }
  4261. //
  4262. //
  4263. //
  4264. //
  4265. //
  4266. //
  4267. // }
  4268. // //
  4269. // }];
  4270. //
  4271. // [uploadTask resume];
  4272. }
  4273. }
  4274. };
  4275. [self.navigationController pushViewController:vc animated:NO];
  4276. }
  4277. // else if([control isEqualToString:@"action "])
  4278. // {
  4279. //
  4280. // DebugLog(@"action push");
  4281. // // SignatureViewController * signvc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  4282. // // signvc.title = [item_json valueForKey:@"aname"];
  4283. // // signvc.indexPath = indexPath;
  4284. // // signvc.delegate = self;
  4285. // // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
  4286. // //
  4287. // // signvc.existSignature = cell.imageviewSignature.image ;
  4288. // //
  4289. // //
  4290. // //
  4291. // // [self.navigationController pushViewController:signvc animated:true];
  4292. // }
  4293. return nil;
  4294. }
  4295. //- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  4296. //{
  4297. //
  4298. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
  4299. //
  4300. // NSString* orderid = [item_json valueForKey:@"id"];
  4301. //
  4302. // // if (self.delegate && [self.delegate respondsToSelector:@selector(SelectOrder:)]) {
  4303. // // [self.delegate SelectOrder:orderid];
  4304. // // }
  4305. // //
  4306. // // [self dismissViewControllerAnimated:YES
  4307. // // completion:^{
  4308. // // //一定要移除手势 否则下次 没有子视图的时候 点击 会崩溃拉
  4309. // // AppDelegate *app = [[UIApplication sharedApplication] delegate];
  4310. // // [app.window removeGestureRecognizer:self.tapGesture];
  4311. // // }];
  4312. // // [pvc categoryMenuSelected:indexPath.row];
  4313. //}
  4314. #pragma mark monthpicker ViewControllerDelegate
  4315. -(void) MPValueChanged:(NSString *)value indexPath :(NSIndexPath*) indexPath
  4316. {
  4317. CommonEditorCellEnum * cell= (CommonEditorCellEnum*) [self.editorTable cellForRowAtIndexPath:indexPath];
  4318. cell.labelValue.text = value;
  4319. {
  4320. CALayer *layer = [cell.contentView layer];
  4321. // layer.borderColor = [[UIColor redColor] CGColor];
  4322. // layer.borderWidth = 1.0;
  4323. layer.shadowColor = [UIColor clearColor].CGColor;
  4324. layer.shadowOffset = CGSizeMake(0, 0);
  4325. layer.shadowOpacity = 1;
  4326. layer.shadowRadius = 2.0;
  4327. }
  4328. // NSMutableString* title = [[item_json valueForKey:@"aname"] mutableCopy];
  4329. // UITableViewCell *cell = (UITableViewCell *) paramSender.superview.superview;
  4330. // NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  4331. NSMutableDictionary* section_json=nil;
  4332. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  4333. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  4334. // NSString* check=@"false";
  4335. // if([paramSender isOn])
  4336. // check=@"true";
  4337. // [item_json setValue:value forKey:@"dirty"];
  4338. NSString* subid=[item_json valueForKey:@"subid"];
  4339. [item_json setValue:value forKey:@"value"];
  4340. if(subid==nil)
  4341. {
  4342. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4343. int count=0;
  4344. count=[[section_json valueForKey:@"count"] intValue];
  4345. for(int i=0;i<count;i++)
  4346. {
  4347. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  4348. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  4349. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  4350. }
  4351. }
  4352. else
  4353. {
  4354. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  4355. int section = [(NSString*)idarr[0] intValue];
  4356. int item=[(NSString*)idarr[1] intValue];
  4357. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  4358. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  4359. NSString* control_type= [olditem valueForKey:@"control"];
  4360. if([control_type isEqualToString:@"enum"])
  4361. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  4362. else if([control_type isEqualToString:@"switch"])
  4363. item_json= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  4364. [item_json setValue:@"true" forKey:@"dirty"];
  4365. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  4366. }
  4367. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4368. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  4369. [self.editorTable reloadData ];
  4370. }
  4371. #pragma mark datetimeChanged
  4372. -(void) DateTimeValueChanged:(NSString *)value indexPath :(NSIndexPath*) indexPath
  4373. {
  4374. NSMutableDictionary* section_json=nil;
  4375. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  4376. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  4377. bool refresh = [[item_json valueForKey:@"refresh"] boolValue];
  4378. bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
  4379. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  4380. NSString* subid=[item_json valueForKey:@"subid"];
  4381. // NSArray* imgs=[RAUtils string2arr:url_up separator:@","];
  4382. // imgs[index];
  4383. item_json[@"value"]=value;
  4384. [item_json setValue:@"true" forKey:@"dirty"];
  4385. if(subid==nil)
  4386. {
  4387. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4388. int count=0;
  4389. count=[[section_json valueForKey:@"count"] intValue];
  4390. for(int i=0;i<count;i++)
  4391. {
  4392. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  4393. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  4394. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  4395. }
  4396. }
  4397. else
  4398. {
  4399. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  4400. int section = [(NSString*)idarr[0] intValue];
  4401. int item=[(NSString*)idarr[1] intValue];
  4402. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  4403. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  4404. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  4405. [item_json setValue:@"true" forKey:@"dirty"];
  4406. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  4407. }
  4408. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4409. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  4410. // NSRange range = NSMakeRange(indexPath.section, 1);
  4411. // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  4412. // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  4413. if(refresh)
  4414. {
  4415. [self refresh:refresh_trigger discardDirty:discardDirty];
  4416. }
  4417. [self.editorTable reloadData ];
  4418. }
  4419. #pragma mark EnumSelectViewControllerDelegate
  4420. -(void) setEnumValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  4421. {
  4422. NSMutableDictionary* section_json=nil;
  4423. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  4424. bool refresh = [[item_json valueForKey:@"refresh"] boolValue];
  4425. bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
  4426. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  4427. NSString* subid=[item_json valueForKey:@"subid"];
  4428. [item_json setObject:value forKey:@"cadedate"];
  4429. if(subid==nil)
  4430. {
  4431. [item_json setValue:@"true" forKey:@"dirty"];
  4432. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4433. int count=0;
  4434. count=[[section_json valueForKey:@"count"] intValue];
  4435. for(int i=0;i<count;i++)
  4436. {
  4437. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  4438. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  4439. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  4440. }
  4441. }
  4442. else
  4443. {
  4444. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  4445. int section = [(NSString*)idarr[0] intValue];
  4446. int item=[(NSString*)idarr[1] intValue];
  4447. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  4448. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  4449. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  4450. [item_json setValue:@"true" forKey:@"dirty"];
  4451. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  4452. }
  4453. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  4454. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4455. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  4456. NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  4457. if(refresh)
  4458. {
  4459. if(restore_json!=nil)
  4460. {
  4461. int rc=[[restore_json valueForKey:@"count"] intValue];
  4462. for(int ir=0;ir<rc;ir++)
  4463. {
  4464. NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  4465. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  4466. for(int i=0;i<section_count;i++)
  4467. {
  4468. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  4469. // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  4470. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  4471. for(int j=0;j<item_count;j++)
  4472. {
  4473. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  4474. // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  4475. if([[itemjson valueForKey:@"name"] isEqualToString:name])
  4476. {
  4477. [itemjson removeObjectForKey:@"dirty"];
  4478. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  4479. }
  4480. }
  4481. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  4482. }
  4483. }
  4484. }
  4485. [self refresh:refresh_trigger discardDirty:discardDirty];
  4486. return ;
  4487. }
  4488. DebugLog(@"CONTENT UPDATE:%@",[RAConvertor DataTOjsonString:self.content_data_download]);
  4489. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  4490. [self.editorTable reloadData ];
  4491. }
  4492. -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  4493. {
  4494. UITableViewCell *cell = [self.editorTable cellForRowAtIndexPath:indexPath];
  4495. // if(/*self.cancommit==false &&*/ string.length==0 && (textField.text.length<=1|| textField.text==nil))
  4496. // {
  4497. // CALayer *layer = [cell.contentView layer];
  4498. // // layer.borderColor = [[UIColor redColor] CGColor];
  4499. // // layer.borderWidth = 1.0;
  4500. //
  4501. // layer.shadowColor = [UIColor redColor].CGColor;
  4502. // layer.shadowOffset = CGSizeMake(0, 0);
  4503. // layer.shadowOpacity = 1;
  4504. // layer.shadowRadius = 2.0;
  4505. // }
  4506. // else
  4507. {
  4508. CALayer *layer = [cell.contentView layer];
  4509. // layer.borderColor = [[UIColor redColor] CGColor];
  4510. // layer.borderWidth = 1.0;
  4511. layer.shadowColor = [UIColor clearColor].CGColor;
  4512. layer.shadowOffset = CGSizeMake(0, 0);
  4513. layer.shadowOpacity = 1;
  4514. layer.shadowRadius = 2.0;
  4515. }
  4516. DebugLog(@"enum changed %ld_%ld",(long)indexPath.section,(long)indexPath.row);
  4517. [self setEnumValue:value indexPath:indexPath];
  4518. }
  4519. -(NSMutableDictionary*) enum_subitem_changed:(NSMutableDictionary *) item subid:(NSArray*) subid value:(NSMutableDictionary*)value step:(int) step
  4520. {
  4521. int index = [(NSString*)subid[step] intValue];
  4522. NSMutableDictionary * cadedate= [[item objectForKey:@"cadedate"] mutableCopy];
  4523. NSMutableDictionary * subitem= [[item objectForKey:@"sub_item"] mutableCopy];
  4524. if(cadedate!=nil)
  4525. {
  4526. NSMutableDictionary * valjson=[[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",index]]mutableCopy];
  4527. valjson= [self enum_subitem_changed:valjson subid:subid value:value step:step+1];
  4528. [cadedate setObject:valjson forKey:[NSString stringWithFormat:@"val_%d",index]];
  4529. [item setObject:cadedate forKey:@"cadedate"];
  4530. return item;
  4531. }
  4532. else if(subitem!=nil)
  4533. {
  4534. NSMutableDictionary * itemjson=[[subitem objectForKey:[NSString stringWithFormat:@"item_%d",index]] mutableCopy];
  4535. if(step==subid.count-1)
  4536. {
  4537. itemjson =value;
  4538. }
  4539. else
  4540. itemjson =[self enum_subitem_changed:itemjson subid:subid value:value step:step+1];
  4541. [subitem setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",index]];
  4542. [item setObject:subitem forKey:@"sub_item"];
  4543. return item;
  4544. }
  4545. return nil;
  4546. }
  4547. //#pragma mark SignatureViewControllerDelegate
  4548. ////-(void)SignatureVCReturnData:(NSData *)imagedata indexPath:(NSIndexPath *)indexPath
  4549. ////{
  4550. ////
  4551. ////}
  4552. //-(void)SignatureVCReturnImage:(UIImage *)image indexPath:(NSIndexPath *)indexPath
  4553. //{
  4554. //
  4555. // // NSMutableDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  4556. // //
  4557. // // if(image==nil)
  4558. // // [item_json removeObjectForKey:@"signature"];
  4559. // // else
  4560. // // [item_json setObject:image forKey:@"signature"];
  4561. // // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4562. // // [self.content_data setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4563. // //
  4564. // //
  4565. // //
  4566. // // CommonEditorCellSignature* cell = (CommonEditorCellSignature*) [self.editorTable cellForRowAtIndexPath:indexPath];
  4567. // // cell.imageviewSignature.image = image;
  4568. //}
  4569. #pragma mark textView delegate
  4570. //- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
  4571. //- (BOOL)textViewShouldEndEditing:(UITextView *)textView;
  4572. - (BOOL)textViewShouldBeginEditing:(UITextView *)textView
  4573. {
  4574. DebugLog(@"textViewShouldBeginEditing");
  4575. self.editingcell = (UITableViewCell*)textView.superview.superview;
  4576. return textView.editable;
  4577. }
  4578. - (void)textViewDidBeginEditing:(UITextView *)textView
  4579. {
  4580. self.lasttextview = textView;
  4581. UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
  4582. self.lasttextview_from = [self.editorTable indexPathForCell:cell];
  4583. }
  4584. - (void)textViewDidEndEditing:(UITextView *)textView
  4585. {
  4586. // UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
  4587. NSIndexPath * indexPath = self.lasttextview_from;//[self.editorTable indexPathForCell:cell];
  4588. NSMutableDictionary* section_json=nil;
  4589. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  4590. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  4591. NSString* subid=[item_json valueForKey:@"subid"];
  4592. NSString* item_value = item_json[@"value"];
  4593. if(item_value.length==0)
  4594. item_value = @"";
  4595. if(![textView.text isEqualToString:item_value])
  4596. {
  4597. //值不相同才设置dirty
  4598. [item_json setValue:@"true" forKey:@"dirty"];
  4599. self.isdirty = true;
  4600. }
  4601. // [item_json setValue:@"true" forKey:@"dirty"];
  4602. [item_json setValue:textView.text forKey:@"value"];
  4603. // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
  4604. if(subid==nil)
  4605. {
  4606. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4607. int count=0;
  4608. count=[[section_json valueForKey:@"count"] intValue];
  4609. for(int i=0;i<count;i++)
  4610. {
  4611. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  4612. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  4613. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  4614. }
  4615. }
  4616. else
  4617. {
  4618. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  4619. int section = [(NSString*)idarr[0] intValue];
  4620. int item=[(NSString*)idarr[1] intValue];
  4621. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  4622. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  4623. NSString* control_type= [olditem valueForKey:@"control"];
  4624. if([control_type isEqualToString:@"enum"])
  4625. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  4626. else if([control_type isEqualToString:@"switch"])
  4627. item_json= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  4628. [item_json setValue:@"true" forKey:@"dirty"];
  4629. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  4630. }
  4631. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4632. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  4633. self.lasttextview = nil;
  4634. self.lasttextview_from=nil;
  4635. // if(self.resize)
  4636. // {
  4637. // NSTimeInterval animationDuration = 0.30f;
  4638. // CGRect frame = self.view.frame;
  4639. // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
  4640. // // { //还原界面
  4641. // // moveY = prewMoveY;
  4642. // frame.origin.y +=self.ioffset;
  4643. // frame.size. height -=self.ioffset;
  4644. // self.view.frame = frame;
  4645. // // }
  4646. // //self.view移回原位置
  4647. // [UIView beginAnimations:@"ResizeView" context:nil];
  4648. // [UIView setAnimationDuration:animationDuration];
  4649. // self.view.frame = frame;
  4650. // [UIView commitAnimations];
  4651. // //[textField resignFirstResponder];
  4652. // self.ioffset=0;
  4653. // }
  4654. }
  4655. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  4656. {
  4657. UITableViewCell *cell = (UITableViewCell *) textView.superview.superview;
  4658. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  4659. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  4660. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  4661. NSString* required = [item_json valueForKey:@"required"];
  4662. if([required isEqualToString:@"true"] && text.length==0 && (textView.text.length<=1|| textView.text==nil))
  4663. {
  4664. CALayer *layer = [cell.contentView layer];
  4665. // layer.borderColor = [[UIColor redColor] CGColor];
  4666. // layer.borderWidth = 1.0;
  4667. layer.shadowColor = [UIColor redColor].CGColor;
  4668. layer.shadowOffset = CGSizeMake(0, 0);
  4669. layer.shadowOpacity = 1;
  4670. layer.shadowRadius = 2.0;
  4671. }
  4672. else
  4673. {
  4674. CALayer *layer = [cell.contentView layer];
  4675. // layer.borderColor = [[UIColor redColor] CGColor];
  4676. // layer.borderWidth = 1.0;
  4677. layer.shadowColor = [UIColor clearColor].CGColor;
  4678. layer.shadowOffset = CGSizeMake(0, 0);
  4679. layer.shadowOpacity = 1;
  4680. layer.shadowRadius = 2.0;
  4681. }
  4682. return YES;
  4683. }
  4684. //- (void)textViewDidChange:(UITextView *)textView;
  4685. //
  4686. //- (void)textViewDidChangeSelection:(UITextView *)textView;
  4687. //
  4688. //- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
  4689. //- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
  4690. #pragma mark textField delegate
  4691. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  4692. DebugLog(@"textField shouldChangeCharactersInRange");
  4693. DebugLog(@"text:%@",textField.text);
  4694. CommonEditorCellEdit *cell = (CommonEditorCellEdit *) textField.superview.superview;
  4695. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  4696. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  4697. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  4698. NSString* required = [item_json valueForKey:@"required"];
  4699. if([required isEqualToString:@"true"] && string.length==0 && (textField.text.length<=1|| textField.text==nil))
  4700. {
  4701. CALayer *layer = cell.labelTitle.layer;
  4702. // layer.borderColor = [[UIColor redColor] CGColor];
  4703. // layer.borderWidth = 1.0;
  4704. layer.shadowColor = [UIColor redColor].CGColor;
  4705. layer.shadowOffset = CGSizeMake(0, 0);
  4706. layer.shadowOpacity = 1;
  4707. layer.shadowRadius = 2.0;
  4708. layer = cell.starMark.layer;
  4709. // layer.borderColor = [[UIColor redColor] CGColor];
  4710. // layer.borderWidth = 1.0;
  4711. layer.shadowColor = [UIColor redColor].CGColor;
  4712. layer.shadowOffset = CGSizeMake(0, 0);
  4713. layer.shadowOpacity = 1;
  4714. layer.shadowRadius = 2.0;
  4715. //UIImageView * iv =
  4716. cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_attention_24"]];
  4717. cell.textfield.rightViewMode=UITextFieldViewModeUnlessEditing;
  4718. textField.layer.cornerRadius=8.0f;
  4719. textField.layer.borderWidth= 1.0f;
  4720. textField.layer.masksToBounds=YES;
  4721. textField.layer.borderColor=[[UIColor redColor]CGColor];
  4722. }
  4723. else
  4724. {
  4725. CALayer *layer = cell.labelTitle.layer;//[cell.contentView layer];
  4726. // layer.borderColor = [[UIColor redColor] CGColor];
  4727. // layer.borderWidth = 1.0;
  4728. layer.shadowColor = [UIColor clearColor].CGColor;
  4729. layer.shadowOffset = CGSizeMake(0, 0);
  4730. layer.shadowOpacity = 1;
  4731. layer = cell.starMark.layer;//[cell.contentView layer];
  4732. layer.shadowColor = [UIColor clearColor].CGColor;
  4733. layer.shadowOffset = CGSizeMake(0, 0);
  4734. layer.shadowOpacity = 1;
  4735. //cell.textfield.layer.borderColor= [[UIColor lightGrayColor] CGColor];
  4736. //UIImageView * iv =
  4737. // cell.textfield.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mark_wish_16"]];
  4738. cell.textfield.rightViewMode=UITextFieldViewModeNever;
  4739. textField.layer.cornerRadius=8.0f;
  4740. textField.layer.borderWidth= 1.0f;
  4741. textField.layer.masksToBounds=YES;
  4742. textField.layer.borderColor=[[UIColor lightGrayColor]CGColor];
  4743. }
  4744. //
  4745. // if([required isEqualToString:@"true"] && string.length==0 && (textField.text.length<=1|| textField.text==nil))
  4746. // {
  4747. // CALayer *layer = [cell.contentView layer];
  4748. // // layer.borderColor = [[UIColor redColor] CGColor];
  4749. // // layer.borderWidth = 1.0;
  4750. //
  4751. // layer.shadowColor = [UIColor redColor].CGColor;
  4752. // layer.shadowOffset = CGSizeMake(0, 0);
  4753. // layer.shadowOpacity = 1;
  4754. // layer.shadowRadius = 2.0;
  4755. // }
  4756. // else
  4757. // {
  4758. // CALayer *layer = [cell.contentView layer];
  4759. // // layer.borderColor = [[UIColor redColor] CGColor];
  4760. // // layer.borderWidth = 1.0;
  4761. //
  4762. // layer.shadowColor = [UIColor clearColor].CGColor;
  4763. // layer.shadowOffset = CGSizeMake(0, 0);
  4764. // layer.shadowOpacity = 1;
  4765. // layer.shadowRadius = 2.0;
  4766. // }
  4767. int lenth = [[item_json valueForKey:@"length"] intValue];
  4768. NSString* keyboard = [item_json valueForKey:@"keyboard"];
  4769. if(![keyboard isEqualToString:@"number"] && ![keyboard isEqualToString:@"int"])
  4770. {
  4771. if(lenth==0)
  4772. {
  4773. if([item_json[@"autocomplete"] boolValue])
  4774. {
  4775. self.autocompleteView.hidden = false;
  4776. CGRect f = self.autocompleteView.frame;
  4777. CGRect rframe=[RAUtils relativeFrameForScreenWithView:textField];
  4778. NSLog(@"edit y %f",rframe.origin.y);
  4779. self.autocompleteView.frame = CGRectMake(f.origin.x, rframe.origin.y+rframe.size.height, f.size.width, f.size.height);
  4780. [self.autocompleteView performSearch:textField.text];
  4781. }
  4782. return TRUE;
  4783. }
  4784. else
  4785. {
  4786. if([item_json[@"autocomplete"] boolValue])
  4787. {
  4788. self.autocompleteView.hidden = false;
  4789. CGRect f = self.autocompleteView.frame;
  4790. CGRect rframe=[RAUtils relativeFrameForScreenWithView:textField];
  4791. NSLog(@"edit y %f",rframe.origin.y);
  4792. self.autocompleteView.frame = CGRectMake(f.origin.x, rframe.origin.y+rframe.size.height, f.size.width, f.size.height);
  4793. [self.autocompleteView performSearch:textField.text];
  4794. }
  4795. return (lenth>textField.text.length ||[string isEqualToString:@""]);
  4796. }
  4797. }
  4798. NSCharacterSet *cs;
  4799. if([keyboard isEqualToString:@"number"])
  4800. cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
  4801. else
  4802. cs = [[NSCharacterSet characterSetWithCharactersInString:INTNUMBERS]invertedSet];
  4803. NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
  4804. BOOL canChange = [string isEqualToString:filtered];
  4805. // if([item_json[@"autocomplete"] boolValue]==true&&canChange)
  4806. // {
  4807. //
  4808. // }
  4809. if(lenth==0)
  4810. {
  4811. if([item_json[@"autocomplete"] boolValue])
  4812. {
  4813. self.autocompleteView.hidden = false;
  4814. CGRect f = self.autocompleteView.frame;
  4815. CGRect rframe=[RAUtils relativeFrameForScreenWithView:textField];
  4816. NSLog(@"edit y %f",rframe.origin.y);
  4817. self.autocompleteView.frame = CGRectMake(f.origin.x, rframe.origin.y+rframe.size.height, f.size.width, f.size.height);
  4818. [self.autocompleteView performSearch:textField.text];
  4819. }
  4820. return canChange;
  4821. }
  4822. else
  4823. {
  4824. if([item_json[@"autocomplete"] boolValue])
  4825. {
  4826. self.autocompleteView.hidden = false;
  4827. CGRect f = self.autocompleteView.frame;
  4828. CGRect rframe=[RAUtils relativeFrameForScreenWithView:textField];
  4829. NSLog(@"edit y %f",rframe.origin.y);
  4830. self.autocompleteView.frame = CGRectMake(f.origin.x, rframe.origin.y+rframe.size.height, f.size.width, f.size.height);
  4831. [self.autocompleteView performSearch:textField.text];
  4832. }
  4833. return canChange&& (lenth>textField.text.length ||[string isEqualToString:@""]);
  4834. }
  4835. }
  4836. //- (void)textFieldDidChangeSelection:(UITextField *)textField
  4837. //{
  4838. //
  4839. //}
  4840. - (void)textFieldDidEndEditing:(UITextField *)textField
  4841. {
  4842. DebugLog(@"textFieldDidEndEditing");
  4843. // UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  4844. NSIndexPath * indexPath = self.lastedit_from;
  4845. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  4846. if ([item_json objectForKey:@"fill"]) {
  4847. NSString *fillText = [item_json objectForKey:@"fill"];
  4848. if (fillText && textField.text.length == 0) {
  4849. textField.text = fillText;
  4850. }
  4851. }
  4852. if([item_json[@"autocomplete"] boolValue])
  4853. {
  4854. self.autocompleteView.hidden = true;
  4855. }
  4856. [self textfieldSetValue:indexPath value:textField.text];
  4857. // NSMutableDictionary* section_json=nil;
  4858. //
  4859. //
  4860. //
  4861. // textField.text = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  4862. //
  4863. // // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  4864. // NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  4865. //
  4866. // NSString* subid=[item_json valueForKey:@"subid"];
  4867. // NSString* refresh_trigger = [item_json valueForKey:@"name"];
  4868. //
  4869. // [item_json setValue:@"true" forKey:@"dirty"];
  4870. // [item_json setValue:textField.text forKey:@"value"];
  4871. // if([[item_json valueForKey:@"keyboard"] isEqualToString:@"number"])
  4872. // {
  4873. // float f = [ textField.text floatValue];
  4874. // [item_json setValue:[NSString stringWithFormat:@"%.2f",f] forKey:@"value"];
  4875. //
  4876. // }
  4877. //
  4878. // // [self.content_data_control[indexPath.section] setObject:item_json forKey:indexPath.row];
  4879. // if(subid==nil)
  4880. // {
  4881. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  4882. // int count=0;
  4883. //
  4884. // count=[[section_json valueForKey:@"count"] intValue];
  4885. //
  4886. // for(int i=0;i<count;i++)
  4887. // {
  4888. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  4889. // if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  4890. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  4891. //
  4892. //
  4893. // }
  4894. //
  4895. //
  4896. // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  4897. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  4898. //
  4899. // int refresh = [[item_json valueForKey:@"refresh"] intValue];
  4900. //
  4901. // NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  4902. // bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
  4903. // if(refresh)
  4904. // {
  4905. //
  4906. // if(restore_json!=nil)
  4907. // {
  4908. // int rc=[[restore_json valueForKey:@"count"] intValue];
  4909. // for(int ir=0;ir<rc;ir++)
  4910. // {
  4911. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  4912. //
  4913. //
  4914. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  4915. // for(int i=0;i<section_count;i++)
  4916. // {
  4917. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  4918. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  4919. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  4920. // for(int j=0;j<item_count;j++)
  4921. // {
  4922. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  4923. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  4924. //
  4925. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  4926. // {
  4927. // [itemjson removeObjectForKey:@"dirty"];
  4928. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  4929. // }
  4930. //
  4931. // }
  4932. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  4933. // }
  4934. //
  4935. //
  4936. // }
  4937. //
  4938. // }
  4939. // [self refresh:refresh_trigger] ;
  4940. //
  4941. // }
  4942. // else if(partial_refresh)
  4943. // {
  4944. // NSString* name = [item_json valueForKey:@"name"] ;
  4945. // NSString* url = [item_json valueForKey:@"data_interface"] ;
  4946. //
  4947. //
  4948. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4949. //
  4950. // [params setValue:textField.text forKey:name];
  4951. //
  4952. //
  4953. // UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
  4954. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4955. //
  4956. // NSDictionary* editor_json = [iSalesNetwork commoneditor_partialrefresh:params url:url];
  4957. //
  4958. // dispatch_async(dispatch_get_main_queue(), ^{
  4959. //
  4960. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  4961. //
  4962. //
  4963. // if([[editor_json valueForKey:@"result"] intValue]==2)
  4964. // {
  4965. //
  4966. // int prcount = [[editor_json valueForKey:@"count"] intValue];
  4967. // for(int ipr=0;ipr<prcount;ipr++)
  4968. // {
  4969. // NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
  4970. // NSString* name = [pr_item valueForKey:@"name"];
  4971. // NSString* value = [pr_item valueForKey:@"value"];
  4972. //
  4973. // [self setValue:name value:value];
  4974. // }
  4975. //
  4976. //
  4977. // }
  4978. // else
  4979. // {
  4980. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
  4981. // }
  4982. //
  4983. //
  4984. // });
  4985. // });
  4986. //
  4987. //
  4988. //
  4989. // }
  4990. // self.lastedit = nil;
  4991. // self.lastedit_from=nil;
  4992. // return ;
  4993. // }
  4994. // else
  4995. // {
  4996. // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  4997. // int section = [(NSString*)idarr[0] intValue];
  4998. // int item=[(NSString*)idarr[1] intValue];
  4999. //
  5000. //
  5001. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  5002. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  5003. //
  5004. // NSString* control_type= [olditem valueForKey:@"control"];
  5005. // NSMutableDictionary* new_item=nil;
  5006. // [item_json setValue:@"true" forKey:@"dirty"];
  5007. // if([control_type isEqualToString:@"enum"])
  5008. // new_item= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  5009. // else if([control_type isEqualToString:@"switch"])
  5010. // new_item= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  5011. //
  5012. // [section_json setObject:new_item forKey:[NSString stringWithFormat:@"item_%d",item ]];
  5013. //
  5014. //
  5015. // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  5016. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  5017. //
  5018. // int refresh = [[item_json valueForKey:@"refresh"] intValue];
  5019. //
  5020. // NSDictionary * restore_json=[item_json objectForKeyedSubscript:@"restore"];
  5021. // bool partial_refresh=[[item_json valueForKey:@"partial_refresh"] boolValue];
  5022. // if(refresh)
  5023. // {
  5024. //
  5025. // if(restore_json!=nil)
  5026. // {
  5027. // int rc=[[restore_json valueForKey:@"count"] intValue];
  5028. // for(int ir=0;ir<rc;ir++)
  5029. // {
  5030. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  5031. //
  5032. //
  5033. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  5034. // for(int i=0;i<section_count;i++)
  5035. // {
  5036. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  5037. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  5038. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  5039. // for(int j=0;j<item_count;j++)
  5040. // {
  5041. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  5042. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  5043. //
  5044. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  5045. // {
  5046. // [itemjson removeObjectForKey:@"dirty"];
  5047. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  5048. // }
  5049. //
  5050. // }
  5051. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  5052. // }
  5053. //
  5054. //
  5055. // }
  5056. //
  5057. // }
  5058. // [self refresh:refresh_trigger] ;
  5059. //
  5060. // }
  5061. // else if(partial_refresh)
  5062. // {
  5063. // NSString* name = [item_json valueForKey:@"name"] ;
  5064. // NSString* url = [item_json valueForKey:@"data_interface"] ;
  5065. //
  5066. //
  5067. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5068. //
  5069. // [params setValue:textField.text forKey:name];
  5070. //
  5071. //
  5072. // UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
  5073. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5074. //
  5075. // NSDictionary* editor_json = [iSalesNetwork commoneditor_partialrefresh:params url:url];
  5076. //
  5077. // dispatch_async(dispatch_get_main_queue(), ^{
  5078. //
  5079. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  5080. //
  5081. //
  5082. // if([[editor_json valueForKey:@"result"] intValue]==2)
  5083. // {
  5084. //
  5085. // int prcount = [[editor_json valueForKey:@"count"] intValue];
  5086. // for(int ipr=0;ipr<prcount;ipr++)
  5087. // {
  5088. // NSDictionary* pr_item = [editor_json objectForKey:[NSString stringWithFormat:@"item_%d",ipr]];
  5089. // NSString* name = [pr_item valueForKey:@"name"];
  5090. // NSString* value = [pr_item valueForKey:@"value"];
  5091. //
  5092. // [self setValue:name value:value];
  5093. // }
  5094. //
  5095. // }
  5096. // else
  5097. // {
  5098. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
  5099. // }
  5100. //
  5101. //
  5102. // });
  5103. // });
  5104. //
  5105. //
  5106. //
  5107. // }
  5108. // self.lastedit = nil;
  5109. // self.lastedit_from=nil;
  5110. //
  5111. // return;
  5112. // }
  5113. //
  5114. }
  5115. - (void)textFieldDidBeginEditing:(UITextField *)textField
  5116. {
  5117. DebugLog(@"textField textFieldDidBeginEditing");
  5118. self.lastedit = textField;
  5119. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  5120. self.lastedit_from = [self.editorTable indexPathForCell:cell];
  5121. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[self.lastedit_from.section])[self.lastedit_from.row];
  5122. if ([item_json valueForKey:@"clear"]) {
  5123. //开始编辑时清掉旧内容
  5124. BOOL clear = [[item_json valueForKey:@"clear"] doubleValue] == [textField.text doubleValue];
  5125. if (clear) {
  5126. textField.text = nil;
  5127. }
  5128. }
  5129. }
  5130. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  5131. {
  5132. // [self searchAction];
  5133. [textField resignFirstResponder];
  5134. return YES;
  5135. }
  5136. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  5137. self.editingcell = (UITableViewCell*)textField.superview.superview;
  5138. NSIndexPath* indexPath=[self.editorTable indexPathForCell:self.editingcell];
  5139. // NSMutableDictionary* section_json=nil;
  5140. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  5141. if([item_json[@"autocomplete"] boolValue]==true)
  5142. {
  5143. // [textField endEditing:true];
  5144. self.lastedit_from = [self.editorTable indexPathForCell:(UITableViewCell*) textField.superview.superview];
  5145. self.autocompleteView.active_field = textField;
  5146. // self.autocompleteView.hidden = false;
  5147. self.autocompleteView.searchInput.keyboardType=textField.keyboardType;
  5148. self.autocompleteView.searchInput.text= textField.text;
  5149. [self.autocompleteView.searchInput becomeFirstResponder];
  5150. __weak typeof(self) weakself = self;
  5151. self.autocompleteView.returnValue = ^(NSString *str) {
  5152. //textField = true;
  5153. // [textField endEditing:false];
  5154. textField.text=str;
  5155. // [textField endEditing:true];
  5156. [weakself textFieldDidEndEditing:textField];
  5157. };
  5158. CGRect rframe=[RAUtils relativeFrameForScreenWithView:textField];
  5159. self.autocompleteView.frame= CGRectMake(rframe.origin.x,rframe.origin.y+rframe.size.height,rframe.size.width,400);//CGRectMake(screenframe.origin.x, screenframe.origin.y, screenframe.size.width, end_y);
  5160. // return false;
  5161. }
  5162. return YES;
  5163. }
  5164. #pragma mark- autocomplete //自动完成填空内容需要实现此协议
  5165. -(nullable NSArray*)sync_loadCadidate:(nonnull NSString*)str
  5166. {
  5167. NSMutableArray* ret = [NSMutableArray new];
  5168. NSDictionary* obj = @{@"name":@"",@"value":@"autocomplete datasource loadCadidate does not impl"};
  5169. [ret addObject:obj];
  5170. return ret;
  5171. }
  5172. #pragma mark- img changed
  5173. // image 改变时执行
  5174. - (void) imgIsChanged:(NSString *)url_down url_up:(NSString *)url_up indexPath: (NSIndexPath *) indexPath index:(int)index url_index:(NSString* )url_index{
  5175. // DebugLog(@"Sender is = %@", url);
  5176. NSMutableDictionary* section_json=nil;
  5177. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  5178. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  5179. bool refresh = [[item_json valueForKey:@"refresh"] boolValue];
  5180. bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
  5181. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  5182. NSString* subid=[item_json valueForKey:@"subid"];
  5183. // NSArray* imgs=[RAUtils string2arr:url_up separator:@","];
  5184. // imgs[index];
  5185. item_json[ [NSString stringWithFormat:@"img_url_%d",index]]=url_down;
  5186. item_json[@"avalue"]=url_up;
  5187. item_json[[NSString stringWithFormat:@"img_url_aname_%d",index]]=url_index;
  5188. [item_json setValue:@"true" forKey:@"dirty"];
  5189. if(subid==nil)
  5190. {
  5191. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  5192. int count=0;
  5193. count=[[section_json valueForKey:@"count"] intValue];
  5194. for(int i=0;i<count;i++)
  5195. {
  5196. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  5197. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  5198. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  5199. }
  5200. }
  5201. else
  5202. {
  5203. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  5204. int section = [(NSString*)idarr[0] intValue];
  5205. int item=[(NSString*)idarr[1] intValue];
  5206. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  5207. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  5208. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  5209. [item_json setValue:@"true" forKey:@"dirty"];
  5210. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  5211. }
  5212. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  5213. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  5214. // NSRange range = NSMakeRange(indexPath.section, 1);
  5215. // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  5216. // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  5217. if(refresh)
  5218. {
  5219. [self refresh:refresh_trigger discardDirty:discardDirty];
  5220. }
  5221. }
  5222. #pragma mark- switch changed
  5223. - (void) switchIsChanged:(UISwitch *)paramSender{
  5224. // [self.switchlock lock];
  5225. // DebugLog(@"switch lock");
  5226. UITableViewCell *cell = (UITableViewCell *) paramSender.superview.superview;
  5227. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  5228. if(indexPath==nil)
  5229. {
  5230. [paramSender setOn:!paramSender.isOn];
  5231. return ;
  5232. }
  5233. NSMutableDictionary* section_json=nil;
  5234. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  5235. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  5236. bool refresh = [[item_json valueForKey:@"refresh"] boolValue];
  5237. bool discardDirty = [[item_json valueForKey:@"discard_dirty"] boolValue];
  5238. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  5239. NSString* subid=[item_json valueForKey:@"subid"];
  5240. NSString* check=@"false";
  5241. if([paramSender isOn])
  5242. check=@"true";
  5243. [item_json setValue:@"true" forKey:@"dirty"];
  5244. [item_json setValue:check forKey:@"value"];
  5245. if(subid==nil)
  5246. {
  5247. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  5248. int count=0;
  5249. count=[[section_json valueForKey:@"count"] intValue];
  5250. for(int i=0;i<count;i++)
  5251. {
  5252. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  5253. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  5254. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  5255. }
  5256. }
  5257. else
  5258. {
  5259. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  5260. int section = [(NSString*)idarr[0] intValue];
  5261. int item=[(NSString*)idarr[1] intValue];
  5262. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  5263. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  5264. item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  5265. [item_json setValue:@"true" forKey:@"dirty"];
  5266. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  5267. }
  5268. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  5269. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  5270. NSRange range = NSMakeRange(indexPath.section, 1);
  5271. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  5272. [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  5273. if(refresh)
  5274. {
  5275. [self refresh:refresh_trigger discardDirty:discardDirty];
  5276. }
  5277. DebugLog(@"switch unlock");
  5278. // [self.switchlock unlock];
  5279. }
  5280. -(NSMutableDictionary*) fill_switch_subitem:(NSMutableDictionary *) switch_item subid:(NSArray*) subid source:(NSMutableDictionary*)source mapping:(NSDictionary*)mapping //step:(int) step
  5281. {
  5282. NSString* value = [switch_item valueForKey:@"value"];
  5283. NSMutableDictionary* boolitem=nil;
  5284. NSMutableDictionary* subjson=nil;
  5285. if([value isEqualToString:@"true"])
  5286. {
  5287. boolitem =[[switch_item objectForKey:@"true"] mutableCopy];
  5288. }
  5289. else
  5290. {
  5291. boolitem =[[switch_item objectForKey:@"false"] mutableCopy];
  5292. }
  5293. subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  5294. if( subjson!=nil /*&& !active*/)
  5295. {
  5296. int sub_count = [[subjson valueForKey:@"count"] intValue];
  5297. for(int l=0;l<sub_count;l++)
  5298. {
  5299. NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  5300. // NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  5301. NSString* mapto = [modify_item valueForKey:@"name"];
  5302. if(mapto.length==0)
  5303. continue;
  5304. NSString* valuefrom= [mapping valueForKey:[modify_item valueForKey:@"name"]];
  5305. if(valuefrom==nil)
  5306. continue;
  5307. NSString* valuestr= [source valueForKey:valuefrom];
  5308. if(TRUE)
  5309. {
  5310. if(valuestr.length>0)
  5311. [modify_item setValue:valuestr forKey:@"value"];
  5312. else
  5313. [modify_item setValue:@"" forKey:@"value"];
  5314. [modify_item setValue:@"true" forKey:@"dirty"];
  5315. [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]];
  5316. }
  5317. }
  5318. [boolitem setObject:subjson forKey:@"sub_item"];
  5319. if([value isEqualToString:@"true"])
  5320. [switch_item setObject:boolitem forKey:@"true"];
  5321. else
  5322. [switch_item setObject:boolitem forKey:@"false"];
  5323. }
  5324. return switch_item;
  5325. }
  5326. -(NSMutableDictionary*) fill_enum_subitem:(NSMutableDictionary *) enum_item subid:(NSArray*) subid source:(NSMutableDictionary*)source mapping:(NSDictionary*)mapping //step:(int) step
  5327. {
  5328. NSMutableDictionary* cadedatejson = [[enum_item objectForKey:@"cadedate"] mutableCopy];
  5329. int count = [[cadedatejson valueForKey:@"count"]intValue];
  5330. for(int i=0;i<count;i++)
  5331. {
  5332. NSMutableDictionary* val_json = [[cadedatejson objectForKey:[NSString stringWithFormat:@"val_%d",i]] mutableCopy];
  5333. int check = [[val_json valueForKey:@"check"] intValue];
  5334. if(check==1)
  5335. {
  5336. NSMutableDictionary* subjson=[[val_json objectForKey:@"sub_item"] mutableCopy];
  5337. if( subjson!=nil /*&& !active*/)
  5338. {
  5339. int sub_count = [[subjson valueForKey:@"count"] intValue];
  5340. for(int l=0;l<sub_count;l++)
  5341. {
  5342. NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  5343. // NSString* subid=[modify_item valueForKey:@"subid"];
  5344. //
  5345. //
  5346. // NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  5347. NSString* control_type = [modify_item valueForKey:@"control"];
  5348. if([control_type isEqualToString:@"switch"])
  5349. modify_item= [self fill_switch_subitem:modify_item subid:nil source:source mapping:mapping ];
  5350. else if([control_type isEqualToString:@"enum"])
  5351. {
  5352. modify_item= [self fill_enum_subitem:modify_item subid:nil source:source mapping:mapping ];
  5353. }
  5354. else
  5355. {
  5356. NSString* mapto = [modify_item valueForKey:@"name"];
  5357. if(mapto.length==0)
  5358. continue;
  5359. NSString* valuefrom= [mapping valueForKey:[modify_item valueForKey:@"name"]];
  5360. if(valuefrom==nil)
  5361. continue;
  5362. NSString* valuestr= [source valueForKey:valuefrom];
  5363. if(true)
  5364. {
  5365. if(valuestr.length>0)
  5366. [modify_item setValue:valuestr forKey:@"value"];
  5367. else
  5368. [modify_item setValue:@"" forKey:@"value"];
  5369. //[modify_item setValue:valuestr forKey:@"value"];
  5370. // [modify_item setValue:@"true" forKey:@"dirty"];
  5371. }
  5372. }
  5373. [modify_item setValue:@"true" forKey:@"dirty"];
  5374. [subjson setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",l ]];
  5375. // [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  5376. // NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  5377. }
  5378. [val_json setObject:subjson forKey:@"sub_item"];
  5379. }
  5380. }
  5381. [cadedatejson setObject:val_json forKey:[NSString stringWithFormat:@"val_%d",i]];
  5382. }
  5383. [enum_item setObject:cadedatejson forKey:@"cadedate"];
  5384. return enum_item;
  5385. }
  5386. -(NSMutableDictionary*) switch_subitem_changed:(NSMutableDictionary *) switch_item subid:(NSArray*) subid value:(NSMutableDictionary*)valuejson step:(int) step
  5387. {
  5388. int index = [(NSString*)subid[step] intValue];
  5389. NSString* value = [switch_item valueForKey:@"value"];
  5390. NSMutableDictionary* boolitem=nil;
  5391. NSMutableDictionary* subjson=nil;
  5392. if([value isEqualToString:@"true"])
  5393. {
  5394. boolitem =[[switch_item objectForKey:@"true"] mutableCopy];
  5395. }
  5396. else
  5397. {
  5398. boolitem =[[switch_item objectForKey:@"false"] mutableCopy];
  5399. }
  5400. subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  5401. if(subjson!=nil)
  5402. {
  5403. NSMutableDictionary * itemjson=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",index]] mutableCopy];
  5404. if(step==subid.count-1)
  5405. {
  5406. itemjson =valuejson;
  5407. }
  5408. [subjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",index]];
  5409. [boolitem setObject:subjson forKey:@"sub_item"];
  5410. if([value isEqualToString:@"true"])
  5411. [switch_item setObject:boolitem forKey:@"true"];
  5412. else
  5413. [switch_item setObject:boolitem forKey:@"false"];
  5414. return switch_item;
  5415. }
  5416. return nil;
  5417. }
  5418. #pragma mark Request Editor
  5419. //-(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  5420. //{
  5421. // return [RANetwork request_Editor:request_url params:params];
  5422. //}
  5423. //
  5424. //- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  5425. //{
  5426. //
  5427. // NSLog(@"willDisplayCell");
  5428. // NSString *cellclass;
  5429. // const char *class_name_ch = object_getClassName([cell class]);
  5430. // cellclass = [NSString stringWithUTF8String:class_name_ch];
  5431. //
  5432. // CommonEditorCellTextView * tvcell=nil;
  5433. // if([cellclass isEqualToString:@"CommonEditorCellTextView"])
  5434. // {
  5435. // tvcell=(CommonEditorCellTextView*)self.editingcell;
  5436. // tvcell.textview.scrollEnabled=true;
  5437. //
  5438. //
  5439. // }
  5440. //}
  5441. //- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath
  5442. //{
  5443. //
  5444. // NSLog(@"didEndDisplayingCell");
  5445. // NSString *cellclass;
  5446. // const char *class_name_ch = object_getClassName([cell class]);
  5447. // cellclass = [NSString stringWithUTF8String:class_name_ch];
  5448. //
  5449. // CommonEditorCellTextView * tvcell=nil;
  5450. // if([cellclass isEqualToString:@"CommonEditorCellTextView"])
  5451. // {
  5452. // tvcell=(CommonEditorCellTextView*)self.editingcell;
  5453. // tvcell.textview.scrollEnabled=false;
  5454. //
  5455. //
  5456. // }
  5457. //
  5458. //}
  5459. #pragma mark - Responding to keyboard events
  5460. - (void)keyboardWillChangeFrame:(NSNotification *)notification {
  5461. // return;
  5462. DebugLog(@"keyboardWillChangeFrame");
  5463. // 使用tableContainer计算frame 保证屏幕旋转后table height正确
  5464. CGRect table_origin_screen_frame = [self.tableContainer convertRect:self.tableContainer.bounds toView:self.view.window];
  5465. // NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
  5466. // duration *= 0.0;
  5467. CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  5468. CGFloat end_y = end.origin.y;
  5469. CGRect screenframe=[[UIScreen mainScreen] bounds];
  5470. // CGRect controlframe= self.lastedit.frame;
  5471. // self.autocompleteView.frame= CGRectMake(200,200,200,200);//CGRectMake(screenframe.origin.x, screenframe.origin.y, screenframe.size.width, end_y);
  5472. NSIndexPath *indexPath = [self.editorTable indexPathForCell:self.editingcell];
  5473. CGRect table_frame = self.editorTable.frame;
  5474. // table底部距离键盘顶部偏移
  5475. CGFloat offset = CGRectGetMaxY(table_origin_screen_frame) - end_y;
  5476. if (offset > 0) {
  5477. // table -> top > offset: table.y = -offset
  5478. // 事实上top:topLayoutGuide
  5479. // self.additionalSafeAreaInsets
  5480. float y0=self.view.safeAreaLayoutGuide.topAnchor.accessibilityActivationPoint.y;
  5481. CGFloat topAvailableHeight = (CGRectGetMinY(table_origin_screen_frame) - y0);
  5482. if (topAvailableHeight > 0 || true) {
  5483. if (topAvailableHeight > offset) {
  5484. table_frame.origin.y = -offset;
  5485. } else {
  5486. // 向上移动到topLayoutGuide,不足部分通过缩减高度到达keyboard顶部
  5487. // table_frame.origin.y = -topAvailableHeight;
  5488. // table_frame.size.height = (end_y - self.topLayoutGuide.length);
  5489. for (NSLayoutConstraint *constraint in self.tableContainer.constraints) {
  5490. if (constraint.firstAttribute == NSLayoutAttributeBottom) {
  5491. // int a=0;
  5492. [self.tableContainer removeConstraint:constraint];
  5493. NSLayoutConstraint *bottom_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
  5494. attribute:NSLayoutAttributeBottom
  5495. relatedBy:NSLayoutRelationEqual
  5496. toItem:self.tableContainer
  5497. attribute:NSLayoutAttributeBottom
  5498. multiplier:1
  5499. constant:-end.size.height];
  5500. self.tb_bottom_constraint = bottom_constraint;
  5501. [self.tableContainer addConstraint:bottom_constraint];
  5502. break;
  5503. //
  5504. }
  5505. }
  5506. }
  5507. } else {
  5508. // contentInset = (top = 64, left = 0, bottom = 0, right = 0),topAvailableHeight = -64
  5509. table_frame.size.height = table_origin_screen_frame.size.height - offset;
  5510. }
  5511. // table_frame.size.height = CGRectGetHeight(table_origin_screen_frame) - (CGRectGetMaxY(table_origin_screen_frame) - end_y);
  5512. } else {
  5513. // table_frame.size.height = CGRectGetHeight(table_origin_screen_frame);
  5514. // table_frame = self.tableContainer.bounds;
  5515. for (NSLayoutConstraint *constraint in self.tableContainer.constraints) {
  5516. if (constraint.firstAttribute == NSLayoutAttributeBottom) {
  5517. // int a=0;
  5518. [self.tableContainer removeConstraint:constraint];
  5519. NSLayoutConstraint *bottom_constraint = [NSLayoutConstraint constraintWithItem:self.editorTable
  5520. attribute:NSLayoutAttributeBottom
  5521. relatedBy:NSLayoutRelationEqual
  5522. toItem:self.tableContainer
  5523. attribute:NSLayoutAttributeBottom
  5524. multiplier:1
  5525. constant:0];
  5526. self.tb_bottom_constraint = bottom_constraint;
  5527. [self.tableContainer addConstraint:bottom_constraint];
  5528. break;
  5529. //
  5530. }
  5531. }
  5532. }
  5533. self.editorTable.frame = table_frame;
  5534. CGRect cell_screen_frame = [self.editingcell convertRect:self.editingcell.bounds toView:self.view.window];
  5535. int cover =CGRectGetMaxY(cell_screen_frame) - end_y;
  5536. if (cover>0) {
  5537. // Cell 被键盘遮挡后才滚动
  5538. NSLog(@"scrollToRowAtIndexPath");
  5539. NSString *cellclass;
  5540. const char *class_name_ch = object_getClassName([self.editingcell class]);
  5541. cellclass = [NSString stringWithUTF8String:class_name_ch];
  5542. CommonEditorCellTextView * tvcell=nil;
  5543. // if([cellclass isEqualToString:@"CommonEditorCellTextView"])
  5544. {
  5545. // tvcell=(CommonEditorCellTextView*)self.editingcell;
  5546. // tvcell.textview.scrollEnabled=false;
  5547. CGPoint current_offset=self.editorTable.contentOffset;
  5548. NSLog(@"OFFSET %f",current_offset.y);
  5549. CGPoint moveto= CGPointMake(self.editingcell.frame.origin.x,current_offset.y+cover);
  5550. [self.editorTable setContentOffset:moveto];
  5551. }
  5552. ;
  5553. // self.editorTable cell
  5554. // self.editorTable scrollto
  5555. // self.editorTable scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition) animated:<#(BOOL)#>
  5556. // CGPoint current_offset=self.editorTable.contentOffset;
  5557. //
  5558. // NSLog(@"OFFSET %f",current_offset.y);
  5559. // CGPoint moveto= CGPointMake(self.editingcell.frame.origin.x,current_offset.y+cover);
  5560. // [self.editorTable setContentOffset:self.editingcell.frame.origin];
  5561. // [self.editorTable scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:NO];
  5562. //
  5563. }
  5564. // ===============================================
  5565. if (end_y >= [UIScreen mainScreen].bounds.size.height) {
  5566. self.keyboard_show = NO;
  5567. } else {
  5568. self.keyboard_show = YES;
  5569. }
  5570. }
  5571. - (void)keyboardDidChangeFrame:(NSNotification *)notification {
  5572. NSLog(@"keyboardDidChangeFrame");
  5573. // NSString *cellclass;
  5574. // const char *class_name_ch = object_getClassName([self.editingcell class]);
  5575. // cellclass = [NSString stringWithUTF8String:class_name_ch];
  5576. //
  5577. // CommonEditorCellTextView * tvcell=nil;
  5578. // if([cellclass isEqualToString:@"CommonEditorCellTextView"])
  5579. // {
  5580. //
  5581. // tvcell=(CommonEditorCellTextView*)self.editingcell;
  5582. // tvcell.textview.scrollEnabled=true;
  5583. //
  5584. //
  5585. // }
  5586. return;
  5587. // 使用tableContainer计算frame 保证屏幕旋转后table height正确
  5588. // CGRect table_origin_screen_frame = [self.tableContainer convertRect:self.tableContainer.bounds toView:self.view.window];
  5589. CGRect screen_rect = [RAUtils relativeFrameForScreenWithView:self.editorTable];
  5590. //
  5591. // // NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
  5592. // // duration *= 0.0;
  5593. CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  5594. // CGRect begin = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
  5595. float kbheight = end.size.height;
  5596. CGFloat keyboard_top = end.origin.y;
  5597. NSLog(@"keyboard rect: %@",NSStringFromCGRect(end));
  5598. NSLog(@"view rect: %@",NSStringFromCGRect(self.view.frame));
  5599. NSLog(@"view screen rect: %@",NSStringFromCGRect(screen_rect));
  5600. // self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
  5601. float dark = screen_rect.origin.y+screen_rect.size.height-keyboard_top;
  5602. if(dark>0)
  5603. {
  5604. // self.editorTable.scrollEnabled = true;
  5605. // self.editorTable.contentSize = CGSizeMake(self.editorTable.frame.size.width, self.editorTable.frame.size.height+dark);
  5606. self.editorTable.contentSize=CGSizeMake(self.editorTable.contentSize.width, self.editorTable.contentSize.height+kbheight);
  5607. }
  5608. else
  5609. {
  5610. // self.editorTable.scrollEnabled = false;
  5611. // self.editorTable.contentSize = self.editorTable.frame.size;
  5612. self.editorTable.contentSize=CGSizeMake(self.editorTable.contentSize.width, self.editorTable.contentSize.height-kbheight);
  5613. }
  5614. }
  5615. //static float table_origin_h = 0;
  5616. //
  5617. //- (void)keyboardWillShow:(NSNotification *)notification {
  5618. // DebugLog(@"keyboardWillShow");
  5619. ////
  5620. //// if(self.keyboard_show)
  5621. //// return;
  5622. ////
  5623. //// self.keyboard_show=true;
  5624. //// /*
  5625. //// Reduce the size of the text view so that it's not obscured by the keyboard.
  5626. //// Animate the resize so that it's in sync with the appearance of the keyboard.
  5627. //// */
  5628. ////
  5629. //// NSDictionary *userInfo = [notification userInfo];
  5630. ////
  5631. //// // Get the origin of the keyboard when it's displayed.
  5632. //// NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  5633. ////
  5634. //// // 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.
  5635. //// // CGRect keyboardRect = [aValue CGRectValue];
  5636. //// CGSize keyboardSize = [aValue CGRectValue].size;
  5637. //// DebugLog(@"keyboard height:%f",keyboardSize.height);
  5638. //// // Get the duration of the animation.
  5639. //// NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
  5640. //// NSTimeInterval animationDuration;
  5641. //// [animationDurationValue getValue:&animationDuration];
  5642. ////
  5643. ////
  5644. //// // if(self.keyboard_h==0)
  5645. //// // {
  5646. //// self.keyboard_h =keyboardSize.height;
  5647. //// CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:self.editingcell];
  5648. //// CGRect rect_screen = [ UIScreen mainScreen ].bounds;
  5649. ////
  5650. //// // int vpos =self.view.frame.origin.y+self.view.frame.size.height;
  5651. //// // int loginpos = self.editingcell.frame.origin.y+self.editingcell.frame.size.height;
  5652. //// //
  5653. //// int cellpos = cellrect_screen.origin.y+cellrect_screen.size.height;
  5654. //// // screen.size.height-keyboardSize.height-(cellpos_screen.origin.x+cellpos_screen.size.height);
  5655. //// 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);
  5656. //// if(self.ioffset>0)
  5657. //// {
  5658. //// // self.resize = true;
  5659. ////
  5660. ////
  5661. //// CGPoint contentOffsetPoint = self.editorTable.contentOffset;
  5662. ////
  5663. ////
  5664. //// contentOffsetPoint.y+=self.ioffset;
  5665. ////
  5666. //// self.editorTable.contentOffset=contentOffsetPoint;
  5667. ////
  5668. ////
  5669. //// // NSTimeInterval animationDuration = 0.30f;
  5670. //// // CGRect frame = self.view.frame;
  5671. //// // frame.origin.y -=self.ioffset;//view的Y轴上移
  5672. //// // frame.size.height +=self.ioffset; //View的高度增加
  5673. //// // self.view.frame = frame;
  5674. //// // [UIView beginAnimations:@"ResizeView" context:nil];
  5675. //// // [UIView setAnimationDuration:animationDuration];
  5676. //// // self.view.frame = frame;
  5677. //// // [UIView commitAnimations];//设置调整界面的动画效果
  5678. //// }
  5679. ////
  5680. //// table_origin_h = self.editorTable.frame.size.height;
  5681. //// self.editorTable.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, self.editorTable.frame.size.height-self.keyboard_h);
  5682. ////
  5683. //// // CGSize tablecontent =self.editorTable.contentSize;
  5684. //// // tablecontent.height=tablecontent.height+self.keyboard_h;
  5685. //// // self.editorTable.contentSize=tablecontent;
  5686. //// // }
  5687. //// // Animate the resize of the text view's frame in sync with the keyboard's appearance.
  5688. //// // [self moveInputBarWithKeyboardHeight:keyboardRect.size.height withDuration:animationDuration];
  5689. //}
  5690. //- (void)keyboardWillHide:(NSNotification *)notification {
  5691. // DebugLog(@"keyboardWillHide");
  5692. //
  5693. //// self.keyboard_show=false;
  5694. //// NSDictionary* userInfo = [notification userInfo];
  5695. ////
  5696. //// /*
  5697. //// Restore the size of the text view (fill self's view).
  5698. //// Animate the resize so that it's in sync with the disappearance of the keyboard.
  5699. //// */
  5700. //// NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
  5701. //// NSTimeInterval animationDuration;
  5702. //// [animationDurationValue getValue:&animationDuration];
  5703. //// CGSize tablecontent =self.editorTable.contentSize;
  5704. //// tablecontent.height=tablecontent.height-self.keyboard_h;
  5705. //// // self.editorTable.contentSize=tablecontent;
  5706. ////
  5707. //// self.editorTable.frame = CGRectMake(0, 0, self.editorTable.frame.size.width, table_origin_h);
  5708. ////
  5709. //// self.keyboard_h= 0;
  5710. //// DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  5711. ////
  5712. ////
  5713. //// // if(self.resize)
  5714. //// // {
  5715. //// // NSTimeInterval animationDuration = 0.30f;
  5716. //// // CGRect frame = self.view.frame;
  5717. //// // // if(prewTag == textField.tag) //当结束编辑的View的TAG是上次的就移动
  5718. //// // // { //还原界面
  5719. //// // // moveY = prewMoveY;
  5720. //// // frame.origin.y +=self.ioffset;
  5721. //// // frame.size. height -=self.ioffset;
  5722. //// // self.view.frame = frame;
  5723. //// // // }
  5724. //// // //self.view移回原位置
  5725. //// // [UIView beginAnimations:@"ResizeView" context:nil];
  5726. //// // [UIView setAnimationDuration:animationDuration];
  5727. //// // self.view.frame = frame;
  5728. //// // [UIView commitAnimations];
  5729. //// // //[textField resignFirstResponder];
  5730. //// // self.ioffset=0;
  5731. //// // }
  5732. ////
  5733. ////
  5734. //// // [self moveInputBarWithKeyboardHeight:0.0 withDuration:animationDuration];
  5735. //}
  5736. #pragma mark - RageCell Delegate
  5737. - (void)commonEditorRangeCell:(CommonEditorRangeCell *)cell didChangeMinValue:(NSString *)minValue maxValue:(NSString *)maxValue atIndexPath:(NSIndexPath *)indexPath{
  5738. if (indexPath == nil) {
  5739. if (cell != nil) {
  5740. indexPath = [self.editorTable indexPathForCell:cell];
  5741. } else {
  5742. return;
  5743. }
  5744. }
  5745. if (indexPath == nil) {
  5746. return;
  5747. }
  5748. NSString *section_key = [NSString stringWithFormat:@"section_%ld",indexPath.section];
  5749. NSString *item_key = [NSString stringWithFormat:@"item_%ld",indexPath.row];
  5750. NSMutableDictionary *section_json = [[self.content_data_download objectForKey:section_key] mutableCopy];
  5751. NSMutableDictionary *item_json = [((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  5752. [item_json setObject:minValue forKey:@"min_value"];
  5753. [item_json setObject:maxValue forKey:@"max_value"];
  5754. [section_json setObject:item_json forKey:item_key];
  5755. [self.content_data_download setObject:section_json forKey:section_key];
  5756. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  5757. }
  5758. #pragma mark - WebCell Delegate
  5759. - (void)commonEditorWebCell:(CommonEditorWebCell *)cell didChangeContentHeight:(CGFloat)contentHeight {
  5760. // return;
  5761. NSIndexPath *indexPath = [self.editorTable indexPathForCell:cell];
  5762. if (indexPath == nil) {
  5763. return;
  5764. }
  5765. NSMutableDictionary* section_json=nil;
  5766. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  5767. NSString* subid=[item_json valueForKey:@"subid"];
  5768. NSString* control = [item_json valueForKey:@"control"];
  5769. id height_obj = [item_json objectForKey:@"height"];
  5770. // NSLog(@"indexPath: %@ origin height: %@ currentHeight: %f",indexPath,height_obj,contentHeight);
  5771. if ([control isEqualToString:@"webview"] && [height_obj floatValue] != contentHeight)
  5772. {
  5773. [item_json setValue:@(contentHeight) forKey:@"height"];
  5774. if(subid==nil)
  5775. {
  5776. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  5777. int count=0;
  5778. count=[[section_json valueForKey:@"count"] intValue];
  5779. for(int i=0;i<count;i++)
  5780. {
  5781. NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  5782. if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  5783. [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  5784. }
  5785. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  5786. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  5787. }
  5788. // else
  5789. // {
  5790. // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  5791. // int section = [(NSString*)idarr[0] intValue];
  5792. // int item=[(NSString*)idarr[1] intValue];
  5793. //
  5794. //
  5795. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  5796. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  5797. //
  5798. // NSString* control_type= [olditem valueForKey:@"control"];
  5799. // NSMutableDictionary* new_item=nil;
  5800. //// [item_json setValue:@"true" forKey:@"dirty"];
  5801. // if([control_type isEqualToString:@"enum"])
  5802. // new_item= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  5803. // else if([control_type isEqualToString:@"switch"])
  5804. // new_item= [self switch_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  5805. //
  5806. // [section_json setObject:new_item forKey:[NSString stringWithFormat:@"item_%d",item ]];
  5807. //
  5808. //
  5809. // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  5810. // self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  5811. // }
  5812. // // 更新数据
  5813. // [item_json setObject:@(contentHeight) forKey:@"height"];
  5814. //
  5815. // NSMutableDictionary *section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  5816. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  5817. // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  5818. // self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  5819. //
  5820. // // 调用 tableView 的 beginUpdates 和 endUpdates,更新 cell 的高度
  5821. // [self.editorTable beginUpdates];
  5822. // [self.editorTable endUpdates];
  5823. dispatch_async(dispatch_get_main_queue(), ^{
  5824. // UI更新代码
  5825. [self.editorTable reloadData];
  5826. //[self.editorTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  5827. });
  5828. }
  5829. }
  5830. - (void)MActionClicked:(UIButton *)sender {
  5831. [RAUtils message_alert:@"MActionClicked dose not impl" title:@"Warring" controller:self];
  5832. }
  5833. #pragma mark - Banner Delegate
  5834. - (void)commonEditorBannerCell:(CommonEditorBannerCell *)cell didClickItemAtIndexPath:(NSIndexPath *)indexPath {
  5835. if ([[[cell content] objectForKey:@"count"] integerValue] == 0) {
  5836. return;
  5837. }
  5838. ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
  5839. preVC.content = [cell content];
  5840. [preVC setOffset:indexPath.row];
  5841. if (self.navigationController) {
  5842. [self.navigationController pushViewController:preVC animated:YES];
  5843. } else {
  5844. [self presentViewController:preVC animated:true completion:nil];
  5845. }
  5846. }
  5847. #pragma mark 为子类暴露的接口
  5848. -(void) handle_editor_cell_select:(UITableView *)tableView IndexPath:(NSIndexPath *)indexPath
  5849. {
  5850. NSAssert(true, ([NSString stringWithFormat:@"%@ handle_editor_cell_select not impl",[self class_name]]));
  5851. }
  5852. @end