CommonEditorViewController.m 311 KB

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